1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-16 05:25:21 +02:00

2005-03-12 Alain Magloire

Plan item 79518: for PathEntry variable manager.
	* model/org/eclipse/cdt/internal/core/model/PathEntryManager.java
	* src/org/eclipse/cdt/core/resources/IPathEntryVariableManager.java
	* src/org/eclipse/cdt/core/resources/PathEntryVariableChangeEvent.java
	* src/org/eclipse/cdt/internal/core/PathEntryVariableManager.java
This commit is contained in:
Alain Magloire 2005-03-13 03:24:33 +00:00
parent 4be89c40a4
commit 512e196451
5 changed files with 74 additions and 28 deletions

View file

@ -1,3 +1,10 @@
2005-03-12 Alain Magloire
Plan item 79518: for PathEntry variable manager.
* model/org/eclipse/cdt/internal/core/model/PathEntryManager.java
* src/org/eclipse/cdt/core/resources/IPathEntryVariableManager.java
* src/org/eclipse/cdt/core/resources/PathEntryVariableChangeEvent.java
* src/org/eclipse/cdt/internal/core/PathEntryVariableManager.java
2005-03-03 Alain Magloire 2005-03-03 Alain Magloire
Part of plan item 79518: for PathEntry variable manager. Part of plan item 79518: for PathEntry variable manager.
* model/org/eclipse/cdt/internal/core/model/PathEntryManager.java * model/org/eclipse/cdt/internal/core/model/PathEntryManager.java

View file

