blob: d37fd8cf44296b441146070936edc483d28273ff (
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
|
/*******************************************************************************
* Copyright (c) 2004, 2011 QNX Software Systems 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:
* QNX Software Systems - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.make.internal.core.scannerconfig;
import java.util.ArrayList;
import java.util.List;
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.IPathEntryContainer;
import org.eclipse.cdt.make.core.MakeCorePlugin;
import org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IDiscoveredPathInfo;
import org.eclipse.cdt.make.internal.core.MakeMessages;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
public class DiscoveredPathContainer implements IPathEntryContainer {
public static final IPath CONTAINER_ID = new Path("org.eclipse.cdt.make.core.DISCOVERED_SCANNER_INFO"); //$NON-NLS-1$
protected final IProject fProject;
private IPathEntry[] fPathEntries;
public DiscoveredPathContainer(IProject project) {
fProject = project;
fPathEntries = null;
}
// public IPathEntry[] getPathEntries() {
// IPathEntry[] fPathEntries;
// try {
// fPathEntries = getPathEntries(getPathEntryMap());
// } catch (CoreException e) {
// MakeCorePlugin.log(e);
// return new IPathEntry[0];
// }
// return fPathEntries;
// }
@Override
public String getDescription() {
return MakeMessages.getString("DiscoveredContainer.description"); //$NON-NLS-1$
}
@Override
public IPath getPath() {
return CONTAINER_ID;
}
@Override
public IPathEntry[] getPathEntries() {
if (fPathEntries == null) {
try {
fPathEntries = computeNewPathEntries();
} catch (CoreException e) {
MakeCorePlugin.log(e);
return new IPathEntry[0];
}
}
return fPathEntries;
}
private IPathEntry[] computeNewPathEntries() throws CoreException {
IDiscoveredPathInfo info = MakeCorePlugin.getDefault().getDiscoveryManager().getDiscoveredInfo(fProject);
IPath[] includes = info.getIncludePaths();
Map<String, String> syms = info.getSymbols();
List<IPathEntry> entries = new ArrayList<>(includes.length + syms.size());
for (IPath inc : includes) {
entries.add(CoreModel.newIncludeEntry(Path.EMPTY, Path.EMPTY, inc, true));
}
Set<Entry<String, String>> entrySet = syms.entrySet();
for (Entry<String, String> entry : entrySet) {
entries.add(CoreModel.newMacroEntry(Path.EMPTY, entry.getKey(), entry.getValue()));
}
return entries.toArray(new IPathEntry[entries.size()]);
}
}
|