Changeset 14682


Ignore:
Timestamp:
04/17/14 11:49:30 (9 years ago)
Author:
Mark Evenson
Message:

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.

Location:
trunk/abcl
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/abcl/src/org/armedbear/lisp/Java.java

    r14466 r14682  
    10411041    }
    10421042
     1043    private static boolean isAssignable(Class<?> from, Class<?> to) {
     1044        from = maybeBoxClass(from);
     1045        to = maybeBoxClass(to);
     1046        if (to.isAssignableFrom(from)) {
     1047            return true;
     1048        }
     1049        if (Byte.class.equals(from)) {
     1050            return Short.class.equals(to) || Integer.class.equals(to) || Long.class.equals(to) || Float.class.equals(to) || Double.class.equals(to);
     1051        } else if (Short.class.equals(from) || Character.class.equals(from)) {
     1052            return Integer.class.equals(to) || Long.class.equals(to) || Float.class.equals(to) || Double.class.equals(to);
     1053        } else if (Integer.class.equals(from)) {
     1054            return Long.class.equals(to) || Float.class.equals(to) || Double.class.equals(to);
     1055        } else if (Long.class.equals(from)) {
     1056            return Float.class.equals(to) || Double.class.equals(to);
     1057        } else if (Float.class.equals(from)) {
     1058            return Double.class.equals(to);
     1059        }
     1060        return false;
     1061    }
     1062
    10431063    private static boolean isApplicableMethod(Class<?>[] methodTypes,
    10441064            Object[] args) {
     
    10461066            Class<?> methodType = methodTypes[i];
    10471067            Object arg = args[i];
    1048             if (methodType.isPrimitive()) {
    1049                 Class<?> x = getBoxedClass(methodType);
    1050                 if (!x.isInstance(arg)) {
    1051                     return false;
    1052                 }
    1053             } else if (arg != null && !methodType.isInstance(arg)) {
     1068            if (!isAssignable(arg.getClass(), methodType)) {
    10541069                return false;
    10551070            }
     
    10601075    private static boolean isMoreSpecialized(Class<?>[] xtypes, Class<?>[] ytypes) {
    10611076        for (int i = 0; i < xtypes.length; ++i) {
    1062             Class<?> xtype = xtypes[i];
    1063             if (xtype.isPrimitive()) {
    1064                 xtype = getBoxedClass(xtype);
    1065             }
    1066             Class<?> ytype = ytypes[i];
    1067             if (ytype.isPrimitive()) {
    1068                 ytype = getBoxedClass(ytype);
    1069             }
     1077            Class<?> xtype = maybeBoxClass(xtypes[i]);
     1078            Class<?> ytype = maybeBoxClass(ytypes[i]);
    10701079            if (xtype.equals(ytype)) {
    10711080                continue;
    10721081            }
    1073             if (ytype.isAssignableFrom(xtype)) {
     1082            if (isAssignable(xtype, ytype)) {
    10741083                return true;
    10751084            }
  • trunk/abcl/test/lisp/abcl/java-tests.lisp

    r11605 r14682  
    196196  t)
    197197
     198(deftest jcall.5
     199  (jcall "join" (jstatic "currentThread" "java.lang.Thread") 1 1)
     200  nil)
     201
     202(deftest jcall.6
     203  (jcall "offsetByCodePoints" "foobar" 0 #\Nul)
     204  0)
     205
    198206(deftest jfield.1
    199207  (type-of (jfield "java.lang.Integer" "TYPE"))
Note: See TracChangeset for help on using the changeset viewer.