Changeset 13282


Ignore:
Timestamp:
05/21/11 12:40:49 (10 years ago)
Author:
Mark Evenson
Message:

Make JAVA:JRESOLVE-METHOD try harder to resolve a JAVA-OBJECT instance.

Unclear if this behavior comes from a bug in how we intialize
JAVA-OBJECT's intendedClass or is a "natural" result of some casting
assumption. We assume that users of JRESOLVE-METHOD would prefer some
sort of callable result as opposed to NIL as the current JAVA
introspection APIs assumption seems to geared to guessing a reasonable
default. Those wishing strict introspection semantics are advised to
use the java.lang.reflect package directly.

File:
1 edited

Legend:

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

    r13259 r13282  
    772772
    773773    private static final Primitive JRESOLVE_METHOD = new pf_jresolve_method();
    774     @DocString(name="jresolve_method", args="method-name instance &rest args",
     774    @DocString(name="jresolve-method", args="method-name instance &rest args",
    775775    doc="Finds the most specific Java method METHOD-NAME on INSTANCE " +
    776776        "applicable to arguments ARGS. Returns NIL if no suitable method is " +
     
    778778        "when it is called with a string as the first parameter (METHOD-REF).")
    779779    private static final class pf_jresolve_method extends Primitive {
    780 
    781780        pf_jresolve_method() {
    782781            super(Symbol.JRESOLVE_METHOD);
     
    807806            Object[] methodArgs = translateMethodArguments(args, 2);
    808807            Method method = findMethod(instance, intendedClass, methodName, methodArgs);
     808            if (method != null) {
     809                return JavaObject.getInstance(method);
     810            } else if (instanceArg instanceof JavaObject) {
     811                // Sometimes JavaObject.intendedClass has the default
     812                // value java.lang.Object, so we try again to resolve
     813                // the method using a dynamically requested value for
     814                // java.lang.Class.
     815                intendedClass = ((JavaObject)instanceArg).getObject().getClass();
     816                method = findMethod(instance, intendedClass, methodName, methodArgs);
     817            } else {
     818                return NIL;
     819            }
    809820            if (method != null) {
    810821                return JavaObject.getInstance(method);
Note: See TracChangeset for help on using the changeset viewer.