1 ;;; jbrowse.el --- Simple class browser for Java Programming Language.
3 ;; Copyright (C) 2000 Daiki Ueno
5 ;; Author: Daiki Ueno <ueno@unixuser.org>
8 ;; This file is not part of any package.
10 ;; This program is free software; you can redistribute it and/or
11 ;; modify it under the terms of the GNU General Public License as
12 ;; published by the Free Software Foundation; either version 2, or
13 ;; (at your option) any later version.
15 ;; This program is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with this program; see the file COPYING. If not, write to
22 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
29 (defvar jbrowse-class-java-lang-reflect-method
30 (java-find-class "java.lang.reflect.Method"))
31 (defvar jbrowse-class-java-lang-reflect-modifier
32 (java-find-class "java.lang.reflect.Modifier"))
33 (defvar jbrowse-class-java-lang-class
34 (java-find-class "java.lang.Class"))
35 (defvar jbrowse-class-java-lang-package
36 (java-find-class "java.lang.Package"))
38 (defvar jbrowse-class-obarray (make-vector 31 0))
40 (defun jbrowse-type-string (type)
41 (let ((name (java-call-virtual-method type "getName")))
42 (if (eq (string-to-char name) ?\[)
45 (java-call-virtual-method type "getComponentType"))
47 (or (java-call-virtual-method type "isPrimitive")
48 (set (intern name jbrowse-class-obarray) nil)) ;Prepare cache entry.
51 (defvar jbrowse-modifier-chars
52 '((public ?+) (private ?-) (protected ?#)))
54 (defun jbrowse-modifier-chars (modifiers)
55 (let ((alist jbrowse-modifier-chars)
58 (if (java-call-static-method
59 jbrowse-class-java-lang-reflect-modifier
60 (concat "is" (capitalize (symbol-name (car (car alist)))))
62 (push (nth 1 (car alist)) chars))
63 (setq alist (cdr alist)))
66 (defun jbrowse-make-method-info (method)
69 (java-call-virtual-method method "getName")
71 (java-call-virtual-method method "getReturnType"))
72 (jbrowse-modifier-chars
73 (java-call-virtual-method method "getModifiers")))
76 (java-call-virtual-method method "getParameterTypes"))))
78 (defun jbrowse-describe-method-info (info)
80 (let ((modifier-chars (nth 2 info)))
82 (apply #'string modifier-chars)
86 (jbrowse-insert-type (nth 1 info))
87 (let ((params (nthcdr 3 info)))
91 (jbrowse-insert-type (pop params)))
95 (defun jbrowse-insert-type (type)
96 (if (intern-soft type jbrowse-class-obarray)
100 (setq extent (make-extent point (point)))
101 (set-extent-properties
102 extent `(mouse-face highlight help-symbol ,type))
104 extent 'activate-function
105 #'(lambda (event extent)
106 (help-symbol-run-function-1
107 event extent 'jbrowse-describe-class))))
110 (defun jbrowse-make-class-info (name)
112 (java-call-static-method
113 jbrowse-class-java-lang-class "forName" name))
115 (java-call-virtual-method class "getSuperclass")))
117 (and super (java-call-virtual-method super "getName"))
119 #'jbrowse-make-method-info
120 (java-call-virtual-method class "getDeclaredMethods")))))
122 (defun jbrowse-describe-class-1 (class info)
123 (with-displaying-help-buffer
125 (with-current-buffer standard-output
126 (if (null (car info))
127 (insert (format "`%s' is\n\n" class))
128 (insert (format "`%s' is derived from `" class))
129 (jbrowse-insert-type (car info))
131 (let ((methods (cdr info)))
133 (jbrowse-describe-method-info (pop methods))))
134 ;; Return the text we displayed.
135 (buffer-string nil nil standard-output)))
136 (format "class `%s'" class)))
138 (defun jbrowse-describe-class (class)
140 (let ((classes (mapcar #'java-class-name (java-class-list))))
142 (if current-prefix-arg
146 (java-call-virtual-method package "getName"))
147 (java-call-static-method
148 jbrowse-class-java-lang-package "getPackages"))))
149 (completing-read "Describe class: " (mapcar #'list classes)))
150 (completing-read "Describe class: " jbrowse-class-obarray)))))
151 (let ((class-info (symbol-value (intern-soft class jbrowse-class-obarray))))
153 (setq class-info (jbrowse-make-class-info class))
154 (set (intern class jbrowse-class-obarray) class-info))
155 (jbrowse-describe-class-1 class class-info)))
159 ;;; jbrowse.el ends here