@ -50,6 +50,7 @@ import org.eclipse.cdt.core.model.PathEntryContainerChanged;
import org.eclipse.cdt.core.model.PathEntryContainerInitializer; import org.eclipse.cdt.core.model.PathEntryContainerInitializer;
import org.eclipse.cdt.core.resources.IPathEntryStore; import org.eclipse.cdt.core.resources.IPathEntryStore;
import org.eclipse.cdt.core.resources.IPathEntryStoreListener; import org.eclipse.cdt.core.resources.IPathEntryStoreListener;
import org.eclipse.cdt.core.resources.IPathEntryVariableManager;
import org.eclipse.cdt.core.resources.PathEntryStoreChangedEvent; import org.eclipse.cdt.core.resources.PathEntryStoreChangedEvent;
import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
@ -375,7 +376,7 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
IPathEntry[] containerEntries = container.getPathEntries(); IPathEntry[] containerEntries = container.getPathEntries();
if (containerEntries != null) { if (containerEntries != null) {
for (int j = 0; j < containerEntries.length; j++) { for (int j = 0; j < containerEntries.length; j++) {
IPathEntry newEntry = cloneEntry(projectPath, containerEntries[j]); IPathEntry newEntry = cloneEntryAndExpand(projectPath, containerEntries[j]);
listEntries.add(newEntry); listEntries.add(newEntry);
} }
} }
@ -422,16 +423,16 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
IPathEntry[] containerEntries = container.getPathEntries(); IPathEntry[] containerEntries = container.getPathEntries();
if (containerEntries != null) { if (containerEntries != null) {
for (int j = 0; j < containerEntries.length; j++) { for (int j = 0; j < containerEntries.length; j++) {
IPathEntry newEntry = cloneEntry(projectPath, containerEntries[j]); IPathEntry newEntry = cloneEntryAndExpand(projectPath, containerEntries[j]);
resolvedEntries.add(newEntry); resolvedEntries.add(newEntry);
} }
} }
} else { } else {
resolvedEntries.add(cloneEntry(projectPath, entry)); resolvedEntries.add(cloneEntryAndExpand(projectPath, entry));
} }
} }
} else { } else {
IPathEntry clone = cloneEntry(projectPath, entry); IPathEntry clone = cloneEntryAndExpand(projectPath, entry);
IPathEntry e = getExpandedPathEntry(clone, cproject); IPathEntry e = getExpandedPathEntry(clone, cproject);
if (e != null) { if (e != null) {
resolvedEntries.add(e); resolvedEntries.add(e);
@ -1526,7 +1527,7 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
return false; return false;
} }
protected IPathEntry cloneEntry(IPath rpath, IPathEntry entry) { protected IPathEntry cloneEntryAndExpand(IPath rpath, IPathEntry entry) {
// get the path // get the path
IPath entryPath = entry.getPath(); IPath entryPath = entry.getPath();
@ -1534,18 +1535,42 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
entryPath = Path.EMPTY; entryPath = Path.EMPTY;
} }
IPath resourcePath = (entryPath.isAbsolute()) ? entryPath : rpath.append(entryPath); IPath resourcePath = (entryPath.isAbsolute()) ? entryPath : rpath.append(entryPath);
IPathEntryVariableManager varManager = CCorePlugin.getDefault().getPathEntryVariableManager();
switch (entry.getEntryKind()) { switch (entry.getEntryKind()) {
case IPathEntry.CDT_INCLUDE : { case IPathEntry.CDT_INCLUDE : {
IIncludeEntry include = (IIncludeEntry)entry; IIncludeEntry include = (IIncludeEntry)entry;
return CoreModel.newIncludeEntry(resourcePath, include.getBasePath(), include.getIncludePath(),
IPath basePath = include.getBasePath();
basePath = varManager.resolvePath(basePath);
IPath includePath = include.getIncludePath();
includePath = varManager.resolvePath(includePath);
return CoreModel.newIncludeEntry(resourcePath, basePath, includePath,
include.isSystemInclude(), include.getExclusionPatterns(), include.isExported()); include.isSystemInclude(), include.getExclusionPatterns(), include.isExported());
} }
case IPathEntry.CDT_LIBRARY : { case IPathEntry.CDT_LIBRARY : {
ILibraryEntry library = (ILibraryEntry)entry; ILibraryEntry library = (ILibraryEntry)entry;
return CoreModel.newLibraryEntry(resourcePath, library.getBasePath(), library.getLibraryPath(),
library.getSourceAttachmentPath(), library.getSourceAttachmentRootPath(), IPath basePath = library.getBasePath();
library.getSourceAttachmentPrefixMapping(), library.isExported()); basePath = varManager.resolvePath(basePath);
IPath libraryPath = library.getLibraryPath();
libraryPath = varManager.resolvePath(libraryPath);
IPath sourceAttachmentPath = library.getSourceAttachmentPath();
sourceAttachmentPath = varManager.resolvePath(sourceAttachmentPath);
IPath sourceAttachmentRootPath = library.getSourceAttachmentRootPath();
sourceAttachmentRootPath = varManager.resolvePath(sourceAttachmentRootPath);
IPath sourceAttachmentPrefixMapping = library.getSourceAttachmentPrefixMapping();
sourceAttachmentPrefixMapping = varManager.resolvePath(sourceAttachmentPrefixMapping);
return CoreModel.newLibraryEntry(resourcePath, basePath, libraryPath,
sourceAttachmentPath, sourceAttachmentRootPath,
sourceAttachmentPrefixMapping, library.isExported());
} }
case IPathEntry.CDT_MACRO : { case IPathEntry.CDT_MACRO : {
IMacroEntry macro = (IMacroEntry)entry; IMacroEntry macro = (IMacroEntry)entry;
@ -1564,8 +1589,9 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
ISourceEntry source = (ISourceEntry)entry; ISourceEntry source = (ISourceEntry)entry;
return CoreModel.newSourceEntry(resourcePath, source.getExclusionPatterns()); return CoreModel.newSourceEntry(resourcePath, source.getExclusionPatterns());
} }
case IPathEntry.CDT_CONTAINER : case IPathEntry.CDT_CONTAINER : {
return CoreModel.newContainerEntry(entry.getPath(), entry.isExported()); return CoreModel.newContainerEntry(entry.getPath(), entry.isExported());
}
} }
return entry; return entry;
} }

View file

