| Line | |
|---|
| 1 | (in-package :jss) |
|---|
| 2 | |
|---|
| 3 | (defvar *jtypecache* (make-hash-table :test 'eq)) |
|---|
| 4 | |
|---|
| 5 | (defun jtypep (object type) |
|---|
| 6 | (declare (optimize (speed 3) (safety 0))) |
|---|
| 7 | (let ((class (or (gethash type *jtypecache*) |
|---|
| 8 | (ignore-errors (setf (gethash type *jtypecache*) (find-java-class type))))) |
|---|
| 9 | (method (load-time-value (jmethod "java.lang.Class" "isInstance" "java.lang.Object")))) |
|---|
| 10 | (and class |
|---|
| 11 | (jcall method class object)))) |
|---|
| 12 | |
|---|
| 13 | (defmacro jtypecase (keyform &body cases) |
|---|
| 14 | "JTYPECASE Keyform {(Type Form*)}* |
|---|
| 15 | Evaluates the Forms in the first clause for which Type names a class that Keyform isInstance of |
|---|
| 16 | is true." |
|---|
| 17 | (sys::case-body 'jtypecase keyform cases t 'jtypep nil nil nil)) |
|---|
| 18 | |
|---|
Note: See
TracBrowser
for help on using the repository browser.