Ticket #362: get-java-field.patch

File get-java-field.patch, 1.8 KB (added by Robert Goldman, 7 years ago)

Patch for invoke.lisp

  • contrib/jss/invoke.lisp

    diff --git a/contrib/jss/invoke.lisp b/contrib/jss/invoke.lisp
    index dcd5487..4ed07ae 100644
    a b If OBJECT is a symbol it names a dot qualified static FIELD." 
    325325                            (jobject-class object))))
    326326             (jfield (if (java-object-p field)
    327327                         field
    328                          (find field (#"getDeclaredFields" class)
    329                                :key 'jfield-name :test 'equal))))
     328                         (or (find-declared-field field class)
     329                             (error "Unable to find a FIELD named ~a for ~a"
     330                                    field object)))))
    330331        (#"setAccessible" jfield +true+)
    331332        (values (#"get" jfield object) jfield))
    332333      (if (symbolp object)
    If OBJECT is a symbol it names a dot qualified static FIELD." 
    334335            (jfield class field))
    335336          (jfield field object))))
    336337
     338(defun find-declared-field (field class)
     339  "Return a FIELD object corresponding to the definition of FIELD
     340\(a string\) visible at CLASS. *Not* restricted to public classes, and checks
     341all superclasses of CLASS.
     342   Returns NIL if no field object is found."
     343  (loop while class
     344        for field-obj = (get-declared-field class field)
     345        if field-obj
     346          do (return-from find-declared-field field-obj)
     347        else
     348          do (setf class (jclass-superclass class)))
     349  nil)
     350
     351(defun get-declared-field (class fieldname)
     352  (find fieldname (#"getDeclaredFields" class)
     353        :key 'jfield-name :test 'equal))
     354
    337355;; TODO use #"getSuperclass" and #"getInterfaces" to see whether there
    338356;; are fields in superclasses that we might set
    339357(defun set-java-field (object field value &optional (try-harder *running-in-osgi*))