Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre-Charles David2019-01-22 15:59:53 +0000
committerPierre-Charles David2019-02-08 13:37:39 +0000
commit7ece7ecc9d2f3f65b0844d928ab33705bd452620 (patch)
tree2bc778629e9574b7fdba24d1385f3977fb453927
parentaf40943ff46dfdf754f0454a34e0c34920d2b65e (diff)
downloadorg.eclipse.sirius-7ece7ecc9d2f3f65b0844d928ab33705bd452620.tar.gz
org.eclipse.sirius-7ece7ecc9d2f3f65b0844d928ab33705bd452620.tar.xz
org.eclipse.sirius-7ece7ecc9d2f3f65b0844d928ab33705bd452620.zip
[542859] Enrich IEvaluationResult and add default implementation
Bug: 542859 Change-Id: I279c8b1b21f33bfe8b448a1e0616451ad682ce9b Signed-off-by: Pierre-Charles David <pierre-charles.david@obeo.fr>
-rw-r--r--plugins/org.eclipse.sirius.common.acceleo.aql/src/org/eclipse/sirius/common/acceleo/aql/business/internal/AQLSiriusInterpreter.java32
-rw-r--r--plugins/org.eclipse.sirius.common/plugin.properties3
-rw-r--r--plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/Messages.java3
-rw-r--r--plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/interpreter/EvaluationResult.java217
-rw-r--r--plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/interpreter/IEvaluationResult.java61
-rw-r--r--plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/interpreter/IInterpreter.java16
-rw-r--r--plugins/org.eclipse.sirius.doc/doc/Release_Notes.html6
-rw-r--r--plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile3
-rw-r--r--plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/internal/interpreter/SessionInterpreter.java23
9 files changed, 306 insertions, 58 deletions
diff --git a/plugins/org.eclipse.sirius.common.acceleo.aql/src/org/eclipse/sirius/common/acceleo/aql/business/internal/AQLSiriusInterpreter.java b/plugins/org.eclipse.sirius.common.acceleo.aql/src/org/eclipse/sirius/common/acceleo/aql/business/internal/AQLSiriusInterpreter.java
index 753b8f63eb..8877ff4351 100644
--- a/plugins/org.eclipse.sirius.common.acceleo.aql/src/org/eclipse/sirius/common/acceleo/aql/business/internal/AQLSiriusInterpreter.java
+++ b/plugins/org.eclipse.sirius.common.acceleo.aql/src/org/eclipse/sirius/common/acceleo/aql/business/internal/AQLSiriusInterpreter.java
@@ -225,27 +225,25 @@ public class AQLSiriusInterpreter extends AcceleoAbstractInterpreter implements
diagnostic.merge(evalResult.getDiagnostic());
}
- return new IEvaluationResult() {
-
- @Override
- public Object getValue() {
- return evalResult.getResult();
- }
-
- @Override
- public Diagnostic getDiagnostic() {
- List<Diagnostic> children = diagnostic.getChildren();
- if (children.size() == 1) {
- return children.get(0);
- } else {
- return diagnostic;
- }
- }
- };
+ Diagnostic diag = minimize(diagnostic);
+ if (diag.getSeverity() >= Diagnostic.ERROR) {
+ return org.eclipse.sirius.common.tools.api.interpreter.EvaluationResult.ofError(diag);
+ } else {
+ return org.eclipse.sirius.common.tools.api.interpreter.EvaluationResult.ofValue(evalResult.getResult(), getConverter(), diag);
+ }
} catch (ExecutionException e) {
throw new EvaluationException(e.getCause());
}
}
+
+ private Diagnostic minimize(Diagnostic diag) {
+ List<Diagnostic> children = diag.getChildren();
+ if (children.size() == 1) {
+ return children.get(0);
+ } else {
+ return diag;
+ }
+ }
@Override
public String getVariablePrefix() {
diff --git a/plugins/org.eclipse.sirius.common/plugin.properties b/plugins/org.eclipse.sirius.common/plugin.properties
index 22b08a8d80..bd1ccdd838 100644
--- a/plugins/org.eclipse.sirius.common/plugin.properties
+++ b/plugins/org.eclipse.sirius.common/plugin.properties
@@ -59,6 +59,7 @@ ResourceSetFactory_ignoredOverrides = Several overrides are contributed for the
ResourceSyncClientNotifier_actionName = ResourceSyncClient notification
ResourceUtil_backupFileAlreadyExists = the file already exists
ResourceUtil_backupFileTask = Backup and refresh workspace
+Interpreter_evaluationError = Error while evaluating expression
ServiceInterpreter_invalidReceiver = The receiver of the service call {0} is not an EObject (it is a {1})
ServiceInterpreter_javaClassNotFound = Could not find Java extension class {0}
ServiceInterpreter_unknownService = Unknown service "{0}"
@@ -68,4 +69,4 @@ TimeProfiler2_otherCategory = Other
TimeProfiler2_otherTaskName = Other
VariableInterpreter_unknownVariable = Unknown variable "{0}".
VariableInterpreter_unkownVariable = The current context does not contains variable named: {0}
-MessageTranslator_missingResourceMessage = The key {0} has not been found in the properties file for label localization.
+MessageTranslator_missingResourceMessage = The key {0} has not been found in the properties file for label localization. \ No newline at end of file
diff --git a/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/Messages.java b/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/Messages.java
index ee30c7ad0d..f071d79306 100644
--- a/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/Messages.java
+++ b/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/Messages.java
@@ -99,6 +99,9 @@ public final class Messages {
@TranslatableMessage
public static String FindMessages_abstractFindLabelDialogNoMatchingElementMessage;
+
+ @TranslatableMessage
+ public static String Interpreter_evaluationError;
@TranslatableMessage
public static String MonomorphicService_serviceError;
diff --git a/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/interpreter/EvaluationResult.java b/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/interpreter/EvaluationResult.java
new file mode 100644
index 0000000000..4f0ecc3416
--- /dev/null
+++ b/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/interpreter/EvaluationResult.java
@@ -0,0 +1,217 @@
+/*******************************************************************************
+ * Copyright (c) 2019 Obeo.
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.sirius.common.tools.api.interpreter;
+
+import java.util.Collection;
+import java.util.Optional;
+import java.util.OptionalInt;
+
+import org.eclipse.emf.common.util.BasicDiagnostic;
+import org.eclipse.emf.common.util.Diagnostic;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.sirius.common.tools.DslCommonPlugin;
+import org.eclipse.sirius.common.tools.internal.interpreter.DefaultConverter;
+
+/**
+ * Default implementation of {@link IEvaluationResult} that should be suitable for most cases.
+ *
+ * @author pcdavid
+ */
+public class EvaluationResult implements IEvaluationResult {
+
+ /**
+ * When an evaluation failed, no value is available so all conversion methods return and empty optional.
+ *
+ * @author pcdavid
+ *
+ */
+ private static final class FailedEvaluationConverter implements IConverter {
+ @Override
+ public Optional<String> toString(Object rawValue) {
+ return Optional.empty();
+ }
+
+ @Override
+ public OptionalInt toInt(Object rawValue) {
+ return OptionalInt.empty();
+ }
+
+ @Override
+ public Optional<Collection<EObject>> toEObjectCollection(Object rawValue) {
+ return Optional.empty();
+ }
+
+ @Override
+ public Optional<EObject> toEObject(Object rawValue) {
+ return Optional.empty();
+ }
+
+ @Override
+ public Optional<Boolean> toBoolean(Object rawValue) {
+ return Optional.empty();
+ }
+ }
+
+ /**
+ * The raw, uninterpreted and unconverted value that resulted from the evaluation of the expression. May be empty if
+ * the expression did not succeed or simply returned <code>null</code>.
+ */
+ private final Optional<Object> rawValue;
+
+ /**
+ * The converter to use for interpreting the raw value into the various types that are supported by Sirius.
+ */
+ private final IConverter converter;
+
+ /**
+ * Indicates if the evaluation succeeded or not.
+ */
+ private final Diagnostic diagnostic;
+
+ /**
+ * Constructor.
+ *
+ * @param rawValue
+ * the raw, uninterpreted and unconverted value that resulted from the evaluation of the expression.
+ * @param converter
+ * the converter to use for interpreting the raw value into the various types that are supported by
+ * Sirius.
+ * @param diagnostic
+ * indicates if the evaluation succeeded or not.
+ */
+ protected EvaluationResult(Optional<Object> rawValue, IConverter converter, Diagnostic diagnostic) {
+ this.rawValue = rawValue;
+ this.converter = converter;
+ this.diagnostic = diagnostic;
+ }
+
+ /**
+ * Static factory method to create a plain successufl result from a raw value.
+ *
+ * @param rawValue
+ * the raw value of the evaluation.
+ * @return the {@link IEvaluationResult} representing the successful result.
+ */
+ public static IEvaluationResult ofValue(Object rawValue) {
+ return ofValue(rawValue, new DefaultConverter(), Diagnostic.OK_INSTANCE);
+ }
+
+ /**
+ * Static factory method to create a plain successufl result from a raw value.
+ *
+ * @param rawValue
+ * the raw value of the evaluation.
+ * @param converter
+ * a specific converter to use to coerce the raw value instead of the default.
+ * @return the {@link IEvaluationResult} representing the successful result.
+ */
+ public static IEvaluationResult ofValue(Object rawValue, IConverter converter) {
+ return ofValue(rawValue, converter, Diagnostic.OK_INSTANCE);
+ }
+
+ /**
+ * Static factory method to create a successufl result with additional (non-ERROR) diagnotics.
+ *
+ * @param rawValue
+ * the raw value of the evaluation.
+ * @param converter
+ * a specific converter to use to coerce the raw value instead of the default.
+ * @param diagnostic
+ * additional diagnostics about the evaluation, which can be INFO or WARNING, but not ERROR.
+ *
+ * @return the {@link IEvaluationResult} representing the successful result.
+ */
+ public static IEvaluationResult ofValue(Object rawValue, IConverter converter, Diagnostic diagnostic) {
+ if (diagnostic.getSeverity() >= Diagnostic.ERROR) {
+ throw new IllegalArgumentException("An evalution can not produce a meaningful value if it was in error"); //$NON-NLS-1$
+ }
+ return new EvaluationResult(Optional.ofNullable(rawValue), converter, diagnostic);
+ }
+
+ /**
+ * Static factory method to create a result indicate that the evaluation failed with an error.
+ *
+ * @param error
+ * the diagnostic representing the evaluation error(s).
+ * @return the {@link IEvaluationResult} representing the failed evaluation.
+ */
+ public static IEvaluationResult ofError(Diagnostic error) {
+ return new EvaluationResult(Optional.empty(), new FailedEvaluationConverter(), error);
+ }
+
+ /**
+ * Static factory method to create a result indicate that the evaluation failed with an exception.
+ *
+ * @param th
+ * the exception which caused the evaluation to fail.
+ * @return the {@link IEvaluationResult} representing the failed evaluation.
+ */
+ public static IEvaluationResult ofError(Throwable th) {
+ BasicDiagnostic diag = new BasicDiagnostic(Diagnostic.ERROR, DslCommonPlugin.PLUGIN_ID, 0, org.eclipse.sirius.common.tools.Messages.Interpreter_evaluationError, new Object[] { th });
+ return ofError(diag);
+ }
+
+ @Override
+ public Object getValue() {
+ return rawValue.orElse(null);
+ }
+
+ @Override
+ public Optional<Collection<EObject>> asEObjects() {
+ return rawValue.flatMap(converter::toEObjectCollection);
+ }
+
+ @Override
+ public Optional<String> asString() {
+ return rawValue.flatMap(converter::toString);
+ }
+
+ @Override
+ public OptionalInt asInt() {
+ if (rawValue.isPresent()) {
+ return converter.toInt(rawValue.get());
+ } else {
+ return OptionalInt.empty();
+ }
+ }
+
+ @Override
+ public Optional<Boolean> asBoolean() {
+ return rawValue.flatMap(converter::toBoolean);
+ }
+
+ @Override
+ public Optional<EObject> asEObject() {
+ return rawValue.flatMap(converter::toEObject);
+ }
+
+ @Override
+ public Diagnostic getDiagnostic() {
+ return diagnostic;
+ }
+
+ @Override
+ public boolean success() {
+ return diagnostic.getSeverity() < Diagnostic.ERROR;
+ }
+
+ @Override
+ public String toString() {
+ if (success()) {
+ return String.valueOf(getValue());
+ } else {
+ return diagnostic.toString();
+ }
+ }
+}
diff --git a/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/interpreter/IEvaluationResult.java b/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/interpreter/IEvaluationResult.java
index 7b1f0a1d36..8eb6c2ca6c 100644
--- a/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/interpreter/IEvaluationResult.java
+++ b/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/interpreter/IEvaluationResult.java
@@ -12,26 +12,79 @@
*******************************************************************************/
package org.eclipse.sirius.common.tools.api.interpreter;
+import java.util.Collection;
+import java.util.Optional;
+import java.util.OptionalInt;
+
import org.eclipse.emf.common.util.Diagnostic;
+import org.eclipse.emf.ecore.EObject;
/**
- * This interface represents the result of the evaluation of an expression
- * with its value and a diagnostic.
+ * This interface represents the result of the evaluation of an expression with its value and a diagnostic.
*
* @author <a href="mailto:stephane.begaudeau@obeo.fr">Stephane Begaudeau</a>
+ * @author <a href="mailto:pierre-charles.david@obeo.fr">Pierre-Charles David</a>
*/
public interface IEvaluationResult {
/**
- * Returns the value computed from the evaluation of the expression.
+ * Returns the raw value computed from the evaluation of the expression.
*
* @return The value
*/
Object getValue();
/**
+ * Coerces the value as a collection of EObject if possible.
+ *
+ * @return a collection of {@link EObject}, which will be empty if the raw value could not be coerced.
+ */
+ Optional<Collection<EObject>> asEObjects();
+
+ /**
+ * Coerces the value as a string.
+ *
+ * @return a string representation of the value, which will be empty if the raw value could not be coerced
+ * meaningfully.
+ */
+ Optional<String> asString();
+
+ /**
+ * Coerces the value as an int if possible.
+ *
+ * @return an int representing the result of the evaluation, which will be empty if the raw value can not be coerced
+ * meaningfully.
+ */
+ OptionalInt asInt();
+
+ /**
+ * Coerces the value as a boolean if possible.
+ *
+ * @return a boolean representing the result of the evaluation, which will be empty if the raw value can not be
+ * coerced meaningfully.
+ */
+ Optional<Boolean> asBoolean();
+
+ /**
+ * Coerces the value as an {@link EObject} if possible.
+ *
+ * @return an {@link EObject} representing the result of the evaluation, which will be empty if the raw value can
+ * not be coerced meaningfully.
+ */
+ Optional<EObject> asEObject();
+
+ /**
* The diagnostic computed during the evaluation of the expression.
*
* @return The diagnostic
*/
Diagnostic getDiagnostic();
-} \ No newline at end of file
+
+ /**
+ * Indicates if the evaluation was successful, i.e. produced a meaningful value and no error. It will be considered
+ * a success even if there were {@link Diagnostic#INFO INFO} or {@link Diagnostic#WARNING WARNING} produced (which
+ * will be accessible via {@link #getDiagnostic()}.
+ *
+ * @return <code>true</code> if the evaluation was successful.
+ */
+ boolean success();
+}
diff --git a/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/interpreter/IInterpreter.java b/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/interpreter/IInterpreter.java
index 63a000a69d..57b2812403 100644
--- a/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/interpreter/IInterpreter.java
+++ b/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/interpreter/IInterpreter.java
@@ -16,7 +16,6 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Map;
-import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.ECrossReferenceAdapter;
import org.eclipse.sirius.ecore.extender.business.api.accessor.MetamodelDescriptor;
@@ -96,19 +95,8 @@ public interface IInterpreter {
* if the evaluation was not successful.
*/
default IEvaluationResult evaluateExpression(EObject target, String expression) throws EvaluationException {
- final Object result = this.evaluate(target, expression);
- return new IEvaluationResult() {
-
- @Override
- public Object getValue() {
- return result;
- }
-
- @Override
- public Diagnostic getDiagnostic() {
- return Diagnostic.OK_INSTANCE;
- }
- };
+ Object result = this.evaluate(target, expression);
+ return EvaluationResult.ofValue(result, getConverter());
}
/**
diff --git a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html
index d038ca18cd..943a4d23b7 100644
--- a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html
+++ b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html
@@ -130,6 +130,10 @@
<code>getConverter()</code> has been added to obtain the
<code>IConverter</code> for a given interpreter.
</li>
+ <li><span class="label label-success">Added</span> A new class
+ <code>org.eclipse.sirius.common.tools.api.interpreter.EvaluationResult</code> has been added. It serves as a default implementation of
+ <code>IEvaluationResult</code>. It provides static factory methods for common cases (successful evaluation or failure).
+ </li>
<li><span class="label label-info">Modified</span> In
<code>org.eclipse.sirius.common.tools.api.interpreter.TypeName</code>, the methods
<code>getJavaClass()</code> and
@@ -179,7 +183,7 @@
<ul>
<li><span class="label label-info">Modified</span> The interface
<code>org.eclipse.sirius.common.tools.api.interpreter.IInterpreterWithDiagnostic.IEvaluationResult</code> has been promoted as a top-level type as
- <code>org.eclipse.sirius.common.tools.api.interpreter.IEvaluationResult</code>.
+ <code>org.eclipse.sirius.common.tools.api.interpreter.IEvaluationResult</code>. In the process it has gained several methods to check for success and coerce the raw evaluation result into any of the types that are used by Sirius (depending on the usage context).
</li>
<li><span class="label label-danger">Removed</span> In interface
<code>org.eclipse.sirius.common.tools.api.interpreter.IInterpreter</code> (and all its implementations shipped with Sirius), the methods
diff --git a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile
index b996eeb7d1..36f3a2ae1a 100644
--- a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile
+++ b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile
@@ -20,6 +20,7 @@ h4. Changes in @org.eclipse.sirius.common@
* <span class="label label-success">Added</span> A new interface @org.eclipse.sirius.common.tools.api.interpreter.IConverter@ has been added: it encapsulates the coercion rules used to convert raw results returned by interpreted expressions into the types expected by Sirius (depending on the context of use of the expression).
* <span class="label label-success">Added</span> In interface @org.eclipse.sirius.common.tools.api.interpreter.IInterpreter@, a new method @getConverter()@ has been added to obtain the @IConverter@ for a given interpreter.
+* <span class="label label-success">Added</span> A new class @org.eclipse.sirius.common.tools.api.interpreter.EvaluationResult@ has been added. It serves as a default implementation of @IEvaluationResult@. It provides static factory methods for common cases (successful evaluation or failure).
* <span class="label label-info">Modified</span> In @org.eclipse.sirius.common.tools.api.interpreter.TypeName@, the methods @getJavaClass()@ and @getPackagePrefix()@ which used to return a @org.eclipse.sirius.ext.base.Option<T>@ now return standard @java.util.Optional<T>@ instead.
* <span class="label label-info">Modified</span> In @org.eclipse.sirius.common.tools.api.profiler.ProfilerTaskRegistry@, the method @get(String)@ which used to return a @org.eclipse.sirius.ext.base.Option<T>@ now return standard @java.util.Optional<T>@ instead.
* <span class="label label-info">Modified</span> In @org.eclipse.sirius.common.tools.api.query.NotifierQuery@, the method @getAdapter(Class<?>)@ which used to return a @org.eclipse.sirius.ext.base.Option<T>@ now return standard @java.util.Optional<T>@ instead.
@@ -27,7 +28,7 @@ h4. Changes in @org.eclipse.sirius.common@
* <span class="label label-info">Modified</span> In @org.eclipse.sirius.common.tools.api.util.MarkerUtil@, the method @addMarkerFor(IResource, String, int, String)@ which used to return a @org.eclipse.sirius.ext.base.Option<T>@ now return standard @java.util.Optional<T>@ instead.
* <span class="label label-info">Modified</span> In @org.eclipse.sirius.common.tools.api.util.ReflectionHelper@, all the following methods which used to return a @org.eclipse.sirius.ext.base.Option<T>@ now return standard @java.util.Optional<T>@ instead: @setConstructorVisibleWithoutException(Class<? extends Object>, Class<?>...)@
@setFieldVisibleWithoutException(Class<? extends Object>, String)@, @getClassForNameWithoutException(String)@, @instantiateWithoutException(String, Class<?>[], Object[])@, @getFieldValueWithoutException(Object, String)@, @getFieldValueWithoutException(Class<? extends Object>, String)@, and @getFieldValueWithoutException(Object, String, Class<? extends Object>)@.
-* <span class="label label-info">Modified</span> The interface @org.eclipse.sirius.common.tools.api.interpreter.IInterpreterWithDiagnostic.IEvaluationResult@ has been promoted as a top-level type as @org.eclipse.sirius.common.tools.api.interpreter.IEvaluationResult@.
+* <span class="label label-info">Modified</span> The interface @org.eclipse.sirius.common.tools.api.interpreter.IInterpreterWithDiagnostic.IEvaluationResult@ has been promoted as a top-level type as @org.eclipse.sirius.common.tools.api.interpreter.IEvaluationResult@. In the process it has gained several methods to check for success and coerce the raw evaluation result into any of the types that are used by Sirius (depending on the usage context).
* <span class="label label-danger">Removed</span> In interface @org.eclipse.sirius.common.tools.api.interpreter.IInterpreter@ (and all its implementations shipped with Sirius), the methods @addVariableStatusListener()@ and @removeVariableStatusListener()@ have been removed, along with the corresponding type @org.eclipse.sirius.common.tools.api.interpreter.IVariableStatusListener@. These correspond to obsolete and unused mechanisms.
* <span class="label label-danger">Removed</span> The @interface org.eclipse.sirius.common.tools.api.interpreter.IInterpreterWithDiagnostic@ has been removed. The single method it defined, @evaluateExpression()@, is now implemented directly by the main @IInterpreter@ interface. In effect, all @IInterpreter@ are now "with diagnostic".
* <span class="label label-danger">Removed</span> The interface @org.eclipse.sirius.tools.api.interpreter.context.SiriusInterpreterContextFactory@ has been removed from the API (it has been moved into an internal package): it should only be needed by Sirius itself and has no reason to be exposed as public API.
diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/internal/interpreter/SessionInterpreter.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/internal/interpreter/SessionInterpreter.java
index d3e92b306e..6ff75abd0a 100644
--- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/internal/interpreter/SessionInterpreter.java
+++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/internal/interpreter/SessionInterpreter.java
@@ -21,8 +21,6 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.atomic.AtomicReference;
-import org.eclipse.emf.common.util.BasicDiagnostic;
-import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.ECrossReferenceAdapter;
import org.eclipse.sirius.common.tools.DslCommonPlugin;
@@ -32,6 +30,7 @@ import org.eclipse.sirius.common.tools.api.contentassist.ContentProposal;
import org.eclipse.sirius.common.tools.api.contentassist.IProposalProvider;
import org.eclipse.sirius.common.tools.api.interpreter.CompoundInterpreter;
import org.eclipse.sirius.common.tools.api.interpreter.EvaluationException;
+import org.eclipse.sirius.common.tools.api.interpreter.EvaluationResult;
import org.eclipse.sirius.common.tools.api.interpreter.IConverter;
import org.eclipse.sirius.common.tools.api.interpreter.IEvaluationResult;
import org.eclipse.sirius.common.tools.api.interpreter.IInterpreter;
@@ -44,8 +43,6 @@ import org.eclipse.sirius.common.tools.internal.interpreter.DefaultConverter;
import org.eclipse.sirius.ecore.extender.business.api.accessor.MetamodelDescriptor;
import org.eclipse.sirius.ecore.extender.business.api.accessor.ModelAccessor;
import org.eclipse.sirius.tools.api.profiler.SiriusTasksKey;
-import org.eclipse.sirius.viewpoint.Messages;
-import org.eclipse.sirius.viewpoint.SiriusPlugin;
/**
* A generic interpreter.
@@ -164,30 +161,16 @@ public class SessionInterpreter implements IInterpreter, IProposalProvider {
result = interpreter.evaluateExpression(target, expression);
} catch (EvaluationException evx) {
this.evaluationErrorHandler.get().handleException(evx);
- result = creatErrorResult(evx);
+ result = EvaluationResult.ofError(evx);
// CHECKSTYLE:OFF
} catch (RuntimeException rex) {
// CHECKSTYLE:ON
this.evaluationErrorHandler.get().handleException(rex);
- result = creatErrorResult(rex);
+ result = EvaluationResult.ofError(rex);
}
return result;
}
- private IEvaluationResult creatErrorResult(Exception ex) {
- final BasicDiagnostic diag = new BasicDiagnostic(Diagnostic.ERROR, SiriusPlugin.ID, 0, Messages.SessionInterpreter_evaluationError, new Object[] { ex });
- return new IEvaluationResult() {
- @Override
- public Object getValue() {
- return null;
- }
-
- @Override
- public Diagnostic getDiagnostic() {
- return diag;
- }
- };
- }
@Override
public Object evaluate(final EObject target, final String expression) throws EvaluationException {

Back to the top