summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorahaase2008-02-08 16:17:38 (EST)
committer ahaase2008-02-08 16:17:38 (EST)
commit58dfa0be0c8ce678ff5c80c53fc7a549a2348936 (patch)
tree239dc018c527c0e664a46e9c2dfed8224a68b0e0
parent83b7717b20c860aefbdeff4ae5ca8ca03f81ee36 (diff)
downloadorg.eclipse.xpand-58dfa0be0c8ce678ff5c80c53fc7a549a2348936.zip
org.eclipse.xpand-58dfa0be0c8ce678ff5c80c53fc7a549a2348936.tar.gz
org.eclipse.xpand-58dfa0be0c8ce678ff5c80c53fc7a549a2348936.tar.bz2
changed the expression tests to test against both the old and the new runtime
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/common/ExpressionBase.java5
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/expr/GlobalParamExpression.java2
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/expr/InvocationOnCollectionExpression.java7
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/expr/InvocationOnWhateverExpression.java13
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/expr/PropertyOnCollectionExpression.java13
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/expr/PropertyOnWhateverExpression.java10
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/internal/FunctionDefContextImpl.java10
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/internal/JavaBuiltinConverterFactory.java2
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/internal/StringBufferConverter.java34
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/internal/StringBuilderConverter.java34
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/internal/ExecutionContextImpl.java2
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/syslib/CollectionOperations.java205
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/syslib/PrimitiveOperations.java6
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/syslib/StringOperations.java165
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/syslib/SysLibNames.java3
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/TypeType.java26
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/internal/JavaBeansProperty.java2
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/internal/JavaBeansStaticProperty.java2
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/internal/JavaBeansType.java2
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/internal/JavaOperation.java25
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/util/StringHelper.java19
-rw-r--r--plugins/org.eclipse.xtend.backend/todo.txt7
-rw-r--r--plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/OldDefinitionConverter.java8
-rw-r--r--plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/OldExpressionConverter.java42
-rw-r--r--plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/OldTypeAnalyzer.java319
-rw-r--r--plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/XpandDefinitionName.java6
-rw-r--r--plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/XtendBackendFacade.java18
-rw-r--r--plugins/org.eclipse.xtend.tests/META-INF/MANIFEST.MF5
-rw-r--r--plugins/org.eclipse.xtend.tests/src/org/eclipse/xtend/expression/ast/AType.java25
-rw-r--r--plugins/org.eclipse.xtend.tests/src/org/eclipse/xtend/expression/ast/EvaluationTest.java102
-rw-r--r--plugins/org.eclipse.xtend.tests/src/org/eclipse/xtend/expression/ast/TestType.java37
-rw-r--r--plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/type/baseimpl/BuiltinMetaModel.java6
-rw-r--r--plugins/org.eclipse.xtend/src/org/eclipse/xtend/expression/ExecutionContextImpl.java4
-rw-r--r--plugins/org.eclipse.xtend/src/org/eclipse/xtend/expression/TypeSystemImpl.java5
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/common/ExpressionBaseTest.java2
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/AndExpressionTest.java4
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/ConcatExpressionTest.java8
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/CreateCachedExpressionTest.java6
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/CreateUncachedExpressionTest.java4
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/HidingLocalVarDefExpressionTest.java6
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/IfExpressionTest.java8
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/InitClosureExpressionTest.java4
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/InvocationOnCollectionExpressionTest.java10
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/InvocationOnObjectExpressionTest.java8
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/InvocationOnWhateverExpressionTest.java20
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/ListLiteralExpressionTest.java6
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/LiteralExpressionTest.java4
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/LocalVarEvalExpressionTest.java4
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/NewLocalVarDefExpressionTest.java6
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/OrExpressionTest.java4
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/PropertyOnCollectionExpressionTest.java12
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/PropertyOnObjectExpressionTest.java8
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/PropertyOnWhateverExpressionTest.java12
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/SequenceExpressionTest.java6
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/SetPropertyExpressionTest.java8
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/SwitchExpressionTest.java8
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/functions/FunctionTest.java6
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/functions/JavaBuiltinConverterTest.java36
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/functions/PolymorphicResolverTest.java2
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/syslib/OverrideTest.java8
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/testhelpers/BackendTestHelper.java (renamed from tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/helpers/BackendTestHelper.java)2
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/testhelpers/BeanWithSizeProperty.java (renamed from tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/helpers/BeanWithSizeProperty.java)23
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/testhelpers/CheckEvaluationExpression.java (renamed from tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/helpers/CheckEvaluationExpression.java)4
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/testhelpers/CounterFunction.java (renamed from tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/helpers/CounterFunction.java)2
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/testhelpers/ExceptionThrowingExpression.java (renamed from tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/helpers/ExceptionThrowingExpression.java)2
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/testhelpers/MutableLiteralExpression.java (renamed from tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/helpers/MutableLiteralExpression.java)2
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/testhelpers/NamedFunctionFactory.java (renamed from tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/helpers/NamedFunctionFactory.java)2
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/types/AbstractTypeTest.java2
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/types/JavaBeansTypeTest.java32
69 files changed, 1264 insertions, 188 deletions
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 2ebf880..0f5031f 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
@@ -13,6 +13,9 @@ package org.eclipse.xtend.backend.common;
import java.util.ArrayList;
import java.util.List;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
/**
*
@@ -22,6 +25,8 @@ public abstract class ExpressionBase {
private final SourcePos _sourcePos;
private final List<ExecutionListener> _listeners = new ArrayList<ExecutionListener> ();
+ protected final Log _log = LogFactory.getLog (getClass ());
+
public ExpressionBase (SourcePos sourcePos) {
_sourcePos = sourcePos;
}
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/expr/GlobalParamExpression.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/expr/GlobalParamExpression.java
index 6456d53..a4d9fe5 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/expr/GlobalParamExpression.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/expr/GlobalParamExpression.java
@@ -29,7 +29,7 @@ public final class GlobalParamExpression extends ExpressionBase {
}
@Override
- protected Object evaluateInternal(ExecutionContext ctx) {
+ protected Object evaluateInternal (ExecutionContext ctx) {
return ctx.getGlobalParamContext().getGlobalParams().get (_varName);
}
}
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/expr/InvocationOnCollectionExpression.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/expr/InvocationOnCollectionExpression.java
index 2208245..cad3e68 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/expr/InvocationOnCollectionExpression.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/expr/InvocationOnCollectionExpression.java
@@ -12,12 +12,12 @@ package org.eclipse.xtend.backend.expr;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.HashSet;
import java.util.List;
import org.eclipse.xtend.backend.common.ExecutionContext;
import org.eclipse.xtend.backend.common.ExpressionBase;
import org.eclipse.xtend.backend.common.SourcePos;
+import org.eclipse.xtend.backend.syslib.CollectionOperations;
/**
@@ -51,11 +51,12 @@ public final class InvocationOnCollectionExpression extends ExpressionBase {
for (ExpressionBase expr: _params)
params.add (expr.evaluate (ctx));
- final Collection<Object> result = (coll instanceof List) ? new ArrayList<Object> () : new HashSet<Object> ();
+ final Collection<Object> result = CollectionOperations.createMatchingCollection (coll);
for (Object o: coll) {
params.set (0, o);
- result.add (ctx.getFunctionDefContext().invoke (ctx, _functionName, params));
+
+ CollectionOperations.addFlattened (result, ctx.getFunctionDefContext().invoke (ctx, _functionName, params));
}
return result;
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/expr/InvocationOnWhateverExpression.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/expr/InvocationOnWhateverExpression.java
index 2912f5c..406d99e 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/expr/InvocationOnWhateverExpression.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/expr/InvocationOnWhateverExpression.java
@@ -12,15 +12,21 @@ package org.eclipse.xtend.backend.expr;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.HashSet;
import java.util.List;
import org.eclipse.xtend.backend.common.ExecutionContext;
import org.eclipse.xtend.backend.common.ExpressionBase;
import org.eclipse.xtend.backend.common.SourcePos;
+import org.eclipse.xtend.backend.syslib.CollectionOperations;
/**
+ * This expression invokes a function on the first argument, deciding at runtime whether to do the "collection magic" of
+ * invoking the function on every member of the collection that is the first argument and returning the collection of
+ * all the arguments.<br>
+ *
+ * This expression does *not* do implicit "this" resolution - it is the responsibility of the initializing code, e.g. in the
+ * middle end, to statically resolve that.
*
* @author Arno Haase (http://www.haase-consulting.com)
*/
@@ -55,11 +61,12 @@ public final class InvocationOnWhateverExpression extends ExpressionBase {
final Collection<?> coll = (Collection<?>) params.get (0);
- final Collection<Object> result = (coll instanceof List) ? new ArrayList<Object> () : new HashSet<Object> ();
+ final Collection<Object> result = CollectionOperations.createMatchingCollection (coll);
for (Object o: coll) {
params.set (0, o);
- result.add (ctx.getFunctionDefContext().invoke (ctx, _functionName, params));
+
+ CollectionOperations.addFlattened (result, ctx.getFunctionDefContext().invoke (ctx, _functionName, params));
}
return result;
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/expr/PropertyOnCollectionExpression.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/expr/PropertyOnCollectionExpression.java
index efaed70..1921eee 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/expr/PropertyOnCollectionExpression.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/expr/PropertyOnCollectionExpression.java
@@ -10,14 +10,12 @@ Contributors:
*/
package org.eclipse.xtend.backend.expr;
-import java.util.ArrayList;
import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
import org.eclipse.xtend.backend.common.ExecutionContext;
import org.eclipse.xtend.backend.common.ExpressionBase;
import org.eclipse.xtend.backend.common.SourcePos;
+import org.eclipse.xtend.backend.syslib.CollectionOperations;
/**
@@ -43,10 +41,13 @@ public final class PropertyOnCollectionExpression extends ExpressionBase {
return null;
}
- final Collection<Object> result = (coll instanceof List) ? new ArrayList<Object> () : new HashSet<Object> ();
+ final Collection<Object> result = CollectionOperations.createMatchingCollection (coll);
- for (Object o: coll)
- result.add (ctx.getTypesystem().findType(o).getProperty(ctx, o, _propertyName));
+ if (_log.isDebugEnabled())
+ _log.debug ("evaluating property " + _propertyName + " on collection " + coll);
+
+ for (Object o: coll)
+ CollectionOperations.addFlattened (result, ctx.getTypesystem().findType(o).getProperty(ctx, o, _propertyName));
return result;
}
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/expr/PropertyOnWhateverExpression.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/expr/PropertyOnWhateverExpression.java
index 3286207..5163e28 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/expr/PropertyOnWhateverExpression.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/expr/PropertyOnWhateverExpression.java
@@ -10,15 +10,13 @@ Contributors:
*/
package org.eclipse.xtend.backend.expr;
-import java.util.ArrayList;
import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
import org.eclipse.xtend.backend.common.BackendType;
import org.eclipse.xtend.backend.common.ExecutionContext;
import org.eclipse.xtend.backend.common.ExpressionBase;
import org.eclipse.xtend.backend.common.SourcePos;
+import org.eclipse.xtend.backend.syslib.CollectionOperations;
import org.eclipse.xtend.backend.types.builtin.CollectionType;
@@ -53,10 +51,10 @@ public final class PropertyOnWhateverExpression extends ExpressionBase {
if (isProperty (t, _propertyName))
return t.getProperty (ctx, o, _propertyName);
- final Collection<Object> result = (o instanceof List) ? new ArrayList<Object> () : new HashSet<Object> ();
+ final Collection<Object> result = CollectionOperations.createMatchingCollection ((Collection<?>) o);
- for (Object obj: (Collection<?>) o)
- result.add (ctx.getTypesystem().findType(obj).getProperty(ctx, obj, _propertyName));
+ for (Object obj: (Collection<?>) o)
+ CollectionOperations.addFlattened (result, ctx.getTypesystem().findType(obj).getProperty(ctx, obj, _propertyName));
return result;
}
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/internal/FunctionDefContextImpl.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/internal/FunctionDefContextImpl.java
index e0fece3..295bc54 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/internal/FunctionDefContextImpl.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/internal/FunctionDefContextImpl.java
@@ -24,6 +24,7 @@ import org.eclipse.xtend.backend.functions.FunctionDefContextInternal;
import org.eclipse.xtend.backend.util.Cache;
import org.eclipse.xtend.backend.util.DoubleKeyCache;
import org.eclipse.xtend.backend.util.ErrorHandler;
+import org.eclipse.xtend.backend.util.StringHelper;
/**
@@ -103,7 +104,14 @@ public final class FunctionDefContextImpl implements FunctionDefContextInternal
public Object invoke (ExecutionContext ctx, String functionName, List<? extends Object> params) {
final Collection<Function> candidates = findFunctionCandidates (ctx, functionName, params);
- final Function f = new PolymorphicResolver(functionName).evaluateGuards(ctx, candidates);
+
+ Function f = null;
+ try {
+ f = new PolymorphicResolver(functionName).evaluateGuards(ctx, candidates);
+ }
+ catch (Exception exc) {
+ ErrorHandler.handle ("could not resolve function '" + functionName + "' for parameter types " + StringHelper.getTypesAsString (params) + " - candidates were " + candidates, exc);
+ }
return ctx.getFunctionInvoker().invoke (ctx, f, params);
}
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/internal/JavaBuiltinConverterFactory.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/internal/JavaBuiltinConverterFactory.java
index 72f27cf..f7c2c0f 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/internal/JavaBuiltinConverterFactory.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/internal/JavaBuiltinConverterFactory.java
@@ -44,6 +44,8 @@ public final class JavaBuiltinConverterFactory {
_converters.put (Character.TYPE, new CharConverter ());
_converters.put (String.class, new StringConverter ());
+ _converters.put (StringBuilder.class, new StringBuilderConverter ());
+ _converters.put (StringBuffer.class, new StringBufferConverter ());
_converters.put (EfficientLazyString.class, new EfficientLazyStringConverter ());
}
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/internal/StringBufferConverter.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/internal/StringBufferConverter.java
new file mode 100644
index 0000000..3fcdae5
--- /dev/null
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/internal/StringBufferConverter.java
@@ -0,0 +1,34 @@
+/*
+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.functions.java.internal;
+
+
+/**
+ * This class is necessary because any CharSequence is a valid backend representation of
+ * a String.
+ *
+ * @author Arno Haase (http://www.haase-consulting.com)
+ */
+public final class StringBufferConverter implements JavaBuiltinConverter{
+
+ public Object backendToJava (Object o) {
+ if (o == null)
+ return null;
+ if (o instanceof StringBuffer)
+ return o;
+
+ return new StringBuffer (o.toString());
+ }
+
+ public Object javaToBackend (Object o) {
+ return o;
+ }
+}
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/internal/StringBuilderConverter.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/internal/StringBuilderConverter.java
new file mode 100644
index 0000000..41bc21b
--- /dev/null
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/internal/StringBuilderConverter.java
@@ -0,0 +1,34 @@
+/*
+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.functions.java.internal;
+
+
+/**
+ * This class is necessary because any CharSequence is a valid backend representation of
+ * a String.
+ *
+ * @author Arno Haase (http://www.haase-consulting.com)
+ */
+public final class StringBuilderConverter implements JavaBuiltinConverter{
+
+ public Object backendToJava (Object o) {
+ if (o == null)
+ return null;
+ if (o instanceof StringBuilder)
+ return o;
+
+ return new StringBuilder (o.toString());
+ }
+
+ public Object javaToBackend (Object o) {
+ return o;
+ }
+}
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 c850792..fa22cf5 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
@@ -82,7 +82,7 @@ public final class ExecutionContextImpl implements ExecutionContext {
}
public void logNullDeRef (SourcePos pos) {
- final StringBuilder sb = new StringBuilder ("dereferenced null (" + pos + ")");
+ final StringBuilder sb = new StringBuilder ("dereferenced null " + ((pos != null) ? ("(" + pos + ")") : ""));
for (int i=_stacktrace.size() - 1; i>= 0; i--)
sb.append ("\n " + _stacktrace.get (i));
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/syslib/CollectionOperations.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/syslib/CollectionOperations.java
index b0ef21c..80db834 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/syslib/CollectionOperations.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/syslib/CollectionOperations.java
@@ -12,14 +12,19 @@ package org.eclipse.xtend.backend.syslib;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.eclipse.xtend.backend.common.BackendType;
+import org.eclipse.xtend.backend.common.EfficientLazyString;
import org.eclipse.xtend.backend.common.Function;
+import org.eclipse.xtend.backend.common.Helpers;
import org.eclipse.xtend.backend.functions.java.AbstractExecutionContextAware;
+import org.eclipse.xtend.backend.functions.java.M2tHidden;
/**
@@ -55,6 +60,10 @@ public final class CollectionOperations extends AbstractExecutionContextAware {
public boolean contains (Collection<Object> c, Object o) {
return c.contains (o);
}
+
+ public boolean containsAll (Collection<Object> c, Collection<?> o) {
+ return c.containsAll (o);
+ }
public void clear (Collection<Object> c) {
c.clear();
@@ -85,12 +94,82 @@ public final class CollectionOperations extends AbstractExecutionContextAware {
return c.lastIndexOf (o);
}
+ public Object first (List<?> c) {
+ return c.get (0);
+ }
+
+ public Object last (List<?> c) {
+ return c.get (c.size() - 1);
+ }
+
+ public List<?> withoutFirst (List<?> l) {
+ final List<Object> result = new ArrayList<Object> ();
+
+ for (int i=1; i<l.size(); i++)
+ result.add (l.get (i));
+
+ return result;
+ }
+
+ public List<?> withoutLast (List<?> l) {
+ final List<Object> result = new ArrayList<Object> ();
+
+ for (int i=0; i<l.size()-1; i++)
+ result.add (l.get (i));
+
+ return result;
+ }
+
+ /////////////////////////////////////////////
+ // collection "arithmetic"
+ /////////////////////////////////////////////
+
+ public Set<?> union (Collection<?> c1, Collection<?> c2) {
+ if (c2 == null) {
+ _ctx.logNullDeRef (null);
+ return null;
+ }
+
+ final Set<Object> result = new HashSet<Object> (c1);
+ result.addAll (c2);
+ return result;
+ }
+
+ public Set<?> without (Collection<?> c1, Collection<?> c2) {
+ if (c2 == null) {
+ _ctx.logNullDeRef (null);
+ return null;
+ }
+
+ final Set<Object> result = new HashSet<Object> (c1);
+ result.removeAll (c2);
+ return result;
+ }
+
+ public Set<?> intersect (Collection<?> c1, Collection<?> c2) {
+ if (c2 == null) {
+ _ctx.logNullDeRef (null);
+ return null;
+ }
+
+ final Set<Object> result = new HashSet<Object> (c1);
+ result.retainAll (c2);
+ return result;
+ }
+
+ public List<Object> reverse (List<Object> l) {
+ final List<Object> result = new ArrayList<Object> (l);
+ Collections.reverse (result);
+ return result;
+ }
+
+
/////////////////////////////////////////////
// "functional" operations on collections
/////////////////////////////////////////////
- public List<?> select (Collection<?> c, Function f) {
- final List<Object> result = new ArrayList<Object>();
+ public Collection<?> select (Collection<?> c, Function f) {
+ final Collection<Object> result = createMatchingCollection(c);
for (Object o: c)
if (Boolean.TRUE.equals (f.invoke(_ctx, new Object[] {o})))
@@ -107,25 +186,95 @@ public final class CollectionOperations extends AbstractExecutionContextAware {
return null;
}
- public List<?> typeSelect (Collection<?> c, BackendType t) {
- final List<Object> result = new ArrayList<Object>();
+ public Collection<?> typeSelect (Collection<?> c, BackendType t) {
+ final Collection<Object> result = createMatchingCollection (c);
- for (Object candidate: c)
+ for (Object candidate: c) {
+ if (candidate == null)
+ continue; //TODO this is backwards compatible - but somehow inconsistent. Change this?
+
if (t.isAssignableFrom (_ctx.getTypesystem().findType (candidate)))
result.add (candidate);
+ }
return result;
}
- public List<?> collect (Collection<?> c, Function f) {
- final List<Object> result = new ArrayList<Object> ();
+ public Collection<?> collect (Collection<?> c, Function f) {
+ final Collection<Object> result = createMatchingCollection (c);
for (Object o: c)
result.add (f.invoke(_ctx, new Object[] {o}));
return result;
}
+
+ public Collection<?> reject (Collection<?> c, Function f) {
+ final Collection<Object> result = createMatchingCollection(c);
+
+ for (Object o: c)
+ if (! (Boolean.TRUE.equals (f.invoke(_ctx, new Object[] {o}))))
+ result.add (o);
+
+ return result;
+ }
+ public boolean exists (Collection<?> c, Function f) {
+ for (Object o: c)
+ if (Boolean.TRUE.equals (f.invoke(_ctx, new Object[] {o})))
+ return true;
+
+ return false;
+ }
+
+ public boolean notExists (Collection<?> c, Function f) {
+ for (Object o: c)
+ if (Boolean.TRUE.equals (f.invoke(_ctx, new Object[] {o})))
+ return false;
+
+ return true;
+ }
+
+ public boolean forAll (Collection<?> c, Function f) {
+ for (Object o: c)
+ if (! (Boolean.TRUE.equals (f.invoke (_ctx, new Object[] {o}))))
+ return false;
+
+ return true;
+ }
+
+ public List<?> sortBy (Collection<Object> c, final Function f) {
+ final List<?> result = new ArrayList<Object> (c);
+ Collections.sort (result, new Comparator<Object> () {
+
+ @SuppressWarnings("unchecked")
+ public int compare (Object o1, Object o2) {
+ final Object comp1 = f.invoke (_ctx, new Object[] {o1});
+ final Object comp2 = f.invoke (_ctx, new Object[] {o2});
+
+ if (comp1==comp2)
+ return 0;
+ if (comp1==null)
+ return -1;
+ if (comp2==null)
+ return 1;
+ if (comp1 instanceof Comparable)
+ return ((Comparable) comp1).compareTo (comp2);
+ return comp1.toString ().compareTo (comp2.toString ());
+ }
+ });
+
+ return result;
+ }
+
+ public Collection<?> flattenedCopy (Collection<?> c) {
+ final Collection<Object> result = createMatchingCollection (c);
+
+ for (Object o: c)
+ addFlattened (result, o);
+
+ return result;
+ }
///////////////////////////////////
// operations on maps
@@ -172,12 +321,50 @@ public final class CollectionOperations extends AbstractExecutionContextAware {
// conversion operations
///////////////////////////////////
- public List<?> asList (Collection<?> c) {
+ public List<?> toList (Collection<?> c) {
return new ArrayList<Object> (c);
}
- public Set<?> asSet (Collection<?> c) {
+ public Set<?> toSet (Collection<?> c) {
return new HashSet<Object> (c);
}
+ public CharSequence toString (Collection<?> coll, CharSequence separator) {
+ EfficientLazyString result = new EfficientLazyString ();
+
+ boolean first = true;
+
+ for (Object o: coll) {
+ if (first)
+ first = false;
+ else
+ result = EfficientLazyString.createAppendedString (result, separator);
+
+ result = EfficientLazyString.createAppendedString (result, Helpers.overridableToString (_ctx, o));
+ }
+
+ return result;
+ }
+
+ ///////////////////////////////////
+ // helpers
+ ///////////////////////////////////
+
+ @M2tHidden
+ public static void addFlattened (Collection<Object> coll, Object newEl) {
+ if (newEl instanceof Collection)
+ coll.addAll ((Collection<?>) newEl);
+ else
+ coll.add (newEl);
+ }
+
+ @M2tHidden
+ public static Collection<Object> createMatchingCollection (Collection<?> coll) {
+ if (coll instanceof List)
+ return new ArrayList<Object>();
+ else
+ return new HashSet<Object>();
+ }
}
+
+
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/syslib/PrimitiveOperations.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/syslib/PrimitiveOperations.java
index 69fe404..33b1374 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/syslib/PrimitiveOperations.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/syslib/PrimitiveOperations.java
@@ -69,7 +69,7 @@ public final class PrimitiveOperations {
if (d == null || l == null)
return null;
- return d - l;
+ return l - d;
}
@@ -121,7 +121,7 @@ public final class PrimitiveOperations {
if (d == null || l == null)
return null;
- return d / l;
+ return l / d;
}
@@ -147,7 +147,7 @@ public final class PrimitiveOperations {
if (d == null || l == null)
return null;
- return d % l;
+ return l % d;
}
//////////////////////////////////////////
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/syslib/StringOperations.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/syslib/StringOperations.java
index 96e6803..b1a4bab 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/syslib/StringOperations.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/syslib/StringOperations.java
@@ -10,6 +10,9 @@ Contributors:
*/
package org.eclipse.xtend.backend.syslib;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.xtend.backend.common.EfficientLazyString;
import org.eclipse.xtend.backend.common.ExecutionContext;
import org.eclipse.xtend.backend.common.Helpers;
@@ -24,12 +27,172 @@ import org.eclipse.xtend.backend.functions.java.M2tHidden;
public final class StringOperations extends AbstractExecutionContextAware {
public String toString (Object o) {
- if (o == null)
+ if (o == null)
return "";
return String.valueOf (o);
}
+ public boolean startsWith (String s1, String s2) {
+ if (s1 == null || s2 == null) {
+ _ctx.logNullDeRef (null);
+ return false;
+ }
+
+ return s1.startsWith (s2);
+ }
+
+ public boolean endsWith (String s1, String s2) {
+ if (s1 == null || s2 == null) {
+ _ctx.logNullDeRef (null);
+ return false;
+ }
+
+ return s1.endsWith (s2);
+ }
+
+ public boolean contains (String s1, String s2) {
+ if (s1 == null || s2 == null) {
+ _ctx.logNullDeRef (null);
+ return false;
+ }
+
+ return s1.contains (s2);
+ }
+
+ public String substring (String s, int indexFrom) {
+ if (s == null) {
+ _ctx.logNullDeRef (null);
+ return null;
+ }
+
+ return s.substring (indexFrom);
+ }
+
+ public CharSequence substring (CharSequence s, int indexFrom, int indexTo) {
+ if (s == null) {
+ _ctx.logNullDeRef (null);
+ return null;
+ }
+
+ return s.subSequence (indexFrom, indexTo);
+ }
+
+ public String toUpperCase (String s) {
+ if (s == null) {
+ _ctx.logNullDeRef (null);
+ return null;
+ }
+
+ return s.toUpperCase();
+ }
+
+ public String toLowerCase (String s) {
+ if (s == null) {
+ _ctx.logNullDeRef (null);
+ return null;
+ }
+
+ return s.toLowerCase();
+ }
+
+ public String toFirstUpper (String s) {
+ if (s == null) {
+ _ctx.logNullDeRef (null);
+ return null;
+ }
+
+ if (s.length() < 2)
+ return s.toUpperCase();
+
+ return s.substring (0, 1).toUpperCase() + s.substring (1);
+ }
+
+ public String toFirstLower (String s) {
+ if (s == null) {
+ _ctx.logNullDeRef (null);
+ return null;
+ }
+
+ if (s.length() < 2)
+ return s.toLowerCase();
+
+ return s.substring (0, 1).toLowerCase() + s.substring (1);
+ }
+
+ public List<String> toCharList (String s) {
+ final List<String> result = new ArrayList<String> ();
+
+ if (s == null) {
+ _ctx.logNullDeRef (null);
+ return result;
+ }
+
+ for (char ch: s.toCharArray())
+ result.add ("" + ch);
+
+ return result;
+ }
+
+ public String replace (String s, CharSequence searchString, CharSequence replaceString) {
+ if (s == null || searchString == null || replaceString == null) {
+ _ctx.logNullDeRef (null);
+ return null;
+ }
+
+ return s.replace (searchString, replaceString);
+ }
+
+ public String replaceFirstUsingRegex (String s, String searchString, String replaceString) {
+ if (s == null || searchString == null || replaceString == null) {
+ _ctx.logNullDeRef (null);
+ return null;
+ }
+
+ return s.replaceFirst (searchString, replaceString);
+ }
+
+ public String replaceAllUsingRegex (String s, String searchString, String replaceString) {
+ if (s == null || searchString == null || replaceString == null) {
+ _ctx.logNullDeRef (null);
+ return null;
+ }
+
+ return s.replaceAll (searchString, replaceString);
+ }
+
+ public String[] split (String s, String regex) {
+ if (s == null || regex == null) {
+ _ctx.logNullDeRef (null);
+ return null;
+ }
+ return s.split (regex);
+ }
+
+ public Boolean matches (String s, String regex) {
+ if (s == null || regex == null) {
+ _ctx.logNullDeRef (null);
+ return null;
+ }
+
+ return s.matches (regex);
+ }
+
+ public String trim (String s) {
+ if (s == null)
+ return null;
+
+ return s.trim ();
+ }
+
+ public Long asInteger (String s) {
+ if (s == null)
+ return null;
+
+ return Long.valueOf (s);
+ }
+
+
public CharSequence operatorPlus (Object o1, Object o2) {
return concat (o1, o2);
}
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/syslib/SysLibNames.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/syslib/SysLibNames.java
index 1ba19c9..a21f27d 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/syslib/SysLibNames.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/syslib/SysLibNames.java
@@ -26,6 +26,9 @@ public interface SysLibNames {
String IMPLIES = "implies";
+ String SUBSTRING = "substring";
+ String REPLACE_ALL_REGEX = "replaceAllUsingRegex";
+
// function names for operator overloading
String OPERATOR_PLUS = "operatorPlus";
String OPERATOR_MINUS = "operatorMinus";
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/TypeType.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/TypeType.java
index b7d1794..7d7ddaa 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/TypeType.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/TypeType.java
@@ -11,10 +11,13 @@ Contributors:
package org.eclipse.xtend.backend.types.builtin;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import org.eclipse.xtend.backend.common.BackendType;
import org.eclipse.xtend.backend.common.ExecutionContext;
+import org.eclipse.xtend.backend.common.ExpressionBase;
+import org.eclipse.xtend.backend.common.Function;
import org.eclipse.xtend.backend.types.AbstractProperty;
import org.eclipse.xtend.backend.types.AbstractType;
import org.eclipse.xtend.backend.util.ReflectionHelper;
@@ -46,6 +49,29 @@ public final class TypeType extends AbstractType {
return result;
}
});
+
+ register ("getProperty", new Function () {
+ final List<? extends BackendType> _paramTypes = Arrays.asList (TypeType.this, StringType.INSTANCE);
+
+ public ExpressionBase getGuard () {
+ return null;
+ }
+
+ public List<? extends BackendType> getParameterTypes () {
+ return _paramTypes;
+ }
+
+ public Object invoke (ExecutionContext ctx, Object[] params) {
+ final BackendType t = (BackendType) params[0];
+ final String propname = (String) params[1];
+
+ return t.getProperties().get(propname);
+ }
+
+ public boolean isCached () {
+ return false;
+ }
+ });
}
public boolean isAssignableFrom (BackendType other) {
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/internal/JavaBeansProperty.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/internal/JavaBeansProperty.java
index 57aaba8..0f827b0 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/internal/JavaBeansProperty.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/internal/JavaBeansProperty.java
@@ -23,7 +23,7 @@ import org.eclipse.xtend.backend.util.ErrorHandler;
*
* @author Arno Haase (http://www.haase-consulting.com)
*/
-final class JavaBeansProperty implements Property {
+public final class JavaBeansProperty implements Property {
private final PropertyDescriptor _pd;
private final BackendType _owner;
private final BackendType _type;
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/internal/JavaBeansStaticProperty.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/internal/JavaBeansStaticProperty.java
index 9b66658..e970179 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/internal/JavaBeansStaticProperty.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/internal/JavaBeansStaticProperty.java
@@ -21,7 +21,7 @@ import org.eclipse.xtend.backend.functions.java.internal.JavaBuiltinConverter;
*
* @author Arno Haase (http://www.haase-consulting.com)
*/
-final class JavaBeansStaticProperty implements StaticProperty {
+public final class JavaBeansStaticProperty implements StaticProperty {
private final String _name;
private final Object _value;
private final BackendType _owner;
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/internal/JavaBeansType.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/internal/JavaBeansType.java
index 894f69f..c02b999 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/internal/JavaBeansType.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/internal/JavaBeansType.java
@@ -38,7 +38,7 @@ import org.eclipse.xtend.backend.util.ErrorHandler;
*
* @author Arno Haase (http://www.haase-consulting.com)
*/
-final class JavaBeansType implements BackendType {
+public final class JavaBeansType implements BackendType {
private final Class<?> _javaClass;
private final List<NamedFunction> _operations = new ArrayList<NamedFunction>();
private final Map<String, JavaBeansProperty> _properties = new HashMap<String, JavaBeansProperty> ();
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/internal/JavaOperation.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/internal/JavaOperation.java
index a12a5ae..8be81aa 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/internal/JavaOperation.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/internal/JavaOperation.java
@@ -12,8 +12,11 @@ package org.eclipse.xtend.backend.types.java.internal;
import java.lang.reflect.Method;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.eclipse.xtend.backend.common.BackendType;
import org.eclipse.xtend.backend.common.ExecutionContext;
import org.eclipse.xtend.backend.common.ExpressionBase;
@@ -23,6 +26,7 @@ import org.eclipse.xtend.backend.functions.java.internal.JavaBuiltinConverter;
import org.eclipse.xtend.backend.functions.java.internal.JavaBuiltinConverterFactory;
import org.eclipse.xtend.backend.util.CollectionHelper;
import org.eclipse.xtend.backend.util.ErrorHandler;
+import org.eclipse.xtend.backend.util.StringHelper;
@@ -32,7 +36,9 @@ import org.eclipse.xtend.backend.util.ErrorHandler;
*
* @author Arno Haase (http://www.haase-consulting.com)
*/
-final class JavaOperation implements Function {
+public final class JavaOperation implements Function {
+ private final Log _log = LogFactory.getLog(getClass());
+
private final Method _mtd;
private final List<BackendType> _parameterTypes;
private final ExpressionBase _guard;
@@ -46,7 +52,7 @@ final class JavaOperation implements Function {
_guard = guard;
for (int i=0; i<mtd.getParameterTypes().length; i++) {
- final ParameterConverter pc = JavaBuiltinConverterFactory.getParameterConverter (mtd.getParameterTypes()[i], i);
+ final ParameterConverter pc = JavaBuiltinConverterFactory.getParameterConverter (mtd.getParameterTypes()[i], i+1);
if (pc != null)
_parameterConverters.add(pc);
}
@@ -67,7 +73,22 @@ final class JavaOperation implements Function {
pc.convert(params);
try {
+ if (_log.isDebugEnabled()) {
+ final Object target = params[0];
+ final List<?> realParams = Arrays.asList(CollectionHelper.withoutFirst(params));
+
+ _log.debug ("invoking method " + _mtd + " on " +
+ target + "[" + StringHelper.getTypeAsString (target) + "] " +
+ "for (" + realParams + ": " + StringHelper.getTypesAsString (realParams) + ")");
+ }
+
final Object resultRaw = _mtd.invoke (params[0], CollectionHelper.withoutFirst (params));
+
+ if (_log.isDebugEnabled()) {
+ final Object convertedResult = _returnValueConverter.javaToBackend (resultRaw);
+ _log.debug (" ... result: " + convertedResult + " [" + StringHelper.getTypeAsString(convertedResult) + "]");
+ }
+
return _returnValueConverter.javaToBackend (resultRaw);
} catch (Exception e) {
ErrorHandler.handle (e);
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/util/StringHelper.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/util/StringHelper.java
index 5a46f9c..56cdb8b 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/util/StringHelper.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/util/StringHelper.java
@@ -12,9 +12,11 @@ package org.eclipse.xtend.backend.util;
import java.text.DateFormat;
import java.text.NumberFormat;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;
+import java.util.List;
/**
@@ -25,6 +27,23 @@ import java.util.Iterator;
public final class StringHelper {
private static final NumberFormat _numFormat = NumberFormat.getNumberInstance();
+ public static String getTypeAsString (Object o) {
+ if (o == null)
+ return "<null>";
+ else
+ return o.getClass().getSimpleName();
+ }
+
+ public static List<String> getTypesAsString (List<?> l) {
+ final List<String> result = new ArrayList<String> ();
+
+ for (Object o: l)
+ result.add (getTypeAsString(o));
+
+ return result;
+ }
+
+
/**
* formats a number using the default locale settings.
*/
diff --git a/plugins/org.eclipse.xtend.backend/todo.txt b/plugins/org.eclipse.xtend.backend/todo.txt
index 61b58e7..8b918b9 100644
--- a/plugins/org.eclipse.xtend.backend/todo.txt
+++ b/plugins/org.eclipse.xtend.backend/todo.txt
@@ -11,7 +11,7 @@ AOP
Profiler
Protected Region Resolver
-List.sortBy(closure)
+complete syslib: toUpper etc., List.sortBy(closure)
new String --> ""
static properties; enums
@@ -65,7 +65,10 @@ Overwriting / hiding of functions is only posible for functions without guards (
the necessity of comparing guards for equality)
IteratorType is now handled via the Java type system
Only one global type system to avoid ambiguities when objects are passed from one compilation unit to another
-
+Collection.remove, Collection.removeAll return a boolean instead of the collection now, same as the JDK implementations
+many collection operations (e.g. "flatten") retain the collection type now instead of always returning a list
+renamed "flatten" to "flattenedCopy"
+removed Collection.forAll (--> duplicate for notExists) and List.sortBy (very special functionality)
Ideen für die Zukunft
---------------------
diff --git a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/OldDefinitionConverter.java b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/OldDefinitionConverter.java
index 5c371db..dd22cd4 100644
--- a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/OldDefinitionConverter.java
+++ b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/OldDefinitionConverter.java
@@ -191,8 +191,8 @@ final class OldDefinitionConverter {
for (Expression e: stmt.getParameters())
params.add (convertExpression (e));
-
- final Type targetType = ((ParameterizedType) stmt.getTarget().analyze (_ctx, new HashSet<AnalysationIssue> ())).getInnerType();
+ final Type rawTargetType = new OldTypeAnalyzer().analyze(_ctx, stmt.getTarget());
+ final Type targetType = (rawTargetType instanceof ParameterizedType) ? ((ParameterizedType) rawTargetType).getInnerType() : _ctx.getObjectType();
final Type[] argTypes = new Type[stmt.getParametersAsList().size()];
for (int i=0; i<stmt.getParametersAsList().size(); i++)
@@ -241,7 +241,7 @@ final class OldDefinitionConverter {
final ExpressionBase separator = (stmt.getSeparator() != null) ? convertExpression (stmt.getSeparator()) : null;
final ExpressionBase target = convertExpression (stmt.getTarget());
- final Type collType = stmt.getTarget().analyze(oldContext, new HashSet<AnalysationIssue>());
+ final Type collType = new OldTypeAnalyzer().analyze (oldContext, stmt.getTarget());
final Type eleType = (collType instanceof ParameterizedType) ? ((ParameterizedType) collType).getInnerType() : _ctx.getObjectType();
final String varName = stmt.getVariable().getValue();
@@ -304,7 +304,7 @@ final class OldDefinitionConverter {
private ExpressionBase convertLetStatement (LetStatement stmt, Set<XpandDefinitionName> referencedDefinitions) {
final String varName = stmt.getVarName().getValue();
- final Type type = stmt.getVarValue().analyze (_ctx, new HashSet<AnalysationIssue> ());
+ final Type type = new OldTypeAnalyzer().analyze (_ctx, stmt.getVarValue());
final XpandExecutionContext oldContext = _ctx;
_ctx = (XpandExecutionContext) _ctx.cloneWithVariable (new Variable (varName, type));
diff --git a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/OldExpressionConverter.java b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/OldExpressionConverter.java
index a20a9ed..cfc5d26 100644
--- a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/OldExpressionConverter.java
+++ b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/OldExpressionConverter.java
@@ -12,7 +12,6 @@ package org.eclipse.xtend.middleend.old;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.HashSet;
import java.util.List;
import org.eclipse.internal.xtend.expression.ast.BooleanLiteral;
@@ -61,9 +60,10 @@ import org.eclipse.xtend.backend.expr.PropertyOnObjectExpression;
import org.eclipse.xtend.backend.expr.PropertyOnWhateverExpression;
import org.eclipse.xtend.backend.expr.SequenceExpression;
import org.eclipse.xtend.backend.syslib.SysLibNames;
+import org.eclipse.xtend.backend.types.builtin.CollectionType;
import org.eclipse.xtend.backend.types.builtin.ObjectType;
+import org.eclipse.xtend.backend.util.CollectionHelper;
import org.eclipse.xtend.backend.util.Pair;
-import org.eclipse.xtend.expression.AnalysationIssue;
import org.eclipse.xtend.expression.ExecutionContext;
import org.eclipse.xtend.expression.Variable;
import org.eclipse.xtend.typesystem.StaticProperty;
@@ -123,8 +123,9 @@ final class OldExpressionConverter {
if (expr instanceof ConstructorCallExpression)
return convertConstructorCallExpression ((ConstructorCallExpression) expr);
+
if (expr instanceof IfExpression)
- convertIfExpression((IfExpression) expr);
+ return convertIfExpression((IfExpression) expr);
if (expr instanceof SwitchExpression)
return convertSwitchExpression ((SwitchExpression) expr);
@@ -141,13 +142,13 @@ final class OldExpressionConverter {
final List<Type> paramTypes = new ArrayList<Type>();
for (Expression e: expr.getParams())
- paramTypes.add (e.analyze(_ctx, new HashSet<AnalysationIssue>()));
+ paramTypes.add (new OldTypeAnalyzer ().analyze (_ctx, e));
if (expr.getTarget() == null) {
if (hasThis()) {
// if a function matches directly (i.e. without implicitly passing 'this' as a first parameter), that
// has precedence in matching
- if (_ctx.getExtensionForTypes (functionName, paramTypes.toArray (new Type[0])) != null)
+ if (hasMatchingOperationCall (functionName, paramTypes.toArray (new Type[0])))
return new InvocationOnObjectExpression (functionName, params, false, sourcePos);
else {
final ExpressionBase thisExpression = new LocalVarEvalExpression (org.eclipse.xtend.backend.util.SyntaxConstants.THIS, sourcePos);
@@ -159,9 +160,21 @@ final class OldExpressionConverter {
return new InvocationOnObjectExpression (functionName, params, false, sourcePos);
}
else
- return createInvocationOnTargetExpression(functionName, convert (expr.getTarget()), expr.getTarget ().analyze (_ctx, new HashSet<AnalysationIssue> ()), params, paramTypes, true, sourcePos);
+ return createInvocationOnTargetExpression(functionName, convert (expr.getTarget()), new OldTypeAnalyzer ().analyze (_ctx, expr.getTarget ()), params, paramTypes, true, sourcePos);
+ }
+
+ private boolean hasMatchingOperationCall (String functionName, Type[] paramTypes) {
+ if (_ctx.getExtensionForTypes (functionName, paramTypes) != null)
+ return true;
+
+ if (paramTypes.length == 0)
+ return false;
+
+ final Type target = paramTypes[0];
+ return target.getOperation(functionName, CollectionHelper.withoutFirst (paramTypes)) != null;
}
+
/**
* transform built-in operator names from the old to the new special names
*/
@@ -193,6 +206,11 @@ final class OldExpressionConverter {
if ("!".equals (functionName))
return SysLibNames.OPERATOR_NOT;
+ if ("subString".equals (functionName))
+ return SysLibNames.SUBSTRING;
+ if ("replaceAll".equals (functionName))
+ return SysLibNames.REPLACE_ALL_REGEX;
+
return functionName;
}
@@ -206,7 +224,7 @@ final class OldExpressionConverter {
paramTypes.add (0, targetType);
final Type[] paramTypeArray = paramTypes.toArray(new Type[0]);
- if (_ctx.getExtensionForTypes (functionName, paramTypeArray) != null)
+ if (hasMatchingOperationCall (functionName, paramTypeArray))
// check if there is a function that directly matches the collection
return new InvocationOnObjectExpression (functionName, allParams, true, sourcePos);
else
@@ -258,7 +276,7 @@ final class OldExpressionConverter {
private ExpressionBase convertLetExpression (LetExpression expr) {
final ExpressionBase varExpr = convert (expr.getVarExpression());
- final Type varType = expr.getVarExpression().analyze(_ctx, new HashSet<AnalysationIssue>());
+ final Type varType = new OldTypeAnalyzer ().analyze (_ctx, expr.getVarExpression());
final ExecutionContext oldCtx = _ctx;
_ctx = _ctx.cloneWithVariable (new Variable (expr.getName(), varType));
@@ -275,10 +293,12 @@ final class OldExpressionConverter {
}
private ExpressionBase convertIfExpression (IfExpression expr) {
+ final ExpressionBase elseExpr = (expr.getElsePart() != null) ? convert (expr.getElsePart()) : new LiteralExpression (null, getSourcePos (expr));
+
return new org.eclipse.xtend.backend.expr.IfExpression (
convert (expr.getCondition()),
convert (expr.getThenPart()),
- convert (expr.getElsePart()),
+ elseExpr,
getSourcePos(expr));
}
@@ -311,14 +331,14 @@ final class OldExpressionConverter {
}
else {
// evaluate the target and evaluate the property on the result
- final Type t = expr.getTarget().analyze (_ctx, new HashSet<AnalysationIssue>());
+ final Type t = new OldTypeAnalyzer ().analyze (_ctx,expr.getTarget());
return createPropertyExpression(convert (expr.getTarget()), t, expr.getName().getValue(), sourcePos);
}
}
private ExpressionBase createPropertyExpression (ExpressionBase target, Type type, String varName, SourcePos sourcePos) {
if (isCollectionType (type)) {
- if ("size".equals (varName) || "isEmpty".equals (varName)) //TODO reference the type system for this
+ if (CollectionType.INSTANCE.getProperties().keySet().contains (varName))
return new PropertyOnObjectExpression (target, varName, sourcePos);
else
return new PropertyOnCollectionExpression (target, varName, sourcePos);
diff --git a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/OldTypeAnalyzer.java b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/OldTypeAnalyzer.java
new file mode 100644
index 0000000..78239d0
--- /dev/null
+++ b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/OldTypeAnalyzer.java
@@ -0,0 +1,319 @@
+/*
+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.middleend.old;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.eclipse.internal.xtend.expression.ast.BooleanLiteral;
+import org.eclipse.internal.xtend.expression.ast.BooleanOperation;
+import org.eclipse.internal.xtend.expression.ast.Case;
+import org.eclipse.internal.xtend.expression.ast.ChainExpression;
+import org.eclipse.internal.xtend.expression.ast.CollectionExpression;
+import org.eclipse.internal.xtend.expression.ast.ConstructorCallExpression;
+import org.eclipse.internal.xtend.expression.ast.Expression;
+import org.eclipse.internal.xtend.expression.ast.FeatureCall;
+import org.eclipse.internal.xtend.expression.ast.GlobalVarExpression;
+import org.eclipse.internal.xtend.expression.ast.IfExpression;
+import org.eclipse.internal.xtend.expression.ast.IntegerLiteral;
+import org.eclipse.internal.xtend.expression.ast.LetExpression;
+import org.eclipse.internal.xtend.expression.ast.ListLiteral;
+import org.eclipse.internal.xtend.expression.ast.NullLiteral;
+import org.eclipse.internal.xtend.expression.ast.OperationCall;
+import org.eclipse.internal.xtend.expression.ast.RealLiteral;
+import org.eclipse.internal.xtend.expression.ast.StringLiteral;
+import org.eclipse.internal.xtend.expression.ast.SwitchExpression;
+import org.eclipse.internal.xtend.expression.ast.TypeSelectExpression;
+import org.eclipse.internal.xtend.expression.parser.SyntaxConstants;
+import org.eclipse.internal.xtend.xtend.ast.CreateExtensionStatement;
+import org.eclipse.internal.xtend.xtend.ast.ExpressionExtensionStatement;
+import org.eclipse.internal.xtend.xtend.ast.Extension;
+import org.eclipse.internal.xtend.xtend.ast.JavaExtensionStatement;
+import org.eclipse.xtend.expression.ExecutionContext;
+import org.eclipse.xtend.expression.Variable;
+import org.eclipse.xtend.typesystem.ParameterizedType;
+import org.eclipse.xtend.typesystem.Property;
+import org.eclipse.xtend.typesystem.StaticProperty;
+import org.eclipse.xtend.typesystem.Type;
+
+
+/**
+ * This class is a visitor that serves as a replacement for the "analyze"
+ * methods of the Expression classes. While the "analyze" methods perform
+ * strict static checking, this class does a "best effort": It finds
+ * the best statically predictable type, based on the assumption that
+ * the code is dynamically correct.<br>
+ *
+ * An example can illustrate this. Let "x" be a collection with statically
+ * unknown inner type. Then the two approaches yield different results for
+ * "x.myProperty". The analyze methods in the expressions return "null"
+ * because they can not statically ensure the type correctness of the
+ * expression. This class on the other hand returns the type "Collection[Object]".
+ *
+ * @author Arno Haase (http://www.haase-consulting.com)
+ */
+public class OldTypeAnalyzer {
+ public Type analyze (ExecutionContext ctx, Extension ext, Type[] paramTypes) {
+ if (ext instanceof JavaExtensionStatement)
+ return analyzeJavaExtension (ctx, (JavaExtensionStatement) ext);
+ if (ext instanceof ExpressionExtensionStatement)
+ return analyzeExpressionExtension (ctx, (ExpressionExtensionStatement) ext, paramTypes);
+ if (ext instanceof CreateExtensionStatement)
+ return ctx.getTypeForName (((CreateExtensionStatement) ext).getReturnTypeIdentifier().getValue());;
+
+ throw new IllegalArgumentException ("unknown extension type " + ext.getClass().getName());
+ }
+
+ private Type analyzeExpressionExtension (ExecutionContext ctx, ExpressionExtensionStatement ext, Type[] paramTypes) {
+ ctx = ctx.cloneWithoutVariables();
+
+ for (int i=0; i<ext.getParameterNames().size(); i++) {
+ final String name = ext.getParameterNames().get(i);
+ final Type value = paramTypes[i];
+
+ ctx = ctx.cloneWithVariable (new Variable (name, value));
+ }
+
+ return analyze (ctx, ext.getExpression());
+ }
+
+ private Type analyzeJavaExtension (ExecutionContext ctx, JavaExtensionStatement ext) {
+ if (ext.getReturnTypeIdentifier() != null)
+ return ctx.getTypeForName (ext.getReturnTypeIdentifier().getValue());
+
+ return ctx.getObjectType(); // Typesystem provides no support for evaluating the return type of the Method...
+ }
+
+
+ public Type analyze (ExecutionContext ctx, Expression expr) {
+ if (expr instanceof BooleanLiteral)
+ return ctx.getBooleanType();
+ if (expr instanceof IntegerLiteral)
+ return ctx.getIntegerType();
+ if (expr instanceof NullLiteral)
+ return ctx.getVoidType();
+ if (expr instanceof RealLiteral)
+ return ctx.getRealType();
+ if (expr instanceof StringLiteral)
+ return ctx.getStringType();
+ if (expr instanceof ListLiteral)
+ return analyzeListLiteral (ctx, (ListLiteral) expr);
+
+ if (expr instanceof OperationCall)
+ return analyzeOperationCall (ctx, (OperationCall) expr);
+ if (expr instanceof CollectionExpression)
+ return analyzeCollectionExpression (ctx, (CollectionExpression) expr);
+ if (expr instanceof TypeSelectExpression)
+ return analyzeTypeSelect (ctx, (TypeSelectExpression) expr);
+
+ // This case must come *after* OperationCall etc. because of implementation inheritance in the Xtend AST!
+ if (expr instanceof FeatureCall)
+ return analyzeFeatureCall (ctx, (FeatureCall) expr);
+
+ if (expr instanceof BooleanOperation)
+ return ctx.getBooleanType();
+
+ if (expr instanceof GlobalVarExpression)
+ return analyzeGlobalVar (ctx, (GlobalVarExpression) expr);
+ if (expr instanceof LetExpression)
+ return analyzeLet (ctx, (LetExpression) expr);
+ if (expr instanceof ChainExpression)
+ return analyzeChain (ctx, (ChainExpression) expr);
+
+ if (expr instanceof ConstructorCallExpression)
+ return analyzeConstructorCall (ctx, (ConstructorCallExpression) expr);
+
+ if (expr instanceof IfExpression)
+ return analyzeIf (ctx, (IfExpression) expr);
+ if (expr instanceof SwitchExpression)
+ return analyzeSwitch (ctx, (SwitchExpression) expr);
+
+ throw new IllegalArgumentException ("unknown expression kind " + expr.getClass().getName());
+ }
+
+ private Type analyzeListLiteral (ExecutionContext ctx, ListLiteral expr) {
+ Type innerType = null;
+
+ for (Expression ele: expr.getElements()) {
+ if (innerType == null)
+ innerType = analyze (ctx, ele);
+ else
+ innerType = getCommonSupertype (innerType, analyze (ctx, ele));
+ }
+
+ if (innerType == null)
+ innerType = ctx.getObjectType();
+
+ return ctx.getListType (innerType);
+ }
+
+ private Type analyzeOperationCall (ExecutionContext ctx, OperationCall expr) {
+ return ctx.getObjectType();
+
+ // it would require extreme effort to find matching extensions etc. because we do not know
+ // the parameter types but their *super*types, so ObjectType is a safe assumption here.
+ }
+
+
+ private Type analyzeCollectionExpression (ExecutionContext ctx, CollectionExpression expr) {
+ if (Arrays.asList (SyntaxConstants.COLLECT, SyntaxConstants.SELECT, SyntaxConstants.REJECT, SyntaxConstants.SORT_BY).contains (expr.getName().getValue()))
+ return analyze (ctx, expr.getTarget());
+
+ if (expr.getName().getValue().equals(SyntaxConstants.SELECTFIRST))
+ return ((ParameterizedType) analyze (ctx, expr.getTarget())).getInnerType();
+
+ if (Arrays.asList (SyntaxConstants.EXISTS, SyntaxConstants.NOT_EXISTS, SyntaxConstants.FOR_ALL).contains (expr.getName().getValue()))
+ return ctx.getBooleanType();
+
+ throw new IllegalArgumentException ("unknown collection operation " + expr.getName().getValue());
+ }
+
+ private Type analyzeTypeSelect (ExecutionContext ctx, TypeSelectExpression expr) {
+ final Type innerType = ctx.getTypeForName (expr.getTypeName ());
+ return ctx.getCollectionType(innerType);
+ }
+
+ private Type analyzeFeatureCall (ExecutionContext ctx, FeatureCall expr) {
+ Type targetType = null;
+ if (expr.getTarget() == null) {
+ // enum literal
+ final StaticProperty staticProp = expr.getEnumLiteral(ctx);
+ if (staticProp != null)
+ return staticProp.getReturnType();
+
+ // variable
+ Variable var = ctx.getVariable (expr.getName().getValue());
+ if (var != null)
+ return (Type) var.getValue();
+
+ // implicit variable 'this'
+ var = ctx.getVariable (ExecutionContext.IMPLICIT_VARIABLE);
+ if (var != null)
+ targetType = (Type) var.getValue();
+
+ }
+ else
+ targetType = analyze (ctx, expr.getTarget());
+
+ // simple property
+ if (targetType != null) {
+ Property p = targetType.getProperty (expr.getName().getValue());
+ if (p != null)
+ return p.getReturnType();
+
+ if (targetType instanceof ParameterizedType) {
+ final Type innerType = ((ParameterizedType) targetType).getInnerType ();
+ p = innerType.getProperty (expr.getName().getValue());
+ if (p != null) {
+ Type rt = p.getReturnType();
+
+ if (rt instanceof ParameterizedType)
+ rt = ((ParameterizedType) rt).getInnerType();
+
+ return ctx.getListType(rt);
+ }
+ }
+
+ return ctx.getObjectType();
+ }
+
+ // type literal
+ if (expr.getTarget() == null) {
+ final Type type = ctx.getTypeForName (expr.getName().getValue());
+ if (type != null)
+ return ctx.getTypeType();
+ }
+
+ return ctx.getObjectType();
+ }
+
+ private Type analyzeGlobalVar (ExecutionContext ctx, @SuppressWarnings("unused") GlobalVarExpression expr) {
+ return ctx.getObjectType();
+ }
+
+ private Type analyzeLet (ExecutionContext ctx, LetExpression expr) {
+ final Type t = analyze (ctx, expr.getVarExpression());
+ ctx = ctx.cloneWithVariable (new Variable (expr.getName(), t));
+ return analyze (ctx, expr.getTargetExpression());
+ }
+
+ private Type analyzeChain (ExecutionContext ctx, ChainExpression expr) {
+ return analyze (ctx, expr.getNext());
+ }
+
+ private Type analyzeConstructorCall (ExecutionContext ctx, ConstructorCallExpression expr) {
+ return ctx.getTypeForName (expr.getTypeName());
+ }
+
+ private Type analyzeIf (ExecutionContext ctx, IfExpression expr) {
+ if (expr.getElsePart() == null)
+ return analyze (ctx, expr.getThenPart());
+ else
+ return getCommonSupertype (analyze (ctx, expr.getThenPart()), analyze (ctx, expr.getElsePart()));
+ }
+
+ private Type analyzeSwitch (ExecutionContext ctx, SwitchExpression expr) {
+ Type result = analyze (ctx, expr.getDefaultExpr());
+ for (Case curCase: expr.getCases())
+ result = getCommonSupertype (result, analyze (ctx, curCase.getThenPart()));
+
+ return result;
+ }
+
+ private Type getCommonSupertype (Type t1, Type t2) {
+ if (t1.isAssignableFrom (t2))
+ return t1;
+ if (t2.isAssignableFrom (t1))
+ return t2;
+
+ final Set<Type> commonSupertypes = new HashSet<Type>();
+ for (Type parent1: t1.getSuperTypes())
+ for (Type parent2: t2.getSuperTypes())
+ commonSupertypes.add (getCommonSupertype (parent1, parent2));
+
+ // this is an arbitrary way to disambiguate in the case of several matches / multiple inheritance
+ final Iterator<Type> iter = commonSupertypes.iterator();
+ Type result = iter.next();
+ while (iter.hasNext()) {
+ final Type candidate = iter.next();
+ if (candidate.isAssignableFrom (result))
+ result = candidate;
+ }
+
+ return result;
+ }
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/XpandDefinitionName.java b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/XpandDefinitionName.java
index 25af7df..836b395 100644
--- a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/XpandDefinitionName.java
+++ b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/XpandDefinitionName.java
@@ -10,7 +10,6 @@ Contributors:
*/
package org.eclipse.xtend.middleend.old;
-import java.util.HashSet;
import java.util.List;
import org.eclipse.internal.xpand2.model.XpandDefinition;
@@ -18,7 +17,6 @@ import org.eclipse.internal.xtend.expression.ast.Expression;
import org.eclipse.internal.xtend.expression.ast.FeatureCall;
import org.eclipse.internal.xtend.expression.ast.Identifier;
import org.eclipse.xpand2.XpandExecutionContext;
-import org.eclipse.xtend.expression.AnalysationIssue;
import org.eclipse.xtend.expression.ExecutionContext;
import org.eclipse.xtend.typesystem.Type;
@@ -60,13 +58,13 @@ final class XpandDefinitionName {
if (target == null)
target = new FeatureCall (new Identifier (ExecutionContext.IMPLICIT_VARIABLE), null); // no target is treated as a 'this' reference
- return target.analyze (ctx, new HashSet<AnalysationIssue> ());
+ return new OldTypeAnalyzer().analyze (ctx, target);
}
private static Type[] typesForArgExpressions (List<Expression> args, XpandExecutionContext ctx) {
final Type[] result = new Type[args.size()];
for (int i=0; i<args.size(); i++)
- result[i] = args.get(i).analyze(ctx, new HashSet<AnalysationIssue> ());
+ result[i] = new OldTypeAnalyzer().analyze (ctx, args.get(i));
return result;
}
diff --git a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/XtendBackendFacade.java b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/XtendBackendFacade.java
index a14e513..222d28c 100644
--- a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/XtendBackendFacade.java
+++ b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/XtendBackendFacade.java
@@ -48,7 +48,11 @@ public final class XtendBackendFacade {
* Both mms and localVars may be null.
*/
public static Object evaluateExpression (String expression, Collection<MetaModel> mms, Map<String, Object> localVars) {
- return evaluateExpression (expression, null, null, mms, localVars);
+ return evaluateExpression (expression, mms, localVars, null);
+ }
+
+ public static Object evaluateExpression (String expression, Collection<MetaModel> mms, Map<String, Object> localVars, Map<String, Object> globalVars) {
+ return evaluateExpression (expression, null, null, mms, localVars, globalVars);
}
/**
@@ -57,19 +61,24 @@ public final class XtendBackendFacade {
* The fileEncoding may be null, in which case the platform's default encoding is used. Both mms and localVars may be null.
*/
public static Object evaluateExpression (String expression, String initialXtendFileName, String fileEncoding, Collection<MetaModel> mms, Map<String, Object> localVars) {
+ return evaluateExpression (expression, initialXtendFileName, fileEncoding, mms, localVars, null);
+ }
+
+ public static Object evaluateExpression (String expression, String initialXtendFileName, String fileEncoding, Collection<MetaModel> mms, Map<String, Object> localVars, Map<String, Object> globalVars) {
if (localVars == null)
localVars = new HashMap<String, Object> ();
+ if (globalVars == null)
+ globalVars = new HashMap<String, Object> ();
if (mms == null)
mms = new ArrayList<MetaModel> ();
final Expression oldAst = ParseFacade.expression (expression);
-
ExecutionContextImpl ctx = new ExecutionContextImpl ();
for (MetaModel mm: mms)
ctx.registerMetaModel (mm);
for (String varName: localVars.keySet())
- ctx = (ExecutionContextImpl) ctx.cloneWithVariable (new Variable (varName, localVars.get (varName)));
+ ctx = (ExecutionContextImpl) ctx.cloneWithVariable (new Variable (varName, ctx.getType (localVars.get (varName))));
final BackendTypesystem ts = OldXtendHelper.guessTypesystem (mms);
final TypeToBackendType typeConverter = new TypeToBackendType (ts, ctx);
@@ -79,7 +88,8 @@ public final class XtendBackendFacade {
final FunctionDefContext fdc = (initialXtendFileName != null) ? createForFile (initialXtendFileName, fileEncoding, mms).getFunctionDefContext() : new FunctionDefContextFactory (ts).create();
final ExecutionContext newCtx = BackendFacade.createExecutionContext (fdc, ts, true); //TODO configure isLogStacktrace
newCtx.getLocalVarContext().getLocalVars().putAll (localVars);
-
+ newCtx.getGlobalParamContext().getGlobalParams().putAll (globalVars);
+
return newAst.evaluate (newCtx);
}
diff --git a/plugins/org.eclipse.xtend.tests/META-INF/MANIFEST.MF b/plugins/org.eclipse.xtend.tests/META-INF/MANIFEST.MF
index cfad0a1..d93ce67 100644
--- a/plugins/org.eclipse.xtend.tests/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.xtend.tests/META-INF/MANIFEST.MF
@@ -24,5 +24,8 @@ Require-Bundle: org.junit,
org.eclipse.xtend,
org.antlr.runtime,
org.eclipse.emf.common,
- org.eclipse.xtend.middleend.old
+ org.eclipse.xtend.middleend.old,
+ org.apache.log4j,
+ org.apache.commons.logging,
+ org.eclipse.xtend.backend
Bundle-RequiredExecutionEnvironment: J2SE-1.5
diff --git a/plugins/org.eclipse.xtend.tests/src/org/eclipse/xtend/expression/ast/AType.java b/plugins/org.eclipse.xtend.tests/src/org/eclipse/xtend/expression/ast/AType.java
index 883565e..18c0743 100644
--- a/plugins/org.eclipse.xtend.tests/src/org/eclipse/xtend/expression/ast/AType.java
+++ b/plugins/org.eclipse.xtend.tests/src/org/eclipse/xtend/expression/ast/AType.java
@@ -35,4 +35,29 @@ public class AType {
public Integer myOperation(final String param) {
return new Integer(4);
}
+
+ @Override
+ public int hashCode () {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((test == null) ? 0 : test.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals (Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ final AType other = (AType) obj;
+ if (test == null) {
+ if (other.test != null)
+ return false;
+ } else if (!test.equals(other.test))
+ return false;
+ return true;
+ }
}
diff --git a/plugins/org.eclipse.xtend.tests/src/org/eclipse/xtend/expression/ast/EvaluationTest.java b/plugins/org.eclipse.xtend.tests/src/org/eclipse/xtend/expression/ast/EvaluationTest.java
index b310f5f..8afeb58 100644
--- a/plugins/org.eclipse.xtend.tests/src/org/eclipse/xtend/expression/ast/EvaluationTest.java
+++ b/plugins/org.eclipse.xtend.tests/src/org/eclipse/xtend/expression/ast/EvaluationTest.java
@@ -14,7 +14,9 @@ package org.eclipse.xtend.expression.ast;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import junit.framework.TestCase;
@@ -23,11 +25,13 @@ import org.eclipse.internal.xtend.expression.parser.SyntaxConstants;
import org.eclipse.internal.xtend.type.impl.java.JavaMetaModel;
import org.eclipse.internal.xtend.type.impl.java.beans.JavaBeansStrategy;
import org.eclipse.internal.xtend.xtend.parser.ParseFacade;
+import org.eclipse.xtend.backend.types.builtin.StringType;
import org.eclipse.xtend.expression.EvaluationException;
import org.eclipse.xtend.expression.ExecutionContext;
import org.eclipse.xtend.expression.ExecutionContextImpl;
import org.eclipse.xtend.expression.Type1;
import org.eclipse.xtend.expression.Variable;
+import org.eclipse.xtend.middleend.old.XtendBackendFacade;
import org.eclipse.xtend.typesystem.Property;
/**
@@ -39,29 +43,70 @@ public class EvaluationTest extends TestCase {
private ExecutionContextImpl ec;
@Override
- protected void setUp() throws Exception {
+ protected void setUp() {
ec = new ExecutionContextImpl();
- ec.registerMetaModel(new JavaMetaModel("asdf", new JavaBeansStrategy()));
+ ec.registerMetaModel (new JavaMetaModel("asdf", new JavaBeansStrategy()));
}
- private Expression parse (final String expression) {
- return ParseFacade.expression(expression);
+ private Object eval (String expression) {
+ final Object oldResult = evalOld (expression);
+ final Object newResult = evalNew (expression);
+
+ checkEquals (oldResult, newResult);
+
+ setUp (); // re-init ec
+
+ return oldResult;
}
- private Object eval (String expression) {
- final Expression expr = ParseFacade.expression(expression);
- return expr.evaluate (ec);
+ private Object evalOld (String expression) {
+ final Expression expr = ParseFacade.expression(expression);
+ return expr.evaluate (ec);
}
+ private Object evalNew (String expression) {
+ final Map<String, Object> newLocalVars = new HashMap<String, Object> ();
+ for (String vn: ec.getVisibleVariables().keySet())
+ newLocalVars.put (vn, ec.getVisibleVariables().get(vn).getValue());
+
+ final Map<String, Object> newGlobalVars = new HashMap<String, Object> ();
+ for (String vn: ec.getGlobalVariables().keySet())
+ newGlobalVars.put (vn, ec.getGlobalVariables().get(vn).getValue());
+
+ return XtendBackendFacade.evaluateExpression (expression, ec.getMetaModels(), newLocalVars, newGlobalVars);
+ }
+
+ // be lenient about type equality - the new backend is more consistent at converting types than the old runtime is...
+ private void checkEquals (Object o1, Object o2) {
+ if (o1 == null) {
+ assertTrue (o2 == null);
+ return;
+ }
+
+ if (o1 instanceof Double && o2 instanceof Double) {
+ assertEquals ((Double) o1, (Double) o2, .0000001);
+ return;
+ }
+
+ if (o1 instanceof Number && o2 instanceof Number) {
+ assertEquals (((Number) o1).longValue(), ((Number) o2).longValue());
+ return;
+ }
+
+ if (o1 instanceof CharSequence && o2 instanceof CharSequence) {
+ assertEquals (o1.toString(), o2.toString());
+ return;
+ }
+
+ assertEquals (o1, o2);
+ }
+
+
private Object eval (String expression, String localVarName, Object localVarValue) {
ec = (ExecutionContextImpl) ec.cloneWithVariable (new Variable (localVarName, localVarValue));
return eval (expression);
}
- private Object eval (Expression expr) {
- return expr.evaluate (ec);
- }
-
public final void testSimple() {
final Object result = eval ("true == null");
assertFalse(((Boolean) result).booleanValue());
@@ -113,6 +158,7 @@ public class EvaluationTest extends TestCase {
assertEquals(new Long(11), eval ("4 * 2 + 3"));
assertEquals(new Long(11), eval ("3 + 4 * 2"));
assertEquals(new Long(9), eval ("4 * 2 + 3 / 3"));
+ assertEquals(new Long(4), eval ("4 * 2 - (9 / 2)"));
assertEquals(new Double(11), eval ("3 + 4.0 * 2"));
assertEquals(new Double(11), eval ("4.0 * 2 + 3"));
@@ -132,11 +178,13 @@ public class EvaluationTest extends TestCase {
}
public final void testTypeLiteral1() {
- assertEquals(ec.getStringType(), eval (parse("String")));
+ assertEquals (ec.getStringType(), evalOld ("String"));
+ assertEquals (StringType.INSTANCE, evalNew ("String"));
- assertTrue (eval ("String.getProperty('length')") instanceof Property);
+ assertTrue (evalOld ("String.getProperty('length')") instanceof Property);
+ assertTrue (evalNew ("String.getProperty('length')") instanceof org.eclipse.xtend.backend.common.Property);
- assertEquals(AType.TEST, eval(getATypeName() + "::TEST"));
+ assertEquals (AType.TEST, eval (getATypeName() + "::TEST"));
}
private String getATypeName() {
@@ -167,7 +215,7 @@ public class EvaluationTest extends TestCase {
list.add(new Long(3));
list.add(new Long(4));
- final String expr = "col.typeSelect(String).forAll(e|col.typeSelect(Integer).exists(a| a == e.length))";
+ final String expr = "col.typeSelect(String).forAll (e|col.typeSelect(Integer).exists(a | a == e.length))";
assertEquals(Boolean.FALSE, eval (expr, "col", list));
list.add(new Long(5));
@@ -179,7 +227,7 @@ public class EvaluationTest extends TestCase {
}
public final void testGlobalVar() {
- ec = new ExecutionContextImpl(Collections.singletonMap("horst", new Variable("horst", "TEST")));
+ ec = new ExecutionContextImpl (Collections.singletonMap ("horst", new Variable("horst", "TEST")));
assertEquals("TEST", eval ("GLOBALVAR horst"));
}
@@ -201,7 +249,7 @@ public class EvaluationTest extends TestCase {
}
public final void testConstruction() {
- assertEquals("", eval ("new String"));
+ assertEquals(new AType (), eval ("new org::eclipse::xtend::expression::ast::AType"));
try {
eval ("new Unkown");
@@ -225,13 +273,9 @@ public class EvaluationTest extends TestCase {
public void testCollectShortCutWithFeatureCalls() throws Exception {
- TestMetaModel mm = new TestMetaModel();
- ec = new ExecutionContextImpl();
- ec.registerMetaModel(mm);
-
- assertEquals (Arrays.asList("test"), eval ("x.list.list.strings.toLowerCase()", "x", Collections.singletonList(mm.singleType.newInstance())));
- assertEquals (Arrays.asList("test"), eval ("x.list().list().strings().toLowerCase()", "x", Collections.singletonList(mm.singleType.newInstance())));
- assertEquals (Arrays.asList("test"), eval ("x.list.list().list.strings().toLowerCase()", "x", Collections.singletonList(mm.singleType.newInstance())));
+ assertEquals (Arrays.asList ("test"), eval ("x.list.list.strings.toLowerCase()", "x", Collections.singletonList (new TestType ())));
+ assertEquals (Arrays.asList ("test"), eval ("x.list().list().strings().toLowerCase()", "x", Collections.singletonList (new TestType ())));
+ assertEquals (Arrays.asList ("test"), eval ("x.list.list().list.strings().toLowerCase()", "x", Collections.singletonList (new TestType ())));
}
public void testCollectOnNull() throws Exception {
@@ -239,13 +283,17 @@ public class EvaluationTest extends TestCase {
}
public void testEvaluationOrderOfOperands() throws Exception {
- assertEquals("12",eval ("x.toString() + x.toString()", "x", new Cls ()));
+ ec = (ExecutionContextImpl) ec.cloneWithVariable (new Variable ("x", new Cls()));
+ checkEquals ("12", evalOld ("x.asString() + x.asString()"));
+
+ ec = (ExecutionContextImpl) ec.cloneWithVariable (new Variable ("x", new Cls()));
+ checkEquals ("12", evalNew ("x.asString() + x.asString()"));
}
public static class Cls {
int c = 1;
- @Override
- public String toString() {
+
+ public String asString() {
return ""+c++;
}
}
diff --git a/plugins/org.eclipse.xtend.tests/src/org/eclipse/xtend/expression/ast/TestType.java b/plugins/org.eclipse.xtend.tests/src/org/eclipse/xtend/expression/ast/TestType.java
new file mode 100644
index 0000000..de4c758
--- /dev/null
+++ b/plugins/org.eclipse.xtend.tests/src/org/eclipse/xtend/expression/ast/TestType.java
@@ -0,0 +1,37 @@
+/*
+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.expression.ast;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+
+/**
+ *
+ * @author Arno Haase (http://www.haase-consulting.com)
+ */
+public class TestType {
+ public Collection<String> getStrings () {
+ return Arrays.asList("test");
+ }
+
+ public Collection<TestType> getList () {
+ return Arrays.asList (this);
+ }
+
+ public Collection<String> strings() {
+ return Arrays.asList("test");
+ }
+
+ public Collection<TestType> list() {
+ return Arrays.asList(this);
+ }
+}
diff --git a/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/type/baseimpl/BuiltinMetaModel.java b/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/type/baseimpl/BuiltinMetaModel.java
index c85bbb7..1472b72 100644
--- a/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/type/baseimpl/BuiltinMetaModel.java
+++ b/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/type/baseimpl/BuiltinMetaModel.java
@@ -246,13 +246,13 @@ public final class BuiltinMetaModel implements MetaModel {
return getVoidType();
}
if (obj instanceof Set) {
- return getSetType(null);
+ return getSetType(getObjectType());
}
if (obj instanceof List) {
- return getListType(null);
+ return getListType(getObjectType());
}
if (obj instanceof Collection) {
- return getCollectionType(null);
+ return getCollectionType(getObjectType());
}
// datatypes
if (stringType.isInstance(obj)) {
diff --git a/plugins/org.eclipse.xtend/src/org/eclipse/xtend/expression/ExecutionContextImpl.java b/plugins/org.eclipse.xtend/src/org/eclipse/xtend/expression/ExecutionContextImpl.java
index 9685995..7df9e22 100644
--- a/plugins/org.eclipse.xtend/src/org/eclipse/xtend/expression/ExecutionContextImpl.java
+++ b/plugins/org.eclipse.xtend/src/org/eclipse/xtend/expression/ExecutionContextImpl.java
@@ -120,6 +120,10 @@ public class ExecutionContextImpl implements ExecutionContext {
typeSystem.registerMetaModel(mm);
}
+ public List<MetaModel> getMetaModels () {
+ return typeSystem.getMetaModels();
+ }
+
public Operation findOperation(final String name, final Object target, final Object[] params) {
return typeSystem.findOperation(name, target, params);
}
diff --git a/plugins/org.eclipse.xtend/src/org/eclipse/xtend/expression/TypeSystemImpl.java b/plugins/org.eclipse.xtend/src/org/eclipse/xtend/expression/TypeSystemImpl.java
index 9e74151..f366eeb 100644
--- a/plugins/org.eclipse.xtend/src/org/eclipse/xtend/expression/TypeSystemImpl.java
+++ b/plugins/org.eclipse.xtend/src/org/eclipse/xtend/expression/TypeSystemImpl.java
@@ -57,6 +57,10 @@ public class TypeSystemImpl implements TypeSystem {
metaModels.add(metaModel);
}
+ public List<MetaModel> getMetaModels () {
+ return metaModels;
+ }
+
private Type[] toTypes(final Object[] params) {
final Type[] types = new Type[params.length];
for (int i = 0; i < types.length; i++) {
@@ -140,6 +144,7 @@ public class TypeSystemImpl implements TypeSystem {
}
}
}
+
return bestMatch;
}
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 0a01dff..adb72cb 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
@@ -10,7 +10,7 @@ Contributors:
*/
package org.eclipse.xtend.backend.common;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.*;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.*;
import static org.junit.Assert.*;
import java.util.ArrayList;
diff --git a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/AndExpressionTest.java b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/AndExpressionTest.java
index dfaa164..424cb26 100644
--- a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/AndExpressionTest.java
+++ b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/AndExpressionTest.java
@@ -10,10 +10,10 @@ Contributors:
*/
package org.eclipse.xtend.backend.expr;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.*;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.*;
import static org.junit.Assert.*;
-import org.eclipse.xtend.backend.helpers.ExceptionThrowingExpression;
+import org.eclipse.xtend.backend.testhelpers.ExceptionThrowingExpression;
import org.junit.Test;
diff --git a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/ConcatExpressionTest.java b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/ConcatExpressionTest.java
index e7b408b..b491978 100644
--- a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/ConcatExpressionTest.java
+++ b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/ConcatExpressionTest.java
@@ -10,9 +10,9 @@ Contributors:
*/
package org.eclipse.xtend.backend.expr;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.SOURCE_POS;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.createEmptyExecutionContext;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.createLiteral;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.SOURCE_POS;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.createEmptyExecutionContext;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.createLiteral;
import static org.junit.Assert.assertEquals;
import java.util.Arrays;
@@ -23,7 +23,7 @@ import org.eclipse.xtend.backend.common.Helpers;
import org.eclipse.xtend.backend.common.NamedFunction;
import org.eclipse.xtend.backend.functions.FunctionDefContextFactory;
import org.eclipse.xtend.backend.functions.FunctionDefContextInternal;
-import org.eclipse.xtend.backend.helpers.NamedFunctionFactory;
+import org.eclipse.xtend.backend.testhelpers.NamedFunctionFactory;
import org.eclipse.xtend.backend.types.CompositeTypesystem;
import org.eclipse.xtend.backend.types.builtin.ObjectType;
import org.junit.Test;
diff --git a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/CreateCachedExpressionTest.java b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/CreateCachedExpressionTest.java
index 7444dc2..d3dff23 100644
--- a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/CreateCachedExpressionTest.java
+++ b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/CreateCachedExpressionTest.java
@@ -10,9 +10,9 @@ Contributors:
*/
package org.eclipse.xtend.backend.expr;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.SOURCE_POS;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.createEmptyExecutionContext;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.createLiteral;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.SOURCE_POS;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.createEmptyExecutionContext;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.createLiteral;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
diff --git a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/CreateUncachedExpressionTest.java b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/CreateUncachedExpressionTest.java
index a97629e..bd4bfa7 100644
--- a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/CreateUncachedExpressionTest.java
+++ b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/CreateUncachedExpressionTest.java
@@ -10,8 +10,8 @@ Contributors:
*/
package org.eclipse.xtend.backend.expr;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.SOURCE_POS;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.createEmptyExecutionContext;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.SOURCE_POS;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.createEmptyExecutionContext;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertTrue;
diff --git a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/HidingLocalVarDefExpressionTest.java b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/HidingLocalVarDefExpressionTest.java
index b38c7ff..9ff08bb 100644
--- a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/HidingLocalVarDefExpressionTest.java
+++ b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/HidingLocalVarDefExpressionTest.java
@@ -10,9 +10,9 @@ Contributors:
*/
package org.eclipse.xtend.backend.expr;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.SOURCE_POS;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.createEmptyExecutionContext;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.createLiteral;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.SOURCE_POS;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.createEmptyExecutionContext;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.createLiteral;
import static org.junit.Assert.assertEquals;
import org.eclipse.xtend.backend.common.ExecutionContext;
diff --git a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/IfExpressionTest.java b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/IfExpressionTest.java
index 12a8e4c..9da8784 100644
--- a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/IfExpressionTest.java
+++ b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/IfExpressionTest.java
@@ -10,13 +10,13 @@ Contributors:
*/
package org.eclipse.xtend.backend.expr;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.SOURCE_POS;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.createEmptyExecutionContext;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.createLiteral;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.SOURCE_POS;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.createEmptyExecutionContext;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.createLiteral;
import static org.junit.Assert.assertEquals;
import org.eclipse.xtend.backend.common.ExpressionBase;
-import org.eclipse.xtend.backend.helpers.MutableLiteralExpression;
+import org.eclipse.xtend.backend.testhelpers.MutableLiteralExpression;
import org.junit.Test;
diff --git a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/InitClosureExpressionTest.java b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/InitClosureExpressionTest.java
index d983329..79884f8 100644
--- a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/InitClosureExpressionTest.java
+++ b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/InitClosureExpressionTest.java
@@ -10,8 +10,8 @@ Contributors:
*/
package org.eclipse.xtend.backend.expr;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.SOURCE_POS;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.createEmptyExecutionContext;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.SOURCE_POS;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.createEmptyExecutionContext;
import static org.junit.Assert.assertEquals;
import java.util.ArrayList;
diff --git a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/InvocationOnCollectionExpressionTest.java b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/InvocationOnCollectionExpressionTest.java
index 3cc2d3d..7cbd285 100644
--- a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/InvocationOnCollectionExpressionTest.java
+++ b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/InvocationOnCollectionExpressionTest.java
@@ -10,9 +10,9 @@ Contributors:
*/
package org.eclipse.xtend.backend.expr;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.SOURCE_POS;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.createEmptyExecutionContext;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.createLiteral;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.SOURCE_POS;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.createEmptyExecutionContext;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.createLiteral;
import static org.junit.Assert.assertEquals;
import java.util.Arrays;
@@ -29,4 +29,8 @@ public class InvocationOnCollectionExpressionTest {
assertEquals (Arrays.asList (3L, 4L, 5L), new InvocationOnCollectionExpression (createLiteral (Arrays.asList(1L, 2L, 3L)), "operatorPlus", Arrays.asList (createLiteral (2L)), SOURCE_POS).evaluate (createEmptyExecutionContext ()));
assertEquals (null, new InvocationOnCollectionExpression (createLiteral (null), "operatorPlus", Arrays.asList (createLiteral (2L)), SOURCE_POS).evaluate (createEmptyExecutionContext ()));
}
+
+ @Test public void testFlatten () {
+ assertEquals (Arrays.asList("a","b","b","c","d"), new InvocationOnCollectionExpression (createLiteral (Arrays.asList ("a,b", "b,c,d")), "split", Arrays.asList (createLiteral (",")), SOURCE_POS).evaluate (createEmptyExecutionContext()));
+ }
}
diff --git a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/InvocationOnObjectExpressionTest.java b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/InvocationOnObjectExpressionTest.java
index 8a32985..6ca97ba 100644
--- a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/InvocationOnObjectExpressionTest.java
+++ b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/InvocationOnObjectExpressionTest.java
@@ -10,7 +10,7 @@ Contributors:
*/
package org.eclipse.xtend.backend.expr;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.*;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.*;
import static org.junit.Assert.*;
import java.util.Arrays;
@@ -26,10 +26,10 @@ public class InvocationOnObjectExpressionTest {
@Test public void testInvocation () {
assertEquals (3L, new InvocationOnObjectExpression ("operatorPlus", Arrays.asList (createLiteral (1L), createLiteral (2L)), false, SOURCE_POS).evaluate (createEmptyExecutionContext ()));
assertEquals (3L, new InvocationOnObjectExpression ("operatorPlus", Arrays.asList (createLiteral (1L), createLiteral (2L)), true, SOURCE_POS).evaluate (createEmptyExecutionContext ()));
- assertEquals (Arrays.asList (1L), new InvocationOnObjectExpression ("asList", Arrays.asList (createLiteral (Arrays.asList(1L))), false, SOURCE_POS).evaluate (createEmptyExecutionContext()));
- assertEquals (Arrays.asList (1L), new InvocationOnObjectExpression ("asList", Arrays.asList (createLiteral (Arrays.asList(1L))), true, SOURCE_POS).evaluate (createEmptyExecutionContext()));
+ assertEquals (Arrays.asList (1L), new InvocationOnObjectExpression ("toList", Arrays.asList (createLiteral (Arrays.asList(1L))), false, SOURCE_POS).evaluate (createEmptyExecutionContext()));
+ assertEquals (Arrays.asList (1L), new InvocationOnObjectExpression ("toList", Arrays.asList (createLiteral (Arrays.asList(1L))), true, SOURCE_POS).evaluate (createEmptyExecutionContext()));
- assertEquals (null, new InvocationOnObjectExpression ("asList", Arrays.asList (createLiteral (null)), true, SOURCE_POS).evaluate (createEmptyExecutionContext()));
+ assertEquals (null, new InvocationOnObjectExpression ("toList", Arrays.asList (createLiteral (null)), true, SOURCE_POS).evaluate (createEmptyExecutionContext()));
assertEquals (null, new InvocationOnObjectExpression ("operatorPlus", Arrays.asList (createLiteral (null), createLiteral (2L)), true, SOURCE_POS).evaluate (createEmptyExecutionContext()));
try {
diff --git a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/InvocationOnWhateverExpressionTest.java b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/InvocationOnWhateverExpressionTest.java
index 4b118b6..dd045be 100644
--- a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/InvocationOnWhateverExpressionTest.java
+++ b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/InvocationOnWhateverExpressionTest.java
@@ -10,9 +10,9 @@ Contributors:
*/
package org.eclipse.xtend.backend.expr;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.SOURCE_POS;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.createEmptyExecutionContext;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.createLiteral;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.SOURCE_POS;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.createEmptyExecutionContext;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.createLiteral;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
@@ -31,13 +31,13 @@ public class InvocationOnWhateverExpressionTest {
@Test public void testInvocationOnObject () {
assertEquals (3L, new InvocationOnWhateverExpression ("operatorPlus", Arrays.asList (createLiteral (1L), createLiteral (2L)), false, SOURCE_POS).evaluate (createEmptyExecutionContext ()));
assertEquals (3L, new InvocationOnWhateverExpression ("operatorPlus", Arrays.asList (createLiteral (1L), createLiteral (2L)), true, SOURCE_POS).evaluate (createEmptyExecutionContext ()));
- assertEquals (Arrays.asList (1L), new InvocationOnWhateverExpression ("asList", Arrays.asList (createLiteral (Arrays.asList(1L))), false, SOURCE_POS).evaluate (createEmptyExecutionContext()));
- assertEquals (Arrays.asList (1L), new InvocationOnWhateverExpression ("asList", Arrays.asList (createLiteral (Arrays.asList(1L))), true, SOURCE_POS).evaluate (createEmptyExecutionContext()));
+ assertEquals (Arrays.asList (1L), new InvocationOnWhateverExpression ("toList", Arrays.asList (createLiteral (Arrays.asList(1L))), false, SOURCE_POS).evaluate (createEmptyExecutionContext()));
+ assertEquals (Arrays.asList (1L), new InvocationOnWhateverExpression ("toList", Arrays.asList (createLiteral (Arrays.asList(1L))), true, SOURCE_POS).evaluate (createEmptyExecutionContext()));
- assertEquals (Arrays.asList (Collections.singleton (1L)), new InvocationOnWhateverExpression ("asList", Arrays.asList (createLiteral (Collections.singleton (Collections.singleton (1L)))), false, SOURCE_POS).evaluate (createEmptyExecutionContext()));
- assertEquals (Arrays.asList (Collections.singleton (1L)), new InvocationOnWhateverExpression ("asList", Arrays.asList (createLiteral (Collections.singleton (Collections.singleton (1L)))), true, SOURCE_POS).evaluate (createEmptyExecutionContext()));
+ assertEquals (Arrays.asList (Collections.singleton (1L)), new InvocationOnWhateverExpression ("toList", Arrays.asList (createLiteral (Collections.singleton (Collections.singleton (1L)))), false, SOURCE_POS).evaluate (createEmptyExecutionContext()));
+ assertEquals (Arrays.asList (Collections.singleton (1L)), new InvocationOnWhateverExpression ("toList", Arrays.asList (createLiteral (Collections.singleton (Collections.singleton (1L)))), true, SOURCE_POS).evaluate (createEmptyExecutionContext()));
- assertEquals (null, new InvocationOnWhateverExpression ("asList", Arrays.asList (createLiteral (null)), true, SOURCE_POS).evaluate (createEmptyExecutionContext()));
+ assertEquals (null, new InvocationOnWhateverExpression ("toList", Arrays.asList (createLiteral (null)), true, SOURCE_POS).evaluate (createEmptyExecutionContext()));
assertEquals (null, new InvocationOnWhateverExpression ("operatorPlus", Arrays.asList (createLiteral (null), createLiteral (2L)), true, SOURCE_POS).evaluate (createEmptyExecutionContext()));
try {
@@ -57,4 +57,8 @@ public class InvocationOnWhateverExpressionTest {
assertEquals (Arrays.asList (1L, 2L, 3L), new InvocationOnWhateverExpression ("operatorMinus", Arrays.asList (createLiteral (Arrays.asList (3L, 4L, 5L)), createLiteral (2L)), true, SOURCE_POS).evaluate (createEmptyExecutionContext ()));
assertEquals (Arrays.asList (1L, 2L, 3L), new InvocationOnWhateverExpression ("operatorMinus", Arrays.asList (createLiteral (Arrays.asList (3L, 4L, 5L)), createLiteral (2L)), false, SOURCE_POS).evaluate (createEmptyExecutionContext ()));
}
+
+ @Test public void testFlatten () {
+ assertEquals (Arrays.asList("a","b","b","c","d"), new InvocationOnWhateverExpression ("split", Arrays.asList (createLiteral (Arrays.asList ("a,b", "b,c,d")), createLiteral (",")), false, SOURCE_POS).evaluate (createEmptyExecutionContext()));
+ }
}
diff --git a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/ListLiteralExpressionTest.java b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/ListLiteralExpressionTest.java
index 67e5401..2e99bd8 100644
--- a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/ListLiteralExpressionTest.java
+++ b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/ListLiteralExpressionTest.java
@@ -10,9 +10,9 @@ Contributors:
*/
package org.eclipse.xtend.backend.expr;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.SOURCE_POS;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.createEmptyExecutionContext;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.createLiteral;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.SOURCE_POS;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.createEmptyExecutionContext;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.createLiteral;
import static org.junit.Assert.assertEquals;
import java.util.ArrayList;
diff --git a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/LiteralExpressionTest.java b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/LiteralExpressionTest.java
index f6ab2fd..cb0c626 100644
--- a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/LiteralExpressionTest.java
+++ b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/LiteralExpressionTest.java
@@ -10,8 +10,8 @@ Contributors:
*/
package org.eclipse.xtend.backend.expr;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.SOURCE_POS;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.createEmptyExecutionContext;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.SOURCE_POS;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.createEmptyExecutionContext;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
diff --git a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/LocalVarEvalExpressionTest.java b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/LocalVarEvalExpressionTest.java
index 5d66d58..e72268d 100644
--- a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/LocalVarEvalExpressionTest.java
+++ b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/LocalVarEvalExpressionTest.java
@@ -10,8 +10,8 @@ Contributors:
*/
package org.eclipse.xtend.backend.expr;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.SOURCE_POS;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.createEmptyExecutionContext;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.SOURCE_POS;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.createEmptyExecutionContext;
import static org.junit.Assert.assertEquals;
import org.eclipse.xtend.backend.common.ExecutionContext;
diff --git a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/NewLocalVarDefExpressionTest.java b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/NewLocalVarDefExpressionTest.java
index ef136f3..1858a5b 100644
--- a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/NewLocalVarDefExpressionTest.java
+++ b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/NewLocalVarDefExpressionTest.java
@@ -10,9 +10,9 @@ Contributors:
*/
package org.eclipse.xtend.backend.expr;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.SOURCE_POS;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.createEmptyExecutionContext;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.createLiteral;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.SOURCE_POS;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.createEmptyExecutionContext;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.createLiteral;
import static org.junit.Assert.*;
import org.eclipse.xtend.backend.common.ExecutionContext;
diff --git a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/OrExpressionTest.java b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/OrExpressionTest.java
index a5988c7..5969a48 100644
--- a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/OrExpressionTest.java
+++ b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/OrExpressionTest.java
@@ -10,10 +10,10 @@ Contributors:
*/
package org.eclipse.xtend.backend.expr;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.*;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.*;
import static org.junit.Assert.*;
-import org.eclipse.xtend.backend.helpers.ExceptionThrowingExpression;
+import org.eclipse.xtend.backend.testhelpers.ExceptionThrowingExpression;
import org.junit.Test;
diff --git a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/PropertyOnCollectionExpressionTest.java b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/PropertyOnCollectionExpressionTest.java
index 8365bed..df2ada8 100644
--- a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/PropertyOnCollectionExpressionTest.java
+++ b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/PropertyOnCollectionExpressionTest.java
@@ -10,14 +10,14 @@ Contributors:
*/
package org.eclipse.xtend.backend.expr;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.SOURCE_POS;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.createEmptyExecutionContext;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.createLiteral;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.SOURCE_POS;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.createEmptyExecutionContext;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.createLiteral;
import static org.junit.Assert.assertEquals;
import java.util.Arrays;
-import org.eclipse.xtend.backend.helpers.BeanWithSizeProperty;
+import org.eclipse.xtend.backend.testhelpers.BeanWithSizeProperty;
import org.junit.Test;
@@ -30,4 +30,8 @@ public class PropertyOnCollectionExpressionTest {
assertEquals (Arrays.asList (1L, 2L, 3L), new PropertyOnCollectionExpression (createLiteral (Arrays.asList ("a", "ab", "abc")), "length", SOURCE_POS).evaluate (createEmptyExecutionContext()));
assertEquals (Arrays.asList (7L, 12L), new PropertyOnCollectionExpression (createLiteral (Arrays.asList (new BeanWithSizeProperty (7), new BeanWithSizeProperty (12))), "size", SOURCE_POS).evaluate (createEmptyExecutionContext()));
}
+
+ @Test public void testFlatten () {
+ assertEquals (Arrays.asList("a0","a1","a0","a1","a2"), new PropertyOnCollectionExpression (createLiteral (Arrays.asList (new BeanWithSizeProperty (2), new BeanWithSizeProperty (3))), "chunks", SOURCE_POS).evaluate (createEmptyExecutionContext()));
+ }
}
diff --git a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/PropertyOnObjectExpressionTest.java b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/PropertyOnObjectExpressionTest.java
index 7ce530f..07ff8c9 100644
--- a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/PropertyOnObjectExpressionTest.java
+++ b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/PropertyOnObjectExpressionTest.java
@@ -10,14 +10,14 @@ Contributors:
*/
package org.eclipse.xtend.backend.expr;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.SOURCE_POS;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.createEmptyExecutionContext;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.createLiteral;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.SOURCE_POS;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.createEmptyExecutionContext;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.createLiteral;
import static org.junit.Assert.assertEquals;
import java.util.Arrays;
-import org.eclipse.xtend.backend.helpers.BeanWithSizeProperty;
+import org.eclipse.xtend.backend.testhelpers.BeanWithSizeProperty;
import org.junit.Test;
diff --git a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/PropertyOnWhateverExpressionTest.java b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/PropertyOnWhateverExpressionTest.java
index e863265..cc196c7 100644
--- a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/PropertyOnWhateverExpressionTest.java
+++ b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/PropertyOnWhateverExpressionTest.java
@@ -10,14 +10,14 @@ Contributors:
*/
package org.eclipse.xtend.backend.expr;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.SOURCE_POS;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.createEmptyExecutionContext;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.createLiteral;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.SOURCE_POS;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.createEmptyExecutionContext;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.createLiteral;
import static org.junit.Assert.assertEquals;
import java.util.Arrays;
-import org.eclipse.xtend.backend.helpers.BeanWithSizeProperty;
+import org.eclipse.xtend.backend.testhelpers.BeanWithSizeProperty;
import org.junit.Test;
@@ -37,4 +37,8 @@ public class PropertyOnWhateverExpressionTest {
private Object eval (Object param, String propertyName) {
return new PropertyOnWhateverExpression (createLiteral (param), propertyName, SOURCE_POS).evaluate (createEmptyExecutionContext());
}
+
+ @Test public void testFlatten () {
+ assertEquals (Arrays.asList("a0","a1","a0","a1","a2"), new PropertyOnWhateverExpression (createLiteral (Arrays.asList (new BeanWithSizeProperty (2), new BeanWithSizeProperty (3))), "chunks", SOURCE_POS).evaluate (createEmptyExecutionContext()));
+ }
}
diff --git a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/SequenceExpressionTest.java b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/SequenceExpressionTest.java
index 7f35df7..1028712 100644
--- a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/SequenceExpressionTest.java
+++ b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/SequenceExpressionTest.java
@@ -10,13 +10,13 @@ Contributors:
*/
package org.eclipse.xtend.backend.expr;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.SOURCE_POS;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.createEmptyExecutionContext;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.SOURCE_POS;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.createEmptyExecutionContext;
import static org.junit.Assert.assertEquals;
import java.util.Arrays;
-import org.eclipse.xtend.backend.helpers.CheckEvaluationExpression;
+import org.eclipse.xtend.backend.testhelpers.CheckEvaluationExpression;
import org.junit.Test;
diff --git a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/SetPropertyExpressionTest.java b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/SetPropertyExpressionTest.java
index 578388d..a001f9c 100644
--- a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/SetPropertyExpressionTest.java
+++ b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/SetPropertyExpressionTest.java
@@ -10,15 +10,15 @@ Contributors:
*/
package org.eclipse.xtend.backend.expr;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.SOURCE_POS;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.createEmptyExecutionContext;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.createLiteral;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.SOURCE_POS;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.createEmptyExecutionContext;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.createLiteral;
import static org.junit.Assert.*;
import java.util.ArrayList;
import org.eclipse.xtend.backend.common.ExecutionException;
-import org.eclipse.xtend.backend.helpers.BeanWithSizeProperty;
+import org.eclipse.xtend.backend.testhelpers.BeanWithSizeProperty;
import org.junit.Test;
diff --git a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/SwitchExpressionTest.java b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/SwitchExpressionTest.java
index 9c67d66..70347d8 100644
--- a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/SwitchExpressionTest.java
+++ b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/SwitchExpressionTest.java
@@ -10,8 +10,8 @@ Contributors:
*/
package org.eclipse.xtend.backend.expr;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.SOURCE_POS;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.createEmptyExecutionContext;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.SOURCE_POS;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.createEmptyExecutionContext;
import static org.junit.Assert.assertEquals;
import java.util.ArrayList;
@@ -22,8 +22,8 @@ import org.eclipse.xtend.backend.common.ExpressionBase;
import org.eclipse.xtend.backend.common.NamedFunction;
import org.eclipse.xtend.backend.functions.FunctionDefContextFactory;
import org.eclipse.xtend.backend.functions.FunctionDefContextInternal;
-import org.eclipse.xtend.backend.helpers.CheckEvaluationExpression;
-import org.eclipse.xtend.backend.helpers.NamedFunctionFactory;
+import org.eclipse.xtend.backend.testhelpers.CheckEvaluationExpression;
+import org.eclipse.xtend.backend.testhelpers.NamedFunctionFactory;
import org.eclipse.xtend.backend.types.CompositeTypesystem;
import org.eclipse.xtend.backend.types.builtin.StringType;
import org.eclipse.xtend.backend.util.Pair;
diff --git a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/functions/FunctionTest.java b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/functions/FunctionTest.java
index b64a07b..59088e3 100644
--- a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/functions/FunctionTest.java
+++ b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/functions/FunctionTest.java
@@ -10,7 +10,7 @@ Contributors:
*/
package org.eclipse.xtend.backend.functions;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.createEmptyExecutionContext;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.createEmptyExecutionContext;
import static org.junit.Assert.assertEquals;
import java.util.ArrayList;
@@ -19,8 +19,8 @@ import org.eclipse.xtend.backend.common.EfficientLazyString;
import org.eclipse.xtend.backend.common.ExecutionContext;
import org.eclipse.xtend.backend.common.NamedFunction;
import org.eclipse.xtend.backend.functions.java.JavaDefinedFunction;
-import org.eclipse.xtend.backend.helpers.CounterFunction;
-import org.eclipse.xtend.backend.helpers.NamedFunctionFactory;
+import org.eclipse.xtend.backend.testhelpers.CounterFunction;
+import org.eclipse.xtend.backend.testhelpers.NamedFunctionFactory;
import org.junit.Test;
diff --git a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/functions/JavaBuiltinConverterTest.java b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/functions/JavaBuiltinConverterTest.java
index 633b90d..f43df6b 100644
--- a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/functions/JavaBuiltinConverterTest.java
+++ b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/functions/JavaBuiltinConverterTest.java
@@ -10,12 +10,13 @@ Contributors:
*/
package org.eclipse.xtend.backend.functions;
-import static org.junit.Assert.*;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
import java.util.Arrays;
import java.util.List;
+import org.eclipse.xtend.backend.common.EfficientLazyString;
import org.eclipse.xtend.backend.functions.java.ParameterConverter;
import org.eclipse.xtend.backend.functions.java.internal.IntConverter;
import org.eclipse.xtend.backend.functions.java.internal.JavaBuiltinConverterFactory;
@@ -116,9 +117,22 @@ public class JavaBuiltinConverterTest {
checkEquals (new Character ('a'), JavaBuiltinConverterFactory.getConverter (Character.class).backendToJava ("a"));
checkEquals (null, JavaBuiltinConverterFactory.getConverter (Character.class).backendToJava (null));
+ checkEquals ("a", JavaBuiltinConverterFactory.getConverter (String.class).backendToJava (new StringBuilder ("a")));
+ checkEquals (null, JavaBuiltinConverterFactory.getConverter (String.class).backendToJava (null));
+
+ checkEquals (new StringBuilder ("a"), JavaBuiltinConverterFactory.getConverter (StringBuilder.class).backendToJava ("a"));
+ checkEquals (null, JavaBuiltinConverterFactory.getConverter (StringBuilder.class).backendToJava (null));
+
+ checkEquals (new StringBuffer ("a"), JavaBuiltinConverterFactory.getConverter (StringBuffer.class).backendToJava ("a"));
+ checkEquals (null, JavaBuiltinConverterFactory.getConverter (StringBuffer.class).backendToJava (null));
+
+ final EfficientLazyString els = (EfficientLazyString) JavaBuiltinConverterFactory.getConverter (EfficientLazyString.class).backendToJava ("a");
+ assertEquals ("a", els.toString());
+ checkEquals (null, JavaBuiltinConverterFactory.getConverter (EfficientLazyString.class).backendToJava (null));
+
checkEquals ("a", JavaBuiltinConverterFactory.getConverter (Character.TYPE).javaToBackend ('a'));
checkEquals ("a", JavaBuiltinConverterFactory.getConverter (Character.class).javaToBackend ('a'));
- checkEquals (null, JavaBuiltinConverterFactory.getConverter (Long.class).javaToBackend (null));
+ checkEquals (null, JavaBuiltinConverterFactory.getConverter (Character.class).javaToBackend (null));
}
@Test public void testList () {
@@ -126,11 +140,23 @@ public class JavaBuiltinConverterTest {
checkArraysEqual (new String[] {"a", "b", "c"}, (Object[]) JavaBuiltinConverterFactory.getConverter (new String[0].getClass()).backendToJava(Arrays.asList("a", "b", "c")));
}
+
+ /**
+ * This is necessary because JUnit's assertEquals is lenient in comparing numbers - it always compares their longValue, and
+ * since we are testing type conversion here, that's not what we want ;-)
+ */
private void checkEquals (Object o1, Object o2) {
if (o1 == null)
assertTrue (o2 == null);
- else
- assertTrue (o1.equals (o2));
+ else {
+ assertEquals (o1.getClass(), o2.getClass());
+
+ // this is necessary because some CharSequence implementations do not have equals methods, e.g. StringBuilder ;-(
+ if (o1 instanceof CharSequence)
+ assertEquals (o1.toString(), o2.toString());
+ else
+ assertEquals (o1, o2);
+ }
}
private void checkArraysEqual (Object[] a1, Object[] a2) {
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 97ea3a1..4746e33 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
@@ -10,7 +10,7 @@ Contributors:
*/
package org.eclipse.xtend.backend.functions;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.createEmptyExecutionContext;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.createEmptyExecutionContext;
import static org.junit.Assert.assertEquals;
import java.util.Arrays;
diff --git a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/syslib/OverrideTest.java b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/syslib/OverrideTest.java
index fdba06d..88d69cc 100644
--- a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/syslib/OverrideTest.java
+++ b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/syslib/OverrideTest.java
@@ -10,9 +10,9 @@ Contributors:
*/
package org.eclipse.xtend.backend.syslib;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.SOURCE_POS;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.createEmptyExecutionContext;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.createLiteral;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.SOURCE_POS;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.createEmptyExecutionContext;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.createLiteral;
import static org.junit.Assert.assertEquals;
import java.util.Arrays;
@@ -23,7 +23,7 @@ import org.eclipse.xtend.backend.common.NamedFunction;
import org.eclipse.xtend.backend.expr.ConcatExpression;
import org.eclipse.xtend.backend.functions.FunctionDefContextFactory;
import org.eclipse.xtend.backend.functions.FunctionDefContextInternal;
-import org.eclipse.xtend.backend.helpers.NamedFunctionFactory;
+import org.eclipse.xtend.backend.testhelpers.NamedFunctionFactory;
import org.eclipse.xtend.backend.types.CompositeTypesystem;
import org.eclipse.xtend.backend.types.builtin.LongType;
import org.eclipse.xtend.backend.types.builtin.ObjectType;
diff --git a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/helpers/BackendTestHelper.java b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/testhelpers/BackendTestHelper.java
index 2c770bb..d89e281 100644
--- a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/helpers/BackendTestHelper.java
+++ b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/testhelpers/BackendTestHelper.java
@@ -8,7 +8,7 @@ http://www.eclipse.org/legal/epl-v10.html
Contributors:
Arno Haase - initial API and implementation
*/
-package org.eclipse.xtend.backend.helpers;
+package org.eclipse.xtend.backend.testhelpers;
import org.eclipse.xtend.backend.BackendFacade;
import org.eclipse.xtend.backend.common.BackendTypesystem;
diff --git a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/helpers/BeanWithSizeProperty.java b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/testhelpers/BeanWithSizeProperty.java
index 597c652..0c7ee1e 100644
--- a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/helpers/BeanWithSizeProperty.java
+++ b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/testhelpers/BeanWithSizeProperty.java
@@ -8,7 +8,10 @@ http://www.eclipse.org/legal/epl-v10.html
Contributors:
Arno Haase - initial API and implementation
*/
-package org.eclipse.xtend.backend.helpers;
+package org.eclipse.xtend.backend.testhelpers;
+
+import java.util.ArrayList;
+import java.util.List;
/**
@@ -30,4 +33,22 @@ public class BeanWithSizeProperty {
public void setSize (long size) {
_size = size;
}
+
+ public List<String> getChunks () {
+ final List<String> result = new ArrayList<String>();
+
+ for (int i=0; i<_size; i++)
+ result.add ("a" + i);
+
+ return result;
+ }
+
+ public Object myFunction (StringBuilder s, int i) {
+ return "asdf" + s + getSize() + " - " + (getSize() - i);
+ }
+
+ @Override
+ public String toString () {
+ return "BeanWithSize [" + _size + "]";
+ }
}
diff --git a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/helpers/CheckEvaluationExpression.java b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/testhelpers/CheckEvaluationExpression.java
index aaf830e..94ba6de 100644
--- a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/helpers/CheckEvaluationExpression.java
+++ b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/testhelpers/CheckEvaluationExpression.java
@@ -8,9 +8,9 @@ http://www.eclipse.org/legal/epl-v10.html
Contributors:
Arno Haase - initial API and implementation
*/
-package org.eclipse.xtend.backend.helpers;
+package org.eclipse.xtend.backend.testhelpers;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.*;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.*;
import org.eclipse.xtend.backend.common.ExecutionContext;
import org.eclipse.xtend.backend.common.ExpressionBase;
diff --git a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/helpers/CounterFunction.java b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/testhelpers/CounterFunction.java
index a16e74d..5c4c44b 100644
--- a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/helpers/CounterFunction.java
+++ b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/testhelpers/CounterFunction.java
@@ -1,4 +1,4 @@
-package org.eclipse.xtend.backend.helpers;
+package org.eclipse.xtend.backend.testhelpers;
public class CounterFunction {
diff --git a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/helpers/ExceptionThrowingExpression.java b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/testhelpers/ExceptionThrowingExpression.java
index 5cb6ae8..4d8c6c4 100644
--- a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/helpers/ExceptionThrowingExpression.java
+++ b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/testhelpers/ExceptionThrowingExpression.java
@@ -8,7 +8,7 @@ http://www.eclipse.org/legal/epl-v10.html
Contributors:
Arno Haase - initial API and implementation
*/
-package org.eclipse.xtend.backend.helpers;
+package org.eclipse.xtend.backend.testhelpers;
import org.eclipse.xtend.backend.common.ExecutionContext;
import org.eclipse.xtend.backend.common.ExpressionBase;
diff --git a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/helpers/MutableLiteralExpression.java b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/testhelpers/MutableLiteralExpression.java
index cd4ad5c..a1945dc 100644
--- a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/helpers/MutableLiteralExpression.java
+++ b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/testhelpers/MutableLiteralExpression.java
@@ -8,7 +8,7 @@ http://www.eclipse.org/legal/epl-v10.html
Contributors:
Arno Haase - initial API and implementation
*/
-package org.eclipse.xtend.backend.helpers;
+package org.eclipse.xtend.backend.testhelpers;
import org.eclipse.xtend.backend.common.ExecutionContext;
import org.eclipse.xtend.backend.common.ExpressionBase;
diff --git a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/helpers/NamedFunctionFactory.java b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/testhelpers/NamedFunctionFactory.java
index 4d45c24..d94c446 100644
--- a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/helpers/NamedFunctionFactory.java
+++ b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/testhelpers/NamedFunctionFactory.java
@@ -8,7 +8,7 @@ http://www.eclipse.org/legal/epl-v10.html
Contributors:
Arno Haase - initial API and implementation
*/
-package org.eclipse.xtend.backend.helpers;
+package org.eclipse.xtend.backend.testhelpers;
import java.util.Arrays;
import java.util.List;
diff --git a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/types/AbstractTypeTest.java b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/types/AbstractTypeTest.java
index b551fec..c075840 100644
--- a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/types/AbstractTypeTest.java
+++ b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/types/AbstractTypeTest.java
@@ -11,7 +11,7 @@ Contributors:
package org.eclipse.xtend.backend.types;
import static org.junit.Assert.*;
-import static org.eclipse.xtend.backend.helpers.BackendTestHelper.*;
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.*;
import java.util.Arrays;
diff --git a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/types/JavaBeansTypeTest.java b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/types/JavaBeansTypeTest.java
new file mode 100644
index 0000000..7078414
--- /dev/null
+++ b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/types/JavaBeansTypeTest.java
@@ -0,0 +1,32 @@
+/*
+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.types;
+
+import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.createEmptyExecutionContext;
+import static org.junit.Assert.assertEquals;
+
+import java.util.Arrays;
+
+import org.eclipse.xtend.backend.common.ExecutionContext;
+import org.eclipse.xtend.backend.testhelpers.BeanWithSizeProperty;
+import org.junit.Test;
+
+/**
+ *
+ * @author Arno Haase (http://www.haase-consulting.com)
+ */
+public class JavaBeansTypeTest {
+ @Test public void testInvokeWithConversion () {
+ final ExecutionContext ctx = createEmptyExecutionContext();
+
+ assertEquals ("asdfabc7 - 2", ctx.getFunctionDefContext().invoke (ctx, "myFunction", Arrays.asList(new BeanWithSizeProperty(7), "abc", 5L)));
+ }
+}