From e8f05b99482a81acb522e950ea4fcedf856d1dbc Mon Sep 17 00:00:00 2001 From: Darin Swanson Date: Wed, 7 Apr 2004 21:35:03 +0000 Subject: Bug 57334 - Too much validation going on in launch config location --- .../variables/StringSubstitutionEngine.java | 59 ++++++++++++++++------ .../internal/variables/StringVariableManager.java | 9 +++- 2 files changed, 51 insertions(+), 17 deletions(-) (limited to 'org.eclipse.core.variables/src/org/eclipse/core/internal') diff --git a/org.eclipse.core.variables/src/org/eclipse/core/internal/variables/StringSubstitutionEngine.java b/org.eclipse.core.variables/src/org/eclipse/core/internal/variables/StringSubstitutionEngine.java index 79ec024f0..03d772137 100644 --- a/org.eclipse.core.variables/src/org/eclipse/core/internal/variables/StringSubstitutionEngine.java +++ b/org.eclipse.core.variables/src/org/eclipse/core/internal/variables/StringSubstitutionEngine.java @@ -16,7 +16,6 @@ import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Stack; - import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; @@ -44,7 +43,7 @@ public class StringSubstitutionEngine { private StringBuffer fResult; /** - * whether substitutions were performed + * Whether substitutions were performed */ private boolean fSubs; @@ -83,11 +82,11 @@ public class StringSubstitutionEngine { * @exception CoreException if unable to resolve a referenced variable or if a cycle exists * in referenced variables */ - public String performStringSubstitution(String expression, boolean reportUndefinedVariables, IStringVariableManager manager) throws CoreException { - substitute(expression, reportUndefinedVariables, manager); + public String performStringSubstitution(String expression, boolean reportUndefinedVariables, boolean resolveVariables, IStringVariableManager manager) throws CoreException { + substitute(expression, reportUndefinedVariables, resolveVariables, manager); List resolvedVariableSets = new ArrayList(); while (fSubs) { - HashSet resolved = substitute(fResult.toString(), reportUndefinedVariables, manager); + HashSet resolved = substitute(fResult.toString(), reportUndefinedVariables, true, manager); for(int i=resolvedVariableSets.size()-1; i>=0; i--) { @@ -113,15 +112,28 @@ public class StringSubstitutionEngine { return fResult.toString(); } + /** + * Performs recursive string validation to ensure that all of the variables + * contained in the expression exist + * @param expression expression to validate + * @param manager registry of variables + * @exception CoreException if a referenced variable does not exist or if a cycle exists + * in referenced variables + */ + public void validateStringVariables(String expression, IStringVariableManager manager) throws CoreException { + performStringSubstitution(expression, true, false, manager); + } + /** * Makes a substitution pass of the given expression returns a Set of the variables that were resolved in this * pass * * @param expression source expression * @param reportUndefinedVariables whether to report undefined variables as an error + * @param resolveVariables whether to resolve the value of any variables * @exception CoreException if unable to resolve a variable */ - private HashSet substitute(String expression, boolean reportUndefinedVariables, IStringVariableManager manager) throws CoreException { + private HashSet substitute(String expression, boolean reportUndefinedVariables, boolean resolveVariables, IStringVariableManager manager) throws CoreException { fResult = new StringBuffer(expression.length()); fStack = new Stack(); fSubs = false; @@ -177,7 +189,7 @@ public class StringSubstitutionEngine { resolvedVariables.add(substring); pos = end + 1; - String value = resolve(tos, reportUndefinedVariables, manager); + String value= resolve(tos, reportUndefinedVariables, resolveVariables, manager); if (value == null) { value = ""; //$NON-NLS-1$ } @@ -219,11 +231,12 @@ public class StringSubstitutionEngine { * @param var * @param reportUndefinedVariables whether to report undefined variables as * an error + * @param resolveVariables whether to resolve the variables value or just to validate that this variable is valid * @param manager variable registry * @return variable value, possibly null * @exception CoreException if unable to resolve a value */ - private String resolve(VariableReference var, boolean reportUndefinedVariables, IStringVariableManager manager) throws CoreException { + private String resolve(VariableReference var, boolean reportUndefinedVariables, boolean resolveVariables, IStringVariableManager manager) throws CoreException { String text = var.getText(); int pos = text.indexOf(VARIABLE_ARG); String name = null; @@ -246,23 +259,37 @@ public class StringSubstitutionEngine { throw new CoreException(new Status(IStatus.ERROR, VariablesPlugin.getUniqueIdentifier(), VariablesPlugin.INTERNAL_ERROR, MessageFormat.format(VariablesMessages.getString("StringSubstitutionEngine.3"), new String[]{name}), null)); //$NON-NLS-1$ } else { // leave as is - StringBuffer res = new StringBuffer(var.getText()); - res.insert(0, VARIABLE_START); - res.append(VARIABLE_END); - return res.toString(); + return getOriginalVarText(var); } } else { - fSubs = true; - return dynamicVariable.getValue(arg); + if (resolveVariables) { + fSubs = true; + return dynamicVariable.getValue(arg); + } else { + //leave as is + return getOriginalVarText(var); + } } } else { if (arg == null) { - fSubs = true; - return valueVariable.getValue(); + if (resolveVariables) { + fSubs = true; + return valueVariable.getValue(); + } else { + //leave as is + return getOriginalVarText(var); + } } else { // error - an argument specified for a value variable throw new CoreException(new Status(IStatus.ERROR, VariablesPlugin.getUniqueIdentifier(), VariablesPlugin.INTERNAL_ERROR, MessageFormat.format(VariablesMessages.getString("StringSubstitutionEngine.4"), new String[]{valueVariable.getName()}), null)); //$NON-NLS-1$ } } } + + private String getOriginalVarText(VariableReference var) { + StringBuffer res = new StringBuffer(var.getText()); + res.insert(0, VARIABLE_START); + res.append(VARIABLE_END); + return res.toString(); + } } \ No newline at end of file diff --git a/org.eclipse.core.variables/src/org/eclipse/core/internal/variables/StringVariableManager.java b/org.eclipse.core.variables/src/org/eclipse/core/internal/variables/StringVariableManager.java index 05bc6945b..41e66ddd8 100644 --- a/org.eclipse.core.variables/src/org/eclipse/core/internal/variables/StringVariableManager.java +++ b/org.eclipse.core.variables/src/org/eclipse/core/internal/variables/StringVariableManager.java @@ -527,11 +527,18 @@ public class StringVariableManager implements IStringVariableManager { buffer.append("}"); //$NON-NLS-1$ return buffer.toString(); } + /* (non-Javadoc) * @see org.eclipse.debug.internal.core.stringsubstitution.IStringVariableManager#performStringSubstitution(java.lang.String, boolean) */ public String performStringSubstitution(String expression, boolean reportUndefinedVariables) throws CoreException { - return new StringSubstitutionEngine().performStringSubstitution(expression, reportUndefinedVariables, this); + return new StringSubstitutionEngine().performStringSubstitution(expression, reportUndefinedVariables, true, this); } + /* (non-Javadoc) + * @see org.eclipse.core.variables.IStringVariableManager#validateStringVariables(java.lang.String) + */ + public void validateStringVariables(String expression) throws CoreException { + new StringSubstitutionEngine().validateStringVariables(expression, this); + } } -- cgit v1.2.3