diff options
author | Alain Magloire | 2004-04-28 16:46:21 +0000 |
---|---|---|
committer | Alain Magloire | 2004-04-28 16:46:21 +0000 |
commit | ebeb4082c9c7cc6c1f3d1a22b713ddc2fdf0b786 (patch) | |
tree | 2f42bb6ad61aea3aaaceb341247bd8ebf8adfcd9 | |
parent | 129ff70d20acded879cca5c607193006d7639373 (diff) | |
download | org.eclipse.cdt-ebeb4082c9c7cc6c1f3d1a22b713ddc2fdf0b786.tar.gz org.eclipse.cdt-ebeb4082c9c7cc6c1f3d1a22b713ddc2fdf0b786.tar.xz org.eclipse.cdt-ebeb4082c9c7cc6c1f3d1a22b713ddc2fdf0b786.zip |
Work in progress for the PathEntry API
8 files changed, 192 insertions, 138 deletions
diff --git a/core/org.eclipse.cdt.core/ChangeLog b/core/org.eclipse.cdt.core/ChangeLog index ae28695d6c2..1c26c7f0dcf 100644 --- a/core/org.eclipse.cdt.core/ChangeLog +++ b/core/org.eclipse.cdt.core/ChangeLog @@ -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 diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java index 3cf0222db24..68800367f06 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java @@ -359,6 +359,22 @@ public class CoreModel { * 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. + * * Note that this operation does not attempt to validate or access the * resources at the given paths. * <p> @@ -386,21 +402,6 @@ public class CoreModel { } /** - * 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 * <p> diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IIncludeEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IIncludeEntry.java index 9762e465442..86278816388 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IIncludeEntry.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IIncludeEntry.java @@ -29,6 +29,13 @@ public interface IIncludeEntry extends IPathEntry { IPath getBasePath(); /** + * Return the includePath with the base path. + * + * @return + */ + IPath getFullIncludePath(); + + /** * Return the reference path * * @return diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IncludeEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IncludeEntry.java index 20b91b6f016..90aa8ede636 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IncludeEntry.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IncludeEntry.java @@ -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); + } } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/LibraryEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/LibraryEntry.java index 66733791bad..f1d02fcd6d7 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/LibraryEntry.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/LibraryEntry.java @@ -118,4 +118,8 @@ public class LibraryEntry extends APathEntry implements ILibraryEntry { } return super.equals(obj); } + + public IPath getFullLibaryPath() { + return basePath.append(getPath()); + } } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryManager.java index c8f0657f3f1..ab67e205a0e 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryManager.java @@ -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; } diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/ScannerInfo.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/ScannerInfo.java index f9ff3c4c8ce..9e7222fe587 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/ScannerInfo.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/ScannerInfo.java @@ -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) * diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/ScannerProvider.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/ScannerProvider.java index df123c3741f..b73cc839a41 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/ScannerProvider.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/ScannerProvider.java @@ -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); } /* |