1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-25 01:45:33 +02:00

Work in progress for the PathEntry API

This commit is contained in:
Alain Magloire 2004-04-28 16:46:21 +00:00
parent 129ff70d20
commit ebeb4082c9
8 changed files with 192 additions and 138 deletions

View file

@ -1,3 +1,14 @@
2004-04-28 Alain Magloire
Work in Progress for the PathEntry API
* model/org/eclipse/cdt/core/model/CoreModel.java
* model/org/eclipse/cdt/core/model/IIncludeEntry.java
* model/org/eclipse/cdt/internal/core/model/IncludeEntry.java
* model/org/eclipse/cdt/internal/core/model/LibraryEntry.java
* model/org/eclipse/cdt/internal/core/model/PathEntryManager.java
* src/org/eclipse/cdt/core/resources/ScannerInfo.java
* src/org/eclipse/cdt/core/resources/ScannerProvider.java
2004-04-27 Alain Magloire
Fix for PR 60182

View file

@ -355,6 +355,22 @@ public class CoreModel {
return new ContainerEntry(id, isExported);
}
/**
* Creates and returns a new entry of kind <code>CDT_LIBRARY</code>
* for the archive or folder identified by the given absolute path.
*
* @param baseRef
* the base reference path to find the library
* @param libraryPath
* the library name.
* @return a new library entry
*
*/
public static ILibraryEntry newLibraryRefEntry(IPath baseRef, IPath libraryPath) {
return new LibraryEntry(null, baseRef, libraryPath, null, null, null, false);
}
/**
* Creates and returns a new entry of kind <code>CDT_LIBRARY</code>
* for the archive or folder identified by the given absolute path.
@ -385,21 +401,6 @@ public class CoreModel {
return new LibraryEntry(basePath, null, libraryPath, sourceAttachmentPath, sourceAttachmentRootPath, sourceAttachmentPrefixMapping, isExported);
}
/**
* Creates and returns a new entry of kind <code>CDT_LIBRARY</code>
* for the archive or folder identified by the given absolute path.
*
* @param baseRef
* the base reference path to find the library
* @param libraryPath
* the library name.
* @return a new library entry
*
*/
public static ILibraryEntry newLibraryRefEntry(IPath baseRef, IPath libraryPath) {
return new LibraryEntry(null, baseRef, libraryPath, null, null, null, false);
}
/**
* Creates and returns a new entry of kind <code>CDT_OUTPUT</code> for
* the project's output folder

View file

@ -28,6 +28,13 @@ public interface IIncludeEntry extends IPathEntry {
*/
IPath getBasePath();
/**
* Return the includePath with the base path.
*
* @return
*/
IPath getFullIncludePath();
/**
* Return the reference path
*

View file

@ -75,4 +75,11 @@ public class IncludeEntry extends APathEntry implements IIncludeEntry {
}
return super.equals(obj);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.model.IIncludeEntry#getFullIncludePath()
*/
public IPath getFullIncludePath() {
return basePath.append(includePath);
}
}

View file

@ -118,4 +118,8 @@ public class LibraryEntry extends APathEntry implements ILibraryEntry {
}
return super.equals(obj);
}
public IPath getFullLibaryPath() {
return basePath.append(getPath());
}
}

View file

