Changeset 4947


Ignore:
Timestamp:
12/02/03 22:29:59 (17 years ago)
Author:
dmcnaught
Message:

Added ENSURE-JCLASS so the user can pass a string or a class object

and things will still work

File:
1 edited

Legend:

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

    r4940 r4947  
    22;;;
    33;;; Copyright (C) 2003 Peter Graves
    4 ;;; $Id: java.lisp,v 1.7 2003-12-02 14:27:20 dmcnaught Exp $
     4;;; $Id: java.lisp,v 1.8 2003-12-02 22:29:59 dmcnaught Exp $
    55;;;
    66;;; This program is free software; you can redistribute it and/or
     
    3535  (jcall (jmethod "java.lang.Object" "getClass") obj))
    3636
     37(defun ensure-jclass (class-or-string)
     38  "If handed a string, return a Class object."
     39  (if (stringp class-or-string)
     40      (jclass class-or-string)
     41      class-or-string))
     42
    3743(defun jclass-superclass (class)
    3844  "Returns the superclass of CLASS, or NIL if it hasn't got one"
    39   (jcall (jmethod "java.lang.Class" "getSuperclass") class))
     45  (jcall (jmethod "java.lang.Class" "getSuperclass") (ensure-jclass class)))
    4046
    4147(defun jclass-interfaces (class)
    4248  "Returns the vector of interfaces of CLASS"
    43   (jcall (jmethod "java.lang.Class" "getInterfaces") class))
     49  (jcall (jmethod "java.lang.Class" "getInterfaces") (ensure-jclass class)))
    4450
    4551(defun jclass-interface-p (class)
    4652  "Returns T if CLASS is an interface"
    47   (jcall (jmethod "java.lang.Class" "isInterface") class))
     53  (jcall (jmethod "java.lang.Class" "isInterface") (ensure-jclass class)))
    4854
    4955(defun jclass-constructors (class)
    5056  "Returns a vector of constructors for CLASS"
    51   (jcall (jmethod "java.lang.Class" "getConstructors") class))
     57  (jcall (jmethod "java.lang.Class" "getConstructors") (ensure-jclass class)))
    5258
    5359(defun jconstructor-params (constructor)
     
    5864  "Returns a vector of all (or just the declared/public, if DECLARED/PUBLIC is true) fields of CLASS"
    5965  (let* ((getter (if declared "getDeclaredFields" "getFields"))
    60          (fields (jcall (jmethod "java.lang.Class" getter) class)))
     66         (fields (jcall (jmethod "java.lang.Class" getter) (ensure-jclass class))))
    6167    (if public (delete-if-not #'jmember-public-p fields) fields)))
    62 
    6368
    6469(defun jfield-type (field)
     
    7378  "Return a vector of all (or just the declared/public, if DECLARED/PUBLIC is true) methods of CLASS"
    7479  (let* ((getter (if declared "getDeclaredMethods" "getMethods"))
    75          (methods (jcall (jmethod "java.lang.Class" getter) class)))
     80         (methods (jcall (jmethod "java.lang.Class" getter) (ensure-jclass class))))
    7681    (if public (delete-if-not #'jmember-public-p methods) methods)))
    77 
    7882
    7983(defun jmethod-params (method)
     
    9296  "OBJ is an instance of CLASS (or one of its subclasses)"
    9397  (and (java-object-p obj)
    94        (jcall (jmethod "java.lang.Class" "isInstance" "java.lang.Object") class obj)))
     98       (jcall (jmethod "java.lang.Class" "isInstance" "java.lang.Object") (ensure-jclass class) obj)))
    9599
    96100(defun jmember-static-p (member)
Note: See TracChangeset for help on using the changeset viewer.