summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorahaase2008-03-19 16:04:37 (EDT)
committerahaase2008-03-19 16:04:37 (EDT)
commitbcd8cb5ccbdd9a165bd71b4c32a063ef403c290b (patch)
treeab406ac4097512a23cf5a987a513da165c841971
parent3b03b3f5a06ae1e38fedfcce7baabb0d5d9f49fd (diff)
downloadorg.eclipse.xpand-bcd8cb5ccbdd9a165bd71b4c32a063ef403c290b.zip
org.eclipse.xpand-bcd8cb5ccbdd9a165bd71b4c32a063ef403c290b.tar.gz
org.eclipse.xpand-bcd8cb5ccbdd9a165bd71b4c32a063ef403c290b.tar.bz2
added listener functionality for ExpressionBase (request to enable shortcuts during evaluation)
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/common/EvaluationVetoException.java35
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/common/ExecutionContext.java9
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/common/ExecutionListener.java4
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/common/ExpressionBase.java15
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/internal/ExecutionContextImpl.java7
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/CompositeTypesystem.java355
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/middleend/internal/MiddleEndImpl.java2
-rw-r--r--plugins/org.eclipse.xtend.backend/todo.txt2
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/common/ExpressionBaseTest.java73
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/functions/PolymorphicResolverTest.java2
10 files changed, 292 insertions, 212 deletions
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/common/EvaluationVetoException.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/common/EvaluationVetoException.java
new file mode 100644
index 0000000..255edf6
--- /dev/null
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/common/EvaluationVetoException.java
@@ -0,0 +1,35 @@
+/*
+Copyright (c) 2008 Arno Haase.
+All rights reserved. This program and the accompanying materials
+are made available under the terms of the Eclipse Public License v1.0
+which accompanies this distribution, and is available at
+http://www.eclipse.org/legal/epl-v10.html
+
+Contributors:
+ Arno Haase - initial API and implementation
+ */
+package org.eclipse.xtend.backend.common;
+
+
+/**
+ * This exception allows ExecutionListener implementations to veto the evaluation of the
+ * actual evaluation of the expression. To do this, they need to throw this exception
+ * in their preExecute method.<br>
+ *
+ * Vetoing the evaluation of an expression requires them to provide an object that is used
+ * as the result of the expression. This object is passed to the exception as the sole
+ * constructor parameter.
+ *
+ * @author Arno Haase (http://www.haase-consulting.com)
+ */
+public final class EvaluationVetoException extends Exception {
+ private final Object _substitutedExpressionResult;
+
+ public EvaluationVetoException (Object substitutedExpressionResult) {
+ _substitutedExpressionResult = substitutedExpressionResult;
+ }
+
+ public Object getSubstitutedExpressionResult () {
+ return _substitutedExpressionResult;
+ }
+}
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/common/ExecutionContext.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/common/ExecutionContext.java
index 4d697a9..018dfc2 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/common/ExecutionContext.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/common/ExecutionContext.java
@@ -43,4 +43,13 @@ public interface ExecutionContext {
List<StacktraceEntry> getStacktrace ();
ContributionStateContext getContributionStateContext ();
+
+ /**
+ * This list of "global" ExecutionListeners allows the registration of listeners that
+ * are notified of the evaluation of any expression. This is in addition to the list
+ * of listeners registered per expression node.<br>
+ *
+ * Listeners registered per node are notified *before* (pre) these global listeners.
+ */
+ List<ExecutionListener> getGlobalExecutionListeners ();
}
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/common/ExecutionListener.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/common/ExecutionListener.java
index 69ff1dd..4461542 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/common/ExecutionListener.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/common/ExecutionListener.java
@@ -25,6 +25,6 @@ package org.eclipse.xtend.backend.common;
* @author Arno Haase (http://www.haase-consulting.com)
*/
public interface ExecutionListener {
- void preExecute (ExecutionContext ctx);
- void postExecute (Object result, ExecutionContext ctx);
+ void preExecute (ExecutionContext ctx, ExpressionBase originator) throws EvaluationVetoException;
+ void postExecute (Object result, ExecutionContext ctx, ExpressionBase originator);
}
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/common/ExpressionBase.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/common/ExpressionBase.java
index 0f5031f..5122a9a 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/common/ExpressionBase.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/common/ExpressionBase.java
@@ -39,14 +39,20 @@ public abstract class ExpressionBase {
_listeners.add (l);
}
- private void firePreEvent (ExecutionContext ctx) {
+ private void firePreEvent (ExecutionContext ctx) throws EvaluationVetoException {
+ for (ExecutionListener l: ctx.getGlobalExecutionListeners())
+ l.preExecute (ctx, this);
+
for (ExecutionListener l: _listeners)
- l.preExecute (ctx);
+ l.preExecute (ctx, this);
}
private void firePostEvent (Object result, ExecutionContext ctx) {
for (int i=_listeners.size()-1; i >= 0; i--)
- _listeners.get(i).postExecute (result, ctx);
+ _listeners.get(i).postExecute (result, ctx, this);
+
+ for (int i=ctx.getGlobalExecutionListeners().size()-1; i >= 0; i--)
+ ctx.getGlobalExecutionListeners().get(i).postExecute (result, ctx, this);
}
public final Object evaluate (ExecutionContext ctx) {
@@ -56,6 +62,9 @@ public abstract class ExpressionBase {
firePostEvent (result, ctx);
return result;
}
+ catch (EvaluationVetoException exc) {
+ return exc.getSubstitutedExpressionResult();
+ }
catch (ExecutionException exc) {
exc.addStackTraceElement (new StacktraceEntry (_sourcePos, ctx));
throw exc;
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/internal/ExecutionContextImpl.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/internal/ExecutionContextImpl.java
index 791a0cc..9f55664 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/internal/ExecutionContextImpl.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/internal/ExecutionContextImpl.java
@@ -21,6 +21,7 @@ import org.eclipse.xtend.backend.common.Constants;
import org.eclipse.xtend.backend.common.ContributionStateContext;
import org.eclipse.xtend.backend.common.CreationCache;
import org.eclipse.xtend.backend.common.ExecutionContext;
+import org.eclipse.xtend.backend.common.ExecutionListener;
import org.eclipse.xtend.backend.common.FunctionDefContext;
import org.eclipse.xtend.backend.common.FunctionInvoker;
import org.eclipse.xtend.backend.common.LocalVarContext;
@@ -44,6 +45,8 @@ public final class ExecutionContextImpl implements ExecutionContext {
private AdviceContext _adviceContext = new AdviceContextImpl ();
private final ContributionStateContext _contributionStateContext = new ContributionStateContext ();
+
+ private final List<ExecutionListener> _globalExecutionListeners = new ArrayList<ExecutionListener> ();
public ExecutionContextImpl (FunctionDefContext initialFunctionDefContext, BackendTypesystem typesystem, boolean logStacktrace) {
_functionDefContext = initialFunctionDefContext;
@@ -106,4 +109,8 @@ public final class ExecutionContextImpl implements ExecutionContext {
public void setAdviceContext (AdviceContext ctx) {
_adviceContext = ctx;
}
+
+ public List<ExecutionListener> getGlobalExecutionListeners () {
+ return _globalExecutionListeners;
+ }
}
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/CompositeTypesystem.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/CompositeTypesystem.java
index aaf42ff..3756ed8 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/CompositeTypesystem.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/CompositeTypesystem.java
@@ -40,191 +40,182 @@ import org.eclipse.xtend.backend.types.java.internal.GlobalJavaBeansTypesystem;
import org.eclipse.xtend.backend.util.Cache;
import org.eclipse.xtend.backend.util.IdentityCache;
+
/**
- * This is the "normal" implementation of a backend type system - it can
- * recursively contain other type system implementations, and it contributes the
- * built-in types.
+ * This is the "normal" implementation of a backend type system - it can recursively
+ * contain other type system implementations, and it contributes the built-in types.
*
* @author Arno Haase (http://www.haase-consulting.com)
*/
public final class CompositeTypesystem implements BackendTypesystem {
- private BackendTypesystem _rootTypesystem = this;
- private final List<BackendTypesystem> _inner = new ArrayList<BackendTypesystem>();
-
- private static final Map<String, BackendType> _typeByUniqueRepresentation = new HashMap<String, BackendType>();
-
- static {
- _typeByUniqueRepresentation.put("{builtin}Boolean",
- BooleanType.INSTANCE);
- _typeByUniqueRepresentation.put("{builtin}Collection",
- CollectionType.INSTANCE);
- _typeByUniqueRepresentation.put("{builtin}Double", DoubleType.INSTANCE);
- _typeByUniqueRepresentation.put("{builtin}Function",
- FunctionType.INSTANCE);
- _typeByUniqueRepresentation.put("{builtin}List", ListType.INSTANCE);
- _typeByUniqueRepresentation.put("{builtin}Long", LongType.INSTANCE);
- _typeByUniqueRepresentation.put("{builtin}Map", MapType.INSTANCE);
- _typeByUniqueRepresentation.put("{builtin}Object", ObjectType.INSTANCE);
- _typeByUniqueRepresentation.put("{builtin}Property",
- PropertyType.INSTANCE);
- _typeByUniqueRepresentation.put("{builtin}Set", SetType.INSTANCE);
- _typeByUniqueRepresentation.put("{builtin}StaticProperty",
- StaticPropertyType.INSTANCE);
- _typeByUniqueRepresentation.put("{builtin}String", StringType.INSTANCE);
- _typeByUniqueRepresentation.put("{builtin}Type", TypeType.INSTANCE);
- _typeByUniqueRepresentation.put("{builtin}Void", VoidType.INSTANCE);
- }
-
- private final BackendTypesystem _javaBeansTypesystem = new GlobalJavaBeansTypesystem();
- {
- _javaBeansTypesystem.setRootTypesystem(_rootTypesystem);
- }
-
- private final IdentityCache<Object, BackendType> _typeByInstanceCache = new IdentityCache<Object, BackendType>() {
-
- @Override
- protected BackendType create(Object o) {
- if (o == null)
- return VoidType.INSTANCE;
-
- BackendType bestMatch = findSimpleBuiltinType(o.getClass());
- for (BackendTypesystem ts : _inner)
- bestMatch = bestMatch(bestMatch, ts.findType(o));
-
- if (bestMatch != null)
- return bestMatch;
-
- bestMatch = _javaBeansTypesystem.findType(o);
- if (bestMatch != null)
- return bestMatch;
-
- return ObjectType.INSTANCE;
- }
- };
-
- private final Cache<Class<?>, BackendType> _typeByClassCache = new Cache<Class<?>, BackendType>() {
- @Override
- protected BackendType create(Class<?> key) {
- BackendType bestMatch = findSimpleBuiltinType(key);
-
- for (BackendTypesystem ts : _inner)
- bestMatch = bestMatch(bestMatch, ts.findType(key));
-
- if (bestMatch != null)
- return bestMatch;
-
- final BackendType jbResult = _javaBeansTypesystem.findType(key);
- if (jbResult != null)
- return jbResult;
-
- return ObjectType.INSTANCE;
- }
- };
-
- private BackendType bestMatch(BackendType t1, BackendType t2) {
- if (t1 == null)
- return t2;
- if (t2 == null)
- return t1;
-
- if (t1.isAssignableFrom(t2))
- return t2;
- if (t2.isAssignableFrom(t1))
- return t1;
-
- throw new IllegalArgumentException("no unique best match for types "
- + t1 + " and " + t2);
- }
-
- // TODO remove this - add "asBackendType" to frontend type instead
- public Collection<BackendTypesystem> getInner() {
- final Collection<BackendTypesystem> result = new ArrayList<BackendTypesystem>(
- _inner);
- result.add(_javaBeansTypesystem);
- return result;
- }
-
- public void register(BackendTypesystem ts) {
- _inner.add(ts);
- ts.setRootTypesystem(getRootTypesystem());
- }
-
- public BackendType findType(Object o) {
- return _typeByInstanceCache.get(o);
- }
-
- public BackendType findType(Class<?> cls) {
- return _typeByClassCache.get(cls);
- }
-
- public BackendType findType(String uniqueRepresentation) {
- final BackendType asBuiltin = _typeByUniqueRepresentation
- .get(uniqueRepresentation);
- if (asBuiltin != null)
- return asBuiltin;
-
- for (BackendTypesystem ts : _inner) {
- final BackendType t = ts.findType(uniqueRepresentation);
- if (t != null)
- return t;
- }
-
- return _javaBeansTypesystem.findType(uniqueRepresentation);
- }
-
- public BackendTypesystem getRootTypesystem() {
- return _rootTypesystem;
- }
-
- public void setRootTypesystem(BackendTypesystem ts) {
- _rootTypesystem = ts;
- for (BackendTypesystem child : _inner)
- child.setRootTypesystem(ts);
-
- _javaBeansTypesystem.setRootTypesystem(ts);
- }
-
- private BackendType findSimpleBuiltinType(Class<?> cls) {
- if (cls == null)
- return ObjectType.INSTANCE; // convenience handling e.g. for
- // interface types whose Java supertype
- // is 'null'
-
- if (List.class.isAssignableFrom(cls))
- return ListType.INSTANCE;
- if (Set.class.isAssignableFrom(cls))
- return SetType.INSTANCE;
- if (Collection.class.isAssignableFrom(cls))
- return CollectionType.INSTANCE;
-
- if (Map.class.isAssignableFrom(cls))
- return MapType.INSTANCE;
-
- if (CharSequence.class.isAssignableFrom(cls))
- return StringType.INSTANCE;
-
- if (cls == Boolean.class || cls == Boolean.TYPE)
- return BooleanType.INSTANCE;
-
- if (cls == Long.class || cls == Long.TYPE)
- return LongType.INSTANCE;
- if (cls == Double.class || cls == Double.TYPE)
- return DoubleType.INSTANCE;
- if (cls == Object.class || cls == ObjectType.class)
- return ObjectType.INSTANCE;
- if (Function.class.isAssignableFrom(cls))
- return FunctionType.INSTANCE;
-
- if (cls == Void.TYPE)
- return VoidType.INSTANCE;
-
- if (BackendType.class.isAssignableFrom(cls))
- return TypeType.INSTANCE;
- if (Property.class.isAssignableFrom(cls))
- return PropertyType.INSTANCE;
- if (StaticProperty.class.isAssignableFrom(cls))
- return StaticPropertyType.INSTANCE;
-
- return null;
- }
+ private BackendTypesystem _rootTypesystem = this;
+ private final List<BackendTypesystem> _inner = new ArrayList<BackendTypesystem>();
+
+ private static final Map<String, BackendType> _typeByUniqueRepresentation = new HashMap<String, BackendType> ();
+
+ static {
+ _typeByUniqueRepresentation.put ("{builtin}Boolean", BooleanType.INSTANCE);
+ _typeByUniqueRepresentation.put ("{builtin}Collection", CollectionType.INSTANCE);
+ _typeByUniqueRepresentation.put ("{builtin}Double", DoubleType.INSTANCE);
+ _typeByUniqueRepresentation.put ("{builtin}Function", FunctionType.INSTANCE);
+ _typeByUniqueRepresentation.put ("{builtin}List", ListType.INSTANCE);
+ _typeByUniqueRepresentation.put ("{builtin}Long", LongType.INSTANCE);
+ _typeByUniqueRepresentation.put ("{builtin}Map", MapType.INSTANCE);
+ _typeByUniqueRepresentation.put ("{builtin}Object", ObjectType.INSTANCE);
+ _typeByUniqueRepresentation.put ("{builtin}Property", PropertyType.INSTANCE);
+ _typeByUniqueRepresentation.put ("{builtin}Set", SetType.INSTANCE);
+ _typeByUniqueRepresentation.put ("{builtin}StaticProperty", StaticPropertyType.INSTANCE);
+ _typeByUniqueRepresentation.put ("{builtin}String", StringType.INSTANCE);
+ _typeByUniqueRepresentation.put ("{builtin}Type", TypeType.INSTANCE);
+ _typeByUniqueRepresentation.put ("{builtin}Void", VoidType.INSTANCE);
+ }
+
+ private final BackendTypesystem _javaBeansTypesystem = new GlobalJavaBeansTypesystem ();
+ {
+ _javaBeansTypesystem.setRootTypesystem (_rootTypesystem);
+ }
+
+ private final IdentityCache<Object, BackendType> _typeByInstanceCache = new IdentityCache<Object, BackendType>() {
+
+ @Override
+ protected BackendType create (Object o) {
+ if (o == null)
+ return VoidType.INSTANCE;
+
+ BackendType bestMatch = findSimpleBuiltinType (o.getClass());
+ for (BackendTypesystem ts: _inner)
+ bestMatch = bestMatch (bestMatch, ts.findType (o));
+
+ if (bestMatch != null)
+ return bestMatch;
+
+ bestMatch = _javaBeansTypesystem.findType (o);
+ if (bestMatch != null)
+ return bestMatch;
+
+ return ObjectType.INSTANCE;
+ }
+ };
+
+ private final Cache<Class<?>, BackendType> _typeByClassCache = new Cache<Class<?>, BackendType>() {
+ @Override
+ protected BackendType create (Class<?> key) {
+ BackendType bestMatch = findSimpleBuiltinType (key);
+
+ for (BackendTypesystem ts : _inner)
+ bestMatch = bestMatch (bestMatch, ts.findType(key));
+
+ if (bestMatch != null)
+ return bestMatch;
+
+ final BackendType jbResult = _javaBeansTypesystem.findType (key);
+ if (jbResult != null)
+ return jbResult;
+
+ return ObjectType.INSTANCE;
+ }
+ };
+
+ private BackendType bestMatch (BackendType t1, BackendType t2) {
+ if (t1 == null)
+ return t2;
+ if (t2 == null)
+ return t1;
+
+ if (t1.isAssignableFrom(t2))
+ return t2;
+ if (t2.isAssignableFrom(t1))
+ return t1;
+
+ throw new IllegalArgumentException ("no unique best match for types " + t1 + " and " + t2);
+ }
+
+ //TODO remove this - add "asBackendType" to frontend type instead
+ public Collection<BackendTypesystem> getInner () {
+ final Collection<BackendTypesystem> result = new ArrayList<BackendTypesystem> (_inner);
+ result.add (_javaBeansTypesystem);
+ return result;
+ }
+
+ public void register (BackendTypesystem ts) {
+ _inner.add(ts);
+ ts.setRootTypesystem (getRootTypesystem());
+ }
+
+ public BackendType findType (Object o) {
+ return _typeByInstanceCache.get (o);
+ }
+
+ public BackendType findType (Class<?> cls) {
+ return _typeByClassCache.get (cls);
+ }
+
+ public BackendType findType (String uniqueRepresentation) {
+ final BackendType asBuiltin = _typeByUniqueRepresentation.get (uniqueRepresentation);
+ if (asBuiltin != null)
+ return asBuiltin;
+
+ for (BackendTypesystem ts: _inner) {
+ final BackendType t = ts.findType (uniqueRepresentation);
+ if (t != null)
+ return t;
+ }
+
+ return _javaBeansTypesystem.findType (uniqueRepresentation);
+ }
+
+ public BackendTypesystem getRootTypesystem () {
+ return _rootTypesystem;
+ }
+
+ public void setRootTypesystem (BackendTypesystem ts) {
+ _rootTypesystem = ts;
+ for (BackendTypesystem child : _inner)
+ child.setRootTypesystem(ts);
+
+ _javaBeansTypesystem.setRootTypesystem (ts);
+ }
+
+ private BackendType findSimpleBuiltinType (Class<?> cls) {
+ if (cls == null)
+ return ObjectType.INSTANCE; // convenience handling e.g. for interface types whose Java supertype is 'null'
+
+ if (List.class.isAssignableFrom (cls))
+ return ListType.INSTANCE;
+ if (Set.class.isAssignableFrom(cls))
+ return SetType.INSTANCE;
+ if (Collection.class.isAssignableFrom(cls))
+ return CollectionType.INSTANCE;
+
+ if (Map.class.isAssignableFrom(cls))
+ return MapType.INSTANCE;
+
+ if (CharSequence.class.isAssignableFrom(cls))
+ return StringType.INSTANCE;
+
+ if (cls == Boolean.class || cls == Boolean.TYPE)
+ return BooleanType.INSTANCE;
+
+ if (cls == Long.class || cls == Long.TYPE)
+ return LongType.INSTANCE;
+ if (cls == Double.class || cls == Double.TYPE)
+ return DoubleType.INSTANCE;
+
+ if (Function.class.isAssignableFrom(cls))
+ return FunctionType.INSTANCE;
+
+ if (cls == Void.TYPE)
+ return VoidType.INSTANCE;
+
+ if (BackendType.class.isAssignableFrom(cls))
+ return TypeType.INSTANCE;
+ if (Property.class.isAssignableFrom(cls))
+ return PropertyType.INSTANCE;
+ if (StaticProperty.class.isAssignableFrom(cls))
+ return StaticPropertyType.INSTANCE;
+
+ return null;
+ }
}
+
+
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/middleend/internal/MiddleEndImpl.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/middleend/internal/MiddleEndImpl.java
index bdfe7d8..2e8f59e 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/middleend/internal/MiddleEndImpl.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/middleend/internal/MiddleEndImpl.java
@@ -123,10 +123,8 @@ public final class MiddleEndImpl implements MiddleEnd {
final FunctionDefContextInternal result = createEmptyFdc();
_fdcs.put (resourceName, result);
- System.out.println ("*****" + resourceName);
final Set<String> reexported = new HashSet<String> ();
collectReexportedResources (reexported, new HashSet<String> (), resourceName);
- System.out.println ("/////" + resourceName);
for (String importedReexp: reexported)
for (NamedFunction f: parseResource (importedReexp).getPublicFunctions())
diff --git a/plugins/org.eclipse.xtend.backend/todo.txt b/plugins/org.eclipse.xtend.backend/todo.txt
index 16f4a20..d67d075 100644
--- a/plugins/org.eclipse.xtend.backend/todo.txt
+++ b/plugins/org.eclipse.xtend.backend/todo.txt
@@ -1,7 +1,5 @@
todo
----
-merge emftypes into backend?
-
"compiled" LangueSpecificMiddleEnd
move to m2t.common
diff --git a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/common/ExpressionBaseTest.java b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/common/ExpressionBaseTest.java
index adb72cb..1b3390d 100644
--- a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/common/ExpressionBaseTest.java
+++ b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/common/ExpressionBaseTest.java
@@ -17,6 +17,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import org.junit.Before;
import org.junit.Test;
@@ -25,32 +26,64 @@ import org.junit.Test;
* @author Arno Haase (http://www.haase-consulting.com)
*/
public class ExpressionBaseTest {
- @Test public void testExecutionListener () {
- final List<String> log = new ArrayList<String> ();
+ private final List<String> _log = new ArrayList<String> ();
- final ExpressionBase expr = createLiteral ("a");
+ @Before
+ public void init () {
+ _log.clear ();
+ }
+
+ private class TestingExecutionListener implements ExecutionListener {
+ private final String _id;
+ private final Object _vetoValue;
+
+ public TestingExecutionListener (String id, Object vetoValue) {
+ _id = id;
+ _vetoValue = vetoValue;
+ }
- expr.registerExecutionListener (new ExecutionListener () {
- public void preExecute (ExecutionContext ctx) {
- log.add ("preFirst");
- }
+ public void preExecute (ExecutionContext ctx, ExpressionBase originator) throws EvaluationVetoException {
+ _log.add("pre" + _id);
+ if (_vetoValue != null)
+ throw new EvaluationVetoException (_vetoValue);
+ }
+
+ public void postExecute (Object result, ExecutionContext ctx, ExpressionBase originator) {
+ _log.add ("post" + _id);
+ }
+ }
+
+
+
+ @Test
+ public void testVeto () {
+ final ExpressionBase expr = new ExpressionBase (createSourcePos()) {
- public void postExecute (Object result, ExecutionContext ctx) {
- log.add ("postFirst");
+ @Override
+ protected Object evaluateInternal (ExecutionContext ctx) {
+ ExpressionBaseTest.this._log.add ("evaluated");
+ return null;
}
- });
- expr.registerExecutionListener (new ExecutionListener () {
- public void preExecute (ExecutionContext ctx) {
- log.add ("preSecond");
- }
-
- public void postExecute (Object result, ExecutionContext ctx) {
- log.add ("postSecond");
- }
- });
+ };
+
+ expr.registerExecutionListener (new TestingExecutionListener ("First", "veto1"));
+ expr.registerExecutionListener (new TestingExecutionListener ("Second", "veto2"));
+
+ assertEquals ("veto1", expr.evaluate (createEmptyExecutionContext()));
+ assertEquals (Arrays.asList ("preFirst"), _log);
+
+ }
+
+
+ @Test
+ public void testExecutionListener () {
+ final ExpressionBase expr = createLiteral ("a");
+
+ expr.registerExecutionListener (new TestingExecutionListener ("First", null));
+ expr.registerExecutionListener (new TestingExecutionListener ("Second", null));
expr.evaluate (createEmptyExecutionContext());
- assertEquals (Arrays.asList ("preFirst", "preSecond", "postSecond", "postFirst"), log);
+ assertEquals (Arrays.asList ("preFirst", "preSecond", "postSecond", "postFirst"), _log);
}
}
diff --git a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/functions/PolymorphicResolverTest.java b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/functions/PolymorphicResolverTest.java
index 4d86f86..bc5431f 100644
--- a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/functions/PolymorphicResolverTest.java
+++ b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/functions/PolymorphicResolverTest.java
@@ -47,7 +47,7 @@ public class PolymorphicResolverTest {
private Collection<Function> getCandidates (Object... params) {
final FunctionDefContextImpl fdc = (FunctionDefContextImpl) createEmptyFdc (new CompositeTypesystem ());
- return new PolymorphicResolver ("operatorPlus").getBestFitCandidates (fdc.findFunctionCandidates (createEmptyExecutionContext(), "operatorPlus", Arrays.asList (params)));
+ return new PolymorphicResolver ("operatorPlus").getBestFitCandidates (fdc.findFunctionCandidates ("operatorPlus", fdc.typesForParameters(createEmptyExecutionContext().getTypesystem(), Arrays.asList (params))));
}
//TODO test resolution with guards