Ignore:
Timestamp:
01/03/09 13:17:22 (14 years ago)
Author:
Mark Evenson
Message:

Revert inadvertent r11528.

File:
1 edited

Legend:

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

    r11528 r11529  
    7676    (apply #'%jnew-proxy interface method-names-and-defs)))
    7777
    78 (defun jmake-invocation-handler (function)
    79   (%jmake-invocation-handler function))
    80  
    81 (when (autoloadp 'jmake-proxy)
    82   (fmakunbound 'jmake-proxy))
    83  
    84 (defgeneric jmake-proxy (interface implementation &optional lisp-this)
    85    (:documentation "Returns a proxy Java object implementing the
    86    provided interface using methods implemented in Lisp - typically
    87    closures, but implementations are free to provide other
    88    mechanisms. You can pass an optional 'lisp-this' object that will
    89    be passed to the implementing methods as their first argument. If
    90    you don't provide this object, NIL will be used. The second
    91    argument of the Lisp methods is the name of the Java method being
    92    implemented. This has the implication that overloaded methods are
    93    merged, so you have to manually discriminate them if you want
    94    to. The remaining arguments are java-objects wrapping the method's
    95    parameters."))
    96 
    97 (defmethod jmake-proxy (interface invocation-handler &optional lisp-this)
    98   "Basic implementation that directly uses an invocation handler."
    99   (%jmake-proxy (jclass interface) invocation-handler lisp-this))
    100 
    101 (defmethod jmake-proxy (interface (implementation function) &optional lisp-this)
    102    "Implements a Java interface forwarding method calls to a Lisp function."
    103    (%jmake-proxy (jclass interface) (jmake-invocation-handler implementation) lisp-this))
    104 
    105  (defmethod jmake-proxy (interface (implementation package) &optional lisp-this)
    106    "Implements a Java interface mapping Java method names to symbols
    107 in a given package. javaMethodName is mapped to a JAVA-METHOD-NAME
    108 symbol. An error is signaled if no such symbol exists in the package,
    109 or if the symbol exists but does not name a function."
    110 
    111    (flet ((java->lisp (name)
    112       (with-output-to-string (str)
    113         (let ((last-lower-p nil))
    114     (map nil (lambda (char)
    115          (let ((upper-p (char= (char-upcase char) char)))
    116            (when (and last-lower-p upper-p)
    117              (princ "-" str))
    118            (setf last-lower-p (not upper-p))
    119            (princ (char-upcase char) str)))
    120          name)))))
    121      (%jmake-proxy (jclass interface)
    122        (jmake-invocation-handler
    123         (lambda (obj method &rest args)
    124           (let ((sym (find-symbol
    125           (java->lisp method)
    126           implementation)))
    127       (unless sym
    128         (error "Symbol ~A, implementation of method ~A, not found in ~A"
    129          (java->lisp method)
    130          method
    131          implementation))
    132       (if (fboundp sym)
    133           (apply (symbol-function sym) obj method args)
    134           (error "Function ~A, implementation of method ~A, not found in ~A"
    135            sym method implementation)))))
    136        lisp-this)))
    137 
    138 (defmethod jmake-proxy (interface (implementation hash-table) &optional lisp-this)
    139    "Implements a Java interface using closures in an hash-table keyed
    140 by Java method name."
    141    (%jmake-proxy (jclass interface)
    142     (jmake-invocation-handler
    143      (lambda (obj method &rest args)
    144        (let ((fn (gethash method implementation)))
    145          (if fn
    146        (apply fn obj args)
    147        (error "Implementation for method ~A not found in ~A"
    148         method implementation)))))
    149     lisp-this))
    150  
    15178(defun jobject-class (obj)
    15279  "Returns the Java class that OBJ belongs to"
     
    307234
    308235(provide "JAVA-EXTENSIONS")
    309  (defun jproperty-value (obj prop)
    310    (%jget-property-value obj prop))
    311  
    312  (defun (setf jproperty-value) (value obj prop)
    313    (%jset-property-value obj prop value))
    314 
Note: See TracChangeset for help on using the changeset viewer.