diff --git a/core/org.eclipse.cdt.core/ChangeLog b/core/org.eclipse.cdt.core/ChangeLog index 8263385df47..f381fe94945 100644 --- a/core/org.eclipse.cdt.core/ChangeLog +++ b/core/org.eclipse.cdt.core/ChangeLog @@ -1,3 +1,9 @@ +2004-02-21 Alain Magloire + + Refactor the ICPathEntry to IPathEntry for consistency. + Regroup the IPathEntry helper methods in PathEntryManager + To much files change in the refactoring to enumerate. + 2004-02-17 David Inglis Fix PR 52095 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 4a8855feea9..dda0ba38e94 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 @@ -11,6 +11,7 @@ import org.eclipse.cdt.internal.core.model.ContainerEntry; import org.eclipse.cdt.internal.core.model.IncludeEntry; import org.eclipse.cdt.internal.core.model.LibraryEntry; import org.eclipse.cdt.internal.core.model.MacroEntry; +import org.eclipse.cdt.internal.core.model.PathEntryManager; import org.eclipse.cdt.internal.core.model.ProjectEntry; import org.eclipse.cdt.internal.core.model.SourceEntry; import org.eclipse.cdt.internal.core.search.indexing.IndexManager; @@ -29,6 +30,7 @@ public class CoreModel { private static CoreModel cmodel = null; private static CModelManager manager = null; + private static PathEntryManager pathEntryManager = null; public final static String CORE_MODEL_ID = CCorePlugin.PLUGIN_ID + ".coremodel"; //$NON-NLS-1$ @@ -159,14 +161,17 @@ public class CoreModel { } /** - * Creates and returns a new non-exported entry of kind CDT_PROJECT for the project identified by the given - * absolute path. + * Creates and returns a new non-exported entry of kind CDT_PROJECT + * for the project identified by the given absolute path. *

- * A project entry is used to denote a prerequisite project. The ICPathEntry[] entries of the project will be contributed. + * A project entry is used to denote a prerequisite project. The + * IPathEntry[] entries of the project will be contributed. *

- * The prerequisite project is referred to using an absolute path relative to the workspace root. + * The prerequisite project is referred to using an absolute path relative + * to the workspace root. *

- * The resulting entry is not exported to dependent projects. This method is equivalent to newProjectEntry(path,false). + * The resulting entry is not exported to dependent projects. This method + * is equivalent to newProjectEntry(path,false). *

* * @param path @@ -180,16 +185,20 @@ public class CoreModel { } /** - * Creates and returns a new entry of kind CDT_PROJECT for the project identified by the given absolute path. + * Creates and returns a new entry of kind CDT_PROJECT for + * the project identified by the given absolute path. *

- * A project entry is used to denote a prerequisite project. All the ICPathEntries of the project will be contributed as a - * whole. The prerequisite project is referred to using an absolute path relative to the workspace root. + * A project entry is used to denote a prerequisite project. All the + * IPathEntries of the project will be contributed as a whole. The + * prerequisite project is referred to using an absolute path relative to + * the workspace root. *

* * @param path * the absolute path of the prerequisite project * @param isExported - * indicates whether this entry is contributed to dependent projects in addition to the output location + * indicates whether this entry is contributed to dependent + * projects in addition to the output location * @return a new project entry */ public static IProjectEntry newProjectEntry(IPath path, boolean isExported) { @@ -197,10 +206,13 @@ public class CoreModel { } /** - * Creates and returns a new entry of kind CDT_CONTAINER for the given path. The path of the container will be - * used during resolution so as to map this container entry to a set of other entries the container is acting for. + * Creates and returns a new entry of kind CDT_CONTAINER for + * the given path. The path of the container will be used during resolution + * so as to map this container entry to a set of other entries the + * container is acting for. *

- * The resulting entry is not exported to dependent projects. This method is equivalent to newContainerEntry(path,false). + * The resulting entry is not exported to dependent projects. This method + * is equivalent to newContainerEntry(path,false). *

* * @param containerPath @@ -208,87 +220,94 @@ public class CoreModel { * @return a new container entry * */ - public static IContainerEntry newContainerEntry(String id) { + public static IContainerEntry newContainerEntry(IPath id) { return newContainerEntry(id, false); } /** - * Creates and returns a new entry of kind CDT_CONTAINER for the given path. The path of the container will be - * used during resolution so as to map this container entry to a set of other entries the container is acting for. + * Creates and returns a new entry of kind CDT_CONTAINER for + * the given path. The path of the container will be used during resolution + * so as to map this container entry to a set of other entries the + * container is acting for. *

- * The resulting entry is not exported to dependent projects. This method is equivalent to newContainerEntry(path,false). + * The resulting entry is not exported to dependent projects. This method + * is equivalent to newContainerEntry(path,false). *

*/ - public static IContainerEntry newContainerEntry(String id, boolean isExported) { + public static IContainerEntry newContainerEntry(IPath id, boolean isExported) { return new ContainerEntry(id, isExported); } /** - * Creates and returns a new non-exported entry of kind CDT_LIBRARY for the archive or folder identified by the - * given absolute path. + * Creates and returns a new non-exported entry of kind CDT_LIBRARY + * 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. + * Note that this operation does not attempt to validate or access the + * resources at the given paths. *

- * The resulting entry is not exported to dependent projects. This method is equivalent to newLibraryEntry(-,-,-,false). + * The resulting entry is not exported to dependent projects. This method + * is equivalent to newLibraryEntry(-,-,-,false). *

* * @param path * the absolute path of the binary archive * @param sourceAttachmentPath - * the absolute path of the corresponding source archive or folder, or null if none. + * the absolute path of the corresponding source archive or + * folder, or null if none. * @param sourceAttachmentRootPath - * the location of the root within the source archive or folder or null. + * the location of the root within the source archive or folder + * or null. * @param sourceAttachmentPrefixMapping * prefix mapping or null. * @return a new library entry * */ - public static ILibraryEntry newLibraryEntry( - IPath path, - IPath sourceAttachmentPath, - IPath sourceAttachmentRootPath, - IPath sourceAttachmentPrefixMapping) { + public static ILibraryEntry newLibraryEntry(IPath path, IPath sourceAttachmentPath, IPath sourceAttachmentRootPath, + IPath sourceAttachmentPrefixMapping) { return newLibraryEntry(path, sourceAttachmentPath, sourceAttachmentRootPath, sourceAttachmentPrefixMapping, false); } /** - * Creates and returns a new non-exported entry of kind CDT_LIBRARY for the archive or folder identified by the - * given absolute path. + * Creates and returns a new non-exported entry of kind CDT_LIBRARY + * 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. + * Note that this operation does not attempt to validate or access the + * resources at the given paths. *

* * @param path * the absolute path of the binary archive * @param sourceAttachmentPath - * the absolute path of the corresponding source archive or folder, or null if none. + * the absolute path of the corresponding source archive or + * folder, or null if none. * @param sourceAttachmentRootPath - * the location of the root within the source archive or folder or null. + * the location of the root within the source archive or folder + * or null. * @param sourceAttachmentPrefixMapping * prefix mapping or null. * @return a new library entry * */ - public static ILibraryEntry newLibraryEntry( - IPath path, - IPath sourceAttachmentPath, - IPath sourceAttachmentRootPath, - IPath sourceAttachmentPrefixMapping, - boolean isExported) { + public static ILibraryEntry newLibraryEntry(IPath path, IPath sourceAttachmentPath, IPath sourceAttachmentRootPath, + IPath sourceAttachmentPrefixMapping, boolean isExported) { return new LibraryEntry(path, sourceAttachmentPath, sourceAttachmentRootPath, sourceAttachmentPrefixMapping, isExported); } /** - * Creates and returns a new entry of kind CDT_SOURCE for the project's source folder identified by the given - * absolute workspace-relative path. + * Creates and returns a new entry of kind CDT_SOURCE for + * the project's source folder identified by the given absolute + * workspace-relative path. *

- * The source folder is referred to using an absolute path relative to the workspace root, e.g. /Project/src. A - * project's source folders are located with that project. That is, a source entry specifying the path /P1/src - * is only usable for project P1. + * The source folder is referred to using an absolute path relative to the + * workspace root, e.g. /Project/src. A project's source + * folders are located with that project. That is, a source entry + * specifying the path /P1/src is only usable for project + * P1. *

*

*

- * Note that all sources/binaries inside a project are contributed as a whole through a project entry (see newProjectEntry). + * Note that all sources/binaries inside a project are contributed as a + * whole through a project entry (see newProjectEntry). * Particular source entries cannot be selectively exported. *

* @@ -302,19 +321,24 @@ public class CoreModel { } /** - * Creates and returns a new entry of kind CDT_SOURCE for the project's source folder identified by the given - * absolute workspace-relative path but excluding all source files with paths matching any of the given patterns. This - * specifies that all package fragments within the root will have children of type ICompilationUnit. + * Creates and returns a new entry of kind CDT_SOURCE for + * the project's source folder identified by the given absolute + * workspace-relative path but excluding all source files with paths + * matching any of the given patterns. This specifies that all package + * fragments within the root will have children of type ICompilationUnit. *

- * The source folder is referred to using an absolute path relative to the workspace root, e.g. /Project/src. A - * project's source folders are located with that project. That is, a source entry specifying the path /P1/src - * is only usable for project P1. + * The source folder is referred to using an absolute path relative to the + * workspace root, e.g. /Project/src. A project's source + * folders are located with that project. That is, a source entry + * specifying the path /P1/src is only usable for project + * P1. *

* * @param path * the absolute workspace-relative path of a source folder * @param exclusionPatterns - * the possibly empty list of exclusion patterns represented as relative paths + * the possibly empty list of exclusion patterns represented as + * relative paths * @return a new source entry with the given exclusion patterns * */ @@ -323,21 +347,27 @@ public class CoreModel { } /** - * Creates and returns a new entry of kind CDT_SOURCE for the project's source folder identified by the given - * absolute workspace-relative path but excluding all source files with paths matching any of the given patterns. This - * specifies that all package fragments within the root will have children of type ICompilationUnit. + * Creates and returns a new entry of kind CDT_SOURCE for + * the project's source folder identified by the given absolute + * workspace-relative path but excluding all source files with paths + * matching any of the given patterns. This specifies that all package + * fragments within the root will have children of type ICompilationUnit. *

- * The source folder is referred to using an absolute path relative to the workspace root, e.g. /Project/src. A - * project's source folders are located with that project. That is, a source entry specifying the path /P1/src - * is only usable for project P1. + * The source folder is referred to using an absolute path relative to the + * workspace root, e.g. /Project/src. A project's source + * folders are located with that project. That is, a source entry + * specifying the path /P1/src is only usable for project + * P1. *

* * @param path * the absolute workspace-relative path of a source folder * @param exclusionPatterns - * the possibly empty list of exclusion patterns represented as relative paths + * the possibly empty list of exclusion patterns represented as + * relative paths * @param specificOutputLocation - * the specific output location for this source entry (null if using project default ouput location) + * the specific output location for this source entry (null + * if using project default ouput location) * @return a new source entry with the given exclusion patterns */ public static ISourceEntry newSourceEntry(IPath path, IPath outputLocation, IPath[] exclusionPatterns) { @@ -345,21 +375,27 @@ public class CoreModel { } /** - * Creates and returns a new entry of kind CDT_SOURCE for the project's source folder identified by the given - * absolute workspace-relative path but excluding all source files with paths matching any of the given patterns. This - * specifies that all package fragments within the root will have children of type ICompilationUnit. + * Creates and returns a new entry of kind CDT_SOURCE for + * the project's source folder identified by the given absolute + * workspace-relative path but excluding all source files with paths + * matching any of the given patterns. This specifies that all package + * fragments within the root will have children of type ICompilationUnit. *

- * The source folder is referred to using an absolute path relative to the workspace root, e.g. /Project/src. A - * project's source folders are located with that project. That is, a source entry specifying the path /P1/src - * is only usable for project P1. + * The source folder is referred to using an absolute path relative to the + * workspace root, e.g. /Project/src. A project's source + * folders are located with that project. That is, a source entry + * specifying the path /P1/src is only usable for project + * P1. *

* * @param path * the absolute workspace-relative path of a source folder * @param exclusionPatterns - * the possibly empty list of exclusion patterns represented as relative paths + * the possibly empty list of exclusion patterns represented as + * relative paths * @param specificOutputLocation - * the specific output location for this source entry (null if using project default ouput location) + * the specific output location for this source entry (null + * if using project default ouput location) * @return a new source entry with the given exclusion patterns */ public static ISourceEntry newSourceEntry(IPath path, IPath outputLocation, boolean isRecursive, IPath[] exclusionPatterns) { @@ -370,10 +406,11 @@ public class CoreModel { * Creates and returns a new entry of kind CDT_INCLUDE * * @param path - * the affected worksapce-relative resource path + * the affected worksapce-relative resource path, the path + * can pe empty or null if it is exported * @param includePath * the absolute path of the include - * @return + * @return IIncludeEntry */ public static IIncludeEntry newIncludeEntry(IPath path, IPath includePath) { return newIncludeEntry(path, includePath, false); @@ -383,42 +420,39 @@ public class CoreModel { * Creates and returns a new entry of kind CDT_INCLUDE * * @param path - * the affected workspace-relative resource path + * the affected workspace-relative resource path + * or the path can be empty or null if it is exported * @param includePath * the absolute path of the include * @param isSystemInclude - * wheter this include path should be consider the system include path - * @return + * wheter this include path should be consider the system + * include path + * @return IIncludeEntry */ public static IIncludeEntry newIncludeEntry(IPath path, IPath includePath, boolean isSystemInclude) { - return newIncludeEntry(path, includePath, isSystemInclude, true, IncludeEntry.NO_EXCLUSION_PATTERNS, true); + return newIncludeEntry(path, includePath, isSystemInclude, true, IncludeEntry.NO_EXCLUSION_PATTERNS); } /** * Creates and returns a new entry of kind CDT_INCLUDE * * @param path - * the affected workspace-relative resource path + * the affected workspace-relative resource path or null if global * @param includePath * the absolute path of the include * @param isSystemInclude - * wheter this include path should be consider the system include path + * wheter this include path should be consider the system + * include path * @param isRecursive - * if the resource is a folder the include applied to all recursively + * if the resource is a folder the include applied to all + * recursively * @param exclusionPatterns * exclusion patterns in the resource if a container - * @param isExported - * whether this cpath is exported. - * @return + * @return IIincludeEntry */ - public static IIncludeEntry newIncludeEntry( - IPath path, - IPath includePath, - boolean isSystemInclude, - boolean isRecursive, - IPath[] exclusionPatterns, - boolean isExported) { - return new IncludeEntry(path, includePath, isSystemInclude, isRecursive, exclusionPatterns, isExported); + public static IIncludeEntry newIncludeEntry(IPath path, IPath includePath, boolean isSystemInclude, boolean isRecursive, + IPath[] exclusionPatterns) { + return new IncludeEntry(path, includePath, isSystemInclude, isRecursive, exclusionPatterns); } /** @@ -446,38 +480,172 @@ public class CoreModel { * @param macroValue * the value of the macro * @param isRecursive - * if the resource is a folder the include applied to all recursively + * if the resource is a folder the include applied to all + * recursively * @param exclusionPatterns * exclusion patterns in the resource if a container * @param isExported * whether this cpath is exported. * @return */ - public static IMacroEntry newMacroEntry( - IPath path, - String macroName, - String macroValue, - boolean isRecursive, - IPath[] exclusionPatterns, - boolean isExported) { + public static IMacroEntry newMacroEntry(IPath path, String macroName, String macroValue, boolean isRecursive, + IPath[] exclusionPatterns, boolean isExported) { return new MacroEntry(path, macroName, macroValue, isRecursive, exclusionPatterns, isExported); } - public ICPathContainer getCPathContainer(IPath containerPath, ICProject project) throws CModelException { - return manager.getCPathContainer(containerPath, project); - } - - public void setCPathContainer( - IPath containerPath, - ICProject[] affectedProjects, - ICPathContainer[] respectiveContainers, - IProgressMonitor monitor) - throws CModelException { - manager.setCPatchContainer(containerPath, affectedProjects, respectiveContainers, monitor); + /** + * Answers the project specific value for a given container. In case this + * container path could not be resolved, then will answer null. + * Both the container path and the project context are supposed to be + * non-null. + *

+ * The containerPath is a formed by a first ID segment followed with extra + * segments, which can be used as additional hints for resolution. If no + * container was ever recorded for this container path onto this project + * (using setPathEntryContainer, then a PathEntryContainerInitializer + * will be activated if any was registered for this container ID onto the + * extension point "org.eclipse.cdt.core.PathEntryContainerInitializer". + *

+ * PathEntry container values are persisted locally to the workspace, but + * are not preserved from a session to another. It is thus highly + * recommended to register a PathEntryContainerInitializer + * for each referenced container (through the extension point + * "org.eclipse.cdt.core.PathEntryContainerInitializer"). + *

+ * + * @param containerPath + * the name of the container, which needs to be resolved + * @param project + * a specific project in which the container is being resolved + * @return the corresponding container or null if unable to + * find one. + * + * @exception CModelException + * if an exception occurred while resolving the container, + * or if the resolved container contains illegal entries + * (contains CDT_CONTAINER entries or null entries). + * + * @see PathEntryContainerInitializer + * @see IPathEntryContainer + * @see #setPathEntryContainer(IPath, ICProject[], IPathEntryContainer, + * IProgressMonitor) + */ + public IPathEntryContainer getPathEntryContainer(IPath containerPath, ICProject project) throws CModelException { + return pathEntryManager.getPathEntryContainer(containerPath, project); } /** - * TODO: this is a temporary hack until, the CDescriptor manager is in place and could fire deltas of Parser change. + * Bind a container reference path to some actual containers (IPathEntryContainer). + * This API must be invoked whenever changes in container need to be + * reflected onto the CModel. + *

+ * In reaction to changing container values, the CModel will be updated to + * reflect the new state of the updated container. + *

+ * This functionality cannot be used while the resource tree is locked. + *

+ * PathEntry container values are persisted locally to the workspace, but + * are not preserved from a session to another. It is thus highly + * recommended to register a PathEntryContainerInitializer + * for each referenced container (through the extension point + * "org.eclipse.cdt.core.PathEntryContainerInitializer"). + *

+ * Note: setting a container to null will cause it to be + * lazily resolved again whenever its value is required. In particular, + * this will cause a registered initializer to be invoked again. + *

+ * + * @param affectedProjects - + * the set of projects for which this container is being bound + * @param newContainer - + * the container for the affected projects + * @param monitor + * a monitor to report progress + * @throws CModelException + * @see PathEntryContainerInitializer + * @see #getPathEntryContainer(IPath, IJavaProject) + * @see IPathEntryContainer + */ + public void setPathEntryContainer(ICProject[] affectedProjects, IPathEntryContainer container, IProgressMonitor monitor) + throws CModelException { + pathEntryManager.setPathEntryContainer(affectedProjects, container, monitor); + } + + /** + * Sets the pathentries of this project using a list of entries. + *

+ * Setting the pathentries to null specifies a default + * classpath (the project root). Setting the pathentry to an empty array + * specifies an empty pathentry. + *

+ * + * @param entries + * a list of entries + * @param monitor + * the given progress monitor + * @exception CModelException + * if the entries could not be set. Reasons include: + */ + public void setRawPathEntries(ICProject cproject, IPathEntry[] newEntries, IProgressMonitor monitor) throws CModelException { + pathEntryManager.setRawPathEntries(cproject, newEntries, monitor); + } + + /** + * Returns the raw pathentries for the project. This corresponds to the + * exact set of entries which were assigned using setRawPathEntries + *

+ * + * @return the raw entires for the project + * @exception CModelException + * if this element does not exist or if an exception occurs + * while accessing its corresponding resource + * @see IPathEntry + */ + public IPathEntry[] getRawPathEntries(ICProject cproject) throws CModelException { + return pathEntryManager.getRawPathEntries(cproject); + } + + /** + * This method returs the resolved pathentries for the project All + * pathEntry.CDT_CONTAINER entries in the project's will be replaced by the + * entries they resolve to. + *

+ * The resulting resolved entries are accurate for the given point in time. + * If the project's raw entries are later modified they can become out of + * date. Because of this, hanging on resolved pathentries is not + * recommended. + *

+ * + * @return the resolved entries for the project + * @exception CModelException + * @see IPathEntry + */ + public IPathEntry[] getResolvedClasspathEntries(ICProject cproject) throws CModelException { + return pathEntryManager.getRawPathEntries(cproject); + } + + /** + * Helper method finding the pathentry container initializer registered for + * a given container ID or null if none was found while + * iterating over the contributions to extension point to the extension + * point "org.eclipse.cdt.core.PathEntryContainerInitializer". + *

+ * A containerID is the first segment of any container path, used to + * identify the registered container initializer. + *

+ * + * @param containerID - + * a containerID identifying a registered initializer + * @return ClasspathContainerInitializer - the registered classpath + * container initializer or null if none was found. + */ + public static PathEntryContainerInitializer getPathEntryContainerInitializer(String containerID) { + return pathEntryManager.getPathEntryContainerInitializer(containerID); + } + + /** + * TODO: this is a temporary hack until, the CDescriptor manager is in + * place and could fire deltas of Parser change. * * @deprecated this function will be removed shortly. */ @@ -492,6 +660,7 @@ public class CoreModel { if (cmodel == null) { cmodel = new CoreModel(); manager = CModelManager.getDefault(); + pathEntryManager = PathEntryManager.getDefault(); } return cmodel; } @@ -501,7 +670,8 @@ public class CoreModel { } /** - * Removes the given element changed listener. Has no affect if an identical listener is not registered. + * Removes the given element changed listener. Has no affect if an + * identical listener is not registered. * * @param listener * the listener @@ -529,7 +699,8 @@ public class CoreModel { if (workspace.isTreeLocked()) { new BatchOperation(action).run(monitor); } else { - // use IWorkspace.run(...) to ensure that a build will be done in autobuild mode + // use IWorkspace.run(...) to ensure that a build will be done in + // autobuild mode workspace.run(new BatchOperation(action), monitor); } } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICPathContainer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICPathContainer.java deleted file mode 100644 index cbac1dd2c20..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICPathContainer.java +++ /dev/null @@ -1,30 +0,0 @@ -/********************************************************************** - * Created on Mar 25, 2003 - * - * Copyright (c) 2002,2003 QNX Software Systems Ltd. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * QNX Software Systems - Initial API and implementation -***********************************************************************/ - -package org.eclipse.cdt.core.model; - -/** - * @author alain - */ -public interface ICPathContainer { - - ICPathEntry[] getCPathEntries(); - - /** - * Answers a readable description of this container - * - * @return String - a string description of the container - */ - String getDescription(); - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICProject.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICProject.java index 32fb5e79942..f43af7f969b 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICProject.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICProject.java @@ -131,7 +131,7 @@ public interface ICProject extends ICContainer { * @exception CModelException if this element does not exist or if an * exception occurs while accessing its corresponding resource */ - ICPathEntry[] getResolvedCPathEntries() throws CModelException; + IPathEntry[] getResolvedPathEntries() throws CModelException; /** * Returns the list of entries for the project. This corresponds to the exact set @@ -142,12 +142,12 @@ public interface ICProject extends ICContainer { * @exception CModelException if this element does not exist or if an * exception occurs while accessing its corresponding resource */ - ICPathEntry[] getRawCPathEntries() throws CModelException; + IPathEntry[] getRawPathEntries() throws CModelException; /** * Sets the entries for this project. * - * @param entries a list of ICPathEntry[] entries + * @param entries a list of IPathEntry[] entries * @param monitor the given progress monitor * @exception CModelException if the entries could not be set. Reasons include: *

*/ - void setRawCPathEntries(ICPathEntry[] entries, IProgressMonitor monitor) throws CModelException; + void setRawPathEntries(IPathEntry[] entries, IProgressMonitor monitor) throws CModelException; } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IContainerEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IContainerEntry.java index 08d88fd0da8..60a68ca0121 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IContainerEntry.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IContainerEntry.java @@ -12,12 +12,14 @@ ***********************************************************************/ package org.eclipse.cdt.core.model; -public interface IContainerEntry extends ICPathEntry { +import org.eclipse.core.runtime.IPath; + +public interface IContainerEntry extends IPathEntry { /** * Returns the id identifying this container. - * @return String + * @return IPath */ - String getId(); + IPath getPath(); } 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 029bc6a0b51..8feec25a55c 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 @@ -14,7 +14,7 @@ package org.eclipse.cdt.core.model; import org.eclipse.core.runtime.IPath; -public interface IIncludeEntry extends ICPathEntry { +public interface IIncludeEntry extends IPathEntry { /** * Returns the affected resource by the include. diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ILibraryEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ILibraryEntry.java index 70fd16522e9..9fd58e9f8fd 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ILibraryEntry.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ILibraryEntry.java @@ -14,7 +14,7 @@ package org.eclipse.cdt.core.model; import org.eclipse.core.runtime.IPath; -public interface ILibraryEntry extends ICPathEntry { +public interface ILibraryEntry extends IPathEntry { /** * Returns the absolute path of the library diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IMacroEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IMacroEntry.java index 09fe86024da..ccb51cbd105 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IMacroEntry.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IMacroEntry.java @@ -14,7 +14,7 @@ package org.eclipse.cdt.core.model; import org.eclipse.core.runtime.IPath; -public interface IMacroEntry extends ICPathEntry { +public interface IMacroEntry extends IPathEntry { /** * Returns the absolute path from the worskspace root or diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICPathEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IPathEntry.java similarity index 98% rename from core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICPathEntry.java rename to core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IPathEntry.java index 2a0562a8c8a..09fb6a41eef 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICPathEntry.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IPathEntry.java @@ -13,7 +13,7 @@ package org.eclipse.cdt.core.model; -public interface ICPathEntry { +public interface IPathEntry { /** * Entry kind constant describing a path entry identifying a diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IPathEntryContainer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IPathEntryContainer.java new file mode 100644 index 00000000000..d8fbd8820c6 --- /dev/null +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IPathEntryContainer.java @@ -0,0 +1,60 @@ +/********************************************************************** + * Created on Mar 25, 2003 + * + * Copyright (c) 2002,2003 QNX Software Systems Ltd. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation +***********************************************************************/ + +package org.eclipse.cdt.core.model; + +import org.eclipse.core.runtime.IPath; + +/** + * @author alain + */ +public interface IPathEntryContainer { + + /** + * Answers the set of path entries this container is mapping to. + *

+ * The set of entries associated with a container may contain any of the following: + *

+ * A container can neither reference further containers. + * + * @return IPathEntry[] - the entries this container represents + * @see IPathEntry + */ + IPathEntry[] getPathEntries(); + + /** + * Answers a readable description of this container + * + * @return String - a string description of the container + */ + String getDescription(); + + /** + * Answers the container path identifying this container. + * A container path is formed by a first ID segment followed with extra segments, which + * can be used as additional hints for resolving to this container. + *

+ * The container ID is also used to identify aClasspathContainerInitializer + * registered on the extension point "org.eclipse.jdt.core.classpathContainerInitializer", which can + * be invoked if needing to resolve the container before it is explicitly set. + *

+ * @return IPath - the container path that is associated with this container + */ + IPath getPath(); + +} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IProjectEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IProjectEntry.java index 8f71cc8460b..ed859938234 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IProjectEntry.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IProjectEntry.java @@ -15,7 +15,7 @@ package org.eclipse.cdt.core.model; import org.eclipse.core.runtime.IPath; -public interface IProjectEntry extends ICPathEntry { +public interface IProjectEntry extends IPathEntry { /** * Returns the absolute path relative to the workspace root. diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ISourceEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ISourceEntry.java index 8c8ba72a824..05202e4c076 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ISourceEntry.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ISourceEntry.java @@ -14,7 +14,7 @@ package org.eclipse.cdt.core.model; import org.eclipse.core.runtime.IPath; -public interface ISourceEntry extends ICPathEntry { +public interface ISourceEntry extends IPathEntry { /** * Returns the absolute path from the worskspace root or diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CPathContainerInitializer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/PathEntryContainerInitializer.java similarity index 91% rename from core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CPathContainerInitializer.java rename to core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/PathEntryContainerInitializer.java index ea6c7d434a7..8c70268070d 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CPathContainerInitializer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/PathEntryContainerInitializer.java @@ -18,12 +18,12 @@ import org.eclipse.core.runtime.IPath; /** */ -public abstract class CPathContainerInitializer { +public abstract class PathEntryContainerInitializer { /** * Creates a new cpath container initializer. */ - public CPathContainerInitializer() { + public PathEntryContainerInitializer() { } public abstract void initialize(IPath containerPath, ICProject project) throws CoreException; diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ACPathEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/APathEntry.java similarity index 89% rename from core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ACPathEntry.java rename to core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/APathEntry.java index dffe125b56b..94ca47f4732 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ACPathEntry.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/APathEntry.java @@ -14,13 +14,13 @@ package org.eclipse.cdt.internal.core.model; import org.eclipse.core.runtime.IPath; -public abstract class ACPathEntry extends CPathEntry { +public abstract class APathEntry extends PathEntry { public static IPath[] NO_EXCLUSION_PATTERNS = {}; IPath[] exclusionPatterns; boolean isRecursive; - public ACPathEntry (int kind, boolean isRecursive, IPath[] exclusionPatterns, boolean isExported) { + public APathEntry (int kind, boolean isRecursive, IPath[] exclusionPatterns, boolean isExported) { super(kind, isExported); this.exclusionPatterns = exclusionPatterns; this.isRecursive = isRecursive; @@ -43,8 +43,8 @@ public abstract class ACPathEntry extends CPathEntry { } public boolean equals(Object obj) { - if (obj instanceof ACPathEntry) { - ACPathEntry otherEntry = (ACPathEntry)obj; + if (obj instanceof APathEntry) { + APathEntry otherEntry = (APathEntry)obj; if (!super.equals(otherEntry)) { return false; } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java index 51f175fe303..288dde158bb 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java @@ -27,7 +27,6 @@ import org.eclipse.cdt.core.model.ICContainer; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElementDelta; import org.eclipse.cdt.core.model.ICModel; -import org.eclipse.cdt.core.model.ICPathContainer; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.IElementChangedListener; import org.eclipse.cdt.core.model.IParent; @@ -50,12 +49,12 @@ import org.eclipse.core.runtime.IProgressMonitor; public class CModelManager implements IResourceChangeListener { - /** - * Unique handle onto the CModel - */ - final CModel cModel = new CModel(); + /** + * Unique handle onto the CModel + */ + final CModel cModel = new CModel(); - public static HashSet OptionNames = new HashSet(20); + public static HashSet OptionNames = new HashSet(20); /** * Used to convert IResourceDeltas into ICElementDeltas. @@ -112,10 +111,11 @@ public class CModelManager implements IResourceChangeListener { */ private HashMap sourceMappers = new HashMap(); + // TODO: This should be in a preference/property page public static final String [] sourceExtensions = {"c", "cxx", "cc", "C", "cpp"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ - public static final String [] headerExtensions = {"h", "hh", "hpp", "H"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - + public static final String [] assemblyExtensions = {"s", "S"}; //$NON-NLS-1$ //$NON-NLS-2$ + public static final IWorkingCopy[] NoWorkingCopy = new IWorkingCopy[0]; static CModelManager factory = null; @@ -447,61 +447,53 @@ public class CModelManager implements IResourceChangeListener { } public boolean isSharedLib(IFile file) { - try { - IBinaryParser parser = getBinaryParser(file.getProject()); - IBinaryFile bin = parser.getBinary(file.getLocation()); - return (bin.getType() == IBinaryFile.SHARED); - } catch (IOException e) { + ICElement celement = create(file); + if (celement instanceof IBinary) { + return ((IBinary)celement).isSharedLib(); } return false; } public boolean isObject(IFile file) { - try { - IBinaryParser parser = getBinaryParser(file.getProject()); - IBinaryFile bin = parser.getBinary(file.getLocation()); - return (bin.getType() == IBinaryFile.OBJECT); - } catch (IOException e) { + ICElement celement = create(file); + if (celement instanceof IBinary) { + return ((IBinary)celement).isObject(); } return false; } public boolean isExecutable(IFile file) { - try { - IBinaryParser parser = getBinaryParser(file.getProject()); - IBinaryFile bin = parser.getBinary(file.getLocation()); - return (bin.getType() == IBinaryFile.EXECUTABLE); - } catch (IOException e) { - //e.printStackTrace(); + ICElement celement = create(file); + if (celement instanceof IBinary) { + return ((IBinary)celement).isExecutable(); } return false; } public boolean isBinary(IFile file) { - try { - IBinaryParser parser = getBinaryParser(file.getProject()); - IBinaryFile bin = parser.getBinary(file.getLocation()); - return (bin.getType() == IBinaryFile.EXECUTABLE - || bin.getType() == IBinaryFile.OBJECT - || bin.getType() == IBinaryFile.SHARED - || bin.getType() == IBinaryFile.CORE); - } catch (IOException e) { - } - return false; + ICElement celement = create(file); + return (celement instanceof IBinary); } public boolean isArchive(IFile file) { - try { - IBinaryParser parser = getBinaryParser(file.getProject()); - IBinaryFile bin = parser.getBinary(file.getLocation()); - return (bin.getType() == IBinaryFile.ARCHIVE); - } catch (IOException e) { - } - return false; + ICElement celement = create(file); + return(celement instanceof IArchive); } public boolean isTranslationUnit(IFile file) { - return isValidTranslationUnitName(file.getName()); + return file != null && isValidTranslationUnitName(file.getName()); + } + + public boolean isSourceUnit(IFile file) { + return file != null && isValidSourceUnitName(file.getName()); + } + + public boolean isHeaderUnit(IFile file) { + return file != null && isValidHeaderUnitName(file.getName()); + } + + public boolean isAssemblyUnit(IFile file) { + return file != null && isValidAssemblyUnitName(file.getName()); } public boolean isValidTranslationUnitName(String name){ @@ -513,7 +505,7 @@ public class CModelManager implements IResourceChangeListener { return false; } String ext = name.substring(index + 1); - String[] cexts = getTranslationUnitExtensions(); + String[] cexts = getHeaderExtensions(); for (int i = 0; i < cexts.length; i++) { if (ext.equals(cexts[i])) return true; @@ -521,6 +513,57 @@ public class CModelManager implements IResourceChangeListener { return false; } + public boolean isValidSourceUnitName(String name){ + if (name == null) { + return false; + } + int index = name.lastIndexOf('.'); + if (index == -1) { + return false; + } + String ext = name.substring(index + 1); + String[] cexts = getSourceExtensions(); + for (int i = 0; i < cexts.length; i++) { + if (ext.equals(cexts[i])) + return true; + } + return false; + } + + public boolean isValidHeaderUnitName(String name){ + if (name == null) { + return false; + } + int index = name.lastIndexOf('.'); + if (index == -1) { + return false; + } + String ext = name.substring(index + 1); + String[] cexts = getHeaderExtensions(); + for (int i = 0; i < cexts.length; i++) { + if (ext.equals(cexts[i])) + return true; + } + return false; + } + + public boolean isValidAssemblyUnitName(String name){ + if (name == null) { + return false; + } + int index = name.lastIndexOf('.'); + if (index == -1) { + return false; + } + String ext = name.substring(index + 1); + String[] cexts = getAssemblyExtensions(); + for (int i = 0; i < cexts.length; i++) { + if (ext.equals(cexts[i])) + return true; + } + return false; + } + public String[] getHeaderExtensions() { return headerExtensions; } @@ -529,12 +572,18 @@ public class CModelManager implements IResourceChangeListener { return sourceExtensions; } + public String[] getAssemblyExtensions() { + return assemblyExtensions; + } + public String[] getTranslationUnitExtensions() { - String[] headers = getHeaderExtensions(); String[] sources = getSourceExtensions(); - String[] cexts = new String[headers.length + sources.length]; + String[] headers = getHeaderExtensions(); + String[] asm = getAssemblyExtensions(); + String[] cexts = new String[headers.length + sources.length + asm.length]; System.arraycopy(sources, 0, cexts, 0, sources.length); System.arraycopy(headers, 0, cexts, sources.length, headers.length); + System.arraycopy(asm, 0, cexts, sources.length + headers.length, asm.length); return cexts; } @@ -886,25 +935,4 @@ public class CModelManager implements IResourceChangeListener { this.getIndexManager().discardJobs(project.getName()); } - /** - * @param containerPath - * @param project - * @return - */ - public ICPathContainer getCPathContainer(IPath containerPath, ICProject project) { - // TODO Auto-generated method stub - return null; - } - - /** - * @param containerPath - * @param affectedProjects - * @param respectiveContainers - * @param monitor - * @return - */ - public Object setCPatchContainer(IPath containerPath, ICProject[] affectedProjects, ICPathContainer[] respectiveContainers, IProgressMonitor monitor) { - // TODO Auto-generated method stub - return null; - } } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProject.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProject.java index e4622607d26..c252d61eeb4 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProject.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProject.java @@ -15,7 +15,6 @@ import java.util.Map; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CProjectNature; import org.eclipse.cdt.core.IBinaryParser; -import org.eclipse.cdt.core.ICDescriptor; import org.eclipse.cdt.core.IBinaryParser.IBinaryArchive; import org.eclipse.cdt.core.IBinaryParser.IBinaryFile; import org.eclipse.cdt.core.model.CModelException; @@ -23,37 +22,20 @@ import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.IArchiveContainer; import org.eclipse.cdt.core.model.IBinaryContainer; import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.ICModelStatus; import org.eclipse.cdt.core.model.ICModelStatusConstants; -import org.eclipse.cdt.core.model.ICPathEntry; import org.eclipse.cdt.core.model.ICProject; -import org.eclipse.cdt.core.model.IContainerEntry; -import org.eclipse.cdt.core.model.IIncludeEntry; import org.eclipse.cdt.core.model.ILibraryEntry; import org.eclipse.cdt.core.model.ILibraryReference; -import org.eclipse.cdt.core.model.IMacroEntry; -import org.eclipse.cdt.core.model.IProjectEntry; -import org.eclipse.cdt.core.model.ISourceEntry; -import org.eclipse.cdt.internal.core.CharOperation; +import org.eclipse.cdt.core.model.IPathEntry; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Preferences; import org.eclipse.core.runtime.QualifiedName; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; public class CProject extends CContainer implements ICProject { - /** - * An empty array of strings indicating that a project doesn't have any prerequesite projects. - */ - protected static final String[] NO_PREREQUISITES = new String[0]; - public CProject(ICElement parent, IProject project) { super(parent, project, CElement.C_PROJECT); } @@ -115,9 +97,9 @@ public class CProject extends CContainer implements ICProject { binParser = CCorePlugin.getDefault().getBinaryParser(getProject()); } catch (CoreException e) { } - ICPathEntry[] entries = getResolvedCPathEntries(); + IPathEntry[] entries = getResolvedPathEntries(); for (int i = 0; i < entries.length; i++) { - if (entries[i].getEntryKind() == ICPathEntry.CDT_LIBRARY) { + if (entries[i].getEntryKind() == IPathEntry.CDT_LIBRARY) { ILibraryEntry entry = (ILibraryEntry) entries[i]; ILibraryReference lib = null; if (binParser != null) { @@ -145,28 +127,14 @@ public class CProject extends CContainer implements ICProject { * @see ICProject#getRequiredProjectNames() */ public String[] getRequiredProjectNames() throws CModelException { - return projectPrerequisites(getResolvedCPathEntries()); + return projectPrerequisites(getResolvedPathEntries()); } - public String[] projectPrerequisites(ICPathEntry[] entries) throws CModelException { - ArrayList prerequisites = new ArrayList(); - for (int i = 0, length = entries.length; i < length; i++) { - if (entries[i].getEntryKind() == ICPathEntry.CDT_PROJECT) { - IProjectEntry entry = (IProjectEntry)entries[i]; - prerequisites.add(entry.getProjectPath().lastSegment()); - } - } - int size = prerequisites.size(); - if (size != 0) { - String[] result = new String[size]; - prerequisites.toArray(result); - return result; - } - return NO_PREREQUISITES; + public String[] projectPrerequisites(IPathEntry[] entries) throws CModelException { + return PathEntryManager.getDefault().projectPrerequisites(entries); } - /** * @see org.eclipse.cdt.core.model.ICProject#getOption(String, boolean) */ @@ -316,264 +284,25 @@ public class CProject extends CContainer implements ICProject { // Do nothing } - - static String PATH_ENTRY = "cpathentry"; //$NON-NLS-1$ - static String PATH_ENTRY_ID = "org.eclipse.cdt.core.cpathentry"; //$NON-NLS-1$ - static String ATTRIBUTE_KIND = "kind"; //$NON-NLS-1$ - static String ATTRIBUTE_PATH = "path"; //$NON-NLS-1$ - static String ATTRIBUTE_EXPORTED = "exported"; //$NON-NLS-1$ - static String ATTRIBUTE_SOURCEPATH = "sourcepath"; //$NON-NLS-1$ - static String ATTRIBUTE_ROOTPATH = "roopath"; //$NON-NLS-1$ - static String ATTRIBUTE_PREFIXMAPPING = "prefixmapping"; //$NON-NLS-1$ - static String ATTRIBUTE_EXCLUDING = "excluding"; //$NON-NLS-1$ - static String ATTRIBUTE_RECUSIVE = "recusive"; //$NON-NLS-1$ - static String ATTRIBUTE_OUTPUT = "output"; //$NON-NLS-1$ - static String ATTRIBUTE_INCLUDE = "include"; //$NON-NLS-1$ - static String ATTRIBUTE_SYSTEM = "system"; //$NON-NLS-1$ - static String ATTRIBUTE_NAME = "name"; //$NON-NLS-1$ - static String ATTRIBUTE_VALUE = "value"; //$NON-NLS-1$ - static String ATTRIBUTE_ID = "id"; //$NON-NLS-1$ - static String VALUE_TRUE = "true"; //$NON-NLS-1$ - /* (non-Javadoc) * @see org.eclipse.cdt.core.model.ICProject#getResolvedCPathEntries() */ - public ICPathEntry[] getResolvedCPathEntries() throws CModelException { - // Not implemented - return getRawCPathEntries(); + public IPathEntry[] getResolvedPathEntries() throws CModelException { + return CoreModel.getDefault().getResolvedClasspathEntries(this); } /* (non-Javadoc) * @see org.eclipse.cdt.core.model.ICProject#getRawCPathEntries() */ - public ICPathEntry[] getRawCPathEntries() throws CModelException { - ArrayList pathEntries = new ArrayList(); - try { - ICDescriptor cdesc = CCorePlugin.getDefault().getCProjectDescription(getProject()); - Element element = cdesc.getProjectData(PATH_ENTRY_ID); - NodeList list = element.getChildNodes(); - for (int i = 0; i < list.getLength(); i++) { - Node childNode = list.item(i); - if (childNode.getNodeType() == Node.ELEMENT_NODE) { - if (childNode.getNodeName().equals(PATH_ENTRY)) { - pathEntries.add(decodeCPathEntry((Element) childNode)); - } - } - } - } catch (CoreException e) { - throw new CModelException(e); - } - return (ICPathEntry[]) pathEntries.toArray(new ICPathEntry[0]); + public IPathEntry[] getRawPathEntries() throws CModelException { + return CoreModel.getDefault().getRawPathEntries(this); } /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ICProject#setRawCPathEntries(org.eclipse.cdt.core.model.ICPathEntry[], org.eclipse.core.runtime.IProgressMonitor) + * @see org.eclipse.cdt.core.model.ICProject#setRawCPathEntries(org.eclipse.cdt.core.model.IPathEntry[], org.eclipse.core.runtime.IProgressMonitor) */ - public void setRawCPathEntries(ICPathEntry[] newEntries, IProgressMonitor monitor) throws CModelException { - try { - SetCPathEntriesOperation op = new SetCPathEntriesOperation(this, getRawCPathEntries(), newEntries); - runOperation(op, monitor); - } catch (CoreException e) { - throw new CModelException(e); - } - + public void setRawPathEntries(IPathEntry[] newEntries, IProgressMonitor monitor) throws CModelException { + CoreModel.getDefault().setRawPathEntries(this, newEntries, monitor); } - ICPathEntry decodeCPathEntry(Element element) throws CModelException { - IPath projectPath = getProject().getFullPath(); - - // kind - String kindAttr = element.getAttribute(ATTRIBUTE_KIND); - int kind = CPathEntry.kindFromString(kindAttr); - - // exported flag - boolean isExported = false; - if (element.hasAttribute(ATTRIBUTE_EXPORTED)) { - isExported = element.getAttribute(ATTRIBUTE_EXPORTED).equals(VALUE_TRUE); - } - - // ensure path is absolute - String pathAttr = element.getAttribute(ATTRIBUTE_PATH); - IPath path = new Path(pathAttr); - if (kind != ICPathEntry.CDT_VARIABLE && !path.isAbsolute()) { - path = projectPath.append(path); - } - - // source attachment info (optional) - IPath sourceAttachmentPath = - element.hasAttribute(ATTRIBUTE_SOURCEPATH) ? new Path(element.getAttribute(ATTRIBUTE_SOURCEPATH)) : null; - IPath sourceAttachmentRootPath = - element.hasAttribute(ATTRIBUTE_ROOTPATH) ? new Path(element.getAttribute(ATTRIBUTE_ROOTPATH)) : null; - IPath sourceAttachmentPrefixMapping = - element.hasAttribute(ATTRIBUTE_PREFIXMAPPING) ? new Path(element.getAttribute(ATTRIBUTE_PREFIXMAPPING)) : null; - - // exclusion patterns (optional) - String exclusion = element.getAttribute(ATTRIBUTE_EXCLUDING); - IPath[] exclusionPatterns = ACPathEntry.NO_EXCLUSION_PATTERNS; - if (!exclusion.equals("")) { //$NON-NLS-1$ - char[][] patterns = CharOperation.splitOn('|', exclusion.toCharArray()); - int patternCount; - if ((patternCount = patterns.length) > 0) { - exclusionPatterns = new IPath[patternCount]; - for (int j = 0; j < patterns.length; j++) { - exclusionPatterns[j] = new Path(new String(patterns[j])); - } - } - } - - boolean isRecursive = false; - if (element.hasAttribute(ATTRIBUTE_RECUSIVE)) { - isRecursive = element.getAttribute(ATTRIBUTE_RECUSIVE).equals(VALUE_TRUE); - } - - // recreate the CP entry - - switch (kind) { - - case ICPathEntry.CDT_PROJECT : - return CoreModel.newProjectEntry(path, isExported); - - case ICPathEntry.CDT_LIBRARY : - return CoreModel.newLibraryEntry( - path, - sourceAttachmentPath, - sourceAttachmentRootPath, - sourceAttachmentPrefixMapping, - isExported); - - case ICPathEntry.CDT_SOURCE : - { - // custom output location - IPath outputLocation = element.hasAttribute(ATTRIBUTE_OUTPUT) ? projectPath.append(element.getAttribute(ATTRIBUTE_OUTPUT)) : null; //$NON-NLS-1$ //$NON-NLS-2$ - // must be an entry in this project or specify another project - String projSegment = path.segment(0); - if (projSegment != null && projSegment.equals(getElementName())) { // this project - return CoreModel.newSourceEntry(path, outputLocation, isRecursive, exclusionPatterns); - } else { // another project - return CoreModel.newProjectEntry(path, isExported); - } - } - - // case ICPathEntry.CDT_VARIABLE : - // return CoreModel.newVariableEntry(path, sourceAttachmentPath, sourceAttachmentRootPath); - - case ICPathEntry.CDT_INCLUDE : - { - // include path info (optional - IPath includePath = - element.hasAttribute(ATTRIBUTE_INCLUDE) ? new Path(element.getAttribute(ATTRIBUTE_INCLUDE)) : null; - // isSysteminclude - boolean isSystemInclude = false; - if (element.hasAttribute(ATTRIBUTE_SYSTEM)) { - isSystemInclude = element.getAttribute(ATTRIBUTE_SYSTEM).equals(VALUE_TRUE); - } - return CoreModel.newIncludeEntry( - path, - includePath, - isSystemInclude, - isRecursive, - exclusionPatterns, - isExported); - } - - case ICPathEntry.CDT_MACRO : - { - String macroName = element.getAttribute(ATTRIBUTE_NAME); //$NON-NLS-1$ - String macroValue = element.getAttribute(ATTRIBUTE_VALUE); //$NON-NLS-1$ - return CoreModel.newMacroEntry(path, macroName, macroValue, isRecursive, exclusionPatterns, isExported); - } - - case ICPathEntry.CDT_CONTAINER : - { - String id = element.getAttribute(ATTRIBUTE_ID); //$NON-NLS-1$ - return CoreModel.newContainerEntry(id, isExported); - } - - default : - { - ICModelStatus status = new CModelStatus(ICModelStatus.ERROR, "CPathEntry: unknown kind (" + kindAttr + ")"); //$NON-NLS-1$ //$NON-NLS-2$ - throw new CModelException(status); - } - } - } - - void encodeCPathEntries(Document doc, Element configRootElement, ICPathEntry[] entries) { - Element element; - IPath projectPath = getProject().getFullPath(); - for (int i = 0; i < entries.length; i++) { - element = doc.createElement(PATH_ENTRY); - configRootElement.appendChild(element); - int kind = entries[i].getEntryKind(); - - // Set the kind - element.setAttribute(ATTRIBUTE_KIND, CPathEntry.kindToString(kind)); - - // Save the exclusions attributes - if (entries[i] instanceof ACPathEntry) { - ACPathEntry entry = (ACPathEntry) entries[i]; - IPath[] exclusionPatterns = entry.getExclusionPatterns(); - if (exclusionPatterns.length > 0) { - StringBuffer excludeRule = new StringBuffer(10); - for (int j = 0, max = exclusionPatterns.length; j < max; j++) { - if (j > 0) { - excludeRule.append('|'); - } - excludeRule.append(exclusionPatterns[j]); - } - element.setAttribute(ATTRIBUTE_EXCLUDING, excludeRule.toString()); - } - if (entry.isRecursive()) { - element.setAttribute(ATTRIBUTE_RECUSIVE, VALUE_TRUE); - } - } - - if (kind == ICPathEntry.CDT_SOURCE) { - ISourceEntry source = (ISourceEntry) entries[i]; - IPath path = source.getSourcePath(); - element.setAttribute(ATTRIBUTE_PATH, path.toString()); - IPath output = source.getOutputLocation(); - if (output != null && output.isEmpty()) { - element.setAttribute(ATTRIBUTE_OUTPUT, output.toString()); - } - } else if (kind == ICPathEntry.CDT_LIBRARY) { - ILibraryEntry lib = (ILibraryEntry) entries[i]; - IPath path = lib.getLibraryPath(); - element.setAttribute(ATTRIBUTE_PATH, path.toString()); - if (lib.getSourceAttachmentPath() != null) { - element.setAttribute(ATTRIBUTE_SOURCEPATH, lib.getSourceAttachmentPath().toString()); - } - if (lib.getSourceAttachmentRootPath() != null) { - element.setAttribute(ATTRIBUTE_ROOTPATH, lib.getSourceAttachmentRootPath().toString()); - } - if (lib.getSourceAttachmentPrefixMapping() != null) { - element.setAttribute(ATTRIBUTE_PREFIXMAPPING, lib.getSourceAttachmentPrefixMapping().toString()); - } - } else if (kind == ICPathEntry.CDT_PROJECT) { - IProjectEntry pentry = (IProjectEntry) entries[i]; - IPath path = pentry.getProjectPath(); - element.setAttribute(ATTRIBUTE_PATH, path.toString()); - } else if (kind == ICPathEntry.CDT_INCLUDE) { - IIncludeEntry include = (IIncludeEntry) entries[i]; - IPath path = include.getResourcePath(); - element.setAttribute(ATTRIBUTE_PATH, path.toString()); - IPath includePath = include.getIncludePath(); - element.setAttribute(ATTRIBUTE_INCLUDE, includePath.toString()); - if (include.isSystemInclude()) { - element.setAttribute(ATTRIBUTE_SYSTEM, VALUE_TRUE); - } - } else if (kind == ICPathEntry.CDT_MACRO) { - IMacroEntry macro = (IMacroEntry) entries[i]; - IPath path = macro.getResourcePath(); - element.setAttribute(ATTRIBUTE_PATH, path.toString()); - element.setAttribute(ATTRIBUTE_NAME, macro.getMacroName()); - element.setAttribute(ATTRIBUTE_VALUE, macro.getMacroValue()); - } else if (kind == ICPathEntry.CDT_CONTAINER) { - IContainerEntry container = (IContainerEntry) entries[i]; - element.setAttribute(ATTRIBUTE_ID, container.getId()); - } - if (entries[i].isExported()) { - element.setAttribute(ATTRIBUTE_EXPORTED, VALUE_TRUE); - } - } - } } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ContainerEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ContainerEntry.java index eae95703cf0..eea05ae95cf 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ContainerEntry.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ContainerEntry.java @@ -13,22 +13,23 @@ package org.eclipse.cdt.internal.core.model; import org.eclipse.cdt.core.model.IContainerEntry; +import org.eclipse.core.runtime.IPath; -public class ContainerEntry extends CPathEntry implements IContainerEntry { +public class ContainerEntry extends PathEntry implements IContainerEntry { - String id; + IPath path; - public ContainerEntry(String id, boolean isExported) { + public ContainerEntry(IPath path, boolean isExported) { super(IContainerEntry.CDT_CONTAINER, isExported); - this.id = id; + this.path = path; } /** * Returns the id identifying this container. - * @return String + * @return IPath */ - public String getId() { - return id; + public IPath getPath() { + return path; } public boolean equals(Object obj) { @@ -37,12 +38,12 @@ public class ContainerEntry extends CPathEntry implements IContainerEntry { if (!super.equals(container)) { return false; } - if (id == null) { - if (container.getId() != null) { + if (path == null) { + if (container.getPath() != null) { return false; } } else { - if (!id.equals(container.getId())) { + if (!path.equals(container.getPath())) { return false; } } 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 0072ee5ede2..f892675cbc5 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 @@ -9,44 +9,48 @@ * * Contributors: * QNX Software Systems - Initial API and implementation -***********************************************************************/ + ***********************************************************************/ package org.eclipse.cdt.internal.core.model; import org.eclipse.cdt.core.model.IIncludeEntry; import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; -public class IncludeEntry extends ACPathEntry implements IIncludeEntry { +public class IncludeEntry extends APathEntry implements IIncludeEntry { IPath resourcePath; IPath includePath; boolean isSystemInclude; - public IncludeEntry(IPath resourcePath, IPath includePath, boolean isSystemInclude, - boolean isRecursive, IPath[] exclusionPatterns, boolean isExported) { - super(IIncludeEntry.CDT_INCLUDE, isRecursive, exclusionPatterns, isExported); - this.resourcePath = resourcePath; + public IncludeEntry(IPath resourcePath, IPath includePath, boolean isSystemInclude, boolean isRecursive, + IPath[] exclusionPatterns) { + super(IIncludeEntry.CDT_INCLUDE, isRecursive, exclusionPatterns, resourcePath == null || resourcePath.isEmpty()); + this.resourcePath = resourcePath == null ? new Path("") : resourcePath; this.includePath = includePath; this.isSystemInclude = isSystemInclude; } /** * Returns the affected resource by the include. + * * @return IPath */ public IPath getResourcePath() { return resourcePath; } - + /** * Returns the include path + * * @return IPath */ public IPath getIncludePath() { return includePath; } - + /** * Whether or not it a system include path + * * @return boolean */ public boolean isSystemInclude() { @@ -55,7 +59,7 @@ public class IncludeEntry extends ACPathEntry implements IIncludeEntry { public boolean equals(Object obj) { if (obj instanceof IIncludeEntry) { - IIncludeEntry otherEntry = (IIncludeEntry)obj; + IIncludeEntry otherEntry = (IIncludeEntry) obj; if (!super.equals(otherEntry)) { return false; } @@ -84,5 +88,5 @@ public class IncludeEntry extends ACPathEntry implements IIncludeEntry { } return super.equals(obj); } - + } 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 6e418ef0d0f..13487b77f10 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 @@ -15,7 +15,7 @@ package org.eclipse.cdt.internal.core.model; import org.eclipse.cdt.core.model.ILibraryEntry; import org.eclipse.core.runtime.IPath; -public class LibraryEntry extends CPathEntry implements ILibraryEntry { +public class LibraryEntry extends PathEntry implements ILibraryEntry { IPath libraryPath; IPath sourceAttachmentPath; diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MacroEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MacroEntry.java index 95d4d48bc25..b7599bf4ec3 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MacroEntry.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MacroEntry.java @@ -15,7 +15,7 @@ package org.eclipse.cdt.internal.core.model; import org.eclipse.cdt.core.model.IMacroEntry; import org.eclipse.core.runtime.IPath; -public class MacroEntry extends ACPathEntry implements IMacroEntry { +public class MacroEntry extends APathEntry implements IMacroEntry { IPath resourcePath; String macroName; diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CPathEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntry.java similarity index 71% rename from core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CPathEntry.java rename to core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntry.java index 8d0ea5aed0f..6c46c0b902f 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CPathEntry.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntry.java @@ -12,36 +12,36 @@ ***********************************************************************/ package org.eclipse.cdt.internal.core.model; -import org.eclipse.cdt.core.model.ICPathEntry; +import org.eclipse.cdt.core.model.IPathEntry; -public class CPathEntry implements ICPathEntry { +public class PathEntry implements IPathEntry { public int entryKind; public boolean isExported; - public CPathEntry(int entryKind, boolean isExported) { + public PathEntry(int entryKind, boolean isExported) { this.entryKind = entryKind; this.isExported = isExported; } /* (non-Javadoc) - * @see org.eclipse.cdt.core.ICPathEntry#getEntryKind() + * @see org.eclipse.cdt.core.IPathEntry#getEntryKind() */ public int getEntryKind() { return entryKind; } /* (non-Javadoc) - * @see org.eclipse.cdt.core.ICPathEntry#isExported() + * @see org.eclipse.cdt.core.IPathEntry#isExported() */ public boolean isExported() { return isExported; } public boolean equals(Object obj) { - if (obj instanceof ICPathEntry) { - ICPathEntry otherEntry = (ICPathEntry)obj; + if (obj instanceof IPathEntry) { + IPathEntry otherEntry = (IPathEntry)obj; if (entryKind != otherEntry.getEntryKind()) { return false; } @@ -59,19 +59,19 @@ public class CPathEntry implements ICPathEntry { static int kindFromString(String kindStr) { if (kindStr.equalsIgnoreCase("prj")) //$NON-NLS-1$ - return ICPathEntry.CDT_PROJECT; + return IPathEntry.CDT_PROJECT; if (kindStr.equalsIgnoreCase("var")) //$NON-NLS-1$ - return ICPathEntry.CDT_VARIABLE; + return IPathEntry.CDT_VARIABLE; if (kindStr.equalsIgnoreCase("src")) //$NON-NLS-1$ - return ICPathEntry.CDT_SOURCE; + return IPathEntry.CDT_SOURCE; if (kindStr.equalsIgnoreCase("lib")) //$NON-NLS-1$ - return ICPathEntry.CDT_LIBRARY; + return IPathEntry.CDT_LIBRARY; if (kindStr.equalsIgnoreCase("inc")) //$NON-NLS-1$ - return ICPathEntry.CDT_INCLUDE; + return IPathEntry.CDT_INCLUDE; if (kindStr.equalsIgnoreCase("mac")) //$NON-NLS-1$ - return ICPathEntry.CDT_MACRO; + return IPathEntry.CDT_MACRO; if (kindStr.equalsIgnoreCase("con")) //$NON-NLS-1$ - return ICPathEntry.CDT_CONTAINER; + return IPathEntry.CDT_CONTAINER; return -1; } @@ -81,19 +81,19 @@ public class CPathEntry implements ICPathEntry { static String kindToString(int kind) { switch (kind) { - case ICPathEntry.CDT_PROJECT : + case IPathEntry.CDT_PROJECT : return "prj"; //$NON-NLS-1$ - case ICPathEntry.CDT_SOURCE : + case IPathEntry.CDT_SOURCE : return "src"; //$NON-NLS-1$ - case ICPathEntry.CDT_LIBRARY : + case IPathEntry.CDT_LIBRARY : return "lib"; //$NON-NLS-1$ - case ICPathEntry.CDT_VARIABLE : + case IPathEntry.CDT_VARIABLE : return "var"; //$NON-NLS-1$ - case ICPathEntry.CDT_INCLUDE : + case IPathEntry.CDT_INCLUDE : return "inc"; //$NON-NLS-1$ - case ICPathEntry.CDT_MACRO : + case IPathEntry.CDT_MACRO : return "mac"; //$NON-NLS-1$ - case ICPathEntry.CDT_CONTAINER : + case IPathEntry.CDT_CONTAINER : return "con"; //$NON-NLS-1$ default : return "unknown"; //$NON-NLS-1$ @@ -107,25 +107,25 @@ public class CPathEntry implements ICPathEntry { StringBuffer buffer = new StringBuffer(); buffer.append('['); switch (getEntryKind()) { - case ICPathEntry.CDT_LIBRARY : + case IPathEntry.CDT_LIBRARY : buffer.append("CDT_LIBRARY"); //$NON-NLS-1$ break; - case ICPathEntry.CDT_PROJECT : + case IPathEntry.CDT_PROJECT : buffer.append("CDT_PROJECT"); //$NON-NLS-1$ break; - case ICPathEntry.CDT_SOURCE : + case IPathEntry.CDT_SOURCE : buffer.append("CDT_SOURCE"); //$NON-NLS-1$ break; - case ICPathEntry.CDT_VARIABLE : + case IPathEntry.CDT_VARIABLE : buffer.append("CDT_VARIABLE"); //$NON-NLS-1$ break; - case ICPathEntry.CDT_INCLUDE : + case IPathEntry.CDT_INCLUDE : buffer.append("CDT_INCLUDE"); //$NON-NLS-1$ break; - case ICPathEntry.CDT_MACRO : + case IPathEntry.CDT_MACRO : buffer.append("CDT_MACRO"); //$NON-NLS-1$ break; - case ICPathEntry.CDT_CONTAINER : + case IPathEntry.CDT_CONTAINER : buffer.append("CDT_CONTAINER"); //$NON-NLS-1$ break; } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CPathEntryManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryManager.java similarity index 56% rename from core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CPathEntryManager.java rename to core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryManager.java index 4c953ac0802..bcfbf0fb65d 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CPathEntryManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryManager.java @@ -20,20 +20,21 @@ import java.util.Map; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.ICDescriptor; import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.CPathContainerInitializer; import org.eclipse.cdt.core.model.CoreModel; +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.ICElementDelta; import org.eclipse.cdt.core.model.ICModelStatus; -import org.eclipse.cdt.core.model.ICPathContainer; -import org.eclipse.cdt.core.model.ICPathEntry; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.IContainerEntry; 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.IPathEntry; +import org.eclipse.cdt.core.model.IPathEntryContainer; import org.eclipse.cdt.core.model.IProjectEntry; import org.eclipse.cdt.core.model.ISourceEntry; +import org.eclipse.cdt.core.model.PathEntryContainerInitializer; import org.eclipse.cdt.internal.core.CharOperation; -import org.eclipse.core.internal.runtime.Assert; import org.eclipse.core.resources.IWorkspaceRunnable; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; @@ -42,7 +43,9 @@ import org.eclipse.core.runtime.IExtension; import org.eclipse.core.runtime.IExtensionPoint; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.ISafeRunnable; import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Plugin; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -53,11 +56,11 @@ import org.w3c.dom.NodeList; * @author alain * */ -public class CPathEntryManager { +public class PathEntryManager { - static String CONTAINER_INITIALIZER_EXTPOINT_ID = "cpathContainerInitializer"; //$NON-NLS-1$ - static String PATH_ENTRY = "cpathentry"; //$NON-NLS-1$ - static String PATH_ENTRY_ID = "org.eclipse.cdt.core.cpathentry"; //$NON-NLS-1$ + static String CONTAINER_INITIALIZER_EXTPOINT_ID = "pathEntryContainerInitializer"; //$NON-NLS-1$ + static String PATH_ENTRY = "pathentry"; //$NON-NLS-1$ + static String PATH_ENTRY_ID = "org.eclipse.cdt.core.pathentry"; //$NON-NLS-1$ static String ATTRIBUTE_KIND = "kind"; //$NON-NLS-1$ static String ATTRIBUTE_PATH = "path"; //$NON-NLS-1$ static String ATTRIBUTE_EXPORTED = "exported"; //$NON-NLS-1$ @@ -74,40 +77,52 @@ public class CPathEntryManager { static String ATTRIBUTE_ID = "id"; //$NON-NLS-1$ static String VALUE_TRUE = "true"; //$NON-NLS-1$ + final static IPathEntry[] EMPTY = {}; + /** - * Classpath containers pool + * An empty array of strings indicating that a project doesn't have any prerequesite projects. + */ + static final String[] NO_PREREQUISITES = new String[0]; + + /** + * pathentry containers pool */ public static HashMap Containers = new HashMap(5); - public static HashMap PreviousSessionContainers = new HashMap(5); HashMap projectMap = new HashMap(); - final ICPathEntry[] EMPTY = new ICPathEntry[0]; - public final static ICPathContainer ContainerInitializationInProgress = new ICPathContainer() { - public ICPathEntry[] getCPathEntries() { - return null; - } - public String getDescription() { - return "Container Initialization In Progress"; - } //$NON-NLS-1$ - }; - public ICPathEntry[] getResolvedEntries(ICProject cproject) throws CModelException { - ICPathEntry[] entries = (ICPathEntry[]) projectMap.get(cproject); + private static PathEntryManager pathEntryManager; + + private PathEntryManager() { + } + + /** + * Return the singleton. + */ + public static PathEntryManager getDefault() { + if (pathEntryManager == null) { + pathEntryManager = new PathEntryManager(); + } + return pathEntryManager; + } + + public IPathEntry[] getResolvedPathEntries(ICProject cproject) throws CModelException { + IPathEntry[] entries = (IPathEntry[]) projectMap.get(cproject); if (entries == null) { - entries = getRawCPathEntries(cproject); + entries = getRawPathEntries(cproject); ArrayList list = new ArrayList(); for (int i = 0; i < entries.length; i++) { - ICPathEntry entry = entries[i]; + IPathEntry entry = entries[i]; // Expand the containers. - if (entry.getEntryKind() == ICPathEntry.CDT_CONTAINER) { - ICPathContainer container = getCPathContainer((IContainerEntry)entry, cproject); + if (entry.getEntryKind() == IPathEntry.CDT_CONTAINER) { + IContainerEntry centry = (IContainerEntry) entry; + IPathEntryContainer container = getPathEntryContainer(centry, cproject); if (container != null) { - ICPathEntry[] containerEntries = container.getCPathEntries(); + IPathEntry[] containerEntries = container.getPathEntries(); if (containerEntries != null) { for (int j = 0; j < containerEntries.length; j++) { - ICPathEntry cEntry = containerEntries[i]; - if (cEntry.isExported()) { - list.add(cEntry); + if (entry.isExported()) { + list.add(containerEntries[i]); } } } @@ -116,24 +131,246 @@ public class CPathEntryManager { list.add(entry); } } - entries = new ICPathEntry[list.size()]; + entries = new IPathEntry[list.size()]; list.toArray(entries); projectMap.put(cproject, entries); } return entries; } - public void setRawCPathEntries(ICProject cproject, ICPathEntry[] newEntries, IProgressMonitor monitor) throws CModelException { - //try { - // SetCPathEntriesOperation op = new SetCPathEntriesOperation(cproject, getRawCPathEntries(cproject), newEntries); - // runOperation(op, monitor); - //} catch (CoreException e) { - // throw new CModelException(e); - //} - + public void setRawPathEntries(ICProject cproject, IPathEntry[] newEntries, IProgressMonitor monitor) throws CModelException { + try { + SetPathEntriesOperation op = new SetPathEntriesOperation(cproject, getRawPathEntries(cproject), newEntries); + CModelManager.getDefault().runOperation(op, monitor); + } catch (CoreException e) { + throw new CModelException(e); + } + } + + public IPathEntry[] getRawPathEntries(ICProject cproject) throws CModelException { + ArrayList pathEntries = new ArrayList(); + try { + ICDescriptor cdesc = CCorePlugin.getDefault().getCProjectDescription(cproject.getProject()); + Element element = cdesc.getProjectData(PATH_ENTRY_ID); + NodeList list = element.getChildNodes(); + for (int i = 0; i < list.getLength(); i++) { + Node childNode = list.item(i); + if (childNode.getNodeType() == Node.ELEMENT_NODE) { + if (childNode.getNodeName().equals(PATH_ENTRY)) { + pathEntries.add(decodePathEntry(cproject, (Element) childNode)); + } + } + } + } catch (CoreException e) { + throw new CModelException(e); + } + return (IPathEntry[]) pathEntries.toArray(EMPTY); + } + + public void setPathEntryContainer(ICProject[] affectedProjects, IPathEntryContainer newContainer, IProgressMonitor monitor) throws CModelException { + + if (monitor != null && monitor.isCanceled()) { + return; + } + + IPath containerPath = newContainer.getPath(); + final int projectLength = affectedProjects.length; + final ICProject[] modifiedProjects = new ICProject[projectLength]; + System.arraycopy(affectedProjects, 0, modifiedProjects, 0, projectLength); + + // filter out unmodified project containers + int remaining = 0; + for (int i = 0; i < projectLength; i++) { + + if (monitor != null && monitor.isCanceled()) { + return; + } + + ICProject affectedProject = affectedProjects[i]; + + boolean found = false; + if (CoreModel.getDefault().hasCCNature(affectedProject.getProject())) { + IPathEntry[] rawPath = affectedProject.getRawPathEntries(); + for (int j = 0, cpLength = rawPath.length; j < cpLength; j++) { + IPathEntry entry = rawPath[j]; + if (entry.getEntryKind() == IPathEntry.CDT_CONTAINER) { + IContainerEntry cont = (IContainerEntry) entry; + if (cont.getPath().equals(containerPath)) { + found = true; + break; + } + } + } + } + if (!found) { + // filter out this project - does not reference the container path + modifiedProjects[i] = null; + continue; + } + IPathEntryContainer oldContainer = containerGet(affectedProject, containerPath); + if (oldContainer != null && oldContainer.equals(newContainer)) { + modifiedProjects[i] = null; // filter out this project - container did not change + continue; + } + remaining++; + containerPut(affectedProject, containerPath, newContainer); + } + + // Nothing change. + if (remaining == 0) { + return; + } + + // trigger model refresh + try { + //final boolean canChangeResources = !ResourcesPlugin.getWorkspace().isTreeLocked(); + ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() { + public void run(IProgressMonitor progressMonitor) throws CoreException { + for (int i = 0; i < projectLength; i++) { + + if (progressMonitor != null && progressMonitor.isCanceled()) { + return; + } + ICProject affectedProject = (ICProject) modifiedProjects[i]; + if (affectedProject == null) { + continue; // was filtered out + } + // force a refresh of the affected project (will compute deltas) + affectedProject.setRawPathEntries(affectedProject.getRawPathEntries(), progressMonitor); + } + } + }, monitor); + } catch (CoreException e) { + if (e instanceof CModelException) { + throw (CModelException) e; + } else { + throw new CModelException(e); + } + } + } + + public IPathEntryContainer getPathEntryContainer(IContainerEntry entry, ICProject cproject) throws CModelException { + return getPathEntryContainer(entry.getPath(), cproject); + } + + public IPathEntryContainer getPathEntryContainer(final IPath containerPath, final ICProject project) throws CModelException { + + // Try the cache. + IPathEntryContainer container = containerGet(project, containerPath); + + if (container == null) { + final PathEntryContainerInitializer initializer = getPathEntryContainerInitializer(containerPath.segment(0)); + if (initializer != null) { + containerPut(project, containerPath, container); + boolean ok = false; + try { + // wrap initializer call with Safe runnable in case initializer would be + // causing some grief + Platform.run(new ISafeRunnable() { + public void handleException(Throwable exception) { + //Util.log(exception, "Exception occurred in container initializer: "+initializer); //$NON-NLS-1$ + } + public void run() throws Exception { + initializer.initialize(containerPath, project); + } + }); + + // retrieve value (if initialization was successful) + container = containerGet(project, containerPath); + ok = true; + } finally { + if (!ok) { + containerPut(project, containerPath, null); // flush cache + } + } + } + } + return container; + } + + /** + * Helper method finding the container initializer registered for a given container ID or null + * if none was found while iterating over the contributions to extension point to the extension point + * "org.eclipse.cdt.core.PathEntryContainerInitializer". + *

+ * A containerID is the first segment of any container path, used to identify the registered container initializer. + *

+ * + * @param containerID - + * a containerID identifying a registered initializer + * @return PathEntryContainerInitializer - the registered container initializer or null if none was + * found. + */ + public PathEntryContainerInitializer getPathEntryContainerInitializer(String containerID) { + + Plugin core = CCorePlugin.getDefault(); + if (core == null) { + return null; + } + IExtensionPoint extension = core.getDescriptor().getExtensionPoint(CONTAINER_INITIALIZER_EXTPOINT_ID); + if (extension != null) { + IExtension[] extensions = extension.getExtensions(); + for (int i = 0; i < extensions.length; i++) { + IConfigurationElement[] configElements = extensions[i].getConfigurationElements(); + for (int j = 0; j < configElements.length; j++) { + String initializerID = configElements[j].getAttribute("id"); //$NON-NLS-1$ + if (initializerID != null && initializerID.equals(containerID)) { + try { + Object execExt = configElements[j].createExecutableExtension("class"); //$NON-NLS-1$ + if (execExt instanceof PathEntryContainerInitializer) { + return (PathEntryContainerInitializer) execExt; + } + } catch (CoreException e) { + // executable extension could not be created: + // ignore this initializer if + //e.printStackTrace(); + } + } + } + } + } + return null; + } + + public IPathEntryContainer containerGet(ICProject project, IPath containerPath) { + Map projectContainers = (Map) Containers.get(project); + if (projectContainers == null) { + projectContainers = new HashMap(); + Containers.put(project, projectContainers); + } + IPathEntryContainer container = (IPathEntryContainer) projectContainers.get(containerPath); + return container; + } + + public void containerPut(ICProject project, IPath containerPath, IPathEntryContainer container) { + Map projectContainers = (Map) Containers.get(project); + if (projectContainers == null) { + projectContainers = new HashMap(); + Containers.put(project, projectContainers); + } + projectContainers.put(containerPath, container); + } + + public String[] projectPrerequisites(IPathEntry[] entries) throws CModelException { + ArrayList prerequisites = new ArrayList(); + for (int i = 0, length = entries.length; i < length; i++) { + if (entries[i].getEntryKind() == IPathEntry.CDT_PROJECT) { + IProjectEntry entry = (IProjectEntry)entries[i]; + prerequisites.add(entry.getProjectPath().lastSegment()); + } + } + int size = prerequisites.size(); + if (size != 0) { + String[] result = new String[size]; + prerequisites.toArray(result); + return result; + } + return NO_PREREQUISITES; + } + public ICElementDelta[] saveRawPathEntries(ICProject cproject, IPathEntry[] oldEntries, IPathEntry[] newEntries) throws CModelException { try { ICDescriptor descriptor = CCorePlugin.getDefault().getCProjectDescription(cproject.getProject()); - Element rootElement = descriptor.getProjectData(CProject.PATH_ENTRY_ID); + Element rootElement = descriptor.getProjectData(PATH_ENTRY_ID); // Clear out all current children Node child = rootElement.getFirstChild(); while (child != null) { @@ -145,169 +382,112 @@ public class CPathEntryManager { if (newEntries != null && newEntries.length > 0) { // Serialize the include paths Document doc = rootElement.getOwnerDocument(); - encodeCPathEntries(cproject.getProject().getFullPath(), doc, rootElement, newEntries); + encodePathEntries(cproject.getPath(), doc, rootElement, newEntries); descriptor.saveProjectData(); } + + return generatePathEntryDeltas(cproject, oldEntries, newEntries); } catch (CoreException e) { throw new CModelException(e); } } - public ICPathEntry[] getRawCPathEntries(ICProject cproject) throws CModelException { - ArrayList pathEntries = new ArrayList(); - try { - ICDescriptor cdesc = CCorePlugin.getDefault().getCProjectDescription(cproject.getProject()); - Element element = cdesc.getProjectData(PATH_ENTRY_ID); - NodeList list = element.getChildNodes(); - for (int i = 0; i < list.getLength(); i++) { - Node childNode = list.item(i); - if (childNode.getNodeType() == Node.ELEMENT_NODE) { - if (childNode.getNodeName().equals(PATH_ENTRY)) { - pathEntries.add(decodeCPathEntry(cproject, (Element) childNode)); + private ICElementDelta[] generatePathEntryDeltas(ICProject cproject, IPathEntry[] oldEntries, IPathEntry[] newEntries) { + ArrayList list = new ArrayList(); + CModelManager manager = CModelManager.getDefault(); + boolean needToUpdateDependents = false; + boolean hasDelta = false; + + // Check the removed entries. + if (oldEntries != null) { + for (int i = 0; i < oldEntries.length; i++) { + boolean found = false; + for (int j = 0; j < newEntries.length; j++) { + if (oldEntries[i].equals(newEntries[j])) { + found = true; + break; + } + } + // Was it deleted. + if (!found) { + ICElementDelta delta = + makePathEntryDelta(cproject, oldEntries[i], ICElementDelta.F_REMOVED_FROM_CPATHENTRY); + if (delta != null) { + list.add(delta); } } } - } catch (CoreException e) { - throw new CModelException(e); } - return (ICPathEntry[]) pathEntries.toArray(new ICPathEntry[0]); + // Check the new entries. + if (newEntries != null) { + for (int i = 0; i < newEntries.length; i++) { + boolean found = false; + for (int j = 0; j < oldEntries.length; j++) { + if (newEntries[i].equals(oldEntries[j])) { + found = true; + break; + } + } + // is it new? + if (!found) { + ICElementDelta delta = + makePathEntryDelta(cproject, newEntries[i], ICElementDelta.F_ADDED_TO_CPATHENTRY); + if (delta != null) { + list.add(delta); + } + } + } + } + ICElementDelta[] deltas = new ICElementDelta[list.size()]; + list.toArray(deltas); + return deltas; } - public void setCPathContainer( - final IPath containerPath, - ICProject[] affectedProjects, - ICPathContainer[] respectiveContainers, - IProgressMonitor monitor) - throws CModelException { - - if (affectedProjects.length != respectiveContainers.length) - Assert.isTrue(false, "Projects and containers collections should have the same size"); //$NON-NLS-1$ - - if (monitor != null && monitor.isCanceled()) - return; - - final int projectLength = affectedProjects.length; - final ICProject[] modifiedProjects = new ICProject[projectLength]; - System.arraycopy(affectedProjects, 0, modifiedProjects, 0, projectLength); - ICPathEntry[][] oldResolvedPaths = new ICPathEntry[projectLength][]; - - // filter out unmodified project containers - int remaining = 0; - for (int i = 0; i < projectLength; i++) { - - if (monitor != null && monitor.isCanceled()) - return; - - ICProject affectedProject = affectedProjects[i]; - ICPathContainer newContainer = respectiveContainers[i]; - - if (newContainer == null) - newContainer = ContainerInitializationInProgress; // 30920 - prevent infinite loop - - boolean found = false; - if (CoreModel.getDefault().hasCCNature(affectedProject.getProject())) { - ICPathEntry[] rawCPath = affectedProject.getRawCPathEntries(); - for (int j = 0, cpLength = rawCPath.length; j < cpLength; j++) { - ICPathEntry entry = rawCPath[j]; - if (entry.getEntryKind() == ICPathEntry.CDT_CONTAINER) { - IContainerEntry cont = (IContainerEntry) entry; - if (cont.getId().equals(containerPath.segment(0))) { - found = true; - break; - } - } - } - } - if (!found) { - modifiedProjects[i] = null; - // filter out this project - does not reference the container path, or isnt't yet Java project - containerPut(affectedProject, containerPath, newContainer); - continue; - } - ICPathContainer oldContainer = containerGet(affectedProject, containerPath); - if (oldContainer == ContainerInitializationInProgress) { - Map previousContainerValues = (Map) PreviousSessionContainers.get(affectedProject); - if (previousContainerValues != null) { - ICPathContainer previousContainer = (ICPathContainer) previousContainerValues.get(containerPath); - if (previousContainer != null) { - if (true) { - System.out.println("CPContainer INIT - reentering access to project container: [" + affectedProject.getElementName() + "] " + containerPath + " during its initialization, will see previous value: " + previousContainer.getDescription()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - } - containerPut(affectedProject, containerPath, previousContainer); - } - oldContainer = null; - //33695 - cannot filter out restored container, must update affected project to reset cached CP - } else { - oldContainer = null; - } - } - if (oldContainer != null && oldContainer.equals(respectiveContainers[i])) { - modifiedProjects[i] = null; // filter out this project - container did not change - continue; - } - remaining++; - oldResolvedPaths[i] = affectedProject.getResolvedCPathEntries(); - containerPut(affectedProject, containerPath, newContainer); + /** + * return a delta, with the specified change flag. + */ + protected ICElementDelta makePathEntryDelta(ICProject cproject, IPathEntry entry, int flag) { + int kind = entry.getEntryKind(); + ICElement celement = null; + if (kind == IPathEntry.CDT_SOURCE) { + ISourceEntry source = (ISourceEntry) entry; + IPath path = source.getSourcePath(); + celement = CoreModel.getDefault().create(path); + } else if (kind == IPathEntry.CDT_LIBRARY) { + //ILibraryEntry lib = (ILibraryEntry) entry; + //IPath path = lib.getLibraryPath(); + celement = cproject; + } else if (kind == IPathEntry.CDT_PROJECT) { + //IProjectEntry pentry = (IProjectEntry) entry; + //IPath path = pentry.getProjectPath(); + celement = cproject; + } else if (kind == IPathEntry.CDT_INCLUDE) { + IIncludeEntry include = (IIncludeEntry) entry; + IPath path = include.getResourcePath(); + celement = CoreModel.getDefault().create(path); + } else if (kind == IPathEntry.CDT_MACRO) { + IMacroEntry macro = (IMacroEntry) entry; + IPath path = macro.getResourcePath(); + celement = CoreModel.getDefault().create(path); + } else if (kind == IPathEntry.CDT_CONTAINER) { + IContainerEntry container = (IContainerEntry) entry; + celement = cproject; } - - // Nothing change. - if (remaining == 0) - return; - - // trigger model refresh - try { - //final boolean canChangeResources = !ResourcesPlugin.getWorkspace().isTreeLocked(); - ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() { - public void run(IProgressMonitor progressMonitor) throws CoreException { - for (int i = 0; i < projectLength; i++) { - - if (progressMonitor != null && progressMonitor.isCanceled()) - return; - - ICProject affectedProject = (ICProject) modifiedProjects[i]; - if (affectedProject == null) - continue; // was filtered out - - if (true) { - System.out.println("CPContainer SET - updating affected project: [" + affectedProject.getElementName() + "] due to setting container: " + containerPath); //$NON-NLS-1$ //$NON-NLS-2$ - } - - // force a refresh of the affected project (will compute deltas) - affectedProject.setRawCPathEntries(affectedProject.getRawCPathEntries(), progressMonitor); - } - } - }, monitor); - } catch (CoreException e) { - if (true) { - System.out.println("CPContainer SET - FAILED DUE TO EXCEPTION: " + containerPath); //$NON-NLS-1$ - e.printStackTrace(); - } - if (e instanceof CModelException) { - throw (CModelException) e; - } else { - throw new CModelException(e); - } - } finally { - for (int i = 0; i < projectLength; i++) { - if (respectiveContainers[i] == null) { - containerPut(affectedProjects[i], containerPath, null); // reset init in progress marker - } - } + if (celement != null) { + CElementDelta delta = new CElementDelta(cproject.getCModel()); + delta.changed(celement, flag); + return delta; } - - } - - public ICPathContainer getCPathContainer(IContainerEntry entry, ICProject cproject) { return null; } - public static String[] getRegisteredContainerIDs() { - Plugin cdtCorePlugin = CCorePlugin.getDefault(); - if (cdtCorePlugin == null) + static String[] getRegisteredContainerIDs() { + Plugin core = CCorePlugin.getDefault(); + if (core == null) { return null; - + } ArrayList containerIDList = new ArrayList(5); - IExtensionPoint extension = cdtCorePlugin.getDescriptor().getExtensionPoint(CONTAINER_INITIALIZER_EXTPOINT_ID); + IExtensionPoint extension = core.getDescriptor().getExtensionPoint(CONTAINER_INITIALIZER_EXTPOINT_ID); if (extension != null) { IExtension[] extensions = extension.getExtensions(); for (int i = 0; i < extensions.length; i++) { @@ -324,93 +504,12 @@ public class CPathEntryManager { return containerIDs; } - /** - * Helper method finding the classpath container initializer registered for a given classpath container ID or null - * if none was found while iterating over the contributions to extension point to the extension point - * "org.eclipse.jdt.core.classpathContainerInitializer". - *

- * A containerID is the first segment of any container path, used to identify the registered container initializer. - *

- * - * @param containerID - - * a containerID identifying a registered initializer - * @return ClasspathContainerInitializer - the registered classpath container initializer or null if none was - * found. - * @since 2.1 - */ - public static CPathContainerInitializer getCPathContainerInitializer(String containerID) { - - Plugin cdtCorePlugin = CCorePlugin.getDefault(); - if (cdtCorePlugin == null) - return null; - - IExtensionPoint extension = cdtCorePlugin.getDescriptor().getExtensionPoint(CONTAINER_INITIALIZER_EXTPOINT_ID); - if (extension != null) { - IExtension[] extensions = extension.getExtensions(); - for (int i = 0; i < extensions.length; i++) { - IConfigurationElement[] configElements = extensions[i].getConfigurationElements(); - for (int j = 0; j < configElements.length; j++) { - String initializerID = configElements[j].getAttribute("id"); //$NON-NLS-1$ - if (initializerID != null && initializerID.equals(containerID)) { - if (true) { - System.out.println("CPContainer INIT - found initializer: " + containerID + " --> " + configElements[j].getAttribute("class")); //$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$ - } - try { - Object execExt = configElements[j].createExecutableExtension("class"); //$NON-NLS-1$ - if (execExt instanceof CPathContainerInitializer) { - return (CPathContainerInitializer) execExt; - } - } catch (CoreException e) { - // executable extension could not be created: ignore this initializer if - System.out.println("CPContainer INIT - failed to instanciate initializer: " + containerID + " --> " + configElements[j].getAttribute("class")); //$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$ - e.printStackTrace(); - } - } - } - } - } - return null; - } - - public static ICPathContainer containerGet(ICProject project, IPath containerPath) { - Map projectContainers = (Map) Containers.get(project); - if (projectContainers == null) { - return null; - } - ICPathContainer container = (ICPathContainer) projectContainers.get(containerPath); - return container; - } - - public static void containerPut(ICProject project, IPath containerPath, ICPathContainer container) { - - Map projectContainers = (Map) Containers.get(project); - if (projectContainers == null) { - projectContainers = new HashMap(1); - Containers.put(project, projectContainers); - } - - if (container == null) { - projectContainers.remove(containerPath); - Map previousContainers = (Map) PreviousSessionContainers.get(project); - if (previousContainers != null) { - previousContainers.remove(containerPath); - } - } else { - projectContainers.put(containerPath, container); - } - - // do not write out intermediate initialization value - if (container == ContainerInitializationInProgress) { - return; - } - } - - ICPathEntry decodeCPathEntry(ICProject cProject, Element element) throws CModelException { + static IPathEntry decodePathEntry(ICProject cProject, Element element) throws CModelException { IPath projectPath = cProject.getProject().getFullPath(); // kind String kindAttr = element.getAttribute(ATTRIBUTE_KIND); - int kind = CPathEntry.kindFromString(kindAttr); + int kind = PathEntry.kindFromString(kindAttr); // exported flag boolean isExported = false; @@ -421,7 +520,7 @@ public class CPathEntryManager { // ensure path is absolute String pathAttr = element.getAttribute(ATTRIBUTE_PATH); IPath path = new Path(pathAttr); - if (kind != ICPathEntry.CDT_VARIABLE && !path.isAbsolute()) { + if (kind != IPathEntry.CDT_VARIABLE && !path.isAbsolute()) { path = projectPath.append(path); } @@ -435,7 +534,7 @@ public class CPathEntryManager { // exclusion patterns (optional) String exclusion = element.getAttribute(ATTRIBUTE_EXCLUDING); - IPath[] exclusionPatterns = ACPathEntry.NO_EXCLUSION_PATTERNS; + IPath[] exclusionPatterns = APathEntry.NO_EXCLUSION_PATTERNS; if (!exclusion.equals("")) { //$NON-NLS-1$ char[][] patterns = CharOperation.splitOn('|', exclusion.toCharArray()); int patternCount; @@ -456,10 +555,10 @@ public class CPathEntryManager { switch (kind) { - case ICPathEntry.CDT_PROJECT : + case IPathEntry.CDT_PROJECT : return CoreModel.newProjectEntry(path, isExported); - case ICPathEntry.CDT_LIBRARY : + case IPathEntry.CDT_LIBRARY : return CoreModel.newLibraryEntry( path, sourceAttachmentPath, @@ -467,10 +566,10 @@ public class CPathEntryManager { sourceAttachmentPrefixMapping, isExported); - case ICPathEntry.CDT_SOURCE : + case IPathEntry.CDT_SOURCE : { // custom output location - IPath outputLocation = element.hasAttribute(ATTRIBUTE_OUTPUT) ? projectPath.append(element.getAttribute(ATTRIBUTE_OUTPUT)) : null; //$NON-NLS-1$ //$NON-NLS-2$ + IPath outputLocation = element.hasAttribute(ATTRIBUTE_OUTPUT) ? projectPath.append(element.getAttribute(ATTRIBUTE_OUTPUT)) : null; // must be an entry in this project or specify another // project String projSegment = path.segment(0); @@ -481,11 +580,7 @@ public class CPathEntryManager { } } - // case ICPathEntry.CDT_VARIABLE : - // return CoreModel.newVariableEntry(path, - // sourceAttachmentPath, sourceAttachmentRootPath); - - case ICPathEntry.CDT_INCLUDE : + case IPathEntry.CDT_INCLUDE : { // include path info (optional IPath includePath = @@ -500,45 +595,43 @@ public class CPathEntryManager { includePath, isSystemInclude, isRecursive, - exclusionPatterns, - isExported); + exclusionPatterns); } - case ICPathEntry.CDT_MACRO : + case IPathEntry.CDT_MACRO : { - String macroName = element.getAttribute(ATTRIBUTE_NAME); //$NON-NLS-1$ - String macroValue = element.getAttribute(ATTRIBUTE_VALUE); //$NON-NLS-1$ + String macroName = element.getAttribute(ATTRIBUTE_NAME); + String macroValue = element.getAttribute(ATTRIBUTE_VALUE); return CoreModel.newMacroEntry(path, macroName, macroValue, isRecursive, exclusionPatterns, isExported); } - case ICPathEntry.CDT_CONTAINER : + case IPathEntry.CDT_CONTAINER : { - String id = element.getAttribute(ATTRIBUTE_ID); //$NON-NLS-1$ + IPath id = new Path(element.getAttribute(ATTRIBUTE_ID)); return CoreModel.newContainerEntry(id, isExported); } default : { - ICModelStatus status = new CModelStatus(ICModelStatus.ERROR, "CPathEntry: unknown kind (" + kindAttr + ")"); //$NON-NLS-1$ + ICModelStatus status = new CModelStatus(ICModelStatus.ERROR, "PathEntry: unknown kind (" + kindAttr + ")"); //$NON-NLS-1$ //$NON-NLS-2$ throw new CModelException(status); } } } - void encodeCPathEntries(IPath projectPath, Document doc, Element configRootElement, ICPathEntry[] entries) { + static void encodePathEntries(IPath projectPath, Document doc, Element configRootElement, IPathEntry[] entries) { Element element; - //IPath projectPath = getProject().getFullPath(); for (int i = 0; i < entries.length; i++) { element = doc.createElement(PATH_ENTRY); configRootElement.appendChild(element); int kind = entries[i].getEntryKind(); // Set the kind - element.setAttribute(ATTRIBUTE_KIND, CPathEntry.kindToString(kind)); + element.setAttribute(ATTRIBUTE_KIND, PathEntry.kindToString(kind)); // Save the exclusions attributes - if (entries[i] instanceof ACPathEntry) { - ACPathEntry entry = (ACPathEntry) entries[i]; + if (entries[i] instanceof APathEntry) { + APathEntry entry = (APathEntry) entries[i]; IPath[] exclusionPatterns = entry.getExclusionPatterns(); if (exclusionPatterns.length > 0) { StringBuffer excludeRule = new StringBuffer(10); @@ -555,7 +648,7 @@ public class CPathEntryManager { } } - if (kind == ICPathEntry.CDT_SOURCE) { + if (kind == IPathEntry.CDT_SOURCE) { ISourceEntry source = (ISourceEntry) entries[i]; IPath path = source.getSourcePath(); element.setAttribute(ATTRIBUTE_PATH, path.toString()); @@ -563,7 +656,7 @@ public class CPathEntryManager { if (output != null && output.isEmpty()) { element.setAttribute(ATTRIBUTE_OUTPUT, output.toString()); } - } else if (kind == ICPathEntry.CDT_LIBRARY) { + } else if (kind == IPathEntry.CDT_LIBRARY) { ILibraryEntry lib = (ILibraryEntry) entries[i]; IPath path = lib.getLibraryPath(); element.setAttribute(ATTRIBUTE_PATH, path.toString()); @@ -576,11 +669,11 @@ public class CPathEntryManager { if (lib.getSourceAttachmentPrefixMapping() != null) { element.setAttribute(ATTRIBUTE_PREFIXMAPPING, lib.getSourceAttachmentPrefixMapping().toString()); } - } else if (kind == ICPathEntry.CDT_PROJECT) { + } else if (kind == IPathEntry.CDT_PROJECT) { IProjectEntry pentry = (IProjectEntry) entries[i]; IPath path = pentry.getProjectPath(); element.setAttribute(ATTRIBUTE_PATH, path.toString()); - } else if (kind == ICPathEntry.CDT_INCLUDE) { + } else if (kind == IPathEntry.CDT_INCLUDE) { IIncludeEntry include = (IIncludeEntry) entries[i]; IPath path = include.getResourcePath(); element.setAttribute(ATTRIBUTE_PATH, path.toString()); @@ -589,15 +682,15 @@ public class CPathEntryManager { if (include.isSystemInclude()) { element.setAttribute(ATTRIBUTE_SYSTEM, VALUE_TRUE); } - } else if (kind == ICPathEntry.CDT_MACRO) { + } else if (kind == IPathEntry.CDT_MACRO) { IMacroEntry macro = (IMacroEntry) entries[i]; IPath path = macro.getResourcePath(); element.setAttribute(ATTRIBUTE_PATH, path.toString()); element.setAttribute(ATTRIBUTE_NAME, macro.getMacroName()); element.setAttribute(ATTRIBUTE_VALUE, macro.getMacroValue()); - } else if (kind == ICPathEntry.CDT_CONTAINER) { + } else if (kind == IPathEntry.CDT_CONTAINER) { IContainerEntry container = (IContainerEntry) entries[i]; - element.setAttribute(ATTRIBUTE_ID, container.getId()); + element.setAttribute(ATTRIBUTE_ID, container.getPath().toString()); } if (entries[i].isExported()) { element.setAttribute(ATTRIBUTE_EXPORTED, VALUE_TRUE); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ProjectEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ProjectEntry.java index 48a1f3ff17d..7ab83ba117e 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ProjectEntry.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ProjectEntry.java @@ -16,7 +16,7 @@ import org.eclipse.cdt.core.model.IProjectEntry; import org.eclipse.core.runtime.IPath; -public class ProjectEntry extends CPathEntry implements IProjectEntry { +public class ProjectEntry extends PathEntry implements IProjectEntry { IPath projectPath; diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SetCPathEntriesOperation.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SetCPathEntriesOperation.java deleted file mode 100644 index 6a3e206ef48..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SetCPathEntriesOperation.java +++ /dev/null @@ -1,221 +0,0 @@ -/********************************************************************** - * Created on Mar 25, 2003 - * - * Copyright (c) 2002,2003 QNX Software Systems Ltd. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * QNX Software Systems - Initial API and implementation -***********************************************************************/ - -package org.eclipse.cdt.internal.core.model; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.Iterator; - -import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.ICDescriptor; -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.CoreModel; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.ICElementDelta; -import org.eclipse.cdt.core.model.ICPathEntry; -import org.eclipse.cdt.core.model.IContainerEntry; -import org.eclipse.cdt.core.model.IIncludeEntry; -import org.eclipse.cdt.core.model.IMacroEntry; -import org.eclipse.cdt.core.model.ISourceEntry; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IProjectDescription; -import org.eclipse.core.resources.IWorkspaceRoot; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - -/** - */ -public class SetCPathEntriesOperation extends CModelOperation { - - ICPathEntry[] oldEntries; - ICPathEntry[] newEntries; - CProject project; - - public SetCPathEntriesOperation(CProject project, ICPathEntry[] oldEntries, ICPathEntry[] newEntries) { - super(project); - this.oldEntries = oldEntries; - this.newEntries = newEntries; - this.project = project; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.model.CModelOperation#executeOperation() - */ - protected void executeOperation() throws CModelException { - // project reference updated - may throw an exception if unable to write .cdtproject file - updateProjectReferencesIfNecessary(); - try { - - ICDescriptor descriptor = CCorePlugin.getDefault().getCProjectDescription(project.getProject()); - Element rootElement = descriptor.getProjectData(CProject.PATH_ENTRY_ID); - // Clear out all current children - Node child = rootElement.getFirstChild(); - while (child != null) { - rootElement.removeChild(child); - child = rootElement.getFirstChild(); - } - - // Save the entries - if (newEntries != null && newEntries.length > 0) { - // Serialize the include paths - Document doc = rootElement.getOwnerDocument(); - project.encodeCPathEntries(doc, rootElement, newEntries); - descriptor.saveProjectData(); - } - - generateCPathEntryDeltas(); - done(); - } catch (CoreException e) { - throw new CModelException(e); - } - } - - protected void updateProjectReferencesIfNecessary() throws CModelException { - String[] oldRequired = this.project.projectPrerequisites(oldEntries); - String[] newRequired = this.project.projectPrerequisites(newEntries); - - try { - IProject projectResource = project.getProject(); - IProjectDescription description = projectResource.getDescription(); - - IProject[] projectReferences = description.getReferencedProjects(); - - HashSet oldReferences = new HashSet(projectReferences.length); - for (int i = 0; i < projectReferences.length; i++) { - String projectName = projectReferences[i].getName(); - oldReferences.add(projectName); - } - HashSet newReferences = (HashSet) oldReferences.clone(); - - for (int i = 0; i < oldRequired.length; i++) { - String projectName = oldRequired[i]; - newReferences.remove(projectName); - } - for (int i = 0; i < newRequired.length; i++) { - String projectName = newRequired[i]; - newReferences.add(projectName); - } - - Iterator iter; - int newSize = newReferences.size(); - - checkIdentity : { - if (oldReferences.size() == newSize) { - iter = newReferences.iterator(); - while (iter.hasNext()) { - if (!oldReferences.contains(iter.next())) { - break checkIdentity; - } - } - return; - } - } - String[] requiredProjectNames = new String[newSize]; - int index = 0; - iter = newReferences.iterator(); - while (iter.hasNext()) { - requiredProjectNames[index++] = (String) iter.next(); - } - Arrays.sort(requiredProjectNames); // ensure that if changed, the order is consistent - - IProject[] requiredProjectArray = new IProject[newSize]; - IWorkspaceRoot wksRoot = projectResource.getWorkspace().getRoot(); - for (int i = 0; i < newSize; i++) { - requiredProjectArray[i] = wksRoot.getProject(requiredProjectNames[i]); - } - - description.setReferencedProjects(requiredProjectArray); - projectResource.setDescription(description, this.fMonitor); - - } catch (CoreException e) { - throw new CModelException(e); - } - } - - private void generateCPathEntryDeltas() { - CModelManager manager = CModelManager.getDefault(); - boolean needToUpdateDependents = false; - CElementDelta delta = new CElementDelta(getCModel()); - boolean hasDelta = false; - - // Check the removed entries. - for (int i = 0; i < oldEntries.length; i++) { - boolean found = false; - for (int j = 0; j < newEntries.length; j++) { - if (oldEntries[i].equals(newEntries[j])) { - found = true; - break; - } - } - // Was it deleted. - if (!found) { - addCPathEntryDeltas(oldEntries[i], ICElementDelta.F_REMOVED_FROM_CPATHENTRY, delta); - } - } - // Check the new entries. - for (int i = 0; i < newEntries.length; i++) { - boolean found = false; - for (int j = 0; j < oldEntries.length; j++) { - if (newEntries[i].equals(oldEntries[j])) { - found = true; - break; - } - } - // is it new? - if (!found) { - addCPathEntryDeltas(newEntries[i], ICElementDelta.F_ADDED_TO_CPATHENTRY, delta); - } - } - } - - /** - * Adds deltas, with the specified change flag. - */ - protected void addCPathEntryDeltas(ICPathEntry entry, int flag, CElementDelta delta) { - - int kind = entry.getEntryKind(); - ICElement celement = null; - if (kind == ICPathEntry.CDT_SOURCE) { - ISourceEntry source = (ISourceEntry) entry; - IPath path = source.getSourcePath(); - celement = CoreModel.getDefault().create(path); - } else if (kind == ICPathEntry.CDT_LIBRARY) { - //ILibraryEntry lib = (ILibraryEntry) entry; - //IPath path = lib.getLibraryPath(); - celement = project; - } else if (kind == ICPathEntry.CDT_PROJECT) { - //IProjectEntry pentry = (IProjectEntry) entry; - //IPath path = pentry.getProjectPath(); - celement = project; - } else if (kind == ICPathEntry.CDT_INCLUDE) { - IIncludeEntry include = (IIncludeEntry) entry; - IPath path = include.getResourcePath(); - celement = CoreModel.getDefault().create(path); - } else if (kind == ICPathEntry.CDT_MACRO) { - IMacroEntry macro = (IMacroEntry) entry; - IPath path = macro.getResourcePath(); - celement = CoreModel.getDefault().create(path); - } else if (kind == ICPathEntry.CDT_CONTAINER) { - IContainerEntry container = (IContainerEntry) entry; - celement = project; - } - if (celement != null) { - delta.changed(celement, flag); - addDelta(delta); - } - } -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SetPathEntriesOperation.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SetPathEntriesOperation.java new file mode 100644 index 00000000000..a26549ba26c --- /dev/null +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SetPathEntriesOperation.java @@ -0,0 +1,126 @@ +/********************************************************************** + * Created on Mar 25, 2003 + * + * Copyright (c) 2002,2003 QNX Software Systems Ltd. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation +***********************************************************************/ + +package org.eclipse.cdt.internal.core.model; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Iterator; + +import org.eclipse.cdt.core.model.CModelException; +import org.eclipse.cdt.core.model.ICElementDelta; +import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.core.model.IPathEntry; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectDescription; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.runtime.CoreException; + +/** + */ +public class SetPathEntriesOperation extends CModelOperation { + + /** + * An empty array of strings indicating that a project doesn't have any prerequesite projects. + */ + static final String[] NO_PREREQUISITES = new String[0]; + + IPathEntry[] oldEntries; + IPathEntry[] newEntries; + ICProject cproject; + + public SetPathEntriesOperation(ICProject project, IPathEntry[] oldEntries, IPathEntry[] newEntries) { + super(project); + this.oldEntries = oldEntries; + this.newEntries = newEntries; + this.cproject = project; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.model.CModelOperation#executeOperation() + */ + protected void executeOperation() throws CModelException { + // project reference updated - may throw an exception if unable to write .cdtproject file + updateProjectReferencesIfNecessary(); + PathEntryManager mgr = PathEntryManager.getDefault(); + ICElementDelta[] deltas = mgr.saveRawPathEntries(cproject, oldEntries, newEntries); + for (int i = 0; i < deltas.length; i++) { + addDelta(deltas[i]); + } + done(); + } + + protected void updateProjectReferencesIfNecessary() throws CModelException { + PathEntryManager mgr = PathEntryManager.getDefault(); + String[] oldRequired = mgr.projectPrerequisites(oldEntries); + String[] newRequired = mgr.projectPrerequisites(newEntries); + + try { + IProject projectResource = cproject.getProject(); + IProjectDescription description = projectResource.getDescription(); + + IProject[] projectReferences = description.getReferencedProjects(); + + HashSet oldReferences = new HashSet(projectReferences.length); + for (int i = 0; i < projectReferences.length; i++) { + String projectName = projectReferences[i].getName(); + oldReferences.add(projectName); + } + HashSet newReferences = (HashSet) oldReferences.clone(); + + for (int i = 0; i < oldRequired.length; i++) { + String projectName = oldRequired[i]; + newReferences.remove(projectName); + } + for (int i = 0; i < newRequired.length; i++) { + String projectName = newRequired[i]; + newReferences.add(projectName); + } + + Iterator iter; + int newSize = newReferences.size(); + + checkIdentity : { + if (oldReferences.size() == newSize) { + iter = newReferences.iterator(); + while (iter.hasNext()) { + if (!oldReferences.contains(iter.next())) { + break checkIdentity; + } + } + return; + } + } + String[] requiredProjectNames = new String[newSize]; + int index = 0; + iter = newReferences.iterator(); + while (iter.hasNext()) { + requiredProjectNames[index++] = (String) iter.next(); + } + Arrays.sort(requiredProjectNames); // ensure that if changed, the order is consistent + + IProject[] requiredProjectArray = new IProject[newSize]; + IWorkspaceRoot wksRoot = projectResource.getWorkspace().getRoot(); + for (int i = 0; i < newSize; i++) { + requiredProjectArray[i] = wksRoot.getProject(requiredProjectNames[i]); + } + + description.setReferencedProjects(requiredProjectArray); + projectResource.setDescription(description, this.fMonitor); + + } catch (CoreException e) { + throw new CModelException(e); + } + } + +} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SourceEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SourceEntry.java index 2e317eb1dad..05797e006d1 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SourceEntry.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SourceEntry.java @@ -15,7 +15,7 @@ package org.eclipse.cdt.internal.core.model; import org.eclipse.cdt.core.model.ISourceEntry; import org.eclipse.core.runtime.IPath; -public class SourceEntry extends ACPathEntry implements ISourceEntry { +public class SourceEntry extends APathEntry implements ISourceEntry { IPath sourcePath; IPath outputLocation;