From 459e7a37e00d381973d431e7b1db2a8051e1dcfd Mon Sep 17 00:00:00 2001
From: Luc Bourlier
Date: Tue, 21 Oct 2003 17:34:35 +0000
Subject: Bug 43332 - String Substitution Support - org.eclipse.core.variables
---
org.eclipse.debug.core/.classpath | 1 +
org.eclipse.debug.core/.project | 1 +
.../core/org/eclipse/debug/core/DebugPlugin.java | 12 -
.../eclipse/debug/internal/core/LaunchManager.java | 3 +-
.../core/stringsubstitution/DynamicVariable.java | 61 ---
.../core/stringsubstitution/IDynamicVariable.java | 37 --
.../IDynamicVariableResolver.java | 33 --
.../core/stringsubstitution/IStringVariable.java | 56 ---
.../stringsubstitution/IStringVariableManager.java | 145 ------
.../core/stringsubstitution/IValueVariable.java | 54 --
.../IValueVariableInitializer.java | 30 --
.../stringsubstitution/IValueVariableListener.java | 45 --
.../StringSubstitutionEngine.java | 229 ---------
.../StringSubstitutionMessages.java | 45 --
.../StringSubstitutionMessages.properties | 16 -
.../core/stringsubstitution/StringVariable.java | 79 ---
.../stringsubstitution/StringVariableManager.java | 552 ---------------------
.../core/stringsubstitution/ValueVariable.java | 124 -----
org.eclipse.debug.core/plugin.xml | 4 +-
.../schema/dynamicVariables.exsd | 112 -----
org.eclipse.debug.core/schema/valueVariables.exsd | 147 ------
org.eclipse.debug.ui/.classpath | 1 +
org.eclipse.debug.ui/.project | 1 +
org.eclipse.debug.ui/plugin.xml | 3 +-
.../ui/stringsubstitution/IArgumentSelector.java | 2 +-
.../ui/stringsubstitution/PromptingResolver.java | 4 +-
.../ui/stringsubstitution/ResourceResolver.java | 4 +-
.../ui/stringsubstitution/ResourceSelector.java | 2 +-
.../StringVariableLabelProvider.java | 2 +-
.../StringVariablePresentationManager.java | 2 +-
.../StringVariableSelectionDialog.java | 6 +-
.../ui/stringsubstitution/WorkspaceResolver.java | 2 +-
32 files changed, 22 insertions(+), 1793 deletions(-)
delete mode 100644 org.eclipse.debug.core/core/org/eclipse/debug/internal/core/stringsubstitution/DynamicVariable.java
delete mode 100644 org.eclipse.debug.core/core/org/eclipse/debug/internal/core/stringsubstitution/IDynamicVariable.java
delete mode 100644 org.eclipse.debug.core/core/org/eclipse/debug/internal/core/stringsubstitution/IDynamicVariableResolver.java
delete mode 100644 org.eclipse.debug.core/core/org/eclipse/debug/internal/core/stringsubstitution/IStringVariable.java
delete mode 100644 org.eclipse.debug.core/core/org/eclipse/debug/internal/core/stringsubstitution/IStringVariableManager.java
delete mode 100644 org.eclipse.debug.core/core/org/eclipse/debug/internal/core/stringsubstitution/IValueVariable.java
delete mode 100644 org.eclipse.debug.core/core/org/eclipse/debug/internal/core/stringsubstitution/IValueVariableInitializer.java
delete mode 100644 org.eclipse.debug.core/core/org/eclipse/debug/internal/core/stringsubstitution/IValueVariableListener.java
delete mode 100644 org.eclipse.debug.core/core/org/eclipse/debug/internal/core/stringsubstitution/StringSubstitutionEngine.java
delete mode 100644 org.eclipse.debug.core/core/org/eclipse/debug/internal/core/stringsubstitution/StringSubstitutionMessages.java
delete mode 100644 org.eclipse.debug.core/core/org/eclipse/debug/internal/core/stringsubstitution/StringSubstitutionMessages.properties
delete mode 100644 org.eclipse.debug.core/core/org/eclipse/debug/internal/core/stringsubstitution/StringVariable.java
delete mode 100644 org.eclipse.debug.core/core/org/eclipse/debug/internal/core/stringsubstitution/StringVariableManager.java
delete mode 100644 org.eclipse.debug.core/core/org/eclipse/debug/internal/core/stringsubstitution/ValueVariable.java
delete mode 100644 org.eclipse.debug.core/schema/dynamicVariables.exsd
delete mode 100644 org.eclipse.debug.core/schema/valueVariables.exsd
diff --git a/org.eclipse.debug.core/.classpath b/org.eclipse.debug.core/.classpath
index ae3b58c5d..2fca06953 100644
--- a/org.eclipse.debug.core/.classpath
+++ b/org.eclipse.debug.core/.classpath
@@ -5,5 +5,6 @@
- * A variable is identified by its name, and optionally accepts an argument. When an
- * argument is present, a colon seperates the variable name from its argument.
- *
- * Variables can be contributed by extensions or programmatically. There are two
- * kinds of variables.
- * null
if none.
diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchManager.java b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchManager.java
index 431ca5975..85d1bf01a 100644
--- a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchManager.java
+++ b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchManager.java
@@ -63,6 +63,7 @@ import org.eclipse.core.runtime.ISafeRunnable;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
+import org.eclipse.core.variables.VariablesPlugin;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunch;
@@ -1560,7 +1561,7 @@ public class LaunchManager implements ILaunchManager, IResourceChangeListener {
Map.Entry entry= (Map.Entry) iter.next();
String value = (String) entry.getValue();
// translate any string substitution variables
- String translated = DebugPlugin.getDefault().getStringVariableManager().performStringSubstitution(value);
+ String translated = VariablesPlugin.getDefault().getStringVariableManager().performStringSubstitution(value);
env.put(entry.getKey(), translated);
}
diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/stringsubstitution/DynamicVariable.java b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/stringsubstitution/DynamicVariable.java
deleted file mode 100644
index 1cc54c870..000000000
--- a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/stringsubstitution/DynamicVariable.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2003 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.debug.internal.core.stringsubstitution;
-
-import java.text.MessageFormat;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.debug.core.DebugPlugin;
-
-/**
- * Dynamic variable
- */
-public class DynamicVariable extends StringVariable implements IDynamicVariable {
-
- /**
- * Resolver, or null
until needed
- */
- private IDynamicVariableResolver fResolver;
-
- /* (non-Javadoc)
- * @see org.eclipse.debug.internal.core.stringsubstitution.IContextVariable#getValue(java.lang.String)
- */
- public String getValue(String argument) throws CoreException {
- if (fResolver == null) {
- String name = getConfigurationElement().getAttribute("resolver"); //$NON-NLS-1$
- if (name == null) {
- throw new CoreException(new Status(IStatus.ERROR, DebugPlugin.getUniqueIdentifier(), DebugPlugin.INTERNAL_ERROR, MessageFormat.format("Contributed context variable {0} must specify a resolver.",new String[]{getName()}), null)); //$NON-NLS-1$
- }
- Object object = getConfigurationElement().createExecutableExtension("resolver"); //$NON-NLS-1$
- if (object instanceof IDynamicVariableResolver) {
- fResolver = (IDynamicVariableResolver)object;
- } else {
- throw new CoreException(new Status(IStatus.ERROR, DebugPlugin.getUniqueIdentifier(), DebugPlugin.INTERNAL_ERROR, MessageFormat.format("Contributed context variable resolver for {0} must be an instance of IContextVariableResolver.",new String[]{getName()}), null)); //$NON-NLS-1$
- }
- }
- return fResolver.resolveValue(this, argument);
- }
-
- /**
- * Constructs a new context variable.
- *
- * @param name variable name
- * @param description variable description or null
- * @param configurationElement configuration element
- */
- public DynamicVariable(String name, String description, IConfigurationElement configurationElement) {
- super(name, description, configurationElement);
- }
-
-}
diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/stringsubstitution/IDynamicVariable.java b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/stringsubstitution/IDynamicVariable.java
deleted file mode 100644
index 833be9dad..000000000
--- a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/stringsubstitution/IDynamicVariable.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2003 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.debug.internal.core.stringsubstitution;
-
-import org.eclipse.core.runtime.CoreException;
-
-/**
- * A dynamic variable is a variable whose value is computed dynamically
- * by a resolver at the time a string substitution is performed. A dynamic
- * variable is contributed by an extension.
- *
- * TODO: example extension
- *
- * @since 3.0
- */
-public interface IDynamicVariable extends IStringVariable {
-
- /**
- * Returns the value of this variable when referenced with the given
- * argument, possibly null
.
- *
- * @param argument argument present in variable expression or null
- * if none
- * @return value of this variable when referenced with the given argument, possibly
- * null
- * @throws CoreException if unable to resolve a value for this variable
- */
- public String getValue(String argument) throws CoreException;
-}
diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/stringsubstitution/IDynamicVariableResolver.java b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/stringsubstitution/IDynamicVariableResolver.java
deleted file mode 100644
index f252a2916..000000000
--- a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/stringsubstitution/IDynamicVariableResolver.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2003 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.debug.internal.core.stringsubstitution;
-
-import org.eclipse.core.runtime.CoreException;
-
-/**
- * Resolves the value for a dynamic variable. A dynamic variable extension
- * contributes a resolver which must implement this interface.
- *
- * @since 3.0
- */
-public interface IDynamicVariableResolver {
-
- /**
- * Resolves and returns a value for the specified variable when referenced
- * with the given argument, possibly null
- *
- * @param variable variable to resolve a value for
- * @param argument argument present in expression or null
if none
- * @return variable value, possibly null
- * @throws CoreException if unable to resolve a value for the given variable
- */
- public String resolveValue(IDynamicVariable variable, String argument) throws CoreException;
-}
diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/stringsubstitution/IStringVariable.java b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/stringsubstitution/IStringVariable.java
deleted file mode 100644
index 3976ab485..000000000
--- a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/stringsubstitution/IStringVariable.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2003 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.debug.internal.core.stringsubstitution;
-
-
-/**
- * A variable that can be referenced in an expression, which resolves to a string
- * value. Variables are referenced in expressions via their name, in the following
- * format.
- *
- * ${varname} or ${varname:argument}
- *
- *
- *
- * IValueVariable
- variables that have a value (with getter and setter), and
- * accept no arguments. The value of this type of variable is resolved at the time
- * its value is set via its setter API.IDynamicVariable
- variables whose value is resolved at the time
- * a string substitution is performed by a contributed resolver. Dynamic variables
- * may accept an argument.
null
- *
- * @return a description of this variable, or null
if none
- */
- public String getDescription();
-
-}
diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/stringsubstitution/IStringVariableManager.java b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/stringsubstitution/IStringVariableManager.java
deleted file mode 100644
index cb5c2dcd2..000000000
--- a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/stringsubstitution/IStringVariableManager.java
+++ /dev/null
@@ -1,145 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2003 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.debug.internal.core.stringsubstitution;
-
-import org.eclipse.core.runtime.CoreException;
-
-/**
- * Regisitry for string variables.
- *
- * @since 3.0
- */
-public interface IStringVariableManager {
-
- /**
- * Returns all registered variables.
- *
- * @return a collection of all registered variables
- */
- public IStringVariable[] getVariables();
-
- /**
- * Returns all registered value variables.
- *
- * @return a collection of all registered value variables
- */
- public IValueVariable[] getValueVariables();
-
- /**
- * Returns the value variable with the given name, or null
- * if none.
- *
- * @param name variable name
- * @return the value variable with the given name, or null
- * if none
- */
- public IValueVariable getValueVariable(String name);
-
- /**
- * Returns all registered dynamic variables.
- *
- * @return a collection of all registered dynamic variables
- */
- public IDynamicVariable[] getDynamicVariables();
-
- /**
- * Returns the dynamic variable with the given name or null
- * if none.
- *
- * @param name variable name
- * @return the dynamic variable with the given name or null
- * if none
- */
- public IDynamicVariable getDynamicVariable(String name);
-
- /**
- * Recursively resolves and replaces all variable references in the given
- * expression with their corresponding values. Reports errors for references
- * to undefined variables (equivalent to calling
- * performStringSubstitution(expression, true)
).
- *
- * @param expression expression referencing variables
- * @return expression with variable references replaced with variable values
- * @throws CoreException if unable to resolve the value of one or more variables
- */
- public String performStringSubstitution(String expression) throws CoreException;
-
- /**
- * Recursively resolves and replaces all variable references in the given
- * expression with their corresponding values. Allows the client to control
- * whether references to undefeind variables are reported as an error (i.e.
- * an exception is thrown).
- *
- * @param expression expression referencing variables
- * @param reportUndefinedVariables whether a reference to an undefined variable
- * is to be considered an error (i.e. throw an exception)
- * @return expression with variable references replaced with variable values
- * @throws CoreException if unable to resolve the value of one or more variables
- */
- public String performStringSubstitution(String expression, boolean reportUndefinedVariables) throws CoreException;
-
- /**
- * Returns a new value variable with the given name and description.
- *
- * @param name variable name, cannot be null
- * @param description variable description, possibly null
- * @return a new variable
- * @exception CoreException if a variable already exists with the given name
- */
- public IValueVariable newValueVariable(String name, String description);
-
- /**
- * Adds the given variables to the variable registry.
- *
- * @param variables the variables to add
- * @throws CoreException if one or more variables to add has a name collision with
- * an existing variable
- */
- public void addVariables(IValueVariable[] variables) throws CoreException;
-
- /**
- * Removes the given variables from the registry. Has no effect for unregistered
- * variables.
- *
- * @param variables variables to remove
- */
- public void removeVariables(IValueVariable[] variables);
-
- /**
- * Registers the given listener for value variable notifications. Has no effect
- * if an identical listener is already registered.
- *
- * @param listener value variable listener to add
- */
- public void addValueVariableListener(IValueVariableListener listener);
-
- /**
- * Removes the given listener from the list of registered value variable
- * listeners. Has no effect if an identical listener is not already registered.
- *
- * @param listener value variable listener to remove
- */
- public void removeValueVariableListener(IValueVariableListener listener);
-
- /**
- * Convenience method that returns an expression referencing the given
- * variable and optional argument. For example, calling the method with
- * a varName
of my_var
and an argument
- * of my_arg
results in the string $(my_var:my_arg}
.
- *
- * @param varName variable name
- * @param arg argument text or null
- * @return an expression referencing the given variable and
- * optional argument
- */
- public String generateVariableExpression(String varName, String arg);
-
-}
diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/stringsubstitution/IValueVariable.java b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/stringsubstitution/IValueVariable.java
deleted file mode 100644
index 2d3b1b90a..000000000
--- a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/stringsubstitution/IValueVariable.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2003 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.debug.internal.core.stringsubstitution;
-
-/**
- * A variable with a value that can be set and retrieved. The context in which
- * a value variable is referenced does not effect the value of the variable.
- * A value variable can be contributed by an extension or created programmatically.
- * A contributor may optionally specify an initial value for a variable, or
- * provide a delegate that will initialie the variable with a value.
- *
- * TODO: example plug-in XML
- *
- * @since 3.0
- */
-public interface IValueVariable extends IStringVariable {
-
- /**
- * Sets the value of this variable to the given value. A value of
- * null
indicates the value of this variable is undefined.
- *
- * @param value variable value, possibly null
- */
- public void setValue(String value);
-
- /**
- * Returns the value of this variable, or null
if none.
- *
- * @return the value of this variable, or null
if none
- */
- public String getValue();
-
- /**
- * Returns whether this variable was contributed by an extension.
- *
- * @return whether this variable was contributed by an extension
- */
- public boolean isContributed();
-
- /**
- * Sets the description of this variable to the given value.
- *
- * @param description variable description, possibly null
- */
- public void setDescription(String description);
-}
diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/stringsubstitution/IValueVariableInitializer.java b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/stringsubstitution/IValueVariableInitializer.java
deleted file mode 100644
index f3e70a15e..000000000
--- a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/stringsubstitution/IValueVariableInitializer.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2003 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.debug.internal.core.stringsubstitution;
-
-/**
- * Value variable initializers compute an initial value for a value
- * variable contributed by an extension, which is not defined with an initial
- * value. This provides a mechnism for programatically computing the initial
- * value of a value variable.
- * - * Clients may implement this interface. - *
- * @since 3.0 - */ -public interface IValueVariableInitializer { - /** - * Initializes the specified variable. - * - * @param variable variable to initialize - */ - public void initialize(IValueVariable variable); -} diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/stringsubstitution/IValueVariableListener.java b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/stringsubstitution/IValueVariableListener.java deleted file mode 100644 index 1fe70a9f3..000000000 --- a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/stringsubstitution/IValueVariableListener.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.debug.internal.core.stringsubstitution; - -/** - * A string variable listener is notified of variables as they are added - * and removed from the string variable manager. As well, listeners are - * notified when a value variable changes value. - * - * since 3.0 - */ -public interface IValueVariableListener { - - /** - * Notification the given variables have been added to the variable - * manager. - * - * @param variables added variables - */ - public void variablesAdded(IValueVariable[] variables); - - /** - * Notification the given variables have been removed from the variable - * manager. - * - * @param variables removed variables - */ - public void variablesRemoved(IValueVariable[] variables); - - /** - * Notification the given variables have been changed value. - * - * @param variables changed variables - */ - public void variablesChanged(IValueVariable[] variables); - -} diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/stringsubstitution/StringSubstitutionEngine.java b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/stringsubstitution/StringSubstitutionEngine.java deleted file mode 100644 index 6c15361b5..000000000 --- a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/stringsubstitution/StringSubstitutionEngine.java +++ /dev/null @@ -1,229 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.debug.internal.core.stringsubstitution; - -import java.text.MessageFormat; -import java.util.Stack; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.debug.core.DebugPlugin; - -/** - * Performs string substitution for context and value variables. - */ -public class StringSubstitutionEngine { - - // delimiters - private static final String VARIABLE_START = "${"; //$NON-NLS-1$ - private static final char VARIABLE_END = '}'; //$NON-NLS-1$ - private static final char VARIABLE_ARG = ':'; //$NON-NLS-1$ - // parsing states - private static final int SCAN_FOR_START = 0; - private static final int SCAN_FOR_END = 1; - - /** - * Resulting string - */ - private StringBuffer fResult; - - /** - * whether substitutions were performed - */ - private boolean fSubs; - - /** - * Stack of variables to resolve - */ - private Stack fStack; - - class VariableReference { - - // the text inside the variable reference - private StringBuffer fText; - - public VariableReference() { - fText = new StringBuffer(); - } - - public void append(String text) { - fText.append(text); - } - - public String getText() { - return fText.toString(); - } - - } - - /** - * Performs recursive string substitution and returns the resulting string. - * - * @param expression expression to resolve - * @param reportUndefinedVariables whether to report undefined variables as an error - * @param manager registry of variables - * @return the resulting string with all variables recursively - * substituted - * @exception CoreException if unable to resolve a referenced variable - */ - public String performStringSubstitution(String expression, boolean reportUndefinedVariables, IStringVariableManager manager) throws CoreException { - substitute(expression, reportUndefinedVariables, manager); - while (fSubs) { - substitute(fResult.toString(), reportUndefinedVariables, manager); - } - return fResult.toString(); - } - - /** - * Makes a substitution pass of the given expression and returns - * whether any substitutions were made. - * - * @param expression source expression - * @param reportUndefinedVariables whether to report undefined variables as an error - * @exception CoreException if unable to resolve a variable - */ - private void substitute(String expression, boolean reportUndefinedVariables, IStringVariableManager manager) throws CoreException { - fResult = new StringBuffer(expression.length()); - fStack = new Stack(); - fSubs = false; - int pos = 0; - int state = SCAN_FOR_START; - while (pos < expression.length()) { - switch (state) { - case SCAN_FOR_START: - int start = expression.indexOf(VARIABLE_START, pos); - if (start >= 0) { - int length = start - pos; - // copy non-variable text to the result - if (length > 0) { - fResult.append(expression.substring(pos, start)); - } - pos = start + 2; - state = SCAN_FOR_END; - fStack.push(new VariableReference()); - } else { - // done - no more variables - fResult.append(expression.substring(pos)); - pos = expression.length(); - } - break; - case SCAN_FOR_END: - // be careful of nested variables - start = expression.indexOf(VARIABLE_START, pos); - int end = expression.indexOf(VARIABLE_END, pos); - if (end < 0) { - // variables are not completed - VariableReference tos = (VariableReference)fStack.peek(); - tos.append(expression.substring(pos)); - pos = expression.length(); - } else { - if (start >= 0 && start < end) { - // start of a nested variable - int length = start - pos; - if (length > 0) { - VariableReference tos = (VariableReference)fStack.peek(); - tos.append(expression.substring(pos, start)); - } - pos = start + 2; - fStack.push(new VariableReference()); - } else { - // end of variable reference - VariableReference tos = (VariableReference)fStack.pop(); - tos.append(expression.substring(pos, end)); - pos = end + 1; - String value = resolve(tos, reportUndefinedVariables, manager); - if (value == null) { - value = ""; //$NON-NLS-1$ - } - if (fStack.isEmpty()) { - // append to result - fResult.append(value); - state = SCAN_FOR_START; - } else { - // append to previous variable - tos = (VariableReference)fStack.peek(); - tos.append(value); - } - } - } - break; - } - } - // process incomplete variable references - while (!fStack.isEmpty()) { - VariableReference tos = (VariableReference)fStack.pop(); - if (fStack.isEmpty()) { - fResult.append(VARIABLE_START); - fResult.append(tos.getText()); - } else { - VariableReference var = (VariableReference)fStack.peek(); - var.append(VARIABLE_START); - var.append(tos.getText()); - } - } - } - - /** - * Resolve and return the value of the given variable reference, - * possiblynull
.
- *
- * @param var
- * @param reportUndefinedVariables whether to report undefined variables as
- * an error
- * @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 {
- String text = var.getText();
- int pos = text.indexOf(VARIABLE_ARG);
- String name = null;
- String arg = null;
- if (pos > 0) {
- name = text.substring(0, pos);
- pos++;
- if (pos < text.length()) {
- arg = text.substring(pos);
- }
- } else {
- name = text;
- }
- IValueVariable valueVariable = manager.getValueVariable(name);
- if (valueVariable == null) {
- IDynamicVariable dynamicVariable = manager.getDynamicVariable(name);
- if (dynamicVariable == null) {
- // no variables with the given name
- if (reportUndefinedVariables) {
- throw new CoreException(new Status(IStatus.ERROR, DebugPlugin.getUniqueIdentifier(), DebugPlugin.INTERNAL_ERROR, MessageFormat.format(StringSubstitutionMessages.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();
- }
- } else {
- fSubs = true;
- return dynamicVariable.getValue(arg);
- }
- } else {
- if (arg == null) {
- fSubs = true;
- return valueVariable.getValue();
- } else {
- // error - an argument specified for a value variable
- throw new CoreException(new Status(IStatus.ERROR, DebugPlugin.getUniqueIdentifier(), DebugPlugin.INTERNAL_ERROR, MessageFormat.format("Variable {0} does not accept arguments.", new String[]{valueVariable.getName()}), null)); //$NON-NLS-1$
- }
- }
- }
-
-}
\ No newline at end of file
diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/stringsubstitution/StringSubstitutionMessages.java b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/stringsubstitution/StringSubstitutionMessages.java
deleted file mode 100644
index fbdb91aed..000000000
--- a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/stringsubstitution/StringSubstitutionMessages.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2003 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.debug.internal.core.stringsubstitution;
-
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-
-/**
- * StringSubstitutionMessages
- */
-public class StringSubstitutionMessages {
-
- private static final String BUNDLE_NAME = "org.eclipse.debug.internal.core.stringsubstitution.StringSubstitutionMessages"; //$NON-NLS-1$
-
- private static final ResourceBundle RESOURCE_BUNDLE =
- ResourceBundle.getBundle(BUNDLE_NAME);
-
- /**
- *
- */
- private StringSubstitutionMessages() {
-
- // TODO Auto-generated constructor stub
- }
- /**
- * @param key
- * @return
- */
- public static String getString(String key) {
- // TODO Auto-generated method stub
- try {
- return RESOURCE_BUNDLE.getString(key);
- } catch (MissingResourceException e) {
- return '!' + key + '!';
- }
- }
-}
diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/stringsubstitution/StringSubstitutionMessages.properties b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/stringsubstitution/StringSubstitutionMessages.properties
deleted file mode 100644
index e812fb2b9..000000000
--- a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/stringsubstitution/StringSubstitutionMessages.properties
+++ /dev/null
@@ -1,16 +0,0 @@
-###############################################################################
-# Copyright (c) 2000, 2003 IBM Corporation and others.
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Common Public License v1.0
-# which accompanies this distribution, and is available at
-# http://www.eclipse.org/legal/cpl-v10.html
-#
-# Contributors:
-# IBM Corporation - initial API and implementation
-###############################################################################
-
-StringSubstitutionEngine.3=Reference to undefined variable {0}
-
-StringVariableManager.26=Variables with the specified names are already registered.
-StringVariableManager.27=Variable named {0} already registered
-
diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/stringsubstitution/StringVariable.java b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/stringsubstitution/StringVariable.java
deleted file mode 100644
index be929f00d..000000000
--- a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/stringsubstitution/StringVariable.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2003 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.debug.internal.core.stringsubstitution;
-
-import org.eclipse.core.runtime.IConfigurationElement;
-
-/**
- * Common implementation of context and value variables
- */
-public abstract class StringVariable implements IStringVariable {
-
- /**
- * Variable name
- */
- private String fName;
-
- /**
- * Variable description, or null
- */
- private String fDescription;
-
- /**
- * Configuration element associated with this variable, or null
- */
- private IConfigurationElement fConfigurationElement;
-
- /**
- * Constructs a new variable with the given name and description.
- *
- * @param name variable name
- * @param description variable description, or null
- */
- public StringVariable(String name, String description, IConfigurationElement configurationElement) {
- fName = name;
- fDescription = description;
- fConfigurationElement = configurationElement;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.debug.internal.core.stringsubstitution.IStringVariable#getName()
- */
- public String getName() {
- return fName;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.debug.internal.core.stringsubstitution.IStringVariable#getDescription()
- */
- public String getDescription() {
- return fDescription;
- }
-
- /**
- * Returns the configuration element associated with this variable, or null
- * if none.
- *
- * @return configuration element or null
- */
- protected IConfigurationElement getConfigurationElement() {
- return fConfigurationElement;
- }
-
- /**
- * @see IValueVariable#setDescription(String)
- * @param description
- */
- public void setDescription(String description) {
- fDescription = description;
- }
-
-}
diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/stringsubstitution/StringVariableManager.java b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/stringsubstitution/StringVariableManager.java
deleted file mode 100644
index e80cf3b55..000000000
--- a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/stringsubstitution/StringVariableManager.java
+++ /dev/null
@@ -1,552 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2003 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.debug.internal.core.stringsubstitution;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.text.MessageFormat;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IExtensionPoint;
-import org.eclipse.core.runtime.ISafeRunnable;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.MultiStatus;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.Preferences;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.debug.core.DebugPlugin;
-import org.eclipse.debug.internal.core.ListenerList;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-/**
- * Singleton string variable manager.
- */
-public class StringVariableManager implements IStringVariableManager {
-
- /**
- * Dynamic variables - maps variable names to variables.
- */
- private Map fDynamicVariables;
-
- /**
- * Value variables - maps variable names to variables.
- */
- private Map fValueVariables;
-
- /**
- * Variable listeners
- */
- private ListenerList fListeners;
-
- // notifications
- private static final int ADDED = 0;
- private static final int CHANGED = 1;
- private static final int REMOVED = 2;
-
- /**
- * Singleton variable manager.
- */
- private static StringVariableManager fgManager;
-
- /**
- * Simple identifier constant (value "dynamicVariables"
) for the
- * context variables extension point.
- *
- * @since 3.0
- * TODO: this should be public API
- */
- public static final String EXTENSION_POINT_DYNAMIC_VARIABLES = "dynamicVariables"; //$NON-NLS-1$
-
- /**
- * Simple identifier constant (value "valueVariables"
) for the
- * value variables extension point.
- *
- * @since 3.0
- * TODO: this should be public API
- */
- public static final String EXTENSION_POINT_VALUE_VARIABLES = "valueVariables"; //$NON-NLS-1$
-
- // true during initialization code - supress change notification
- private boolean fInitializing = false;
-
- // Variable extension point constants
- private static final String ATTR_NAME= "name"; //$NON-NLS-1$
- private static final String ATTR_DESCRIPTION="description"; //$NON-NLS-1$
- // Persisted variable XML constants
- private static final String VALUE_VARIABLES_TAG= "valueVariables"; //$NON-NLS-1$
- private static final String VALUE_VARIABLE_TAG= "valueVariable"; //$NON-NLS-1$
- private static final String NAME_TAG= "name"; //$NON-NLS-1$
- private static final String VALUE_TAG= "value"; //$NON-NLS-1$
- private static final String DESCRIPTION_TAG="description"; //$NON-NLS-1$
- private static final String INITIALIZED_TAG="contributed"; //$NON-NLS-1$
- // XML values
- private static final String TRUE_VALUE= "true"; //$NON-NLS-1$
- private static final String FALSE_VALUE= "false"; //$NON-NLS-1$
- // preference store key for value variables
- private static final String PREF_VALUE_VARIABLES= DebugPlugin.getUniqueIdentifier() + ".valueVariables"; //$NON-NLS-1$
-
- /**
- * Notifies a string variable listener in a safe runnable to handle
- * exceptions.
- */
- class StringVariableNotifier implements ISafeRunnable {
-
- private IValueVariableListener fListener;
- private int fType;
- private IValueVariable[] fVariables;
-
- /**
- * @see org.eclipse.core.runtime.ISafeRunnable#handleException(java.lang.Throwable)
- */
- public void handleException(Throwable exception) {
- IStatus status = new Status(IStatus.ERROR, DebugPlugin.getUniqueIdentifier(), DebugPlugin.INTERNAL_ERROR, "An exception occurred during string variable change notification", exception); //$NON-NLS-1$
- DebugPlugin.log(status);
- }
-
- /**
- * @see org.eclipse.core.runtime.ISafeRunnable#run()
- */
- public void run() throws Exception {
- switch (fType) {
- case ADDED:
- fListener.variablesAdded(fVariables);
- break;
- case REMOVED:
- fListener.variablesRemoved(fVariables);
- break;
- case CHANGED:
- fListener.variablesChanged(fVariables);
- break;
- }
- }
-
- /**
- * Notifies the given listener of the add/change/remove
- *
- * @param listener the listener to notify
- * @param launch the launch that has changed
- * @param update the type of change
- */
- public void notify(IValueVariable[] variables, int update) {
- fVariables = variables;
- fType = update;
- Object[] copiedListeners= fListeners.getListeners();
- for (int i= 0; i < copiedListeners.length; i++) {
- fListener = (IValueVariableListener)copiedListeners[i];
- Platform.run(this);
- }
- fVariables = null;
- fListener = null;
- // persist variables whenever there is an add/change/remove
- storeValueVariables();
- }
- }
-
- /**
- * Returns a new notifier.
- *
- * @return a new notifier
- */
- private StringVariableNotifier getNotifier() {
- return new StringVariableNotifier();
- }
-
- /**
- * Returns the default string variable manager
- *
- * @return string variable manager
- */
- public static StringVariableManager getDefault() {
- if (fgManager == null) {
- fgManager = new StringVariableManager();
- }
- return fgManager;
- }
-
- /**
- * Constructs a new string variable manager.
- */
- private StringVariableManager() {
- fListeners = new ListenerList(5);
- }
-
- /**
- * Load contributed variables and persisted variables
- */
- private void initialize() {
- if (fDynamicVariables == null) {
- fInitializing = true;
- fDynamicVariables = new HashMap(5);
- fValueVariables = new HashMap(5);
- loadPersistedValueVariables();
- loadContributedValueVariables();
- loadDynamicVariables();
- fInitializing = false;
- }
- }
-
- /**
- * Loads contributed dynamic variables
- */
- private void loadDynamicVariables() {
- IExtensionPoint point= DebugPlugin.getDefault().getDescriptor().getExtensionPoint(EXTENSION_POINT_DYNAMIC_VARIABLES);
- IConfigurationElement elements[]= point.getConfigurationElements();
- for (int i = 0; i < elements.length; i++) {
- IConfigurationElement element = elements[i];
- String name= element.getAttribute(ATTR_NAME);
- if (name == null) {
- DebugPlugin.logMessage(MessageFormat.format("Variable extension missing required 'name' attribute: {0}", new String[] {element.getDeclaringExtension().getLabel()}), null); //$NON-NLS-1$
- continue;
- }
- String description= element.getAttribute(ATTR_DESCRIPTION);
- DynamicVariable variable= new DynamicVariable(name, description, element);
- fDynamicVariables.put(variable.getName(), variable);
- }
- }
-
- /**
- * Loads any persisted value variables from the preference store.
- */
- private void loadPersistedValueVariables() {
- String variablesString= DebugPlugin.getDefault().getPluginPreferences().getString(PREF_VALUE_VARIABLES);
- if (variablesString.length() == 0) {
- return;
- }
- Element root= null;
- try {
- ByteArrayInputStream stream= new ByteArrayInputStream(variablesString.getBytes("UTF-8")); //$NON-NLS-1$
- DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
- root = parser.parse(stream).getDocumentElement();
- } catch (Throwable throwable) {
- DebugPlugin.logMessage("An exception occurred while loading persisted value variables.", throwable); //$NON-NLS-1$
- return;
- }
- if (!root.getNodeName().equals(VALUE_VARIABLES_TAG)) {
- DebugPlugin.logMessage("Invalid format encountered while loading persisted value variables.", null); //$NON-NLS-1$
- return;
- }
- NodeList list= root.getChildNodes();
- for (int i= 0, numItems= list.getLength(); i < numItems; i++) {
- Node node= list.item(i);
- if (node.getNodeType() == Node.ELEMENT_NODE) {
- Element element= (Element) node;
- if (!element.getNodeName().equals(VALUE_VARIABLE_TAG)) {
- DebugPlugin.logMessage(MessageFormat.format("Invalid XML element encountered while loading value variables: {0}", new String[] {node.getNodeName()}), null); //$NON-NLS-1$
- continue;
- }
- String name= element.getAttribute(NAME_TAG);
- if (name.length() > 0) {
- String value= element.getAttribute(VALUE_TAG);
- String description= element.getAttribute(DESCRIPTION_TAG);
- boolean initialized= TRUE_VALUE.equals(element.getAttribute(INITIALIZED_TAG));
- ValueVariable variable= new ValueVariable(name, description, null);
- if (initialized) {
- variable.setValue(value);
- }
- fValueVariables.put(name, variable);
- } else {
- DebugPlugin.logMessage("Invalid variable entry encountered while loading value variables. Variable name is null.", null); //$NON-NLS-1$
- }
- }
- }
- }
-
- /**
- * Loads contributed value variables. This is done after the persisted value
- * variables are restored. Any contributed variables with the same name are
- * merged with existing persisted values.
- */
- private void loadContributedValueVariables() {
- IExtensionPoint point= DebugPlugin.getDefault().getDescriptor().getExtensionPoint(EXTENSION_POINT_VALUE_VARIABLES);
- IConfigurationElement elements[]= point.getConfigurationElements();
- for (int i = 0; i < elements.length; i++) {
- IConfigurationElement element = elements[i];
- String name= element.getAttribute(ATTR_NAME);
- if (name == null) {
- DebugPlugin.logMessage(MessageFormat.format("Variable extension missing required 'name' attribute: {0}", new String[] {element.getDeclaringExtension().getLabel()}), null); //$NON-NLS-1$
- continue;
- }
- String description= element.getAttribute(ATTR_DESCRIPTION);
- ValueVariable variable= new ValueVariable(name, description, element);
- // if already present, merge with persisted value
- ValueVariable existing = (ValueVariable)getValueVariable(name);
- if (existing != null) {
- if (existing.isInitialized()) {
- variable.setValue(existing.getValue());
- }
- }
- fValueVariables.put(variable.getName(), variable);
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.debug.internal.core.stringsubstitution.IStringVariableManager#getVariables()
- */
- public IStringVariable[] getVariables() {
- initialize();
- List list = new ArrayList(fDynamicVariables.size() + fValueVariables.size());
- list.addAll(fDynamicVariables.values());
- list.addAll(fValueVariables.values());
- return (IStringVariable[]) list.toArray(new IStringVariable[list.size()]);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.debug.internal.core.stringsubstitution.IStringVariableManager#getValueVariables()
- */
- public IValueVariable[] getValueVariables() {
- initialize();
- return (IValueVariable[]) fValueVariables.values().toArray(new IValueVariable[fValueVariables.size()]);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.debug.internal.core.stringsubstitution.IStringVariableManager#getDynamicVariables()
- */
- public IDynamicVariable[] getDynamicVariables() {
- initialize();
- return (IDynamicVariable[]) fDynamicVariables.values().toArray(new IDynamicVariable[fDynamicVariables.size()]);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.debug.internal.core.stringsubstitution.IStringVariableManager#performStringSubstitution(java.lang.String)
- */
- public String performStringSubstitution(String expression) throws CoreException {
- return performStringSubstitution(expression, true);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.debug.internal.core.stringsubstitution.IStringVariableManager#newValueVariable(java.lang.String, java.lang.String)
- */
- public IValueVariable newValueVariable(String name, String description) {
- IConfigurationElement element = null;
- ValueVariable existing = (ValueVariable)getValueVariable(name);
- if (existing != null && existing.isContributed()) {
- element = existing.getConfigurationElement();
- }
- return new ValueVariable(name, description, element);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.debug.internal.core.stringsubstitution.IStringVariableManager#addVariables(org.eclipse.debug.internal.core.stringsubstitution.IValueVariable[])
- */
- public void addVariables(IValueVariable[] variables) throws CoreException {
- initialize();
- MultiStatus status = new MultiStatus(DebugPlugin.getUniqueIdentifier(), DebugPlugin.INTERNAL_ERROR, StringSubstitutionMessages.getString("StringVariableManager.26"), null); //$NON-NLS-1$
- for (int i = 0; i < variables.length; i++) {
- IValueVariable variable = variables[i];
- if (getValueVariable(variable.getName()) != null) {
- status.add(new Status(IStatus.ERROR, DebugPlugin.getUniqueIdentifier(), DebugPlugin.INTERNAL_ERROR, MessageFormat.format(StringSubstitutionMessages.getString("StringVariableManager.27"), new String[]{variable.getName()}), null)); //$NON-NLS-1$
- }
- }
- if (status.isOK()) {
- for (int i = 0; i < variables.length; i++) {
- IValueVariable variable = variables[i];
- fValueVariables.put(variable.getName(), variable);
- }
- IValueVariable[] copy = new IValueVariable[variables.length];
- System.arraycopy(variables, 0, copy, 0, variables.length);
- getNotifier().notify(copy, ADDED);
- return;
- }
- throw new CoreException(status);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.debug.internal.core.stringsubstitution.IStringVariableManager#removeVariables(org.eclipse.debug.internal.core.stringsubstitution.IValueVariable[])
- */
- public void removeVariables(IValueVariable[] variables) {
- initialize();
- List removed = new ArrayList(variables.length);
- for (int i = 0; i < variables.length; i++) {
- IValueVariable variable = variables[i];
- if (fValueVariables.remove(variable.getName()) != null) {
- removed.add(variable);
- }
- }
- if (removed.size() > 0) {
- getNotifier().notify((IValueVariable[])removed.toArray(new IValueVariable[removed.size()]), REMOVED);
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.debug.internal.core.stringsubstitution.IStringVariableManager#getDynamicVariable(java.lang.String)
- */
- public IDynamicVariable getDynamicVariable(String name) {
- initialize();
- return (IDynamicVariable) fDynamicVariables.get(name);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.debug.internal.core.stringsubstitution.IStringVariableManager#getValueVariable(java.lang.String)
- */
- public IValueVariable getValueVariable(String name) {
- initialize();
- return (IValueVariable) fValueVariables.get(name);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.debug.internal.core.stringsubstitution.IStringVariableManager#addValueVariableListener(org.eclipse.debug.internal.core.stringsubstitution.IValueVariableListener)
- */
- public void addValueVariableListener(IValueVariableListener listener) {
- fListeners.add(listener);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.debug.internal.core.stringsubstitution.IStringVariableManager#removeValueVariableListener(org.eclipse.debug.internal.core.stringsubstitution.IValueVariableListener)
- */
- public void removeValueVariableListener(IValueVariableListener listener) {
- fListeners.remove(listener);
- }
-
- /**
- * Returns a memento representing the value variables currently registered.
- *
- * @return memento representing the value variables currently registered
- * @throws IOException if an I/O exception occurs while creating the XML.
- * @throws ParserConfigurationException if an exception occurs while creating the XML document.
- * @throws TransformerException if an exception occurs while serializing the XML document.
- */
- private String getValueVariablesAsXML() throws IOException, ParserConfigurationException, TransformerException {
- IValueVariable[] variables = getValueVariables();
-
- Document document= getDocument();
- Element rootElement= document.createElement(VALUE_VARIABLES_TAG);
- document.appendChild(rootElement);
- for (int i = 0; i < variables.length; i++) {
- ValueVariable variable = (ValueVariable)variables[i];
- Element element= document.createElement(VALUE_VARIABLE_TAG);
- element.setAttribute(NAME_TAG, variable.getName());
- String value= variable.getValue();
- if (value != null) {
- element.setAttribute(VALUE_TAG, value);
- }
- String description= variable.getDescription();
- if (description != null) {
- element.setAttribute(DESCRIPTION_TAG, description);
- }
- element.setAttribute(INITIALIZED_TAG, variable.isInitialized() ? TRUE_VALUE : FALSE_VALUE);
- rootElement.appendChild(element);
- }
- return serializeDocument(document);
- }
-
- private Document getDocument() throws ParserConfigurationException {
- DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
- DocumentBuilder docBuilder = dfactory.newDocumentBuilder();
- Document doc =docBuilder.newDocument();
- return doc;
- }
-
- /**
- * Serializes a XML document into a string - encoded in UTF8 format,
- * with platform line separators.
- *
- * @param doc document to serialize
- * @return the document as a string
- * @throws TransformerException if an unrecoverable error occurs during the serialization
- * @throws IOException if the encoding attempted to be used is not supported
- */
- private String serializeDocument(Document doc) throws TransformerException, UnsupportedEncodingException {
- ByteArrayOutputStream s= new ByteArrayOutputStream();
-
- TransformerFactory factory= TransformerFactory.newInstance();
- Transformer transformer= factory.newTransformer();
- transformer.setOutputProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$
- transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$
-
- DOMSource source= new DOMSource(doc);
- StreamResult outputTarget= new StreamResult(s);
- transformer.transform(source, outputTarget);
-
- return s.toString("UTF8"); //$NON-NLS-1$
- }
-
- /**
- * Saves the value variables currently registered in the
- * preference store.
- */
- private void storeValueVariables() {
- Preferences prefs= DebugPlugin.getDefault().getPluginPreferences();
- String variableString= ""; //$NON-NLS-1$
- if (!fValueVariables.isEmpty()) {
- try {
- variableString= getValueVariablesAsXML();
- } catch (IOException e) {
- DebugPlugin.log(new Status(IStatus.ERROR, DebugPlugin.getUniqueIdentifier(), IStatus.ERROR, "An exception occurred while storing launch configuration variables.", e)); //$NON-NLS-1$
- return;
- } catch (ParserConfigurationException e) {
- DebugPlugin.log(new Status(IStatus.ERROR, DebugPlugin.getUniqueIdentifier(), IStatus.ERROR, "An exception occurred while storing launch configuration variables.", e)); //$NON-NLS-1$
- return;
- } catch (TransformerException e) {
- DebugPlugin.log(new Status(IStatus.ERROR, DebugPlugin.getUniqueIdentifier(), IStatus.ERROR, "An exception occurred while storing launch configuration variables.", e)); //$NON-NLS-1$
- return;
- }
- }
- prefs.setValue(PREF_VALUE_VARIABLES, variableString);
- DebugPlugin.getDefault().savePluginPreferences();
- }
-
- /**
- * Fire a change notification for the given variable.
- *
- * @param variable the variable that has changed
- */
- protected void notifyChanged(ValueVariable variable) {
- if (!fInitializing) {
- IValueVariable existing = getValueVariable(variable.getName());
- if (variable.equals(existing)) {
- // do not do change notification for unregistered variables
- getNotifier().notify(new IValueVariable[]{variable}, CHANGED);
- }
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.debug.internal.core.stringsubstitution.IStringVariableManager#generateVariableExpression(java.lang.String, java.lang.String)
- */
- public String generateVariableExpression(String varName, String arg) {
- StringBuffer buffer = new StringBuffer();
- buffer.append("${"); //$NON-NLS-1$
- buffer.append(varName);
- if (arg != null) {
- buffer.append(":"); //$NON-NLS-1$
- buffer.append(arg);
- }
- 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);
- }
-
-}
diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/stringsubstitution/ValueVariable.java b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/stringsubstitution/ValueVariable.java
deleted file mode 100644
index 322ef45d1..000000000
--- a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/stringsubstitution/ValueVariable.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2003 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.debug.internal.core.stringsubstitution;
-
-import java.text.MessageFormat;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.debug.core.DebugPlugin;
-
-/**
- * Implementation of a value variable.
- */
-public class ValueVariable extends StringVariable implements IValueVariable {
-
- /**
- * Variable value or null
if none
- */
- private String fValue;
-
- /**
- * Whether this variable's value has been initialized
- */
- private boolean fInitialized = false;
-
- /**
- * Constructs a new value variable with the given name, description, and
- * associated configuration element.
- *
- * @param name variable name
- * @param description variable description, or null
- * @param configurationElement configuration element or null
- */
- public ValueVariable(String name, String description, IConfigurationElement configurationElement) {
- super(name, description, configurationElement);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.debug.internal.core.stringsubstitution.IValueVariable#setValue(java.lang.String)
- */
- public void setValue(String value) {
- fValue = value;
- setInitialized(true);
- StringVariableManager.getDefault().notifyChanged(this);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.debug.internal.core.stringsubstitution.IValueVariable#getValue()
- */
- public String getValue() {
- if (!isInitialized()) {
- initialize();
- }
- return fValue;
- }
-
- /**
- * Initialize this variable's value.
- */
- private void initialize() {
- if (getConfigurationElement() != null) {
- // check for a explicit value specified in plug-in XML
- String value = getConfigurationElement().getAttribute("initialValue"); //$NON-NLS-1$
- if (value == null) {
- // check for initializer
- String className = getConfigurationElement().getAttribute("initializerClass"); //$NON-NLS-1$
- if (className != null) {
- try {
- Object object = getConfigurationElement().createExecutableExtension("initializerClass"); //$NON-NLS-1$
- if (object instanceof IValueVariableInitializer) {
- IValueVariableInitializer initializer = (IValueVariableInitializer)object;
- initializer.initialize(this);
- } else {
- DebugPlugin.logMessage(MessageFormat.format("Unable to initialize variable {0} - initializer must be an instance of IValueVariableInitializer.", new String[]{getName()}), null); //$NON-NLS-1$
- }
- } catch (CoreException e) {
- DebugPlugin.logMessage(MessageFormat.format("Unable to initialize variable {0}",new String[]{getName()}), e); //$NON-NLS-1$
- }
- }
- } else {
- setValue(value);
- }
- }
- setInitialized(true);
- }
-
- /**
- * Returns whether this variable has been initialized with a value by one of:
- * setValue(String)
initialValue
attribute