Changeset 14715


Ignore:
Timestamp:
07/29/14 22:55:15 (7 years ago)
Author:
Mark Evenson
Message:

jss: GET-JAVA-FIELD now finds non-public inherited fields with TRY-HARDER.

Robert Goldman contributes in <http://abcl.org/trac/ticket/362>:

GET-JAVA-FIELD, when its optional TRY-HARDER argument is NIL, will
return any public field on its argument object, whether defined
locally or inherited.

When TRY-HARDER argument is true, on the other hand, it will return
non-public fields as well as public ones but only non-public fields
that are defined locally -- not non-public fields that are inherited.

This non-orthogonality seems wrong (just read the contorted
description above and imagine it as a docstring!). I am attaching a
proposed patch which searches up the class hierarchy to find inherited
non-public fields when TRY-HARDER is true.

Location:
trunk/abcl/contrib/jss
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/abcl/contrib/jss/invoke.lisp

    r14599 r14715  
    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))
     
    334335            (jfield class field))
    335336          (jfield field object))))
     337
     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))
    336354
    337355;; TODO use #"getSuperclass" and #"getInterfaces" to see whether there
  • trunk/abcl/contrib/jss/jss.asd

    r14615 r14715  
    22(asdf:defsystem :jss
    33  :author "Alan Ruttenberg, Mark Evenson"
    4   :version "3.0.7"
    5   :description "<> asdf:defsystem <urn:abcl.org/release/1.3.0/contrib/jss#3.0.7"
     4  :version "3.0.8"
     5  :description "<> asdf:defsystem <urn:abcl.org/release/1.4.0/contrib/jss#3.0.8"
    66  :components ((:module base
    77                        :pathname "" :serial t
Note: See TracChangeset for help on using the changeset viewer.