summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorahaase2008-01-23 08:22:49 (EST)
committerahaase2008-01-23 08:22:49 (EST)
commit69940dc01c20e9647ada3cf773fa7662bede0358 (patch)
treed6020c4d26449204b06698f29e2125fc82deb0ae
parent533f247def6b244187390d5de73b2cd200b6b2e0 (diff)
downloadorg.eclipse.xpand-69940dc01c20e9647ada3cf773fa7662bede0358.zip
org.eclipse.xpand-69940dc01c20e9647ada3cf773fa7662bede0358.tar.gz
org.eclipse.xpand-69940dc01c20e9647ada3cf773fa7662bede0358.tar.bz2
cleaned up: Java function support moved from the Java type system into the real backend
-rw-r--r--plugins/org.eclipse.xtend.backend/META-INF/MANIFEST.MF1
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/ArrayConverter.java30
-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/EfficientLazyStringConverter.java25
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/ExecutionContextAware.java26
-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/JavaBuiltinConverterFactory.java91
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/JavaDefinedFunction.java186
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/JavaFunctionClassContributor.java46
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/M2tHidden.java27
-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.java24
-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
17 files changed, 603 insertions, 0 deletions
diff --git a/plugins/org.eclipse.xtend.backend/META-INF/MANIFEST.MF b/plugins/org.eclipse.xtend.backend/META-INF/MANIFEST.MF
index 67e0f7c..7b87b10 100644
--- a/plugins/org.eclipse.xtend.backend/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.xtend.backend/META-INF/MANIFEST.MF
@@ -7,6 +7,7 @@ Export-Package: org.eclipse.xtend.backend,
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,
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/ArrayConverter.java
new file mode 100644
index 0000000..4c82603
--- /dev/null
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/ArrayConverter.java
@@ -0,0 +1,30 @@
+package org.eclipse.xtend.backend.functions.java;
+
+import java.lang.reflect.Array;
+import java.util.Arrays;
+import java.util.List;
+
+
+class ArrayConverter implements JavaBuiltinConverter {
+ private final Class<?> _componentType;
+
+ public ArrayConverter (Class<?> componentType) {
+ _componentType = componentType;
+ }
+
+ public Object backendToJava (Object o) {
+ if (o == null)
+ return null;
+
+ final List<?> l = (List<?>) o;
+ final Object[] result = (Object[]) Array.newInstance (_componentType, l.size());
+ return l.toArray (result);
+ }
+
+ public Object javaToBackend (Object o) {
+ if (o == null)
+ return null;
+
+ return Arrays.asList ((Object[]) o);
+ }
+}
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
new file mode 100644
index 0000000..e7cd036
--- /dev/null
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/ByteConverter.java
@@ -0,0 +1,18 @@
+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
new file mode 100644
index 0000000..4680a13
--- /dev/null
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/CharConverter.java
@@ -0,0 +1,19 @@
+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/EfficientLazyStringConverter.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/EfficientLazyStringConverter.java
new file mode 100644
index 0000000..10daf1a
--- /dev/null
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/EfficientLazyStringConverter.java
@@ -0,0 +1,25 @@
+package org.eclipse.xtend.backend.functions.java;
+
+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.
+ */
+class EfficientLazyStringConverter implements JavaBuiltinConverter {
+
+ public Object backendToJava (Object o) {
+ if (o == null)
+ return null;
+
+ final EfficientLazyString result = new EfficientLazyString ();
+ result.append (o);
+ return result;
+ }
+
+ public Object javaToBackend (Object o) {
+ return o;
+ }
+}
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/ExecutionContextAware.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/ExecutionContextAware.java
new file mode 100644
index 0000000..b73391f
--- /dev/null
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/ExecutionContextAware.java
@@ -0,0 +1,26 @@
+/*
+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.common.ExecutionContext;
+
+
+/**
+ * This marker interface gives Java extensions access to the execution context.
+ * if the class providing a Java extension implements this interface, the executor
+ * calls the setExecutionContext method to ensure that the method has access to
+ * the current ExecutionContext.
+ *
+ * @author Arno Haase (http://www.haase-consulting.com)
+ */
+public interface ExecutionContextAware {
+ void setExecutionContext (ExecutionContext ctx);
+}
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
new file mode 100644
index 0000000..fe1ebec
--- /dev/null
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/FloatConverter.java
@@ -0,0 +1,18 @@
+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
new file mode 100644
index 0000000..6f0ec56
--- /dev/null
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/IntConverter.java
@@ -0,0 +1,18 @@
+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
new file mode 100644
index 0000000..59c1a54
--- /dev/null
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/JavaBuiltinConverter.java
@@ -0,0 +1,17 @@
+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/JavaBuiltinConverterFactory.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/JavaBuiltinConverterFactory.java
new file mode 100644
index 0000000..c6e4a94
--- /dev/null
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/JavaBuiltinConverterFactory.java
@@ -0,0 +1,91 @@
+package org.eclipse.xtend.backend.functions.java;
+
+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.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 {
+ private static final Map<Class<?>, JavaBuiltinConverter> _converters = new HashMap<Class<?>, JavaBuiltinConverter> ();
+ private static final Map<Class<?>, BackendType> _additionalTypes = new HashMap<Class<?>, BackendType> ();
+
+ static {
+ _converters.put (Integer.class, new IntConverter ());
+ _converters.put (Integer.TYPE, new IntConverter ());
+ _converters.put (Short.class, new ShortConverter ());
+ _converters.put (Short.TYPE, new ShortConverter ());
+ _converters.put (Byte.class, new ByteConverter ());
+ _converters.put (Byte.TYPE, new ByteConverter ());
+
+ _converters.put (Float.class, new FloatConverter ());
+ _converters.put (Float.TYPE, new FloatConverter ());
+
+ _converters.put (Character.class, new CharConverter ());
+ _converters.put (Character.TYPE, new CharConverter ());
+
+ _converters.put (String.class, new StringConverter ());
+ _converters.put (EfficientLazyString.class, new EfficientLazyStringConverter ());
+ }
+
+ static {
+ _additionalTypes.put (Integer.class, LongType.INSTANCE);
+ _additionalTypes.put (Integer.TYPE, LongType.INSTANCE);
+ _additionalTypes.put (Short.class, LongType.INSTANCE);
+ _additionalTypes.put (Short.TYPE, LongType.INSTANCE);
+ _additionalTypes.put (Byte.class, LongType.INSTANCE);
+ _additionalTypes.put (Byte.TYPE, LongType.INSTANCE);
+
+ _additionalTypes.put (Float.class, DoubleType.INSTANCE);
+ _additionalTypes.put (Float.TYPE, DoubleType.INSTANCE);
+
+ _additionalTypes.put (Character.class, StringType.INSTANCE);
+ _additionalTypes.put (Character.TYPE, StringType.INSTANCE);
+ }
+
+ public static JavaBuiltinConverter getConverter (Class<?> cls) {
+ final JavaBuiltinConverter resultRaw = _converters.get (cls);
+ if (resultRaw != null)
+ return resultRaw;
+
+ if (cls.isArray())
+ return new ArrayConverter (cls.getComponentType());
+
+ return NullConverter.INSTANCE;
+ }
+
+
+ /**
+ * This method returns a wrapper around a JavaBuiltinConverter that knows about the index of a (parameter) array.
+ */
+ public static ParameterConverter getParameterConverter (Class<?> paramClass, int index) {
+ final JavaBuiltinConverter inner = getConverter(paramClass);
+ if (inner == NullConverter.INSTANCE)
+ return null;
+
+ return new ParameterConverter (index, inner);
+ }
+
+
+ /**
+ * This method retrieves the backend type for non-standard built-in Java types.
+ */
+ public static BackendType getTypeForAdditionalBuiltin (Class<?> cls) {
+ final BackendType resultRaw = _additionalTypes.get (cls);
+ if (resultRaw != null)
+ return resultRaw;
+
+ if (cls.isArray())
+ return ListType.INSTANCE;
+
+ return null;
+ }
+}
+
+
+
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
new file mode 100644
index 0000000..42231ef
--- /dev/null
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/JavaDefinedFunction.java
@@ -0,0 +1,186 @@
+/*
+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 java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.xtend.backend.common.BackendType;
+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.util.ErrorHandler;
+
+
+/**
+ * This class represents a "helper" function that is defined in a Java class but for which the defining
+ * object is not an explicit parameter. It is used for "JAVA extension" style functions. <br>
+ *
+ * If it represents a non-static method, a single instance of the underlying class is shared by all methods
+ * of the class, and across all compilation units etc. from which they are referenced. This single instance
+ * is scoped with the ExecutionContext used.
+ *
+ * @author Arno Haase (http://www.haase-consulting.com)
+ */
+public final class JavaDefinedFunction implements Function {
+ private final Method _mtd;
+ private final List<BackendType> _parameterTypes;
+ private final ExpressionBase _guard;
+ private final boolean _isStatic;
+
+ private final List<ParameterConverter> _parameterConverters = new ArrayList<ParameterConverter>();
+ private final JavaBuiltinConverter _returnValueConverter;
+
+
+ /**
+ * This is a convenience factory method that creates functions for all public methods for an entire class.
+ */
+ public static List<JavaDefinedFunction> createForEntireClass (Class<?> cls, BackendTypesystem ts) {
+ final List<JavaDefinedFunction> result = new ArrayList<JavaDefinedFunction>();
+
+ for (Method mtd: cls.getDeclaredMethods()) {
+ // register only public methods
+ if (! isPublic (mtd))
+ continue;
+
+ // do not register infrastructure methods inherited from ExecutionContextAware
+ if (ExecutionContextAware.class.isAssignableFrom (cls)) {
+ try {
+ ExecutionContextAware.class.getMethod (mtd.getName(), mtd.getParameterTypes());
+ continue;
+ }
+ catch (NoSuchMethodException e) {
+ }
+ }
+
+ if (mtd.getAnnotation (M2tHidden.class) != null)
+ continue;
+
+ result.add (new JavaDefinedFunction (mtd, null, ts));
+ }
+ return result;
+ }
+
+ private static boolean isPublic (Method mtd) {
+ return (mtd.getModifiers() & Modifier.PUBLIC) != 0;
+ }
+
+
+ /**
+ * shortcut constructor that attempts to derive the parameter types from the method's signature
+ */
+ public JavaDefinedFunction (Method mtd, ExpressionBase guard, BackendTypesystem ts) {
+ this (mtd, guessParameterTypes(mtd, ts), guard);
+ }
+
+
+ /**
+ * This constructor provides full control
+ */
+ public JavaDefinedFunction (Method mtd, List<BackendType> parameterTypes, ExpressionBase guard) {
+ _mtd = mtd;
+ _parameterTypes = parameterTypes;
+ _guard = guard;
+
+ for (int i=0; i<mtd.getParameterTypes().length; i++) {
+ final ParameterConverter pc = JavaBuiltinConverterFactory.getParameterConverter (mtd.getParameterTypes()[i], i);
+ if (pc != null)
+ _parameterConverters.add(pc);
+ }
+
+ _returnValueConverter = JavaBuiltinConverterFactory.getConverter (mtd.getReturnType());
+
+ _isStatic = (mtd.getModifiers() & Modifier.STATIC) != 0;
+ }
+
+ private Object getInstance (ExecutionContext ctx) {
+ if (_isStatic)
+ return null;
+
+ try {
+ Object result = ctx.getContributionStateContext().retrieveState (_mtd.getDeclaringClass());
+ if (result == null) {
+ result = _mtd.getDeclaringClass().newInstance();
+ ctx.getContributionStateContext().storeState(_mtd.getDeclaringClass(), result);
+ }
+ return result;
+ }
+ catch (Exception exc) {
+ ErrorHandler.handle (exc);
+ return null; // just for the compiler - this is never executed
+ }
+ }
+
+ public static List<BackendType> guessParameterTypes (Method mtd, BackendTypesystem ts) {
+ final List<BackendType> result = new ArrayList<BackendType>();
+
+ for (Class<?> cls: mtd.getParameterTypes())
+ result.add (ts.findType (cls));
+
+ return result;
+ }
+
+ public String getName () {
+ return _mtd.getName();
+ }
+
+ public boolean isCached () {
+ return false;
+ }
+
+ public List<BackendType> getParameterTypes() {
+ return _parameterTypes;
+ }
+
+ public Object invoke (ExecutionContext ctx, Object[] params) {
+ for (ParameterConverter pc: _parameterConverters)
+ pc.convert(params);
+
+ Object o = getInstance (ctx);
+ if (o instanceof ExecutionContextAware) {
+ ((ExecutionContextAware) o).setExecutionContext (ctx);
+ }
+
+ try {
+ final Object resultRaw = _mtd.invoke (o, params);
+ return _returnValueConverter.javaToBackend (resultRaw);
+
+ } catch (Exception e) {
+ ErrorHandler.handle(e);
+ return null; // to make the compiler happy - this is never executed
+ }
+ }
+
+ public ExpressionBase getGuard () {
+ return _guard;
+ }
+
+ @Override
+ public String toString () {
+ return "JavaDefinedFunction '" + getName() + "' " + _parameterTypes;
+ }
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
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
new file mode 100644
index 0000000..d2899c8
--- /dev/null
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/JavaFunctionClassContributor.java
@@ -0,0 +1,46 @@
+/*
+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 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;
+
+
+/**
+ * This class contributes no types, but all public methods in a Java class as functions, both static and
+ * non-static. Non-static methods share an instance of the providing class *per Contributor instance*.
+ * For more global sharing of the instance, Contributor instances must be shared.
+ *
+ * @author Arno Haase (http://www.haase-consulting.com)
+ */
+public final class JavaFunctionClassContributor implements BackendContributor {
+ private final List<NamedFunction> _functions = new ArrayList<NamedFunction>();
+
+ public JavaFunctionClassContributor (Class<?> cls, BackendTypesystem ts) {
+ for (JavaDefinedFunction f: JavaDefinedFunction.createForEntireClass (cls, ts))
+ _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/M2tHidden.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/M2tHidden.java
new file mode 100644
index 0000000..167ba6c
--- /dev/null
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/M2tHidden.java
@@ -0,0 +1,27 @@
+/*
+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 java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+
+/**
+ * Methods marked with this annotation will not be registered as extensions if their class is registered
+ *
+ * @author Arno Haase (http://www.haase-consulting.com)
+ */
+@Retention (RetentionPolicy.RUNTIME)
+@Target (ElementType.METHOD)
+public @interface M2tHidden {
+}
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
new file mode 100644
index 0000000..7774e86
--- /dev/null
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/NullConverter.java
@@ -0,0 +1,19 @@
+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
new file mode 100644
index 0000000..cc91db0
--- /dev/null
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/ParameterConverter.java
@@ -0,0 +1,24 @@
+package org.eclipse.xtend.backend.functions.java;
+
+
+/**
+ * This class serves as an abstraction to convert between the internal, canonical representation
+ * of the instances of a type, and a variation thereof needed by a specific operation (specifically,
+ * a Java implementation).<p>
+ *
+ * Examples of this are the List <--> Array conversion, int <--> long, float <--> double or
+ * CharSequence <--> String.
+ */
+public final class ParameterConverter {
+ private final int _index;
+ private final JavaBuiltinConverter _inner;
+
+ public ParameterConverter (int index, JavaBuiltinConverter inner) {
+ _index = index;
+ _inner = inner;
+ }
+
+ public void convert (Object[] params) {
+ params [_index] = _inner.backendToJava (params[_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
new file mode 100644
index 0000000..ded3adc
--- /dev/null
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/ShortConverter.java
@@ -0,0 +1,18 @@
+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
new file mode 100644
index 0000000..6599b64
--- /dev/null
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/StringConverter.java
@@ -0,0 +1,20 @@
+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;
+ }
+}