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