Commit 053c6fcf authored by mevenson@1c010e3e-69d0-11dd-93a8-456734b0d56f's avatar mevenson@1c010e3e-69d0-11dd-93a8-456734b0d56f
Browse files

Make JCALL work in more places.

A reimplementation of org.apache.commons.lang.ClassUtils.isAssignable
instead of the standard isAssignableFrom test.

<http://abcl.org/trac/ticket/352> .

From Olof.
parent b95802eb
...@@ -1040,17 +1040,32 @@ public final class Java ...@@ -1040,17 +1040,32 @@ public final class Java
return result; return result;
} }
private static boolean isAssignable(Class<?> from, Class<?> to) {
from = maybeBoxClass(from);
to = maybeBoxClass(to);
if (to.isAssignableFrom(from)) {
return true;
}
if (Byte.class.equals(from)) {
return Short.class.equals(to) || Integer.class.equals(to) || Long.class.equals(to) || Float.class.equals(to) || Double.class.equals(to);
} else if (Short.class.equals(from) || Character.class.equals(from)) {
return Integer.class.equals(to) || Long.class.equals(to) || Float.class.equals(to) || Double.class.equals(to);
} else if (Integer.class.equals(from)) {
return Long.class.equals(to) || Float.class.equals(to) || Double.class.equals(to);
} else if (Long.class.equals(from)) {
return Float.class.equals(to) || Double.class.equals(to);
} else if (Float.class.equals(from)) {
return Double.class.equals(to);
}
return false;
}
private static boolean isApplicableMethod(Class<?>[] methodTypes, private static boolean isApplicableMethod(Class<?>[] methodTypes,
Object[] args) { Object[] args) {
for (int i = 0; i < methodTypes.length; ++i) { for (int i = 0; i < methodTypes.length; ++i) {
Class<?> methodType = methodTypes[i]; Class<?> methodType = methodTypes[i];
Object arg = args[i]; Object arg = args[i];
if (methodType.isPrimitive()) { if (!isAssignable(arg.getClass(), methodType)) {
Class<?> x = getBoxedClass(methodType);
if (!x.isInstance(arg)) {
return false;
}
} else if (arg != null && !methodType.isInstance(arg)) {
return false; return false;
} }
} }
...@@ -1059,18 +1074,12 @@ public final class Java ...@@ -1059,18 +1074,12 @@ public final class Java
private static boolean isMoreSpecialized(Class<?>[] xtypes, Class<?>[] ytypes) { private static boolean isMoreSpecialized(Class<?>[] xtypes, Class<?>[] ytypes) {
for (int i = 0; i < xtypes.length; ++i) { for (int i = 0; i < xtypes.length; ++i) {
Class<?> xtype = xtypes[i]; Class<?> xtype = maybeBoxClass(xtypes[i]);
if (xtype.isPrimitive()) { Class<?> ytype = maybeBoxClass(ytypes[i]);
xtype = getBoxedClass(xtype);
}
Class<?> ytype = ytypes[i];
if (ytype.isPrimitive()) {
ytype = getBoxedClass(ytype);
}
if (xtype.equals(ytype)) { if (xtype.equals(ytype)) {
continue; continue;
} }
if (ytype.isAssignableFrom(xtype)) { if (isAssignable(xtype, ytype)) {
return true; return true;
} }
} }
......
...@@ -195,6 +195,14 @@ ...@@ -195,6 +195,14 @@
(jcall method "test" (make-immediate-object nil :boolean) 0 "this is a test" 10 4)) (jcall method "test" (make-immediate-object nil :boolean) 0 "this is a test" 10 4))
t) t)
(deftest jcall.5
(jcall "join" (jstatic "currentThread" "java.lang.Thread") 1 1)
nil)
(deftest jcall.6
(jcall "offsetByCodePoints" "foobar" 0 #\Nul)
0)
(deftest jfield.1 (deftest jfield.1
(type-of (jfield "java.lang.Integer" "TYPE")) (type-of (jfield "java.lang.Integer" "TYPE"))
#+abcl java-object #+abcl java-object
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment