summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorahaase2008-01-31 17:36:18 (EST)
committerahaase2008-01-31 17:36:18 (EST)
commit735d9e314a2045dfe0085c21b6fbda729bdb685f (patch)
treec1424a1a09e94334d728719ec1a66182005a7b7b
parenta343b56857b67317dced1afc2100ded643a7bb75 (diff)
downloadorg.eclipse.xpand-735d9e314a2045dfe0085c21b6fbda729bdb685f.zip
org.eclipse.xpand-735d9e314a2045dfe0085c21b6fbda729bdb685f.tar.gz
org.eclipse.xpand-735d9e314a2045dfe0085c21b6fbda729bdb685f.tar.bz2
added more tests; refactored the backend to separate internal API
-rw-r--r--plugins/org.eclipse.xtend.backend/META-INF/MANIFEST.MF16
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/expr/InitClosureExpression.java2
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/FunctionDefContextFactory.java (renamed from plugins/org.eclipse.xtend.middleend/src/org/eclipose/xtend/middleend/FunctionDefContextFactory.java)11
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/FunctionDefContextInternal.java29
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/internal/Closure.java (renamed from plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/Closure.java)2
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/internal/FunctionDefContextImpl.java (renamed from plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/FunctionDefContextImpl.java)22
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/internal/PolymorphicResolver.java (renamed from plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/PolymorphicResolver.java)6
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/internal/TypesComparator.java (renamed from plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/TypesComparator.java)4
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/ByteConverter.java18
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/CharConverter.java19
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/FloatConverter.java18
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/IntConverter.java18
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/JavaBuiltinConverter.java17
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/JavaDefinedFunction.java2
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/JavaFunctionClassContributor.java8
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/NullConverter.java19
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/ParameterConverter.java14
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/ShortConverter.java18
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/StringConverter.java20
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/internal/ArrayConverter.java (renamed from plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/ArrayConverter.java)18
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/internal/ByteConverter.java32
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/internal/CharConverter.java33
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/internal/EfficientLazyStringConverter.java (renamed from plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/EfficientLazyStringConverter.java)16
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/internal/FloatConverter.java32
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/internal/IntConverter.java32
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/internal/JavaBuiltinConverter.java29
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/internal/JavaBuiltinConverterFactory.java (renamed from plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/JavaBuiltinConverterFactory.java)20
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/internal/NullConverter.java31
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/internal/ShortConverter.java32
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/internal/StringConverter.java32
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/iface/BackendContributor.java36
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/syslib/CollectionOperations.java183
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/syslib/FileIoOperations.java131
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/syslib/FileOutlet.java127
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/syslib/InMemoryPostprocessor.java30
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/syslib/Outlet.java31
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/syslib/PrimitiveOperations.java262
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/syslib/ReflectionOperations.java81
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/syslib/StringOperations.java64
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/syslib/SysLibNames.java45
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/syslib/SyslibContributor.java59
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/syslib/UriBasedPostprocessor.java23
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/CompositeTypesystem.java2
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/BuiltinProperty.java4
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/internal/AbstractJavaBeansTypesystem.java (renamed from plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/AbstractJavaBeansTypesystem.java)4
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/internal/GlobalJavaBeansTypesystem.java (renamed from plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/GlobalJavaBeansTypesystem.java)2
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/internal/JavaBeansProperty.java (renamed from plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/JavaBeansProperty.java)4
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/internal/JavaBeansStaticProperty.java (renamed from plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/JavaBeansStaticProperty.java)4
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/internal/JavaBeansType.java (renamed from plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/JavaBeansType.java)4
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/internal/JavaOperation.java (renamed from plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/JavaOperation.java)8
-rw-r--r--plugins/org.eclipse.xtend.backend/todo.txt39
-rw-r--r--plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/OldDefinitionConverter.java6
-rw-r--r--plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/OldExtensionConverter.java8
-rw-r--r--plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/OldXpandRegistry.java14
-rw-r--r--plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/OldXtendRegistry.java14
-rw-r--r--plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/XpandBackendFacade.java6
-rw-r--r--plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/XtendBackendFacade.java2
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/ConcatExpressionTest.java41
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/InitClosureExpressionTest.java6
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/expr/SwitchExpressionTest.java6
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/functions/PolymorphicResolverTest.java54
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/helpers/BackendTestHelper.java5
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/types/AbstractTypeTest.java31
-rw-r--r--tests/org.eclipse.xtend.backend.test/todo.txt4
64 files changed, 1613 insertions, 297 deletions
diff --git a/plugins/org.eclipse.xtend.backend/META-INF/MANIFEST.MF b/plugins/org.eclipse.xtend.backend/META-INF/MANIFEST.MF
index e4ce600..ae4c0f6 100644
--- a/plugins/org.eclipse.xtend.backend/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.xtend.backend/META-INF/MANIFEST.MF
@@ -3,14 +3,14 @@ Bundle-ManifestVersion: 2
Bundle-Name: Backend Plug-in
Bundle-SymbolicName: org.eclipse.xtend.backend
Bundle-Version: 1.0.0
-Export-Package: org.eclipse.xtend.backend,
+Export-Package: org.eclipse.xtend.backend;uses:="org.eclipse.xtend.backend.common",
org.eclipse.xtend.backend.common,
- org.eclipse.xtend.backend.expr,
- org.eclipse.xtend.backend.functions,
- org.eclipse.xtend.backend.functions.java,
- org.eclipse.xtend.backend.iface,
- org.eclipse.xtend.backend.types,
- org.eclipse.xtend.backend.types.builtin,
- org.eclipse.xtend.backend.types.java,
+ org.eclipse.xtend.backend.expr;uses:="org.eclipse.xtend.backend.common",
+ 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.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",
org.eclipse.xtend.backend.util
Require-Bundle: org.apache.commons.logging
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/expr/InitClosureExpression.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/expr/InitClosureExpression.java
index 5f55f7f..b4a63da 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/expr/InitClosureExpression.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/expr/InitClosureExpression.java
@@ -16,7 +16,7 @@ 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.functions.Closure;
+import org.eclipse.xtend.backend.functions.internal.Closure;
/**
diff --git a/plugins/org.eclipse.xtend.middleend/src/org/eclipose/xtend/middleend/FunctionDefContextFactory.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/FunctionDefContextFactory.java
index d2e5f5d..dd83b68 100644
--- a/plugins/org.eclipse.xtend.middleend/src/org/eclipose/xtend/middleend/FunctionDefContextFactory.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/FunctionDefContextFactory.java
@@ -8,10 +8,10 @@ http://www.eclipse.org/legal/epl-v10.html
Contributors:
Arno Haase - initial API and implementation
*/
-package org.eclipose.xtend.middleend;
+package org.eclipse.xtend.backend.functions;
import org.eclipse.xtend.backend.common.BackendTypesystem;
-import org.eclipse.xtend.backend.functions.FunctionDefContextImpl;
+import org.eclipse.xtend.backend.functions.internal.FunctionDefContextImpl;
import org.eclipse.xtend.backend.syslib.SyslibContributor;
@@ -26,8 +26,9 @@ public final class FunctionDefContextFactory {
_syslib = new SyslibContributor (ts);
}
- public FunctionDefContextImpl create () {
- return new FunctionDefContextImpl (_syslib);
+ public FunctionDefContextInternal create () {
+ final FunctionDefContextInternal result = new FunctionDefContextImpl ();
+ result.register (_syslib.getContributedFunctions());
+ return result;
}
-
}
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
new file mode 100644
index 0000000..7946133
--- /dev/null
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/FunctionDefContextInternal.java
@@ -0,0 +1,29 @@
+/*
+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 java.util.Collection;
+
+import org.eclipse.xtend.backend.common.FunctionDefContext;
+import org.eclipse.xtend.backend.common.NamedFunction;
+
+
+
+/**
+ * This interface provides additional access to the Fdc for use during initialization,
+ * e.g. in the middle ends.
+ *
+ * @author Arno Haase (http://www.haase-consulting.com)
+ */
+public interface FunctionDefContextInternal extends FunctionDefContext {
+ void register (NamedFunction f);
+ void register (Collection <NamedFunction> f);
+}
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/Closure.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/internal/Closure.java
index be2f035..82a56a0 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/Closure.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/internal/Closure.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.functions;
+package org.eclipse.xtend.backend.functions.internal;
import java.util.List;
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/FunctionDefContextImpl.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/internal/FunctionDefContextImpl.java
index 4c23bba..6fd00bf 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/FunctionDefContextImpl.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/internal/FunctionDefContextImpl.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.functions;
+package org.eclipse.xtend.backend.functions.internal;
import java.util.ArrayList;
import java.util.Collection;
@@ -17,9 +17,10 @@ import java.util.List;
import org.eclipse.xtend.backend.common.BackendType;
import org.eclipse.xtend.backend.common.ExecutionContext;
import org.eclipse.xtend.backend.common.Function;
-import org.eclipse.xtend.backend.common.FunctionDefContext;
import org.eclipse.xtend.backend.common.NamedFunction;
-import org.eclipse.xtend.backend.iface.BackendContributor;
+import org.eclipse.xtend.backend.functions.DuplicateAwareFunctionCollection;
+import org.eclipse.xtend.backend.functions.DuplicateAwareNamedFunctionCollection;
+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;
@@ -29,7 +30,7 @@ import org.eclipse.xtend.backend.util.ErrorHandler;
*
* @author Arno Haase (http://www.haase-consulting.com)
*/
-public final class FunctionDefContextImpl implements FunctionDefContext {
+public final class FunctionDefContextImpl implements FunctionDefContextInternal {
private final Cache<BackendType, Collection<NamedFunction>> _byFirstParameterType = new Cache<BackendType, Collection<NamedFunction>>() {
@Override
@@ -86,12 +87,8 @@ public final class FunctionDefContextImpl implements FunctionDefContext {
}
};
- public FunctionDefContextImpl (BackendContributor syslib) {
- register (syslib);
- }
-
- public void register (BackendContributor bc) {
- for (NamedFunction f: bc.getContributedFunctions())
+ public void register (Collection<NamedFunction> functions) {
+ for (NamedFunction f: functions)
register (f);
}
@@ -110,7 +107,10 @@ public final class FunctionDefContextImpl implements FunctionDefContext {
return ctx.getFunctionInvoker().invoke (ctx, f, params);
}
- private Collection<Function> findFunctionCandidates (ExecutionContext ctx, String functionName, List<? extends Object> params) {
+ /**
+ * is public only for testing purposes
+ */
+ public Collection<Function> findFunctionCandidates (ExecutionContext ctx, String functionName, List<? extends Object> params) {
final List<BackendType> paramTypes = new ArrayList<BackendType>();
for (Object o: params)
paramTypes.add (ctx.getTypesystem().findType(o));
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/PolymorphicResolver.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/internal/PolymorphicResolver.java
index a1ea46b..d2b7f14 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/PolymorphicResolver.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/internal/PolymorphicResolver.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.functions;
+package org.eclipse.xtend.backend.functions.internal;
import java.util.ArrayList;
import java.util.Collection;
@@ -24,8 +24,8 @@ import org.eclipse.xtend.backend.common.Function;
*
* @author Arno Haase (http://www.haase-consulting.com)
*/
-final class PolymorphicResolver {
- private final String _name; // for error messages
+public final class PolymorphicResolver {
+ private final String _name; // only for error messages
/**
* @param functionName the name of the functions to be resolved - used for error messages
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/TypesComparator.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/internal/TypesComparator.java
index 8e000c7..3905142 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/TypesComparator.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/internal/TypesComparator.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.functions;
+package org.eclipse.xtend.backend.functions.internal;
import java.util.Comparator;
import java.util.List;
@@ -23,7 +23,7 @@ import org.eclipse.xtend.backend.common.BackendType;
*
* @author Arno Haase (http://www.haase-consulting.com)
*/
-final class TypesComparator implements Comparator<List<? extends BackendType>> {
+public final class TypesComparator implements Comparator<List<? extends BackendType>> {
public int compare(final List<? extends BackendType> types1, final List<? extends BackendType> types2) {
if (types1 == null || types2 == null)
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/ByteConverter.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/ByteConverter.java
deleted file mode 100644
index e7cd036..0000000
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/ByteConverter.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package org.eclipse.xtend.backend.functions.java;
-
-
-class ByteConverter implements JavaBuiltinConverter {
- public static final JavaBuiltinConverter INSTANCE = new ByteConverter ();
-
- public Object backendToJava (Object o) {
- if (o == null)
- return null;
- return ((Number) o).byteValue();
- }
-
- public Object javaToBackend (Object o) {
- if (o == null)
- return null;
- return ((Number) o).longValue();
- }
-}
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/CharConverter.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/CharConverter.java
deleted file mode 100644
index 4680a13..0000000
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/CharConverter.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package org.eclipse.xtend.backend.functions.java;
-
-
-class CharConverter implements JavaBuiltinConverter {
- public static final JavaBuiltinConverter INSTANCE = new CharConverter ();
-
- public Object backendToJava (Object o) {
- if (o == null)
- return null;
- final String s = String.valueOf (o);
- return s.charAt(0);
- }
-
- public Object javaToBackend (Object o) {
- if (o == null)
- return null;
- return String.valueOf (o);
- }
-}
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/FloatConverter.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/FloatConverter.java
deleted file mode 100644
index fe1ebec..0000000
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/FloatConverter.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package org.eclipse.xtend.backend.functions.java;
-
-
-class FloatConverter implements JavaBuiltinConverter {
- public static final JavaBuiltinConverter INSTANCE = new FloatConverter ();
-
- public Object backendToJava (Object o) {
- if (o == null)
- return null;
- return ((Number) o).floatValue();
- }
-
- public Object javaToBackend (Object o) {
- if (o == null)
- return null;
- return ((Number) o).doubleValue();
- }
-}
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/IntConverter.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/IntConverter.java
deleted file mode 100644
index 6f0ec56..0000000
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/IntConverter.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package org.eclipse.xtend.backend.functions.java;
-
-
-class IntConverter implements JavaBuiltinConverter {
- public static final JavaBuiltinConverter INSTANCE = new IntConverter ();
-
- public Object backendToJava (Object o) {
- if (o == null)
- return null;
- return ((Number) o).intValue();
- }
-
- public Object javaToBackend (Object o) {
- if (o == null)
- return null;
- return ((Number) o).longValue();
- }
-}
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/JavaBuiltinConverter.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/JavaBuiltinConverter.java
deleted file mode 100644
index 59c1a54..0000000
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/JavaBuiltinConverter.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package org.eclipse.xtend.backend.functions.java;
-
-
-/**
- * This interface serves as an abstraction to convert types supported by Java but not directly
- * supported by the backend - such as Integer or Float - to backend types and vice versa.
- */
-public interface JavaBuiltinConverter {
- Object javaToBackend (Object o);
- Object backendToJava (Object o);
-}
-
-
-
-
-
-
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/JavaDefinedFunction.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/JavaDefinedFunction.java
index fa09b26..1d5c9c6 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/JavaDefinedFunction.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/JavaDefinedFunction.java
@@ -21,6 +21,8 @@ import org.eclipse.xtend.backend.common.BackendTypesystem;
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.functions.java.internal.JavaBuiltinConverter;
+import org.eclipse.xtend.backend.functions.java.internal.JavaBuiltinConverterFactory;
import org.eclipse.xtend.backend.util.ErrorHandler;
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/JavaFunctionClassContributor.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/JavaFunctionClassContributor.java
index d2899c8..b0349ad 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/JavaFunctionClassContributor.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/JavaFunctionClassContributor.java
@@ -14,10 +14,8 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
-import org.eclipse.xtend.backend.common.BackendType;
import org.eclipse.xtend.backend.common.BackendTypesystem;
import org.eclipse.xtend.backend.common.NamedFunction;
-import org.eclipse.xtend.backend.iface.BackendContributor;
/**
@@ -27,7 +25,7 @@ import org.eclipse.xtend.backend.iface.BackendContributor;
*
* @author Arno Haase (http://www.haase-consulting.com)
*/
-public final class JavaFunctionClassContributor implements BackendContributor {
+public final class JavaFunctionClassContributor {
private final List<NamedFunction> _functions = new ArrayList<NamedFunction>();
public JavaFunctionClassContributor (Class<?> cls, BackendTypesystem ts) {
@@ -35,10 +33,6 @@ public final class JavaFunctionClassContributor implements BackendContributor {
_functions.add (new NamedFunction (f.getName(), f));
}
- public BackendType convertToType (List<String> segments) {
- return null; // no types are contributed
- }
-
public Collection<NamedFunction> getContributedFunctions () {
return _functions;
}
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/NullConverter.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/NullConverter.java
deleted file mode 100644
index 7774e86..0000000
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/NullConverter.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package org.eclipse.xtend.backend.functions.java;
-
-
-/**
- * This is a "Null Object" implementation that performs no conversion whatsoever
- */
-class NullConverter implements JavaBuiltinConverter {
- public static final JavaBuiltinConverter INSTANCE = new NullConverter ();
-
- private NullConverter () {}
-
- public Object backendToJava (Object o) {
- return o;
- }
-
- public Object javaToBackend (Object o) {
- return o;
- }
-}
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/ParameterConverter.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/ParameterConverter.java
index cc91db0..df32a79 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/ParameterConverter.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/ParameterConverter.java
@@ -1,5 +1,17 @@
+/*
+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;
+import org.eclipse.xtend.backend.functions.java.internal.JavaBuiltinConverter;
+
/**
* This class serves as an abstraction to convert between the internal, canonical representation
@@ -8,6 +20,8 @@ package org.eclipse.xtend.backend.functions.java;
*
* Examples of this are the List <--> Array conversion, int <--> long, float <--> double or
* CharSequence <--> String.
+ *
+ * @author Arno Haase (http://www.haase-consulting.com)
*/
public final class ParameterConverter {
private final int _index;
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/ShortConverter.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/ShortConverter.java
deleted file mode 100644
index ded3adc..0000000
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/ShortConverter.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package org.eclipse.xtend.backend.functions.java;
-
-
-class ShortConverter implements JavaBuiltinConverter {
- public static final JavaBuiltinConverter INSTANCE = new ShortConverter ();
-
- public Object backendToJava (Object o) {
- if (o == null)
- return null;
- return ((Number) o).shortValue();
- }
-
- public Object javaToBackend (Object o) {
- if (o == null)
- return null;
- return ((Number) o).longValue();
- }
-}
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/StringConverter.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/StringConverter.java
deleted file mode 100644
index 6599b64..0000000
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/StringConverter.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package org.eclipse.xtend.backend.functions.java;
-
-
-/**
- * This class is necessary because any CharSequence is a valid backend representation of
- * a String.
- */
-class StringConverter implements JavaBuiltinConverter{
-
- public Object backendToJava (Object o) {
- if (o == null)
- return null;
-
- return o.toString(); // official way to convert a CharSequence to a String
- }
-
- public Object javaToBackend (Object o) {
- return o;
- }
-}
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/ArrayConverter.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/internal/ArrayConverter.java
index 4c82603..8dfdce2 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/ArrayConverter.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/internal/ArrayConverter.java
@@ -1,11 +1,25 @@
-package org.eclipse.xtend.backend.functions.java;
+/*
+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;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.List;
-class ArrayConverter implements JavaBuiltinConverter {
+/**
+ *
+ * @author Arno Haase (http://www.haase-consulting.com)
+ */
+public final class ArrayConverter implements JavaBuiltinConverter {
private final Class<?> _componentType;
public ArrayConverter (Class<?> componentType) {
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/internal/ByteConverter.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/internal/ByteConverter.java
new file mode 100644
index 0000000..7f13080
--- /dev/null
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/internal/ByteConverter.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.functions.java.internal;
+
+
+/**
+ *
+ * @author Arno Haase (http://www.haase-consulting.com)
+ */
+public final class ByteConverter implements JavaBuiltinConverter {
+ public static final JavaBuiltinConverter INSTANCE = new ByteConverter ();
+
+ public Object backendToJava (Object o) {
+ if (o == null)
+ return null;
+ return ((Number) o).byteValue();
+ }
+
+ public Object javaToBackend (Object o) {
+ if (o == null)
+ return null;
+ return ((Number) o).longValue();
+ }
+}
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/internal/CharConverter.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/internal/CharConverter.java
new file mode 100644
index 0000000..4fb3236
--- /dev/null
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/internal/CharConverter.java
@@ -0,0 +1,33 @@
+/*
+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;
+
+
+/**
+ *
+ * @author Arno Haase (http://www.haase-consulting.com)
+ */
+public final class CharConverter implements JavaBuiltinConverter {
+ public static final JavaBuiltinConverter INSTANCE = new CharConverter ();
+
+ public Object backendToJava (Object o) {
+ if (o == null)
+ return null;
+ final String s = String.valueOf (o);
+ return s.charAt(0);
+ }
+
+ public Object javaToBackend (Object o) {
+ if (o == null)
+ return null;
+ return String.valueOf (o);
+ }
+}
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/EfficientLazyStringConverter.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/internal/EfficientLazyStringConverter.java
index 7d11185..5a00b7d 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/EfficientLazyStringConverter.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/internal/EfficientLazyStringConverter.java
@@ -1,4 +1,14 @@
-package org.eclipse.xtend.backend.functions.java;
+/*
+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;
import org.eclipse.xtend.backend.common.EfficientLazyString;
@@ -7,8 +17,10 @@ import org.eclipse.xtend.backend.common.EfficientLazyString;
* This class is provided to allow Java methods to deal with EfficientLazyString without
* the performance penalty of conversion to String and without forcing them to deal with
* conversion and special cases.
+ *
+ * @author Arno Haase (http://www.haase-consulting.com)
*/
-class EfficientLazyStringConverter implements JavaBuiltinConverter {
+public final class EfficientLazyStringConverter implements JavaBuiltinConverter {
public Object backendToJava (Object o) {
if (o == null)
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/internal/FloatConverter.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/internal/FloatConverter.java
new file mode 100644
index 0000000..3fc8e2e
--- /dev/null
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/internal/FloatConverter.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.functions.java.internal;
+
+
+/**
+ *
+ * @author Arno Haase (http://www.haase-consulting.com)
+ */
+public final class FloatConverter implements JavaBuiltinConverter {
+ public static final JavaBuiltinConverter INSTANCE = new FloatConverter ();
+
+ public Object backendToJava (Object o) {
+ if (o == null)
+ return null;
+ return ((Number) o).floatValue();
+ }
+
+ public Object javaToBackend (Object o) {
+ if (o == null)
+ return null;
+ return ((Number) o).doubleValue();
+ }
+}
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/internal/IntConverter.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/internal/IntConverter.java
new file mode 100644
index 0000000..c8f7b9b
--- /dev/null
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/internal/IntConverter.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.functions.java.internal;
+
+
+/**
+ *
+ * @author Arno Haase (http://www.haase-consulting.com)
+ */
+public final class IntConverter implements JavaBuiltinConverter {
+ public static final JavaBuiltinConverter INSTANCE = new IntConverter ();
+
+ public Object backendToJava (Object o) {
+ if (o == null)
+ return null;
+ return ((Number) o).intValue();
+ }
+
+ public Object javaToBackend (Object o) {
+ if (o == null)
+ return null;
+ return ((Number) o).longValue();
+ }
+}
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/internal/JavaBuiltinConverter.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/internal/JavaBuiltinConverter.java
new file mode 100644
index 0000000..a52ff81
--- /dev/null
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/internal/JavaBuiltinConverter.java
@@ -0,0 +1,29 @@
+/*
+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 interface serves as an abstraction to convert types supported by Java but not directly
+ * supported by the backend - such as Integer or Float - to backend types and vice versa.
+ *
+ * @author Arno Haase (http://www.haase-consulting.com)
+ */
+public interface JavaBuiltinConverter {
+ Object javaToBackend (Object o);
+ Object backendToJava (Object o);
+}
+
+
+
+
+
+
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/JavaBuiltinConverterFactory.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/internal/JavaBuiltinConverterFactory.java
index c6e4a94..72f27cf 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/JavaBuiltinConverterFactory.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/internal/JavaBuiltinConverterFactory.java
@@ -1,17 +1,31 @@
-package org.eclipse.xtend.backend.functions.java;
+/*
+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;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.xtend.backend.common.BackendType;
import org.eclipse.xtend.backend.common.EfficientLazyString;
+import org.eclipse.xtend.backend.functions.java.ParameterConverter;
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;
-
-public class JavaBuiltinConverterFactory {
+/**
+ *
+ * @author Arno Haase (http://www.haase-consulting.com)
+ */
+public final class JavaBuiltinConverterFactory {
private static final Map<Class<?>, JavaBuiltinConverter> _converters = new HashMap<Class<?>, JavaBuiltinConverter> ();
private static final Map<Class<?>, BackendType> _additionalTypes = new HashMap<Class<?>, BackendType> ();
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/internal/NullConverter.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/internal/NullConverter.java
new file mode 100644
index 0000000..5528a64
--- /dev/null
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/internal/NullConverter.java
@@ -0,0 +1,31 @@
+/*
+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 is a "Null Object" implementation that performs no conversion whatsoever
+ *
+ * @author Arno Haase (http://www.haase-consulting.com)
+ */
+public final class NullConverter implements JavaBuiltinConverter {
+ public static final JavaBuiltinConverter INSTANCE = new NullConverter ();
+
+ private NullConverter () {}
+
+ public Object backendToJava (Object o) {
+ return o;
+ }
+
+ public Object javaToBackend (Object o) {
+ return o;
+ }
+}
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/internal/ShortConverter.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/internal/ShortConverter.java
new file mode 100644
index 0000000..fff3fb3
--- /dev/null
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/internal/ShortConverter.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.functions.java.internal;
+
+
+/**
+ *
+ * @author Arno Haase (http://www.haase-consulting.com)
+ */
+public final class ShortConverter implements JavaBuiltinConverter {
+ public static final JavaBuiltinConverter INSTANCE = new ShortConverter ();
+
+ public Object backendToJava (Object o) {
+ if (o == null)
+ return null;
+ return ((Number) o).shortValue();
+ }
+
+ public Object javaToBackend (Object o) {
+ if (o == null)
+ return null;
+ return ((Number) o).longValue();
+ }
+}
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/internal/StringConverter.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/internal/StringConverter.java
new file mode 100644
index 0000000..6bf2438
--- /dev/null
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/internal/StringConverter.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.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 StringConverter implements JavaBuiltinConverter{
+
+ public Object backendToJava (Object o) {
+ if (o == null)
+ return null;
+
+ return o.toString(); // official way to convert a CharSequence to a String
+ }
+
+ public Object javaToBackend (Object o) {
+ return o;
+ }
+}
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/iface/BackendContributor.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/iface/BackendContributor.java
deleted file mode 100644
index bbf1f47..0000000
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/iface/BackendContributor.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
-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.iface;
-
-import java.util.Collection;
-import java.util.List;
-
-import org.eclipse.xtend.backend.common.BackendType;
-import org.eclipse.xtend.backend.common.NamedFunction;
-
-
-//TODO add an 'init' method to pass in the string argument and the backend typesystem?
-
-
-/**
- *
- * @author Arno Haase (http://www.haase-consulting.com)
- */
-public interface BackendContributor {
-
- /**
- * This method is used by the middle end to resolve type literals. This Contributor
- * should return "null" if it does not feel responsible for a giben type literal.
- */
- BackendType convertToType (List<String> segments);
-
- Collection<NamedFunction> getContributedFunctions ();
-}
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
new file mode 100644
index 0000000..b0ef21c
--- /dev/null
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/syslib/CollectionOperations.java
@@ -0,0 +1,183 @@
+/*
+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 java.util.ArrayList;
+import java.util.Collection;
+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.Function;
+import org.eclipse.xtend.backend.functions.java.AbstractExecutionContextAware;
+
+
+/**
+ *
+ * @author Arno Haase (http://www.haase-consulting.com)
+ */
+public final class CollectionOperations extends AbstractExecutionContextAware {
+
+ /////////////////////////////////////////////
+ // "simple" operations on the collections
+ /////////////////////////////////////////////
+
+ public boolean add (Collection<Object> c, Object o) {
+ return c.add (o);
+ }
+
+ public boolean addAll (Collection<Object> c, Collection<Object> o) {
+ return c.addAll (o);
+ }
+
+ public boolean remove (Collection<Object> c, Object o) {
+ return c.remove (o);
+ }
+
+ public boolean removeAll (Collection<Object> c, Collection<Object> o) {
+ return c.removeAll (o);
+ }
+
+ public boolean retainAll (Collection<Object> c, Collection<Object> o) {
+ return c.retainAll (o);
+ }
+
+ public boolean contains (Collection<Object> c, Object o) {
+ return c.contains (o);
+ }
+
+ public void clear (Collection<Object> c) {
+ c.clear();
+ }
+
+
+ public Object get (List<Object> c, int ind) {
+ return c.get (ind);
+ }
+
+ public Object remove (List<Object> c, int ind) {
+ return c.remove (ind);
+ }
+
+ public Object set (List<Object> c, int ind, Object o) {
+ return c.set (ind, o);
+ }
+
+ public void add (List<Object> c, int ind, Object o) {
+ c.add (ind, o);
+ }
+
+ public int indexOf (List<Object> c, Object o) {
+ return c.indexOf (o);
+ }
+
+ public int lastIndexOf (List<Object> c, Object o) {
+ return c.lastIndexOf (o);
+ }
+
+ /////////////////////////////////////////////
+ // "functional" operations on collections
+ /////////////////////////////////////////////
+
+ public List<?> select (Collection<?> c, Function f) {
+ final List<Object> result = new ArrayList<Object>();
+
+ for (Object o: c)
+ if (Boolean.TRUE.equals (f.invoke(_ctx, new Object[] {o})))
+ result.add (o);
+
+ return result;
+ }
+
+ public Object selectFirst (Collection<?> c, Function f) {
+ for (Object o: c)
+ if (Boolean.TRUE.equals (f.invoke (_ctx, new Object[] {o})))
+ return o;
+
+ return null;
+ }
+
+ public List<?> typeSelect (Collection<?> c, BackendType t) {
+ final List<Object> result = new ArrayList<Object>();
+
+ for (Object candidate: c)
+ 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> ();
+
+ for (Object o: c)
+ result.add (f.invoke(_ctx, new Object[] {o}));
+
+ return result;
+ }
+
+
+ ///////////////////////////////////
+ // operations on maps
+ ///////////////////////////////////
+
+ public boolean containsKey (Map<Object,Object> m, Object key) {
+ return m.containsKey (key);
+ }
+
+ public boolean containsValue (Map<Object,Object> m, Object value) {
+ return m.containsValue (value);
+ }
+
+ public Object get (Map<Object,Object> m, Object key) {
+ return m.get (key);
+ }
+
+ public Object put (Map<Object,Object> m, Object key, Object value) {
+ return m.put (key, value);
+ }
+
+ public Object remove (Map<Object,Object> m, Object key) {
+ return m.remove (key);
+ }
+
+ public void putAll (Map<Object,Object> m, Map<Object, Object> o) {
+ m.putAll (o);
+ }
+
+ public void clear (Map<Object,Object> m) {
+ m.clear ();
+ }
+
+ public Set<Object> keySet (Map<Object,Object> m) {
+ return m.keySet();
+ }
+
+ public Collection<?> values (Map<Object,Object> m) {
+ return m.values();
+ }
+
+
+ ///////////////////////////////////
+ // conversion operations
+ ///////////////////////////////////
+
+ public List<?> asList (Collection<?> c) {
+ return new ArrayList<Object> (c);
+ }
+
+ public Set<?> asSet (Collection<?> c) {
+ return new HashSet<Object> (c);
+ }
+
+}
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/syslib/FileIoOperations.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/syslib/FileIoOperations.java
new file mode 100644
index 0000000..ecbb91e
--- /dev/null
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/syslib/FileIoOperations.java
@@ -0,0 +1,131 @@
+/*
+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 java.io.File;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.xtend.backend.common.EfficientLazyString;
+import org.eclipse.xtend.backend.util.ErrorHandler;
+
+
+/**
+ * This class provides functions for writing data to files. Since this is part of the core functionality
+ * of a code generator, these functions are in the syslib.<br>
+ *
+ * These functions replace the "FILE" construct of XPand. The class makes use of the "single instance per
+ * ExecutionContext" guarantee to store pre-registered "outlets" and allow reuse of predefined
+ * output configurations.
+ *
+ * @author Arno Haase (http://www.haase-consulting.com)
+ */
+public final class FileIoOperations {
+ private Map<String, Outlet> _outlets = new HashMap<String, Outlet>();
+
+ public static final String DEFAULT_OUTLET_NAME = "OUT";
+
+ ///////////////////////////////////////////////////////////
+ // registering the outlets
+ ///////////////////////////////////////////////////////////
+
+ public void registerDefaultOutlet (Outlet outlet) {
+ _outlets.put (DEFAULT_OUTLET_NAME, outlet);
+ }
+
+ public void registerDefaultOutlet (String baseDir, String fileEncoding, boolean overwrite) {
+ final FileOutlet fo = new FileOutlet ();
+ fo.setBaseDir (new File (baseDir));
+ fo.setFileEncoding (fileEncoding);
+ fo.setOverwrite (overwrite);
+
+ registerDefaultOutlet (fo);
+ }
+
+ public void registerDefaultOutlet (String baseDir, String fileEncoding) {
+ registerDefaultOutlet (baseDir, fileEncoding, true);
+ }
+
+ public void registerDefaultOutlet (String baseDir) {
+ registerDefaultOutlet (baseDir, null);
+ }
+
+ public void registerOutlet (String name, Outlet outlet) {
+ _outlets.put (name, outlet);
+ }
+
+ public void registerOutlet (String name, String baseDir, String fileEncoding, boolean overwrite) {
+ final FileOutlet fo = new FileOutlet ();
+ fo.setBaseDir (new File (baseDir));
+ fo.setFileEncoding (fileEncoding);
+ fo.setOverwrite (overwrite);
+
+ registerOutlet (name, fo);
+ }
+
+ public void registerOutlet (String name, String baseDir, String fileEncoding) {
+ registerOutlet (name, baseDir, fileEncoding, true);
+ }
+
+ public void registerOutlet (String name, String baseDir) {
+ registerOutlet (name, baseDir, null);
+ }
+
+ ///////////////////////////////////////////////////////////
+ // actually writing to the files
+ ///////////////////////////////////////////////////////////
+
+ public void writeToFile (String fileName, CharSequence content) {
+ writeToFile (DEFAULT_OUTLET_NAME, fileName, false, content);
+ }
+
+ public void writeToFile (String outletName, String fileName, CharSequence content) {
+ writeToFile (outletName, fileName, false, content);
+ }
+
+ public void writeToFile (String fileName, boolean append, CharSequence content) {
+ writeToFile (DEFAULT_OUTLET_NAME, fileName, append, content);
+ }
+
+ public void writeToFile (String outletName, String fileName, boolean append, CharSequence content) {
+
+ try {
+ final Outlet outlet = _outlets.get (outletName);
+ if (outlet == null)
+ throw new IllegalArgumentException ("no outlet '" + outletName + "' was registered.");
+
+ for (InMemoryPostprocessor pp: outlet.getInMemoryPostprocessors())
+ content = pp.process (content, outlet.createUri (fileName));
+
+ final Writer w = outlet.createWriter (fileName, append);
+
+ try {
+ if (content instanceof EfficientLazyString)
+ ((EfficientLazyString) content).writeTo (w);
+ else
+ w.write (content.toString()); // content is already a CharSequence --> no handling of overwritten toString() required here
+
+ } finally {
+ w.close();
+ }
+
+ for (UriBasedPostprocessor pp: outlet.getUriBasedPostprocessors())
+ pp.process (outlet.createUri (fileName));
+
+ } catch (IOException exc) {
+ ErrorHandler.handle (exc);
+ }
+ }
+}
+
+
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/syslib/FileOutlet.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/syslib/FileOutlet.java
new file mode 100644
index 0000000..2fd2ad1
--- /dev/null
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/syslib/FileOutlet.java
@@ -0,0 +1,127 @@
+/*
+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 java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.xtend.backend.util.ErrorHandler;
+import org.eclipse.xtend.backend.util.NullWriter;
+
+
+/**
+ *
+ * @author Arno Haase (http://www.haase-consulting.com)
+ */
+public final class FileOutlet implements Outlet {
+ private File _baseDir;
+ private String _fileEncoding = System.getProperty ("file.encoding");
+ private boolean _overwrite = false;;
+ private boolean _append = false;
+
+ private final List<InMemoryPostprocessor> _inMemoryPp = new ArrayList<InMemoryPostprocessor> ();
+ private final List<UriBasedPostprocessor> _uriBasedPp = new ArrayList<UriBasedPostprocessor> ();
+
+ public void register (InMemoryPostprocessor pp) {
+ _inMemoryPp.add (pp);
+ }
+
+ public void register (UriBasedPostprocessor pp) {
+ _uriBasedPp.add (pp);
+ }
+
+ public File getBaseDir () {
+ return _baseDir;
+ }
+
+ public void setBaseDir (File baseDir) {
+ _baseDir = baseDir;
+ }
+
+ public String getFileEncoding () {
+ return _fileEncoding;
+ }
+
+ public void setFileEncoding (String fileEncoding) {
+ _fileEncoding = fileEncoding;
+ }
+
+ public boolean isOverwrite () {
+ return _overwrite;
+ }
+
+ public void setOverwrite (boolean overwrite) {
+ _overwrite = overwrite;
+ }
+
+ public void setAppend (boolean append) {
+ _append = append;
+ }
+
+ public boolean isAppend () {
+ return _append;
+ }
+
+ public Writer createWriter (String filename) {
+ return createWriter (filename, _append);
+ }
+
+ public Writer createWriter (String filename, boolean append) {
+ try {
+ final File target = createTargetFile (filename);
+ if (target.exists() && !_overwrite)
+ return new NullWriter ();
+
+ final File f = new File (_baseDir, filename);
+ final File parentDir = f.getParentFile();
+
+ if (parentDir.isFile())
+ throw new IllegalStateException ("'" + parentDir + "' exists but is no directory.");
+ if (! parentDir.exists ())
+ parentDir.mkdirs();
+
+ final FileOutputStream fos = new FileOutputStream (f, append);
+ final BufferedOutputStream bos = new BufferedOutputStream (fos);
+
+ if (_fileEncoding == null)
+ return new OutputStreamWriter (bos);
+ else
+ return new OutputStreamWriter (bos, _fileEncoding);
+ } catch (IOException exc) {
+ ErrorHandler.handle (exc);
+ return null; // just for the compiler - this code is never executed
+ }
+ }
+
+ private File createTargetFile (String filename) {
+ return new File (_baseDir, filename);
+ }
+
+ public String createUri (String filename) {
+ return createTargetFile (filename).getPath().replace ("\\", "/");
+ }
+
+ public List<InMemoryPostprocessor> getInMemoryPostprocessors () {
+ return _inMemoryPp;
+ }
+
+ public List<UriBasedPostprocessor> getUriBasedPostprocessors () {
+ return _uriBasedPp;
+ }
+}
+
+
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/syslib/InMemoryPostprocessor.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/syslib/InMemoryPostprocessor.java
new file mode 100644
index 0000000..257a923
--- /dev/null
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/syslib/InMemoryPostprocessor.java
@@ -0,0 +1,30 @@
+/*
+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;
+
+/**
+ * This interface represents a postprocessor that is given access to
+ * the contents of a file before it is written.<br>
+ *
+ * The unprocessed CharSequence may be an EfficientLazyString that
+ * is not yet serialized, waiting for streaming. It should be noted
+ * that in this - common - case any postprocessing may impact
+ * performance.<br>
+ *
+ * The returned CharSequence is used. It is okay to modify the parameter
+ * that was passed in, but the returned object is what will be
+ * processed by the subsequent steps in the pipeline.
+ *
+ * @author Arno Haase (http://www.haase-consulting.com)
+ */
+public interface InMemoryPostprocessor {
+ CharSequence process (CharSequence unprocessed, String uri);
+}
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/syslib/Outlet.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/syslib/Outlet.java
new file mode 100644
index 0000000..b7b294e
--- /dev/null
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/syslib/Outlet.java
@@ -0,0 +1,31 @@
+/*
+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 java.io.Writer;
+import java.util.List;
+
+
+/**
+ * This is the most fundamental abstraction as a data sink. It serves as a callback for
+ * all writing operations.
+ *
+ * @author Arno Haase (http://www.haase-consulting.com)
+ */
+public interface Outlet {
+ Writer createWriter (String filename);
+ Writer createWriter (String filename, boolean append);
+
+ String createUri (String filename);
+
+ List<InMemoryPostprocessor> getInMemoryPostprocessors ();
+ List<UriBasedPostprocessor> getUriBasedPostprocessors ();
+}
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
new file mode 100644
index 0000000..69fe404
--- /dev/null
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/syslib/PrimitiveOperations.java
@@ -0,0 +1,262 @@
+/*
+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;
+
+
+/**
+ *
+ * @author Arno Haase (http://www.haase-consulting.com)
+ */
+public final class PrimitiveOperations {
+
+ ////////////////////////////////////////////////////
+ // arithmetic operations
+ ////////////////////////////////////////////////////
+
+ public Long operatorPlus (Long l1, Long l2) {
+ if (l1 == null || l2 == null)
+ return null;
+
+ return l1 + l2;
+ }
+ public Double operatorPlus (Double d1, Double d2) {
+ if (d1 == null || d2 == null)
+ return null;
+
+ return d1 + d2;
+ }
+ public Double operatorPlus (Double d, Long l) {
+ if (d == null || l == null)
+ return null;
+
+ return d + l;
+ }
+ public Double operatorPlus (Long l, Double d) {
+ if (d == null || l == null)
+ return null;
+
+ return d + l;
+ }
+
+
+ public Long operatorMinus (Long l1, Long l2) {
+ if (l1 == null || l2 == null)
+ return null;
+
+ return l1 - l2;
+ }
+ public Double operatorMinus (Double d1, Double d2) {
+ if (d1 == null || d2 == null)
+ return null;
+
+ return d1 - d2;
+ }
+ public Double operatorMinus (Double d, Long l) {
+ if (d == null || l == null)
+ return null;
+
+ return d - l;
+ }
+ public Double operatorMinus (Long l, Double d) {
+ if (d == null || l == null)
+ return null;
+
+ return d - l;
+ }
+
+
+ public Long operatorMult (Long l1, Long l2) {
+ if (l1 == null || l2 == null)
+ return null;
+
+ return l1 * l2;
+ }
+ public Double operatorMult (Double d1, Double d2) {
+ if (d1 == null || d2 == null)
+ return null;
+
+ return d1 * d2;
+ }
+ public Double operatorMult (Double d, Long l) {
+ if (d == null || l == null)
+ return null;
+
+ return d * l;
+ }
+ public Double operatorMult (Long l, Double d) {
+ if (d == null || l == null)
+ return null;
+
+ return d * l;
+ }
+
+
+ public Long operatorDiv (Long l1, Long l2) {
+ if (l1 == null || l2 == null)
+ return null;
+
+ return l1 / l2;
+ }
+ public Double operatorDiv (Double d1, Double d2) {
+ if (d1 == null || d2 == null)
+ return null;
+
+ return d1 / d2;
+ }
+ public Double operatorDiv (Double d, Long l) {
+ if (d == null || l == null)
+ return null;
+
+ return d / l;
+ }
+ public Double operatorDiv (Long l, Double d) {
+ if (d == null || l == null)
+ return null;
+
+ return d / l;
+ }
+
+
+ public Long operatorMod (Long l1, Long l2) {
+ if (l1 == null || l2 == null)
+ return null;
+
+ return l1 % l2;
+ }
+ public Double operatorMod (Double d1, Double d2) {
+ if (d1 == null || d2 == null)
+ return null;
+
+ return d1 % d2;
+ }
+ public Double operatorMod (Double d, Long l) {
+ if (d == null || l == null)
+ return null;
+
+ return d % l;
+ }
+ public Double operatorMod (Long l, Double d) {
+ if (d == null || l == null)
+ return null;
+
+ return d % l;
+ }
+
+ //////////////////////////////////////////
+ // comparison
+ //////////////////////////////////////////
+
+ public boolean operatorEquals (Object o1, Object o2) {
+ if (o1 == null || o2 == null)
+ return o1 == o2;
+
+ return o1.equals (o2);
+ }
+
+ public boolean operatorNotEquals (Object o1, Object o2) {
+ return ! operatorEquals (o1, o2);
+ }
+
+ @SuppressWarnings("unchecked")
+ public Boolean operatorLess (Object o1, Object o2) {
+ if (o1 == null || o2 == null)
+ return null;
+
+ if (! (o1 instanceof Comparable))
+ throw new IllegalArgumentException ("Object " + o1 + " of type " + o1.getClass().getName() + " is not Comparable");
+
+ return ((Comparable) o1).compareTo(o2) < 0;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Boolean operatorLessOrEquals (Object o1, Object o2) {
+ if (o1 == null || o2 == null)
+ return null;
+
+ if (! (o1 instanceof Comparable))
+ throw new IllegalArgumentException ("Object " + o1 + " of type " + o1.getClass().getName() + " is not Comparable");
+
+ return ((Comparable) o1).compareTo(o2) <= 0;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Boolean operatorGreaterOrEquals (Object o1, Object o2) {
+ if (o1 == null || o2 == null)
+ return null;
+
+ if (! (o1 instanceof Comparable))
+ throw new IllegalArgumentException ("Object " + o1 + " of type " + o1.getClass().getName() + " is not Comparable");
+
+ return ((Comparable) o1).compareTo(o2) >= 0;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Boolean operatorGreater (Object o1, Object o2) {
+ if (o1 == null || o2 == null)
+ return null;
+
+ if (! (o1 instanceof Comparable))
+ throw new IllegalArgumentException ("Object " + o1 + " of type " + o1.getClass().getName() + " is not Comparable");
+
+ return ((Comparable) o1).compareTo(o2) > 0;
+ }
+
+
+ //////////////////////////////////////////
+ // unary minus
+ //////////////////////////////////////////
+
+ public Long operatorMinus (Long l) {
+ if (l == null)
+ return null;
+
+ return -l;
+ }
+
+ public Double operatorMinus (Double d) {
+ if (d == null)
+ return null;
+
+ return -d;
+ }
+
+ //////////////////////////////////////////
+ // misc
+ //////////////////////////////////////////
+
+ public Boolean operatorNot (Boolean b) {
+ if (b == null)
+ return null;
+ return !b;
+ }
+
+ public Boolean implies (Boolean b1, Boolean b2) {
+ if (b1 == null || b2 == null)
+ return null;
+
+ return ! (b1 && !b2);
+ }
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/syslib/ReflectionOperations.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/syslib/ReflectionOperations.java
new file mode 100644
index 0000000..6816916
--- /dev/null
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/syslib/ReflectionOperations.java
@@ -0,0 +1,81 @@
+/*
+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 java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.xtend.backend.common.BackendType;
+import org.eclipse.xtend.backend.common.Function;
+import org.eclipse.xtend.backend.common.Property;
+import org.eclipse.xtend.backend.common.StaticProperty;
+import org.eclipse.xtend.backend.functions.java.AbstractExecutionContextAware;
+
+
+/**
+ * This class provides the built-in operations for the Xtend reflection layer
+ *
+ * @author Arno Haase (http://www.haase-consulting.com)
+ */
+public final class ReflectionOperations extends AbstractExecutionContextAware {
+
+ //////////////////////////////////
+ // operations on Type
+ //////////////////////////////////
+
+ public Object newInstance (BackendType t) {
+ return t.create();
+ }
+
+ public boolean isInstance (BackendType t, Object o) {
+ return t.isAssignableFrom (_ctx.getTypesystem().findType(o));
+ }
+
+ public boolean isAssignableFrom (BackendType t1, BackendType t2) {
+ return t1.isAssignableFrom (t2);
+ }
+
+ public Property getProperty (BackendType t, String name) {
+ return t.getProperties().get (name);
+ }
+
+ public StaticProperty getStaticProperty (BackendType t, String name) {
+ return t.getStaticProperties().get (name);
+ }
+
+ public Function getOperation (BackendType t, String name, List<BackendType> paramTypes) {
+ final List<BackendType> allParamTypes = new ArrayList<BackendType> ();
+ allParamTypes.add (t);
+ allParamTypes.addAll (paramTypes);
+ return _ctx.getFunctionDefContext().getMatch (_ctx, name, allParamTypes);
+ }
+
+ //////////////////////////////////
+ // operations on Property
+ //////////////////////////////////
+
+ public Object get (Property p, Object o) {
+ return p.get (_ctx, o);
+ }
+
+ public void set (Property p, Object o, Object value) {
+ p.set (_ctx, o, value);
+ }
+
+
+ //////////////////////////////////
+ // operations on StaticProperty
+ //////////////////////////////////
+
+ public Object get (StaticProperty p) {
+ return p.get();
+ }
+}
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
new file mode 100644
index 0000000..96e6803
--- /dev/null
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/syslib/StringOperations.java
@@ -0,0 +1,64 @@
+/*
+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 org.eclipse.xtend.backend.common.EfficientLazyString;
+import org.eclipse.xtend.backend.common.ExecutionContext;
+import org.eclipse.xtend.backend.common.Helpers;
+import org.eclipse.xtend.backend.functions.java.AbstractExecutionContextAware;
+import org.eclipse.xtend.backend.functions.java.M2tHidden;
+
+
+/**
+ *
+ * @author Arno Haase (http://www.haase-consulting.com)
+ */
+public final class StringOperations extends AbstractExecutionContextAware {
+
+ public String toString (Object o) {
+ if (o == null)
+ return "";
+
+ return String.valueOf (o);
+ }
+
+ public CharSequence operatorPlus (Object o1, Object o2) {
+ return concat (o1, o2);
+ }
+
+ /**
+ * This method is duplicated with a different name so as to allow explicit concatenation
+ * even if '+' is defined for the concrete types.
+ */
+ public CharSequence concat (Object o1, Object o2) {
+ if (o1 instanceof EfficientLazyString)
+ return EfficientLazyString.createAppendedString ((EfficientLazyString) o1, overridableToString (_ctx, o2));
+
+ EfficientLazyString result = new EfficientLazyString ();
+
+ result = EfficientLazyString.createAppendedString (result, overridableToString (_ctx, o1));
+ result = EfficientLazyString.createAppendedString (result, overridableToString (_ctx, o2));
+
+ return result;
+ }
+
+ /**
+ * This method is public static so as to be available as a helper method for all code that needs to call "toString".
+ * It calls "toString" on an object, taking into account all potential overriding extensions.<br>
+ *
+ * This method is however not itself intended to be published as an extension. It is a helper function, intended to
+ * be used by other extensions.
+ */
+ @M2tHidden
+ public static CharSequence overridableToString (ExecutionContext ctx, Object o) {
+ return Helpers.overridableToString (ctx, o);
+ }
+}
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
new file mode 100644
index 0000000..1ba19c9
--- /dev/null
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/syslib/SysLibNames.java
@@ -0,0 +1,45 @@
+/*
+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 org.eclipse.xtend.backend.common.Helpers;
+
+
+/**
+ *
+ * @author Arno Haase (http://www.haase-consulting.com)
+ */
+public interface SysLibNames {
+ // special function names
+ String WRITE_TO_FILE = "writeToFile";
+ String REGISTER_OUTLET = "registerOutlet";
+
+ String TYPE_SELECT = "typeSelect";
+
+ String IMPLIES = "implies";
+
+ // function names for operator overloading
+ String OPERATOR_PLUS = "operatorPlus";
+ String OPERATOR_MINUS = "operatorMinus";
+ String OPERATOR_MULT = "operatorMult";
+ String OPERATOR_DIV = "operatorDiv";
+ String OPERATOR_MOD = "operatorMod";
+
+ String OPERATOR_EQUALS = Helpers.EQUALS_NAME;
+ String OPERATOR_NOT_EQUALS = "operatorNotEquals";
+ String OPERATOR_LESS = "operatorLess";
+ String OPERATOR_LESS_OR_EQUALS = "operatorLessOrEquals";
+ String OPERATOR_GREATER = "operatorGreater";
+ String OPERATOR_GREATER_OR_EQUALS = "operatorGreaterOrEquals";
+
+ String OPERATOR_NOT = "operatorNot";
+ String OPERATOR_UNARY_MINUS = "operatorMinus";
+}
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/syslib/SyslibContributor.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/syslib/SyslibContributor.java
new file mode 100644
index 0000000..48fedea
--- /dev/null
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/syslib/SyslibContributor.java
@@ -0,0 +1,59 @@
+/*
+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 java.io.InputStream;
+import java.util.Collection;
+
+import org.eclipse.xtend.backend.common.BackendTypesystem;
+import org.eclipse.xtend.backend.common.NamedFunction;
+import org.eclipse.xtend.backend.functions.DuplicateAwareNamedFunctionCollection;
+import org.eclipse.xtend.backend.functions.java.JavaFunctionClassContributor;
+import org.eclipse.xtend.backend.util.ErrorHandler;
+import org.eclipse.xtend.backend.util.ResourceToList;
+
+
+/**
+ *
+ * @author Arno Haase (http://www.haase-consulting.com)
+ */
+public final class SyslibContributor {
+ public static final String SYSLIB_EXTENSION_RESOURCE = "/xtend.syslib.extensions";
+
+ private final DuplicateAwareNamedFunctionCollection _functions = new DuplicateAwareNamedFunctionCollection ();
+
+ public SyslibContributor (BackendTypesystem ts) {
+ // register built-in functions
+ registerExtensionClass (ts, StringOperations.class);
+ registerExtensionClass (ts, CollectionOperations.class);
+ registerExtensionClass (ts, FileIoOperations.class);
+ registerExtensionClass (ts, PrimitiveOperations.class);
+
+ // allow external overwriting and extension
+ final InputStream in = getClass().getResourceAsStream (SYSLIB_EXTENSION_RESOURCE);
+ for (String s: new ResourceToList (in).getResult()) {
+ try {
+ registerExtensionClass(ts, Class.forName(s));
+ } catch (ClassNotFoundException e) {
+ ErrorHandler.handle (e);
+ }
+ }
+ }
+
+ private void registerExtensionClass (BackendTypesystem ts, Class<?> cls) {
+ for (NamedFunction f: new JavaFunctionClassContributor (cls, ts).getContributedFunctions())
+ _functions.register (f);
+ }
+
+ public Collection<NamedFunction> getContributedFunctions () {
+ return _functions.getFunctions();
+ }
+}
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/syslib/UriBasedPostprocessor.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/syslib/UriBasedPostprocessor.java
new file mode 100644
index 0000000..574ee6a
--- /dev/null
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/syslib/UriBasedPostprocessor.java
@@ -0,0 +1,23 @@
+/*
+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;
+
+
+/**
+ * This interface represents a postprocessor that modifies - or performs
+ * some other action based on - a file after it was persisted, e.g. written
+ * to a file.
+ *
+ * @author Arno Haase (http://www.haase-consulting.com)
+ */
+public interface UriBasedPostprocessor {
+ void process (String uri);
+}
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/CompositeTypesystem.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/CompositeTypesystem.java
index 37db3ff..50ee206 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/CompositeTypesystem.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/CompositeTypesystem.java
@@ -35,7 +35,7 @@ import org.eclipse.xtend.backend.types.builtin.StaticPropertyType;
import org.eclipse.xtend.backend.types.builtin.StringType;
import org.eclipse.xtend.backend.types.builtin.TypeType;
import org.eclipse.xtend.backend.types.builtin.VoidType;
-import org.eclipse.xtend.backend.types.java.GlobalJavaBeansTypesystem;
+import org.eclipse.xtend.backend.types.java.internal.GlobalJavaBeansTypesystem;
import org.eclipse.xtend.backend.util.Cache;
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/BuiltinProperty.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/BuiltinProperty.java
index 733d1ec..686a957 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/BuiltinProperty.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/BuiltinProperty.java
@@ -14,8 +14,8 @@ import java.lang.reflect.Method;
import org.eclipse.xtend.backend.common.BackendType;
import org.eclipse.xtend.backend.common.ExecutionContext;
-import org.eclipse.xtend.backend.functions.java.JavaBuiltinConverter;
-import org.eclipse.xtend.backend.functions.java.JavaBuiltinConverterFactory;
+import org.eclipse.xtend.backend.functions.java.internal.JavaBuiltinConverter;
+import org.eclipse.xtend.backend.functions.java.internal.JavaBuiltinConverterFactory;
import org.eclipse.xtend.backend.types.AbstractProperty;
import org.eclipse.xtend.backend.util.ErrorHandler;
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/AbstractJavaBeansTypesystem.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/internal/AbstractJavaBeansTypesystem.java
index 0cc720d..892b461 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/AbstractJavaBeansTypesystem.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/internal/AbstractJavaBeansTypesystem.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.types.java;
+package org.eclipse.xtend.backend.types.java.internal;
import java.beans.IntrospectionException;
import java.util.HashMap;
@@ -16,7 +16,7 @@ import java.util.Map;
import org.eclipse.xtend.backend.common.BackendType;
import org.eclipse.xtend.backend.common.BackendTypesystem;
-import org.eclipse.xtend.backend.functions.java.JavaBuiltinConverterFactory;
+import org.eclipse.xtend.backend.functions.java.internal.JavaBuiltinConverterFactory;
import org.eclipse.xtend.backend.util.ErrorHandler;
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/GlobalJavaBeansTypesystem.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/internal/GlobalJavaBeansTypesystem.java
index 89e6751..c04d73c 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/GlobalJavaBeansTypesystem.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/internal/GlobalJavaBeansTypesystem.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.types.java;
+package org.eclipse.xtend.backend.types.java.internal;
/**
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/JavaBeansProperty.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/internal/JavaBeansProperty.java
index 275d165..57aaba8 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/JavaBeansProperty.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/internal/JavaBeansProperty.java
@@ -8,14 +8,14 @@ http://www.eclipse.org/legal/epl-v10.html
Contributors:
Arno Haase - initial API and implementation
*/
-package org.eclipse.xtend.backend.types.java;
+package org.eclipse.xtend.backend.types.java.internal;
import java.beans.PropertyDescriptor;
import org.eclipse.xtend.backend.common.BackendType;
import org.eclipse.xtend.backend.common.ExecutionContext;
import org.eclipse.xtend.backend.common.Property;
-import org.eclipse.xtend.backend.functions.java.JavaBuiltinConverter;
+import org.eclipse.xtend.backend.functions.java.internal.JavaBuiltinConverter;
import org.eclipse.xtend.backend.util.ErrorHandler;
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/JavaBeansStaticProperty.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/internal/JavaBeansStaticProperty.java
index 03280e8..9b66658 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/JavaBeansStaticProperty.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/internal/JavaBeansStaticProperty.java
@@ -8,13 +8,13 @@ http://www.eclipse.org/legal/epl-v10.html
Contributors:
Arno Haase - initial API and implementation
*/
-package org.eclipse.xtend.backend.types.java;
+package org.eclipse.xtend.backend.types.java.internal;
import java.lang.reflect.Field;
import org.eclipse.xtend.backend.common.BackendType;
import org.eclipse.xtend.backend.common.StaticProperty;
-import org.eclipse.xtend.backend.functions.java.JavaBuiltinConverter;
+import org.eclipse.xtend.backend.functions.java.internal.JavaBuiltinConverter;
/**
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/JavaBeansType.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/internal/JavaBeansType.java
index 30f9b46..894f69f 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/JavaBeansType.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/internal/JavaBeansType.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.types.java;
+package org.eclipse.xtend.backend.types.java.internal;
import java.beans.IntrospectionException;
import java.beans.Introspector;
@@ -29,7 +29,7 @@ import org.eclipse.xtend.backend.common.ExecutionContext;
import org.eclipse.xtend.backend.common.NamedFunction;
import org.eclipse.xtend.backend.common.Property;
import org.eclipse.xtend.backend.common.StaticProperty;
-import org.eclipse.xtend.backend.functions.java.JavaBuiltinConverterFactory;
+import org.eclipse.xtend.backend.functions.java.internal.JavaBuiltinConverterFactory;
import org.eclipse.xtend.backend.types.builtin.VoidType;
import org.eclipse.xtend.backend.util.ErrorHandler;
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/JavaOperation.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/internal/JavaOperation.java
index c71fd86..a12a5ae 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/JavaOperation.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/internal/JavaOperation.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.types.java;
+package org.eclipse.xtend.backend.types.java.internal;
import java.lang.reflect.Method;
import java.util.ArrayList;
@@ -18,9 +18,9 @@ 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.functions.java.JavaBuiltinConverter;
-import org.eclipse.xtend.backend.functions.java.JavaBuiltinConverterFactory;
import org.eclipse.xtend.backend.functions.java.ParameterConverter;
+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;
@@ -32,7 +32,7 @@ import org.eclipse.xtend.backend.util.ErrorHandler;
*
* @author Arno Haase (http://www.haase-consulting.com)
*/
-public final class JavaOperation implements Function {
+final class JavaOperation implements Function {
private final Method _mtd;
private final List<BackendType> _parameterTypes;
private final ExpressionBase _guard;
diff --git a/plugins/org.eclipse.xtend.backend/todo.txt b/plugins/org.eclipse.xtend.backend/todo.txt
index 5c0d333..1941842 100644
--- a/plugins/org.eclipse.xtend.backend/todo.txt
+++ b/plugins/org.eclipse.xtend.backend/todo.txt
@@ -1,39 +1,33 @@
todo
----
-Adapter für Xpand und Xtend
+registry of handlers for different kinds of resources (including classes and byte code (?)); classes need way to express their fdc!!! --> rethink fdc concept?
+make the concept of the "XyzRegistry" explicit, common abstraction --> interoperability of languages
+configuration of backend type system - parameters to the backend?
+globalVars rauswerfen? --> ContributionStateContext?
-potential bug - EfficientLazyString is mutable || return value from cached function
+JavaBeansType: Interfaces als Supertypen
+UML type system
+logNullDeRef: log call stack including call parameters - runtime flag to log "verbosely"?
+AOP
+Profiler
-UML typesystem
Check: SourcePos-Infos in Fehlern, Exceptions in ExpressionBase ordentlich gewrappt
-logNullDeRef: log call stack including call parameters
-
-Outlets: Funktionen "registerOutlet" parallel zu "file" --> Outlets registrieren (inkl. Default-Outlet),
- Convenience mit Primitives und "richtige" Outlets. Outlet: Liefert Writer für identifizierenden
- String (d.h. Filenamen)
-
-BackendContributor: init-Methode statt Constructor-Parameter
static properties; enums
+kommentieren
+
Marker-Interface / Annotation "FunctionDefs" o.ä. --> generische Unterscheidung für Java-Importer, ob Klasse
als Bean oder als "Funktionen-Container"
-JavaBeansType: Interfaces als Supertypen
-
-syslib vervollständigen
testen, insbes. syslib
DefinitionType in FunctionType mergen
-globalVars rauswerfen?
-
dead code elimination?
isInstance
-AOP
-
Buddy Policy für syslib und backend
syslib-Funktion: allFunctions (List<Type>) --> auch Funktionen ohne Parameter zur Laufzeit
@@ -42,7 +36,6 @@ Function-Match (z.B. &myFunc (String, Foo) --> spät binden! --> dynamisch durchg
wird gematcht
Currying
Map als Builtin-Typ
-Typesystem je Compilationunit
Properties über getter/setter abbilden (z.B. im mm keine property mehr)?
Eigene Properties definieren (d.h. generische Map dafür an jedem Objekt)?
"final" (auch als Hint für Optimierung --> wird nicht durch dynamische Exytensions
@@ -67,11 +60,18 @@ replace/add von Extensions im dynamischen Scope
equals auf Type-Implementierungen
+Unterstützung
+-------------
+UML und EMF testen
+
+
Decisions
---------
Overwriting / hiding of functions is only posible for functions without guards (to avoid
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
+
Ideen für die Zukunft
---------------------
@@ -101,4 +101,7 @@ metaType etc.
EMF-Typesystem
setExecutionContext bei ExecutionContextAware nicht als exportierte Funktion behandeln
toString() überschreibbar, trotz lazy evaluation
+Operators: implies, <, <=, ==, !=, >=, >, !, unary -,
+potential bug - EfficientLazyString is mutable || return value from cached function -->
+ flag "isImmutable" in EfficientLazyString; static method "concat" insetad of "append" to treat this transparently
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 0de9210..5c371db 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
@@ -50,7 +50,7 @@ import org.eclipse.xtend.backend.expr.LiteralExpression;
import org.eclipse.xtend.backend.expr.LocalVarEvalExpression;
import org.eclipse.xtend.backend.expr.NewLocalVarDefExpression;
import org.eclipse.xtend.backend.expr.SequenceExpression;
-import org.eclipse.xtend.backend.functions.FunctionDefContextImpl;
+import org.eclipse.xtend.backend.functions.FunctionDefContextInternal;
import org.eclipse.xtend.backend.functions.SourceDefinedFunction;
import org.eclipse.xtend.backend.syslib.FileIoOperations;
import org.eclipse.xtend.backend.syslib.SysLibNames;
@@ -89,13 +89,13 @@ final class OldDefinitionConverter {
/**
* converts an extension to a function, taking care of mutual registration with its fdc
*/
- public NamedFunction create (XpandDefinition def, FunctionDefContextImpl fdc, Set<XpandDefinitionName> referencedDefinitions) {
+ public NamedFunction create (XpandDefinition def, FunctionDefContextInternal fdc, Set<XpandDefinitionName> referencedDefinitions) {
final NamedFunction result = createUnregistered (def, fdc, referencedDefinitions);
fdc.register (result);
return result;
}
- private NamedFunction createUnregistered (XpandDefinition def, FunctionDefContextImpl fdc, Set<XpandDefinitionName> referencedDefinitions) {
+ private NamedFunction createUnregistered (XpandDefinition def, FunctionDefContextInternal fdc, Set<XpandDefinitionName> referencedDefinitions) {
if (def instanceof Definition) {
final String canonicalName = new XpandDefinitionName (def).getCanonicalDefinitionName();
return new NamedFunction (canonicalName, createNormalDefinition ((Definition) def, fdc, referencedDefinitions));
diff --git a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/OldExtensionConverter.java b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/OldExtensionConverter.java
index 2b0d0ed..2579940 100644
--- a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/OldExtensionConverter.java
+++ b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/OldExtensionConverter.java
@@ -28,7 +28,7 @@ import org.eclipse.xtend.backend.common.NamedFunction;
import org.eclipse.xtend.backend.expr.CreateCachedExpression;
import org.eclipse.xtend.backend.expr.LocalVarEvalExpression;
import org.eclipse.xtend.backend.expr.NewLocalVarDefExpression;
-import org.eclipse.xtend.backend.functions.FunctionDefContextImpl;
+import org.eclipse.xtend.backend.functions.FunctionDefContextInternal;
import org.eclipse.xtend.backend.functions.SourceDefinedFunction;
import org.eclipse.xtend.backend.util.SyntaxConstants;
import org.eclipse.xtend.expression.AnalysationIssue;
@@ -56,13 +56,13 @@ final class OldExtensionConverter {
/**
* converts an extension to a function, taking care of mutual registration with its fdc
*/
- public NamedFunction create (Extension extension, FunctionDefContextImpl fdc) {
- final NamedFunction result = new NamedFunction (extension.getName(), createUnregistered(extension, fdc));
+ public NamedFunction create (Extension extension, FunctionDefContextInternal fdc) {
+ final NamedFunction result = new NamedFunction (extension.getName(), createUnregistered (extension, fdc));
fdc.register (result);
return result;
}
- private Function createUnregistered (Extension extension, FunctionDefContextImpl fdc) {
+ private Function createUnregistered (Extension extension, FunctionDefContextInternal fdc) {
if (extension instanceof JavaExtensionStatement)
return createJavaExtension ((JavaExtensionStatement) extension);
diff --git a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/OldXpandRegistry.java b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/OldXpandRegistry.java
index 319930b..3aa71d8 100644
--- a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/OldXpandRegistry.java
+++ b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/OldXpandRegistry.java
@@ -18,14 +18,14 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
-import org.eclipose.xtend.middleend.FunctionDefContextFactory;
import org.eclipse.internal.xpand2.ast.Template;
import org.eclipse.internal.xpand2.model.XpandDefinition;
import org.eclipse.xpand2.XpandExecutionContext;
import org.eclipse.xpand2.XpandUtil;
import org.eclipse.xtend.backend.common.BackendTypesystem;
import org.eclipse.xtend.backend.common.NamedFunction;
-import org.eclipse.xtend.backend.functions.FunctionDefContextImpl;
+import org.eclipse.xtend.backend.functions.FunctionDefContextFactory;
+import org.eclipse.xtend.backend.functions.FunctionDefContextInternal;
import org.eclipse.xtend.backend.util.Cache;
import org.eclipse.xtend.backend.xtendlib.XtendLibContributor;
@@ -40,9 +40,9 @@ final class OldXpandRegistry {
private final BackendTypesystem _ts;
private final OldXtendRegistry _extensions;
- private final Cache<String, FunctionDefContextImpl> _functionDefContexts = new Cache<String, FunctionDefContextImpl> () {
+ private final Cache<String, FunctionDefContextInternal> _functionDefContexts = new Cache<String, FunctionDefContextInternal> () {
@Override
- protected FunctionDefContextImpl create (String compilationUnit) {
+ protected FunctionDefContextInternal create (String compilationUnit) {
return new FunctionDefContextFactory (_ts).create();
}
};
@@ -60,7 +60,7 @@ final class OldXpandRegistry {
}
- private FunctionDefContextImpl getFunctionDefContext (String xtendName) {
+ private FunctionDefContextInternal getFunctionDefContext (String xtendName) {
return _functionDefContexts.get (OldXtendHelper.normalizeXtendResourceName (xtendName));
}
@@ -85,10 +85,10 @@ final class OldXpandRegistry {
final OldDefinitionConverter definitionFactory = new OldDefinitionConverter (ctx, typeConverter);
final List<NamedFunction> defined = new ArrayList<NamedFunction>();
- final FunctionDefContextImpl fdc = getFunctionDefContext (xpandFile);
+ final FunctionDefContextInternal fdc = getFunctionDefContext (xpandFile);
// register the XtendLib. Do this first so the extension can override functions
- fdc.register (new XtendLibContributor (_ts));
+ fdc.register (new XtendLibContributor (_ts).getContributedFunctions());
//TODO imported namespaces
diff --git a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/OldXtendRegistry.java b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/OldXtendRegistry.java
index 7bc3112..2593ef4 100644
--- a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/OldXtendRegistry.java
+++ b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/OldXtendRegistry.java
@@ -18,14 +18,14 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
-import org.eclipose.xtend.middleend.FunctionDefContextFactory;
import org.eclipse.internal.xtend.xtend.XtendFile;
import org.eclipse.internal.xtend.xtend.ast.Extension;
import org.eclipse.internal.xtend.xtend.ast.ExtensionFile;
import org.eclipse.internal.xtend.xtend.ast.ImportStatement;
import org.eclipse.xtend.backend.common.BackendTypesystem;
import org.eclipse.xtend.backend.common.NamedFunction;
-import org.eclipse.xtend.backend.functions.FunctionDefContextImpl;
+import org.eclipse.xtend.backend.functions.FunctionDefContextFactory;
+import org.eclipse.xtend.backend.functions.FunctionDefContextInternal;
import org.eclipse.xtend.backend.util.Cache;
import org.eclipse.xtend.backend.xtendlib.XtendLibContributor;
import org.eclipse.xtend.expression.ExecutionContext;
@@ -40,9 +40,9 @@ final class OldXtendRegistry {
private final ExecutionContext _ctx;
private final BackendTypesystem _ts;
- private final Cache<String, FunctionDefContextImpl> _functionDefContexts = new Cache<String, FunctionDefContextImpl> () {
+ private final Cache<String, FunctionDefContextInternal> _functionDefContexts = new Cache<String, FunctionDefContextInternal> () {
@Override
- protected FunctionDefContextImpl create (String compilationUnit) {
+ protected FunctionDefContextInternal create (String compilationUnit) {
return new FunctionDefContextFactory (_ts).create();
}
};
@@ -71,7 +71,7 @@ final class OldXtendRegistry {
}
- private FunctionDefContextImpl getFunctionDefContext (String xtendName) {
+ private FunctionDefContextInternal getFunctionDefContext (String xtendName) {
return _functionDefContexts.get (OldXtendHelper.normalizeXtendResourceName (xtendName));
}
@@ -100,10 +100,10 @@ final class OldXtendRegistry {
final List<NamedFunction> defined = new ArrayList<NamedFunction>();
final List<NamedFunction> exported = new ArrayList<NamedFunction>();
- final FunctionDefContextImpl fdc = getFunctionDefContext (xtendFile);
+ final FunctionDefContextInternal fdc = getFunctionDefContext (xtendFile);
// register the XtendLib. Do this first so the extension can override functions
- fdc.register (new XtendLibContributor (_ts));
+ fdc.register (new XtendLibContributor (_ts).getContributedFunctions());
for (Extension ext: file.getExtensions()) {
final NamedFunction f = extensionFactory.create (ext, fdc);
diff --git a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/XpandBackendFacade.java b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/XpandBackendFacade.java
index cb7d17c..61ba1df 100644
--- a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/XpandBackendFacade.java
+++ b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/XpandBackendFacade.java
@@ -20,7 +20,6 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
-import org.eclipose.xtend.middleend.FunctionDefContextFactory;
import org.eclipse.internal.xpand2.ast.Definition;
import org.eclipse.internal.xpand2.ast.Statement;
import org.eclipse.internal.xpand2.ast.Template;
@@ -39,7 +38,8 @@ import org.eclipse.xtend.backend.common.ExecutionContext;
import org.eclipse.xtend.backend.common.ExpressionBase;
import org.eclipse.xtend.backend.common.FunctionDefContext;
import org.eclipse.xtend.backend.common.NamedFunction;
-import org.eclipse.xtend.backend.functions.FunctionDefContextImpl;
+import org.eclipse.xtend.backend.functions.FunctionDefContextFactory;
+import org.eclipse.xtend.backend.functions.FunctionDefContextInternal;
import org.eclipse.xtend.backend.functions.SourceDefinedFunction;
import org.eclipse.xtend.backend.syslib.FileIoOperations;
import org.eclipse.xtend.backend.syslib.FileOutlet;
@@ -113,7 +113,7 @@ public final class XpandBackendFacade {
final ExpressionBase converted = defConverter.convertStatementSequence (statements, tpl, referenced);
- final FunctionDefContextImpl fdc = new FunctionDefContextFactory (ts).create();
+ final FunctionDefContextInternal fdc = new FunctionDefContextFactory (ts).create();
//TODO refactor this to extract common code - both from here and from OldXpandRegistry
final OldXpandRegistry oxr = new OldXpandRegistry (ctx, ts, new OldXtendRegistry (ctx, ts));
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 f6ffec2..94abeef 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
@@ -16,7 +16,6 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
-import org.eclipose.xtend.middleend.FunctionDefContextFactory;
import org.eclipse.internal.xtend.expression.ast.Expression;
import org.eclipse.internal.xtend.xtend.parser.ParseFacade;
import org.eclipse.xtend.backend.BackendFacade;
@@ -25,6 +24,7 @@ import org.eclipse.xtend.backend.common.ExecutionContext;
import org.eclipse.xtend.backend.common.ExpressionBase;
import org.eclipse.xtend.backend.common.FunctionDefContext;
import org.eclipse.xtend.backend.common.NamedFunction;
+import org.eclipse.xtend.backend.functions.FunctionDefContextFactory;
import org.eclipse.xtend.backend.functions.SourceDefinedFunction;
import org.eclipse.xtend.expression.ExecutionContextImpl;
import org.eclipse.xtend.expression.Variable;
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 52ed5fe..18b6725 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,8 +16,18 @@ 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.types.CompositeTypesystem;
+import org.eclipse.xtend.backend.types.builtin.ObjectType;
import org.junit.Test;
@@ -39,4 +49,35 @@ public class ConcatExpressionTest {
private Object eval (ExpressionBase... parts) {
return new ConcatExpression (Arrays.asList(parts), SOURCE_POS).evaluate (createEmptyExecutionContext()).toString();
}
+
+ @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);
+ }
+
+ public Object invoke (ExecutionContext ctx, Object[] params) {
+ return "#" + params[0] + "!";
+ }
+
+ public boolean isCached () {
+ return false;
+ }
+ });
+
+ final FunctionDefContextInternal fdc = new FunctionDefContextFactory (new CompositeTypesystem ()).create();
+ fdc.register (myToString);
+
+ final ExpressionBase expr = new ConcatExpression (Arrays.asList (createLiteral("a"), createLiteral("b")), SOURCE_POS);
+
+ final ExecutionContext ctx = createEmptyExecutionContext();
+ assertEquals ("ab", expr.evaluate(ctx).toString());
+
+ ctx.setFunctionDefContext(fdc);
+ assertEquals ("#a!#b!", expr.evaluate(ctx).toString());
+ }
}
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 64160b7..f230d04 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
@@ -18,7 +18,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-import org.eclipose.xtend.middleend.FunctionDefContextFactory;
import org.eclipse.xtend.backend.BackendFacade;
import org.eclipse.xtend.backend.common.BackendType;
import org.eclipse.xtend.backend.common.BackendTypesystem;
@@ -26,7 +25,8 @@ 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.FunctionDefContextImpl;
+import org.eclipse.xtend.backend.functions.FunctionDefContextFactory;
+import org.eclipse.xtend.backend.functions.FunctionDefContextInternal;
import org.eclipse.xtend.backend.types.CompositeTypesystem;
import org.eclipse.xtend.backend.types.builtin.StringType;
import org.junit.Test;
@@ -78,7 +78,7 @@ public class InitClosureExpressionTest {
@Test public void testFdcPropagation () {
final BackendTypesystem ts = new CompositeTypesystem ();
- final FunctionDefContextImpl fdc = new FunctionDefContextFactory (ts).create();
+ final FunctionDefContextInternal fdc = new FunctionDefContextFactory (ts).create();
fdc.register (new NamedFunction ("myFunction", new Function () {
public ExpressionBase getGuard () {
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 39fa9d6..5f70b92 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
@@ -18,13 +18,13 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-import org.eclipose.xtend.middleend.FunctionDefContextFactory;
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.FunctionDefContextImpl;
+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.types.CompositeTypesystem;
import org.eclipse.xtend.backend.types.builtin.StringType;
@@ -126,7 +126,7 @@ public class SwitchExpressionTest {
}
});
- final FunctionDefContextImpl fdc = new FunctionDefContextFactory (new CompositeTypesystem ()).create();
+ final FunctionDefContextInternal fdc = new FunctionDefContextFactory (new CompositeTypesystem ()).create();
fdc.register (myStringEquals);
final ExecutionContext ctx = createEmptyExecutionContext();
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
new file mode 100644
index 0000000..97ea3a1
--- /dev/null
+++ b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/functions/PolymorphicResolverTest.java
@@ -0,0 +1,54 @@
+/*
+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.Arrays;
+import java.util.Collection;
+
+import org.eclipse.xtend.backend.common.Function;
+import org.eclipse.xtend.backend.functions.internal.FunctionDefContextImpl;
+import org.eclipse.xtend.backend.functions.internal.PolymorphicResolver;
+import org.eclipse.xtend.backend.types.CompositeTypesystem;
+import org.junit.Test;
+
+/**
+ *
+ * @author Arno Haase (http://www.haase-consulting.com)
+ */
+public class PolymorphicResolverTest {
+ @Test public void testWithoutGuards () {
+ // this test relies on there being five syslib implementations of operatorPlus - four for the
+ // combinations of Long and Double, and one for Object and Object
+ assertEquals (1, getCandidates (2L, 2.0).size());
+ assertEquals (1, getCandidates (2.0, 2L).size());
+
+ assertEquals (1, getCandidates ("a", "b").size ());
+
+ assertEquals (2, getCandidates (null, 2.0).size ());
+ assertEquals (2, getCandidates (2.0, null).size ());
+ assertEquals (2, getCandidates (null, 2L).size ());
+ assertEquals (2, getCandidates (2L, null).size ());
+ assertEquals (4, getCandidates (null, null).size ());
+
+ assertEquals (1, getCandidates (null, "a").size ());
+ assertEquals (1, getCandidates ("a", null).size ());
+ }
+
+ private Collection<Function> getCandidates (Object... params) {
+ final FunctionDefContextImpl fdc = (FunctionDefContextImpl) new FunctionDefContextFactory (new CompositeTypesystem ()).create();
+ return new PolymorphicResolver ("operatorPlus").getBestFitCandidates (fdc.findFunctionCandidates (createEmptyExecutionContext(), "operatorPlus", Arrays.asList (params)));
+ }
+
+ //TODO test resolution with guards
+}
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/helpers/BackendTestHelper.java
index 1c92862..daec6f1 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/helpers/BackendTestHelper.java
@@ -16,8 +16,7 @@ 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.expr.LiteralExpression;
-import org.eclipse.xtend.backend.functions.FunctionDefContextImpl;
-import org.eclipse.xtend.backend.syslib.SyslibContributor;
+import org.eclipse.xtend.backend.functions.FunctionDefContextFactory;
import org.eclipse.xtend.backend.types.CompositeTypesystem;
@@ -34,7 +33,7 @@ public class BackendTestHelper {
*/
public static ExecutionContext createEmptyExecutionContext () {
final BackendTypesystem ts = new CompositeTypesystem ();
- return BackendFacade.createExecutionContext (new FunctionDefContextImpl (new SyslibContributor (ts)), ts);
+ return BackendFacade.createExecutionContext (new FunctionDefContextFactory (ts).create(), ts);
}
public static ExpressionBase createLiteral (Object literal) {
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
new file mode 100644
index 0000000..b551fec
--- /dev/null
+++ b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/types/AbstractTypeTest.java
@@ -0,0 +1,31 @@
+/*
+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.junit.Assert.*;
+import static org.eclipse.xtend.backend.helpers.BackendTestHelper.*;
+
+import java.util.Arrays;
+
+import org.eclipse.xtend.backend.expr.PropertyOnObjectExpression;
+import org.junit.Test;
+
+
+/**
+ *
+ * @author Arno Haase (http://www.haase-consulting.com)
+ */
+public class AbstractTypeTest {
+ @Test public void testInheritedProperties () {
+ // tests that ListType inherits the property "size" from CollectionType
+ assertEquals (2L, new PropertyOnObjectExpression (createLiteral (Arrays.asList ("a", "b")), "size", SOURCE_POS).evaluate (createEmptyExecutionContext()));
+ }
+}
diff --git a/tests/org.eclipse.xtend.backend.test/todo.txt b/tests/org.eclipse.xtend.backend.test/todo.txt
index ce1bffa..9727ea9 100644
--- a/tests/org.eclipse.xtend.backend.test/todo.txt
+++ b/tests/org.eclipse.xtend.backend.test/todo.txt
@@ -1,5 +1,7 @@
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
@@ -12,9 +14,9 @@ expression-Implementierungen
Aufruf der Listener
CurriedFunction, CurryingExpression
GlobalParamExpression
-Verwendung von syslib für toString: ConcatExpression, operatorPlus,
+Verwendung von syslib für toString: operatorPlus,
syslib-Implementierungen
Schreiben in Files