1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +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.ICdtVariableManager;
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.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.core.settings.model.ICMultiItemsHolder;
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.AbstractPage;
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.envvar.EnvVarOperationProcessor;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.variables.IDynamicVariable;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.MessageDialog;
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 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 ICConfigurationDescription cfgd = null;
private StorableCdtVariables vars = null;
private IStorableCdtVariables vars = null;
//currently the "CWD" and "PWD" macros are not displayed in UI
private static final String fHiddenMacros[] = new String[]{
@ -130,8 +126,7 @@ public class CPropertyVarsTab extends AbstractCPropertyTab {
private boolean fShowSysMacros = false;
private Set<String> fIncorrectlyDefinedMacrosNames = new HashSet<String>();
private static final int CONTEXT = ICoreVariableContextInfo.CONTEXT_CONFIGURATION;
private TableViewer tv;
private Label fStatusLabel;
private Label lb1, lb2;
@ -272,10 +267,10 @@ public class CPropertyVarsTab extends AbstractCPropertyTab {
if (!isUserVar(vars[i]))
vars[i] = null;
for (ICConfigurationDescription c : getCfs()) {
fUserSup.deleteAll(CONTEXT, c);
fUserSup.deleteAll(c);
for (ICdtVariable macro : vars)
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 (forAll) {
for (ICConfigurationDescription c : page.getCfgsEditable())
fUserSup.createMacro(macro, CONTEXT, c);
fUserSup.createMacro(macro, c);
} else {
if (page.isMultiCfg() && cfgd instanceof ICMultiItemsHolder) {
for (ICConfigurationDescription c : getCfs())
fUserSup.createMacro(macro, CONTEXT, c);
fUserSup.createMacro(macro, c);
replaceMacros();
} else
fUserSup.createMacro(macro, CONTEXT, cfgd);
fUserSup.createMacro(macro, cfgd);
}
}
else if (vars != null)
@ -333,11 +328,11 @@ public class CPropertyVarsTab extends AbstractCPropertyTab {
if (page.isMultiCfg() && cfgd instanceof ICMultiItemsHolder) {
ICConfigurationDescription[] cfs = (ICConfigurationDescription[])((ICMultiItemsHolder)cfgd).getItems();
for (int k=0; k<cfs.length; k++)
fUserSup.deleteMacro(macros[i].getName(), CONTEXT, cfs[k]);
fUserSup.deleteMacro(macros[i].getName(), cfs[k]);
replaceMacros();
}
else
fUserSup.deleteMacro(macros[i].getName(), CONTEXT, cfgd);
fUserSup.deleteMacro(macros[i].getName(), cfgd);
}
else if (vars != null)
vars.deleteMacro(macros[i].getName());
@ -368,9 +363,9 @@ public class CPropertyVarsTab extends AbstractCPropertyTab {
if (page.isMultiCfg() && cfgd instanceof ICMultiItemsHolder) {
ICConfigurationDescription[] cfs = (ICConfigurationDescription[])((ICMultiItemsHolder)cfgd).getItems();
for (int i=0; i<cfs.length; i++)
fUserSup.deleteAll(CONTEXT, cfs[i]);
fUserSup.deleteAll(cfs[i]);
} else
fUserSup.deleteAll(CONTEXT, cfgd);
fUserSup.deleteAll(cfgd);
}
else if (vars != null)
vars.deleteAll();
@ -610,19 +605,8 @@ public class CPropertyVarsTab extends AbstractCPropertyTab {
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) {
if (isDynamic(v))
if (fUserSup.isDynamic(v))
return UIMessages.getString(VALUE_ECLIPSE_DYNAMIC);
String value = EMPTY_STR;
try {
@ -646,13 +630,13 @@ public class CPropertyVarsTab extends AbstractCPropertyTab {
if (r0.length != r1.length)
return; // unprobable
for (int i=0; i<r0.length; i++) {
ICdtVariable[] vs = fUserSup.getMacros(CONTEXT, r0[i].getConfiguration());
fUserSup.setMacros(vs, CONTEXT, r1[i].getConfiguration());
ICdtVariable[] vs = fUserSup.getMacros(r0[i].getConfiguration());
fUserSup.setMacros(vs, r1[i].getConfiguration());
}
}
} else {
ICdtVariable[] vs = fUserSup.getMacros(CONTEXT, src.getConfiguration());
fUserSup.setMacros(vs, CONTEXT, dst.getConfiguration());
ICdtVariable[] vs = fUserSup.getMacros(src.getConfiguration());
fUserSup.setMacros(vs, dst.getConfiguration());
}
} else if (vars != null)
fUserSup.storeWorkspaceVariables(true);

View file

@ -23,7 +23,6 @@ import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@ -84,7 +83,7 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
*/
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
@ -97,13 +96,13 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
* Queue of deltas created explicitly by the C Model that
* 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.
* 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.
@ -113,12 +112,12 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
/**
* 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.
*/
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.
*/
@ -127,7 +126,7 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
/*
* Temporary cache of newly opened elements
*/
private ThreadLocal temporaryCache = new ThreadLocal();
private ThreadLocal<Map<ICElement, Object>> temporaryCache = new ThreadLocal<Map<ICElement, Object>>();
/**
* Infos cache.
@ -142,17 +141,17 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
/**
* 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.
*/
private HashMap binaryParsersMap = new HashMap();
private HashMap<IProject, BinaryParserConfig[]> binaryParsersMap = new HashMap<IProject, BinaryParserConfig[]>();
/**
* 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];
@ -464,7 +463,7 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
if (celement.getElementType() == ICElement.C_CCONTAINER) {
ICProject cproject = celement.getCProject();
CProjectInfo pinfo = (CProjectInfo)peekAtInfo(cproject);
ArrayList list = new ArrayList(5);
ArrayList<ICElement> list = new ArrayList<ICElement>(5);
if (pinfo != null && pinfo.vBin != null) {
if (peekAtInfo(pinfo.vBin) != null) {
try {
@ -520,7 +519,7 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
if (cdesc != null) {
ICExtensionReference[] cextensions = cdesc.get(CCorePlugin.BINARY_PARSER_UNIQ_ID, true);
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++) {
BinaryParserConfig config = new BinaryParserConfig(cextensions[i]);
list.add(config);
@ -933,7 +932,7 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
}
if (deltaToNotify != null) {
// 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);
}
}
@ -988,27 +987,24 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
fCModelDeltas.clear();
}
private ICElementDelta mergeDeltas(Collection deltas) {
private ICElementDelta mergeDeltas(Collection<ICElementDelta> deltas) {
synchronized (deltas) {
if (deltas.size() == 0)
return null;
if (deltas.size() == 1)
return (ICElementDelta)deltas.iterator().next();
return deltas.iterator().next();
if (deltas.size() <= 1)
return null;
Iterator iterator = deltas.iterator();
ICElement cRoot = getCModel();
CElementDelta rootDelta = new CElementDelta(cRoot);
boolean insertedTree = false;
while (iterator.hasNext()) {
CElementDelta delta = (CElementDelta)iterator.next();
for (ICElementDelta delta : deltas) {
ICElement element = delta.getElement();
if (cRoot.equals(element)) {
ICElementDelta[] children = delta.getAffectedChildren();
for (int j = 0; j < children.length; j++) {
CElementDelta projectDelta = (CElementDelta)children[j];
for (ICElementDelta child : delta.getAffectedChildren()) {
CElementDelta projectDelta = (CElementDelta)child;
rootDelta.insertDeltaTree(projectDelta.getElement(), projectDelta);
insertedTree = true;
}
@ -1020,7 +1016,7 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
}
}
} else {
rootDelta.insertDeltaTree(element, delta);
rootDelta.insertDeltaTree(element, (CElementDelta)delta);
insertedTree = true;
}
}
@ -1042,12 +1038,11 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
* Returns the info for the 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) {
Object result = tempCache.get(element);
if (result != null) {
if (result != null)
return result;
}
}
return this.cache.getInfo(element);
}
@ -1057,7 +1052,7 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
* disturbing the cache ordering.
*/
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) {
Object result = tempCache.get(element);
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
* 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
Object existingInfo = this.cache.peekAtInfo(openedElement);
if (openedElement instanceof IParent && existingInfo instanceof CElementInfo) {
@ -1089,12 +1084,8 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
}
}
Iterator iterator = newElements.keySet().iterator();
while (iterator.hasNext()) {
ICElement element = (ICElement)iterator.next();
Object info = newElements.get(element);
this.cache.putInfo(element, info);
}
for (ICElement element : newElements.keySet())
this.cache.putInfo(element, newElements.get(element));
}
/**
@ -1128,10 +1119,10 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
* Returns the temporary cache for newly opened elements for the current thread.
* Creates it if not already created.
*/
public HashMap getTemporaryCache() {
HashMap result = (HashMap)this.temporaryCache.get();
public HashMap<ICElement, Object> getTemporaryCache() {
HashMap<ICElement, Object> result = (HashMap<ICElement, Object>)this.temporaryCache.get();
if (result == null) {
result = new HashMap();
result = new HashMap<ICElement, Object>();
this.temporaryCache.set(result);
}
return result;

View file

@ -20,19 +20,20 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
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.IPDOMManager;
import org.eclipse.cdt.core.envvar.IEnvironmentVariableManager;
import org.eclipse.cdt.core.index.IIndexManager;
import org.eclipse.cdt.core.model.CModelException;
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.parser.IScannerInfoProvider;
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.PositionTrackerManager;
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.model.BufferManager;
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 == 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;
Collection copies = perFactoryWorkingCopies.values();
Collection<IWorkingCopy> copies = perFactoryWorkingCopies.values();
IWorkingCopy[] result = new IWorkingCopy[copies.size()];
copies.toArray(result);
return result;
@ -234,11 +236,11 @@ public class CCorePlugin extends Plugin {
}
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) {
return MessageFormat.format(getResourceString(key), args);
return MessageFormat.format(getResourceString(key), (Object[])args);
}
public static ResourceBundle getResourceBundle() {
@ -380,29 +382,23 @@ public class CCorePlugin extends Plugin {
* @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
Preferences preferences = getDefault().getPluginPreferences();
HashSet optionNames = CModelManager.OptionNames;
HashSet<String> optionNames = CModelManager.OptionNames;
// get preferences set to their default
String[] defaultPropertyNames = preferences.defaultPropertyNames();
for (int i = 0; i < defaultPropertyNames.length; i++){
String propertyName = defaultPropertyNames[i];
if (optionNames.contains(propertyName)) {
for (String propertyName : preferences.defaultPropertyNames()){
if (optionNames.contains(propertyName))
defaultOptions.put(propertyName, preferences.getDefaultString(propertyName));
}
}
// get preferences not set to their default
String[] propertyNames = preferences.propertyNames();
for (int i = 0; i < propertyNames.length; i++){
String propertyName = propertyNames[i];
if (optionNames.contains(propertyName)) {
for (String propertyName : preferences.propertyNames()) {
if (optionNames.contains(propertyName))
defaultOptions.put(propertyName, preferences.getDefaultString(propertyName));
}
}
// get encoding through resource plugin
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>)
* @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
Plugin plugin = getDefault();
if (plugin != null) {
Preferences preferences = plugin.getPluginPreferences();
HashSet optionNames = CModelManager.OptionNames;
HashSet<String> optionNames = CModelManager.OptionNames;
// get preferences set to their default
String[] defaultPropertyNames = preferences.defaultPropertyNames();
for (int i = 0; i < defaultPropertyNames.length; i++){
String propertyName = defaultPropertyNames[i];
for (String propertyName : preferences.defaultPropertyNames()){
if (optionNames.contains(propertyName)){
options.put(propertyName, preferences.getDefaultString(propertyName));
}
}
// get preferences not set to their default
String[] propertyNames = preferences.propertyNames();
for (int i = 0; i < propertyNames.length; i++){
String propertyName = propertyNames[i];
for (String propertyName : preferences.propertyNames()){
if (optionNames.contains(propertyName)){
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
* @see CCorePlugin#getDefaultOptions
*/
public static void setOptions(HashMap newOptions) {
public static void setOptions(HashMap<String, String> newOptions) {
// see #initializeDefaultPluginPreferences() for changing default settings
Preferences preferences = getDefault().getPluginPreferences();
@ -497,9 +489,7 @@ public class CCorePlugin extends Plugin {
if (newOptions == null){
newOptions = getDefaultOptions();
}
Iterator keys = newOptions.keySet().iterator();
while (keys.hasNext()){
String key = (String)keys.next();
for (String key : newOptions.keySet()){
if (!CModelManager.OptionNames.contains(key)) continue; // unrecognized option
if (key.equals(CORE_ENCODING)) continue; // skipped, contributed by resource prefs
String value = (String)newOptions.get(key);
@ -563,15 +553,10 @@ public class CCorePlugin extends Plugin {
ICExtensionReference ext[] = new ICExtensionReference[0];
if (project != null) {
try {
ICDescriptor cdesc = getCProjectDescription(project);
ICDescriptor cdesc = getCProjectDescription(project, false);
ICExtensionReference[] cextensions = cdesc.get(BINARY_PARSER_UNIQ_ID, true);
if (cextensions.length > 0) {
ArrayList list = new ArrayList(cextensions.length);
for (int i = 0; i < cextensions.length; i++) {
list.add(cextensions[i]);
}
ext = (ICExtensionReference[])list.toArray(ext);
}
if (cextensions != null && cextensions.length > 0)
ext = cextensions;
} catch (CoreException e) {
log(e);
}
@ -589,19 +574,19 @@ public class CCorePlugin extends Plugin {
IBinaryParser parsers[] = null;
if (project != null) {
try {
ICDescriptor cdesc = getCProjectDescription(project);
ICDescriptor cdesc = getCProjectDescription(project, false);
ICExtensionReference[] cextensions = cdesc.get(BINARY_PARSER_UNIQ_ID, true);
if (cextensions.length > 0) {
ArrayList list = new ArrayList(cextensions.length);
for (int i = 0; i < cextensions.length; i++) {
ArrayList<IBinaryParser> list = new ArrayList<IBinaryParser>(cextensions.length);
for (ICExtensionReference ref : cextensions) {
IBinaryParser parser = null;
try {
parser = (IBinaryParser) cextensions[i].createExtension();
parser = (IBinaryParser)ref.createExtension();
} catch (ClassCastException e) {
//
log(e); // wrong binary parser definition ?
}
if (parser != null) {
list.add(parser);
list.add(parser);
}
}
parsers = new IBinaryParser[list.size()];
@ -939,11 +924,10 @@ public class CCorePlugin extends Plugin {
String[] empty = new String[0];
if (extension != null) {
IExtension[] extensions = extension.getExtensions();
ArrayList list = new ArrayList(extensions.length);
for (int i = 0; i < extensions.length; i++) {
list.add(extensions[i].getUniqueIdentifier());
}
return (String[]) list.toArray(empty);
ArrayList<String> list = new ArrayList<String>(extensions.length);
for (IExtension e : extensions)
list.add(e.getUniqueIdentifier());
return list.toArray(empty);
}
return empty;
}
@ -954,18 +938,15 @@ public class CCorePlugin extends Plugin {
IExtensionPoint extension = Platform.getExtensionRegistry().getExtensionPoint(CCorePlugin.PLUGIN_ID, ERROR_PARSER_SIMPLE_ID);
if (extension != null) {
IExtension[] extensions = extension.getExtensions();
List list = new ArrayList(extensions.length);
for (int i = 0; i < extensions.length; i++) {
String parserID = extensions[i].getUniqueIdentifier();
List<IErrorParser> list = new ArrayList<IErrorParser>(extensions.length);
for (IExtension e : extensions) {
String parserID = e.getUniqueIdentifier();
if ((id == null && parserID != null) || (id != null && id.equals(parserID))) {
IConfigurationElement[] configElements = extensions[i]. getConfigurationElements();
for (int j = 0; j < configElements.length; j++) {
IErrorParser parser = (IErrorParser)configElements[j].createExecutableExtension("class"); //$NON-NLS-1$
list.add(parser);
}
for (IConfigurationElement ce : e.getConfigurationElements())
list.add((IErrorParser)ce.createExecutableExtension("class")); //$NON-NLS-1$
}
}
return (IErrorParser[]) list.toArray(empty);
return list.toArray(empty);
}
} catch (CoreException e) {
log(e);
@ -975,29 +956,8 @@ public class CCorePlugin extends Plugin {
public IScannerInfoProvider getScannerInfoProvider(IProject 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
* Same as: <pre>
@ -1234,4 +1194,13 @@ public class CCorePlugin extends Plugin {
public ICProjectDescriptionManager getProjectDescriptionManager(){
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
* are made available under the terms of the Eclipse Public License v1.0
* 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.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.eclipse.cdt.core.cdtvariables.CdtVariableException;
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.internal.core.cdtvariables.UserDefinedVariableSupplier.VarKey;
import org.eclipse.cdt.internal.core.settings.model.ExceptionFactory;
@ -29,19 +29,16 @@ import org.eclipse.cdt.utils.cdtvariables.CdtVariableResolver;
* @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 EXPAND_ENVIRONMENT_MACROS = "expandEnvironmentMacros"; //$NON-NLS-1$
// public static final String TRUE = "true"; //$NON-NLS-1$
private HashMap fMacros;
// private boolean fExpandInMakefile = false;
private HashMap<String, ICdtVariable> fMacros;
private boolean fIsDirty = false;
private boolean fIsChanged = false;
private boolean fIsReadOnly;
private HashMap getMap(){
private HashMap<String, ICdtVariable> getMap(){
if(fMacros == null)
fMacros = new HashMap();
fMacros = new HashMap<String, ICdtVariable>();
return fMacros;
}
@ -49,13 +46,14 @@ public class StorableCdtVariables {
fIsReadOnly = readOnly;
}
@SuppressWarnings("unchecked")
public StorableCdtVariables(StorableCdtVariables base, boolean readOnly) {
fMacros = (HashMap)base.getMap().clone();
fMacros = (HashMap<String, ICdtVariable>)base.getMap().clone();
fIsReadOnly = 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++){
addMacro(vars[i]);
}
@ -86,13 +84,9 @@ public class StorableCdtVariables {
}
public void serialize(ICStorageElement element){
// if(fExpandInMakefile)
// element.setAttribute(EXPAND_ENVIRONMENT_MACROS,TRUE);
if(fMacros != null){
Iterator iter = fMacros.values().iterator();
while(iter.hasNext()){
StorableCdtVariable macro = (StorableCdtVariable)iter.next();
for (ICdtVariable v : fMacros.values()){
StorableCdtVariable macro = (StorableCdtVariable)v;
ICStorageElement macroEl;
if(CdtVariableResolver.isStringListVariable(macro.getValueType()))
macroEl = element.createChild(StorableCdtVariable.STRINGLIST_MACRO_ELEMENT_NAME);
@ -188,9 +182,7 @@ public class StorableCdtVariables {
deleteAll();
else{
if (getMap().size() != 0) {
Iterator iter = getMap().values().iterator();
while(iter.hasNext()){
ICdtVariable m = (ICdtVariable)iter.next();
for (ICdtVariable m : getMap().values()){
int i;
for(i = 0 ; i < macros.length; i++){
if(m.getName().equals(macros[i].getName()))
@ -343,9 +335,8 @@ public class StorableCdtVariables {
}
public ICdtVariable[] getMacros(){
Collection macros = getMap().values();
return (ICdtVariable[])macros.toArray(new ICdtVariable[macros.size()]);
Collection<ICdtVariable> macros = getMap().values();
return macros.toArray(new ICdtVariable[macros.size()]);
}
public ICdtVariable deleteMacro(String name){
@ -367,7 +358,7 @@ public class StorableCdtVariables {
public boolean deleteAll(){
if(fIsReadOnly)
throw ExceptionFactory.createIsReadOnlyException();
Map map = getMap();
Map<String, ICdtVariable> map = getMap();
if(map.size() > 0){
fIsDirty = 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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -67,7 +67,7 @@ public class UserDefinedVariableSupplier extends CoreMacroSupplierBase {
private static UserDefinedVariableSupplier fInstance;
private StorableCdtVariables fWorkspaceMacros;
private Set fListeners;
private Set<ICdtVariableChangeListener> fListeners;
private StorableCdtVariables getStorableMacros(int contextType, Object contextData){
StorableCdtVariables macros = null;
@ -93,7 +93,7 @@ public class UserDefinedVariableSupplier extends CoreMacroSupplierBase {
}
private UserDefinedVariableSupplier(){
fListeners = Collections.synchronizedSet(new HashSet());
fListeners = Collections.synchronizedSet(new HashSet<ICdtVariableChangeListener>());
}
public static UserDefinedVariableSupplier getInstance(){
@ -376,16 +376,16 @@ public class UserDefinedVariableSupplier extends CoreMacroSupplierBase {
return createVariableChangeEvent(newVars, oldVars);
}
static ICdtVariable[] varsFromKeySet(Set set){
static ICdtVariable[] varsFromKeySet(Set<VarKey> 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();
for(VarKey key : set) {
vars[i++] = key.getVariable();
}
return vars;
}
@SuppressWarnings("unchecked")
static VariableChangeEvent createVariableChangeEvent(ICdtVariable[] newVars, ICdtVariable[] oldVars){
ICdtVariable[] addedVars = null, removedVars = null, changedVars = null;
@ -395,8 +395,8 @@ public class UserDefinedVariableSupplier extends CoreMacroSupplierBase {
} else if(newVars == null || newVars.length == 0){
removedVars = (ICdtVariable[])oldVars.clone();
} else {
HashSet newSet = new HashSet(newVars.length);
HashSet oldSet = new HashSet(oldVars.length);
HashSet<VarKey> newSet = new HashSet<VarKey>(newVars.length);
HashSet<VarKey> oldSet = new HashSet<VarKey>(oldVars.length);
for(int i = 0; i < newVars.length; i++){
newSet.add(new VarKey(newVars[i], true));
@ -406,7 +406,7 @@ public class UserDefinedVariableSupplier extends CoreMacroSupplierBase {
oldSet.add(new VarKey(oldVars[i], true));
}
HashSet newSetCopy = (HashSet)newSet.clone();
HashSet<VarKey> newSetCopy = (HashSet<VarKey>)newSet.clone();
newSet.removeAll(oldSet);
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() {
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
if (cfgDescs == null) {
cfgDescs = CDTPropertyManager.getProjectDescription(this, getProject()).getConfigurations();
cfgDescs = CDTPropertyManager.getProjectDescription(this, prj).getConfigurations();
if (cfgDescs == null || cfgDescs.length == 0) return;
Arrays.sort(cfgDescs, CDTListComparator.getInstance());
} else {
// just register in CDTPropertyManager;
CDTPropertyManager.getProjectDescription(this, getProject());
CDTPropertyManager.getProjectDescription(this, prj);
}
// Do nothing if widget not created yet.