mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-01 14:15:23 +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:
parent
4be89c40a4
commit
512e196451
5 changed files with 74 additions and 28 deletions
|
@ -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
|
||||
Part of plan item 79518: for PathEntry variable manager.
|
||||
* model/org/eclipse/cdt/internal/core/model/PathEntryManager.java
|
||||
|
|
|
@ -50,6 +50,7 @@ import org.eclipse.cdt.core.model.PathEntryContainerChanged;
|
|||
import org.eclipse.cdt.core.model.PathEntryContainerInitializer;
|
||||
import org.eclipse.cdt.core.resources.IPathEntryStore;
|
||||
import org.eclipse.cdt.core.resources.IPathEntryStoreListener;
|
||||
import org.eclipse.cdt.core.resources.IPathEntryVariableManager;
|
||||
import org.eclipse.cdt.core.resources.PathEntryStoreChangedEvent;
|
||||
import org.eclipse.core.resources.IMarker;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
|
@ -375,7 +376,7 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
|
|||
IPathEntry[] containerEntries = container.getPathEntries();
|
||||
if (containerEntries != null) {
|
||||
for (int j = 0; j < containerEntries.length; j++) {
|
||||
IPathEntry newEntry = cloneEntry(projectPath, containerEntries[j]);
|
||||
IPathEntry newEntry = cloneEntryAndExpand(projectPath, containerEntries[j]);
|
||||
listEntries.add(newEntry);
|
||||
}
|
||||
}
|
||||
|
@ -422,16 +423,16 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
|
|||
IPathEntry[] containerEntries = container.getPathEntries();
|
||||
if (containerEntries != null) {
|
||||
for (int j = 0; j < containerEntries.length; j++) {
|
||||
IPathEntry newEntry = cloneEntry(projectPath, containerEntries[j]);
|
||||
IPathEntry newEntry = cloneEntryAndExpand(projectPath, containerEntries[j]);
|
||||
resolvedEntries.add(newEntry);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
resolvedEntries.add(cloneEntry(projectPath, entry));
|
||||
resolvedEntries.add(cloneEntryAndExpand(projectPath, entry));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
IPathEntry clone = cloneEntry(projectPath, entry);
|
||||
IPathEntry clone = cloneEntryAndExpand(projectPath, entry);
|
||||
IPathEntry e = getExpandedPathEntry(clone, cproject);
|
||||
if (e != null) {
|
||||
resolvedEntries.add(e);
|
||||
|
@ -1526,7 +1527,7 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
|
|||
return false;
|
||||
}
|
||||
|
||||
protected IPathEntry cloneEntry(IPath rpath, IPathEntry entry) {
|
||||
protected IPathEntry cloneEntryAndExpand(IPath rpath, IPathEntry entry) {
|
||||
|
||||
// get the path
|
||||
IPath entryPath = entry.getPath();
|
||||
|
@ -1534,18 +1535,42 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
|
|||
entryPath = Path.EMPTY;
|
||||
}
|
||||
IPath resourcePath = (entryPath.isAbsolute()) ? entryPath : rpath.append(entryPath);
|
||||
|
||||
|
||||
IPathEntryVariableManager varManager = CCorePlugin.getDefault().getPathEntryVariableManager();
|
||||
switch (entry.getEntryKind()) {
|
||||
case IPathEntry.CDT_INCLUDE : {
|
||||
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());
|
||||
}
|
||||
case IPathEntry.CDT_LIBRARY : {
|
||||
ILibraryEntry library = (ILibraryEntry)entry;
|
||||
return CoreModel.newLibraryEntry(resourcePath, library.getBasePath(), library.getLibraryPath(),
|
||||
library.getSourceAttachmentPath(), library.getSourceAttachmentRootPath(),
|
||||
library.getSourceAttachmentPrefixMapping(), library.isExported());
|
||||
|
||||
IPath basePath = library.getBasePath();
|
||||
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 : {
|
||||
IMacroEntry macro = (IMacroEntry)entry;
|
||||
|
@ -1564,8 +1589,9 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
|
|||
ISourceEntry source = (ISourceEntry)entry;
|
||||
return CoreModel.newSourceEntry(resourcePath, source.getExclusionPatterns());
|
||||
}
|
||||
case IPathEntry.CDT_CONTAINER :
|
||||
case IPathEntry.CDT_CONTAINER : {
|
||||
return CoreModel.newContainerEntry(entry.getPath(), entry.isExported());
|
||||
}
|
||||
}
|
||||
return entry;
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
package org.eclipse.cdt.core.resources;
|
||||
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
|
||||
/**
|
||||
* Manages a collection of variables
|
||||
|
@ -53,7 +54,7 @@ public interface IPathEntryVariableManager {
|
|||
* <li>The variable value is relative</li>
|
||||
* </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
|
||||
|
@ -63,7 +64,7 @@ public interface IPathEntryVariableManager {
|
|||
* @return the value for the variable, or <code>null</code> if there is no
|
||||
* variable defined with the given name
|
||||
*/
|
||||
public String getValue(String name);
|
||||
public IPath getValue(String name);
|
||||
|
||||
/**
|
||||
* Returns an array containing all defined variable names.
|
||||
|
@ -120,7 +121,7 @@ public interface IPathEntryVariableManager {
|
|||
* @param path the path to be resolved
|
||||
* @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
|
||||
|
|
|
@ -14,6 +14,8 @@ package org.eclipse.cdt.core.resources;
|
|||
|
||||
import java.util.EventObject;
|
||||
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
|
||||
/**
|
||||
* Describes a change in path variable.
|
||||
*/
|
||||
|
@ -38,7 +40,7 @@ public class PathEntryVariableChangeEvent extends EventObject {
|
|||
/**
|
||||
* The value of the changed variable (may be null).
|
||||
*/
|
||||
private String value;
|
||||
private IPath value;
|
||||
|
||||
/** The event type. */
|
||||
private int type;
|
||||
|
@ -46,7 +48,7 @@ public class PathEntryVariableChangeEvent extends EventObject {
|
|||
/**
|
||||
* 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);
|
||||
if (type < VARIABLE_CHANGED || type > VARIABLE_DELETED)
|
||||
throw new IllegalArgumentException("Invalid event type: " + type); //$NON-NLS-1$
|
||||
|
@ -55,7 +57,7 @@ public class PathEntryVariableChangeEvent extends EventObject {
|
|||
this.type = type;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
public IPath getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,9 @@ import org.eclipse.cdt.core.resources.IPathEntryVariableChangeListener;
|
|||
import org.eclipse.cdt.core.resources.IPathEntryVariableManager;
|
||||
import org.eclipse.cdt.core.resources.PathEntryVariableChangeEvent;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.ISafeRunnable;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.core.runtime.Preferences;
|
||||
|
||||
|
@ -55,20 +57,24 @@ public class PathEntryVariableManager implements IPathEntryVariableManager {
|
|||
*
|
||||
* @see org.eclipse.core.resources.IPathEntryVariableManager#getValue(String)
|
||||
*/
|
||||
public String getValue(String varName) {
|
||||
public IPath getValue(String varName) {
|
||||
String key = getKeyForName(varName);
|
||||
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)
|
||||
*/
|
||||
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;
|
||||
// read previous value and set new value atomically in order to generate the right event
|
||||
synchronized (this) {
|
||||
String currentValue = getValue(varName);
|
||||
IPath currentValue = getValue(varName);
|
||||
boolean variableExists = currentValue != null;
|
||||
if (!variableExists && newValue == null) {
|
||||
return;
|
||||
|
@ -80,7 +86,7 @@ public class PathEntryVariableManager implements IPathEntryVariableManager {
|
|||
preferences.setToDefault(getKeyForName(varName));
|
||||
eventType = PathEntryVariableChangeEvent.VARIABLE_DELETED;
|
||||
} else {
|
||||
preferences.setValue(getKeyForName(varName), newValue);
|
||||
preferences.setValue(getKeyForName(varName), newValue.toPortableString());
|
||||
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)
|
||||
*/
|
||||
public String resolvePath(String variable) {
|
||||
if (variable == null || variable.length() == 0 || variable.indexOf('$') == -1) {
|
||||
return variable;
|
||||
public IPath resolvePath(IPath path) {
|
||||
if (path == null || path.segmentCount() == 0) {
|
||||
return path;
|
||||
}
|
||||
String variable = path.toPortableString();
|
||||
if (variable.indexOf('$') == -1) {
|
||||
return path;
|
||||
}
|
||||
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_DELETED
|
||||
*/
|
||||
private void fireVariableChangeEvent(String name, String value, int type) {
|
||||
private void fireVariableChangeEvent(String name, IPath value, int type) {
|
||||
if (this.listeners.size() == 0)
|
||||
return;
|
||||
// use a separate collection to avoid interference of simultaneous additions/removals
|
||||
|
@ -228,7 +238,7 @@ public class PathEntryVariableManager implements IPathEntryVariableManager {
|
|||
if (inMacro) {
|
||||
inMacro = false;
|
||||
String p = param.toString();
|
||||
String v = getValue(p);
|
||||
String v = getValue(p).toPortableString();
|
||||
if (v != null) {
|
||||
sb.append(v);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue