Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: e4b0f54cf87f2782448b82b4f2012b5de31aa89d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*******************************************************************************
 *  Copyright (c) 2004, 2013 IBM Corporation and others.
 *
 *  This program and the accompanying materials
 *  are made available under the terms of the Eclipse Public License 2.0
 *  which accompanies this distribution, and is available at
 *  https://www.eclipse.org/legal/epl-2.0/
 *
 *  SPDX-License-Identifier: EPL-2.0
 *
 *  Contributors:
 *  IBM - Initial API and implementation
 *******************************************************************************/
package org.eclipse.cdt.make.internal.core.scannerconfig;

import java.util.ArrayList;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.IPathEntry;
import org.eclipse.cdt.core.model.IPathEntryContainerExtension;
import org.eclipse.cdt.make.core.MakeCorePlugin;
import org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IDiscoveredPathInfo;
import org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IPerFileDiscoveredPathInfo;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;

public class PerFileDiscoveredPathContainer extends DiscoveredPathContainer implements IPathEntryContainerExtension {
	public PerFileDiscoveredPathContainer(IProject project) {
		super(project);
	}

	@Override
	public IPathEntry[] getPathEntries(IPath path, int mask) {
		ArrayList<IPathEntry> entries = new ArrayList<IPathEntry>();
		try {
			IDiscoveredPathInfo info = MakeCorePlugin.getDefault().getDiscoveryManager().getDiscoveredInfo(fProject);
			if (info instanceof IPerFileDiscoveredPathInfo) {
				IResource rc = fProject.getWorkspace().getRoot().findMember(path);
				if (rc.getType() == IResource.FOLDER || rc.getType() == IResource.PROJECT) {
					return new IPathEntry[0];
				}

				IPerFileDiscoveredPathInfo filePathInfo = (IPerFileDiscoveredPathInfo) info;

				if ((mask & IPathEntry.CDT_INCLUDE) != 0) {
					IPath[] includes = filePathInfo.getIncludePaths(path);
					for (int i = 0; i < includes.length; i++) {
						// add as a system include path
						entries.add(CoreModel.newIncludeEntry(path, Path.EMPTY, includes[i], true));
					}
					includes = filePathInfo.getQuoteIncludePaths(path);
					for (int i = 0; i < includes.length; i++) {
						// add as a local include path
						entries.add(CoreModel.newIncludeEntry(path, Path.EMPTY, includes[i], false));
					}
				}
				if ((mask & IPathEntry.CDT_MACRO) != 0) {
					Map<String, String> syms = filePathInfo.getSymbols(path);
					Set<Entry<String, String>> entrySet = syms.entrySet();
					for (Entry<String, String> entry : entrySet) {
						entries.add(CoreModel.newMacroEntry(path, entry.getKey(), entry.getValue()));
					}
				}
				// compare the resource with include and macros files
				IPath fullResPath = fProject.getWorkspace().getRoot().getFile(path).getLocation();
				if (fullResPath == null) {
					fullResPath = path;
				}
				if ((mask & IPathEntry.CDT_INCLUDE_FILE) != 0) {
					IPath[] includeFiles = filePathInfo.getIncludeFiles(path);
					for (int i = 0; i < includeFiles.length; i++) {
						if (!includeFiles[i].equals(fullResPath)) {
							entries.add(CoreModel.newIncludeFileEntry(path, includeFiles[i]));
						}
					}
				}
				if ((mask & IPathEntry.CDT_MACRO_FILE) != 0) {
					IPath[] imacrosFiles = filePathInfo.getMacroFiles(path);
					for (int i = 0; i < imacrosFiles.length; i++) {
						if (!imacrosFiles[i].equals(fullResPath)) {
							entries.add(CoreModel.newMacroFileEntry(path, imacrosFiles[i]));
						}
					}
				}
			}
		}
		catch (CoreException e) {
			//
		}
		return entries.toArray(new IPathEntry[entries.size()]);
	}

	@Override
	public boolean isEmpty(IPath path) {
		IDiscoveredPathInfo info;
		try {
			info = MakeCorePlugin.getDefault().getDiscoveryManager().getDiscoveredInfo(fProject);
			if (info instanceof IPerFileDiscoveredPathInfo) {
				IPerFileDiscoveredPathInfo filePathInfo = (IPerFileDiscoveredPathInfo) info;
				return filePathInfo.isEmpty(path);
			}
		} catch (CoreException e) {
		}
		return false;
	}

}

Back to the top