@ -27,7 +27,6 @@ import org.eclipse.cdt.core.model.IElementChangedListener;
import org.eclipse.cdt.core.model.IIncludeEntry;
import org.eclipse.cdt.core.model.ILibraryEntry;
import org.eclipse.cdt.core.model.IMacroEntry;
import org.eclipse.cdt.core.model.IOutputEntry;
import org.eclipse.cdt.core.model.IPathEntry;
import org.eclipse.cdt.core.model.IPathEntryContainer;
import org.eclipse.cdt.core.model.IProjectEntry;
@ -87,84 +86,6 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
return pathEntryManager;
}
public IOutputEntry[] getOutputEntries(ICProject cproject) throws CModelException {
IPathEntry[] entries = getResolvedPathEntries(cproject);
ArrayList list = new ArrayList(entries.length);
for (int i = 0; i < entries.length; ++i) {
if (entries[i].getEntryKind() == IPathEntry.CDT_OUTPUT) {
list.add(entries[i]);
}
}
IOutputEntry[] outs = new IOutputEntry[list.size()];
list.toArray(outs);
return outs;
}
public IProjectEntry[] getProjectEntries(ICProject cproject) throws CModelException {
IPathEntry[] entries = getResolvedPathEntries(cproject);
ArrayList list = new ArrayList(entries.length);
for (int i = 0; i < entries.length; ++i) {
if (entries[i].getEntryKind() == IPathEntry.CDT_PROJECT) {
list.add(entries[i]);
}
}
IProjectEntry[] projects = new IProjectEntry[list.size()];
list.toArray(projects);
return projects;
}
public ISourceEntry[] getSourceEntries(ICProject cproject) throws CModelException {
IPathEntry[] entries = getResolvedPathEntries(cproject);
ArrayList list = new ArrayList(entries.length);
for (int i = 0; i < entries.length; ++i) {
if (entries[i].getEntryKind() == IPathEntry.CDT_SOURCE) {
list.add(entries[i]);
}
}
ISourceEntry[] sources = new ISourceEntry[list.size()];
list.toArray(sources);
return sources;
}
public ILibraryEntry[] getLibraryEntries(ICProject cproject) throws CModelException {
IPathEntry[] entries = getResolvedPathEntries(cproject);
ArrayList list = new ArrayList(entries.length);
for (int i = 0; i < entries.length; ++i) {
if (entries[i].getEntryKind() == IPathEntry.CDT_LIBRARY) {
list.add(entries[i]);
}
}
ILibraryEntry[] libs = new ILibraryEntry[list.size()];
list.toArray(libs);
return libs;
}
public IMacroEntry[] getMacroEntries(ICProject cproject) throws CModelException {
IPathEntry[] entries = getResolvedPathEntries(cproject);
ArrayList list = new ArrayList(entries.length);
for (int i = 0; i < entries.length; ++i) {
if (entries[i].getEntryKind() == IPathEntry.CDT_MACRO) {
list.add(entries[i]);
}
}
IMacroEntry[] macros = new IMacroEntry[list.size()];
list.toArray(macros);
return macros;
}
public IIncludeEntry[] getIncludeEntries(ICProject cproject) throws CModelException {
IPathEntry[] entries = getResolvedPathEntries(cproject);
ArrayList list = new ArrayList(entries.length);
for (int i = 0; i < entries.length; ++i) {
if (entries[i].getEntryKind() == IPathEntry.CDT_INCLUDE) {
list.add(entries[i]);
}
}
IIncludeEntry[] includes = new IIncludeEntry[list.size()];
list.toArray(includes);
return includes;
}
public IPathEntry[] getResolvedPathEntries(ICProject cproject) throws CModelException {
IPathEntry[] entries = (IPathEntry[]) resolvedMap.get(cproject);
if (entries == null) {
@ -202,9 +123,9 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
switch(entry.getEntryKind()) {
case IPathEntry.CDT_INCLUDE: {
IIncludeEntry includeEntry = (IIncludeEntry)entry;
IPath includePath = includeEntry.getIncludePath();
IPath refPath = includeEntry.getBaseReference();
if (refPath != null && !refPath.isEmpty()) {
IPath includePath = includeEntry.getIncludePath();
if (refPath.isAbsolute()) {
IResource res = cproject.getCModel().getWorkspace().getRoot().findMember(refPath);
if (res != null && res.getType() == IResource.PROJECT) {
@ -240,8 +161,93 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
}
break;
}
case IPathEntry.CDT_MACRO:
case IPathEntry.CDT_MACRO: {
IMacroEntry macroEntry = (IMacroEntry)entry;
IPath refPath = macroEntry.getBaseReference();
if (refPath != null && !refPath.isEmpty()) {
String name = macroEntry.getMacroName();
if (refPath.isAbsolute()) {
IResource res = cproject.getCModel().getWorkspace().getRoot().findMember(refPath);
if (res != null && res.getType() == IResource.PROJECT) {
ICProject refCProject = CoreModel.getDefault().create((IProject)res);
if (refCProject != null) {
IPathEntry[] entries = getResolvedPathEntries(refCProject);
for (int i = 0; i < entries.length; i++) {
if (entries[i].getEntryKind() == IPathEntry.CDT_MACRO) {
IMacroEntry refEntry = (IMacroEntry)entries[i];
if (refEntry.getMacroName().equals(name)) {
String value = refEntry.getMacroValue();
return CoreModel.newMacroEntry(macroEntry.getPath(), name, value);
}
}
}
}
}
} else { // Container ref
IPathEntryContainer container = getPathEntryContainer(refPath, cproject);
if (container != null) {
IPathEntry[] entries = container.getPathEntries();
for (int i = 0; i < entries.length; i++) {
if (entries[i].getEntryKind() == IPathEntry.CDT_MACRO) {
IMacroEntry refEntry = (IMacroEntry)entries[i];
if (refEntry.getMacroName().equals(name)) {
String value = refEntry.getMacroValue();
return CoreModel.newMacroEntry(macroEntry.getPath(), name, value);
}
}
}
}
}
}
break;
}
case IPathEntry.CDT_LIBRARY: {
ILibraryEntry libEntry = (ILibraryEntry)entry;
IPath refPath = libEntry.getBaseReference();
if (refPath != null && !refPath.isEmpty()) {
IPath libraryPath = libEntry.getPath();
if (refPath.isAbsolute()) {
IResource res = cproject.getCModel().getWorkspace().getRoot().findMember(refPath);
if (res != null && res.getType() == IResource.PROJECT) {
ICProject refCProject = CoreModel.getDefault().create((IProject)res);
if (refCProject != null) {
IPathEntry[] entries = getResolvedPathEntries(refCProject);
for (int i = 0; i < entries.length; i++) {
if (entries[i].getEntryKind() == IPathEntry.CDT_LIBRARY) {
ILibraryEntry refEntry = (ILibraryEntry)entries[i];
if (refEntry.getPath().equals(libraryPath)) {
return CoreModel.newLibraryEntry(refEntry.getBasePath(),
refEntry.getPath(), refEntry.getSourceAttachmentPath(),
refEntry.getSourceAttachmentRootPath(),
refEntry.getSourceAttachmentPrefixMapping(), false);
}
}
}
}
}
} else { // Container ref
IPathEntryContainer container = getPathEntryContainer(refPath, cproject);
if (container != null) {
IPathEntry[] entries = container.getPathEntries();
for (int i = 0; i < entries.length; i++) {
if (entries[i].getEntryKind() == IPathEntry.CDT_INCLUDE) {
ILibraryEntry refEntry = (ILibraryEntry)entries[i];
if (refEntry.getPath().equals(libraryPath)) {
return CoreModel.newLibraryEntry(refEntry.getBasePath(),
refEntry.getPath(), refEntry.getSourceAttachmentPath(),
refEntry.getSourceAttachmentRootPath(),
refEntry.getSourceAttachmentPrefixMapping(), false);
}
}
}
}
}
}
break;
}
}
return entry;
}
@ -275,7 +281,7 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
boolean foundSource = false;
boolean foundOutput = false;
for (int i = 0; i < pathEntries.length; i++) {
IPathEntry rawEntry = (IPathEntry) pathEntries[i];
IPathEntry rawEntry = pathEntries[i];
if (rawEntry.getEntryKind() == IPathEntry.CDT_SOURCE) {
foundSource = true;
}

View file

@ -17,26 +17,15 @@ import org.eclipse.cdt.core.parser.IScannerInfo;
public class ScannerInfo implements IScannerInfo {
private Map macroMap;
private String[] includePaths;
private final Map macroMap;
private final String[] includePaths;
final static String[] EMPTY_ARRAY_STRING = new String[0];
protected ScannerInfo() {
}
protected ScannerInfo(String[] includePaths, Map macroMap) {
this.includePaths = includePaths;
this.macroMap = macroMap;
}
public synchronized void setIncludePaths(String[] paths) {
includePaths = paths;
}
public synchronized void setDefinedSymbols(Map map) {
macroMap = map;
}
/*
* (non-Javadoc)
*

View file

@ -16,6 +16,7 @@ import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import org.eclipse.cdt.core.AbstractCExtension;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ElementChangedEvent;
@ -33,7 +34,7 @@ import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath;
public class ScannerProvider implements IScannerInfoProvider, IElementChangedListener {
public class ScannerProvider extends AbstractCExtension implements IScannerInfoProvider, IElementChangedListener {
// Listeners interested in build model changes
private static Map listeners;
@ -43,7 +44,7 @@ public class ScannerProvider implements IScannerInfoProvider, IElementChangedLis
/*
* @return
*/
private synchronized static Map getListeners() {
private static Map getListeners() {
if (listeners == null) {
listeners = new HashMap();
}
@ -54,15 +55,47 @@ public class ScannerProvider implements IScannerInfoProvider, IElementChangedLis
* @param project
* @param info
*/
private static void notifyInfoListeners(IProject project, IScannerInfo info) {
protected static void notifyInfoListeners(IProject project, IScannerInfo info) {
// Call in the cavalry
List listeners = (List)getListeners().get(project);
if (listeners == null) {
return;
}
ListIterator iter = listeners.listIterator();
while (iter.hasNext()) {
((IScannerInfoChangeListener)iter.next()).changeNotification(project, info);
IScannerInfoChangeListener[] observers = new IScannerInfoChangeListener[listeners.size()];
listeners.toArray(observers);
for (int i = 0; i < observers.length; i++) {
observers[i].changeNotification(project, info);
}
}
private void addInfoFromEntry(IPathEntry entry, IPath resPath, List includeList, Map symbolMap) {
switch(entry.getEntryKind()) {
case IPathEntry.CDT_INCLUDE: {
IIncludeEntry include = (IIncludeEntry)entry;
IPath entryPath = include.getPath();
if (entryPath.equals(resPath) ||
entryPath.isPrefixOf(resPath) && include.isExported()) {
includeList.add(include.getFullIncludePath().toOSString());
}
break;
}
case IPathEntry.CDT_MACRO: {
IMacroEntry macro = (IMacroEntry)entry;
IPath entryPath = macro.getPath();
if (entryPath.equals(resPath) ||
entryPath.isPrefixOf(resPath) && macro.isExported()) {
String name = macro.getMacroName();
if (name != null && name.length() > 0) {
String value = macro.getMacroValue();
if (value == null) {
value = new String();
}
symbolMap.put(name, value);
}
}
break;
}
}
}
@ -74,44 +107,40 @@ public class ScannerProvider implements IScannerInfoProvider, IElementChangedLis
public IScannerInfo getScannerInformation(IResource resource) {
IPath resPath = resource.getFullPath();
ICProject cproject = CoreModel.getDefault().create(resource.getProject());
ScannerInfo info = new ScannerInfo();
try {
if (cproject != null) {
ArrayList includeList = new ArrayList();
Map symbolMap = new HashMap();
IPathEntry[] entries = cproject.getResolvedPathEntries();
for (int i = 0; i < entries.length; i++) {
int kind = entries[i].getEntryKind();
if (kind == IPathEntry.CDT_INCLUDE) {
IIncludeEntry include = (IIncludeEntry)entries[i];
IPath entryPath = include.getPath();
if (entryPath.equals(resPath) ||
entryPath.isPrefixOf(resPath) && include.isExported()) {
includeList.add(include.getIncludePath().toOSString());
}
} else if (kind == IPathEntry.CDT_MACRO) {
IMacroEntry macro = (IMacroEntry)entries[i];
IPath entryPath = macro.getPath();
if (entryPath.equals(resPath) ||
entryPath.isPrefixOf(resPath) && macro.isExported()) {
String name = macro.getMacroName();
if (name != null && name.length() > 0) {
String value = macro.getMacroValue();
if (value == null) {
value = new String();
switch (entries[i].getEntryKind()) {
case IPathEntry.CDT_PROJECT: {
IResource res = resource.getWorkspace().getRoot().findMember(entries[i].getPath());
if (res != null && res.getType() == IResource.PROJECT) {
ICProject refCProject = CoreModel.getDefault().create((IProject)res);
if (refCProject != null) {
IPathEntry[] projEntries = refCProject.getResolvedPathEntries();
for (int j = 0; j < projEntries.length; j++) {
if (entries[i].getEntryKind() == IPathEntry.CDT_INCLUDE) {
addInfoFromEntry(projEntries[j], resPath, includeList, symbolMap);
}
}
}
symbolMap.put(name, value);
}
break;
}
default:
addInfoFromEntry(entries[i], resPath, includeList, symbolMap);
}
}
info.setDefinedSymbols(symbolMap);
info.setIncludePaths((String[])includeList.toArray());
String[] includes = new String[includeList.size()];
includeList.toArray(includes);
return new ScannerInfo(includes, symbolMap);
}
} catch (CModelException e) {
//
}
return info;
return new ScannerInfo(null, null);
}
/*