diff options
Diffstat (limited to 'core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables')
14 files changed, 1020 insertions, 1096 deletions
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/BuildSystemVariableSupplier.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/BuildSystemVariableSupplier.java index 40bfd2d20f1..f78c1859353 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/BuildSystemVariableSupplier.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/BuildSystemVariableSupplier.java @@ -22,50 +22,51 @@ import org.eclipse.cdt.utils.cdtvariables.SupplierBasedCdtVariableManager; public class BuildSystemVariableSupplier extends CoreMacroSupplierBase { private static BuildSystemVariableSupplier fInstance; - private BuildSystemVariableSupplier(){ + + private BuildSystemVariableSupplier() { } - - public static BuildSystemVariableSupplier getInstance(){ - if(fInstance == null){ + + public static BuildSystemVariableSupplier getInstance() { + if (fInstance == null) { fInstance = new BuildSystemVariableSupplier(); } return fInstance; } - private class ExtensionMacroProvider extends CdtVariableManager{ + + private class ExtensionMacroProvider extends CdtVariableManager { private IVariableContextInfo fStartInfo; private int fContextType; private Object fContextData; private boolean fStartInitialized; - - public ExtensionMacroProvider(int contextType, Object contextData){ + + public ExtensionMacroProvider(int contextType, Object contextData) { fContextType = contextType; fContextData = contextData; } @Override - public IVariableContextInfo getMacroContextInfo(int contextType,Object contextData){ + public IVariableContextInfo getMacroContextInfo(int contextType, Object contextData) { IVariableContextInfo startInfo = getStartInfo(); - if(contextType == fContextType && - contextData == fContextData) + if (contextType == fContextType && contextData == fContextData) return startInfo; - + IVariableContextInfo info = super.getMacroContextInfo(contextType, contextData); - if(info == null) + if (info == null) return null; - - if(SupplierBasedCdtVariableManager.checkParentContextRelation(startInfo,info)) + + if (SupplierBasedCdtVariableManager.checkParentContextRelation(startInfo, info)) return info; return null; } - - protected IVariableContextInfo getStartInfo(){ - if(fStartInfo == null && !fStartInitialized){ - IVariableContextInfo info = super.getMacroContextInfo(fContextType,fContextData); - if(info != null){ + + protected IVariableContextInfo getStartInfo() { + if (fStartInfo == null && !fStartInitialized) { + IVariableContextInfo info = super.getMacroContextInfo(fContextType, fContextData); + if (info != null) { ICdtVariableSupplier suppliers[] = info.getSuppliers(); suppliers = filterValidSuppliers(suppliers); - if(suppliers != null) - fStartInfo = new DefaultVariableContextInfo(fContextType,fContextData,suppliers); + if (suppliers != null) + fStartInfo = new DefaultVariableContextInfo(fContextType, fContextData, suppliers); else fStartInfo = info.getNext(); fStartInitialized = true; @@ -74,47 +75,45 @@ public class BuildSystemVariableSupplier extends CoreMacroSupplierBase { } return fStartInfo; } - - protected ICdtVariableSupplier[] filterValidSuppliers(ICdtVariableSupplier suppliers[]){ - if(suppliers == null) + + protected ICdtVariableSupplier[] filterValidSuppliers(ICdtVariableSupplier suppliers[]) { + if (suppliers == null) return null; int i = 0, j = 0; - for(i = 0; i < suppliers.length; i++){ - if(suppliers[i] == this) + for (i = 0; i < suppliers.length; i++) { + if (suppliers[i] == this) break; } - - - if(i >= suppliers.length) + + if (i >= suppliers.length) return null; - + int startNum = i + 1; - ICdtVariableSupplier validSuppliers[] = - new ICdtVariableSupplier[suppliers.length - startNum]; - - for(i = startNum, j = 0; i < suppliers.length; i++, j++) + ICdtVariableSupplier validSuppliers[] = new ICdtVariableSupplier[suppliers.length - startNum]; + + for (i = startNum, j = 0; i < suppliers.length; i++, j++) validSuppliers[j] = suppliers[i]; - + return validSuppliers; } } @Override protected ICdtVariable getMacro(String name, int type, Object data) { - ICConfigurationDescription des = (ICConfigurationDescription)data; + ICConfigurationDescription des = (ICConfigurationDescription) data; ICdtVariablesContributor cr = des.getBuildVariablesContributor(); - if(cr != null) + if (cr != null) return cr.getVariable(name, new ExtensionMacroProvider(type, data)); return null; } @Override protected ICdtVariable[] getMacros(int type, Object data) { - ICConfigurationDescription des = (ICConfigurationDescription)data; + ICConfigurationDescription des = (ICConfigurationDescription) data; ICdtVariablesContributor cr = des.getBuildVariablesContributor(); - if(cr != null) + if (cr != null) return cr.getVariables(new ExtensionMacroProvider(type, data)); return new ICdtVariable[0]; } diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/CdtMacroSupplier.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/CdtMacroSupplier.java index 2dc248db910..a47a3402f01 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/CdtMacroSupplier.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/CdtMacroSupplier.java @@ -26,7 +26,7 @@ import org.osgi.framework.Bundle; /** * This supplier is used to suply MBS-predefined macros - * + * * @since 3.0 */ public class CdtMacroSupplier extends CoreMacroSupplierBase { @@ -45,485 +45,466 @@ public class CdtMacroSupplier extends CoreMacroSupplierBase { public static final String VAR_ARCH_TYPE = "ArchType"; //$NON-NLS-1$ private static CdtMacroSupplier fInstance; - - private static final String fConfigurationMacros[] = new String[] { - VAR_CONFIG_NAME, - VAR_CONFIG_DESCRIPTION, - VAR_PROJ_NAME, - VAR_PROJ_DIR_PATH, -// "BuildArtifactFileName", //$NON-NLS-1$ -// "BuildArtifactFileExt", //$NON-NLS-1$ -// "BuildArtifactFileBaseName", //$NON-NLS-1$ -// "BuildArtifactFilePrefix", //$NON-NLS-1$ -// "TargetOsList", //$NON-NLS-1$ -// "TargetArchList", //$NON-NLS-1$ - }; - private static final String fWorkspaceMacros[] = new String[] { - VAR_WORKSPACE_DIR_PATH, - VAR_DIRECTORY_DELIMITER, - VAR_PATH_DELIMITER, + private static final String fConfigurationMacros[] = new String[] { VAR_CONFIG_NAME, VAR_CONFIG_DESCRIPTION, + VAR_PROJ_NAME, VAR_PROJ_DIR_PATH, + // "BuildArtifactFileName", //$NON-NLS-1$ + // "BuildArtifactFileExt", //$NON-NLS-1$ + // "BuildArtifactFileBaseName", //$NON-NLS-1$ + // "BuildArtifactFilePrefix", //$NON-NLS-1$ + // "TargetOsList", //$NON-NLS-1$ + // "TargetArchList", //$NON-NLS-1$ }; - private static final String fCDTEclipseMacros[] = new String[] { - VAR_ECLIPSE_VERSION, - VAR_CDT_VERSION, -// "MBSVersion", //$NON-NLS-1$ - VAR_HOST_OS_NAME, - VAR_HOST_ARCH_NAME, - VAR_OS_TYPE, - VAR_ARCH_TYPE, - }; - - -/* private String getExplicitFileMacroValue(String name, IPath inputFileLocation, IPath outputFileLocation, IConfiguration cfg){ - String value = null; - if("InputFileName".equals(name)){ //$NON-NLS-1$ - if(inputFileLocation != null && inputFileLocation.segmentCount() > 0) - value = inputFileLocation.lastSegment(); - }else if("InputFileExt".equals(name)){ //$NON-NLS-1$ - if(inputFileLocation != null && inputFileLocation.segmentCount() > 0) - value = getExtension(inputFileLocation.lastSegment()); - }else if("InputFileBaseName".equals(name)){ //$NON-NLS-1$ - if(inputFileLocation != null && inputFileLocation.segmentCount() > 0) - value = getBaseName(inputFileLocation.lastSegment()); - }else if("InputFileRelPath".equals(name)){ //$NON-NLS-1$ - if(inputFileLocation != null && inputFileLocation.segmentCount() > 0){ - IPath workingDirectory = getBuilderCWD(cfg); - if(workingDirectory != null){ - IPath filePath = ManagedBuildManager.calculateRelativePath(workingDirectory, inputFileLocation); - if(filePath != null) - value = filePath.toOSString(); + private static final String fWorkspaceMacros[] = new String[] { VAR_WORKSPACE_DIR_PATH, VAR_DIRECTORY_DELIMITER, + VAR_PATH_DELIMITER, }; + + private static final String fCDTEclipseMacros[] = new String[] { VAR_ECLIPSE_VERSION, VAR_CDT_VERSION, + // "MBSVersion", //$NON-NLS-1$ + VAR_HOST_OS_NAME, VAR_HOST_ARCH_NAME, VAR_OS_TYPE, VAR_ARCH_TYPE, }; + + /* private String getExplicitFileMacroValue(String name, IPath inputFileLocation, IPath outputFileLocation, IConfiguration cfg){ + String value = null; + if("InputFileName".equals(name)){ //$NON-NLS-1$ + if(inputFileLocation != null && inputFileLocation.segmentCount() > 0) + value = inputFileLocation.lastSegment(); + }else if("InputFileExt".equals(name)){ //$NON-NLS-1$ + if(inputFileLocation != null && inputFileLocation.segmentCount() > 0) + value = getExtension(inputFileLocation.lastSegment()); + }else if("InputFileBaseName".equals(name)){ //$NON-NLS-1$ + if(inputFileLocation != null && inputFileLocation.segmentCount() > 0) + value = getBaseName(inputFileLocation.lastSegment()); + }else if("InputFileRelPath".equals(name)){ //$NON-NLS-1$ + if(inputFileLocation != null && inputFileLocation.segmentCount() > 0){ + IPath workingDirectory = getBuilderCWD(cfg); + if(workingDirectory != null){ + IPath filePath = ManagedBuildManager.calculateRelativePath(workingDirectory, inputFileLocation); + if(filePath != null) + value = filePath.toOSString(); + } } } - } - else if("InputDirRelPath".equals(name)){ //$NON-NLS-1$ - if(inputFileLocation != null && inputFileLocation.segmentCount() > 0){ - IPath workingDirectory = getBuilderCWD(cfg); - if(workingDirectory != null){ - IPath filePath = ManagedBuildManager.calculateRelativePath(workingDirectory, inputFileLocation.removeLastSegments(1).addTrailingSeparator()); - if(filePath != null) - value = filePath.toOSString(); + else if("InputDirRelPath".equals(name)){ //$NON-NLS-1$ + if(inputFileLocation != null && inputFileLocation.segmentCount() > 0){ + IPath workingDirectory = getBuilderCWD(cfg); + if(workingDirectory != null){ + IPath filePath = ManagedBuildManager.calculateRelativePath(workingDirectory, inputFileLocation.removeLastSegments(1).addTrailingSeparator()); + if(filePath != null) + value = filePath.toOSString(); + } } } - } - else if("OutputFileName".equals(name)){ //$NON-NLS-1$ - if(outputFileLocation != null && outputFileLocation.segmentCount() > 0) - value = outputFileLocation.lastSegment(); - }else if("OutputFileExt".equals(name)){ //$NON-NLS-1$ - if(outputFileLocation != null && outputFileLocation.segmentCount() > 0) - value = getExtension(outputFileLocation.lastSegment()); - }else if("OutputFileBaseName".equals(name)){ //$NON-NLS-1$ - if(outputFileLocation != null && outputFileLocation.segmentCount() > 0) - value = getBaseName(outputFileLocation.lastSegment()); - }else if("OutputFileRelPath".equals(name)){ //$NON-NLS-1$ - if(outputFileLocation != null && outputFileLocation.segmentCount() > 0){ - IPath workingDirectory = getBuilderCWD(cfg); - if(workingDirectory != null){ - IPath filePath = ManagedBuildManager.calculateRelativePath(workingDirectory, outputFileLocation); - if(filePath != null) - value = filePath.toOSString(); + else if("OutputFileName".equals(name)){ //$NON-NLS-1$ + if(outputFileLocation != null && outputFileLocation.segmentCount() > 0) + value = outputFileLocation.lastSegment(); + }else if("OutputFileExt".equals(name)){ //$NON-NLS-1$ + if(outputFileLocation != null && outputFileLocation.segmentCount() > 0) + value = getExtension(outputFileLocation.lastSegment()); + }else if("OutputFileBaseName".equals(name)){ //$NON-NLS-1$ + if(outputFileLocation != null && outputFileLocation.segmentCount() > 0) + value = getBaseName(outputFileLocation.lastSegment()); + }else if("OutputFileRelPath".equals(name)){ //$NON-NLS-1$ + if(outputFileLocation != null && outputFileLocation.segmentCount() > 0){ + IPath workingDirectory = getBuilderCWD(cfg); + if(workingDirectory != null){ + IPath filePath = ManagedBuildManager.calculateRelativePath(workingDirectory, outputFileLocation); + if(filePath != null) + value = filePath.toOSString(); + } } - } - }else if("OutputDirRelPath".equals(name)){ //$NON-NLS-1$ - if(outputFileLocation != null && outputFileLocation.segmentCount() > 0){ - IPath workingDirectory = getBuilderCWD(cfg); - if(workingDirectory != null){ - IPath filePath = ManagedBuildManager.calculateRelativePath(workingDirectory, outputFileLocation.removeLastSegments(1).addTrailingSeparator()); - if(filePath != null) - value = filePath.toOSString(); + }else if("OutputDirRelPath".equals(name)){ //$NON-NLS-1$ + if(outputFileLocation != null && outputFileLocation.segmentCount() > 0){ + IPath workingDirectory = getBuilderCWD(cfg); + if(workingDirectory != null){ + IPath filePath = ManagedBuildManager.calculateRelativePath(workingDirectory, outputFileLocation.removeLastSegments(1).addTrailingSeparator()); + if(filePath != null) + value = filePath.toOSString(); + } } } - } - - return value; - }*/ - public String[] getMacroNames(int contextType){ - return getMacroNames(contextType,true); + return value; + }*/ + + public String[] getMacroNames(int contextType) { + return getMacroNames(contextType, true); } - private String[] getMacroNames(int contextType, boolean clone){ + private String[] getMacroNames(int contextType, boolean clone) { String names[] = null; - switch(contextType){ + switch (contextType) { case ICoreVariableContextInfo.CONTEXT_CONFIGURATION: - names = fConfigurationMacros; + names = fConfigurationMacros; break; case ICoreVariableContextInfo.CONTEXT_WORKSPACE: - names = fWorkspaceMacros; + names = fWorkspaceMacros; break; case ICoreVariableContextInfo.CONTEXT_INSTALLATIONS: - names = fCDTEclipseMacros; + names = fCDTEclipseMacros; break; case ICoreVariableContextInfo.CONTEXT_ECLIPSEENV: break; } - if(names != null) - return clone ? (String[])names.clone() : names; + if (names != null) + return clone ? (String[]) names.clone() : names; return null; } - private CdtMacroSupplier(){ - + private CdtMacroSupplier() { + } - public static CdtMacroSupplier getInstance(){ - if(fInstance == null) + public static CdtMacroSupplier getInstance() { + if (fInstance == null) fInstance = new CdtMacroSupplier(); return fInstance; } - + /* (non-Javadoc) * @see org.eclipse.cdt.managedbuilder.macros.IBuildMacroSupplier#getMacro(java.lang.String, int, java.lang.Object) */ @Override - public ICdtVariable getMacro(String macroName, int contextType, - Object contextData) { - ICdtVariable macro = null; - switch(contextType){ + public ICdtVariable getMacro(String macroName, int contextType, Object contextData) { + ICdtVariable macro = null; + switch (contextType) { case ICoreVariableContextInfo.CONTEXT_CONFIGURATION: - if(contextData instanceof ICConfigurationDescription){ - macro = getMacro(macroName, (ICConfigurationDescription)contextData); + if (contextData instanceof ICConfigurationDescription) { + macro = getMacro(macroName, (ICConfigurationDescription) contextData); } break; case ICoreVariableContextInfo.CONTEXT_WORKSPACE: - if(contextData == null || contextData instanceof IWorkspace){ - macro = getMacro(macroName, (IWorkspace)contextData); + if (contextData == null || contextData instanceof IWorkspace) { + macro = getMacro(macroName, (IWorkspace) contextData); } break; case ICoreVariableContextInfo.CONTEXT_INSTALLATIONS: - if(contextData == null){ + if (contextData == null) { macro = getMacro(macroName); } break; case ICoreVariableContextInfo.CONTEXT_ECLIPSEENV: break; } - + return macro; } - private IProject getProject(ICConfigurationDescription cfgDes){ + private IProject getProject(ICConfigurationDescription cfgDes) { ICProjectDescription des = cfgDes.getProjectDescription(); return des != null ? des.getProject() : null; } - - public ICdtVariable getMacro(String macroName, ICConfigurationDescription cfg){ + + public ICdtVariable getMacro(String macroName, ICConfigurationDescription cfg) { ICdtVariable macro = null; if (VAR_CONFIG_NAME.equals(macroName)) { - macro = new CdtVariable(macroName,ICdtVariable.VALUE_TEXT,cfg.getName()); - } - else if (VAR_CONFIG_DESCRIPTION.equals(macroName)) { - macro = new CdtVariable(macroName,ICdtVariable.VALUE_TEXT,cfg.getDescription()); + macro = new CdtVariable(macroName, ICdtVariable.VALUE_TEXT, cfg.getName()); + } else if (VAR_CONFIG_DESCRIPTION.equals(macroName)) { + macro = new CdtVariable(macroName, ICdtVariable.VALUE_TEXT, cfg.getDescription()); } else if (VAR_PROJ_NAME.equals(macroName)) { IProject project = getProject(cfg); - if(project != null) - macro = new CdtVariable(macroName,ICdtVariable.VALUE_TEXT,project.getName()); + if (project != null) + macro = new CdtVariable(macroName, ICdtVariable.VALUE_TEXT, project.getName()); } else if (VAR_PROJ_DIR_PATH.equals(macroName)) { IProject project = getProject(cfg); - if(project != null && project.getLocation() != null) // in the EFS world getLocation() can return null - macro = new CdtVariable(macroName,ICdtVariable.VALUE_TEXT,project.getLocation().toString()); + if (project != null && project.getLocation() != null) // in the EFS world getLocation() can return null + macro = new CdtVariable(macroName, ICdtVariable.VALUE_TEXT, project.getLocation().toString()); } -/* else if("BuildArtifactFileName".equals(macroName)){ //$NON-NLS-1$ - String name = cfg.getArtifactName(); - String ext = cfg.getArtifactExtension(); - if(ext != null && !EMPTY_STRING.equals(ext)) - name = name + DOT + ext; - macro = new BuildMacro(macroName,IBuildMacro.VALUE_TEXT,name); - }*/ -/* else if("BuildArtifactFileExt".equals(macroName)){ //$NON-NLS-1$ - String ext = cfg.getArtifactExtension(); - macro = new BuildMacro(macroName,IBuildMacro.VALUE_TEXT,ext); - }*/ -/* else if("BuildArtifactFileBaseName".equals(macroName)){ //$NON-NLS-1$ - String name = cfg.getArtifactName(); - ITool targetTool = cfg.calculateTargetTool(); - if(targetTool != null){ - IOutputType pot = targetTool.getPrimaryOutputType(); - String prefix = pot.getOutputPrefix(); - - - // Resolve any macros in the outputPrefix - // Note that we cannot use file macros because if we do a clean - // we need to know the actual - // name of the file to clean, and cannot use any builder - // variables such as $@. Hence - // we use the next best thing, i.e. configuration context. - - // figure out the configuration we're using - IBuildObject toolParent = targetTool.getParent(); - IConfiguration config = null; - // if the parent is a config then we're done - if (toolParent instanceof IConfiguration) - config = (IConfiguration) toolParent; - else if (toolParent instanceof IToolChain) { - // must be a toolchain - config = (IConfiguration) ((IToolChain) toolParent) - .getParent(); - } + /* else if("BuildArtifactFileName".equals(macroName)){ //$NON-NLS-1$ + String name = cfg.getArtifactName(); + String ext = cfg.getArtifactExtension(); + if(ext != null && !EMPTY_STRING.equals(ext)) + name = name + DOT + ext; + macro = new BuildMacro(macroName,IBuildMacro.VALUE_TEXT,name); + }*/ + /* else if("BuildArtifactFileExt".equals(macroName)){ //$NON-NLS-1$ + String ext = cfg.getArtifactExtension(); + macro = new BuildMacro(macroName,IBuildMacro.VALUE_TEXT,ext); + }*/ + /* else if("BuildArtifactFileBaseName".equals(macroName)){ //$NON-NLS-1$ + String name = cfg.getArtifactName(); + ITool targetTool = cfg.calculateTargetTool(); + if(targetTool != null){ + IOutputType pot = targetTool.getPrimaryOutputType(); + String prefix = pot.getOutputPrefix(); - else if (toolParent instanceof IResourceConfiguration) { - config = (IConfiguration) ((IResourceConfiguration) toolParent) - .getParent(); - } - else { - // bad - throw new AssertionError( - "tool parent must be one of configuration, toolchain, or resource configuration"); - } + // Resolve any macros in the outputPrefix + // Note that we cannot use file macros because if we do a clean + // we need to know the actual + // name of the file to clean, and cannot use any builder + // variables such as $@. Hence + // we use the next best thing, i.e. configuration context. - if (config != null) { - - try { - prefix = ManagedBuildManager - .getBuildMacroProvider() - .resolveValueToMakefileFormat( - prefix, - "", //$NON-NLS-1$ - " ", //$NON-NLS-1$ - IBuildMacroProvider.CONTEXT_CONFIGURATION, - config); - } + // figure out the configuration we're using + IBuildObject toolParent = targetTool.getParent(); + IConfiguration config = null; + // if the parent is a config then we're done + if (toolParent instanceof IConfiguration) + config = (IConfiguration) toolParent; + else if (toolParent instanceof IToolChain) { + // must be a toolchain + config = (IConfiguration) ((IToolChain) toolParent) + .getParent(); + } - catch (BuildMacroException e) { - } + else if (toolParent instanceof IResourceConfiguration) { + config = (IConfiguration) ((IResourceConfiguration) toolParent) + .getParent(); + } - } + else { + // bad + throw new AssertionError( + "tool parent must be one of configuration, toolchain, or resource configuration"); + } - - if(prefix != null && !EMPTY_STRING.equals(prefix)) - name = prefix + name; - } - macro = new BuildMacro(macroName,IBuildMacro.VALUE_TEXT,name); - }*/ -/* else if("BuildArtifactFilePrefix".equals(macroName)){ //$NON-NLS-1$ - ITool targetTool = cfg.calculateTargetTool(); - if(targetTool != null){ - IOutputType pot = targetTool.getPrimaryOutputType(); - String prefix = pot.getOutputPrefix(); - - // Resolve any macros in the outputPrefix - // Note that we cannot use file macros because if we do a clean - // we need to know the actual - // name of the file to clean, and cannot use any builder - // variables such as $@. Hence - // we use the next best thing, i.e. configuration context. - - // figure out the configuration we're using - IBuildObject toolParent = targetTool.getParent(); - IConfiguration config = null; - // if the parent is a config then we're done - if (toolParent instanceof IConfiguration) - config = (IConfiguration) toolParent; - else if (toolParent instanceof IToolChain) { - // must be a toolchain - config = (IConfiguration) ((IToolChain) toolParent) - .getParent(); - } + if (config != null) { - else if (toolParent instanceof IResourceConfiguration) { - config = (IConfiguration) ((IResourceConfiguration) toolParent) - .getParent(); - } + try { + prefix = ManagedBuildManager + .getBuildMacroProvider() + .resolveValueToMakefileFormat( + prefix, + "", //$NON-NLS-1$ + " ", //$NON-NLS-1$ + IBuildMacroProvider.CONTEXT_CONFIGURATION, + config); + } + + catch (BuildMacroException e) { + } + + } - else { - // bad - throw new AssertionError( - "tool parent must be one of configuration, toolchain, or resource configuration"); - } - if (config != null) { - - try { - prefix = ManagedBuildManager - .getBuildMacroProvider() - .resolveValueToMakefileFormat( - prefix, - "", //$NON-NLS-1$ - " ", //$NON-NLS-1$ - IBuildMacroProvider.CONTEXT_CONFIGURATION, - config); + if(prefix != null && !EMPTY_STRING.equals(prefix)) + name = prefix + name; } + macro = new BuildMacro(macroName,IBuildMacro.VALUE_TEXT,name); + }*/ + /* else if("BuildArtifactFilePrefix".equals(macroName)){ //$NON-NLS-1$ + ITool targetTool = cfg.calculateTargetTool(); + if(targetTool != null){ + IOutputType pot = targetTool.getPrimaryOutputType(); + String prefix = pot.getOutputPrefix(); - catch (BuildMacroException e) { + // Resolve any macros in the outputPrefix + // Note that we cannot use file macros because if we do a clean + // we need to know the actual + // name of the file to clean, and cannot use any builder + // variables such as $@. Hence + // we use the next best thing, i.e. configuration context. + + // figure out the configuration we're using + IBuildObject toolParent = targetTool.getParent(); + IConfiguration config = null; + // if the parent is a config then we're done + if (toolParent instanceof IConfiguration) + config = (IConfiguration) toolParent; + else if (toolParent instanceof IToolChain) { + // must be a toolchain + config = (IConfiguration) ((IToolChain) toolParent) + .getParent(); + } + + else if (toolParent instanceof IResourceConfiguration) { + config = (IConfiguration) ((IResourceConfiguration) toolParent) + .getParent(); + } + + else { + // bad + throw new AssertionError( + "tool parent must be one of configuration, toolchain, or resource configuration"); + } + + if (config != null) { + + try { + prefix = ManagedBuildManager + .getBuildMacroProvider() + .resolveValueToMakefileFormat( + prefix, + "", //$NON-NLS-1$ + " ", //$NON-NLS-1$ + IBuildMacroProvider.CONTEXT_CONFIGURATION, + config); + } + + catch (BuildMacroException e) { + } + + } + + if(prefix == null) + prefix = EMPTY_STRING; + macro = new BuildMacro(macroName,IBuildMacro.VALUE_TEXT,prefix); } + }*/ + /* else if("TargetOsList".equals(macroName)){ //$NON-NLS-1$ + IToolChain toolChain = cfg.getToolChain(); + String osList[] = toolChain.getOSList(); + if(osList == null) + osList = new String[0]; + macro = new BuildMacro(macroName,IBuildMacro.VALUE_TEXT_LIST,osList); + }*/ + /* else if("TargetArchList".equals(macroName)){ //$NON-NLS-1$ + IToolChain toolChain = cfg.getToolChain(); + String archList[] = toolChain.getArchList(); + if(archList == null) + archList = new String[0]; + macro = new BuildMacro(macroName,IBuildMacro.VALUE_TEXT_LIST,archList); - } - - if(prefix == null) - prefix = EMPTY_STRING; - macro = new BuildMacro(macroName,IBuildMacro.VALUE_TEXT,prefix); - } - }*/ -/* else if("TargetOsList".equals(macroName)){ //$NON-NLS-1$ - IToolChain toolChain = cfg.getToolChain(); - String osList[] = toolChain.getOSList(); - if(osList == null) - osList = new String[0]; - macro = new BuildMacro(macroName,IBuildMacro.VALUE_TEXT_LIST,osList); - }*/ -/* else if("TargetArchList".equals(macroName)){ //$NON-NLS-1$ - IToolChain toolChain = cfg.getToolChain(); - String archList[] = toolChain.getArchList(); - if(archList == null) - archList = new String[0]; - macro = new BuildMacro(macroName,IBuildMacro.VALUE_TEXT_LIST,archList); - - }*/ -/* else if("ToolChainVersion".equals(macroName)){ //$NON-NLS-1$ - if(cfg.getToolChain().getVersion() != null) - macro = new BuildMacro(macroName,IBuildMacro.VALUE_TEXT,cfg.getToolChain().getVersion().toString()); - }*/ -/* else if("BuilderVersion".equals(macroName)){ //$NON-NLS-1$ - PluginVersionIdentifier version = cfg.getToolChain().getBuilder().getVersion(); - if(version != null) - macro = new BuildMacro(macroName,IBuildMacro.VALUE_TEXT,version.toString()); - }*/ + }*/ + /* else if("ToolChainVersion".equals(macroName)){ //$NON-NLS-1$ + if(cfg.getToolChain().getVersion() != null) + macro = new BuildMacro(macroName,IBuildMacro.VALUE_TEXT,cfg.getToolChain().getVersion().toString()); + }*/ + /* else if("BuilderVersion".equals(macroName)){ //$NON-NLS-1$ + PluginVersionIdentifier version = cfg.getToolChain().getBuilder().getVersion(); + if(version != null) + macro = new BuildMacro(macroName,IBuildMacro.VALUE_TEXT,version.toString()); + }*/ return macro; } - -// private String getBaseName(String name){ -// String value = null; -// int index = name.lastIndexOf('.'); -// if(index == -1) -// value = name; -// else -// value = name.substring(0,index); -// return value; -// } -// -// private String getExtension(String name){ -// String value = null; -// int index = name.lastIndexOf('.'); -// if(index != -1) -// value = name.substring(index+1); -// return value; -// } - -/* public IBuildMacro getMacro(String macroName, IManagedProject mngProj){ - IBuildMacro macro = null; - if (VAR_PROJ_NAME.equals(macroName)) { - macro = new BuildMacro(macroName,IBuildMacro.VALUE_TEXT,mngProj.getOwner().getName()); - } - else if (VAR_PROJ_DIR_PATH.equals(macroName)) { - macro = new BuildMacro(macroName,IBuildMacro.VALUE_PATH_DIR,mngProj.getOwner().getLocation().toOSString()); + + // private String getBaseName(String name){ + // String value = null; + // int index = name.lastIndexOf('.'); + // if(index == -1) + // value = name; + // else + // value = name.substring(0,index); + // return value; + // } + // + // private String getExtension(String name){ + // String value = null; + // int index = name.lastIndexOf('.'); + // if(index != -1) + // value = name.substring(index+1); + // return value; + // } + + /* public IBuildMacro getMacro(String macroName, IManagedProject mngProj){ + IBuildMacro macro = null; + if (VAR_PROJ_NAME.equals(macroName)) { + macro = new BuildMacro(macroName,IBuildMacro.VALUE_TEXT,mngProj.getOwner().getName()); + } + else if (VAR_PROJ_DIR_PATH.equals(macroName)) { + macro = new BuildMacro(macroName,IBuildMacro.VALUE_PATH_DIR,mngProj.getOwner().getLocation().toOSString()); + } + return macro; } - return macro; - } -*/ - public ICdtVariable getMacro(String macroName, IWorkspace wsp){ - if(wsp == null) + */ + public ICdtVariable getMacro(String macroName, IWorkspace wsp) { + if (wsp == null) wsp = ResourcesPlugin.getWorkspace(); ICdtVariable macro = null; if (VAR_WORKSPACE_DIR_PATH.equals(macroName)) { - macro = new CdtVariable(macroName,ICdtVariable.VALUE_PATH_DIR,wsp.getRoot().getLocation().toOSString()); + macro = new CdtVariable(macroName, ICdtVariable.VALUE_PATH_DIR, wsp.getRoot().getLocation().toOSString()); } else if (VAR_DIRECTORY_DELIMITER.equals(macroName)) { - if(isWin32()){ - macro = new CdtVariable(macroName,ICdtVariable.VALUE_TEXT,"\\"); //$NON-NLS-1$ + if (isWin32()) { + macro = new CdtVariable(macroName, ICdtVariable.VALUE_TEXT, "\\"); //$NON-NLS-1$ } else { - macro = new CdtVariable(macroName,ICdtVariable.VALUE_TEXT,"/"); //$NON-NLS-1$ + macro = new CdtVariable(macroName, ICdtVariable.VALUE_TEXT, "/"); //$NON-NLS-1$ } } else if (VAR_PATH_DELIMITER.equals(macroName)) { - if(isWin32()){ - macro = new CdtVariable(macroName,ICdtVariable.VALUE_TEXT,";"); //$NON-NLS-1$ + if (isWin32()) { + macro = new CdtVariable(macroName, ICdtVariable.VALUE_TEXT, ";"); //$NON-NLS-1$ } else { - macro = new CdtVariable(macroName,ICdtVariable.VALUE_TEXT,":"); //$NON-NLS-1$ + macro = new CdtVariable(macroName, ICdtVariable.VALUE_TEXT, ":"); //$NON-NLS-1$ } } return macro; } - - private boolean isWin32(){ + + private boolean isWin32() { String os = System.getProperty("os.name").toLowerCase(); //$NON-NLS-1$ if (os.startsWith("windows ")) //$NON-NLS-1$ return true; return false; } - public ICdtVariable getMacro(String macroName){ + public ICdtVariable getMacro(String macroName) { ICdtVariable macro = null; if (VAR_ECLIPSE_VERSION.equals(macroName)) { - Bundle bundle = Platform.getBundle("org.eclipse.platform"); //$NON-NLS-1$ - String version = bundle != null ? - (String)bundle.getHeaders().get(org.osgi.framework.Constants.BUNDLE_VERSION) : - null; - macro = new CdtVariable(macroName,ICdtVariable.VALUE_TEXT,version); + Bundle bundle = Platform.getBundle("org.eclipse.platform"); //$NON-NLS-1$ + String version = bundle != null + ? (String) bundle.getHeaders().get(org.osgi.framework.Constants.BUNDLE_VERSION) + : null; + macro = new CdtVariable(macroName, ICdtVariable.VALUE_TEXT, version); + } else if (VAR_CDT_VERSION.equals(macroName)) { + String version = CCorePlugin.getDefault().getBundle().getHeaders() + .get(org.osgi.framework.Constants.BUNDLE_VERSION); + macro = new CdtVariable(macroName, ICdtVariable.VALUE_TEXT, version); } - else if (VAR_CDT_VERSION.equals(macroName)) { - String version = CCorePlugin.getDefault().getBundle().getHeaders().get(org.osgi.framework.Constants.BUNDLE_VERSION); - macro = new CdtVariable(macroName,ICdtVariable.VALUE_TEXT,version); - } -/* else if("MBSVersion".equals(macroName)){ //$NON-NLS-1$ - String version = ManagedBuildManager.getBuildInfoVersion().toString(); - macro = new BuildMacro(macroName,IBuildMacro.VALUE_TEXT,version); - }*/ + /* else if("MBSVersion".equals(macroName)){ //$NON-NLS-1$ + String version = ManagedBuildManager.getBuildInfoVersion().toString(); + macro = new BuildMacro(macroName,IBuildMacro.VALUE_TEXT,version); + }*/ else if (VAR_HOST_OS_NAME.equals(macroName)) { String os = System.getProperty("os.name"); //$NON-NLS-1$ - macro = new CdtVariable(macroName,ICdtVariable.VALUE_TEXT,os); - } - else if (VAR_HOST_ARCH_NAME.equals(macroName)) { + macro = new CdtVariable(macroName, ICdtVariable.VALUE_TEXT, os); + } else if (VAR_HOST_ARCH_NAME.equals(macroName)) { String arch = System.getProperty("os.arch"); //$NON-NLS-1$ - macro = new CdtVariable(macroName,ICdtVariable.VALUE_TEXT,arch); - } - else if (VAR_OS_TYPE.equals(macroName)) { + macro = new CdtVariable(macroName, ICdtVariable.VALUE_TEXT, arch); + } else if (VAR_OS_TYPE.equals(macroName)) { String os = Platform.getOS(); - macro = new CdtVariable(macroName,ICdtVariable.VALUE_TEXT,os); - } - else if (VAR_ARCH_TYPE.equals(macroName)) { + macro = new CdtVariable(macroName, ICdtVariable.VALUE_TEXT, os); + } else if (VAR_ARCH_TYPE.equals(macroName)) { String arch = Platform.getOSArch(); - macro = new CdtVariable(macroName,ICdtVariable.VALUE_TEXT,arch); + macro = new CdtVariable(macroName, ICdtVariable.VALUE_TEXT, arch); } return macro; } - /* (non-Javadoc) * @see org.eclipse.cdt.managedbuilder.macros.IBuildMacroSupplier#getMacros(int, java.lang.Object) */ @Override public ICdtVariable[] getMacros(int contextType, Object contextData) { - String names[] = getMacroNames(contextType,false); - - if(names != null){ + String names[] = getMacroNames(contextType, false); + + if (names != null) { ICdtVariable macros[] = new ICdtVariable[names.length]; int num = 0; for (String name : names) { - ICdtVariable macro = getMacro(name,contextType,contextData); - if(macro != null) + ICdtVariable macro = getMacro(name, contextType, contextData); + if (macro != null) macros[num++] = macro; } - if(macros.length != num){ + if (macros.length != num) { ICdtVariable tmp[] = new ICdtVariable[num]; - if(num > 0) - System.arraycopy(macros,0,tmp,0,num); + if (num > 0) + System.arraycopy(macros, 0, tmp, 0, num); macros = tmp; } return macros; } return null; } - -/* private IPath getBuilderCWD(IConfiguration cfg){ - IPath workingDirectory = null; - IResource owner = cfg.getOwner(); - IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(owner); - - if(info != null){ - if(info.getDefaultConfiguration().equals(cfg)){ - IManagedBuilderMakefileGenerator generator = ManagedBuildManager.getBuildfileGenerator(info.getDefaultConfiguration()); - generator.initialize((IProject)owner,info,null); - - IPath topBuildDir = generator.getBuildWorkingDir(); - if(topBuildDir == null) - topBuildDir = new Path(info.getConfigurationName()); - - IPath projectLocation = owner.getLocation(); - workingDirectory = projectLocation.append(topBuildDir); + + /* private IPath getBuilderCWD(IConfiguration cfg){ + IPath workingDirectory = null; + IResource owner = cfg.getOwner(); + IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(owner); + + if(info != null){ + if(info.getDefaultConfiguration().equals(cfg)){ + IManagedBuilderMakefileGenerator generator = ManagedBuildManager.getBuildfileGenerator(info.getDefaultConfiguration()); + generator.initialize((IProject)owner,info,null); + + IPath topBuildDir = generator.getBuildWorkingDir(); + if(topBuildDir == null) + topBuildDir = new Path(info.getConfigurationName()); + + IPath projectLocation = owner.getLocation(); + workingDirectory = projectLocation.append(topBuildDir); + } } + return workingDirectory; } - return workingDirectory; - } -*/ + */ } diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/CdtVariableManager.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/CdtVariableManager.java index c5418bbc722..3a0cd2e61e2 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/CdtVariableManager.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/CdtVariableManager.java @@ -36,39 +36,43 @@ import org.eclipse.core.variables.IStringVariable; public class CdtVariableManager implements ICdtVariableManager { static private CdtVariableManager fDefault; - public static final UserDefinedVariableSupplier fUserDefinedMacroSupplier = UserDefinedVariableSupplier.getInstance(); - public static final BuildSystemVariableSupplier fBuildSystemVariableSupplier = BuildSystemVariableSupplier.getInstance(); - public static final EnvironmentVariableSupplier fEnvironmentMacroSupplier = EnvironmentVariableSupplier.getInstance(); + public static final UserDefinedVariableSupplier fUserDefinedMacroSupplier = UserDefinedVariableSupplier + .getInstance(); + public static final BuildSystemVariableSupplier fBuildSystemVariableSupplier = BuildSystemVariableSupplier + .getInstance(); + public static final EnvironmentVariableSupplier fEnvironmentMacroSupplier = EnvironmentVariableSupplier + .getInstance(); public static final CdtMacroSupplier fCdtMacroSupplier = CdtMacroSupplier.getInstance(); - public static final EclipseVariablesVariableSupplier fEclipseVariablesMacroSupplier = EclipseVariablesVariableSupplier.getInstance(); + public static final EclipseVariablesVariableSupplier fEclipseVariablesMacroSupplier = EclipseVariablesVariableSupplier + .getInstance(); - protected CdtVariableManager(){ + protected CdtVariableManager() { } - public static CdtVariableManager getDefault(){ - if(fDefault == null) + public static CdtVariableManager getDefault() { + if (fDefault == null) fDefault = new CdtVariableManager(); return fDefault; } + /* (non-Javadoc) * @see org.eclipse.cdt.managedbuilder.macros.IBuildMacroProvider#getMacro(java.lang.String, int, java.lang.Object, boolean) */ @Override public ICdtVariable getVariable(String macroName, ICConfigurationDescription cfg) { - if(cfg instanceof CConfigurationDescriptionCache){ - StorableCdtVariables macros = ((CConfigurationDescriptionCache)cfg).getCachedVariables(); - if(macros != null) + if (cfg instanceof CConfigurationDescriptionCache) { + StorableCdtVariables macros = ((CConfigurationDescriptionCache) cfg).getCachedVariables(); + if (macros != null) return macros.getMacro(macroName); } int type = getContextType(cfg); - return SupplierBasedCdtVariableManager.getVariable(macroName, - getMacroContextInfo(type,cfg),true); + return SupplierBasedCdtVariableManager.getVariable(macroName, getMacroContextInfo(type, cfg), true); } - private IVariableContextInfo getVariableContextInfo(ICConfigurationDescription cfg){ + private IVariableContextInfo getVariableContextInfo(ICConfigurationDescription cfg) { int type = getContextType(cfg); - return getMacroContextInfo(type,cfg); + return getMacroContextInfo(type, cfg); } /* (non-Javadoc) @@ -76,32 +80,28 @@ public class CdtVariableManager implements ICdtVariableManager { */ @Override public ICdtVariable[] getVariables(ICConfigurationDescription cfg) { - if(cfg instanceof CConfigurationDescriptionCache){ - StorableCdtVariables macros = ((CConfigurationDescriptionCache)cfg).getCachedVariables(); - if(macros != null) + if (cfg instanceof CConfigurationDescriptionCache) { + StorableCdtVariables macros = ((CConfigurationDescriptionCache) cfg).getCachedVariables(); + if (macros != null) return macros.getMacros(); } int type = getContextType(cfg); - return SupplierBasedCdtVariableManager.getVariables(getMacroContextInfo(type,cfg), - true); + return SupplierBasedCdtVariableManager.getVariables(getMacroContextInfo(type, cfg), true); } /* (non-Javadoc) * @see org.eclipse.cdt.managedbuilder.macros.IBuildMacroProvider#getSuppliers(int, java.lang.Object) */ - public ICdtVariableSupplier[] getSuppliers(int contextType, - Object contextData) { - IVariableContextInfo info = getMacroContextInfo(contextType,contextData); - if(info != null) + public ICdtVariableSupplier[] getSuppliers(int contextType, Object contextData) { + IVariableContextInfo info = getMacroContextInfo(contextType, contextData); + if (info != null) return info.getSuppliers(); return null; } - public IVariableContextInfo getMacroContextInfo( - int contextType, - Object contextData){ - DefaultVariableContextInfo info = new DefaultVariableContextInfo(contextType,contextData); - if(info.getSuppliers() != null) + public IVariableContextInfo getMacroContextInfo(int contextType, Object contextData) { + DefaultVariableContextInfo info = new DefaultVariableContextInfo(contextType, contextData); + if (info.getSuppliers() != null) return info; return null; } @@ -111,21 +111,20 @@ public class CdtVariableManager implements ICdtVariableManager { */ @Override public String convertStringListToString(String[] value, String listDelimiter) { - return CdtVariableResolver.convertStringListToString(value,listDelimiter); + return CdtVariableResolver.convertStringListToString(value, listDelimiter); } /* (non-Javadoc) * @see org.eclipse.cdt.managedbuilder.macros.IBuildMacroProvider#resolveValue(java.lang.String, java.lang.String, java.lang.String, int, java.lang.Object) */ @Override - public String resolveValue(String value, String nonexistentMacrosValue, - String listDelimiter, ICConfigurationDescription cfg) - throws CdtVariableException { + public String resolveValue(String value, String nonexistentMacrosValue, String listDelimiter, + ICConfigurationDescription cfg) throws CdtVariableException { - IVariableContextInfo info = getMacroContextInfo(getContextType(cfg),cfg); - if(info != null) + IVariableContextInfo info = getMacroContextInfo(getContextType(cfg), cfg); + if (info != null) return CdtVariableResolver.resolveToString(value, - getMacroSubstitutor(info,nonexistentMacrosValue, listDelimiter)); + getMacroSubstitutor(info, nonexistentMacrosValue, listDelimiter)); return null; } @@ -133,13 +132,13 @@ public class CdtVariableManager implements ICdtVariableManager { * @see org.eclipse.cdt.managedbuilder.macros.IBuildMacroProvider#resolveStringListValue(java.lang.String, java.lang.String, int, java.lang.Object) */ @Override - public String[] resolveStringListValue(String value, - String nonexistentMacrosValue, String listDelimiter, + public String[] resolveStringListValue(String value, String nonexistentMacrosValue, String listDelimiter, ICConfigurationDescription cfg) throws CdtVariableException { - IVariableContextInfo info = getMacroContextInfo(getContextType(cfg),cfg); - if(info != null) - return CdtVariableResolver.resolveToStringList(value,getMacroSubstitutor(info,nonexistentMacrosValue, listDelimiter)); + IVariableContextInfo info = getMacroContextInfo(getContextType(cfg), cfg); + if (info != null) + return CdtVariableResolver.resolveToStringList(value, + getMacroSubstitutor(info, nonexistentMacrosValue, listDelimiter)); return null; } @@ -149,8 +148,9 @@ public class CdtVariableManager implements ICdtVariableManager { @Override public boolean isStringListValue(String value, ICConfigurationDescription cfg) throws CdtVariableException { try { - CdtVariableResolver.resolveToStringList(value,getMacroSubstitutor(getMacroContextInfo(getContextType(cfg), cfg)," ",null)); //$NON-NLS-1$ - }catch(CdtVariableException e){ + CdtVariableResolver.resolveToStringList(value, + getMacroSubstitutor(getMacroContextInfo(getContextType(cfg), cfg), " ", null)); //$NON-NLS-1$ + } catch (CdtVariableException e) { return false; } return true; @@ -161,30 +161,30 @@ public class CdtVariableManager implements ICdtVariableManager { * @see org.eclipse.cdt.managedbuilder.macros.IBuildMacroProvider#checkIntegrity(int, java.lang.Object) */ @Override - public void checkVariableIntegrity(ICConfigurationDescription cfg) - throws CdtVariableException { + public void checkVariableIntegrity(ICConfigurationDescription cfg) throws CdtVariableException { int type = getContextType(cfg); - IVariableContextInfo info = getMacroContextInfo(type,cfg); - IVariableSubstitutor subst = new CoreVariableSubstitutor(info,null,""){ //$NON-NLS-1$ + IVariableContextInfo info = getMacroContextInfo(type, cfg); + IVariableSubstitutor subst = new CoreVariableSubstitutor(info, null, "") { //$NON-NLS-1$ @Override protected ResolvedMacro resolveMacro(ICdtVariable macro) throws CdtVariableException { - if(macro instanceof EclipseVariablesVariableSupplier.EclipseVarMacro) - return new ResolvedMacro(macro.getName(),""); //$NON-NLS-1$ + if (macro instanceof EclipseVariablesVariableSupplier.EclipseVarMacro) + return new ResolvedMacro(macro.getName(), ""); //$NON-NLS-1$ return super.resolveMacro(macro); } }; - if(info != null) - CdtVariableResolver.checkIntegrity(info,subst); + if (info != null) + CdtVariableResolver.checkIntegrity(info, subst); } - private int getContextType(ICConfigurationDescription des){ - if(des != null) + private int getContextType(ICConfigurationDescription des) { + if (des != null) return ICoreVariableContextInfo.CONTEXT_CONFIGURATION; return ICoreVariableContextInfo.CONTEXT_WORKSPACE; } - public IVariableSubstitutor getMacroSubstitutor(IVariableContextInfo info, String inexistentMacroValue, String listDelimiter){ + public IVariableSubstitutor getMacroSubstitutor(IVariableContextInfo info, String inexistentMacroValue, + String listDelimiter) { return new CoreVariableSubstitutor(info, inexistentMacroValue, listDelimiter); } @@ -192,52 +192,52 @@ public class CdtVariableManager implements ICdtVariableManager { * @see org.eclipse.cdt.managedbuilder.macros.IBuildMacroProvider#resolveStringListValues(java.lang.String[], java.lang.String, java.lang.String, int, java.lang.Object) */ @Override - public String[] resolveStringListValues(String[] value, String nonexistentMacrosValue, String listDelimiter, ICConfigurationDescription cfg) throws CdtVariableException { - IVariableContextInfo info = getMacroContextInfo(getContextType(cfg),cfg); - if(info != null) + public String[] resolveStringListValues(String[] value, String nonexistentMacrosValue, String listDelimiter, + ICConfigurationDescription cfg) throws CdtVariableException { + IVariableContextInfo info = getMacroContextInfo(getContextType(cfg), cfg); + if (info != null) return CdtVariableResolver.resolveStringListValues(value, - getMacroSubstitutor(info,nonexistentMacrosValue, listDelimiter), true); + getMacroSubstitutor(info, nonexistentMacrosValue, listDelimiter), true); return null; } @Override - public boolean isEnvironmentVariable(ICdtVariable variable, - ICConfigurationDescription cfg) { - if(variable instanceof EnvironmentVariableSupplier.EnvVarMacro) + public boolean isEnvironmentVariable(ICdtVariable variable, ICConfigurationDescription cfg) { + if (variable instanceof EnvironmentVariableSupplier.EnvVarMacro) return true; IVariableContextInfo info = getVariableContextInfo(cfg); ICdtVariable var = fEnvironmentMacroSupplier.getVariable(variable.getName(), info); - if(var != null && variablesEqual(var, variable)) + if (var != null && variablesEqual(var, variable)) return true; return false; } - private static boolean variablesEqual(ICdtVariable var1, ICdtVariable var2){ - if(CDataUtil.objectsEqual(var1, var2)) + private static boolean variablesEqual(ICdtVariable var1, ICdtVariable var2) { + if (CDataUtil.objectsEqual(var1, var2)) return true; - if(var1 == null || var2 == null) + if (var1 == null || var2 == null) return false; - if(var1.getValueType() != var2.getValueType()) + if (var1.getValueType() != var2.getValueType()) return false; - if(!var1.getName().equals(var2.getName())) + if (!var1.getName().equals(var2.getName())) return false; try { - if(CdtVariableResolver.isStringListVariable(var1.getValueType())){ + if (CdtVariableResolver.isStringListVariable(var1.getValueType())) { String[] v1 = var1.getStringListValue(); String[] v2 = var2.getStringListValue(); - if(!Arrays.equals(v1, v2)) + if (!Arrays.equals(v1, v2)) return false; } else { - if(!CDataUtil.objectsEqual(var1.getStringValue(), var2.getStringValue())) + if (!CDataUtil.objectsEqual(var1.getStringValue(), var2.getStringValue())) return false; } - } catch (CdtVariableException e){ + } catch (CdtVariableException e) { return false; } @@ -245,23 +245,23 @@ public class CdtVariableManager implements ICdtVariableManager { } @Override - public IStringVariable toEclipseVariable(ICdtVariable variable, - ICConfigurationDescription cfg) { - if(variable instanceof EclipseVariablesVariableSupplier.EclipseVarMacro){ - return ((EclipseVarMacro)variable).getVariable(); + public IStringVariable toEclipseVariable(ICdtVariable variable, ICConfigurationDescription cfg) { + if (variable instanceof EclipseVariablesVariableSupplier.EclipseVarMacro) { + return ((EclipseVarMacro) variable).getVariable(); } return null; } @Override - public boolean isUserVariable(ICdtVariable variable, - ICConfigurationDescription cfg) { - if(!(variable instanceof StorableCdtVariable)) + public boolean isUserVariable(ICdtVariable variable, ICConfigurationDescription cfg) { + if (!(variable instanceof StorableCdtVariable)) return false; - if(cfg != null) - return UserDefinedVariableSupplier.getInstance().containsVariable(ICoreVariableContextInfo.CONTEXT_CONFIGURATION, cfg, variable); + if (cfg != null) + return UserDefinedVariableSupplier.getInstance() + .containsVariable(ICoreVariableContextInfo.CONTEXT_CONFIGURATION, cfg, variable); - return UserDefinedVariableSupplier.getInstance().containsVariable(ICoreVariableContextInfo.CONTEXT_WORKSPACE, null, variable); + return UserDefinedVariableSupplier.getInstance().containsVariable(ICoreVariableContextInfo.CONTEXT_WORKSPACE, + null, variable); } } diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/CoreMacroSupplierBase.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/CoreMacroSupplierBase.java index 28000ed8b0c..754a7202ce3 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/CoreMacroSupplierBase.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/CoreMacroSupplierBase.java @@ -21,8 +21,8 @@ public abstract class CoreMacroSupplierBase implements ICdtVariableSupplier { @Override public ICdtVariable getVariable(String macroName, IVariableContextInfo context) { - if(context instanceof ICoreVariableContextInfo){ - ICoreVariableContextInfo info = (ICoreVariableContextInfo)context; + if (context instanceof ICoreVariableContextInfo) { + ICoreVariableContextInfo info = (ICoreVariableContextInfo) context; return getMacro(macroName, info.getContextType(), info.getContextData()); } return null; @@ -32,8 +32,8 @@ public abstract class CoreMacroSupplierBase implements ICdtVariableSupplier { @Override public ICdtVariable[] getVariables(IVariableContextInfo context) { - if(context instanceof ICoreVariableContextInfo){ - ICoreVariableContextInfo info = (ICoreVariableContextInfo)context; + if (context instanceof ICoreVariableContextInfo) { + ICoreVariableContextInfo info = (ICoreVariableContextInfo) context; return getMacros(info.getContextType(), info.getContextData()); } return null; diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/CoreVariableSubstitutor.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/CoreVariableSubstitutor.java index 7a2b1d2312d..a7a37426c6c 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/CoreVariableSubstitutor.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/CoreVariableSubstitutor.java @@ -20,24 +20,21 @@ import org.eclipse.cdt.utils.cdtvariables.IVariableContextInfo; import org.eclipse.cdt.utils.cdtvariables.SupplierBasedCdtVariableSubstitutor; /** - * This substituter resolves all macro references - * + * This substituter resolves all macro references + * * @see org.eclipse.cdt.utils.cdtvariables.IVariableSubstitutor * @since 3.0 */ public class CoreVariableSubstitutor extends SupplierBasedCdtVariableSubstitutor { - - public CoreVariableSubstitutor(IVariableContextInfo contextInfo, - String inexistentMacroValue, String listDelimiter, + public CoreVariableSubstitutor(IVariableContextInfo contextInfo, String inexistentMacroValue, String listDelimiter, Map<?, ?> delimiterMap, String incorrectlyReferencedMacroValue) { - super(contextInfo, inexistentMacroValue, listDelimiter, delimiterMap, - incorrectlyReferencedMacroValue); + super(contextInfo, inexistentMacroValue, listDelimiter, delimiterMap, incorrectlyReferencedMacroValue); // TODO Auto-generated constructor stub } - public CoreVariableSubstitutor(IVariableContextInfo contextInfo, - String inexistentMacroValue, String listDelimiter) { + public CoreVariableSubstitutor(IVariableContextInfo contextInfo, String inexistentMacroValue, + String listDelimiter) { super(contextInfo, inexistentMacroValue, listDelimiter); // TODO Auto-generated constructor stub } @@ -45,11 +42,11 @@ public class CoreVariableSubstitutor extends SupplierBasedCdtVariableSubstitutor /* (non-Javadoc) * @see org.eclipse.cdt.managedbuilder.internal.macros.IMacroSubstitutor#setMacroContextInfo(int, java.lang.Object) */ - public void setMacroContextInfo(int contextType, Object contextData) throws CdtVariableException{ - setMacroContextInfo(getMacroContextInfo(contextType,contextData)); + public void setMacroContextInfo(int contextType, Object contextData) throws CdtVariableException { + setMacroContextInfo(getMacroContextInfo(contextType, contextData)); } - - protected IVariableContextInfo getMacroContextInfo(int contextType, Object contextData){ + + protected IVariableContextInfo getMacroContextInfo(int contextType, Object contextData) { return new DefaultVariableContextInfo(contextType, contextData); } diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/DefaultVariableContextInfo.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/DefaultVariableContextInfo.java index 8ec7ba13603..1bdd8273ee0 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/DefaultVariableContextInfo.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/DefaultVariableContextInfo.java @@ -30,51 +30,41 @@ public class DefaultVariableContextInfo implements ICoreVariableContextInfo { private int fType; private Object fData; - public DefaultVariableContextInfo(int type, Object data){ + public DefaultVariableContextInfo(int type, Object data) { fType = type; fData = data; } - protected DefaultVariableContextInfo(int type, Object data, ICdtVariableSupplier suppliers[]){ + protected DefaultVariableContextInfo(int type, Object data, ICdtVariableSupplier suppliers[]) { fType = type; fData = data; fSuppliers = suppliers; } - protected ICdtVariableSupplier[] getSuppliers(int type, Object data){ - switch(type){ + protected ICdtVariableSupplier[] getSuppliers(int type, Object data) { + switch (type) { case CONTEXT_CONFIGURATION: - if(data instanceof ICConfigurationDescription){ - return new ICdtVariableSupplier[]{ - CdtVariableManager.fUserDefinedMacroSupplier, - CdtVariableManager.fBuildSystemVariableSupplier, - CdtVariableManager.fEnvironmentMacroSupplier, - CdtVariableManager.fCdtMacroSupplier - }; + if (data instanceof ICConfigurationDescription) { + return new ICdtVariableSupplier[] { CdtVariableManager.fUserDefinedMacroSupplier, + CdtVariableManager.fBuildSystemVariableSupplier, CdtVariableManager.fEnvironmentMacroSupplier, + CdtVariableManager.fCdtMacroSupplier }; } break; case CONTEXT_WORKSPACE: - if(data == null || data instanceof IWorkspace){ - return new ICdtVariableSupplier[]{ - CdtVariableManager.fUserDefinedMacroSupplier, - CdtVariableManager.fEnvironmentMacroSupplier, - CdtVariableManager.fCdtMacroSupplier, - CdtVariableManager.fEclipseVariablesMacroSupplier - }; + if (data == null || data instanceof IWorkspace) { + return new ICdtVariableSupplier[] { CdtVariableManager.fUserDefinedMacroSupplier, + CdtVariableManager.fEnvironmentMacroSupplier, CdtVariableManager.fCdtMacroSupplier, + CdtVariableManager.fEclipseVariablesMacroSupplier }; } break; case CONTEXT_INSTALLATIONS: - if(data == null){ - return new ICdtVariableSupplier[]{ - CdtVariableManager.fCdtMacroSupplier - }; + if (data == null) { + return new ICdtVariableSupplier[] { CdtVariableManager.fCdtMacroSupplier }; } break; case CONTEXT_ECLIPSEENV: - if(data == null){ - return new ICdtVariableSupplier[]{ - CdtVariableManager.fEnvironmentMacroSupplier - }; + if (data == null) { + return new ICdtVariableSupplier[] { CdtVariableManager.fEnvironmentMacroSupplier }; } break; } @@ -102,7 +92,7 @@ public class DefaultVariableContextInfo implements ICoreVariableContextInfo { */ @Override public ICdtVariableSupplier[] getSuppliers() { - if(fSuppliers == null) + if (fSuppliers == null) fSuppliers = getSuppliers(fType, fData); return fSuppliers; } @@ -112,32 +102,26 @@ public class DefaultVariableContextInfo implements ICoreVariableContextInfo { */ @Override public IVariableContextInfo getNext() { - switch(fType){ + switch (fType) { case CONTEXT_CONFIGURATION: - if(fData instanceof ICConfigurationDescription){ + if (fData instanceof ICConfigurationDescription) { IWorkspace wsp = ResourcesPlugin.getWorkspace(); - if(wsp != null) - return new DefaultVariableContextInfo( - CONTEXT_WORKSPACE, - wsp); + if (wsp != null) + return new DefaultVariableContextInfo(CONTEXT_WORKSPACE, wsp); } break; case CONTEXT_WORKSPACE: - if(fData instanceof IWorkspace){ - return new DefaultVariableContextInfo( - CONTEXT_INSTALLATIONS, - null); + if (fData instanceof IWorkspace) { + return new DefaultVariableContextInfo(CONTEXT_INSTALLATIONS, null); } break; case CONTEXT_INSTALLATIONS: - if(fData == null){ - return new DefaultVariableContextInfo( - CONTEXT_ECLIPSEENV, - null); + if (fData == null) { + return new DefaultVariableContextInfo(CONTEXT_ECLIPSEENV, null); } break; case CONTEXT_ECLIPSEENV: - if(fData == null){ + if (fData == null) { return null; } break; diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/EclipseVariablesVariableSupplier.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/EclipseVariablesVariableSupplier.java index e4c1407b52e..326f4e4e7f7 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/EclipseVariablesVariableSupplier.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/EclipseVariablesVariableSupplier.java @@ -40,20 +40,21 @@ import org.eclipse.osgi.util.NLS; */ public class EclipseVariablesVariableSupplier implements ICdtVariableSupplier { - private static final Pattern RESOURCE_VARIABLE_PATTERN= Pattern.compile("(project|resource|container)_(loc|path|name)"); //$NON-NLS-1$ + private static final Pattern RESOURCE_VARIABLE_PATTERN = Pattern + .compile("(project|resource|container)_(loc|path|name)"); //$NON-NLS-1$ // private static final String VAR_PREFIX = "${"; //$NON-NLS-1$ -// private static final char VAR_SUFFIX = '}'; + // private static final char VAR_SUFFIX = '}'; private static final char COLON = ':'; private static EclipseVariablesVariableSupplier fInstance; - private EclipseVariablesVariableSupplier(){ + private EclipseVariablesVariableSupplier() { } - public static EclipseVariablesVariableSupplier getInstance(){ - if(fInstance == null) + public static EclipseVariablesVariableSupplier getInstance() { + if (fInstance == null) fInstance = new EclipseVariablesVariableSupplier(); return fInstance; } @@ -63,15 +64,15 @@ public class EclipseVariablesVariableSupplier implements ICdtVariableSupplier { private String fArgument; private boolean fInitialized; - private EclipseVarMacro(IStringVariable var){ - this(var,null); + private EclipseVarMacro(IStringVariable var) { + this(var, null); } - private EclipseVarMacro(IStringVariable var, String argument){ + private EclipseVarMacro(IStringVariable var, String argument) { fVariable = var; fType = VALUE_TEXT; fName = var.getName(); - if(argument != null) + if (argument != null) fName += COLON + argument; fArgument = argument; } @@ -81,13 +82,12 @@ public class EclipseVariablesVariableSupplier implements ICdtVariableSupplier { */ @Override public String getStringValue() throws CdtVariableException { - if(!fInitialized){ + if (!fInitialized) { try { if (!canExpandVariable(fVariable.getName(), fArgument)) { - final String expression= "${"+fName+"}"; //$NON-NLS-1$//$NON-NLS-2$ + final String expression = "${" + fName + "}"; //$NON-NLS-1$//$NON-NLS-2$ throw new CdtVariableException(ICdtVariableStatus.TYPE_MACRO_REFERENCE_INCORRECT, - NLS.bind(Messages.EclipseVariablesVariableSupplier_illegal_variable, expression), - null, + NLS.bind(Messages.EclipseVariablesVariableSupplier_illegal_variable, expression), null, fVariable.getName(), expression, null); } loadValue(fVariable); @@ -99,27 +99,27 @@ public class EclipseVariablesVariableSupplier implements ICdtVariableSupplier { } private void loadValue(IStringVariable var) throws CdtVariableException { - if(var instanceof IDynamicVariable){ - IDynamicVariable dynamicVar = (IDynamicVariable)var; - if(fArgument == null || dynamicVar.supportsArgument()){ - try{ + if (var instanceof IDynamicVariable) { + IDynamicVariable dynamicVar = (IDynamicVariable) var; + if (fArgument == null || dynamicVar.supportsArgument()) { + try { fStringValue = dynamicVar.getValue(fArgument); - }catch(CoreException e){ + } catch (CoreException e) { fStringValue = null; } - }else + } else fStringValue = null; - }else if(var instanceof IValueVariable){ - if(fArgument == null) - fStringValue = ((IValueVariable)var).getValue(); + } else if (var instanceof IValueVariable) { + if (fArgument == null) + fStringValue = ((IValueVariable) var).getValue(); else fStringValue = null; } } - public IStringVariable getVariable(){ + public IStringVariable getVariable() { return fVariable; } } @@ -134,31 +134,31 @@ public class EclipseVariablesVariableSupplier implements ICdtVariableSupplier { public ICdtVariable getVariable(String macroName) { -// if(contextType != DefaultMacroContextInfo.CONTEXT_WORKSPACE) -// return null; - if(macroName == null || macroName.isEmpty()) + // if(contextType != DefaultMacroContextInfo.CONTEXT_WORKSPACE) + // return null; + if (macroName == null || macroName.isEmpty()) return null; String varName = null; String param = null; IStringVariable var = null; int index = macroName.indexOf(COLON); - if(index == -1) + if (index == -1) varName = macroName; - else if(index > 0){ - varName = macroName.substring(0,index); - param = macroName.substring(index+1); + else if (index > 0) { + varName = macroName.substring(0, index); + param = macroName.substring(index + 1); } - if(varName != null){ + if (varName != null) { IStringVariableManager mngr = VariablesPlugin.getDefault().getStringVariableManager(); var = mngr.getValueVariable(varName); - if(var == null) + if (var == null) var = mngr.getDynamicVariable(varName); } - if(var != null) - return new EclipseVarMacro(var,param); + if (var != null) + return new EclipseVarMacro(var, param); return null; } @@ -171,27 +171,27 @@ public class EclipseVariablesVariableSupplier implements ICdtVariableSupplier { } public ICdtVariable[] getVariables() { -// if(contextType != DefaultMacroContextInfo.CONTEXT_WORKSPACE) -// return null; + // if(contextType != DefaultMacroContextInfo.CONTEXT_WORKSPACE) + // return null; IStringVariableManager mngr = VariablesPlugin.getDefault().getStringVariableManager(); IDynamicVariable vars[] = mngr.getDynamicVariables(); Map<String, IStringVariable> map = new HashMap<String, IStringVariable>(); for (IDynamicVariable var : vars) { - final String name= var.getName(); + final String name = var.getName(); if (!isDeadlockProneVariable(name)) { - map.put(name,var); + map.put(name, var); } } IValueVariable valVars[] = mngr.getValueVariables(); for (IValueVariable valVar : valVars) - map.put(valVar.getName(),valVar); + map.put(valVar.getName(), valVar); Collection<IStringVariable> collection = map.values(); EclipseVarMacro macros[] = new EclipseVarMacro[collection.size()]; Iterator<IStringVariable> iter = collection.iterator(); - for(int i = 0; i < macros.length ; i++) + for (int i = 0; i < macros.length; i++) macros[i] = new EclipseVarMacro(iter.next()); return macros; @@ -203,27 +203,26 @@ public class EclipseVariablesVariableSupplier implements ICdtVariableSupplier { * @return whether the variable is prone to deadlocks */ private static boolean isDeadlockProneVariable(String name) { - return RESOURCE_VARIABLE_PATTERN.matcher(name).matches() - || name.endsWith("_prompt") //$NON-NLS-1$ - || name.equals("selected_text"); //$NON-NLS-1$ + return RESOURCE_VARIABLE_PATTERN.matcher(name).matches() || name.endsWith("_prompt") //$NON-NLS-1$ + || name.equals("selected_text"); //$NON-NLS-1$ } private static boolean canExpandVariable(String name, String argument) { if (argument == null && RESOURCE_VARIABLE_PATTERN.matcher(name).matches()) { return false; } - if (name.endsWith("_prompt") || name.equals("selected_text")) { //$NON-NLS-1$//$NON-NLS-2$ + if (name.endsWith("_prompt") || name.equals("selected_text")) { //$NON-NLS-1$//$NON-NLS-2$ return false; } return true; } -// private String getMacroValue(String name){ -// IStringVariableManager mngr = VariablesPlugin.getDefault().getStringVariableManager(); -// try{ -// return mngr.performStringSubstitution(VAR_PREFIX + name + VAR_SUFFIX); -// }catch (CoreException e){ -// } -// -// return null; -// } + // private String getMacroValue(String name){ + // IStringVariableManager mngr = VariablesPlugin.getDefault().getStringVariableManager(); + // try{ + // return mngr.performStringSubstitution(VAR_PREFIX + name + VAR_SUFFIX); + // }catch (CoreException e){ + // } + // + // return null; + // } } diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/EnvironmentVariableSupplier.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/EnvironmentVariableSupplier.java index d89853a86d9..fd97b1cef7b 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/EnvironmentVariableSupplier.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/EnvironmentVariableSupplier.java @@ -27,29 +27,29 @@ import org.eclipse.core.resources.IWorkspace; /** * This supplier suplies the macros that represent the Managed Build environment variables - * + * * @since 3.0 */ public class EnvironmentVariableSupplier extends CoreMacroSupplierBase { private static EnvironmentVariableSupplier fInstance; private EnvironmentVariableManager fEnvironmentProvider; - - public class EnvVarMacro extends CdtVariable{ + + public class EnvVarMacro extends CdtVariable { private IEnvironmentVariable fVariable; - private EnvVarMacro(IEnvironmentVariable var){ + + private EnvVarMacro(IEnvironmentVariable var) { fName = var.getName(); fVariable = var; } - - private void loadValue(IEnvironmentVariable var){ + + private void loadValue(IEnvironmentVariable var) { String delimiter = var.getDelimiter(); - String value = var.getOperation() != IEnvironmentVariable.ENVVAR_REMOVE ? - var.getValue() : null; - - if(isTextList(value,delimiter)){ + String value = var.getOperation() != IEnvironmentVariable.ENVVAR_REMOVE ? var.getValue() : null; + + if (isTextList(value, delimiter)) { fType = VALUE_TEXT_LIST; - if(value != null){ - List<String> list = EnvVarOperationProcessor.convertToList(value,delimiter); + if (value != null) { + List<String> list = EnvVarOperationProcessor.convertToList(value, delimiter); fStringListValue = list.toArray(new String[list.size()]); } else { fStringListValue = null; @@ -59,11 +59,10 @@ public class EnvironmentVariableSupplier extends CoreMacroSupplierBase { fStringValue = value; } } - - + @Override public int getValueType() { - if(fVariable != null){ + if (fVariable != null) { loadValue(fVariable); //we do not need it any more, release clean the reference @@ -74,7 +73,7 @@ public class EnvironmentVariableSupplier extends CoreMacroSupplierBase { @Override public String getStringValue() throws CdtVariableException { - if(fVariable != null){ + if (fVariable != null) { loadValue(fVariable); //we do not need it any more, release clean the reference @@ -85,7 +84,7 @@ public class EnvironmentVariableSupplier extends CoreMacroSupplierBase { @Override public String[] getStringListValue() throws CdtVariableException { - if(fVariable != null){ + if (fVariable != null) { loadValue(fVariable); //we do not need it any more, release clean the reference @@ -95,31 +94,31 @@ public class EnvironmentVariableSupplier extends CoreMacroSupplierBase { } } - protected EnvironmentVariableSupplier(){ + protected EnvironmentVariableSupplier() { this(EnvironmentVariableManager.getDefault()); } - - public EnvironmentVariableSupplier(EnvironmentVariableManager varProvider){ + + public EnvironmentVariableSupplier(EnvironmentVariableManager varProvider) { fEnvironmentProvider = varProvider; } - + private static boolean isTextList(String str, String delimiter) { if (str == null || delimiter == null || delimiter.isEmpty()) return false; - + // Regex: ([^:]+:)+[^:]* String patternStr = "([^" + delimiter + "]+" + delimiter + ")+[^" + delimiter + "]*"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$//$NON-NLS-4$ return Pattern.matches(patternStr, str); } - - public ICdtVariable createBuildMacro(IEnvironmentVariable var){ - if(var != null) + + public ICdtVariable createBuildMacro(IEnvironmentVariable var) { + if (var != null) return new EnvVarMacro(var); - return null; + return null; } - public static EnvironmentVariableSupplier getInstance(){ - if(fInstance == null) + public static EnvironmentVariableSupplier getInstance() { + if (fInstance == null) fInstance = new EnvironmentVariableSupplier(); return fInstance; } @@ -128,30 +127,29 @@ public class EnvironmentVariableSupplier extends CoreMacroSupplierBase { * @see org.eclipse.cdt.managedbuilder.macros.IBuildMacroSupplier#getMacro(java.lang.String, int, java.lang.Object) */ @Override - public ICdtVariable getMacro(String macroName, int contextType, - Object contextData) { - if(macroName == null || macroName.isEmpty()) - return null; + public ICdtVariable getMacro(String macroName, int contextType, Object contextData) { + if (macroName == null || macroName.isEmpty()) + return null; IEnvironmentVariable var = null; - switch(contextType){ + switch (contextType) { case ICoreVariableContextInfo.CONTEXT_CONFIGURATION: - if(contextData instanceof ICConfigurationDescription){ - var = fEnvironmentProvider.getVariable(macroName, (ICConfigurationDescription)contextData, false); + if (contextData instanceof ICConfigurationDescription) { + var = fEnvironmentProvider.getVariable(macroName, (ICConfigurationDescription) contextData, false); } break; case ICoreVariableContextInfo.CONTEXT_WORKSPACE: - if(contextData == null || contextData instanceof IWorkspace){ - var = fEnvironmentProvider.getVariable(macroName, (ICConfigurationDescription)null, false); + if (contextData == null || contextData instanceof IWorkspace) { + var = fEnvironmentProvider.getVariable(macroName, (ICConfigurationDescription) null, false); } break; -// case IBuildMacroProvider.CONTEXT_ECLIPSEENV: -// if(contextData == null){ -// var = fEnvironmentProvider.getVariable(macroName,fEnvironmentProvider.getContextInfo(contextData),false); -// } -// break; + // case IBuildMacroProvider.CONTEXT_ECLIPSEENV: + // if(contextData == null){ + // var = fEnvironmentProvider.getVariable(macroName,fEnvironmentProvider.getContextInfo(contextData),false); + // } + // break; } - if(var != null && var.getOperation() != IEnvironmentVariable.ENVVAR_REMOVE) + if (var != null && var.getOperation() != IEnvironmentVariable.ENVVAR_REMOVE) return new EnvVarMacro(var); return null; @@ -164,37 +162,37 @@ public class EnvironmentVariableSupplier extends CoreMacroSupplierBase { public ICdtVariable[] getMacros(int contextType, Object contextData) { IEnvironmentVariable vars[] = null; - switch(contextType){ + switch (contextType) { case ICoreVariableContextInfo.CONTEXT_CONFIGURATION: - if(contextData instanceof ICConfigurationDescription){ - vars = fEnvironmentProvider.getVariables((ICConfigurationDescription)contextData, false); + if (contextData instanceof ICConfigurationDescription) { + vars = fEnvironmentProvider.getVariables((ICConfigurationDescription) contextData, false); } break; case ICoreVariableContextInfo.CONTEXT_WORKSPACE: - if(contextData == null || contextData instanceof IWorkspace){ - vars = fEnvironmentProvider.getVariables((ICConfigurationDescription)null, false); + if (contextData == null || contextData instanceof IWorkspace) { + vars = fEnvironmentProvider.getVariables((ICConfigurationDescription) null, false); } break; -// case IBuildMacroProvider.CONTEXT_ECLIPSEENV: -// if(contextData == null){ -// vars = fEnvironmentProvider.getVariables(fEnvironmentProvider.getContextInfo(contextData),false).toArray(false); -// } -// break; + // case IBuildMacroProvider.CONTEXT_ECLIPSEENV: + // if(contextData == null){ + // vars = fEnvironmentProvider.getVariables(fEnvironmentProvider.getContextInfo(contextData),false).toArray(false); + // } + // break; } - - if(vars != null){ + + if (vars != null) { EnvVarMacro macros[] = new EnvVarMacro[vars.length]; - for(int i = 0; i < macros.length; i++) + for (int i = 0; i < macros.length; i++) macros[i] = new EnvVarMacro(vars[i]); - + return macros; } return null; } -/* - public EnvironmentVariableProvider getEnvironmentVariableProvider(){ - return fEnvironmentProvider; - } -*/ + /* + public EnvironmentVariableProvider getEnvironmentVariableProvider(){ + return fEnvironmentProvider; + } + */ } diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/ICoreVariableContextInfo.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/ICoreVariableContextInfo.java index f776bb2dccc..eb00f50318a 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/ICoreVariableContextInfo.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/ICoreVariableContextInfo.java @@ -16,27 +16,26 @@ package org.eclipse.cdt.internal.core.cdtvariables; import org.eclipse.cdt.utils.cdtvariables.IVariableContextInfo; public interface ICoreVariableContextInfo extends IVariableContextInfo { -// public final static int CONTEXT_FILE = 1; -// public final static int CONTEXT_OPTION = 2; + // public final static int CONTEXT_FILE = 1; + // public final static int CONTEXT_OPTION = 2; public final static int CONTEXT_CONFIGURATION = 3; -// public final static int CONTEXT_PROJECT = 4; + // public final static int CONTEXT_PROJECT = 4; public final static int CONTEXT_WORKSPACE = 5; public final static int CONTEXT_INSTALLATIONS = 6; public final static int CONTEXT_ECLIPSEENV = 7; /** * returns the context type - * + * * @return int */ public int getContextType(); /** * returns the context data - * + * * @return Object */ public Object getContextData(); - } diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/StorableCdtVariable.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/StorableCdtVariable.java index a94a3859807..ae0675c93c8 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/StorableCdtVariable.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/StorableCdtVariable.java @@ -23,7 +23,7 @@ import org.eclipse.cdt.utils.cdtvariables.CdtVariableResolver; /** * This class represents the Build Macro that could be loaded * and stored in XML - * + * * @since 3.0 * */ @@ -33,37 +33,37 @@ public class StorableCdtVariable extends CdtVariable { public static final String NAME = "name"; //$NON-NLS-1$ public static final String VALUE = "value"; //$NON-NLS-1$ public static final String TYPE = "type"; //$NON-NLS-1$ - + public static final String VALUE_ELEMENT_NAME = "value"; //$NON-NLS-1$ public static final String VALUE_ELEMENT_VALUE = "name"; //$NON-NLS-1$ - - public static final String TYPE_TEXT = "VALUE_TEXT"; //$NON-NLS-1$ - public static final String TYPE_TEXT_LIST = "VALUE_TEXT_LIST"; //$NON-NLS-1$ - public static final String TYPE_PATH_FILE = "VALUE_PATH_FILE"; //$NON-NLS-1$ - public static final String TYPE_PATH_FILE_LIST = "VALUE_PATH_FILE_LIST"; //$NON-NLS-1$ - public static final String TYPE_PATH_DIR = "VALUE_PATH_DIR"; //$NON-NLS-1$ - public static final String TYPE_PATH_DIR_LIST = "VALUE_PATH_DIR_LIST"; //$NON-NLS-1$ - public static final String TYPE_PATH_ANY = "VALUE_PATH_ANY"; //$NON-NLS-1$ - public static final String TYPE_PATH_ANY_LIST = "VALUE_PATH_ANY_LIST"; //$NON-NLS-1$ - - public StorableCdtVariable(String name, int type, String value){ - super(name,type,value); + + public static final String TYPE_TEXT = "VALUE_TEXT"; //$NON-NLS-1$ + public static final String TYPE_TEXT_LIST = "VALUE_TEXT_LIST"; //$NON-NLS-1$ + public static final String TYPE_PATH_FILE = "VALUE_PATH_FILE"; //$NON-NLS-1$ + public static final String TYPE_PATH_FILE_LIST = "VALUE_PATH_FILE_LIST"; //$NON-NLS-1$ + public static final String TYPE_PATH_DIR = "VALUE_PATH_DIR"; //$NON-NLS-1$ + public static final String TYPE_PATH_DIR_LIST = "VALUE_PATH_DIR_LIST"; //$NON-NLS-1$ + public static final String TYPE_PATH_ANY = "VALUE_PATH_ANY"; //$NON-NLS-1$ + public static final String TYPE_PATH_ANY_LIST = "VALUE_PATH_ANY_LIST"; //$NON-NLS-1$ + + public StorableCdtVariable(String name, int type, String value) { + super(name, type, value); } - - public StorableCdtVariable(String name, int type, String value[]){ - super(name,type,value); + + public StorableCdtVariable(String name, int type, String value[]) { + super(name, type, value); } - public StorableCdtVariable(ICStorageElement element){ + public StorableCdtVariable(ICStorageElement element) { load(element); } - - private void load(ICStorageElement element){ + + private void load(ICStorageElement element) { fName = element.getAttribute(NAME); fType = typeStringToInt(element.getAttribute(TYPE)); - - if(!CdtVariableResolver.isStringListVariable(fType)) + + if (!CdtVariableResolver.isStringListVariable(fType)) fStringValue = element.getAttribute(VALUE); else { ICStorageElement nodeList[] = element.getChildren(); @@ -77,34 +77,34 @@ public class StorableCdtVariable extends CdtVariable { fStringListValue = values.toArray(new String[values.size()]); } } - - private int typeStringToInt(String typeString){ + + private int typeStringToInt(String typeString) { int type; - - if(TYPE_TEXT_LIST.equals(typeString)) + + if (TYPE_TEXT_LIST.equals(typeString)) type = VALUE_TEXT_LIST; - else if(TYPE_PATH_FILE.equals(typeString)) + else if (TYPE_PATH_FILE.equals(typeString)) type = VALUE_PATH_FILE; - else if(TYPE_PATH_FILE_LIST.equals(typeString)) + else if (TYPE_PATH_FILE_LIST.equals(typeString)) type = VALUE_PATH_FILE_LIST; - else if(TYPE_PATH_DIR.equals(typeString)) + else if (TYPE_PATH_DIR.equals(typeString)) type = VALUE_PATH_DIR; - else if(TYPE_PATH_DIR_LIST.equals(typeString)) + else if (TYPE_PATH_DIR_LIST.equals(typeString)) type = VALUE_PATH_DIR_LIST; - else if(TYPE_PATH_ANY.equals(typeString)) + else if (TYPE_PATH_ANY.equals(typeString)) type = VALUE_PATH_ANY; - else if(TYPE_PATH_ANY_LIST.equals(typeString)) + else if (TYPE_PATH_ANY_LIST.equals(typeString)) type = VALUE_PATH_ANY_LIST; else type = VALUE_TEXT; - + return type; } - - private String typeIntToString(int type){ + + private String typeIntToString(int type) { String stringType; - switch(type){ + switch (type) { case VALUE_TEXT_LIST: stringType = TYPE_TEXT_LIST; break; @@ -131,25 +131,24 @@ public class StorableCdtVariable extends CdtVariable { stringType = TYPE_TEXT; break; } - + return stringType; } - public void serialize(ICStorageElement element){ - if(fName != null) - element.setAttribute(NAME,fName); - - element.setAttribute(TYPE,typeIntToString(fType)); + public void serialize(ICStorageElement element) { + if (fName != null) + element.setAttribute(NAME, fName); - if(!CdtVariableResolver.isStringListVariable(fType)){ - if(fStringValue != null) - element.setAttribute(VALUE,fStringValue); - } - else { - if(fStringListValue != null && fStringListValue.length > 0){ - for(int i = 0; i < fStringListValue.length; i++){ + element.setAttribute(TYPE, typeIntToString(fType)); + + if (!CdtVariableResolver.isStringListVariable(fType)) { + if (fStringValue != null) + element.setAttribute(VALUE, fStringValue); + } else { + if (fStringListValue != null && fStringListValue.length > 0) { + for (int i = 0; i < fStringListValue.length; i++) { ICStorageElement valEl = element.createChild(VALUE_ELEMENT_NAME); - if(fStringListValue[i] != null) + if (fStringListValue[i] != null) valEl.setAttribute(VALUE_ELEMENT_VALUE, fStringListValue[i]); } } diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/StorableCdtVariables.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/StorableCdtVariables.java index ff6d2764351..704304bd6e8 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/StorableCdtVariables.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/StorableCdtVariables.java @@ -41,8 +41,8 @@ public class StorableCdtVariables implements IStorableCdtVariables { private boolean fIsChanged = false; private boolean fIsReadOnly; - private HashMap<String, ICdtVariable> getMap(){ - if(fMacros == null) + private HashMap<String, ICdtVariable> getMap() { + if (fMacros == null) fMacros = new HashMap<String, ICdtVariable>(); return fMacros; } @@ -53,7 +53,7 @@ public class StorableCdtVariables implements IStorableCdtVariables { @SuppressWarnings("unchecked") public StorableCdtVariables(StorableCdtVariables base, boolean readOnly) { - fMacros = (HashMap<String, ICdtVariable>)base.getMap().clone(); + fMacros = (HashMap<String, ICdtVariable>) base.getMap().clone(); fIsReadOnly = readOnly; } @@ -70,8 +70,8 @@ public class StorableCdtVariables implements IStorableCdtVariables { fIsReadOnly = readOnly; } - private void load(ICStorageElement element){ -// fExpandInMakefile = TRUE.equals(element.getAttribute(EXPAND_ENVIRONMENT_MACROS)); + private void load(ICStorageElement element) { + // fExpandInMakefile = TRUE.equals(element.getAttribute(EXPAND_ENVIRONMENT_MACROS)); ICStorageElement nodeList[] = element.getChildren(); for (int i = 0; i < nodeList.length; ++i) { @@ -79,8 +79,7 @@ public class StorableCdtVariables implements IStorableCdtVariables { String name = node.getName(); if (StorableCdtVariable.STRING_MACRO_ELEMENT_NAME.equals(name)) { addMacro(new StorableCdtVariable(node)); - } - else if (StorableCdtVariable.STRINGLIST_MACRO_ELEMENT_NAME.equals(name)) { + } else if (StorableCdtVariable.STRINGLIST_MACRO_ELEMENT_NAME.equals(name)) { addMacro(new StorableCdtVariable(node)); } } @@ -88,12 +87,12 @@ public class StorableCdtVariables implements IStorableCdtVariables { fIsChanged = false; } - public void serialize(ICStorageElement element){ - if(fMacros != null){ - for (ICdtVariable v : fMacros.values()){ - StorableCdtVariable macro = (StorableCdtVariable)v; + public void serialize(ICStorageElement element) { + if (fMacros != null) { + for (ICdtVariable v : fMacros.values()) { + StorableCdtVariable macro = (StorableCdtVariable) v; ICStorageElement macroEl; - if(CdtVariableResolver.isStringListVariable(macro.getValueType())) + if (CdtVariableResolver.isStringListVariable(macro.getValueType())) macroEl = element.createChild(StorableCdtVariable.STRINGLIST_MACRO_ELEMENT_NAME); else macroEl = element.createChild(StorableCdtVariable.STRING_MACRO_ELEMENT_NAME); @@ -103,21 +102,21 @@ public class StorableCdtVariables implements IStorableCdtVariables { fIsDirty = false; } - private void addMacro(ICdtVariable macro){ + private void addMacro(ICdtVariable macro) { String name = macro.getName(); - if(name == null) + if (name == null) return; - getMap().put(name,macro); + getMap().put(name, macro); } @Override - public ICdtVariable createMacro(String name, int type, String value){ - if(name == null || "".equals(name = name.trim()) || CdtVariableResolver.isStringListVariable(type)) //$NON-NLS-1$ + public ICdtVariable createMacro(String name, int type, String value) { + if (name == null || "".equals(name = name.trim()) || CdtVariableResolver.isStringListVariable(type)) //$NON-NLS-1$ return null; ICdtVariable macro = checkMacro(name, type, value); - if(macro == null){ + if (macro == null) { macro = new StorableCdtVariable(name, type, value); addMacro(macro); fIsDirty = true; @@ -126,18 +125,15 @@ public class StorableCdtVariables implements IStorableCdtVariables { return macro; } - public ICdtVariable checkMacro(String name, int type, String value){ - if(fIsReadOnly) + public ICdtVariable checkMacro(String name, int type, String value) { + if (fIsReadOnly) throw ExceptionFactory.createIsReadOnlyException(); ICdtVariable macro = getMacro(name); - if(macro != null){ - if(macro.getName().equals(name) - && macro.getValueType() == type){ + if (macro != null) { + if (macro.getName().equals(name) && macro.getValueType() == type) { try { String val = macro.getStringValue(); - if((val != null - && val.equals(value)) - || val == value){ + if ((val != null && val.equals(value)) || val == value) { return macro; } } catch (CdtVariableException e) { @@ -147,26 +143,25 @@ public class StorableCdtVariables implements IStorableCdtVariables { return null; } - public ICdtVariable checkMacro(String name, int type, String value[]){ - if(fIsReadOnly) + public ICdtVariable checkMacro(String name, int type, String value[]) { + if (fIsReadOnly) throw ExceptionFactory.createIsReadOnlyException(); ICdtVariable macro = getMacro(name); - if(macro != null){ - if(macro.getName().equals(name) - && macro.getValueType() == type){ + if (macro != null) { + if (macro.getName().equals(name) && macro.getValueType() == type) { try { String val[] = macro.getStringListValue(); - if(val != null){ - if(value != null && value.length == val.length){ + if (val != null) { + if (value != null && value.length == val.length) { int i; - for(i = 0; i < val.length; i++){ - if(!value[i].equals(val[i])) + for (i = 0; i < val.length; i++) { + if (!value[i].equals(val[i])) break; } - if(i == value.length) + if (i == value.length) return macro; } - } else if (value == val){ + } else if (value == val) { return macro; } } catch (CdtVariableException e) { @@ -181,26 +176,26 @@ public class StorableCdtVariables implements IStorableCdtVariables { * all macros that are present in the store but not included in the given array * will be removed */ - public void setMacros(ICdtVariable macros[]){ - if(fIsReadOnly) + public void setMacros(ICdtVariable macros[]) { + if (fIsReadOnly) throw ExceptionFactory.createIsReadOnlyException(); - if(macros == null || macros.length == 0) + if (macros == null || macros.length == 0) deleteAll(); - else{ + else { if (getMap().size() != 0) { Set<String> existing = new HashSet<String>(); Set<String> macroNames = new HashSet<String>(); - - for (ICdtVariable m : getMap().values()){ + + for (ICdtVariable m : getMap().values()) { existing.add(m.getName()); } - - for (ICdtVariable m : macros){ + + for (ICdtVariable m : macros) { macroNames.add(m.getName()); } - - for (String name : existing){ - if (!macroNames.contains(name)){ + + for (String name : existing) { + if (!macroNames.contains(name)) { deleteMacro(name); } } @@ -210,8 +205,8 @@ public class StorableCdtVariables implements IStorableCdtVariables { } @Override - public void createMacros(ICdtVariable macros[]){ - if(fIsReadOnly) + public void createMacros(ICdtVariable macros[]) { + if (fIsReadOnly) throw ExceptionFactory.createIsReadOnlyException(); for (ICdtVariable macro : macros) { createMacro(macro); @@ -219,36 +214,35 @@ public class StorableCdtVariables implements IStorableCdtVariables { } @Override - public boolean isEmpty(){ + public boolean isEmpty() { return fMacros == null || fMacros.isEmpty(); } @Override - public ICdtVariable createMacro(ICdtVariable copy){ - if(fIsReadOnly) + public ICdtVariable createMacro(ICdtVariable copy) { + if (fIsReadOnly) throw ExceptionFactory.createIsReadOnlyException(); String name = copy.getName(); - if(name == null || "".equals(name = name.trim())) //$NON-NLS-1$ + if (name == null || "".equals(name = name.trim())) //$NON-NLS-1$ return null; int type = copy.getValueType(); ICdtVariable macro = null; - try{ - if(CdtVariableResolver.isStringListVariable(type)){ + try { + if (CdtVariableResolver.isStringListVariable(type)) { String value[] = copy.getStringListValue(); macro = checkMacro(name, type, value); - if(macro == null){ + if (macro == null) { macro = new StorableCdtVariable(name, type, value); addMacro(macro); fIsDirty = true; fIsChanged = true; } - } - else { + } else { String value = copy.getStringValue(); macro = checkMacro(name, type, value); - if(macro == null){ + if (macro == null) { macro = new StorableCdtVariable(name, type, value); addMacro(macro); fIsDirty = true; @@ -256,18 +250,18 @@ public class StorableCdtVariables implements IStorableCdtVariables { } } - }catch(CdtVariableException e){ + } catch (CdtVariableException e) { } return macro; } @Override - public ICdtVariable createMacro(String name, int type, String value[]){ - if(name == null || "".equals(name = name.trim()) || !CdtVariableResolver.isStringListVariable(type)) //$NON-NLS-1$ + public ICdtVariable createMacro(String name, int type, String value[]) { + if (name == null || "".equals(name = name.trim()) || !CdtVariableResolver.isStringListVariable(type)) //$NON-NLS-1$ return null; ICdtVariable macro = checkMacro(name, type, value); - if(macro == null){ + if (macro == null) { macro = new StorableCdtVariable(name, type, value); addMacro(macro); fIsDirty = true; @@ -285,7 +279,7 @@ public class StorableCdtVariables implements IStorableCdtVariables { * by calling the serialize() method * @return boolean */ - public boolean isDirty(){ + public boolean isDirty() { return fIsDirty; } @@ -294,7 +288,7 @@ public class StorableCdtVariables implements IStorableCdtVariables { * @see org.eclipse.cdt.internal.core.cdtvariables.StorableCdtVariables#isDirty() * @param dirty represents the new state */ - public void setDirty(boolean dirty){ + public void setDirty(boolean dirty) { fIsDirty = dirty; } @@ -307,45 +301,44 @@ public class StorableCdtVariables implements IStorableCdtVariables { * @return boolean */ @Override - public boolean isChanged(){ + public boolean isChanged() { return fIsChanged; } -/* public boolean isExpanded(){ - return fExpandInMakefile; - } -*/ -/* public void setExpanded(boolean expand){ - if(fExpandInMakefile != expand){ - fExpandInMakefile = expand; - fIsDirty = true; - //should we set the change state here? - fIsChanged = true; + /* public boolean isExpanded(){ + return fExpandInMakefile; } - } -*/ + */ + /* public void setExpanded(boolean expand){ + if(fExpandInMakefile != expand){ + fExpandInMakefile = expand; + fIsDirty = true; + //should we set the change state here? + fIsChanged = true; + } + } + */ /** * sets the "change" state for this set of macros. * @see org.eclipse.cdt.internal.core.cdtvariables.StorableCdtVariables#isChanged() * @param changed represents the new "change" state */ - public void setChanged(boolean changed){ + public void setChanged(boolean changed) { fIsChanged = changed; } @Override - public ICdtVariable getMacro(String name){ - if(name == null || "".equals(name = name.trim())) //$NON-NLS-1$ + public ICdtVariable getMacro(String name) { + if (name == null || "".equals(name = name.trim())) //$NON-NLS-1$ return null; ICdtVariable var = getMap().get(name); - if(var == null){ + if (var == null) { int indx = name.indexOf(':'); - if(indx != -1){ + if (indx != -1) { String baseName = name.substring(0, indx); ICdtVariable tmp = getMap().get(baseName); - if(tmp != null - && CdtVariableManager.getDefault().toEclipseVariable(tmp, null) != null){ + if (tmp != null && CdtVariableManager.getDefault().toEclipseVariable(tmp, null) != null) { var = EclipseVariablesVariableSupplier.getInstance().getVariable(name); } } @@ -354,21 +347,21 @@ public class StorableCdtVariables implements IStorableCdtVariables { } @Override - public ICdtVariable[] getMacros(){ + public ICdtVariable[] getMacros() { Collection<ICdtVariable> macros = getMap().values(); return macros.toArray(new ICdtVariable[macros.size()]); } @Override - public ICdtVariable deleteMacro(String name){ - if(fIsReadOnly) + public ICdtVariable deleteMacro(String name) { + if (fIsReadOnly) throw ExceptionFactory.createIsReadOnlyException(); - if(name == null || "".equals(name = name.trim())) //$NON-NLS-1$ + if (name == null || "".equals(name = name.trim())) //$NON-NLS-1$ return null; ICdtVariable macro = getMap().remove(name); - if(macro != null){ + if (macro != null) { fIsDirty = true; fIsChanged = true; } @@ -377,11 +370,11 @@ public class StorableCdtVariables implements IStorableCdtVariables { } @Override - public boolean deleteAll(){ - if(fIsReadOnly) + public boolean deleteAll() { + if (fIsReadOnly) throw ExceptionFactory.createIsReadOnlyException(); Map<String, ICdtVariable> map = getMap(); - if(map.size() > 0){ + if (map.size() > 0) { fIsDirty = true; fIsChanged = true; map.clear(); @@ -391,12 +384,12 @@ public class StorableCdtVariables implements IStorableCdtVariables { } @Override - public boolean contains(ICdtVariable var){ + public boolean contains(ICdtVariable var) { ICdtVariable curVar = getMacro(var.getName()); - if(curVar == null) + if (curVar == null) return false; - if(new VarKey(curVar, false).equals(new VarKey(var, false))) + if (new VarKey(curVar, false).equals(new VarKey(var, false))) return true; return false; diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/UserDefinedVariableSupplier.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/UserDefinedVariableSupplier.java index f66d226bf61..134f66d3728 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/UserDefinedVariableSupplier.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/UserDefinedVariableSupplier.java @@ -56,36 +56,35 @@ import org.xml.sax.SAXException; /** * This supplier is used to obtain the user-defined macros - * + * * @since 3.0 */ public class UserDefinedVariableSupplier extends CoreMacroSupplierBase { -// public static final String MACROS_ELEMENT_NAME = "macros"; //$NON-NLS-1$ - public static final String NODENAME = "macros"; //$NON-NLS-1$ - public static final String PREFNAME_WORKSPACE = "workspace"; //$NON-NLS-1$ + // public static final String MACROS_ELEMENT_NAME = "macros"; //$NON-NLS-1$ + public static final String NODENAME = "macros"; //$NON-NLS-1$ + public static final String PREFNAME_WORKSPACE = "workspace"; //$NON-NLS-1$ static final String OLD_VARIABLE_PREFIX = "pathEntryVariable."; //$NON-NLS-1$ - private static UserDefinedVariableSupplier fInstance; - + private StorableCdtVariables fWorkspaceMacros; private Set<ICdtVariableChangeListener> fListeners; - - private StorableCdtVariables getStorableMacros(int contextType, Object contextData){ + + private StorableCdtVariables getStorableMacros(int contextType, Object contextData) { StorableCdtVariables macros = null; - switch(contextType){ + switch (contextType) { case ICoreVariableContextInfo.CONTEXT_CONFIGURATION: - if(contextData instanceof IInternalCCfgInfo){ + if (contextData instanceof IInternalCCfgInfo) { try { - CConfigurationSpecSettings settings = ((IInternalCCfgInfo)contextData).getSpecSettings(); + CConfigurationSpecSettings settings = ((IInternalCCfgInfo) contextData).getSpecSettings(); macros = settings.getMacros(); } catch (CoreException e) { } } break; case ICoreVariableContextInfo.CONTEXT_WORKSPACE: - if(contextData == null || contextData instanceof IWorkspace){ - if(fWorkspaceMacros == null) + if (contextData == null || contextData instanceof IWorkspace) { + if (fWorkspaceMacros == null) fWorkspaceMacros = loadWorkspaceMacros(); macros = fWorkspaceMacros; } @@ -93,34 +92,33 @@ public class UserDefinedVariableSupplier extends CoreMacroSupplierBase { return macros; } - - private UserDefinedVariableSupplier(){ + + private UserDefinedVariableSupplier() { fListeners = Collections.synchronizedSet(new HashSet<ICdtVariableChangeListener>()); } - public static UserDefinedVariableSupplier getInstance(){ - if(fInstance == null) + public static UserDefinedVariableSupplier getInstance() { + if (fInstance == null) fInstance = getInstanceSynch(); return fInstance; } - private static UserDefinedVariableSupplier getInstanceSynch(){ - if(fInstance == null) + private static UserDefinedVariableSupplier getInstanceSynch() { + if (fInstance == null) fInstance = new UserDefinedVariableSupplier(); return fInstance; } - /* (non-Javadoc) * @see org.eclipse.cdt.managedbuilder.macros.IBuildMacroSupplier#getMacro(java.lang.String, int, java.lang.Object) */ @Override public ICdtVariable getMacro(String macroName, int contextType, Object contextData) { - if(macroName == null || macroName.isEmpty()) + if (macroName == null || macroName.isEmpty()) return null; - - StorableCdtVariables macros = getStorableMacros(contextType,contextData); - if(macros != null) + + StorableCdtVariables macros = getStorableMacros(contextType, contextData); + if (macros != null) return macros.getMacro(macroName); return null; } @@ -130,34 +128,30 @@ public class UserDefinedVariableSupplier extends CoreMacroSupplierBase { */ @Override public ICdtVariable[] getMacros(int contextType, Object contextData) { - StorableCdtVariables macros = getStorableMacros(contextType,contextData); - if(macros != null) + StorableCdtVariables macros = getStorableMacros(contextType, contextData); + if (macros != null) return macros.getMacros(); return null; } - - public ICdtVariable createMacro(String macroName, - int type, - String value, - int contextType, - Object contextData){ - if(macroName == null || macroName.isEmpty()) + + public ICdtVariable createMacro(String macroName, int type, String value, int contextType, Object contextData) { + if (macroName == null || macroName.isEmpty()) return null; StorableCdtVariables macros = getStorableMacros(contextType, contextData); - if(macros == null) + if (macros == null) return null; - + ICdtVariable oldVar = macros.getMacro(macroName); - - ICdtVariable macro = macros.createMacro(macroName,type,value); - if(macros.isChanged()){ + + ICdtVariable macro = macros.createMacro(macroName, type, value); + if (macros.isChanged()) { macros.setChanged(false); } - - if(macro != null){ + + if (macro != null) { VariableChangeEvent event = createVariableChangeEvent(macro, oldVar); - if(event != null){ -// updateProjectInfo(contextType, contextData); + if (event != null) { + // updateProjectInfo(contextType, contextData); notifyListeners(event); } } @@ -166,28 +160,24 @@ public class UserDefinedVariableSupplier extends CoreMacroSupplierBase { } - public ICdtVariable createMacro(String macroName, - int type, - String value[], - int contextType, - Object contextData){ - if(macroName == null || macroName.isEmpty()) + public ICdtVariable createMacro(String macroName, int type, String value[], int contextType, Object contextData) { + if (macroName == null || macroName.isEmpty()) return null; StorableCdtVariables macros = getStorableMacros(contextType, contextData); - if(macros == null) + if (macros == null) return null; - + ICdtVariable oldVar = macros.getMacro(macroName); - ICdtVariable macro = macros.createMacro(macroName,type,value); - if(macros.isChanged()){ + ICdtVariable macro = macros.createMacro(macroName, type, value); + if (macros.isChanged()) { macros.setChanged(false); } - - if(macro != null){ + + if (macro != null) { VariableChangeEvent event = createVariableChangeEvent(macro, oldVar); - if(event != null){ -// updateProjectInfo(contextType, contextData); + if (event != null) { + // updateProjectInfo(contextType, contextData); notifyListeners(event); } } @@ -196,162 +186,162 @@ public class UserDefinedVariableSupplier extends CoreMacroSupplierBase { } - public ICdtVariable createMacro(ICdtVariable copy, int contextType, Object contextData){ - if(copy == null) + public ICdtVariable createMacro(ICdtVariable copy, int contextType, Object contextData) { + if (copy == null) return null; String macroName = copy.getName(); - if(macroName == null || macroName.isEmpty()) + if (macroName == null || macroName.isEmpty()) return null; StorableCdtVariables macros = getStorableMacros(contextType, contextData); - if(macros == null) + if (macros == null) return null; - + ICdtVariable oldVar = macros.getMacro(macroName); - + ICdtVariable macro = macros.createMacro(copy); - if(macros.isChanged()){ + if (macros.isChanged()) { macros.setChanged(false); } - - if(macro != null){ + + if (macro != null) { VariableChangeEvent event = createVariableChangeEvent(macro, oldVar); - if(event != null){ -// updateProjectInfo(contextType, contextData); + if (event != null) { + // updateProjectInfo(contextType, contextData); notifyListeners(event); } } return macro; } - public ICdtVariable deleteMacro(String name, int contextType, Object contextData){ - StorableCdtVariables macros = getStorableMacros(contextType,contextData); - if(macros == null) + public ICdtVariable deleteMacro(String name, int contextType, Object contextData) { + StorableCdtVariables macros = getStorableMacros(contextType, contextData); + if (macros == null) return null; ICdtVariable macro = macros.deleteMacro(name); - if(macro != null){ - + if (macro != null) { + VariableChangeEvent event = createVariableChangeEvent(null, macro); - if(event != null){ -// updateProjectInfo(contextType, contextData); + if (event != null) { + // updateProjectInfo(contextType, contextData); notifyListeners(event); } } - + return macro; } - - public void deleteAll(int contextType, Object contextData){ + + public void deleteAll(int contextType, Object contextData) { StorableCdtVariables macros = getStorableMacros(contextType, contextData); - if(macros == null) + if (macros == null) return; ICdtVariable[] oldVars = macros.getMacros(); - - if(macros.deleteAll()){ -// setRebuildStateForContext(contextType, contextData); + + if (macros.deleteAll()) { + // setRebuildStateForContext(contextType, contextData); } - + VariableChangeEvent event = createVariableChangeEvent(null, oldVars); - if(event != null){ -// updateProjectInfo(contextType, contextData); + if (event != null) { + // updateProjectInfo(contextType, contextData); notifyListeners(event); } } - - public void setMacros(ICdtVariable m[], int contextType, Object contextData){ + + public void setMacros(ICdtVariable m[], int contextType, Object contextData) { StorableCdtVariables macros = getStorableMacros(contextType, contextData); - if(macros == null) + if (macros == null) return; ICdtVariable[] oldVars = macros.getMacros(); - + macros.setMacros(m); - if(macros.isChanged()){ + if (macros.isChanged()) { macros.setChanged(false); - + VariableChangeEvent event = createVariableChangeEvent(m, oldVars); - if(event != null){ -// updateProjectInfo(contextType, contextData); + if (event != null) { + // updateProjectInfo(contextType, contextData); notifyListeners(event); } } } - + static class VarKey { private ICdtVariable fVar; private boolean fNameOnly; - - VarKey(ICdtVariable var, boolean nameOnly){ + + VarKey(ICdtVariable var, boolean nameOnly) { fVar = var; fNameOnly = nameOnly; } - - public ICdtVariable getVariable(){ - return fVar; + + public ICdtVariable getVariable() { + return fVar; } @Override public boolean equals(Object obj) { - if(obj == this) + if (obj == this) return true; - - if(!(obj instanceof VarKey)) + + if (!(obj instanceof VarKey)) return false; - - VarKey other = (VarKey)obj; - + + VarKey other = (VarKey) obj; + ICdtVariable otherVar = other.fVar; - - if(fVar == otherVar) + + if (fVar == otherVar) return true; - - if(!CDataUtil.objectsEqual(fVar.getName(), otherVar.getName())) + + if (!CDataUtil.objectsEqual(fVar.getName(), otherVar.getName())) return false; - if(fNameOnly) + if (fNameOnly) return true; - - if(fVar.getValueType() != otherVar.getValueType()) + + if (fVar.getValueType() != otherVar.getValueType()) return false; - if(CdtVariableResolver.isStringListVariable(fVar.getValueType())){ + if (CdtVariableResolver.isStringListVariable(fVar.getValueType())) { try { - if(!Arrays.equals(fVar.getStringListValue(), otherVar.getStringListValue())) + if (!Arrays.equals(fVar.getStringListValue(), otherVar.getStringListValue())) return false; } catch (CdtVariableException e) { CCorePlugin.log(e); } } else { try { - if(!CDataUtil.objectsEqual(fVar.getStringValue(), otherVar.getStringValue())) + if (!CDataUtil.objectsEqual(fVar.getStringValue(), otherVar.getStringValue())) return false; } catch (CdtVariableException e) { CCorePlugin.log(e); } } - + return true; } @Override public int hashCode() { int code = 51; - + String name = fVar.getName(); - if(name != null) + if (name != null) code += name.hashCode(); - if(fNameOnly) + if (fNameOnly) return code; - + code += fVar.getValueType(); - if(CdtVariableResolver.isStringListVariable(fVar.getValueType())){ + if (CdtVariableResolver.isStringListVariable(fVar.getValueType())) { try { String[] value = fVar.getStringListValue(); - if(value != null){ + if (value != null) { for (String element : value) { code += element.hashCode(); } @@ -361,148 +351,147 @@ public class UserDefinedVariableSupplier extends CoreMacroSupplierBase { } } else { try { - String value =fVar.getStringValue(); - if(value != null){ + 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; - + 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<VarKey> set){ + static ICdtVariable[] varsFromKeySet(Set<VarKey> set) { ICdtVariable vars[] = new ICdtVariable[set.size()]; int i = 0; - for(VarKey key : set) { + for (VarKey key : set) { vars[i++] = key.getVariable(); } return vars; } - + @SuppressWarnings("unchecked") - static VariableChangeEvent createVariableChangeEvent(ICdtVariable[] newVars, ICdtVariable[] oldVars){ + static VariableChangeEvent createVariableChangeEvent(ICdtVariable[] newVars, ICdtVariable[] oldVars) { ICdtVariable[] addedVars = null, removedVars = null, changedVars = null; - - if(oldVars == null || oldVars.length == 0){ - if(newVars != null && newVars.length != 0) - addedVars = newVars.clone() ; - } else if(newVars == null || newVars.length == 0){ + + if (oldVars == null || oldVars.length == 0) { + if (newVars != null && newVars.length != 0) + addedVars = newVars.clone(); + } else if (newVars == null || newVars.length == 0) { removedVars = oldVars.clone(); } else { HashSet<VarKey> newSet = new HashSet<VarKey>(newVars.length); HashSet<VarKey> oldSet = new HashSet<VarKey>(oldVars.length); - + for (ICdtVariable newVar : newVars) { newSet.add(new VarKey(newVar, true)); } - + for (ICdtVariable oldVar : oldVars) { oldSet.add(new VarKey(oldVar, true)); } - - HashSet<VarKey> newSetCopy = (HashSet<VarKey>)newSet.clone(); - + + HashSet<VarKey> newSetCopy = (HashSet<VarKey>) newSet.clone(); + newSet.removeAll(oldSet); oldSet.removeAll(newSetCopy); - - if(newSet.size() != 0){ + + if (newSet.size() != 0) { addedVars = varsFromKeySet(newSet); } - - if(oldSet.size() != 0){ + + if (oldSet.size() != 0) { removedVars = varsFromKeySet(oldSet); } - + newSetCopy.removeAll(newSet); - + HashSet<VarKey> modifiedSet = new HashSet<VarKey>(newSetCopy.size()); for (Object element : newSetCopy) { - VarKey key = (VarKey)element; + VarKey key = (VarKey) element; modifiedSet.add(new VarKey(key.getVariable(), false)); } - + for (ICdtVariable oldVar : oldVars) { modifiedSet.remove(new VarKey(oldVar, false)); } - - if(modifiedSet.size() != 0) - changedVars = varsFromKeySet(modifiedSet); + + if (modifiedSet.size() != 0) + changedVars = varsFromKeySet(modifiedSet); } - - if(addedVars != null || removedVars != null || changedVars != null) + + 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 + * */ - public void storeWorkspaceVariables(boolean force){ - try{ - if(fWorkspaceMacros != null) - storeWorkspaceMacros(fWorkspaceMacros,force); - }catch(CoreException e){ + public void storeWorkspaceVariables(boolean force) { + try { + if (fWorkspaceMacros != null) + storeWorkspaceMacros(fWorkspaceMacros, force); + } catch (CoreException e) { } } - - public StorableCdtVariables getWorkspaceVariablesCopy(){ + + public StorableCdtVariables getWorkspaceVariablesCopy() { StorableCdtVariables vars = getStorableMacros(ICoreVariableContextInfo.CONTEXT_WORKSPACE, null); return new StorableCdtVariables(vars, false); } - - public boolean setWorkspaceVariables(StorableCdtVariables vars) throws CoreException{ + + public boolean setWorkspaceVariables(StorableCdtVariables vars) throws CoreException { StorableCdtVariables old = getStorableMacros(ICoreVariableContextInfo.CONTEXT_WORKSPACE, null); ICdtVariable[] oldVars = null; - if(old != null) + if (old != null) oldVars = old.getMacros(); - + ICdtVariable[] newVars = vars.getMacros(); - + fWorkspaceMacros = new StorableCdtVariables(vars, false); - + VariableChangeEvent event = createVariableChangeEvent(newVars, oldVars); - if(event != null){ -// updateProjectInfo(ICoreVariableContextInfo.CONTEXT_WORKSPACE, null); + if (event != null) { + // updateProjectInfo(ICoreVariableContextInfo.CONTEXT_WORKSPACE, null); notifyListeners(event); } storeWorkspaceVariables(true); return event != null; } - - private Preferences getWorkspaceNode(){ + + private Preferences getWorkspaceNode() { Preferences prefNode = InstanceScope.INSTANCE.getNode(CCorePlugin.PLUGIN_ID); - if(prefNode == null) + if (prefNode == null) return null; - + return prefNode.node(NODENAME); } - /* * loads the stored workspace macros */ - protected StorableCdtVariables loadWorkspaceMacros(){ + protected StorableCdtVariables loadWorkspaceMacros() { StorableCdtVariables macros = loadNewStileWorkspaceMacros(); - + //now load PathEntry Variables from preferences loadPathEntryVariables(macros); - - if(macros.isDirty()){ + + if (macros.isDirty()) { try { storeWorkspaceMacros(macros, true); } catch (CoreException e) { @@ -511,183 +500,171 @@ public class UserDefinedVariableSupplier extends CoreMacroSupplierBase { } return macros; } - - protected void loadPathEntryVariables(StorableCdtVariables vars){ + + protected void loadPathEntryVariables(StorableCdtVariables vars) { org.eclipse.core.runtime.Preferences prefs = CCorePlugin.getDefault().getPluginPreferences(); String[] names = prefs.propertyNames(); for (String name : names) { if (name.startsWith(OLD_VARIABLE_PREFIX)) { String value = prefs.getString(name); prefs.setToDefault(name); - if(value.length() != 0){ + if (value.length() != 0) { name = name.substring(OLD_VARIABLE_PREFIX.length()); vars.createMacro(name, ICdtVariable.VALUE_PATH_ANY, value); } } } } - - protected StorableCdtVariables loadNewStileWorkspaceMacros(){ - InputStream stream = loadInputStream(getWorkspaceNode(),PREFNAME_WORKSPACE); - if(stream == null) + + protected StorableCdtVariables loadNewStileWorkspaceMacros() { + InputStream stream = loadInputStream(getWorkspaceNode(), PREFNAME_WORKSPACE); + if (stream == null) return new StorableCdtVariables(false); return loadMacrosFromStream(stream, false); } - - + /* - * stores the given macros + * stores the given macros */ - protected void storeWorkspaceMacros(StorableCdtVariables macros, boolean force) throws CoreException{ - if(!macros.isDirty() && !force) + protected void storeWorkspaceMacros(StorableCdtVariables macros, boolean force) throws CoreException { + if (!macros.isDirty() && !force) return; - + ByteArrayOutputStream stream = storeMacrosToStream(macros); - if(stream == null) + if (stream == null) return; - storeOutputStream(stream,getWorkspaceNode(),PREFNAME_WORKSPACE); + storeOutputStream(stream, getWorkspaceNode(), PREFNAME_WORKSPACE); } - - private StorableCdtVariables loadMacrosFromStream(InputStream stream, boolean readOnly){ - try{ + + private StorableCdtVariables loadMacrosFromStream(InputStream stream, boolean readOnly) { + try { DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder(); InputSource inputSource = new InputSource(stream); Document document = parser.parse(inputSource); Element rootElement = document.getDocumentElement(); - - if(!StorableCdtVariables.MACROS_ELEMENT_NAME.equals(rootElement.getNodeName())) + + if (!StorableCdtVariables.MACROS_ELEMENT_NAME.equals(rootElement.getNodeName())) return null; - + return new StorableCdtVariables(new XmlStorageElement(rootElement), readOnly); + } catch (ParserConfigurationException e) { + + } catch (SAXException e) { + + } catch (IOException e) { + } - catch(ParserConfigurationException e){ - - } - catch(SAXException e){ - - } - catch(IOException e){ - - } - + return null; } - - private ByteArrayOutputStream storeMacrosToStream(StorableCdtVariables macros) throws CoreException{ - try{ - DocumentBuilderFactory factory= DocumentBuilderFactory.newInstance(); - DocumentBuilder builder= factory.newDocumentBuilder(); - Document document= builder.newDocument(); - + + private ByteArrayOutputStream storeMacrosToStream(StorableCdtVariables macros) throws CoreException { + try { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + Document document = builder.newDocument(); + Element rootElement = document.createElement(StorableCdtVariables.MACROS_ELEMENT_NAME); document.appendChild(rootElement); ICStorageElement storageElement = new XmlStorageElement(rootElement); macros.serialize(storageElement); - - Transformer transformer=TransformerFactory.newInstance().newTransformer(); + + Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$ transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); //$NON-NLS-1$ transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$ DOMSource source = new DOMSource(document); - + ByteArrayOutputStream stream = new ByteArrayOutputStream(); StreamResult result = new StreamResult(stream); - + transformer.transform(source, result); return stream; - } - catch(ParserConfigurationException e){ - throw ExceptionFactory.createCoreException(e.getMessage(), - e); - } - catch(TransformerConfigurationException e){ - throw ExceptionFactory.createCoreException(e.getMessage(), - e); - } - catch(TransformerException e){ - throw ExceptionFactory.createCoreException(e.getMessage(), - e); + } catch (ParserConfigurationException e) { + throw ExceptionFactory.createCoreException(e.getMessage(), e); + } catch (TransformerConfigurationException e) { + throw ExceptionFactory.createCoreException(e.getMessage(), e); + } catch (TransformerException e) { + throw ExceptionFactory.createCoreException(e.getMessage(), e); } } - - private InputStream loadInputStream(Preferences node, String key){ - if(node == null || key == null) + + private InputStream loadInputStream(Preferences node, String key) { + if (node == null || key == null) return null; - - String value = node.get(key,null); - if(value == null || value.length() == 0) + + String value = node.get(key, null); + if (value == null || value.length() == 0) return null; - + byte[] bytes; try { bytes = value.getBytes("UTF-8"); //$NON-NLS-1$ } catch (UnsupportedEncodingException e) { bytes = value.getBytes(); } - + return new ByteArrayInputStream(bytes); } - - private void storeOutputStream(ByteArrayOutputStream stream, Preferences node, String key) throws CoreException{ - if(stream == null || node == null || key == null) + + private void storeOutputStream(ByteArrayOutputStream stream, Preferences node, String key) throws CoreException { + if (stream == null || node == null || key == null) throw ExceptionFactory.createCoreException(new IllegalArgumentException()); - byte[] bytes= stream.toByteArray(); - + byte[] bytes = stream.toByteArray(); + String val = null; try { - val= new String(bytes, "UTF-8"); //$NON-NLS-1$ + val = new String(bytes, "UTF-8"); //$NON-NLS-1$ } catch (UnsupportedEncodingException e) { - val= new String(bytes); + val = new String(bytes); } - - node.put(key,val); - - try{ + + node.put(key, val); + + try { node.flush(); - } - catch(BackingStoreException e){ - throw ExceptionFactory.createCoreException(e.getMessage(), - e); + } catch (BackingStoreException e) { + throw ExceptionFactory.createCoreException(e.getMessage(), e); } } - -// protected void updateProjectInfo(int type, Object context){ -// } - + + // protected void updateProjectInfo(int type, Object context){ + // } + /** * Adds a listener that will be notified of changes in Build Variables. * * @param listener - the listener to add */ - public void addListener(ICdtVariableChangeListener listener){ + public void addListener(ICdtVariableChangeListener listener) { fListeners.add(listener); } - + /** * Removes a Build Variables change listener. * * @param listener - the listener to remove. */ - public void removeListener(ICdtVariableChangeListener listener){ + public void removeListener(ICdtVariableChangeListener listener) { fListeners.remove(listener); } - - private void notifyListeners(VariableChangeEvent event){ + + private void notifyListeners(VariableChangeEvent event) { ICdtVariableChangeListener[] listeners = fListeners.toArray(new ICdtVariableChangeListener[fListeners.size()]); for (ICdtVariableChangeListener listener : listeners) { listener.variablesChanged(event); } } - - public boolean containsVariable(int context, Object data, ICdtVariable var){ + + public boolean containsVariable(int context, Object data, ICdtVariable var) { ICdtVariable varContained = getMacro(var.getName(), context, data); - if(varContained == null) + if (varContained == null) return false; - - if(new VarKey(varContained, false).equals(new VarKey(var, false))) + + if (new VarKey(varContained, false).equals(new VarKey(var, false))) return true; - + return false; } - + } diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/UserVarSupplier.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/UserVarSupplier.java index 9ccd620d829..e8b77e5f42d 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/UserVarSupplier.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/UserVarSupplier.java @@ -49,8 +49,7 @@ public class UserVarSupplier implements IUserVarSupplier { * @see org.eclipse.cdt.core.cdtvariables.IUserVarSupplier#createMacro(java.lang.String, int, java.lang.String, java.lang.Object) */ @Override - public ICdtVariable createMacro(String macroName, int type, String value, - ICConfigurationDescription contextData) { + public ICdtVariable createMacro(String macroName, int type, String value, ICConfigurationDescription contextData) { return CdtVariableManager.fUserDefinedMacroSupplier.createMacro(macroName, type, value, CTX, contextData); } @@ -96,8 +95,7 @@ public class UserVarSupplier implements IUserVarSupplier { @Override public boolean isDynamic(ICdtVariable v) { if (v instanceof EclipseVariablesVariableSupplier.EclipseVarMacro) { - EclipseVariablesVariableSupplier.EclipseVarMacro evar = - (EclipseVariablesVariableSupplier.EclipseVarMacro)v; + EclipseVariablesVariableSupplier.EclipseVarMacro evar = (EclipseVariablesVariableSupplier.EclipseVarMacro) v; if (evar.getVariable() instanceof IDynamicVariable) return true; } @@ -115,10 +113,9 @@ public class UserVarSupplier implements IUserVarSupplier { } @Override - public boolean setWorkspaceVariables(IStorableCdtVariables vars) - throws CoreException { + public boolean setWorkspaceVariables(IStorableCdtVariables vars) throws CoreException { if (vars instanceof StorableCdtVariables) - return CdtVariableManager.fUserDefinedMacroSupplier.setWorkspaceVariables((StorableCdtVariables)vars); + return CdtVariableManager.fUserDefinedMacroSupplier.setWorkspaceVariables((StorableCdtVariables) vars); else return false; } diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/VariableChangeEvent.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/VariableChangeEvent.java index 1eeb80c32e2..7ffe0efc185 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/VariableChangeEvent.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/cdtvariables/VariableChangeEvent.java @@ -20,24 +20,25 @@ 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; + + 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[] getAddedVariables() { + return fAddedVars != null ? (ICdtVariable[]) fAddedVars.clone() : EMPTY_VAR_ARRAY; } - public ICdtVariable[] getRemovedVariables(){ - return fRemovedVars != null ? (ICdtVariable[])fRemovedVars.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; + public ICdtVariable[] getChangedVariables() { + return fChangedVars != null ? (ICdtVariable[]) fChangedVars.clone() : EMPTY_VAR_ARRAY; } } |