From 71bfb71873bb89846c830184cb7bd51f21723867 Mon Sep 17 00:00:00 2001 From: Alain Magloire Date: Mon, 23 Feb 2004 04:34:33 +0000 Subject: [PATCH] refactoring suite --- .../org/eclipse/cdt/core/model/CoreModel.java | 18 +++++------- .../eclipse/cdt/core/model/IPathEntry.java | 22 +++++++------- .../internal/core/model/CElementDelta.java | 13 +++++++++ .../cdt/internal/core/model/IncludeEntry.java | 4 +-- .../cdt/internal/core/model/PathEntry.java | 14 ++++----- .../internal/core/model/PathEntryManager.java | 29 ++++++++++--------- .../core/model/SetPathEntriesOperation.java | 22 +++++++------- 7 files changed, 67 insertions(+), 55 deletions(-) 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 de10638a474..2daf802dc64 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 @@ -406,14 +406,13 @@ public class CoreModel { * Creates and returns a new entry of kind CDT_INCLUDE * * @param path - * the affected worksapce-relative resource path, the path - * can pe empty or null if it is exported + * the affected worksapce-relative resource path * @param includePath * the absolute path of the include * @return IIncludeEntry */ - public static IIncludeEntry newIncludeEntry(IPath path, IPath includePath) { - return newIncludeEntry(path, includePath, false); + public static IIncludeEntry newIncludeEntry(IPath resourcePath, IPath includePath) { + return newIncludeEntry(resourcePath, includePath, false); } /** @@ -421,7 +420,6 @@ public class CoreModel { * * @param 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 @@ -429,15 +427,15 @@ public class CoreModel { * include path * @return IIncludeEntry */ - public static IIncludeEntry newIncludeEntry(IPath path, IPath includePath, boolean isSystemInclude) { - return newIncludeEntry(path, includePath, isSystemInclude, true, IncludeEntry.NO_EXCLUSION_PATTERNS); + public static IIncludeEntry newIncludeEntry(IPath resourcePath, IPath includePath, boolean isSystemInclude) { + return newIncludeEntry(resourcePath, 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 or null if global + * the affected workspace-relative resource path * @param includePath * the absolute path of the include * @param isSystemInclude @@ -450,9 +448,9 @@ public class CoreModel { * exclusion patterns in the resource if a container * @return IIincludeEntry */ - public static IIncludeEntry newIncludeEntry(IPath path, IPath includePath, boolean isSystemInclude, boolean isRecursive, + public static IIncludeEntry newIncludeEntry(IPath resourcePath, IPath includePath, boolean isSystemInclude, boolean isRecursive, IPath[] exclusionPatterns) { - return new IncludeEntry(path, includePath, isSystemInclude, isRecursive, exclusionPatterns); + return new IncludeEntry(resourcePath, includePath, isSystemInclude, isRecursive, exclusionPatterns); } /** diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IPathEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IPathEntry.java index 09fb6a41eef..f707d8282e0 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IPathEntry.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IPathEntry.java @@ -34,37 +34,37 @@ public interface IPathEntry { */ 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; + int CDT_INCLUDE = 4; /** * Entry kind constant describing a path entry representing * a container id. * */ - int CDT_CONTAINER = 6; + int CDT_CONTAINER = 5; /** * Entry kind constant describing a path entry representing * a macro definition. * */ - int CDT_MACRO = 7; + int CDT_MACRO = 6; /** * Entry kind constant describing output location * */ - int CDT_OUTPUT = 8; + int CDT_OUTPUT = 7; + + /** + * Entry kind constant describing an entry defined using + * a path that begins with a variable reference. + */ + int CDT_VARIABLE = 10; /** * Returns the kind of this path entry. @@ -75,8 +75,6 @@ public interface IPathEntry { its project *
  • CDT_LIBRARY - this entry describes a library *
  • CDT_PROJECT - this entry describes another project - *
  • CDT_VARIABLE - this entry describes a project or library - * indirectly via a variable in the first segment of the path *
  • CDT_INCLUDE - this entry describes a include path *
  • CDT_MACRO - this entry describes a macro definition *
  • CDT_CONTAINER - this entry describes a container id diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElementDelta.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElementDelta.java index e280042d280..299212c29e7 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElementDelta.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElementDelta.java @@ -670,6 +670,19 @@ public class CElementDelta implements ICElementDelta { buffer.append("MODIFIERS CHANGED"); //$NON-NLS-1$ prev = true; } + if ((changeFlags & ICElementDelta.F_ADDED_TO_PATHENTRY) != 0) { + if (prev) + buffer.append(" | "); //$NON-NLS-1$ + buffer.append("ADDED TO PATHENTRY"); //$NON-NLS-1$ + prev = true; + } + if ((changeFlags & ICElementDelta.F_REMOVED_FROM_PATHENTRY) != 0) { + if (prev) + buffer.append(" | "); //$NON-NLS-1$ + buffer.append("REMOVED FROM PATHENTRY"); //$NON-NLS-1$ + prev = true; + } + //if ((changeFlags & ICElementDelta.F_SUPER_TYPES) != 0) { // if (prev) // buffer.append(" | "); //$NON-NLS-1$ 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 f892675cbc5..df42df0536d 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 @@ -24,8 +24,8 @@ public class IncludeEntry extends APathEntry implements IIncludeEntry { 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; + super(IIncludeEntry.CDT_INCLUDE, isRecursive, exclusionPatterns, false); + this.resourcePath = resourcePath == null ? new Path("/") : resourcePath; this.includePath = includePath; this.isSystemInclude = isSystemInclude; } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntry.java index 6c46c0b902f..bbf09550279 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntry.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntry.java @@ -60,8 +60,8 @@ public class PathEntry implements IPathEntry { if (kindStr.equalsIgnoreCase("prj")) //$NON-NLS-1$ return IPathEntry.CDT_PROJECT; - if (kindStr.equalsIgnoreCase("var")) //$NON-NLS-1$ - return IPathEntry.CDT_VARIABLE; + //if (kindStr.equalsIgnoreCase("var")) //$NON-NLS-1$ + // return IPathEntry.CDT_VARIABLE; if (kindStr.equalsIgnoreCase("src")) //$NON-NLS-1$ return IPathEntry.CDT_SOURCE; if (kindStr.equalsIgnoreCase("lib")) //$NON-NLS-1$ @@ -87,8 +87,8 @@ public class PathEntry implements IPathEntry { return "src"; //$NON-NLS-1$ case IPathEntry.CDT_LIBRARY : return "lib"; //$NON-NLS-1$ - case IPathEntry.CDT_VARIABLE : - return "var"; //$NON-NLS-1$ + //case IPathEntry.CDT_VARIABLE : + // return "var"; //$NON-NLS-1$ case IPathEntry.CDT_INCLUDE : return "inc"; //$NON-NLS-1$ case IPathEntry.CDT_MACRO : @@ -116,9 +116,9 @@ public class PathEntry implements IPathEntry { case IPathEntry.CDT_SOURCE : buffer.append("CDT_SOURCE"); //$NON-NLS-1$ break; - case IPathEntry.CDT_VARIABLE : - buffer.append("CDT_VARIABLE"); //$NON-NLS-1$ - break; + //case IPathEntry.CDT_VARIABLE : + // buffer.append("CDT_VARIABLE"); //$NON-NLS-1$ + // break; case IPathEntry.CDT_INCLUDE : buffer.append("CDT_INCLUDE"); //$NON-NLS-1$ break; diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryManager.java index 4f532feeb73..272f33cd381 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryManager.java @@ -73,7 +73,6 @@ public class PathEntryManager { 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$ final static IPathEntry[] EMPTY = {}; @@ -137,9 +136,10 @@ public class PathEntryManager { 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); + IPathEntry[] oldResolvedEntries = (IPathEntry[])resolvedMap.get(cproject); resolvedMap.put(cproject, null); + SetPathEntriesOperation op = new SetPathEntriesOperation(cproject, oldResolvedEntries, newEntries); + CModelManager.getDefault().runOperation(op, monitor); } catch (CoreException e) { throw new CModelException(e); } @@ -211,6 +211,7 @@ public class PathEntryManager { } remaining++; oldResolvedEntries[i] = (IPathEntry[])resolvedMap.get(affectedProject); + resolvedMap.put(affectedProject, null); containerPut(affectedProject, containerPath, newContainer); } @@ -380,7 +381,7 @@ public class PathEntryManager { } return NO_PREREQUISITES; } - public void saveRawPathEntries(ICProject cproject, IPathEntry[] oldEntries, IPathEntry[] newEntries) throws CModelException { + public void saveRawPathEntries(ICProject cproject, IPathEntry[] newRawEntries) throws CModelException { try { ICDescriptor descriptor = CCorePlugin.getDefault().getCProjectDescription(cproject.getProject()); Element rootElement = descriptor.getProjectData(PATH_ENTRY_ID); @@ -392,10 +393,10 @@ public class PathEntryManager { } // Save the entries - if (newEntries != null && newEntries.length > 0) { + if (newRawEntries != null && newRawEntries.length > 0) { // Serialize the include paths Document doc = rootElement.getOwnerDocument(); - encodePathEntries(cproject.getPath(), doc, rootElement, newEntries); + encodePathEntries(cproject.getPath(), doc, rootElement, newRawEntries); } descriptor.saveProjectData(); } catch (CoreException e) { @@ -488,12 +489,12 @@ public class PathEntryManager { IContainerEntry container = (IContainerEntry) entry; celement = cproject; } - if (celement != null) { - CElementDelta delta = new CElementDelta(cproject.getCModel()); - delta.changed(celement, flag); - return delta; + if (celement == null) { + celement = cproject; } - return null; + CElementDelta delta = new CElementDelta(cproject.getCModel()); + delta.changed(celement, flag); + return delta; } static String[] getRegisteredContainerIDs() { @@ -597,7 +598,7 @@ public class PathEntryManager { case IPathEntry.CDT_INCLUDE : { - // include path info (optional + // include path info IPath includePath = element.hasAttribute(ATTRIBUTE_INCLUDE) ? new Path(element.getAttribute(ATTRIBUTE_INCLUDE)) : null; // isSysteminclude @@ -622,7 +623,7 @@ public class PathEntryManager { case IPathEntry.CDT_CONTAINER : { - IPath id = new Path(element.getAttribute(ATTRIBUTE_ID)); + IPath id = new Path(element.getAttribute(ATTRIBUTE_PATH)); return CoreModel.newContainerEntry(id, isExported); } @@ -705,7 +706,7 @@ public class PathEntryManager { element.setAttribute(ATTRIBUTE_VALUE, macro.getMacroValue()); } else if (kind == IPathEntry.CDT_CONTAINER) { IContainerEntry container = (IContainerEntry) entries[i]; - element.setAttribute(ATTRIBUTE_ID, container.getPath().toString()); + element.setAttribute(ATTRIBUTE_PATH, 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/SetPathEntriesOperation.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SetPathEntriesOperation.java index 620d2a2e3f3..88c426b1f15 100644 --- 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 @@ -35,14 +35,14 @@ public class SetPathEntriesOperation extends CModelOperation { */ static final String[] NO_PREREQUISITES = new String[0]; - IPathEntry[] oldEntries; - IPathEntry[] newEntries; + IPathEntry[] oldResolvedEntries; + IPathEntry[] newRawEntries; ICProject cproject; - public SetPathEntriesOperation(ICProject project, IPathEntry[] oldEntries, IPathEntry[] newEntries) { + public SetPathEntriesOperation(ICProject project, IPathEntry[] oldResolvedEntries, IPathEntry[] newRawEntries) { super(project); - this.oldEntries = oldEntries; - this.newEntries = newEntries; + this.oldResolvedEntries = oldResolvedEntries; + this.newRawEntries = newRawEntries; this.cproject = project; } @@ -52,9 +52,11 @@ public class SetPathEntriesOperation extends CModelOperation { protected void executeOperation() throws CModelException { // project reference updated - may throw an exception if unable to write .cdtproject file updateProjectReferencesIfNecessary(); - PathEntryManager mgr = PathEntryManager.getDefault(); - mgr.saveRawPathEntries(cproject, oldEntries, newEntries); - ICElementDelta[] deltas = mgr.generatePathEntryDeltas(cproject, oldEntries, newEntries); + PathEntryManager mgr = PathEntryManager.getDefault(); + mgr.saveRawPathEntries(cproject, newRawEntries); + hasModifiedResource = true; + IPathEntry[] newResolvedEntries = mgr.getResolvedPathEntries(cproject); + ICElementDelta[] deltas = mgr.generatePathEntryDeltas(cproject, oldResolvedEntries, newResolvedEntries); for (int i = 0; i < deltas.length; i++) { addDelta(deltas[i]); } @@ -63,8 +65,8 @@ public class SetPathEntriesOperation extends CModelOperation { protected void updateProjectReferencesIfNecessary() throws CModelException { PathEntryManager mgr = PathEntryManager.getDefault(); - String[] oldRequired = mgr.projectPrerequisites(oldEntries); - String[] newRequired = mgr.projectPrerequisites(newEntries); + String[] oldRequired = mgr.projectPrerequisites(oldResolvedEntries); + String[] newRequired = mgr.projectPrerequisites(newRawEntries); try { IProject projectResource = cproject.getProject();