summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorahaase2008-01-30 07:26:33 (EST)
committer ahaase2008-01-30 07:26:33 (EST)
commit6e978053be2da94ae2f01f4ac9fdad8259c2c0a9 (patch)
tree13289c7d8ab1a8eb48f53023a43ca3931687adc6
parent68d7497b3ddbc8968b45dc39580a8aabfed42fc1 (diff)
downloadorg.eclipse.xpand-6e978053be2da94ae2f01f4ac9fdad8259c2c0a9.zip
org.eclipse.xpand-6e978053be2da94ae2f01f4ac9fdad8259c2c0a9.tar.gz
org.eclipse.xpand-6e978053be2da94ae2f01f4ac9fdad8259c2c0a9.tar.bz2
Bugfix: added conversion between Java types and canonical internal representations for method-based *properties*
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/functions/java/JavaDefinedFunction.java11
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/AbstractProperty.java52
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/BuiltinProperty.java43
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/StringType.java2
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/TypeType.java3
5 files changed, 85 insertions, 26 deletions
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 42231ef..fa09b26 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
@@ -13,6 +13,7 @@ package org.eclipse.xtend.backend.functions.java;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import org.eclipse.xtend.backend.common.BackendType;
@@ -157,7 +158,15 @@ public final class JavaDefinedFunction implements Function {
return _returnValueConverter.javaToBackend (resultRaw);
} catch (Exception e) {
- ErrorHandler.handle(e);
+ final List<String> paramTypes = new ArrayList<String> ();
+ for (Object p: params) {
+ if (p == null)
+ paramTypes.add (Void.TYPE.getName());
+ else
+ paramTypes.add (p.getClass().getName());
+ }
+
+ ErrorHandler.handle ("could not invoke method " + _mtd + " with parameters " + Arrays.asList(params) + " of types " + paramTypes, e);
return null; // to make the compiler happy - this is never executed
}
}
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/AbstractProperty.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/AbstractProperty.java
new file mode 100644
index 0000000..1b1b960
--- /dev/null
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/AbstractProperty.java
@@ -0,0 +1,52 @@
+/*
+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 org.eclipse.xtend.backend.common.BackendType;
+import org.eclipse.xtend.backend.common.ExecutionContext;
+import org.eclipse.xtend.backend.common.Property;
+
+
+/**
+ *
+ * @author Arno Haase (http://www.haase-consulting.com)
+ */
+public abstract class AbstractProperty implements Property {
+ protected final BackendType _owner;
+ protected final BackendType _type;
+ protected final String _name;
+
+ public AbstractProperty (BackendType owner, BackendType type, String name) {
+ _owner = owner;
+ _type = type;
+ _name = name;
+ }
+
+ public String getName () {
+ return _name;
+ }
+
+ public BackendType getOwner () {
+ return _owner;
+ }
+
+ public BackendType getType () {
+ return _type;
+ }
+
+ public Object get (ExecutionContext ctx, Object o) {
+ throw new IllegalStateException ("property " + _name + " of type " + _owner.getName() + " can not be read");
+ }
+
+ public void set (ExecutionContext ctx, Object o, Object newValue) {
+ throw new IllegalStateException ("property " + _name + " of type " + _owner.getName() + " can not be set");
+ }
+}
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 80693be..47f5612 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,7 +14,9 @@ import java.lang.reflect.Method;
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.JavaBuiltinConverterFactory;
+import org.eclipse.xtend.backend.types.AbstractProperty;
import org.eclipse.xtend.backend.util.ErrorHandler;
@@ -22,51 +24,46 @@ import org.eclipse.xtend.backend.util.ErrorHandler;
*
* @author Arno Haase (http://www.haase-consulting.com)
*/
-public class BuiltinProperty implements Property {
- private final BackendType _owner;
- private final BackendType _type;
- private final String _name;
+public final class BuiltinProperty extends AbstractProperty {
private final Method _getter;
private final Method _setter;
+ private final JavaBuiltinConverter _converter;
+
public BuiltinProperty (BackendType owner, BackendType type, String name, Method getter, Method setter) {
- _owner = owner;
- _type = type;
- _name = name;
+ super (owner, type, name);
_getter = getter;
_setter = setter;
+
+ _converter = JavaBuiltinConverterFactory.getConverter (getJavaClassForProperty (getter, setter));
}
- public String getName () {
- return _name;
- }
-
- public BackendType getOwner () {
- return _owner;
- }
-
- public BackendType getType () {
- return _type;
+ private static Class<?> getJavaClassForProperty (Method getter, Method setter) {
+ if (getter != null)
+ return getter.getReturnType();
+ return setter.getParameterTypes()[0];
}
+ @Override
public Object get (ExecutionContext ctx, Object o) {
if (_getter == null)
- throw new IllegalStateException ("property " + _name + " of type " + _owner.getName() + " can not be read");
+ super.get (ctx, o);
try {
- return _getter.invoke(o);
+ return _converter.javaToBackend (_getter.invoke(o));
} catch (Exception e) {
ErrorHandler.handle(e);
return null; // to make the compiler happy - this is never executed
}
}
+ @Override
public void set (ExecutionContext ctx, Object o, Object newValue) {
- if (_getter == null)
- throw new IllegalStateException ("property " + _name + " of type " + _owner.getName() + " can not be set");
+ if (_setter == null)
+ super.set (ctx, o, newValue);
try {
- _setter.invoke (o, newValue);
+ _setter.invoke (o, _converter.backendToJava (newValue));
} catch (Exception e) {
ErrorHandler.handle(e);
}
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/StringType.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/StringType.java
index 9c9a2ed..6195402 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/StringType.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/StringType.java
@@ -31,7 +31,7 @@ public final class StringType extends AbstractType {
private StringType () {
super ("String");
- register (new BuiltinProperty (this, StringType.INSTANCE, "length", ReflectionHelper.getKnownMethod(CharSequence.class, "length"), null));
+ register (new BuiltinProperty (this, StringType.INSTANCE, "length", ReflectionHelper.getKnownMethod (CharSequence.class, "length"), null));
}
public boolean isAssignableFrom (BackendType other) {
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/TypeType.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/TypeType.java
index 9ae75ea..b7d1794 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/TypeType.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/TypeType.java
@@ -15,6 +15,7 @@ import java.util.List;
import org.eclipse.xtend.backend.common.BackendType;
import org.eclipse.xtend.backend.common.ExecutionContext;
+import org.eclipse.xtend.backend.types.AbstractProperty;
import org.eclipse.xtend.backend.types.AbstractType;
import org.eclipse.xtend.backend.util.ReflectionHelper;
@@ -35,7 +36,7 @@ public final class TypeType extends AbstractType {
register (new BuiltinProperty (this, ListType.INSTANCE, "allProperties", ReflectionHelper.getKnownMethod (BackendType.class, "getProperties"), null));
register (new BuiltinProperty (this, ListType.INSTANCE, "allStaticProperties", ReflectionHelper.getKnownMethod (BackendType.class, "getStaticProperties"), null));
- register (new BuiltinProperty (this, ListType.INSTANCE, "allOperations", null, null) {
+ register (new AbstractProperty (this, ListType.INSTANCE, "allOperations") {
@Override
public Object get (ExecutionContext ctx, Object o) {
final BackendType t = (BackendType) o;