Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMikhail Sennikovsky2007-02-27 12:13:30 +0000
committerMikhail Sennikovsky2007-02-27 12:13:30 +0000
commit975547bcca5fd29c67942e501ec2634d5799331d (patch)
treed6db45ed5dd8908748f129fd043af35603eb0278
parent39237a89b0fb7822d3c3f95d1288a84f7527c861 (diff)
downloadorg.eclipse.cdt-975547bcca5fd29c67942e501ec2634d5799331d.tar.gz
org.eclipse.cdt-975547bcca5fd29c67942e501ec2634d5799331d.tar.xz
org.eclipse.cdt-975547bcca5fd29c67942e501ec2634d5799331d.zip
1. Fix for the [Bug 175675] ClassCastException when parsing a file
2. Path Entry Variable Manager functionality is made as a wrapper over the Workspace-level Cdt Variables (aka Build Macros) functionality 3. bug-fixes
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/dataprovider/ConfigurationDataProvider.java2
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/PathEntryResolveInfoElement.java1
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/PathEntryTranslator.java12
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CLanguageSetting.java58
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CLanguageSettingCache.java32
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CProjectDescriptionManager.java58
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/DescriptionScannerInfoProvider.java23
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java5
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/CdtVarPathEntryVariableManager.java253
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/PathEntryVariableManager.java13
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/ICdtVariableChangeListener.java15
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/UserDefinedVariableSupplier.java282
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/VariableChangeEvent.java37
13 files changed, 722 insertions, 69 deletions
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/dataprovider/ConfigurationDataProvider.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/dataprovider/ConfigurationDataProvider.java
index 8b364b8f38f..30220c21fab 100644
--- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/dataprovider/ConfigurationDataProvider.java
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/dataprovider/ConfigurationDataProvider.java
@@ -297,7 +297,7 @@ public class ConfigurationDataProvider extends CConfigurationDataProvider implem
Tool tool = (Tool)tc.createTool(extTool, id, name, false);
InputType type = (InputType)tool.getInputTypes()[0];
type = (InputType)tool.getEdtableInputType(type);
- type.setSourceContentTypes(type.getSourceContentTypes());
+ type.setSourceContentTypes(des.getContentTypes());
type.setLanguageNameAttribute(des.getName());
type.setName(des.getName());
type.setLanguageIdAttribute(des.getId());
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/PathEntryResolveInfoElement.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/PathEntryResolveInfoElement.java
index 4f5c50ee6d1..2f6dc612980 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/PathEntryResolveInfoElement.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/PathEntryResolveInfoElement.java
@@ -10,7 +10,6 @@
*******************************************************************************/
package org.eclipse.cdt.core.settings.model.util;
-import java.util.ArrayList;
import java.util.List;
import org.eclipse.cdt.core.model.IPathEntry;
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/PathEntryTranslator.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/PathEntryTranslator.java
index 449cec54f80..7dc11664bf4 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/PathEntryTranslator.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/PathEntryTranslator.java
@@ -31,6 +31,7 @@ import org.eclipse.cdt.core.model.ILibraryEntry;
import org.eclipse.cdt.core.model.IMacroEntry;
import org.eclipse.cdt.core.model.IMacroFileEntry;
import org.eclipse.cdt.core.model.IPathEntry;
+import org.eclipse.cdt.core.resources.IPathEntryVariableManager;
import org.eclipse.cdt.core.settings.model.CIncludeFileEntry;
import org.eclipse.cdt.core.settings.model.CIncludePathEntry;
import org.eclipse.cdt.core.settings.model.CLibraryFileEntry;
@@ -556,12 +557,21 @@ public class PathEntryTranslator {
do{
// IPath p;
// IPath inc = getIncludePath();
+ IPath unresolvedBase = basePath;
+ IPath unresolvedValue = valuePath;
+ IPathEntryVariableManager mngr = CCorePlugin.getDefault().getPathEntryVariableManager();
+
+ basePath = mngr.resolvePath(basePath);
+ valuePath = mngr.resolvePath(valuePath);
+
if (!basePath.isEmpty()) {
IPath loc = basePath;
if (!loc.isAbsolute()) {
ResourceInfo rcInfo = findResourceInfo(fRoot, loc.append(valuePath), !isFile);
if (rcInfo.fExists) {
fResourceInfo = rcInfo;
+ fName = unresolvedBase.append(unresolvedValue).toString();
+ fValue = fName;
// fFullPath = fResourceInfo.fRc.getFullPath();
// fLocation = fResourceInfo.fRc.getLocation();
// fName = fValuePath.toString();
@@ -570,6 +580,8 @@ public class PathEntryTranslator {
}
}
fLocation = loc.append(valuePath);
+ fName = unresolvedBase.append(unresolvedValue).toString();
+ fValue = fName;
// fName = fValuePath.toString();
// fValue = fValuePath.toString();
break;
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CLanguageSetting.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CLanguageSetting.java
index 18b9504bd27..9ba4e6dbba3 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CLanguageSetting.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CLanguageSetting.java
@@ -11,7 +11,6 @@
package org.eclipse.cdt.internal.core.settings.model;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
@@ -23,12 +22,6 @@ import org.eclipse.cdt.core.settings.model.extension.impl.CDefaultLanguageData;
import org.eclipse.cdt.core.settings.model.util.CDataUtil;
import org.eclipse.cdt.core.settings.model.util.EntryStore;
import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.ProjectScope;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.content.IContentType;
-import org.eclipse.core.runtime.content.IContentTypeManager;
-import org.eclipse.core.runtime.content.IContentTypeSettings;
-import org.eclipse.core.runtime.preferences.IScopeContext;
public class CLanguageSetting extends CDataProxy implements
ICLanguageSetting {
@@ -97,36 +90,6 @@ public class CLanguageSetting extends CDataProxy implements
return (getSupportedEntryKinds() & kind) == kind;
}
- public String[] getContentTypeFileSpecs (IContentType type) {
- String[] globalSpecs = type.getFileSpecs(IContentType.FILE_EXTENSION_SPEC);
- IContentTypeSettings settings = null;
- IProject project = getProject();
- if (project != null) {
- IScopeContext projectScope = new ProjectScope(project);
- try {
- settings = type.getSettings(projectScope);
- } catch (Exception e) {}
- if (settings != null) {
- String[] specs = settings.getFileSpecs(IContentType.FILE_EXTENSION_SPEC);
- if (specs.length > 0) {
- int total = globalSpecs.length + specs.length;
- String[] projSpecs = new String[total];
- int i=0;
- for (int j=0; j<specs.length; j++) {
- projSpecs[i] = specs[j];
- i++;
- }
- for (int j=0; j<globalSpecs.length; j++) {
- projSpecs[i] = globalSpecs[j];
- i++;
- }
- return projSpecs;
- }
- }
- }
- return globalSpecs;
- }
-
private IProject getProject(){
return getConfiguration().getProjectDescription().getProject();
}
@@ -153,28 +116,13 @@ public class CLanguageSetting extends CDataProxy implements
String[] exts = null;
String[] typeIds = data.getSourceContentTypeIds();
if(typeIds != null && typeIds.length != 0){
- IContentTypeManager manager = Platform.getContentTypeManager();
- IContentType type;
- if(typeIds.length == 1){
- type = manager.getContentType(typeIds[0]);
- if(type != null)
- exts = getContentTypeFileSpecs(type);
- } else {
- List list = new ArrayList();
- for(int i = 0; i < typeIds.length; i++){
- type = manager.getContentType(typeIds[i]);
- if(type != null) {
- list.addAll(Arrays.asList(getContentTypeFileSpecs(type)));
- }
- }
- exts = (String[])list.toArray(new String[list.size()]);
- }
+ exts = CProjectDescriptionManager.getInstance().getExtensionsFromContentTypes(getProject(), typeIds);
} else {
exts = data.getSourceExtensions();
- if(exts != null)
+ if(exts != null && exts.length != 0)
exts = (String[])exts.clone();
else
- exts = new String[0];
+ exts = CDefaultLanguageData.EMPTY_STRING_ARRAY;
}
if(exts == null)
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CLanguageSettingCache.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CLanguageSettingCache.java
index a599cdcad73..77e67e1c426 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CLanguageSettingCache.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CLanguageSettingCache.java
@@ -21,11 +21,13 @@ import org.eclipse.cdt.core.settings.model.extension.CLanguageData;
import org.eclipse.cdt.core.settings.model.extension.impl.CDefaultLanguageData;
import org.eclipse.cdt.core.settings.model.util.CDataUtil;
import org.eclipse.cdt.core.settings.model.util.EntryStore;
+import org.eclipse.core.resources.IProject;
public class CLanguageSettingCache extends CDefaultLanguageData implements
ICLanguageSetting, ICachedData {
private ICResourceDescription fParent;
protected EntryStore fResolvedEntriesStore;
+ private String fCachedExtensions[];
public CLanguageSettingCache(CLanguageData base, CFolderDescriptionCache folderCache) {
fId = base.getId();
@@ -51,7 +53,7 @@ public class CLanguageSettingCache extends CDefaultLanguageData implements
fResolvedEntriesStore = new EntryStore();
}
- ICLanguageSettingEntry[] resolved = fResolvedEntriesStore.getEntries();
+ ICLanguageSettingEntry[] resolved = fResolvedEntriesStore.getEntries(kind);
if(resolved.length == 0){
resolved = CDataUtil.resolveEntries(entries, getConfiguration());
fResolvedEntriesStore.storeEntries(kind, resolved);
@@ -62,7 +64,35 @@ public class CLanguageSettingCache extends CDefaultLanguageData implements
return entries;
}
+ private IProject getProject(){
+ return getConfiguration().getProjectDescription().getProject();
+ }
+
+ public String[] getSourceExtensions() {
+ if(fCachedExtensions == null ){
+ String[] typeIds = getSourceContentTypeIds();
+ String exts[] = null;
+ if(typeIds != null && typeIds.length != 0){
+ exts = CProjectDescriptionManager.getInstance().getExtensionsFromContentTypes(getProject(), typeIds);
+ } else {
+ exts = super.getSourceExtensions();
+ if(exts != null && exts.length != 0)
+ exts = (String[])exts.clone();
+ else
+ exts = CDefaultLanguageData.EMPTY_STRING_ARRAY;
+ }
+
+ if(exts == null)
+ exts = CDefaultLanguageData.EMPTY_STRING_ARRAY;
+ fCachedExtensions = exts;
+ }
+
+ if(fCachedExtensions.length != 0)
+ return (String[])fCachedExtensions.clone();
+ return fCachedExtensions;
+ }
+
public ICLanguageSettingEntry[] getSettingEntries(int kind) {
// int kinds[] = KindBasedStore.getSupportedKinds();
// List list = new ArrayList();
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CProjectDescriptionManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CProjectDescriptionManager.java
index 87ff43f30fa..ccccc4c423b 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CProjectDescriptionManager.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/CProjectDescriptionManager.java
@@ -70,6 +70,7 @@ import org.eclipse.cdt.core.settings.model.extension.CResourceData;
import org.eclipse.cdt.core.settings.model.extension.ICProjectConverter;
import org.eclipse.cdt.core.settings.model.extension.impl.CDataFacroty;
import org.eclipse.cdt.core.settings.model.extension.impl.CDefaultConfigurationData;
+import org.eclipse.cdt.core.settings.model.extension.impl.CDefaultLanguageData;
import org.eclipse.cdt.core.settings.model.util.CDataUtil;
import org.eclipse.cdt.core.settings.model.util.KindBasedStore;
import org.eclipse.cdt.core.settings.model.util.ListComparator;
@@ -89,6 +90,7 @@ import org.eclipse.core.resources.ISavedState;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.IWorkspaceRunnable;
+import org.eclipse.core.resources.ProjectScope;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IExtension;
@@ -103,9 +105,11 @@ import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.content.IContentType;
import org.eclipse.core.runtime.content.IContentTypeManager;
+import org.eclipse.core.runtime.content.IContentTypeSettings;
import org.eclipse.core.runtime.jobs.IJobManager;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.core.runtime.preferences.IScopeContext;
import org.osgi.framework.Version;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -2828,4 +2832,58 @@ public class CProjectDescriptionManager {
return data != null && !PathEntryConfigurationDataProvider.isPathEntryData(data);
}
+
+ public String[] getContentTypeFileSpecs (IProject project, IContentType type) {
+ String[] globalSpecs = type.getFileSpecs(IContentType.FILE_EXTENSION_SPEC);
+ IContentTypeSettings settings = null;
+ if (project != null) {
+ IScopeContext projectScope = new ProjectScope(project);
+ try {
+ settings = type.getSettings(projectScope);
+ } catch (Exception e) {}
+ if (settings != null) {
+ String[] specs = settings.getFileSpecs(IContentType.FILE_EXTENSION_SPEC);
+ if (specs.length > 0) {
+ int total = globalSpecs.length + specs.length;
+ String[] projSpecs = new String[total];
+ int i=0;
+ for (int j=0; j<specs.length; j++) {
+ projSpecs[i] = specs[j];
+ i++;
+ }
+ for (int j=0; j<globalSpecs.length; j++) {
+ projSpecs[i] = globalSpecs[j];
+ i++;
+ }
+ return projSpecs;
+ }
+ }
+ }
+ return globalSpecs;
+ }
+ public String[] getExtensionsFromContentTypes(IProject project, String[] typeIds){
+ String[] exts = null;
+ if(typeIds != null && typeIds.length != 0){
+ IContentTypeManager manager = Platform.getContentTypeManager();
+ IContentType type;
+ if(typeIds.length == 1){
+ type = manager.getContentType(typeIds[0]);
+ if(type != null)
+ exts = getContentTypeFileSpecs(project, type);
+ } else {
+ List list = new ArrayList();
+ for(int i = 0; i < typeIds.length; i++){
+ type = manager.getContentType(typeIds[i]);
+ if(type != null) {
+ list.addAll(Arrays.asList(getContentTypeFileSpecs(project, type)));
+ }
+ }
+ exts = (String[])list.toArray(new String[list.size()]);
+ }
+ }
+
+ if(exts == null)
+ exts = CDefaultLanguageData.EMPTY_STRING_ARRAY;
+ return exts;
+ }
}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/DescriptionScannerInfoProvider.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/DescriptionScannerInfoProvider.java
index 2468b0c9b16..3232d0b0948 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/DescriptionScannerInfoProvider.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/settings/model/DescriptionScannerInfoProvider.java
@@ -100,18 +100,33 @@ public class DescriptionScannerInfoProvider implements IScannerInfoProvider, ICP
return info;
}
+ private static ICLanguageSettingPathEntry[] getPathEntries(ICLanguageSetting ls, int kind){
+ ICLanguageSettingEntry entries[] = ls.getResolvedSettingEntries(kind);
+ ICLanguageSettingPathEntry pathEntries[] = new ICLanguageSettingPathEntry[entries.length];
+ System.arraycopy(entries, 0, pathEntries, 0, entries.length);
+
+ return pathEntries;
+ }
+
+ private static ICMacroEntry[] getMacroEntries(ICLanguageSetting ls){
+ ICLanguageSettingEntry entries[] = ls.getResolvedSettingEntries(ICLanguageSettingEntry.MACRO);
+ ICMacroEntry macroEntries[] = new ICMacroEntry[entries.length];
+ System.arraycopy(entries, 0, macroEntries, 0, entries.length);
+
+ return macroEntries;
+ }
private IScannerInfo createScannerInfo(ICLanguageSetting ls){
- ICLanguageSettingPathEntry pathEntries[] = (ICLanguageSettingPathEntry[])ls.getResolvedSettingEntries(ICLanguageSettingEntry.INCLUDE_PATH);
+ ICLanguageSettingPathEntry pathEntries[] = getPathEntries(ls, ICLanguageSettingEntry.INCLUDE_PATH);
String incs[] = getValues(pathEntries);
- pathEntries = (ICLanguageSettingPathEntry[])ls.getResolvedSettingEntries(ICLanguageSettingEntry.INCLUDE_FILE);
+ pathEntries = getPathEntries(ls, ICLanguageSettingEntry.INCLUDE_FILE);
String incFiles[] = getValues(pathEntries);
- pathEntries = (ICLanguageSettingPathEntry[])ls.getResolvedSettingEntries(ICLanguageSettingEntry.MACRO_FILE);
+ pathEntries = getPathEntries(ls, ICLanguageSettingEntry.MACRO_FILE);
String macroFiles[] = getValues(pathEntries);
- ICMacroEntry macroEntries[] = (ICMacroEntry[])ls.getResolvedSettingEntries(ICLanguageSettingEntry.MACRO);
+ ICMacroEntry macroEntries[] = getMacroEntries(ls);
Map macrosMap = getValues(macroEntries);
return new ExtendedScannerInfo(macrosMap, incs, macroFiles, incFiles);
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java
index 42b8627d743..cff56723c2e 100644
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java
@@ -40,6 +40,7 @@ import org.eclipse.cdt.core.settings.model.WriteAccessException;
import org.eclipse.cdt.internal.core.CConfigBasedDescriptorManager;
import org.eclipse.cdt.internal.core.CContentTypes;
import org.eclipse.cdt.internal.core.CDTLogWriter;
+import org.eclipse.cdt.internal.core.CdtVarPathEntryVariableManager;
import org.eclipse.cdt.internal.core.PathEntryVariableManager;
import org.eclipse.cdt.internal.core.PositionTrackerManager;
import org.eclipse.cdt.internal.core.cdtvariables.CdtVariableManager;
@@ -187,7 +188,7 @@ public class CCorePlugin extends Plugin {
private PDOMManager pdomManager;
- private PathEntryVariableManager fPathEntryVariableManager;
+ private CdtVarPathEntryVariableManager fPathEntryVariableManager;
// -------- static methods --------
@@ -329,7 +330,7 @@ public class CCorePlugin extends Plugin {
fDescriptorManager = fNewCProjectDescriptionManager.getDescriptorManager();
// Start file type manager first !!
- fPathEntryVariableManager = new PathEntryVariableManager();
+ fPathEntryVariableManager = new CdtVarPathEntryVariableManager();
fPathEntryVariableManager.startup();
cdtLog = new CDTLogWriter(CCorePlugin.getDefault().getStateLocation().append(".log").toFile()); //$NON-NLS-1$
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/CdtVarPathEntryVariableManager.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/CdtVarPathEntryVariableManager.java
new file mode 100644
index 00000000000..86de6e94b83
--- /dev/null
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/CdtVarPathEntryVariableManager.java
@@ -0,0 +1,253 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Intel Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Intel Corporation - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.cdtvariables.CdtVariableException;
+import org.eclipse.cdt.core.cdtvariables.ICdtVariable;
+import org.eclipse.cdt.core.resources.IPathEntryVariableChangeListener;
+import org.eclipse.cdt.core.resources.IPathEntryVariableManager;
+import org.eclipse.cdt.core.resources.PathEntryVariableChangeEvent;
+import org.eclipse.cdt.internal.core.cdtvariables.ICdtVariableChangeListener;
+import org.eclipse.cdt.internal.core.cdtvariables.ICoreVariableContextInfo;
+import org.eclipse.cdt.internal.core.cdtvariables.UserDefinedVariableSupplier;
+import org.eclipse.cdt.internal.core.cdtvariables.VariableChangeEvent;
+import org.eclipse.cdt.utils.cdtvariables.CdtVariableResolver;
+import org.eclipse.cdt.utils.cdtvariables.ICdtVariableSupplier;
+import org.eclipse.cdt.utils.cdtvariables.IVariableContextInfo;
+import org.eclipse.cdt.utils.cdtvariables.SupplierBasedCdtVariableSubstitutor;
+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.SafeRunner;
+
+/**
+ * the path entry variable manager is kept for the backward compatibility purposes
+ * currently it presents workspace Cdt variables that hold either a file or folder value
+ *
+ */
+public class CdtVarPathEntryVariableManager implements
+ IPathEntryVariableManager, ICdtVariableChangeListener {
+ private UserDefinedVariableSupplier fUserVarSupplier = UserDefinedVariableSupplier.getInstance();
+ private VarSubstitutor fSubstitutor = new VarSubstitutor();
+ private VarSupplier fVarSupplier = new VarSupplier();
+ private Set fListeners;
+
+ private class VarSubstitutor extends SupplierBasedCdtVariableSubstitutor {
+ public VarSubstitutor() {
+ super(new VarContextInfo(), "", " ");
+ }
+ }
+
+ private class VarContextInfo implements IVariableContextInfo {
+
+ public IVariableContextInfo getNext() {
+ return null;
+ }
+
+ public ICdtVariableSupplier[] getSuppliers() {
+ return new ICdtVariableSupplier[]{fVarSupplier};
+ }
+
+ public boolean equals(Object obj) {
+ if(obj == this)
+ return true;
+
+ if(!(obj instanceof VarContextInfo))
+ return false;
+
+ return true;
+ }
+
+ }
+
+ private class VarSupplier implements ICdtVariableSupplier {
+
+ public ICdtVariable getVariable(String macroName,
+ IVariableContextInfo context) {
+ ICdtVariable var = fUserVarSupplier.getMacro(macroName, ICoreVariableContextInfo.CONTEXT_WORKSPACE, null);
+ if(var != null && getVariablePath(var) != null)
+ return var;
+ return null;
+ }
+
+ public ICdtVariable[] getVariables(IVariableContextInfo context) {
+ ICdtVariable vars[] = fUserVarSupplier.getMacros(ICoreVariableContextInfo.CONTEXT_WORKSPACE, null);
+ List list = new ArrayList();
+ for(int i = 0; i < vars.length; i++){
+ if(getVariablePath(vars[i]) != null)
+ list.add(vars[i]);
+ }
+ return (ICdtVariable[])list.toArray(new ICdtVariable[list.size()]);
+ }
+
+ }
+
+
+
+ public CdtVarPathEntryVariableManager(){
+ fListeners = Collections.synchronizedSet(new HashSet());
+ fUserVarSupplier.addListener(this);
+ }
+
+ public IPath getValue(String name) {
+ ICdtVariable var = fUserVarSupplier.getMacro(name, ICoreVariableContextInfo.CONTEXT_WORKSPACE, null);
+ return getVariablePath(var);
+ }
+
+ public static IPath getVariablePath(ICdtVariable var){
+ if(var != null){
+ switch(var.getValueType()){
+ case ICdtVariable.VALUE_PATH_ANY:
+ case ICdtVariable.VALUE_PATH_DIR:
+ case ICdtVariable.VALUE_PATH_FILE:
+ try {
+ String value = var.getStringValue();
+ if(value != null)
+ return new Path(value);
+ return Path.EMPTY;
+ } catch (CdtVariableException e) {
+ CCorePlugin.log(e);
+ }
+ }
+ }
+ return null;
+ }
+
+ public String[] getVariableNames() {
+ ICdtVariable[] vars = fUserVarSupplier.getMacros(ICoreVariableContextInfo.CONTEXT_WORKSPACE, null);
+ ArrayList list = new ArrayList();
+ for(int i = 0; i > vars.length; i++){
+ if(getVariablePath(vars[i]) != null)
+ list.add(vars[i].getName());
+ }
+ return (String[])list.toArray(new String[list.size()]);
+ }
+
+ public boolean isDefined(String name) {
+ return getValue(name) != null;
+ }
+
+ public IPath resolvePath(IPath path) {
+ String str = path.toPortableString();
+
+ try {
+ str = CdtVariableResolver.resolveToString(str, fSubstitutor);
+ } catch (CdtVariableException e) {
+ CCorePlugin.log(e);
+ }
+
+ return new Path(str);
+ }
+
+ public void setValue(String name, IPath value) throws CoreException {
+ if(value != null)
+ fUserVarSupplier.createMacro(name, ICdtVariable.VALUE_PATH_ANY, value.toString(), ICoreVariableContextInfo.CONTEXT_WORKSPACE, null);
+ else
+ fUserVarSupplier.deleteMacro(name, ICoreVariableContextInfo.CONTEXT_WORKSPACE, null);
+
+ fUserVarSupplier.storeWorkspaceVariables(false);
+ }
+
+ /**
+ * Fires a property change event corresponding to a change to the
+ * current value of the variable with the given name.
+ *
+ * @param name the name of the variable, to be used as the variable
+ * in the event object
+ * @param value the current value of the path variable or <code>null</code> if
+ * the variable was deleted
+ * @param type one of <code>IPathVariableChangeEvent.VARIABLE_CREATED</code>,
+ * <code>PathEntryVariableChangeEvent.VARIABLE_CHANGED</code>, or
+ * <code>PathEntryVariableChangeEvent.VARIABLE_DELETED</code>
+ * @see PathEntryVariableChangeEvent
+ * @see PathEntryVariableChangeEvent#VARIABLE_CREATED
+ * @see PathEntryVariableChangeEvent#VARIABLE_CHANGED
+ * @see PathEntryVariableChangeEvent#VARIABLE_DELETED
+ */
+ private void fireVariableChangeEvent(String name, IPath value, int type) {
+ if (this.fListeners.size() == 0)
+ return;
+ // use a separate collection to avoid interference of simultaneous additions/removals
+ Object[] listenerArray = this.fListeners.toArray();
+ final PathEntryVariableChangeEvent pve = new PathEntryVariableChangeEvent(this, name, value, type);
+ for (int i = 0; i < listenerArray.length; ++i) {
+ final IPathEntryVariableChangeListener l = (IPathEntryVariableChangeListener) listenerArray[i];
+ ISafeRunnable job = new ISafeRunnable() {
+ public void handleException(Throwable exception) {
+ // already being logged in Platform#run()
+ }
+
+ public void run() throws Exception {
+ l.pathVariableChanged(pve);
+ }
+ };
+ SafeRunner.run(job);
+ }
+ }
+
+ /**
+ * @see org.eclipse.core.resources.
+ * IPathEntryVariableManager#addChangeListener(IPathEntryVariableChangeListener)
+ */
+ public void addChangeListener(IPathEntryVariableChangeListener listener) {
+ fListeners.add(listener);
+ }
+
+ /**
+ * @see org.eclipse.core.resources.
+ * IPathEntryVariableManager#removeChangeListener(IPathEntryVariableChangeListener)
+ */
+ public void removeChangeListener(IPathEntryVariableChangeListener listener) {
+ fListeners.remove(listener);
+ }
+
+ public void variablesChanged(VariableChangeEvent event) {
+ ICdtVariable[] added = event.getAddedVariables();
+ ICdtVariable[] removed = event.getRemovedVariables();
+ ICdtVariable[] changed = event.getChangedVariables();
+
+ if(added.length != 0){
+ fireEvent(added, PathEntryVariableChangeEvent.VARIABLE_CREATED);
+ }
+
+ if(removed.length != 0){
+ fireEvent(removed, PathEntryVariableChangeEvent.VARIABLE_DELETED);
+ }
+
+ if(changed.length != 0){
+ fireEvent(changed, PathEntryVariableChangeEvent.VARIABLE_CHANGED);
+ }
+ }
+
+ private void fireEvent(ICdtVariable vars[], int type){
+ for(int i = 0; i < vars.length; i++){
+ IPath path = getVariablePath(vars[i]);
+ if(path != null)
+ fireVariableChangeEvent(vars[i].getName(), path, type);
+ }
+
+ }
+
+ public void startup(){
+ }
+
+ public void shutdown(){
+ }
+
+}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/PathEntryVariableManager.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/PathEntryVariableManager.java
index 0dd51fc88d3..4470134a195 100644
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/PathEntryVariableManager.java
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/PathEntryVariableManager.java
@@ -44,8 +44,17 @@ public class PathEntryVariableManager implements IPathEntryVariableManager {
/**
* Constructor for the class.
- */
- public PathEntryVariableManager() {
+ *
+ * The current manager implementation is not used any more
+ * Instead the CdtVarPathEntryVariableManager is used that actually wraps the CdtVariables contributed at workspace level
+ *
+ * NOTE: all PathEntryVariableManager functionality remains workable with the new
+ * CdtVarPathEntryVariableManager. We could either remove this class or copy the contents of the
+ * CdtVarPathEntryVariableManager to this class to preserve internal class name for better backward compatibility.
+ *
+ *
+ */
+ private PathEntryVariableManager() {
this.listeners = Collections.synchronizedSet(new HashSet());
this.preferences = CCorePlugin.getDefault().getPluginPreferences();
}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/ICdtVariableChangeListener.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/ICdtVariableChangeListener.java
new file mode 100644
index 00000000000..79740cd4bef
--- /dev/null
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/ICdtVariableChangeListener.java
@@ -0,0 +1,15 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Intel Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Intel Corporation - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.cdtvariables;
+
+public interface ICdtVariableChangeListener {
+ void variablesChanged(VariableChangeEvent event);
+}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/UserDefinedVariableSupplier.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/UserDefinedVariableSupplier.java
index 94bd5902e6c..decee3d318c 100644
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/UserDefinedVariableSupplier.java
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/UserDefinedVariableSupplier.java
@@ -15,6 +15,11 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -28,13 +33,15 @@ import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.cdtvariables.CdtVariableException;
import org.eclipse.cdt.core.cdtvariables.ICdtVariable;
-import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.core.settings.model.ICStorageElement;
+import org.eclipse.cdt.core.settings.model.util.CDataUtil;
import org.eclipse.cdt.core.settings.model.util.XmlStorageElement;
import org.eclipse.cdt.internal.core.settings.model.CConfigurationSpecSettings;
import org.eclipse.cdt.internal.core.settings.model.ExceptionFactory;
import org.eclipse.cdt.internal.core.settings.model.IInternalCCfgInfo;
+import org.eclipse.cdt.utils.cdtvariables.CdtVariableResolver;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.preferences.InstanceScope;
@@ -54,10 +61,13 @@ public class UserDefinedVariableSupplier extends CoreMacroSupplierBase {
// public static final String MACROS_ELEMENT_NAME = "macros"; //$NON-NLS-1$
public static final String NODENAME = "macros"; //$NON-NLS-1$
public static final String PREFNAME_WORKSPACE = "workspace"; //$NON-NLS-1$
+ static final String OLD_VARIABLE_PREFIX = "pathEntryVariable."; //$NON-NLS-1$
+
private static UserDefinedVariableSupplier fInstance;
private StorableCdtVariables fWorkspaceMacros;
+ private Set fListeners;
private StorableCdtVariables getStorableMacros(int contextType, Object contextData){
StorableCdtVariables macros = null;
@@ -83,7 +93,7 @@ public class UserDefinedVariableSupplier extends CoreMacroSupplierBase {
}
private UserDefinedVariableSupplier(){
-
+ fListeners = Collections.synchronizedSet(new HashSet());
}
public static UserDefinedVariableSupplier getInstance(){
@@ -127,12 +137,21 @@ public class UserDefinedVariableSupplier extends CoreMacroSupplierBase {
if(macros == null)
return null;
+ ICdtVariable oldVar = macros.getMacro(macroName);
+
ICdtVariable macro = macros.createMacro(macroName,type,value);
if(macros.isChanged()){
setRebuildStateForContext(contextType, contextData);
macros.setChanged(false);
}
+ if(macro != null){
+ VariableChangeEvent event = createVariableChangeEvent(macro, oldVar);
+ if(event != null){
+ notifyListeners(event);
+ }
+ }
+
return macro;
}
@@ -148,12 +167,21 @@ public class UserDefinedVariableSupplier extends CoreMacroSupplierBase {
if(macros == null)
return null;
+ ICdtVariable oldVar = macros.getMacro(macroName);
+
ICdtVariable macro = macros.createMacro(macroName,type,value);
if(macros.isChanged()){
setRebuildStateForContext(contextType, contextData);
macros.setChanged(false);
}
+ if(macro != null){
+ VariableChangeEvent event = createVariableChangeEvent(macro, oldVar);
+ if(event != null){
+ notifyListeners(event);
+ }
+ }
+
return macro;
}
@@ -168,12 +196,20 @@ public class UserDefinedVariableSupplier extends CoreMacroSupplierBase {
if(macros == null)
return null;
+ ICdtVariable oldVar = macros.getMacro(macroName);
+
ICdtVariable macro = macros.createMacro(copy);
if(macros.isChanged()){
setRebuildStateForContext(contextType, contextData);
macros.setChanged(false);
}
+ if(macro != null){
+ VariableChangeEvent event = createVariableChangeEvent(macro, oldVar);
+ if(event != null){
+ notifyListeners(event);
+ }
+ }
return macro;
}
@@ -182,8 +218,15 @@ public class UserDefinedVariableSupplier extends CoreMacroSupplierBase {
if(macros == null)
return null;
ICdtVariable macro = macros.deleteMacro(name);
- if(macro != null)
+ if(macro != null){
setRebuildStateForContext(contextType, contextData);
+
+ VariableChangeEvent event = createVariableChangeEvent(null, macro);
+ if(event != null){
+ notifyListeners(event);
+ }
+
+ }
return macro;
}
@@ -193,8 +236,16 @@ public class UserDefinedVariableSupplier extends CoreMacroSupplierBase {
if(macros == null)
return;
+ ICdtVariable[] oldVars = macros.getMacros();
+
if(macros.deleteAll())
setRebuildStateForContext(contextType, contextData);
+
+ VariableChangeEvent event = createVariableChangeEvent(null, oldVars);
+ if(event != null){
+ notifyListeners(event);
+ }
+
}
public void setMacros(ICdtVariable m[], int contextType, Object contextData){
@@ -202,11 +253,183 @@ public class UserDefinedVariableSupplier extends CoreMacroSupplierBase {
if(macros == null)
return;
+ ICdtVariable[] oldVars = macros.getMacros();
+
macros.setMacros(m);
if(macros.isChanged()){
setRebuildStateForContext(contextType, contextData);
macros.setChanged(false);
+
+ VariableChangeEvent event = createVariableChangeEvent(m, oldVars);
+ if(event != null){
+ notifyListeners(event);
+ }
+
+ }
+ }
+
+ private static class VarKey {
+ private ICdtVariable fVar;
+ private boolean fNameOnly;
+
+ VarKey(ICdtVariable var, boolean nameOnly){
+ fVar = var;
+ fNameOnly = nameOnly;
+ }
+
+ public ICdtVariable getVariable(){
+ return fVar;
+ }
+
+ public boolean equals(Object obj) {
+ if(obj == this)
+ return true;
+
+ if(!(obj instanceof VarKey))
+ return false;
+
+ VarKey other = (VarKey)obj;
+
+ ICdtVariable otherVar = other.fVar;
+
+ if(fVar == otherVar)
+ return true;
+
+ if(!CDataUtil.objectsEqual(fVar.getName(), otherVar.getName()))
+ return false;
+
+ if(fNameOnly)
+ return true;
+
+ if(fVar.getValueType() != otherVar.getValueType())
+ return false;
+
+ if(CdtVariableResolver.isStringListVariable(fVar.getValueType())){
+ try {
+ if(!Arrays.equals(fVar.getStringListValue(), otherVar.getStringListValue()))
+ return false;
+ } catch (CdtVariableException e) {
+ CCorePlugin.log(e);
+ }
+ } else {
+ try {
+ if(!CDataUtil.objectsEqual(fVar.getStringValue(), otherVar.getStringValue()))
+ return false;
+ } catch (CdtVariableException e) {
+ CCorePlugin.log(e);
+ }
+ }
+
+ return true;
+ }
+
+ public int hashCode() {
+ int code = 51;
+
+ String name = fVar.getName();
+ if(name != null)
+ code += name.hashCode();
+
+ if(fNameOnly)
+ return code;
+
+ code += fVar.getValueType();
+ if(CdtVariableResolver.isStringListVariable(fVar.getValueType())){
+ try {
+ String[] value = fVar.getStringListValue();
+ if(value != null){
+ for(int i = 0; i < value.length; i++){
+ code += value[i].hashCode();
+ }
+ }
+ } catch (CdtVariableException e) {
+ CCorePlugin.log(e);
+ }
+ } else {
+ try {
+ String value =fVar.getStringValue();
+ if(value != null){
+ code += value.hashCode();
+ }
+ } catch (CdtVariableException e) {
+ CCorePlugin.log(e);
+ }
+ }
+
+ return code;
+ }
+
+ }
+
+ static VariableChangeEvent createVariableChangeEvent(ICdtVariable newVar, ICdtVariable oldVar){
+ ICdtVariable newVars[] = newVar != null ? new ICdtVariable[]{newVar} : null;
+ ICdtVariable oldVars[] = oldVar != null ? new ICdtVariable[]{oldVar} : null;
+
+ return createVariableChangeEvent(newVars, oldVars);
+ }
+
+ static ICdtVariable[] varsFromKeySet(Set set){
+ ICdtVariable vars[] = new ICdtVariable[set.size()];
+ int i = 0;
+ for(Iterator iter = set.iterator(); iter.hasNext(); i++){
+ VarKey key = (VarKey)iter.next();
+ vars[i] = key.getVariable();
+ }
+
+ return vars;
+ }
+ static VariableChangeEvent createVariableChangeEvent(ICdtVariable[] newVars, ICdtVariable[] oldVars){
+ ICdtVariable[] addedVars = null, removedVars = null, changedVars = null;
+
+ if(oldVars == null || oldVars.length == 0){
+ if(newVars != null && newVars.length != 0)
+ addedVars = (ICdtVariable[])newVars.clone() ;
+ } else if(newVars == null || newVars.length == 0){
+ removedVars = (ICdtVariable[])oldVars.clone();
+ } else {
+ HashSet newSet = new HashSet(newVars.length);
+ HashSet oldSet = new HashSet(oldVars.length);
+
+ for(int i = 0; i < newVars.length; i++){
+ newSet.add(new VarKey(newVars[i], true));
+ }
+
+ for(int i = 0; i < oldVars.length; i++){
+ oldSet.add(new VarKey(oldVars[i], true));
+ }
+
+ HashSet newSetCopy = (HashSet)newSet.clone();
+
+ newSet.removeAll(oldSet);
+ oldSet.removeAll(newSetCopy);
+
+ if(newSet.size() != 0){
+ addedVars = varsFromKeySet(newSet);
+ }
+
+ if(oldSet.size() != 0){
+ removedVars = varsFromKeySet(oldSet);
+ }
+
+ newSetCopy.removeAll(newSet);
+
+ HashSet modifiedSet = new HashSet(newSetCopy.size());
+ for(Iterator iter = newSetCopy.iterator(); iter.hasNext();){
+ VarKey key = (VarKey)iter.next();
+ modifiedSet.add(new VarKey(key.getVariable(), false));
+ }
+
+ for(int i = 0; i < oldVars.length; i++){
+ modifiedSet.remove(new VarKey(oldVars[i], false));
+ }
+
+ if(modifiedSet.size() != 0)
+ changedVars = varsFromKeySet(modifiedSet);
}
+
+ if(addedVars != null || removedVars != null || changedVars != null)
+ return new VariableChangeEvent(addedVars, removedVars, changedVars);
+ return null;
}
/*
@@ -228,8 +451,20 @@ public class UserDefinedVariableSupplier extends CoreMacroSupplierBase {
}
public void setWorkspaceVariables(StorableCdtVariables vars) throws CoreException{
+ StorableCdtVariables old = getStorableMacros(ICoreVariableContextInfo.CONTEXT_WORKSPACE, null);
+ ICdtVariable[] oldVars = null;
+ if(old != null)
+ oldVars = old.getMacros();
+
+ ICdtVariable[] newVars = vars.getMacros();
+
fWorkspaceMacros = new StorableCdtVariables(vars, false);
+ VariableChangeEvent event = createVariableChangeEvent(newVars, oldVars);
+ if(event != null){
+ notifyListeners(event);
+ }
+
storeWorkspaceVariables(true);
}
@@ -246,12 +481,38 @@ public class UserDefinedVariableSupplier extends CoreMacroSupplierBase {
* loads the stored workspace macros
*/
protected StorableCdtVariables loadWorkspaceMacros(){
+ StorableCdtVariables macros = loadNewStileWorkspaceMacros();
+
+ //now load PathEntry Variables from preferences
+
+
+ return macros;
+ }
+
+ protected void loadPathEntryVariables(StorableCdtVariables vars){
+ org.eclipse.core.runtime.Preferences prefs = CCorePlugin.getDefault().getPluginPreferences();
+ String[] names = prefs.propertyNames();
+ for(int i = 0; i < names.length; i++){
+ String name = names[i];
+ if (name.startsWith(OLD_VARIABLE_PREFIX)) {
+ String value = prefs.getString(name);
+ prefs.setToDefault(name);
+ if(value.length() != 0){
+ name = name.substring(OLD_VARIABLE_PREFIX.length());
+ vars.createMacro(name, ICdtVariable.VALUE_PATH_ANY, value);
+ }
+ }
+ }
+ }
+
+ protected StorableCdtVariables loadNewStileWorkspaceMacros(){
InputStream stream = loadInputStream(getWorkspaceNode(),PREFNAME_WORKSPACE);
if(stream == null)
return new StorableCdtVariables(false);
return loadMacrosFromStream(stream);
}
+
/*
* stores the given macros
*/
@@ -396,4 +657,19 @@ public class UserDefinedVariableSupplier extends CoreMacroSupplierBase {
*/
}
+ public void addListener(ICdtVariableChangeListener listener){
+ fListeners.add(listener);
+ }
+
+ public void removeListener(ICdtVariableChangeListener listener){
+ fListeners.remove(listener);
+ }
+
+ private void notifyListeners(VariableChangeEvent event){
+ ICdtVariableChangeListener[] listeners = (ICdtVariableChangeListener[])fListeners.toArray(new ICdtVariableChangeListener[fListeners.size()]);
+ for(int i = 0; i < listeners.length; i++){
+ listeners[i].variablesChanged(event);
+ }
+ }
+
}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/VariableChangeEvent.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/VariableChangeEvent.java
new file mode 100644
index 00000000000..e42425b2ada
--- /dev/null
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/VariableChangeEvent.java
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Intel Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Intel Corporation - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.cdtvariables;
+
+import org.eclipse.cdt.core.cdtvariables.ICdtVariable;
+
+public class VariableChangeEvent {
+ private static final ICdtVariable[] EMPTY_VAR_ARRAY = new ICdtVariable[0];
+
+ private ICdtVariable[] fAddedVars, fRemovedVars, fChangedVars;
+
+ VariableChangeEvent(ICdtVariable[] addedVars, ICdtVariable[] removedVars, ICdtVariable[] changedVars){
+ fAddedVars = addedVars != null ? (ICdtVariable[])addedVars.clone() : null;
+ fRemovedVars = removedVars != null ? (ICdtVariable[])removedVars.clone() : null;
+ fChangedVars = changedVars != null ? (ICdtVariable[])changedVars.clone() : null;
+ }
+ public ICdtVariable[] getAddedVariables(){
+ return fAddedVars != null ? (ICdtVariable[])fAddedVars.clone() : EMPTY_VAR_ARRAY;
+ }
+
+ public ICdtVariable[] getRemovedVariables(){
+ return fRemovedVars != null ? (ICdtVariable[])fRemovedVars.clone() : EMPTY_VAR_ARRAY;
+ }
+
+ public ICdtVariable[] getChangedVariables(){
+ return fChangedVars != null ? (ICdtVariable[])fChangedVars.clone() : EMPTY_VAR_ARRAY;
+ }
+
+}

Back to the top