1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-09-05 14:43:36 +02:00

Bug 224191 : Need public API to create CDT variables

This commit is contained in:
Oleg Krasilnikov 2008-03-28 12:17:28 +00:00
parent f0854abfb0
commit 7cd517b279
9 changed files with 305 additions and 189 deletions

View file

@ -22,15 +22,12 @@ import org.eclipse.cdt.core.cdtvariables.CdtVariableException;
import org.eclipse.cdt.core.cdtvariables.ICdtVariable; import org.eclipse.cdt.core.cdtvariables.ICdtVariable;
import org.eclipse.cdt.core.cdtvariables.ICdtVariableManager; import org.eclipse.cdt.core.cdtvariables.ICdtVariableManager;
import org.eclipse.cdt.core.cdtvariables.ICdtVariableStatus; import org.eclipse.cdt.core.cdtvariables.ICdtVariableStatus;
import org.eclipse.cdt.core.cdtvariables.IStorableCdtVariables;
import org.eclipse.cdt.core.cdtvariables.IUserVarSupplier;
import org.eclipse.cdt.core.model.util.CDTListComparator; import org.eclipse.cdt.core.model.util.CDTListComparator;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.core.settings.model.ICMultiItemsHolder; import org.eclipse.cdt.core.settings.model.ICMultiItemsHolder;
import org.eclipse.cdt.core.settings.model.ICResourceDescription; import org.eclipse.cdt.core.settings.model.ICResourceDescription;
import org.eclipse.cdt.internal.core.cdtvariables.CdtVariableManager;
import org.eclipse.cdt.internal.core.cdtvariables.EclipseVariablesVariableSupplier;
import org.eclipse.cdt.internal.core.cdtvariables.ICoreVariableContextInfo;
import org.eclipse.cdt.internal.core.cdtvariables.StorableCdtVariables;
import org.eclipse.cdt.internal.core.cdtvariables.UserDefinedVariableSupplier;
import org.eclipse.cdt.ui.newui.AbstractCPropertyTab; import org.eclipse.cdt.ui.newui.AbstractCPropertyTab;
import org.eclipse.cdt.ui.newui.AbstractPage; import org.eclipse.cdt.ui.newui.AbstractPage;
import org.eclipse.cdt.ui.newui.CDTPrefUtil; import org.eclipse.cdt.ui.newui.CDTPrefUtil;
@ -39,7 +36,6 @@ import org.eclipse.cdt.ui.newui.UIMessages;
import org.eclipse.cdt.utils.cdtvariables.CdtVariableResolver; import org.eclipse.cdt.utils.cdtvariables.CdtVariableResolver;
import org.eclipse.cdt.utils.envvar.EnvVarOperationProcessor; import org.eclipse.cdt.utils.envvar.EnvVarOperationProcessor;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.variables.IDynamicVariable;
import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.preference.JFacePreferences; import org.eclipse.jface.preference.JFacePreferences;
@ -116,11 +112,11 @@ public class CPropertyVarsTab extends AbstractCPropertyTab {
private static final String VALUE_DELIMITER = " || "; //$NON-NLS-1$ private static final String VALUE_DELIMITER = " || "; //$NON-NLS-1$
private static final ICdtVariableManager vmgr = CCorePlugin.getDefault().getCdtVariableManager(); private static final ICdtVariableManager vmgr = CCorePlugin.getDefault().getCdtVariableManager();
private static final UserDefinedVariableSupplier fUserSup = CdtVariableManager.fUserDefinedMacroSupplier; private static final IUserVarSupplier fUserSup = CCorePlugin.getUserVarSupplier();
private static final EnvCmp comparator = new EnvCmp(); private static final EnvCmp comparator = new EnvCmp();
private ICConfigurationDescription cfgd = null; private ICConfigurationDescription cfgd = null;
private StorableCdtVariables vars = null; private IStorableCdtVariables vars = null;
//currently the "CWD" and "PWD" macros are not displayed in UI //currently the "CWD" and "PWD" macros are not displayed in UI
private static final String fHiddenMacros[] = new String[]{ private static final String fHiddenMacros[] = new String[]{
@ -130,7 +126,6 @@ public class CPropertyVarsTab extends AbstractCPropertyTab {
private boolean fShowSysMacros = false; private boolean fShowSysMacros = false;
private Set<String> fIncorrectlyDefinedMacrosNames = new HashSet<String>(); private Set<String> fIncorrectlyDefinedMacrosNames = new HashSet<String>();
private static final int CONTEXT = ICoreVariableContextInfo.CONTEXT_CONFIGURATION;
private TableViewer tv; private TableViewer tv;
private Label fStatusLabel; private Label fStatusLabel;
@ -272,10 +267,10 @@ public class CPropertyVarsTab extends AbstractCPropertyTab {
if (!isUserVar(vars[i])) if (!isUserVar(vars[i]))
vars[i] = null; vars[i] = null;
for (ICConfigurationDescription c : getCfs()) { for (ICConfigurationDescription c : getCfs()) {
fUserSup.deleteAll(CONTEXT, c); fUserSup.deleteAll(c);
for (ICdtVariable macro : vars) for (ICdtVariable macro : vars)
if (macro != null) if (macro != null)
fUserSup.createMacro(macro, CONTEXT, c); fUserSup.createMacro(macro, c);
} }
} }
@ -293,14 +288,14 @@ public class CPropertyVarsTab extends AbstractCPropertyTab {
if (cfgd != null) { if (cfgd != null) {
if (forAll) { if (forAll) {
for (ICConfigurationDescription c : page.getCfgsEditable()) for (ICConfigurationDescription c : page.getCfgsEditable())
fUserSup.createMacro(macro, CONTEXT, c); fUserSup.createMacro(macro, c);
} else { } else {
if (page.isMultiCfg() && cfgd instanceof ICMultiItemsHolder) { if (page.isMultiCfg() && cfgd instanceof ICMultiItemsHolder) {
for (ICConfigurationDescription c : getCfs()) for (ICConfigurationDescription c : getCfs())
fUserSup.createMacro(macro, CONTEXT, c); fUserSup.createMacro(macro, c);
replaceMacros(); replaceMacros();
} else } else
fUserSup.createMacro(macro, CONTEXT, cfgd); fUserSup.createMacro(macro, cfgd);
} }
} }
else if (vars != null) else if (vars != null)
@ -333,11 +328,11 @@ public class CPropertyVarsTab extends AbstractCPropertyTab {
if (page.isMultiCfg() && cfgd instanceof ICMultiItemsHolder) { if (page.isMultiCfg() && cfgd instanceof ICMultiItemsHolder) {
ICConfigurationDescription[] cfs = (ICConfigurationDescription[])((ICMultiItemsHolder)cfgd).getItems(); ICConfigurationDescription[] cfs = (ICConfigurationDescription[])((ICMultiItemsHolder)cfgd).getItems();
for (int k=0; k<cfs.length; k++) for (int k=0; k<cfs.length; k++)
fUserSup.deleteMacro(macros[i].getName(), CONTEXT, cfs[k]); fUserSup.deleteMacro(macros[i].getName(), cfs[k]);
replaceMacros(); replaceMacros();
} }
else else
fUserSup.deleteMacro(macros[i].getName(), CONTEXT, cfgd); fUserSup.deleteMacro(macros[i].getName(), cfgd);
} }
else if (vars != null) else if (vars != null)
vars.deleteMacro(macros[i].getName()); vars.deleteMacro(macros[i].getName());
@ -368,9 +363,9 @@ public class CPropertyVarsTab extends AbstractCPropertyTab {
if (page.isMultiCfg() && cfgd instanceof ICMultiItemsHolder) { if (page.isMultiCfg() && cfgd instanceof ICMultiItemsHolder) {
ICConfigurationDescription[] cfs = (ICConfigurationDescription[])((ICMultiItemsHolder)cfgd).getItems(); ICConfigurationDescription[] cfs = (ICConfigurationDescription[])((ICMultiItemsHolder)cfgd).getItems();
for (int i=0; i<cfs.length; i++) for (int i=0; i<cfs.length; i++)
fUserSup.deleteAll(CONTEXT, cfs[i]); fUserSup.deleteAll(cfs[i]);
} else } else
fUserSup.deleteAll(CONTEXT, cfgd); fUserSup.deleteAll(cfgd);
} }
else if (vars != null) else if (vars != null)
vars.deleteAll(); vars.deleteAll();
@ -610,19 +605,8 @@ public class CPropertyVarsTab extends AbstractCPropertyTab {
return vmgr.isUserVariable(v, cfgd); return vmgr.isUserVariable(v, cfgd);
} }
/* check whether variable is dynamic */
private boolean isDynamic(ICdtVariable v) {
if (v instanceof EclipseVariablesVariableSupplier.EclipseVarMacro) {
EclipseVariablesVariableSupplier.EclipseVarMacro evar =
(EclipseVariablesVariableSupplier.EclipseVarMacro)v;
if (evar.getVariable() instanceof IDynamicVariable)
return true;
}
return false;
}
private String getString(ICdtVariable v) { private String getString(ICdtVariable v) {
if (isDynamic(v)) if (fUserSup.isDynamic(v))
return UIMessages.getString(VALUE_ECLIPSE_DYNAMIC); return UIMessages.getString(VALUE_ECLIPSE_DYNAMIC);
String value = EMPTY_STR; String value = EMPTY_STR;
try { try {
@ -646,13 +630,13 @@ public class CPropertyVarsTab extends AbstractCPropertyTab {
if (r0.length != r1.length) if (r0.length != r1.length)
return; // unprobable return; // unprobable
for (int i=0; i<r0.length; i++) { for (int i=0; i<r0.length; i++) {
ICdtVariable[] vs = fUserSup.getMacros(CONTEXT, r0[i].getConfiguration()); ICdtVariable[] vs = fUserSup.getMacros(r0[i].getConfiguration());
fUserSup.setMacros(vs, CONTEXT, r1[i].getConfiguration()); fUserSup.setMacros(vs, r1[i].getConfiguration());
} }
} }
} else { } else {
ICdtVariable[] vs = fUserSup.getMacros(CONTEXT, src.getConfiguration()); ICdtVariable[] vs = fUserSup.getMacros(src.getConfiguration());
fUserSup.setMacros(vs, CONTEXT, dst.getConfiguration()); fUserSup.setMacros(vs, dst.getConfiguration());
} }
} else if (vars != null) } else if (vars != null)
fUserSup.storeWorkspaceVariables(true); fUserSup.storeWorkspaceVariables(true);

