Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuc Bourlier2003-10-21 17:44:09 +0000
committerLuc Bourlier2003-10-21 17:44:09 +0000
commitab911fcde82fd45bcc39ac272c5fbda9a69be5fe (patch)
tree444a44edec1192562892a855816e7ade4d7dd83b /org.eclipse.core.variables/src/org/eclipse/core/variables
parent459e7a37e00d381973d431e7b1db2a8051e1dcfd (diff)
downloadeclipse.platform.debug-ab911fcde82fd45bcc39ac272c5fbda9a69be5fe.tar.gz
eclipse.platform.debug-ab911fcde82fd45bcc39ac272c5fbda9a69be5fe.tar.xz
eclipse.platform.debug-ab911fcde82fd45bcc39ac272c5fbda9a69be5fe.zip
Bug 43332 - String Substitution Support - org.eclipse.core.variables
Diffstat (limited to 'org.eclipse.core.variables/src/org/eclipse/core/variables')
-rw-r--r--org.eclipse.core.variables/src/org/eclipse/core/variables/IDynamicVariable.java37
-rw-r--r--org.eclipse.core.variables/src/org/eclipse/core/variables/IDynamicVariableResolver.java33
-rw-r--r--org.eclipse.core.variables/src/org/eclipse/core/variables/IStringVariable.java56
-rw-r--r--org.eclipse.core.variables/src/org/eclipse/core/variables/IStringVariableManager.java157
-rw-r--r--org.eclipse.core.variables/src/org/eclipse/core/variables/IValueVariable.java54
-rw-r--r--org.eclipse.core.variables/src/org/eclipse/core/variables/IValueVariableInitializer.java30
-rw-r--r--org.eclipse.core.variables/src/org/eclipse/core/variables/IValueVariableListener.java45
-rw-r--r--org.eclipse.core.variables/src/org/eclipse/core/variables/VariablesPlugin.java33
8 files changed, 444 insertions, 1 deletions
diff --git a/org.eclipse.core.variables/src/org/eclipse/core/variables/IDynamicVariable.java b/org.eclipse.core.variables/src/org/eclipse/core/variables/IDynamicVariable.java
new file mode 100644
index 000000000..4e6789a8d
--- /dev/null
+++ b/org.eclipse.core.variables/src/org/eclipse/core/variables/IDynamicVariable.java
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * 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.core.variables;
+
+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 <code>null</code>.
+ *
+ * @param argument argument present in variable expression or <code>null</code>
+ * if none
+ * @return value of this variable when referenced with the given argument, possibly
+ * <code>null</code>
+ * @throws CoreException if unable to resolve a value for this variable
+ */
+ public String getValue(String argument) throws CoreException;
+}
diff --git a/org.eclipse.core.variables/src/org/eclipse/core/variables/IDynamicVariableResolver.java b/org.eclipse.core.variables/src/org/eclipse/core/variables/IDynamicVariableResolver.java
new file mode 100644
index 000000000..6187525d2
--- /dev/null
+++ b/org.eclipse.core.variables/src/org/eclipse/core/variables/IDynamicVariableResolver.java
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * 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.core.variables;
+
+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 <code>null</code>
+ *
+ * @param variable variable to resolve a value for
+ * @param argument argument present in expression or <code>null</code> if none
+ * @return variable value, possibly <code>null</code>
+ * @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.core.variables/src/org/eclipse/core/variables/IStringVariable.java b/org.eclipse.core.variables/src/org/eclipse/core/variables/IStringVariable.java
new file mode 100644
index 000000000..69bab0a3b
--- /dev/null
+++ b/org.eclipse.core.variables/src/org/eclipse/core/variables/IStringVariable.java
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * 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.core.variables;
+
+
+/**
+ * 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.
+ * <pre>
+ * ${varname} or ${varname:argument}
+ * </pre>
+ * <p>
+ * 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.
+ * </p>
+ * <p>
+ * Variables can be contributed by extensions or programmatically. There are two
+ * kinds of variables.
+ * <ul>
+ * <li><code>IValueVariable</code> - 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.</li>
+ * <li><code>IDynamicVariable</code> - variables whose value is resolved at the time
+ * a string substitution is performed by a contributed resolver. Dynamic variables
+ * may accept an argument.</li>
+ * </ul>
+ * </p>
+ * @since 3.0
+ */
+public interface IStringVariable {
+
+ /**
+ * Returns the name of this variable. A variable is uniquely identified by
+ * its name.
+ *
+ * @return variable name
+ */
+ public String getName();
+
+ /**
+ * Returns a human readable description of this variable, possibly <code>null</code>
+ *
+ * @return a description of this variable, or <code>null</code> if none
+ */
+ public String getDescription();
+
+}
diff --git a/org.eclipse.core.variables/src/org/eclipse/core/variables/IStringVariableManager.java b/org.eclipse.core.variables/src/org/eclipse/core/variables/IStringVariableManager.java
new file mode 100644
index 000000000..06d2b33f8
--- /dev/null
+++ b/org.eclipse.core.variables/src/org/eclipse/core/variables/IStringVariableManager.java
@@ -0,0 +1,157 @@
+/*******************************************************************************
+ * 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.core.variables;
+
+import org.eclipse.core.runtime.CoreException;
+
+/**
+ * Regisitry for string variables.
+ *
+ * @since 3.0
+ */
+public interface IStringVariableManager {
+
+ /**
+ * Simple identifier constant (value <code>"dynamicVariables"</code>) for the
+ * context variables extension point.
+ */
+ public static final String EXTENSION_POINT_DYNAMIC_VARIABLES = "dynamicVariables"; //$NON-NLS-1$
+
+ /**
+ * Simple identifier constant (value <code>"valueVariables"</code>) for the
+ * value variables extension point.
+ */
+ public static final String EXTENSION_POINT_VALUE_VARIABLES = "valueVariables"; //$NON-NLS-1$
+
+ /**
+ * 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 <code>null</code>
+ * if none.
+ *
+ * @param name variable name
+ * @return the value variable with the given name, or <code>null</code>
+ * 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 <code>null</code>
+ * if none.
+ *
+ * @param name variable name
+ * @return the dynamic variable with the given name or <code>null</code>
+ * 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
+ * <code>performStringSubstitution(expression, true)</code>).
+ *
+ * @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 <code>null</code>
+ * @param description variable description, possibly <code>null</code>
+ * @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 <code>varName</code> of <code>my_var</code> and an <code>argument</code>
+ * of <code>my_arg</code> results in the string <code>$(my_var:my_arg}</code>.
+ *
+ * @param varName variable name
+ * @param arg argument text or <code>null</code>
+ * @return an expression referencing the given variable and
+ * optional argument
+ */
+ public String generateVariableExpression(String varName, String arg);
+
+}
diff --git a/org.eclipse.core.variables/src/org/eclipse/core/variables/IValueVariable.java b/org.eclipse.core.variables/src/org/eclipse/core/variables/IValueVariable.java
new file mode 100644
index 000000000..9ffed0fed
--- /dev/null
+++ b/org.eclipse.core.variables/src/org/eclipse/core/variables/IValueVariable.java
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * 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.core.variables;
+
+/**
+ * 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
+ * <code>null</code> indicates the value of this variable is undefined.
+ *
+ * @param value variable value, possibly <code>null</code>
+ */
+ public void setValue(String value);
+
+ /**
+ * Returns the value of this variable, or <code>null</code> if none.
+ *
+ * @return the value of this variable, or <code>null</code> 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 <code>null</code>
+ */
+ public void setDescription(String description);
+}
diff --git a/org.eclipse.core.variables/src/org/eclipse/core/variables/IValueVariableInitializer.java b/org.eclipse.core.variables/src/org/eclipse/core/variables/IValueVariableInitializer.java
new file mode 100644
index 000000000..16cc8feb6
--- /dev/null
+++ b/org.eclipse.core.variables/src/org/eclipse/core/variables/IValueVariableInitializer.java
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * 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.core.variables;
+
+/**
+ * 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.
+ * <p>
+ * Clients may implement this interface.
+ * </p>
+ * @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.core.variables/src/org/eclipse/core/variables/IValueVariableListener.java b/org.eclipse.core.variables/src/org/eclipse/core/variables/IValueVariableListener.java
new file mode 100644
index 000000000..10a26f82e
--- /dev/null
+++ b/org.eclipse.core.variables/src/org/eclipse/core/variables/IValueVariableListener.java
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * 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.core.variables;
+
+/**
+ * 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.core.variables/src/org/eclipse/core/variables/VariablesPlugin.java b/org.eclipse.core.variables/src/org/eclipse/core/variables/VariablesPlugin.java
index 1d9dbec32..049764787 100644
--- a/org.eclipse.core.variables/src/org/eclipse/core/variables/VariablesPlugin.java
+++ b/org.eclipse.core.variables/src/org/eclipse/core/variables/VariablesPlugin.java
@@ -11,6 +11,7 @@
package org.eclipse.core.variables;
+import org.eclipse.core.internal.variables.StringVariableManager;
import org.eclipse.core.runtime.IPluginDescriptor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Plugin;
@@ -70,7 +71,26 @@ public class VariablesPlugin extends Plugin {
* @param t throwable to log
*/
public static void log(Throwable t) {
- IStatus status= new Status(IStatus.ERROR, PI_CORE_VARIABLES, INTERNAL_ERROR, "Error logged from Core Variables: ", t); //$NON-NLS-1$
+ log(new Status(IStatus.ERROR, PI_CORE_VARIABLES, INTERNAL_ERROR, "Error logged from Core Variables: ", t)); //$NON-NLS-1$
+ }
+
+ /**
+ * Logs the given message with this plug-in's log and the given
+ * throwable or <code>null</code> if none.
+ * @param message the message to log
+ * @param throwable the exception that occurred or <code>null</code> if none
+ */
+ public static void logMessage(String message, Throwable throwable) {
+ log(new Status(IStatus.ERROR, getUniqueIdentifier(), INTERNAL_ERROR, message, throwable));
+ }
+
+ /**
+ * Logs the specified status with this plug-in's log.
+ *
+ * @param status status to log
+ * @since 2.0
+ */
+ public static void log(IStatus status) {
getDefault().getLog().log(status);
}
@@ -86,4 +106,15 @@ public class VariablesPlugin extends Plugin {
}
return getDefault().getDescriptor().getUniqueIdentifier();
}
+
+ /**
+ * Returns the string variable manager.
+ *
+ * @return the string variable manager
+ * @since 3.0
+ */
+ public IStringVariableManager getStringVariableManager() {
+ return StringVariableManager.getDefault();
+ }
+
}

Back to the top