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 e61eea22e64..15afacba49e 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 @@ -4,10 +4,15 @@ package org.eclipse.cdt.core.model; * (c) Copyright QNX Software Systems Ltd. 2002. * All Rights Reserved. */ - + import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.internal.core.model.BatchOperation; import org.eclipse.cdt.internal.core.model.CModelManager; +import org.eclipse.cdt.internal.core.model.ContainerEntry; +import org.eclipse.cdt.internal.core.model.IncludeEntry; +import org.eclipse.cdt.internal.core.model.MacroEntry; +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; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; @@ -24,7 +29,7 @@ public class CoreModel { private static CoreModel cmodel = null; private static CModelManager manager = null; - + public final static String CORE_MODEL_ID = CCorePlugin.PLUGIN_ID + ".coremodel"; /** @@ -119,7 +124,7 @@ public class CoreModel { /** * Return true if name is a valid name for a translation unit. */ - public boolean isValidTranslationUnitName(String name){ + public boolean isValidTranslationUnitName(String name) { return manager.isValidTranslationUnitName(name); } @@ -147,17 +152,288 @@ public class CoreModel { /** * Return true if project has C nature. */ - public boolean hasCNature(IProject project){ + public boolean hasCNature(IProject project) { return manager.hasCNature(project); } /** * Return true if project has C++ nature. */ - public boolean hasCCNature(IProject project){ + public boolean hasCCNature(IProject project) { return manager.hasCCNature(project); } + /** + * 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. + *

+ * 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). + *

+ * + * @param path the absolute path of the binary archive + * @return a new project entry + * + * @see CoreModel#newProjectEntry(IPath, boolean) + */ + public static IProjectEntry newProjectEntry(IPath path) { + return newProjectEntry(path, false); + } + + /** + * 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. + *

+ * + * @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 + * @return a new project entry + */ + public static IProjectEntry newProjectEntry(IPath path, boolean isExported) { + return new ProjectEntry(path, isExported); + } + + /** + * 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). + *

+ * @param containerPath the id of the container + * @return a new container entry + * + */ + public static IContainerEntry newContainerEntry(String 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. + *

+ * 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) { + 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. + * + * 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). + *

+ * @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. + * @param sourceAttachmentRootPath 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) { + 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. + * + * 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. + * @param sourceAttachmentRootPath 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) { + return newLibraryEntry(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. + *

+ * 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). Particular + * source entries cannot be selectively exported. + *

+ * + * @param path the absolute workspace-relative path of a source folder + * @return a new source entry with not exclusion patterns + * + */ + public static ISourceEntry newSourceEntry(IPath path) { + return newSourceEntry(path, SourceEntry.NO_EXCLUSION_PATTERNS); + } + + /** + * 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. + *

+ * + * @param path the absolute workspace-relative path of a source folder + * @param exclusionPatterns the possibly empty list of exclusion patterns + * represented as relative paths + * @return a new source entry with the given exclusion patterns + * + */ + public static ISourceEntry newSourceEntry(IPath path, IPath[] exclusionPatterns) { + return newSourceEntry(path, null, exclusionPatterns); + } + + /** + * 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. + *

+ * @param path the absolute workspace-relative path of a source folder + * @param exclusionPatterns 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) + * @return a new source entry with the given exclusion patterns + */ + public static ISourceEntry newSourceEntry(IPath path, IPath outputLocation, IPath[] exclusionPatterns) { + return new SourceEntry(path, outputLocation, true, exclusionPatterns); + } + + /** + * Creates and returns a new entry of kind CDT_INCLUDE + * @param path the affected worksapce-relative resource path + * @param includePath the absolute path of the include + * @return + */ + public static IIncludeEntry newIncludeEntry(IPath path, IPath includePath) { + return newIncludeEntry(path, includePath, false); + } + + /** + * Creates and returns a new entry of kind CDT_INCLUDE + * @param path the affected workspace-relative resource path + * @param includePath the absolute path of the include + * @param isSystemInclude wheter this include path should be consider the system include path + * @return + */ + public static IIncludeEntry newIncludeEntry(IPath path, IPath includePath, boolean isSystemInclude) { + return newIncludeEntry(path, includePath, isSystemInclude, true, IncludeEntry.NO_EXCLUSION_PATTERNS, true); + } + + /** + * Creates and returns a new entry of kind CDT_INCLUDE + * + * @param path the affected workspace-relative resource path + * @param includePath the absolute path of the include + * @param isSystemInclude 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 + * @param exclusionPatterns exclusion patterns in the resource if a container + * @param isExported whether this cpath is exported. + * @return + */ + 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); + } + + /** + * Creates and returns an entry kind CDT_MACRO + * @param path the affected workspace-relative resource path + * @param macroName the name of the macro + * @param macroValue the value of the macro + * @return + */ + public static IMacroEntry newMacroEntry(IPath path, String macroName, String macroValue) { + return newMacroEntry(path, macroName, macroValue, true, MacroEntry.NO_EXCLUSION_PATTERNS, true); + } + + /** + * Creates and returns an entry kind CDT_MACRO + * @param path the affected workspace-relative resource path + * @param macroName the name of the macro + * @param macroValue the value of the macro + * @param isRecursive 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) { + return new MacroEntry(path, macroName, macroValue, isRecursive, exclusionPatterns, isExported); + } + /** * TODO: this is a temporary hack until, the CDescriptor manager is * in place and could fire deltas of Parser change. @@ -206,7 +482,6 @@ public class CoreModel { private CoreModel() { } - public static void run(IWorkspaceRunnable action, IProgressMonitor monitor) throws CoreException { IWorkspace workspace = ResourcesPlugin.getWorkspace(); if (workspace.isTreeLocked()) { @@ -216,13 +491,12 @@ public class CoreModel { workspace.run(new BatchOperation(action), monitor); } } - - public void startIndexing() - { - manager.getIndexManager().reset(); + + public void startIndexing() { + manager.getIndexManager().reset(); } - - public IndexManager getIndexManager(){ + + public IndexManager getIndexManager() { return manager.getIndexManager(); } } 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/ICPathEntry.java new file mode 100644 index 00000000000..2a0562a8c8a --- /dev/null +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICPathEntry.java @@ -0,0 +1,96 @@ +/********************************************************************** + * 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; + + +public interface ICPathEntry { + + /** + * Entry kind constant describing a path entry identifying a + * library. A library is an archive containing + * consisting of pre-compiled binaries. + */ + int CDT_LIBRARY = 1; + + /** + * Entry kind constant describing a path entry identifying a + * required project. + */ + int CDT_PROJECT = 2; + + /** + * Entry kind constant describing a path entry identifying a + * folder containing source code to be compiled. + */ + int CDT_SOURCE = 3; + + /* + * Entry kind constant describing a path entry defined using + * a path that begins with a variable reference. + */ + int CDT_VARIABLE = 4; + + /** + * Entry kind constant describing a path entry identifying a + * include path. + */ + int CDT_INCLUDE = 5; + + /** + * Entry kind constant describing a path entry representing + * a container id. + * + */ + int CDT_CONTAINER = 6; + + /** + * Entry kind constant describing a path entry representing + * a macro definition. + * + */ + int CDT_MACRO = 7; + + /** + * Entry kind constant describing output location + * + */ + int CDT_OUTPUT = 8; + + /** + * Returns the kind of this path entry. + * + * @return one of: + *