View file

@ -23,7 +23,6 @@ import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -84,7 +83,7 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
*/ */
final CModel cModel = new CModel(); final CModel cModel = new CModel();
public static HashSet OptionNames = new HashSet(20); public static HashSet<String> OptionNames = new HashSet<String>(20);
public static final int DEFAULT_CHANGE_EVENT = 0; // must not collide with ElementChangedEvent event masks public static final int DEFAULT_CHANGE_EVENT = 0; // must not collide with ElementChangedEvent event masks
@ -97,13 +96,13 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
* Queue of deltas created explicitly by the C Model that * Queue of deltas created explicitly by the C Model that
* have yet to be fired. * have yet to be fired.
*/ */
List fCModelDeltas = Collections.synchronizedList(new ArrayList()); List<ICElementDelta> fCModelDeltas = Collections.synchronizedList(new ArrayList<ICElementDelta>());
/** /**
* Queue of reconcile deltas on working copies that have yet to be fired. * Queue of reconcile deltas on working copies that have yet to be fired.
* This is a table form IWorkingCopy to ICElementDelta * This is a table form IWorkingCopy to ICElementDelta
*/ */
HashMap reconcileDeltas = new HashMap(); HashMap<IWorkingCopy, ICElementDelta> reconcileDeltas = new HashMap<IWorkingCopy, ICElementDelta>();
/** /**
* Turns delta firing on/off. By default it is on. * Turns delta firing on/off. By default it is on.
@ -113,12 +112,12 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
/** /**
* Collection of listeners for C element deltas * Collection of listeners for C element deltas
*/ */
protected List fElementChangedListeners = Collections.synchronizedList(new ArrayList()); protected List<IElementChangedListener> fElementChangedListeners = Collections.synchronizedList(new ArrayList<IElementChangedListener>());
/** /**
* A map from ITranslationUnit to IWorkingCopy of the shared working copies. * A map from ITranslationUnit to IWorkingCopy of the shared working copies.
*/ */
public Map sharedWorkingCopies = new HashMap(); public Map<ITranslationUnit, IWorkingCopy> sharedWorkingCopies = new HashMap<ITranslationUnit, IWorkingCopy>();
/** /**
* Set of elements which are out of sync with their buffers. * Set of elements which are out of sync with their buffers.
*/ */
@ -127,7 +126,7 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
/* /*
* Temporary cache of newly opened elements * Temporary cache of newly opened elements
*/ */
private ThreadLocal temporaryCache = new ThreadLocal(); private ThreadLocal<Map<ICElement, Object>> temporaryCache = new ThreadLocal<Map<ICElement, Object>>();
/** /**
* Infos cache. * Infos cache.
@ -142,17 +141,17 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
/** /**
* The list of started BinaryRunners on projects. * The list of started BinaryRunners on projects.
*/ */
private HashMap binaryRunners = new HashMap(); private HashMap<IProject, BinaryRunner> binaryRunners = new HashMap<IProject, BinaryRunner>();
/** /**
* Map of the binary parser for each project. * Map of the binary parser for each project.
*/ */
private HashMap binaryParsersMap = new HashMap(); private HashMap<IProject, BinaryParserConfig[]> binaryParsersMap = new HashMap<IProject, BinaryParserConfig[]>();
/** /**
* The lis of the SourceMappers on projects. * The lis of the SourceMappers on projects.
*/ */
private HashMap sourceMappers = new HashMap(); private HashMap<ICProject, SourceMapper> sourceMappers = new HashMap<ICProject, SourceMapper>();
public static final IWorkingCopy[] NoWorkingCopy = new IWorkingCopy[0]; public static final IWorkingCopy[] NoWorkingCopy = new IWorkingCopy[0];
@ -464,7 +463,7 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
if (celement.getElementType() == ICElement.C_CCONTAINER) { if (celement.getElementType() == ICElement.C_CCONTAINER) {
ICProject cproject = celement.getCProject(); ICProject cproject = celement.getCProject();
CProjectInfo pinfo = (CProjectInfo)peekAtInfo(cproject); CProjectInfo pinfo = (CProjectInfo)peekAtInfo(cproject);
ArrayList list = new ArrayList(5); ArrayList<ICElement> list = new ArrayList<ICElement>(5);
if (pinfo != null && pinfo.vBin != null) { if (pinfo != null && pinfo.vBin != null) {
if (peekAtInfo(pinfo.vBin) != null) { if (peekAtInfo(pinfo.vBin) != null) {
try { try {
@ -520,7 +519,7 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
if (cdesc != null) { if (cdesc != null) {
ICExtensionReference[] cextensions = cdesc.get(CCorePlugin.BINARY_PARSER_UNIQ_ID, true); ICExtensionReference[] cextensions = cdesc.get(CCorePlugin.BINARY_PARSER_UNIQ_ID, true);
if (cextensions.length > 0) { if (cextensions.length > 0) {
ArrayList list = new ArrayList(cextensions.length); ArrayList<BinaryParserConfig> list = new ArrayList<BinaryParserConfig>(cextensions.length);
for (int i = 0; i < cextensions.length; i++) { for (int i = 0; i < cextensions.length; i++) {
BinaryParserConfig config = new BinaryParserConfig(cextensions[i]); BinaryParserConfig config = new BinaryParserConfig(cextensions[i]);
list.add(config); list.add(config);
@ -933,7 +932,7 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
} }
if (deltaToNotify != null) { if (deltaToNotify != null) {
// flush now so as to keep listener reactions to post their own deltas for subsequent iteration // flush now so as to keep listener reactions to post their own deltas for subsequent iteration
this.reconcileDeltas = new HashMap(); this.reconcileDeltas = new HashMap<IWorkingCopy, ICElementDelta>();
notifyListeners(deltaToNotify, ElementChangedEvent.POST_RECONCILE, listeners, listenerMask, listenerCount); notifyListeners(deltaToNotify, ElementChangedEvent.POST_RECONCILE, listeners, listenerMask, listenerCount);
} }
} }
@ -988,27 +987,24 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
fCModelDeltas.clear(); fCModelDeltas.clear();
} }
private ICElementDelta mergeDeltas(Collection deltas) { private ICElementDelta mergeDeltas(Collection<ICElementDelta> deltas) {
synchronized (deltas) { synchronized (deltas) {
if (deltas.size() == 0) if (deltas.size() == 0)
return null; return null;
if (deltas.size() == 1) if (deltas.size() == 1)
return (ICElementDelta)deltas.iterator().next(); return deltas.iterator().next();
if (deltas.size() <= 1) if (deltas.size() <= 1)
return null; return null;
Iterator iterator = deltas.iterator();
ICElement cRoot = getCModel(); ICElement cRoot = getCModel();
CElementDelta rootDelta = new CElementDelta(cRoot); CElementDelta rootDelta = new CElementDelta(cRoot);
boolean insertedTree = false; boolean insertedTree = false;
while (iterator.hasNext()) { for (ICElementDelta delta : deltas) {
CElementDelta delta = (CElementDelta)iterator.next();
ICElement element = delta.getElement(); ICElement element = delta.getElement();
if (cRoot.equals(element)) { if (cRoot.equals(element)) {
ICElementDelta[] children = delta.getAffectedChildren(); for (ICElementDelta child : delta.getAffectedChildren()) {
for (int j = 0; j < children.length; j++) { CElementDelta projectDelta = (CElementDelta)child;
CElementDelta projectDelta = (CElementDelta)children[j];
rootDelta.insertDeltaTree(projectDelta.getElement(), projectDelta); rootDelta.insertDeltaTree(projectDelta.getElement(), projectDelta);
insertedTree = true; insertedTree = true;
} }
@ -1020,7 +1016,7 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
} }
} }
} else { } else {
rootDelta.insertDeltaTree(element, delta); rootDelta.insertDeltaTree(element, (CElementDelta)delta);
insertedTree = true; insertedTree = true;
} }
} }
@ -1042,13 +1038,12 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
* Returns the info for the element. * Returns the info for the element.
*/ */
public synchronized Object getInfo(ICElement element) { public synchronized Object getInfo(ICElement element) {
HashMap tempCache = (HashMap)this.temporaryCache.get(); HashMap<ICElement, Object> tempCache = (HashMap<ICElement, Object>)this.temporaryCache.get();
if (tempCache != null) { if (tempCache != null) {
Object result = tempCache.get(element); Object result = tempCache.get(element);
if (result != null) { if (result != null)
return result; return result;
} }
}
return this.cache.getInfo(element); return this.cache.getInfo(element);
} }
@ -1057,7 +1052,7 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
* disturbing the cache ordering. * disturbing the cache ordering.
*/ */
protected synchronized Object peekAtInfo(ICElement element) { protected synchronized Object peekAtInfo(ICElement element) {
HashMap tempCache = (HashMap)this.temporaryCache.get(); HashMap<ICElement, Object> tempCache = (HashMap<ICElement, Object>)this.temporaryCache.get();
if (tempCache != null) { if (tempCache != null) {
Object result = tempCache.get(element); Object result = tempCache.get(element);
if (result != null) { if (result != null) {
@ -1074,7 +1069,7 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
* added to the cache. If it is the case, another thread has opened the element (or one of * added to the cache. If it is the case, another thread has opened the element (or one of
* its ancestors). So returns without updating the cache. * its ancestors). So returns without updating the cache.
*/ */
protected synchronized void putInfos(ICElement openedElement, Map newElements) { protected synchronized void putInfos(ICElement openedElement, Map<ICElement, Object> newElements) {
// remove children // remove children
Object existingInfo = this.cache.peekAtInfo(openedElement); Object existingInfo = this.cache.peekAtInfo(openedElement);
if (openedElement instanceof IParent && existingInfo instanceof CElementInfo) { if (openedElement instanceof IParent && existingInfo instanceof CElementInfo) {
@ -1089,12 +1084,8 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
} }
} }
Iterator iterator = newElements.keySet().iterator(); for (ICElement element : newElements.keySet())
while (iterator.hasNext()) { this.cache.putInfo(element, newElements.get(element));
ICElement element = (ICElement)iterator.next();
Object info = newElements.get(element);
this.cache.putInfo(element, info);
}
} }
/** /**
@ -1128,10 +1119,10 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
* Returns the temporary cache for newly opened elements for the current thread. * Returns the temporary cache for newly opened elements for the current thread.
* Creates it if not already created. * Creates it if not already created.
*/ */
public HashMap getTemporaryCache() { public HashMap<ICElement, Object> getTemporaryCache() {
HashMap result = (HashMap)this.temporaryCache.get(); HashMap<ICElement, Object> result = (HashMap<ICElement, Object>)this.temporaryCache.get();
if (result == null) { if (result == null) {
result = new HashMap(); result = new HashMap<ICElement, Object>();
this.temporaryCache.set(result); this.temporaryCache.set(result);
} }
return result; return result;

View file

@ -20,19 +20,20 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.MissingResourceException; import java.util.MissingResourceException;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import org.eclipse.cdt.core.cdtvariables.ICdtVariableManager; import org.eclipse.cdt.core.cdtvariables.ICdtVariableManager;
import org.eclipse.cdt.core.cdtvariables.IUserVarSupplier;
import org.eclipse.cdt.core.dom.CDOM; import org.eclipse.cdt.core.dom.CDOM;
import org.eclipse.cdt.core.dom.IPDOMManager; import org.eclipse.cdt.core.dom.IPDOMManager;
import org.eclipse.cdt.core.envvar.IEnvironmentVariableManager; import org.eclipse.cdt.core.envvar.IEnvironmentVariableManager;
import org.eclipse.cdt.core.index.IIndexManager; import org.eclipse.cdt.core.index.IIndexManager;
import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.model.IWorkingCopy; import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.core.parser.IScannerInfoProvider; import org.eclipse.cdt.core.parser.IScannerInfoProvider;
import org.eclipse.cdt.core.resources.IConsole; import org.eclipse.cdt.core.resources.IConsole;
@ -47,6 +48,7 @@ import org.eclipse.cdt.internal.core.CDTLogWriter;
import org.eclipse.cdt.internal.core.CdtVarPathEntryVariableManager; import org.eclipse.cdt.internal.core.CdtVarPathEntryVariableManager;
import org.eclipse.cdt.internal.core.PositionTrackerManager; import org.eclipse.cdt.internal.core.PositionTrackerManager;
import org.eclipse.cdt.internal.core.cdtvariables.CdtVariableManager; import org.eclipse.cdt.internal.core.cdtvariables.CdtVariableManager;
import org.eclipse.cdt.internal.core.cdtvariables.UserVarSupplier;
import org.eclipse.cdt.internal.core.envvar.EnvironmentVariableManager; import org.eclipse.cdt.internal.core.envvar.EnvironmentVariableManager;
import org.eclipse.cdt.internal.core.model.BufferManager; import org.eclipse.cdt.internal.core.model.BufferManager;
import org.eclipse.cdt.internal.core.model.CModelManager; import org.eclipse.cdt.internal.core.model.CModelManager;
@ -209,11 +211,11 @@ public class CCorePlugin extends Plugin {
// if factory is null, default factory must be used // if factory is null, default factory must be used
if (factory == null) factory = BufferManager.getDefaultBufferManager().getDefaultBufferFactory(); if (factory == null) factory = BufferManager.getDefaultBufferManager().getDefaultBufferFactory();
Map sharedWorkingCopies = CModelManager.getDefault().sharedWorkingCopies; Map<ITranslationUnit, IWorkingCopy> sharedWorkingCopies = CModelManager.getDefault().sharedWorkingCopies;
Map perFactoryWorkingCopies = (Map) sharedWorkingCopies.get(factory); Map<ITranslationUnit, IWorkingCopy> perFactoryWorkingCopies = (Map) sharedWorkingCopies.get(factory);
if (perFactoryWorkingCopies == null) return CModelManager.NoWorkingCopy; if (perFactoryWorkingCopies == null) return CModelManager.NoWorkingCopy;
Collection copies = perFactoryWorkingCopies.values(); Collection<IWorkingCopy> copies = perFactoryWorkingCopies.values();
IWorkingCopy[] result = new IWorkingCopy[copies.size()]; IWorkingCopy[] result = new IWorkingCopy[copies.size()];
copies.toArray(result); copies.toArray(result);
return result; return result;
@ -234,11 +236,11 @@ public class CCorePlugin extends Plugin {
} }
public static String getFormattedString(String key, String arg) { public static String getFormattedString(String key, String arg) {
return MessageFormat.format(getResourceString(key), new String[] { arg }); return MessageFormat.format(getResourceString(key), new Object[] { arg });
} }
public static String getFormattedString(String key, String[] args) { public static String getFormattedString(String key, String[] args) {
return MessageFormat.format(getResourceString(key), args); return MessageFormat.format(getResourceString(key), (Object[])args);
} }
public static ResourceBundle getResourceBundle() { public static ResourceBundle getResourceBundle() {
@ -380,30 +382,24 @@ public class CCorePlugin extends Plugin {
* @see #setOptions * @see #setOptions
*/ */
public static HashMap getDefaultOptions() public static HashMap<String, String> getDefaultOptions()
{ {
HashMap defaultOptions = new HashMap(10); HashMap<String, String> defaultOptions = new HashMap<String, String>(10);
// see #initializeDefaultPluginPreferences() for changing default settings // see #initializeDefaultPluginPreferences() for changing default settings
Preferences preferences = getDefault().getPluginPreferences(); Preferences preferences = getDefault().getPluginPreferences();
HashSet optionNames = CModelManager.OptionNames; HashSet<String> optionNames = CModelManager.OptionNames;
// get preferences set to their default // get preferences set to their default
String[] defaultPropertyNames = preferences.defaultPropertyNames(); for (String propertyName : preferences.defaultPropertyNames()){
for (int i = 0; i < defaultPropertyNames.length; i++){ if (optionNames.contains(propertyName))
String propertyName = defaultPropertyNames[i];
if (optionNames.contains(propertyName)) {
defaultOptions.put(propertyName, preferences.getDefaultString(propertyName)); defaultOptions.put(propertyName, preferences.getDefaultString(propertyName));
} }
}
// get preferences not set to their default // get preferences not set to their default
String[] propertyNames = preferences.propertyNames(); for (String propertyName : preferences.propertyNames()) {
for (int i = 0; i < propertyNames.length; i++){ if (optionNames.contains(propertyName))
String propertyName = propertyNames[i];
if (optionNames.contains(propertyName)) {
defaultOptions.put(propertyName, preferences.getDefaultString(propertyName)); defaultOptions.put(propertyName, preferences.getDefaultString(propertyName));
} }
}
// get encoding through resource plugin // get encoding through resource plugin
defaultOptions.put(CORE_ENCODING, ResourcesPlugin.getEncoding()); defaultOptions.put(CORE_ENCODING, ResourcesPlugin.getEncoding());
@ -445,28 +441,24 @@ public class CCorePlugin extends Plugin {
* (key type: <code>String</code>; value type: <code>String</code>) * (key type: <code>String</code>; value type: <code>String</code>)
* @see CCorePlugin#getDefaultOptions * @see CCorePlugin#getDefaultOptions
*/ */
public static HashMap getOptions() { public static HashMap<String, String> getOptions() {
HashMap options = new HashMap(10); HashMap<String, String> options = new HashMap<String, String>(10);
// see #initializeDefaultPluginPreferences() for changing default settings // see #initializeDefaultPluginPreferences() for changing default settings
Plugin plugin = getDefault(); Plugin plugin = getDefault();
if (plugin != null) { if (plugin != null) {
Preferences preferences = plugin.getPluginPreferences(); Preferences preferences = plugin.getPluginPreferences();
HashSet optionNames = CModelManager.OptionNames; HashSet<String> optionNames = CModelManager.OptionNames;
// get preferences set to their default // get preferences set to their default
String[] defaultPropertyNames = preferences.defaultPropertyNames(); for (String propertyName : preferences.defaultPropertyNames()){
for (int i = 0; i < defaultPropertyNames.length; i++){
String propertyName = defaultPropertyNames[i];
if (optionNames.contains(propertyName)){ if (optionNames.contains(propertyName)){
options.put(propertyName, preferences.getDefaultString(propertyName)); options.put(propertyName, preferences.getDefaultString(propertyName));
} }
} }
// get preferences not set to their default // get preferences not set to their default
String[] propertyNames = preferences.propertyNames(); for (String propertyName : preferences.propertyNames()){
for (int i = 0; i < propertyNames.length; i++){
String propertyName = propertyNames[i];
if (optionNames.contains(propertyName)){ if (optionNames.contains(propertyName)){
options.put(propertyName, preferences.getString(propertyName).trim()); options.put(propertyName, preferences.getString(propertyName).trim());
} }
@ -489,7 +481,7 @@ public class CCorePlugin extends Plugin {
* or <code>null</code> to reset all options to their default values * or <code>null</code> to reset all options to their default values
* @see CCorePlugin#getDefaultOptions * @see CCorePlugin#getDefaultOptions
*/ */
public static void setOptions(HashMap newOptions) { public static void setOptions(HashMap<String, String> newOptions) {
// see #initializeDefaultPluginPreferences() for changing default settings // see #initializeDefaultPluginPreferences() for changing default settings
Preferences preferences = getDefault().getPluginPreferences(); Preferences preferences = getDefault().getPluginPreferences();
@ -497,9 +489,7 @@ public class CCorePlugin extends Plugin {
if (newOptions == null){ if (newOptions == null){
newOptions = getDefaultOptions(); newOptions = getDefaultOptions();
} }
Iterator keys = newOptions.keySet().iterator(); for (String key : newOptions.keySet()){
while (keys.hasNext()){
String key = (String)keys.next();
if (!CModelManager.OptionNames.contains(key)) continue; // unrecognized option if (!CModelManager.OptionNames.contains(key)) continue; // unrecognized option
if (key.equals(CORE_ENCODING)) continue; // skipped, contributed by resource prefs if (key.equals(CORE_ENCODING)) continue; // skipped, contributed by resource prefs
String value = (String)newOptions.get(key); String value = (String)newOptions.get(key);
@ -563,15 +553,10 @@ public class CCorePlugin extends Plugin {
ICExtensionReference ext[] = new ICExtensionReference[0]; ICExtensionReference ext[] = new ICExtensionReference[0];
if (project != null) { if (project != null) {
try { try {
ICDescriptor cdesc = getCProjectDescription(project); ICDescriptor cdesc = getCProjectDescription(project, false);
ICExtensionReference[] cextensions = cdesc.get(BINARY_PARSER_UNIQ_ID, true); ICExtensionReference[] cextensions = cdesc.get(BINARY_PARSER_UNIQ_ID, true);
if (cextensions.length > 0) { if (cextensions != null && cextensions.length > 0)
ArrayList list = new ArrayList(cextensions.length); ext = cextensions;
for (int i = 0; i < cextensions.length; i++) {
list.add(cextensions[i]);
}
ext = (ICExtensionReference[])list.toArray(ext);
}
} catch (CoreException e) { } catch (CoreException e) {
log(e); log(e);
} }
@ -589,16 +574,16 @@ public class CCorePlugin extends Plugin {
IBinaryParser parsers[] = null; IBinaryParser parsers[] = null;
if (project != null) { if (project != null) {
try { try {
ICDescriptor cdesc = getCProjectDescription(project); ICDescriptor cdesc = getCProjectDescription(project, false);
ICExtensionReference[] cextensions = cdesc.get(BINARY_PARSER_UNIQ_ID, true); ICExtensionReference[] cextensions = cdesc.get(BINARY_PARSER_UNIQ_ID, true);
if (cextensions.length > 0) { if (cextensions.length > 0) {
ArrayList list = new ArrayList(cextensions.length); ArrayList<IBinaryParser> list = new ArrayList<IBinaryParser>(cextensions.length);
for (int i = 0; i < cextensions.length; i++) { for (ICExtensionReference ref : cextensions) {
IBinaryParser parser = null; IBinaryParser parser = null;
try { try {
parser = (IBinaryParser) cextensions[i].createExtension(); parser = (IBinaryParser)ref.createExtension();
} catch (ClassCastException e) { } catch (ClassCastException e) {
// log(e); // wrong binary parser definition ?
} }
if (parser != null) { if (parser != null) {
list.add(parser); list.add(parser);
@ -939,11 +924,10 @@ public class CCorePlugin extends Plugin {
String[] empty = new String[0]; String[] empty = new String[0];
if (extension != null) { if (extension != null) {
IExtension[] extensions = extension.getExtensions(); IExtension[] extensions = extension.getExtensions();
ArrayList list = new ArrayList(extensions.length); ArrayList<String> list = new ArrayList<String>(extensions.length);
for (int i = 0; i < extensions.length; i++) { for (IExtension e : extensions)
list.add(extensions[i].getUniqueIdentifier()); list.add(e.getUniqueIdentifier());
} return list.toArray(empty);
return (String[]) list.toArray(empty);
} }
return empty; return empty;
} }
@ -954,18 +938,15 @@ public class CCorePlugin extends Plugin {
IExtensionPoint extension = Platform.getExtensionRegistry().getExtensionPoint(CCorePlugin.PLUGIN_ID, ERROR_PARSER_SIMPLE_ID); IExtensionPoint extension = Platform.getExtensionRegistry().getExtensionPoint(CCorePlugin.PLUGIN_ID, ERROR_PARSER_SIMPLE_ID);
if (extension != null) { if (extension != null) {
IExtension[] extensions = extension.getExtensions(); IExtension[] extensions = extension.getExtensions();
List list = new ArrayList(extensions.length); List<IErrorParser> list = new ArrayList<IErrorParser>(extensions.length);
for (int i = 0; i < extensions.length; i++) { for (IExtension e : extensions) {
String parserID = extensions[i].getUniqueIdentifier(); String parserID = e.getUniqueIdentifier();
if ((id == null && parserID != null) || (id != null && id.equals(parserID))) { if ((id == null && parserID != null) || (id != null && id.equals(parserID))) {
IConfigurationElement[] configElements = extensions[i]. getConfigurationElements(); for (IConfigurationElement ce : e.getConfigurationElements())
for (int j = 0; j < configElements.length; j++) { list.add((IErrorParser)ce.createExecutableExtension("class")); //$NON-NLS-1$
IErrorParser parser = (IErrorParser)configElements[j].createExecutableExtension("class"); //$NON-NLS-1$
list.add(parser);
} }
} }
} return list.toArray(empty);
return (IErrorParser[]) list.toArray(empty);
} }
} catch (CoreException e) { } catch (CoreException e) {
log(e); log(e);
@ -975,29 +956,8 @@ public class CCorePlugin extends Plugin {
public IScannerInfoProvider getScannerInfoProvider(IProject project) { public IScannerInfoProvider getScannerInfoProvider(IProject project) {
return fNewCProjectDescriptionManager.getScannerInfoProviderProxy(project); return fNewCProjectDescriptionManager.getScannerInfoProviderProxy(project);
// IScannerInfoProvider provider = null;
// if (project != null) {
// try {
// ICDescriptor desc = getCProjectDescription(project);
// ICExtensionReference[] extensions = desc.get(BUILD_SCANNER_INFO_UNIQ_ID, true);
// if (extensions.length > 0)
// provider = (IScannerInfoProvider) extensions[0].createExtension();
// } catch (CoreException e) {
// // log(e);
// }
// if ( provider == null) {
// return getDefaultScannerInfoProvider(project);
// }
// }
// return provider;
} }
// private IScannerInfoProvider getDefaultScannerInfoProvider(IProject project){
// if(fNewCProjectDescriptionManager.isNewStyleIndexCfg(project))
// return fNewCProjectDescriptionManager.getScannerInfoProvider(project);
// return ScannerProvider.getInstance();
// }
/** /**
* Helper function, returning the content type for a filename * Helper function, returning the content type for a filename
* Same as: <pre> * Same as: <pre>
@ -1234,4 +1194,13 @@ public class CCorePlugin extends Plugin {
public ICProjectDescriptionManager getProjectDescriptionManager(){ public ICProjectDescriptionManager getProjectDescriptionManager(){
return fNewCProjectDescriptionManager; return fNewCProjectDescriptionManager;
} }
/**
* @return editable User-variable's supplier
*/
public static IUserVarSupplier getUserVarSupplier() {
return UserVarSupplier.getInstance();
}
} }

View file

@ -0,0 +1,28 @@
/*******************************************************************************
* Copyright (c) 2008 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.core.cdtvariables;
/**
* Public interface to access StorableCdtVariables class methods
*/
public interface IStorableCdtVariables {
ICdtVariable getMacro(String name);
ICdtVariable[] getMacros();
boolean deleteAll();
boolean contains(ICdtVariable var);
ICdtVariable deleteMacro(String name);
boolean isChanged();
ICdtVariable createMacro(ICdtVariable copy);
ICdtVariable createMacro(String name, int type, String value);
ICdtVariable createMacro(String name, int type, String value[]);
void createMacros(ICdtVariable macros[]);
boolean isEmpty();
}

View file

@ -0,0 +1,37 @@
/*******************************************************************************
* Copyright (c) 2008 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.core.cdtvariables;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.core.runtime.CoreException;
/**
* Public interface to access to UserVarSupplier class methods
*/
public interface IUserVarSupplier {
ICdtVariable createMacro(ICdtVariable copy, ICConfigurationDescription contextData);
ICdtVariable createMacro(String macroName,
int type,
String value,
ICConfigurationDescription contextData);
ICdtVariable createMacro(String macroName,
int type,
String value[],
ICConfigurationDescription contextData);
void deleteAll(ICConfigurationDescription contextData);
ICdtVariable deleteMacro(String name, ICConfigurationDescription contextData);
ICdtVariable[] getMacros(ICConfigurationDescription contextData);
IStorableCdtVariables getWorkspaceVariablesCopy();
boolean isDynamic(ICdtVariable v);
void setMacros(ICdtVariable m[], ICConfigurationDescription contextData);
boolean setWorkspaceVariables(IStorableCdtVariables vars) throws CoreException;
void storeWorkspaceVariables(boolean force);
}

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2005, 2007 Intel Corporation and others. * Copyright (c) 2005, 2008 Intel Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -12,11 +12,11 @@ package org.eclipse.cdt.internal.core.cdtvariables;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.Map; import java.util.Map;
import org.eclipse.cdt.core.cdtvariables.CdtVariableException; import org.eclipse.cdt.core.cdtvariables.CdtVariableException;
import org.eclipse.cdt.core.cdtvariables.ICdtVariable; import org.eclipse.cdt.core.cdtvariables.ICdtVariable;
import org.eclipse.cdt.core.cdtvariables.IStorableCdtVariables;
import org.eclipse.cdt.core.settings.model.ICStorageElement; import org.eclipse.cdt.core.settings.model.ICStorageElement;
import org.eclipse.cdt.internal.core.cdtvariables.UserDefinedVariableSupplier.VarKey; import org.eclipse.cdt.internal.core.cdtvariables.UserDefinedVariableSupplier.VarKey;
import org.eclipse.cdt.internal.core.settings.model.ExceptionFactory; import org.eclipse.cdt.internal.core.settings.model.ExceptionFactory;
@ -29,19 +29,16 @@ import org.eclipse.cdt.utils.cdtvariables.CdtVariableResolver;
* @since 3.0 * @since 3.0
* *
*/ */
public class StorableCdtVariables { public class StorableCdtVariables implements IStorableCdtVariables {
public static final String MACROS_ELEMENT_NAME = "macros"; //$NON-NLS-1$ public static final String MACROS_ELEMENT_NAME = "macros"; //$NON-NLS-1$
// public static final String EXPAND_ENVIRONMENT_MACROS = "expandEnvironmentMacros"; //$NON-NLS-1$ private HashMap<String, ICdtVariable> fMacros;
// public static final String TRUE = "true"; //$NON-NLS-1$
private HashMap fMacros;
// private boolean fExpandInMakefile = false;
private boolean fIsDirty = false; private boolean fIsDirty = false;
private boolean fIsChanged = false; private boolean fIsChanged = false;
private boolean fIsReadOnly; private boolean fIsReadOnly;
private HashMap getMap(){ private HashMap<String, ICdtVariable> getMap(){
if(fMacros == null) if(fMacros == null)
fMacros = new HashMap(); fMacros = new HashMap<String, ICdtVariable>();
return fMacros; return fMacros;
} }
@ -49,13 +46,14 @@ public class StorableCdtVariables {
fIsReadOnly = readOnly; fIsReadOnly = readOnly;
} }
@SuppressWarnings("unchecked")
public StorableCdtVariables(StorableCdtVariables base, boolean readOnly) { public StorableCdtVariables(StorableCdtVariables base, boolean readOnly) {
fMacros = (HashMap)base.getMap().clone(); fMacros = (HashMap<String, ICdtVariable>)base.getMap().clone();
fIsReadOnly = readOnly; fIsReadOnly = readOnly;
} }
public StorableCdtVariables(ICdtVariable vars[], boolean readOnly) { public StorableCdtVariables(ICdtVariable vars[], boolean readOnly) {
fMacros = new HashMap(vars.length); fMacros = new HashMap<String, ICdtVariable>(vars.length);
for(int i = 0; i < vars.length; i++){ for(int i = 0; i < vars.length; i++){
addMacro(vars[i]); addMacro(vars[i]);
} }
@ -86,13 +84,9 @@ public class StorableCdtVariables {
} }
public void serialize(ICStorageElement element){ public void serialize(ICStorageElement element){
// if(fExpandInMakefile)
// element.setAttribute(EXPAND_ENVIRONMENT_MACROS,TRUE);
if(fMacros != null){ if(fMacros != null){
Iterator iter = fMacros.values().iterator(); for (ICdtVariable v : fMacros.values()){
while(iter.hasNext()){ StorableCdtVariable macro = (StorableCdtVariable)v;
StorableCdtVariable macro = (StorableCdtVariable)iter.next();
ICStorageElement macroEl; ICStorageElement macroEl;
if(CdtVariableResolver.isStringListVariable(macro.getValueType())) if(CdtVariableResolver.isStringListVariable(macro.getValueType()))
macroEl = element.createChild(StorableCdtVariable.STRINGLIST_MACRO_ELEMENT_NAME); macroEl = element.createChild(StorableCdtVariable.STRINGLIST_MACRO_ELEMENT_NAME);
@ -188,9 +182,7 @@ public class StorableCdtVariables {
deleteAll(); deleteAll();
else{ else{
if (getMap().size() != 0) { if (getMap().size() != 0) {
Iterator iter = getMap().values().iterator(); for (ICdtVariable m : getMap().values()){
while(iter.hasNext()){
ICdtVariable m = (ICdtVariable)iter.next();
int i; int i;
for(i = 0 ; i < macros.length; i++){ for(i = 0 ; i < macros.length; i++){
if(m.getName().equals(macros[i].getName())) if(m.getName().equals(macros[i].getName()))
@ -343,9 +335,8 @@ public class StorableCdtVariables {
} }
public ICdtVariable[] getMacros(){ public ICdtVariable[] getMacros(){
Collection macros = getMap().values(); Collection<ICdtVariable> macros = getMap().values();
return macros.toArray(new ICdtVariable[macros.size()]);
return (ICdtVariable[])macros.toArray(new ICdtVariable[macros.size()]);
} }
public ICdtVariable deleteMacro(String name){ public ICdtVariable deleteMacro(String name){
@ -367,7 +358,7 @@ public class StorableCdtVariables {
public boolean deleteAll(){ public boolean deleteAll(){
if(fIsReadOnly) if(fIsReadOnly)
throw ExceptionFactory.createIsReadOnlyException(); throw ExceptionFactory.createIsReadOnlyException();
Map map = getMap(); Map<String, ICdtVariable> map = getMap();
if(map.size() > 0){ if(map.size() > 0){
fIsDirty = true; fIsDirty = true;
fIsChanged = true; fIsChanged = true;

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2005, 2007 Intel Corporation and others. * Copyright (c) 2005, 2008 Intel Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -67,7 +67,7 @@ public class UserDefinedVariableSupplier extends CoreMacroSupplierBase {
private static UserDefinedVariableSupplier fInstance; private static UserDefinedVariableSupplier fInstance;
private StorableCdtVariables fWorkspaceMacros; private StorableCdtVariables fWorkspaceMacros;
private Set fListeners; private Set<ICdtVariableChangeListener> fListeners;
private StorableCdtVariables getStorableMacros(int contextType, Object contextData){ private StorableCdtVariables getStorableMacros(int contextType, Object contextData){
StorableCdtVariables macros = null; StorableCdtVariables macros = null;
@ -93,7 +93,7 @@ public class UserDefinedVariableSupplier extends CoreMacroSupplierBase {
} }
private UserDefinedVariableSupplier(){ private UserDefinedVariableSupplier(){
fListeners = Collections.synchronizedSet(new HashSet()); fListeners = Collections.synchronizedSet(new HashSet<ICdtVariableChangeListener>());
} }
public static UserDefinedVariableSupplier getInstance(){ public static UserDefinedVariableSupplier getInstance(){
@ -376,16 +376,16 @@ public class UserDefinedVariableSupplier extends CoreMacroSupplierBase {
return createVariableChangeEvent(newVars, oldVars); return createVariableChangeEvent(newVars, oldVars);
} }
static ICdtVariable[] varsFromKeySet(Set set){ static ICdtVariable[] varsFromKeySet(Set<VarKey> set){
ICdtVariable vars[] = new ICdtVariable[set.size()]; ICdtVariable vars[] = new ICdtVariable[set.size()];
int i = 0; int i = 0;
for(Iterator iter = set.iterator(); iter.hasNext(); i++){ for(VarKey key : set) {
VarKey key = (VarKey)iter.next(); vars[i++] = key.getVariable();
vars[i] = key.getVariable();
} }
return vars; return vars;
} }
@SuppressWarnings("unchecked")
static VariableChangeEvent createVariableChangeEvent(ICdtVariable[] newVars, ICdtVariable[] oldVars){ static VariableChangeEvent createVariableChangeEvent(ICdtVariable[] newVars, ICdtVariable[] oldVars){
ICdtVariable[] addedVars = null, removedVars = null, changedVars = null; ICdtVariable[] addedVars = null, removedVars = null, changedVars = null;
@ -395,8 +395,8 @@ public class UserDefinedVariableSupplier extends CoreMacroSupplierBase {
} else if(newVars == null || newVars.length == 0){ } else if(newVars == null || newVars.length == 0){
removedVars = (ICdtVariable[])oldVars.clone(); removedVars = (ICdtVariable[])oldVars.clone();
} else { } else {
HashSet newSet = new HashSet(newVars.length); HashSet<VarKey> newSet = new HashSet<VarKey>(newVars.length);
HashSet oldSet = new HashSet(oldVars.length); HashSet<VarKey> oldSet = new HashSet<VarKey>(oldVars.length);
for(int i = 0; i < newVars.length; i++){ for(int i = 0; i < newVars.length; i++){
newSet.add(new VarKey(newVars[i], true)); newSet.add(new VarKey(newVars[i], true));
@ -406,7 +406,7 @@ public class UserDefinedVariableSupplier extends CoreMacroSupplierBase {
oldSet.add(new VarKey(oldVars[i], true)); oldSet.add(new VarKey(oldVars[i], true));
} }
HashSet newSetCopy = (HashSet)newSet.clone(); HashSet<VarKey> newSetCopy = (HashSet<VarKey>)newSet.clone();
newSet.removeAll(oldSet); newSet.removeAll(oldSet);
oldSet.removeAll(newSetCopy); oldSet.removeAll(newSetCopy);

View file

@ -0,0 +1,111 @@
/*******************************************************************************
* Copyright (c) 2008 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;
import org.eclipse.cdt.core.cdtvariables.IStorableCdtVariables;
import org.eclipse.cdt.core.cdtvariables.IUserVarSupplier;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.variables.IDynamicVariable;
/**
* Wrapper for UserDefinedMacroSupplier methods
* Note that only config-level macros are supported.
*/
public class UserVarSupplier implements IUserVarSupplier {
private static final int CTX = ICoreVariableContextInfo.CONTEXT_CONFIGURATION;
private static UserVarSupplier sup = null;
/**
* @return an instance of this class.
*/
public static UserVarSupplier getInstance() {
if (sup == null)
sup = new UserVarSupplier();
return sup;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.cdtvariables.IUserVarSupplier#createMacro(org.eclipse.cdt.core.cdtvariables.ICdtVariable, int, java.lang.Object)
*/
public ICdtVariable createMacro(ICdtVariable copy, ICConfigurationDescription contextData) {
return CdtVariableManager.fUserDefinedMacroSupplier.createMacro(copy, CTX, contextData);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.cdtvariables.IUserVarSupplier#createMacro(java.lang.String, int, java.lang.String, java.lang.Object)
*/
public ICdtVariable createMacro(String macroName, int type, String value,
ICConfigurationDescription contextData) {
return CdtVariableManager.fUserDefinedMacroSupplier.createMacro(macroName, type, value, CTX, contextData);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.cdtvariables.IUserVarSupplier#createMacro(java.lang.String, int, java.lang.String[], java.lang.Object)
*/
public ICdtVariable createMacro(String macroName, int type, String[] value,
ICConfigurationDescription contextData) {
return CdtVariableManager.fUserDefinedMacroSupplier.createMacro(macroName, type, value, CTX, contextData);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.cdtvariables.IUserVarSupplier#deleteAll(java.lang.Object)
*/
public void deleteAll(ICConfigurationDescription contextData) {
CdtVariableManager.fUserDefinedMacroSupplier.deleteAll(CTX, contextData);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.cdtvariables.IUserVarSupplier#deleteMacro(java.lang.String, java.lang.Object)
*/
public ICdtVariable deleteMacro(String name, ICConfigurationDescription contextData) {
return CdtVariableManager.fUserDefinedMacroSupplier.deleteMacro(name, CTX, contextData);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.cdtvariables.IUserVarSupplier#getMacros(java.lang.Object)
*/
public ICdtVariable[] getMacros(ICConfigurationDescription contextData) {
return CdtVariableManager.fUserDefinedMacroSupplier.getMacros(CTX, contextData);
}
public void setMacros(ICdtVariable[] m, ICConfigurationDescription contextData) {
CdtVariableManager.fUserDefinedMacroSupplier.setMacros(m, CTX, contextData);
}
/* check whether variable is dynamic */
public boolean isDynamic(ICdtVariable v) {
if (v instanceof EclipseVariablesVariableSupplier.EclipseVarMacro) {
EclipseVariablesVariableSupplier.EclipseVarMacro evar =
(EclipseVariablesVariableSupplier.EclipseVarMacro)v;
if (evar.getVariable() instanceof IDynamicVariable)
return true;
}
return false;
}
public void storeWorkspaceVariables(boolean force) {
CdtVariableManager.fUserDefinedMacroSupplier.storeWorkspaceVariables(force);
}
public IStorableCdtVariables getWorkspaceVariablesCopy() {
return CdtVariableManager.fUserDefinedMacroSupplier.getWorkspaceVariablesCopy();
}
public boolean setWorkspaceVariables(IStorableCdtVariables vars)
throws CoreException {
if (vars instanceof StorableCdtVariables)
return CdtVariableManager.fUserDefinedMacroSupplier.setWorkspaceVariables((StorableCdtVariables)vars);
else
return false;
}
}

View file

@ -545,15 +545,20 @@ implements
} }
private void populateConfigurations() { private void populateConfigurations() {
IProject prj = getProject();
// Do nothing in case of Preferences page.
if (prj == null)
return;
// Do not re-read if list already created by another page // Do not re-read if list already created by another page
if (cfgDescs == null) { if (cfgDescs == null) {
cfgDescs = CDTPropertyManager.getProjectDescription(this, getProject()).getConfigurations(); cfgDescs = CDTPropertyManager.getProjectDescription(this, prj).getConfigurations();
if (cfgDescs == null || cfgDescs.length == 0) return; if (cfgDescs == null || cfgDescs.length == 0) return;
Arrays.sort(cfgDescs, CDTListComparator.getInstance()); Arrays.sort(cfgDescs, CDTListComparator.getInstance());
} else { } else {
// just register in CDTPropertyManager; // just register in CDTPropertyManager;
CDTPropertyManager.getProjectDescription(this, getProject()); CDTPropertyManager.getProjectDescription(this, prj);
} }
// Do nothing if widget not created yet. // Do nothing if widget not created yet.