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 f7dda7b3f10..002705bf348 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 @@ -12,9 +12,6 @@ *******************************************************************************/ package org.eclipse.cdt.core.model; -import java.net.URI; -import java.util.List; - import org.eclipse.cdt.core.CCProjectNature; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CProjectNature; @@ -62,6 +59,9 @@ import org.eclipse.core.runtime.Plugin; import org.eclipse.core.runtime.content.IContentType; import org.eclipse.core.runtime.jobs.ISchedulingRule; +import java.net.URI; +import java.util.List; + /** * @noextend This class is not intended to be subclassed by clients. * @noinstantiate This class is not intended to be instantiated by clients. @@ -71,9 +71,6 @@ public class CoreModel { private static CModelManager manager = CModelManager.getDefault(); private static PathEntryManager pathEntryManager = PathEntryManager.getDefault(); private static CProjectDescriptionManager descriptionManager = CProjectDescriptionManager.getInstance(); - -// private static String FILE_EXT_PATTERN = "*."; //$NON-NLS-1$ -// private static int FILE_EXT_PATTERN_LENGTH = FILE_EXT_PATTERN.length(); public final static String CORE_MODEL_ID = CCorePlugin.PLUGIN_ID + ".coremodel"; //$NON-NLS-1$ @@ -90,7 +87,7 @@ public class CoreModel { public ITranslationUnit createTranslationUnitFrom(ICProject cproject, IPath path) { return manager.createTranslationUnitFrom(cproject, path); } - + /** * Creates a translation from a location URI. Returns null if not found. * @since 5.0 @@ -101,12 +98,12 @@ public class CoreModel { /** * Returns the C model element corresponding to the given handle identifier - * generated by ICElement.getHandleIdentifier(), or - * null if unable to create the associated element. + * generated by {@code ICElement.getHandleIdentifier()}, or + * {@code null} if unable to create the associated element. * * @param handleIdentifier the given handle identifier * @return the C element corresponding to the handle identifier - * + * * @since 5.0 */ public static ICElement create(String handleIdentifier) { @@ -151,9 +148,9 @@ public class CoreModel { /** * Returns the C model. - * + * * @param root the given root - * @return the C model, or null if the root is null + * @return the C model, or {@code null} if the root is null */ public static ICModel create(IWorkspaceRoot root) { if (root == null) { @@ -161,6 +158,7 @@ public class CoreModel { } return manager.getCModel(); } + /** * Returns the default ICModel. */ @@ -279,8 +277,9 @@ public class CoreModel { if (contentType != null) { String id = contentType.getId(); if (CCorePlugin.CONTENT_TYPE_CHEADER.equals(id) - || CCorePlugin.CONTENT_TYPE_CXXHEADER.equals(id)) + || CCorePlugin.CONTENT_TYPE_CXXHEADER.equals(id)) { return false; + } return CCorePlugin.CONTENT_TYPE_CSOURCE.equals(id) || CCorePlugin.CONTENT_TYPE_CXXSOURCE.equals(id) @@ -384,34 +383,26 @@ public class CoreModel { * Return true if project has C nature. */ public static boolean hasCNature(IProject project) { - boolean ok = false; try { - ok = (project.isOpen() && project.hasNature(CProjectNature.C_NATURE_ID)); + return project.isOpen() && project.hasNature(CProjectNature.C_NATURE_ID); } catch (CoreException e) { - //throws exception if the project is not open. - //System.out.println (e); - //e.printStackTrace(); } - return ok; + return false; } /** * Return true if project has C++ nature. */ public static boolean hasCCNature(IProject project) { - boolean ok = false; try { - ok = (project.isOpen() && project.hasNature(CCProjectNature.CC_NATURE_ID)); + return project.isOpen() && project.hasNature(CCProjectNature.CC_NATURE_ID); } catch (CoreException e) { - //throws exception if the project is not open. - //System.out.println (e); - //e.printStackTrace(); } - return ok; + return false; } /** - * Creates and returns a new non-exported entry of kind CDT_PROJECT + * Creates and returns a new non-exported entry of kind {@code CDT_PROJECT} * for the project identified by the given absolute path. *

* A project entry is used to denote a prerequisite project. The @@ -421,13 +412,13 @@ public class CoreModel { * to the workspace root. *

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

- * + * * @param projectPath * the workspace-relative path of the project * @return a new project entry - * + * * @see CoreModel#newProjectEntry(IPath, boolean) */ public static IProjectEntry newProjectEntry(IPath projectPath) { @@ -435,7 +426,7 @@ public class CoreModel { } /** - * Creates and returns a new entry of kind CDT_PROJECT for + * Creates and returns a new entry of kind {@code CDT_PROJECT} for * the project identified by the given workspace-relative path. *

* A project entry is used to denote a prerequisite project. All the @@ -443,7 +434,7 @@ public class CoreModel { * prerequisite project is referred to using an absolute path relative to * the workspace root. *

- * + * * @param projectPath * the absolute workspace-relative path of the prerequisite project * @param isExported @@ -456,31 +447,31 @@ public class CoreModel { } /** - * Creates and returns a new entry of kind CDT_CONTAINER for + * Creates and returns a new entry of kind {@code 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). + * is equivalent to {@code newContainerEntry(path, false)}. *

- * + * * @param id the id of the container * @return a new container entry - * + * */ public static IContainerEntry newContainerEntry(IPath id) { return newContainerEntry(id, false); } /** - * Creates and returns a new entry of kind CDT_CONTAINER for + * Creates and returns a new entry of kind {@code 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). + * is equivalent to {@code newContainerEntry(path,false)}. *

*/ public static IContainerEntry newContainerEntry(IPath id, boolean isExported) { @@ -488,9 +479,9 @@ public class CoreModel { } /** - * Creates and returns a new entry of kind CDT_LIBRARY + * Creates and returns a new entry of kind {@code CDT_LIBRARY} * for the archive or folder identified by the given absolute path. - * + * * @param resourcePath * the affected project-relative resource path * @param baseRef @@ -498,7 +489,7 @@ public class CoreModel { * @param libraryPath * the library name. * @return a new library entry - * + * */ public static ILibraryEntry newLibraryRefEntry(IPath resourcePath, IPath baseRef, IPath libraryPath) { return new LibraryEntry(resourcePath, null, baseRef, libraryPath, null, null, null, false); @@ -506,13 +497,13 @@ public class CoreModel { /** - * Creates and returns a new entry of kind CDT_LIBRARY + * Creates and returns a new entry of kind {@code 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 resourcePath * the affected project-relative resource path * @param basePath @@ -521,16 +512,16 @@ public class CoreModel { * the path of the library * @param sourceAttachmentPath * the project-relative path of the corresponding source archive or - * folder, or null if none. + * folder, or {@code null} if none. * @param sourceAttachmentRootPath * the location of the root within the source archive or folder - * or null. + * or {@code null}. * @param sourceAttachmentPrefixMapping - * prefix mapping or null. + * prefix mapping or {@code null}. * @param isExported * whether the entry is exported * @return a new library entry - * + * */ public static ILibraryEntry newLibraryEntry(IPath resourcePath, IPath basePath, IPath libraryPath, IPath sourceAttachmentPath, IPath sourceAttachmentRootPath, IPath sourceAttachmentPrefixMapping, boolean isExported) { @@ -538,23 +529,23 @@ public class CoreModel { } /** - * Creates and returns a new entry of kind CDT_OUTPUT for + * Creates and returns a new entry of kind {@code CDT_OUTPUT} for * the project's output folder *

- * + * * @param outputPath * the project-relative path of a folder * @return a new source entry with not exclusion patterns - * + * */ public static IOutputEntry newOutputEntry(IPath outputPath) { return newOutputEntry(outputPath, APathEntry.NO_EXCLUSION_PATTERNS); } /** - * Creates and returns a new entry of kind CDT_OUPUT for + * Creates and returns a new entry of kind {@code CDT_OUPUT} for * the project - * + * * @param outputPath * the project-relative path of a folder * @param exclusionPatterns @@ -567,46 +558,46 @@ public class CoreModel { } /** - * Creates and returns a new entry of kind CDT_SOURCE for + * Creates and returns a new entry of kind {@code 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 + * workspace root, e.g. {@code /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. + * specifying the path {@code /P1/src} is only usable for project + * {@code P1}. *

*

*

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

- * + * * @param sourcePath * the project-relative path of a source folder * @return a new source entry with not exclusion patterns - * + * */ public static ISourceEntry newSourceEntry(IPath sourcePath) { return newSourceEntry(sourcePath, APathEntry.NO_EXCLUSION_PATTERNS); } /** - * Creates and returns a new entry of kind CDT_SOURCE for + * Creates and returns a new entry of kind {@code 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. + * fragments within the root will have children of type {@code ICompilationUnit}. *

* The source folder is referred to using an absolute path relative to the - * workspace root, e.g. /Project/src. A project's source + * workspace root, e.g. {@code /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. + * specifying the path {@code /P1/src} is only usable for project + * {@code P1}. *

- * + * * @param sourcePath * the absolute project-relative path of a source folder * @param exclusionPatterns @@ -619,8 +610,8 @@ public class CoreModel { } /** - * Creates and returns a new entry of kind CDT_INCLUDE - * + * Creates and returns a new entry of kind {@code CDT_INCLUDE} + * * @param resourcePath * the affected project-relative resource path * @param basePath @@ -634,8 +625,8 @@ public class CoreModel { } /** - * * Creates and returns a new entry of kind CDT_INCLUDE - * + * * Creates and returns a new entry of kind {@code CDT_INCLUDE} + * * @param resourcePath * the affected project-relative resource path * @param basePath @@ -651,8 +642,8 @@ public class CoreModel { } /** - * Creates and returns a new entry of kind CDT_INCLUDE - * + * Creates and returns a new entry of kind {@code CDT_INCLUDE} + * * @param resourcePath * the affected project-relative resource path * @param basePath @@ -671,8 +662,8 @@ public class CoreModel { } /** - * Creates and returns a new entry of kind CDT_INCLUDE - * + * Creates and returns a new entry of kind {@code CDT_INCLUDE} + * * @param resourcePath * the affected project-relative resource path * @param basePath @@ -694,8 +685,8 @@ public class CoreModel { } /** - * Creates and returns a new entry of kind CDT_INCLUDE - * + * Creates and returns a new entry of kind {@code CDT_INCLUDE} + * * @param resourcePath * the affected project-relative resource path * @param baseRef @@ -709,15 +700,15 @@ public class CoreModel { } /** - * Creates a new entry of kind CDT_INCLUDE_FILE + * Creates a new entry of kind {@code CDT_INCLUDE_FILE} */ public static IIncludeFileEntry newIncludeFileEntry(IPath resourcePath, IPath includeFile) { return newIncludeFileEntry(resourcePath, null, null, includeFile, null, false); } /** - * Creates and returns a new entry of kind CDT_INCLUDE_FILE - * + * Creates and returns a new entry of kind {@code CDT_INCLUDE_FILE} + * * @param resourcePath * the affected project-relative resource path * @param basePath @@ -736,8 +727,8 @@ public class CoreModel { } /** - * Creates and returns an entry kind CDT_MACRO - * + * Creates and returns an entry kind {@code CDT_MACRO} + * * @param resourcePath * the affected project-relative resource path * @param macroName @@ -751,8 +742,8 @@ public class CoreModel { } /** - * Creates and returns an entry kind CDT_MACRO - * + * Creates and returns an entry kind {@code CDT_MACRO} + * * @param resourcePath * the affected project-relative resource path * @param macroName @@ -767,8 +758,8 @@ public class CoreModel { } /** - * Creates and returns an entry kind CDT_MACRO - * + * Creates and returns an entry kind {@code CDT_MACRO} + * * @param resourcePath * the affected workspace-relative resource path * @param macroName @@ -783,8 +774,8 @@ public class CoreModel { } /** - * Creates and returns an entry kind CDT_MACRO - * + * Creates and returns an entry kind {@code CDT_MACRO} + * * @param resourcePath * the affected workspace-relative resource path * @param baseRef @@ -797,15 +788,15 @@ public class CoreModel { } /** - * Creates an entry kind CDT_MACRO_FILE + * Creates an entry kind {@code CDT_MACRO_FILE} */ public static IMacroFileEntry newMacroFileEntry(IPath resourcePath, IPath macroFile) { return newMacroFileEntry(resourcePath, null, null, macroFile, null, false); } /** - * Creates and returns an entry kind CDT_MACRO_FILE - * + * Creates and returns an entry kind {@code CDT_MACRO_FILE} + * * @param resourcePath * the affected workspace-relative resource path * @param basePath @@ -822,36 +813,36 @@ public class CoreModel { /** * Answers the project specific value for a given container. In case this - * container path could not be resolved, then will answer null. + * container path could not be resolved, then will answer {@code 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 + * (using {@code setPathEntryContainer}, then a {@code 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 + * recommended to register a {@code 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 + * @return the corresponding container or {@code 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(ICProject[], IPathEntryContainer, IProgressMonitor) @@ -861,7 +852,7 @@ public class CoreModel { } /** - * Bind a container reference path to some actual containers (IPathEntryContainer). + * Bind a container reference path to some actual containers ({@code IPathEntryContainer}). * This API must be invoked whenever changes in container need to be * reflected onto the CModel. *

@@ -872,15 +863,15 @@ public class CoreModel { *

* 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 + * recommended to register a {@code 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 + * Note: setting a container to {@code 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 container - @@ -898,11 +889,11 @@ public class CoreModel { } /** - * Helper method use by a pathentry container implementing IPathEntryContainerExtension + * Helper method use by a path entry container implementing {@code IPathEntryContainerExtension} * It notify the model of changes. - * Note: the paths in the PathEntryContainerChanged[] array must be on + * Note: the paths in the {@code PathEntryContainerChanged[]} array must be on * source that the container was set too. If not the changes will be silently ignore. - * + * * @param container * @param changes array of changes. * @param monitor progress monitor @@ -914,11 +905,11 @@ public class CoreModel { /** * Sets the pathentries of this project using a list of entries. *

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

- * + * * @param newEntries * a list of entries * @param monitor @@ -932,9 +923,9 @@ public class CoreModel { /** * Returns the raw pathentries for the project. This corresponds to the - * exact set of entries which were assigned using setRawPathEntries + * exact set of entries which were assigned using {@code setRawPathEntries} *

- * + * * @return the raw entires for the project * @exception CModelException * if this element does not exist or if an exception occurs @@ -955,7 +946,7 @@ public class CoreModel { * date. Because of this, hanging on resolved pathentries is not * recommended. *

- * + * * @return the resolved entries for the project * @exception CModelException * @see IPathEntry @@ -973,7 +964,7 @@ public class CoreModel { * date. Because of this, hanging on resolved pathentries is not * recommended. *

- * + * * @return the include entries for the translation unit * @exception CModelException * @see IPathEntry @@ -991,7 +982,7 @@ public class CoreModel { * date. Because of this, hanging on resolved pathentries is not * recommended. *

- * + * * @return the include file entries for the translation unit * @exception CModelException * @see IPathEntry @@ -1009,7 +1000,7 @@ public class CoreModel { * date. Because of this, hanging on resolved pathentries is not * recommended. *

- * + * * @return the resolved entries for the project * @exception CModelException * @see IPathEntry @@ -1027,7 +1018,7 @@ public class CoreModel { * date. Because of this, hanging on resolved pathentries is not * recommended. *

- * + * * @return the macro file entries for the translation unit * @exception CModelException * @see IPathEntry @@ -1038,18 +1029,18 @@ public class CoreModel { /** * Helper method finding the pathentry container initializer registered for - * a given container ID or null if none was found while + * a given container ID or {@code 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. + * container initializer or {@code null} if none was found. */ public static PathEntryContainerInitializer getPathEntryContainerInitializer(String containerID) { return pathEntryManager.getPathEntryContainerInitializer(containerID); @@ -1065,7 +1056,7 @@ public class CoreModel { /** * Set in the map the store, but not persisted. - * + * * @param project * @param store */ @@ -1077,29 +1068,38 @@ public class CoreModel { * Validate a given path entries for a project, using the following rules: *