[Armedbear-cvs] r14715 - trunk/abcl/contrib/jss

mevenson at common-lisp.net mevenson at common-lisp.net
Tue Jul 29 22:55:16 UTC 2014


Author: mevenson
Date: Tue Jul 29 22:55:15 2014
New Revision: 14715

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

Modified:
   trunk/abcl/contrib/jss/invoke.lisp
   trunk/abcl/contrib/jss/jss.asd

Modified: trunk/abcl/contrib/jss/invoke.lisp
==============================================================================
--- trunk/abcl/contrib/jss/invoke.lisp	Fri Jul 18 17:03:20 2014	(r14714)
+++ trunk/abcl/contrib/jss/invoke.lisp	Tue Jul 29 22:55:15 2014	(r14715)
@@ -325,8 +325,9 @@
                             (jobject-class object))))
 	     (jfield (if (java-object-p field)
 			 field
-                         (find field (#"getDeclaredFields" class) 
-                               :key 'jfield-name :test 'equal))))
+                         (or (find-declared-field field class)
+                             (error "Unable to find a FIELD named ~a for ~a"
+                                    field object)))))
 	(#"setAccessible" jfield +true+)
 	(values (#"get" jfield object) jfield))
       (if (symbolp object)
@@ -334,6 +335,23 @@
             (jfield class field))
           (jfield field object))))
 
+(defun find-declared-field (field class)
+  "Return a FIELD object corresponding to the definition of FIELD
+\(a string\) visible at CLASS. *Not* restricted to public classes, and checks
+all superclasses of CLASS.
+   Returns NIL if no field object is found."
+  (loop while class
+        for field-obj = (get-declared-field class field)
+        if field-obj
+          do (return-from find-declared-field field-obj)
+        else
+          do (setf class (jclass-superclass class)))
+  nil)
+
+(defun get-declared-field (class fieldname)
+  (find fieldname (#"getDeclaredFields" class)
+        :key 'jfield-name :test 'equal))
+
 ;; TODO use #"getSuperclass" and #"getInterfaces" to see whether there
 ;; are fields in superclasses that we might set
 (defun set-java-field (object field value &optional (try-harder *running-in-osgi*))

Modified: trunk/abcl/contrib/jss/jss.asd
==============================================================================
--- trunk/abcl/contrib/jss/jss.asd	Fri Jul 18 17:03:20 2014	(r14714)
+++ trunk/abcl/contrib/jss/jss.asd	Tue Jul 29 22:55:15 2014	(r14715)
@@ -1,8 +1,8 @@
 ;;;; -*- Mode: LISP -*-
 (asdf:defsystem :jss
   :author "Alan Ruttenberg, Mark Evenson"
-  :version "3.0.7" 
-  :description "<> asdf:defsystem <urn:abcl.org/release/1.3.0/contrib/jss#3.0.7"
+  :version "3.0.8" 
+  :description "<> asdf:defsystem <urn:abcl.org/release/1.4.0/contrib/jss#3.0.8"
   :components ((:module base 
                         :pathname "" :serial t 
                         :components ((:file "packages")




More information about the armedbear-cvs mailing list