@ -13,6 +13,7 @@
package org.eclipse.cdt.core.resources; package org.eclipse.cdt.core.resources;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
/** /**
* Manages a collection of variables * Manages a collection of variables
@ -53,7 +54,7 @@ public interface IPathEntryVariableManager {
* <li>The variable value is relative</li> * <li>The variable value is relative</li>
* </ul> * </ul>
*/ */
public void setValue(String name, String value) throws CoreException; public void setValue(String name, IPath value) throws CoreException;
/** /**
* Returns the value of the variable with the given name. If there is * Returns the value of the variable with the given name. If there is
@ -63,7 +64,7 @@ public interface IPathEntryVariableManager {
* @return the value for the variable, or <code>null</code> if there is no * @return the value for the variable, or <code>null</code> if there is no
* variable defined with the given name * variable defined with the given name
*/ */
public String getValue(String name); public IPath getValue(String name);
/** /**
* Returns an array containing all defined variable names. * Returns an array containing all defined variable names.
@ -120,7 +121,7 @@ public interface IPathEntryVariableManager {
* @param path the path to be resolved * @param path the path to be resolved
* @return the resolved path or <code>null</code> * @return the resolved path or <code>null</code>
*/ */
public String resolvePath(String path); public IPath resolvePath(IPath path);
/** /**
* Returns <code>true</code> if the given variable is defined and * Returns <code>true</code> if the given variable is defined and

View file

@ -14,6 +14,8 @@ package org.eclipse.cdt.core.resources;
import java.util.EventObject; import java.util.EventObject;
import org.eclipse.core.runtime.IPath;
/** /**
* Describes a change in path variable. * Describes a change in path variable.
*/ */
@ -38,7 +40,7 @@ public class PathEntryVariableChangeEvent extends EventObject {
/** /**
* The value of the changed variable (may be null). * The value of the changed variable (may be null).
*/ */
private String value; private IPath value;
/** The event type. */ /** The event type. */
private int type; private int type;
@ -46,7 +48,7 @@ public class PathEntryVariableChangeEvent extends EventObject {
/** /**
* Constructor for this class. * Constructor for this class.
*/ */
public PathEntryVariableChangeEvent(IPathEntryVariableManager source, String variableName, String value, int type) { public PathEntryVariableChangeEvent(IPathEntryVariableManager source, String variableName, IPath value, int type) {
super(source); super(source);
if (type < VARIABLE_CHANGED || type > VARIABLE_DELETED) if (type < VARIABLE_CHANGED || type > VARIABLE_DELETED)
throw new IllegalArgumentException("Invalid event type: " + type); //$NON-NLS-1$ throw new IllegalArgumentException("Invalid event type: " + type); //$NON-NLS-1$
@ -55,7 +57,7 @@ public class PathEntryVariableChangeEvent extends EventObject {
this.type = type; this.type = type;
} }
public String getValue() { public IPath getValue() {
return value; return value;
} }

View file

@ -23,7 +23,9 @@ import org.eclipse.cdt.core.resources.IPathEntryVariableChangeListener;
import org.eclipse.cdt.core.resources.IPathEntryVariableManager; import org.eclipse.cdt.core.resources.IPathEntryVariableManager;
import org.eclipse.cdt.core.resources.PathEntryVariableChangeEvent; import org.eclipse.cdt.core.resources.PathEntryVariableChangeEvent;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.ISafeRunnable; import org.eclipse.core.runtime.ISafeRunnable;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Preferences; import org.eclipse.core.runtime.Preferences;
@ -55,20 +57,24 @@ public class PathEntryVariableManager implements IPathEntryVariableManager {
* *
* @see org.eclipse.core.resources.IPathEntryVariableManager#getValue(String) * @see org.eclipse.core.resources.IPathEntryVariableManager#getValue(String)
*/ */
public String getValue(String varName) { public IPath getValue(String varName) {
String key = getKeyForName(varName); String key = getKeyForName(varName);
String value = preferences.getString(key); String value = preferences.getString(key);
return value.length() == 0 ? null : value; return value.length() == 0 ? null : Path.fromPortableString(value);
} }
/** /**
* @see org.eclipse.core.resources.IPathEntryVariableManager#setValue(String, IPath) * @see org.eclipse.core.resources.IPathEntryVariableManager#setValue(String, IPath)
*/ */
public void setValue(String varName, String newValue) throws CoreException { public void setValue(String varName, IPath newValue) throws CoreException {
//if the location doesn't have a device, see if the OS will assign one
if (newValue != null && newValue.isAbsolute() && newValue.getDevice() == null) {
newValue = new Path(newValue.toFile().getAbsolutePath());
}
int eventType; int eventType;
// read previous value and set new value atomically in order to generate the right event // read previous value and set new value atomically in order to generate the right event
synchronized (this) { synchronized (this) {
String currentValue = getValue(varName); IPath currentValue = getValue(varName);
boolean variableExists = currentValue != null; boolean variableExists = currentValue != null;
if (!variableExists && newValue == null) { if (!variableExists && newValue == null) {
return; return;
@ -80,7 +86,7 @@ public class PathEntryVariableManager implements IPathEntryVariableManager {
preferences.setToDefault(getKeyForName(varName)); preferences.setToDefault(getKeyForName(varName));
eventType = PathEntryVariableChangeEvent.VARIABLE_DELETED; eventType = PathEntryVariableChangeEvent.VARIABLE_DELETED;
} else { } else {
preferences.setValue(getKeyForName(varName), newValue); preferences.setValue(getKeyForName(varName), newValue.toPortableString());
eventType = variableExists ? PathEntryVariableChangeEvent.VARIABLE_CHANGED : PathEntryVariableChangeEvent.VARIABLE_CREATED; eventType = variableExists ? PathEntryVariableChangeEvent.VARIABLE_CHANGED : PathEntryVariableChangeEvent.VARIABLE_CREATED;
} }
} }
@ -98,12 +104,16 @@ public class PathEntryVariableManager implements IPathEntryVariableManager {
/** /**
* @see org.eclipse.core.resources.IPathEntryVariableManager#resolvePath(IPath) * @see org.eclipse.core.resources.IPathEntryVariableManager#resolvePath(IPath)
*/ */
public String resolvePath(String variable) { public IPath resolvePath(IPath path) {
if (variable == null || variable.length() == 0 || variable.indexOf('$') == -1) { if (path == null || path.segmentCount() == 0) {
return variable; return path;
}
String variable = path.toPortableString();
if (variable.indexOf('$') == -1) {
return path;
} }
String value = expandVariable(variable); String value = expandVariable(variable);
return value == null ? variable : value; return (value == null || value.length() == 0) ? Path.EMPTY : new Path(value);
} }
/** /**
@ -122,7 +132,7 @@ public class PathEntryVariableManager implements IPathEntryVariableManager {
* @see PathEntryVariableChangeEvent#VARIABLE_CHANGED * @see PathEntryVariableChangeEvent#VARIABLE_CHANGED
* @see PathEntryVariableChangeEvent#VARIABLE_DELETED * @see PathEntryVariableChangeEvent#VARIABLE_DELETED
*/ */
private void fireVariableChangeEvent(String name, String value, int type) { private void fireVariableChangeEvent(String name, IPath value, int type) {
if (this.listeners.size() == 0) if (this.listeners.size() == 0)
return; return;
// use a separate collection to avoid interference of simultaneous additions/removals // use a separate collection to avoid interference of simultaneous additions/removals
@ -228,7 +238,7 @@ public class PathEntryVariableManager implements IPathEntryVariableManager {
if (inMacro) { if (inMacro) {
inMacro = false; inMacro = false;
String p = param.toString(); String p = param.toString();
String v = getValue(p); String v = getValue(p).toPortableString();
if (v != null) { if (v != null) {
sb.append(v); sb.append(v);
} }