mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
refactoring suite
This commit is contained in:
parent
0faa6b124c
commit
71bfb71873
7 changed files with 67 additions and 55 deletions
|
@ -406,14 +406,13 @@ public class CoreModel {
|
|||
* Creates and returns a new entry of kind <code>CDT_INCLUDE</code>
|
||||
*
|
||||
* @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 <code>CDT_INCLUDE</code>
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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
|
||||
* <li><code>CDT_LIBRARY</code> - this entry describes a library
|
||||
* <li><code>CDT_PROJECT</code> - this entry describes another project
|
||||
* <li><code>CDT_VARIABLE</code> - this entry describes a project or library
|
||||
* indirectly via a variable in the first segment of the path
|
||||
* <li><code>CDT_INCLUDE</code> - this entry describes a include path
|
||||
* <li><code>CDT_MACRO</code> - this entry describes a macro definition
|
||||
* <li><code>CDT_CONTAINER</code> - this entry describes a container id
|
||||
|
|
|
@ -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$
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Reference in a new issue