[Armedbear-cvs] r14683 - in branches/1.3.1: src/org/armedbear/lisp test/lisp/abcl

mevenson at common-lisp.net mevenson at common-lisp.net
Thu Apr 17 11:50:50 UTC 2014


Author: mevenson
Date: Thu Apr 17 11:50:49 2014
New Revision: 14683

Log:
Backport r14682:  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.

Modified:
   branches/1.3.1/src/org/armedbear/lisp/Java.java
   branches/1.3.1/test/lisp/abcl/java-tests.lisp

Modified: branches/1.3.1/src/org/armedbear/lisp/Java.java
==============================================================================
--- branches/1.3.1/src/org/armedbear/lisp/Java.java	Thu Apr 17 11:49:30 2014	(r14682)
+++ branches/1.3.1/src/org/armedbear/lisp/Java.java	Thu Apr 17 11:50:49 2014	(r14683)
@@ -1040,17 +1040,32 @@
         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,
             Object[] args) {
         for (int i = 0; i < methodTypes.length; ++i) {
             Class<?> methodType = methodTypes[i];
             Object arg = args[i];
-            if (methodType.isPrimitive()) {
-                Class<?> x = getBoxedClass(methodType);
-                if (!x.isInstance(arg)) {
-                    return false;
-                }
-            } else if (arg != null && !methodType.isInstance(arg)) {
+            if (!isAssignable(arg.getClass(), methodType)) {
                 return false;
             }
         }
@@ -1059,18 +1074,12 @@
 
     private static boolean isMoreSpecialized(Class<?>[] xtypes, Class<?>[] ytypes) {
         for (int i = 0; i < xtypes.length; ++i) {
-            Class<?> xtype = xtypes[i];
-            if (xtype.isPrimitive()) {
-                xtype = getBoxedClass(xtype);
-            }
-            Class<?> ytype = ytypes[i];
-            if (ytype.isPrimitive()) {
-                ytype = getBoxedClass(ytype);
-            }
+            Class<?> xtype = maybeBoxClass(xtypes[i]);
+            Class<?> ytype = maybeBoxClass(ytypes[i]);
             if (xtype.equals(ytype)) {
                 continue;
             }
-            if (ytype.isAssignableFrom(xtype)) {
+            if (isAssignable(xtype, ytype)) {
                 return true;
             }
         }

Modified: branches/1.3.1/test/lisp/abcl/java-tests.lisp
==============================================================================
--- branches/1.3.1/test/lisp/abcl/java-tests.lisp	Thu Apr 17 11:49:30 2014	(r14682)
+++ branches/1.3.1/test/lisp/abcl/java-tests.lisp	Thu Apr 17 11:50:49 2014	(r14683)
@@ -195,6 +195,14 @@
     (jcall method "test" (make-immediate-object nil :boolean) 0 "this is a test" 10 4))
   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
   (type-of (jfield "java.lang.Integer" "TYPE"))
   #+abcl    java-object




More information about the armedbear-cvs mailing list