summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorahaase2008-01-31 21:28:35 (EST)
committer ahaase2008-01-31 21:28:35 (EST)
commit0c15f55c63f5f70a32ecd2de2fcdec36d9b5dd64 (patch)
tree7f3e77da9bb8b9afe4820f224f1f2e641d5771f1
parent6b8457f38fc9c9f9fec942157b81386587d3c67e (diff)
downloadorg.eclipse.xpand-0c15f55c63f5f70a32ecd2de2fcdec36d9b5dd64.zip
org.eclipse.xpand-0c15f55c63f5f70a32ecd2de2fcdec36d9b5dd64.tar.gz
org.eclipse.xpand-0c15f55c63f5f70a32ecd2de2fcdec36d9b5dd64.tar.bz2
added tests for implicit conversion to and from non-canonical Java types
-rw-r--r--plugins/org.eclipse.xtend.backend/META-INF/MANIFEST.MF1
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/FunctionDefContextInternal.java2
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/internal/FunctionDefContextImpl.java2
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/ConcatExpressionTest.java20
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/SwitchExpressionTest.java22
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/functions/FunctionTest.java79
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/functions/JavaBuiltinConverterTest.java142
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/helpers/CounterFunction.java10
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/helpers/NamedFunctionFactory.java56
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/syslib/OverrideTest.java67
-rw-r--r--tests/org.eclipse.xtend.backend.test/todo.txt14
11 files changed, 365 insertions, 50 deletions
diff --git a/plugins/org.eclipse.xtend.backend/META-INF/MANIFEST.MF b/plugins/org.eclipse.xtend.backend/META-INF/MANIFEST.MF
index ae4c0f6..d259f77 100644
--- a/plugins/org.eclipse.xtend.backend/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.xtend.backend/META-INF/MANIFEST.MF
@@ -9,6 +9,7 @@ Export-Package: org.eclipse.xtend.backend;uses:="org.eclipse.xtend.backend.commo
org.eclipse.xtend.backend.functions;uses:="org.eclipse.xtend.backend.common",
org.eclipse.xtend.backend.functions.internal;x-friends:="org.eclipse.xtend.backend.test",
org.eclipse.xtend.backend.functions.java;uses:="org.eclipse.xtend.backend.iface,org.eclipse.xtend.backend.common",
+ org.eclipse.xtend.backend.functions.java.internal;x-friends:="org.eclipse.xtend.backend.test",
org.eclipse.xtend.backend.syslib,
org.eclipse.xtend.backend.types;uses:="org.eclipse.xtend.backend.common",
org.eclipse.xtend.backend.types.builtin;uses:="org.eclipse.xtend.backend.common,org.eclipse.xtend.backend.types",
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/FunctionDefContextInternal.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/FunctionDefContextInternal.java
index 7946133..9492584 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/FunctionDefContextInternal.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/FunctionDefContextInternal.java
@@ -25,5 +25,5 @@ import org.eclipse.xtend.backend.common.NamedFunction;
*/
public interface FunctionDefContextInternal extends FunctionDefContext {
void register (NamedFunction f);
- void register (Collection <NamedFunction> f);
+ void register (Collection <? extends NamedFunction> f);
}
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 6fd00bf..e0fece3 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
@@ -87,7 +87,7 @@ public final class FunctionDefContextImpl implements FunctionDefContextInternal
}
};
- public void register (Collection<NamedFunction> functions) {
+ public void register (Collection<? extends NamedFunction> functions) {
for (NamedFunction f: functions)
register (f);
}
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 18b6725..e7b408b 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
@@ -16,16 +16,14 @@ import static org.eclipse.xtend.backend.helpers.BackendTestHelper.createLiteral;
import static org.junit.Assert.assertEquals;
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.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.types.CompositeTypesystem;
import org.eclipse.xtend.backend.types.builtin.ObjectType;
import org.junit.Test;
@@ -51,23 +49,11 @@ public class ConcatExpressionTest {
}
@Test public void testUsesToStringExtension () {
- final NamedFunction myToString = new NamedFunction (Helpers.TO_STRING_METHOD_NAME, new Function () {
- public ExpressionBase getGuard () {
- return null;
- }
-
- public List<? extends BackendType> getParameterTypes () {
- return Arrays.asList (ObjectType.INSTANCE);
- }
-
+ final NamedFunction myToString = new NamedFunctionFactory (Helpers.TO_STRING_METHOD_NAME, ObjectType.INSTANCE) {
public Object invoke (ExecutionContext ctx, Object[] params) {
return "#" + params[0] + "!";
}
-
- public boolean isCached () {
- return false;
- }
- });
+ }.create();
final FunctionDefContextInternal fdc = new FunctionDefContextFactory (new CompositeTypesystem ()).create();
fdc.register (myToString);
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 5f70b92..9c67d66 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
@@ -15,17 +15,15 @@ import static org.eclipse.xtend.backend.helpers.BackendTestHelper.createEmptyExe
import static org.junit.Assert.assertEquals;
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.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.types.CompositeTypesystem;
import org.eclipse.xtend.backend.types.builtin.StringType;
import org.eclipse.xtend.backend.util.Pair;
@@ -106,25 +104,11 @@ public class SwitchExpressionTest {
// register an equals function that returns "true" for any two strings
- final NamedFunction myStringEquals = new NamedFunction ("operatorEquals", new Function () {
-
- public ExpressionBase getGuard () {
- return null;
- }
-
- public List<? extends BackendType> getParameterTypes () {
- return Arrays.asList(StringType.INSTANCE, StringType.INSTANCE);
- }
-
+ final NamedFunction myStringEquals = new NamedFunctionFactory ("operatorEquals", StringType.INSTANCE, StringType.INSTANCE) {
public Object invoke (ExecutionContext ctx, Object[] params) {
- System.err.println ("!!!");
return true;
}
-
- public boolean isCached () {
- return false;
- }
- });
+ }.create();
final FunctionDefContextInternal fdc = new FunctionDefContextFactory (new CompositeTypesystem ()).create();
fdc.register (myStringEquals);
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
new file mode 100644
index 0000000..b64a07b
--- /dev/null
+++ b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/functions/FunctionTest.java
@@ -0,0 +1,79 @@
+/*
+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;
+
+import static org.eclipse.xtend.backend.helpers.BackendTestHelper.createEmptyExecutionContext;
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+
+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.junit.Test;
+
+
+/**
+ *
+ * @author Arno Haase (http://www.haase-consulting.com)
+ */
+public class FunctionTest {
+ @Test public void testCachedAndSingleInstance () {
+ final ExecutionContext ctx = createEmptyExecutionContext ();
+
+ final FunctionDefContextInternal fdc = new FunctionDefContextFactory (ctx.getTypesystem()).create();
+ ctx.setFunctionDefContext (fdc);
+
+ for (JavaDefinedFunction f: JavaDefinedFunction.createForEntireClass (CounterFunction.class, ctx.getTypesystem()))
+ fdc.register (new NamedFunction (f.getName(), f));
+
+ fdc.register (new NamedFunctionFactory ("myCached", true) {
+ public Object invoke (ExecutionContext innerCtx, Object[] params) {
+ return innerCtx.getFunctionDefContext().invoke (innerCtx, "nextCounterValue", new ArrayList<Object> ());
+ }
+ }.create());
+ fdc.register (new NamedFunctionFactory ("myUncached", false) {
+ public Object invoke (ExecutionContext innerCtx, Object[] params) {
+ return innerCtx.getFunctionDefContext().invoke (innerCtx, "nextCounterValue", new ArrayList<Object> ());
+ }
+ }.create());
+
+ assertEquals (0L, fdc.invoke (ctx, "myUncached", new ArrayList<Object> ()));
+ assertEquals (1L, fdc.invoke (ctx, "myUncached", new ArrayList<Object> ()));
+ assertEquals (2L, fdc.invoke (ctx, "myCached", new ArrayList<Object> ()));
+ assertEquals (2L, fdc.invoke (ctx, "myCached", new ArrayList<Object> ()));
+ assertEquals (3L, fdc.invoke (ctx, "myUncached", new ArrayList<Object> ()));
+ assertEquals (2L, fdc.invoke (ctx, "myCached", new ArrayList<Object> ()));
+ assertEquals (4L, fdc.invoke (ctx, "myUncached", new ArrayList<Object> ()));
+ assertEquals (2L, fdc.invoke (ctx, "myCached", new ArrayList<Object> ()));
+ }
+
+ @Test public void testImmutableCachedStringResult () {
+ final ExecutionContext ctx = createEmptyExecutionContext ();
+
+ final FunctionDefContextInternal fdc = new FunctionDefContextFactory (ctx.getTypesystem()).create();
+ ctx.setFunctionDefContext (fdc);
+
+ fdc.register (new NamedFunctionFactory ("myCached", true) {
+ public Object invoke (ExecutionContext innerCtx, Object[] params) {
+ final EfficientLazyString result = new EfficientLazyString ();
+ return EfficientLazyString.createAppendedString (result, "Hi Arno");
+ }
+ }.create());
+
+ assertEquals ("Hi Arno", fdc.invoke (ctx, "myCached", new ArrayList<Object> ()).toString());
+ EfficientLazyString.createAppendedString ((EfficientLazyString) fdc.invoke (ctx, "myCached", new ArrayList<Object> ()), "... and something else");
+ assertEquals ("Hi Arno", fdc.invoke (ctx, "myCached", new ArrayList<Object> ()).toString());
+ }
+}
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
new file mode 100644
index 0000000..633b90d
--- /dev/null
+++ b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/functions/JavaBuiltinConverterTest.java
@@ -0,0 +1,142 @@
+/*
+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;
+
+import static org.junit.Assert.*;
+import static org.eclipse.xtend.backend.helpers.BackendTestHelper.*;
+
+import java.util.Arrays;
+import java.util.List;
+
+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;
+import org.eclipse.xtend.backend.types.builtin.DoubleType;
+import org.eclipse.xtend.backend.types.builtin.ListType;
+import org.eclipse.xtend.backend.types.builtin.LongType;
+import org.eclipse.xtend.backend.types.builtin.StringType;
+import org.junit.Test;
+
+
+/**
+ *
+ * @author Arno Haase (http://www.haase-consulting.com)
+ */
+public class JavaBuiltinConverterTest {
+ @Test public void testParameterConverter () {
+ checkEquals (null, JavaBuiltinConverterFactory.getParameterConverter (Long.class, 0));
+ checkEquals (null, JavaBuiltinConverterFactory.getParameterConverter (Long.TYPE, 0));
+ checkEquals (null, JavaBuiltinConverterFactory.getParameterConverter (Double.class, 0));
+ checkEquals (null, JavaBuiltinConverterFactory.getParameterConverter (Double.TYPE, 0));
+ checkEquals (null, JavaBuiltinConverterFactory.getParameterConverter (List.class, 0));
+ checkEquals (null, JavaBuiltinConverterFactory.getParameterConverter (CharSequence.class, 0));
+
+ final ParameterConverter pc = new ParameterConverter (2, IntConverter.INSTANCE);
+
+ final Object[] p = new Object[] {1L, 2L, 3L, 4L, 5L};
+ pc.convert(p);
+ checkEquals (1L, p[0]);
+ checkEquals (2L, p[1]);
+ checkEquals (3, p[2]);
+ checkEquals (4L, p[3]);
+ checkEquals (5L, p[4]);
+ }
+
+ @Test public void testTypeäForAdditionalBuiltin () {
+ checkEquals (LongType.INSTANCE, JavaBuiltinConverterFactory.getTypeForAdditionalBuiltin (Integer.class));
+ checkEquals (LongType.INSTANCE, JavaBuiltinConverterFactory.getTypeForAdditionalBuiltin (Integer.TYPE));
+ checkEquals (LongType.INSTANCE, JavaBuiltinConverterFactory.getTypeForAdditionalBuiltin (Short.class));
+ checkEquals (LongType.INSTANCE, JavaBuiltinConverterFactory.getTypeForAdditionalBuiltin (Short.TYPE));
+ checkEquals (LongType.INSTANCE, JavaBuiltinConverterFactory.getTypeForAdditionalBuiltin (Byte.class));
+ checkEquals (LongType.INSTANCE, JavaBuiltinConverterFactory.getTypeForAdditionalBuiltin (Byte.TYPE));
+
+ checkEquals (DoubleType.INSTANCE, JavaBuiltinConverterFactory.getTypeForAdditionalBuiltin (Float.class));
+ checkEquals (DoubleType.INSTANCE, JavaBuiltinConverterFactory.getTypeForAdditionalBuiltin (Float.TYPE));
+
+ checkEquals (StringType.INSTANCE, JavaBuiltinConverterFactory.getTypeForAdditionalBuiltin (Character.class));
+ checkEquals (StringType.INSTANCE, JavaBuiltinConverterFactory.getTypeForAdditionalBuiltin (Character.TYPE));
+
+ checkEquals (ListType.INSTANCE, JavaBuiltinConverterFactory.getTypeForAdditionalBuiltin (new Object[]{}.getClass()));
+ }
+
+ @Test public void testLong () {
+ checkEquals (new Long (4), JavaBuiltinConverterFactory.getConverter (Long.TYPE).backendToJava (4L));
+ checkEquals (new Long (4), JavaBuiltinConverterFactory.getConverter (Long.class).backendToJava (4L));
+ checkEquals (null, JavaBuiltinConverterFactory.getConverter (Long.class).backendToJava (null));
+
+ checkEquals (new Integer (4), JavaBuiltinConverterFactory.getConverter (Integer.TYPE).backendToJava (4L));
+ checkEquals (new Integer (4), JavaBuiltinConverterFactory.getConverter (Integer.class).backendToJava (4L));
+ checkEquals (null, JavaBuiltinConverterFactory.getConverter (Integer.class).backendToJava (null));
+
+ checkEquals (new Short ((short) 4), JavaBuiltinConverterFactory.getConverter (Short.TYPE).backendToJava (4L));
+ checkEquals (new Short ((short) 4), JavaBuiltinConverterFactory.getConverter (Short.class).backendToJava (4L));
+ checkEquals (null, JavaBuiltinConverterFactory.getConverter (Short.class).backendToJava (null));
+
+ checkEquals (new Byte ((byte) 4), JavaBuiltinConverterFactory.getConverter (Byte.TYPE).backendToJava (4L));
+ checkEquals (new Byte ((byte) 4), JavaBuiltinConverterFactory.getConverter (Byte.class).backendToJava (4L));
+ checkEquals (null, JavaBuiltinConverterFactory.getConverter (Byte.class).backendToJava (null));
+
+ checkEquals (new Long (4), JavaBuiltinConverterFactory.getConverter (Long.TYPE).javaToBackend (4L));
+ checkEquals (new Long (4), JavaBuiltinConverterFactory.getConverter (Long.class).javaToBackend (4L));
+ checkEquals (null, JavaBuiltinConverterFactory.getConverter (Long.class).javaToBackend (null));
+
+ checkEquals (new Long(4), JavaBuiltinConverterFactory.getConverter (Integer.TYPE).javaToBackend (new Integer (4)));
+ checkEquals (new Long (4), JavaBuiltinConverterFactory.getConverter (Integer.class).javaToBackend (new Integer (4)));
+ checkEquals (null, JavaBuiltinConverterFactory.getConverter (Integer.class).javaToBackend (null));
+
+ checkEquals (new Long (4), JavaBuiltinConverterFactory.getConverter (Short.TYPE).javaToBackend ((short) 4));
+ checkEquals (new Long (4), JavaBuiltinConverterFactory.getConverter (Short.class).javaToBackend ((short) 4));
+ checkEquals (null, JavaBuiltinConverterFactory.getConverter (Short.class).javaToBackend (null));
+
+ checkEquals (new Long (4), JavaBuiltinConverterFactory.getConverter (Byte.TYPE).javaToBackend ((byte) 4));
+ checkEquals (new Long (4), JavaBuiltinConverterFactory.getConverter (Byte.class).javaToBackend ((byte) 4));
+ checkEquals (null, JavaBuiltinConverterFactory.getConverter (Byte.class).javaToBackend (null));
+ }
+
+ @Test public void testDouble () {
+ checkEquals (new Float (4), JavaBuiltinConverterFactory.getConverter (Float.TYPE).backendToJava (4.0));
+ checkEquals (new Float (4), JavaBuiltinConverterFactory.getConverter (Float.class).backendToJava (4.0));
+ checkEquals (null, JavaBuiltinConverterFactory.getConverter (Float.class).backendToJava (null));
+
+ checkEquals (new Double (4), JavaBuiltinConverterFactory.getConverter (Float.TYPE).javaToBackend (4.0f));
+ checkEquals (new Double (4), JavaBuiltinConverterFactory.getConverter (Float.class).javaToBackend (4.0f));
+ checkEquals (null, JavaBuiltinConverterFactory.getConverter (Float.class).javaToBackend (null));
+ }
+
+ @Test public void testString () {
+ checkEquals (new Character ('a'), JavaBuiltinConverterFactory.getConverter (Character.TYPE).backendToJava ("a"));
+ checkEquals (new Character ('a'), JavaBuiltinConverterFactory.getConverter (Character.class).backendToJava ("a"));
+ checkEquals (null, JavaBuiltinConverterFactory.getConverter (Character.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));
+ }
+
+ @Test public void testList () {
+ checkArraysEqual (new Long[] {1L, 2L, 3L}, (Object[]) JavaBuiltinConverterFactory.getConverter (new Long[0].getClass()).backendToJava(Arrays.asList(1L, 2L, 3L)));
+ checkArraysEqual (new String[] {"a", "b", "c"}, (Object[]) JavaBuiltinConverterFactory.getConverter (new String[0].getClass()).backendToJava(Arrays.asList("a", "b", "c")));
+ }
+
+ private void checkEquals (Object o1, Object o2) {
+ if (o1 == null)
+ assertTrue (o2 == null);
+ else
+ assertTrue (o1.equals (o2));
+ }
+
+ private void checkArraysEqual (Object[] a1, Object[] a2) {
+ assertEquals (a1.length, a2.length);
+ assertEquals (a1.getClass(), a2.getClass());
+ assertEquals (a1.getClass().getComponentType(), a2.getClass().getComponentType());
+ assertEquals (Arrays.asList(a1), Arrays.asList(a2));
+ }
+}
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/helpers/CounterFunction.java
new file mode 100644
index 0000000..a16e74d
--- /dev/null
+++ b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/helpers/CounterFunction.java
@@ -0,0 +1,10 @@
+package org.eclipse.xtend.backend.helpers;
+
+
+public class CounterFunction {
+ private int _counter = 0;
+
+ public int nextCounterValue () {
+ return _counter++;
+ }
+}
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/helpers/NamedFunctionFactory.java
new file mode 100644
index 0000000..4d45c24
--- /dev/null
+++ b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/helpers/NamedFunctionFactory.java
@@ -0,0 +1,56 @@
+/*
+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.helpers;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.xtend.backend.common.BackendType;
+import org.eclipse.xtend.backend.common.ExpressionBase;
+import org.eclipse.xtend.backend.common.Function;
+import org.eclipse.xtend.backend.common.NamedFunction;
+
+
+/**
+ *
+ * @author Arno Haase (http://www.haase-consulting.com)
+ */
+public abstract class NamedFunctionFactory implements Function {
+ private final String _name;
+ private final List<BackendType> _parameterTypes;
+ private final boolean _cached;
+
+ public NamedFunctionFactory (String name, BackendType... paramTypes) {
+ this (name, false, paramTypes);
+ }
+
+ public NamedFunction create () {
+ return new NamedFunction (_name, this);
+ }
+
+ public NamedFunctionFactory (String name, boolean cached, BackendType... paramTypes) {
+ _name = name;
+ _cached = cached;
+ _parameterTypes = Arrays.asList (paramTypes);
+ }
+
+ public ExpressionBase getGuard () {
+ return null;
+ }
+
+ public List<? extends BackendType> getParameterTypes () {
+ return _parameterTypes;
+ }
+
+ public boolean isCached () {
+ return _cached;
+ }
+}
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
new file mode 100644
index 0000000..fdba06d
--- /dev/null
+++ b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/syslib/OverrideTest.java
@@ -0,0 +1,67 @@
+/*
+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.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.junit.Assert.assertEquals;
+
+import java.util.Arrays;
+
+import org.eclipse.xtend.backend.common.ExecutionContext;
+import org.eclipse.xtend.backend.common.ExpressionBase;
+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.types.CompositeTypesystem;
+import org.eclipse.xtend.backend.types.builtin.LongType;
+import org.eclipse.xtend.backend.types.builtin.ObjectType;
+import org.junit.Test;
+
+
+/**
+ *
+ * @author Arno Haase (http://www.haase-consulting.com)
+ */
+public class OverrideTest {
+ /**
+ * This method tests that it is possible to override a function from the syslib by
+ * contributing another function of the same signature to the fdc.
+ */
+ @Test public void testOverride () {
+ final NamedFunction myLongToString = new NamedFunctionFactory ("toString", LongType.INSTANCE) {
+ public Object invoke (ExecutionContext ctx, Object[] params) {
+ return "Long<" + params[0] + ">";
+ }
+ }.create();
+ final NamedFunction myObjectToString = new NamedFunctionFactory ("toString", ObjectType.INSTANCE) {
+ public Object invoke (ExecutionContext ctx, Object[] params) {
+ return "Object<" + params[0] + ">";
+ }
+ }.create();
+
+ final ExpressionBase expr = new ConcatExpression (Arrays.asList (createLiteral (25L), createLiteral ("Abc")), SOURCE_POS);
+
+ final FunctionDefContextInternal fdc = new FunctionDefContextFactory (new CompositeTypesystem ()).create();
+ fdc.register (myLongToString);
+ fdc.register (myObjectToString);
+
+ final ExecutionContext ctx = createEmptyExecutionContext();
+ assertEquals ("25Abc", expr.evaluate (ctx).toString());
+
+ ctx.setFunctionDefContext(fdc);
+ assertEquals ("Long<25>Object<Abc>", expr.evaluate (ctx).toString());
+
+ }
+}
diff --git a/tests/org.eclipse.xtend.backend.test/todo.txt b/tests/org.eclipse.xtend.backend.test/todo.txt
index 9727ea9..3f81f5b 100644
--- a/tests/org.eclipse.xtend.backend.test/todo.txt
+++ b/tests/org.eclipse.xtend.backend.test/todo.txt
@@ -1,25 +1,15 @@
todo
----
-overriding of syslib functions by functions registered later
-cached functions
-properties are inherited (--> List.size)
-overwriting of extensions, e.g. syslib
-eine Instanz je JavaDefinedFunction-Klasse
-creation cache
-immutable auf cached-ergebnis
-polymorphic resolver
-efficientLazyString: streaming
-Java-Type <--> Cacnonical type
-expression-Implementierungen
Aufruf der Listener
CurriedFunction, CurryingExpression
GlobalParamExpression
-
Verwendung von syslib für toString: operatorPlus,
syslib-Implementierungen
Schreiben in Files
+EmfTypesystem
+
Xpand und Xtend: Middleends...