Initial Commit
[packages] / xemacs-packages / jde / lisp / jde-wiz.el
1 ;;; jde-wiz.el
2 ;; $Revision: 1.91 $
3 ;; Author: Paul Kinnucan <paulk@mathworks.com>
4 ;; Maintainer: Paul Kinnucan
5 ;; Keywords: java, tools
6
7 ;; Copyright (C) 1997, 1998, 2000, 2001, 2002, 2003, 2004 Paul Kinnucan.
8
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
12 ;; any later version.
13
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 ;; GNU General Public License for more details.
18
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
23
24 (require 'semantic-util)
25 (require 'beanshell)
26 (require 'jde-complete)
27 (require 'efc)
28 (require 'jde-parse)
29 (require 'jde-gen)
30
31 (defgroup jde-wiz nil
32   "JDE Wizards"
33   :group 'jde
34   :prefix "jde-wiz-")
35
36 (defun jde-wiz-escape-backslashes-in-path (path)
37   (mapconcat
38    (lambda (char)
39      (if (eq char ?\\) "\\\\" (char-to-string char)))
40    path ""))
41
42 (defun jde-wiz-update-class-list()
43   "Update the class list used to resolve class names.
44 The first time you invoke a JDE wizard, the JDE builds a list of all classes on
45 the classpath defined by jde-global-classpath. Wizards use this list to resolve
46 unqualified class names. If you add any classes to the classpath after invoking
47 a wizard, you should update the class list."
48   (interactive)
49   (if (jde-bsh-running-p)
50       (progn
51         (message "Rescanning classes...")
52         (jde-jeval (jde-create-prj-values-str))
53         (jde-jeval "jde.util.JdeUtilities.updateClassList();")
54         (message "Rescanning classes...Complete"))))
55
56 (defun jde-wiz-set-bsh-project()
57   "Update the beanshell's concept of the current project and the
58 classpath associated with it.  This may cause an update scan of the
59 class list the next time a wizard uses the class list for a lookup.
60 The scanning only occurs if the project is newly opened or its
61 classpath has been changed since the last scan, and switching between
62 projects does not necessarily force a rescan as the scan information
63 is cached in the beanshell.  You can force a rescan for a project by
64 calling `jde-wiz-update-class-list'."
65   (interactive)
66   (when (jde-bsh-running-p)
67     (jde-jeval (jde-create-prj-values-str))))
68
69 (defun jde-wiz-get-package-name ()
70   (let ((package-re "^[ \t]*package[ \t]+\\(.*\\)[ \t]*;"))
71     (save-excursion
72       (goto-char (point-max))
73       (when (re-search-backward package-re (point-min) t)
74         (looking-at package-re)
75         (buffer-substring-no-properties
76          (match-beginning 1)
77          (match-end 1))))))
78
79
80 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
81 ;; Method Interface Implementation wizard                                  ;;
82 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
83
84 (defun jde-wiz-get-unqualified-name (name)
85   (string-match "[^.]+$" name)
86   (substring name (match-beginning 0) (match-end 0)))
87
88 (defun jde-wiz-update-implements-clause (interface-name &optional extends)
89   "Updates the implements clause unless extends is non-nil. In that case the
90 extends clause is updated"
91   (interactive
92    "sEnter interface: ")
93   (let (keyword
94         (interface
95          (jde-wiz-get-unqualified-name interface-name)))
96     (if extends
97         (setq keyword "extends")
98       (setq keyword "implements"))
99     (save-excursion
100       (let* ((class-re "class[ \t]+\\([a-zA-z]+[a-zA-Z0-9._]*\\).*[ \n]*")
101              (open-brace-pos
102               (scan-lists (point) -1 1))
103              (class-name-end-pos
104               (when open-brace-pos
105                 (goto-char open-brace-pos)
106                 (when (re-search-backward class-re (point-min) t)
107                   (looking-at class-re)
108                   (match-end 1))))
109              (implements-keyword-end-pos
110               (when (and open-brace-pos class-name-end-pos)
111                 (goto-char open-brace-pos)
112                 (if (re-search-backward keyword class-name-end-pos t)
113                     (match-end 0)))))
114         (if implements-keyword-end-pos
115             (progn
116               (goto-char implements-keyword-end-pos)
117               (insert (concat " " interface ",")))
118           (when class-name-end-pos
119             (goto-char (- open-brace-pos 1))
120             (if (looking-at " {")
121                 (delete-char 1)  ;; if we don't delete, we end up with 2 spaces
122               (forward-char))
123             (insert (concat " " keyword " " interface " "))))))))
124
125 (defun jde-wiz-generate-interface (interface-name)
126   "*Generate a skeleton implementation of a specified interface."
127   (let* ((code
128           (read
129            (jde-jeval
130             (concat
131              "jde.wizards.InterfaceFactory.makeInterfaceExpression(\""
132              interface-name "\", true);")))))
133     (if  code
134       (let ((required-imports
135              (jde-jeval-r
136                 "jde.wizards.InterfaceFactory.getImportedClasses();")))
137           (eval code)
138           (if required-imports
139               (jde-import-insert-imports-into-buffer required-imports t))
140           (jde-wiz-update-implements-clause interface-name)))))
141
142 (defun jde-wiz-gen-implementation-methods (gen-list)
143   "Executes the given list of generation statements. Generation statements
144 are either strings that may be used as introductory comment for the
145 subsequent method(s) or invocations of `jde-wiz-gen-method'."
146   (let ((items gen-list))
147     (while (car items)
148       (let ((to-end (- (point-max) (point))))
149         (if (stringp (car items))
150             (progn
151               (tempo-save-named 'comment-line (car items))
152               (jde-gen-section-comment))
153           (eval (car items)))
154         (goto-char (- (point-max) to-end)))
155       (setq items (cdr items)))))
156
157 (defun jde-wiz-implement-interface-internal (interface-name)
158   "*Generate a skeleton implementation of a specified interface.
159 This command works only for interfaces defined by `jde-global-classpath', if
160 set, otherwise the CLASSPATH environment variable."
161   (interactive
162    "sInterface name: ")
163   (let ((names
164          (jde-jeval-r
165           (format "jde.util.JdeUtilities.getQualifiedName(\"%s\");"
166                   interface-name ))))
167     (if names
168         (if (> (length names) 1)
169             (jde-wiz-generate-interface
170              (efc-query-options
171               names
172               "Select interface to implement."
173               "Class Name dialog"))
174           (jde-wiz-generate-interface (car names)))
175       (error "Cannot find interface %s on the current classpath."
176              interface-name))))
177
178 (defun jde-wiz-implement-interface (interface-name)
179   "*Generate a skeleton implementation of a specified interface.
180 This command works only for interfaces that exist on the classpath
181 defined by `jde-global-classpath', if set, otherwise
182 by the CLASSPATH environment variable. This command uses
183 `jde-gen-method-template' as a template for generating the
184 code for each of the skeleton methods required to implement
185 the interface. You can thus customize the format of the skeleton
186 methods by customizing `jde-gen-method-template' The template
187 in turn invokes the `jde-javadoc-autodoc-at-line' function to
188 generate the skeleton javadoc for each skeleton method. This function
189 uses various templates that you can customize to customize
190 the skeleton javadoc. See the function's documentation for
191 more information."
192   (interactive
193    "sInterface name: ")
194   (condition-case err
195       (let ((pos (point)))
196         (jde-wiz-implement-interface-internal interface-name)
197         (jde-wiz-indent pos))
198     (error
199      (message "%s" (error-message-string err)))))
200
201
202 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
203 ;; EventSource     wizard                                                  ;;
204 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
205 (defun jde-wiz-generate-event-source (event-listener-interface-name)
206   "*Generate a skeleton implementation of a source of events for the event listener
207 INTERFACE-NAME. This command will generate methods to add and remove listeners
208 and fire every method of all listeners registered. It creates a data structure
209 to store the listeners too."
210   (condition-case err
211       (let* ((pos (point))
212              (code
213               (read
214                (jde-jeval
215                 (concat
216                  "jde.wizards.EventSourceFactory.makeEventSourceSupportExpression(\""
217                  event-listener-interface-name "\", true);")))))
218         (if code
219             (let ((required-imports
220                    (jde-jeval-r
221                     "jde.wizards.EventSourceFactory.getImportedClasses();")))
222               (message "%s" "evaluating")
223               (eval code)
224               (message "%s" "eval done")
225               (jde-wiz-indent pos)
226               (if required-imports
227                   (jde-import-insert-imports-into-buffer required-imports t)
228                 (message "%s" "no imports"))
229               )))
230     (error
231      (message "%s" (error-message-string err)))))
232
233 (defun jde-wiz-gen-event-source (gen-list)
234   "Executes the given list of generation statements. Generation statements
235 are either strings that may be used as introductory comment for the
236 subsequent method(s) or invocations of `jde-wiz-gen-listener-registry',
237 `jde-wiz-gen-method'."
238   (let ((items gen-list))
239     (while (car items)
240       (let ((to-end (- (point-max) (point))))
241         (if (stringp (car items))
242             (progn
243               (tempo-save-named 'comment-line (car items))
244               (jde-gen-section-comment))
245           (eval (car items)))
246         (goto-char (- (point-max) to-end)))
247       (setq items (cdr items))
248       ))
249   )
250
251 (defun jde-wiz-gen-listener-registry (listener-class)
252   "Generates a method by setting the tempo named tags and
253 invoking `jde-gen-listener-registry'. This method is usually
254 called by an expression generated in the beanshell."
255   (tempo-save-named 'listenerFQN listener-class)
256   (jde-gen-listener-registry)
257 )
258
259 (defun jde-wiz-gen-event-source-fire-method
260   (listener-class method ret-type params)
261   "Generates a method by setting the tempo named tags and
262 invoking `jde-gen-event-source-fire-method'. This method is usually
263 called by an expression generated in the beanshell."
264   (tempo-save-named 'listenerFQN listener-class)
265   (tempo-save-named 'method-name method)
266   (tempo-save-named 'return-type ret-type)
267   (tempo-save-named 'params params)
268   (jde-gen-event-source-fire-method)
269 )
270
271 (defun jde-wiz-implement-event-source-internal (interface-name)
272   "*Generate a skeleton implementation of a source of events for the event listener
273 INTERFACE-NAME. This command will generate methods to add and remove listeners
274 and fire every method of all listeners registered. It creates a data structure
275 to store the listeners too. This command works only for interfaces defined by `jde-global-classpath', if
276 set, otherwise the CLASSPATH environment variable."
277   (interactive
278    "sListener Interface name: ")
279   (condition-case err
280       (let ((names
281              (jde-jeval-r
282               (format "jde.util.JdeUtilities.getQualifiedName(\"%s\");" interface-name ))))
283         (if names
284             (if (> (length names) 1)
285                 (jde-wiz-generate-event-source
286                  (efc-query-options names
287                                     "Select interface to implement."
288                                     "class name dialog"))
289               (jde-wiz-generate-event-source (car names)))
290           (error "Cannot find listener interface %s on the current classpath." interface-name)))
291     (error
292      (message "%s" (error-message-string err)))))
293
294 (defun jde-wiz-implement-event-source (interface-name)
295   "*Generate a skeleton implementation of a source of events for the event listener
296 INTERFACE-NAME. This command will generate methods to add and remove listeners
297 and fire every method of all listeners registered. It creates a data structure
298 to store the listeners too. This command works only for interfaces that exist on the classpath
299 defined by `jde-global-classpath', if set, otherwise
300 by the CLASSPATH environment variable."
301   (interactive
302    "sListener Interface name: ")
303   (jde-wiz-implement-event-source-internal interface-name))
304
305 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
306 ;; Method override wizard                                                  ;;
307 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
308
309 (defun jde-wiz-override-method ()
310   "Overrides a method whose name you specify, using
311 completion, in the minibuffer. Press space at the
312 prompt to see a list of all methods that can be overriden
313 or type the first few letters of the name of the method
314 and press space to see a list of all methods that
315 complete the name.
316
317 This command creates a skeleton implementation of the
318 overridden method at point. This command infers the
319 qualified name of the class of the overriden method by
320 prepending the package name of the current buffer to
321 the class containing point. If the class defines
322 more than one method of the same name, this command
323 prompts you to select the desired method from a list
324 of method prototypes.
325
326 This command also generates import statements for
327 the parameter and return types of the overridden method.
328 The import statements are inserted after the last
329 existing import statement or the package statement
330 or the first blank line in the source file. Import
331 statements are generated only for types for which an
332 import statement does not already exist in the file.
333
334 NOTE: this command works only if the overriding class
335       has been previously compiled."
336   (interactive)
337
338   (condition-case err
339       (let* ((super-class (jde-parse-get-super-class-at-point))
340              (qualified-super-class
341               (jde-parse-get-qualified-name super-class t))
342              (classinfo
343               (jde-complete-get-classinfo qualified-super-class jde-complete-protected))
344              pair pos class-name qualified-class-name method-name)
345         (setq pair
346               (assoc
347                (completing-read "Method to overwrite: " classinfo nil t)
348                classinfo))
349
350         (if (not pair)
351             (error "No method specified for completion."))
352
353         (setq pos (string-match " : " (car pair)))
354         (setq method-name
355               (if pos
356                   (substring (car pair) 0 pos)
357                 (cdr pair)))
358
359         (setq class-name
360          (jde-parse-get-super-class-at-point))
361         (setq qualified-class-name
362          (jde-parse-get-qualified-name class-name t))
363         (setq pos (string-match "(" method-name))
364
365         (if qualified-super-class
366             (let ((signatures
367                    (jde-jeval
368                     (concat
369                      "jde.wizards.MethodOverrideFactory.getCandidateSignatures(\""
370                      qualified-class-name "\",\"" (substring method-name 0 pos) "\");") t)))
371               (jde-wiz-override-method-internal method-name
372                                                 signatures))
373           (error "Cannot find parent class %s" super-class)))
374     (error
375      (message "%s" (error-message-string err)))))
376
377
378 (defun jde-wiz-override-method-internal (selected-method methods)
379   (let* ((selected-method-args (jde-wiz-number-of-arguments selected-method))
380          (pos (point))
381          (variant 0) skeleton required-imports
382          (index 0))
383     (while methods
384       (if (jde-wiz-check-signatures selected-method (car methods))
385           (progn
386             (setq variant index)
387             (setq methods nil))
388         (progn
389           (setq index (+ 1 index))
390           (setq methods (cdr methods)))))
391
392     (jde-jeval-r
393      (concat
394       "jde.wizards.MethodOverrideFactory.getMethodSkeletonExpression("
395       (int-to-string variant) ");"))
396     (setq required-imports
397           (jde-jeval-r
398            "jde.wizards.MethodOverrideFactory.getImportedClasses();"))
399     (if required-imports
400         (jde-import-insert-imports-into-buffer required-imports t))))
401
402 (defun jde-wiz-gen-method (modifiers return-type name parameters exceptions
403                                      default-body)
404   "Generates a method by setting the tempo named tags and
405 invoking `jde-gen-method'. This method is usually
406 called by an expression generated in the beanshell."
407   (tempo-save-named 'modifiers modifiers)
408   (tempo-save-named 'return-type return-type)
409   (tempo-save-named 'name name)
410   (tempo-save-named 'parameters parameters)
411   (tempo-save-named 'exceptions exceptions)
412   (tempo-save-named 'default-body default-body)
413   (jde-gen-method)
414 )
415
416 (defun jde-wiz-gen-delegation-methods (gen-list)
417   "Executes the given list of generation statements. Generation statements
418 are either strings that may be used as introductory comment for the
419 subsequent method(s) or invocations of `jde-wiz-gen-method'."
420   (let ((items gen-list))
421     (while (car items)
422       (let ((to-end (- (point-max) (point))))
423         (if (stringp (car items))
424             (progn
425               (tempo-save-named 'comment-line (car items))
426               (jde-gen-section-comment))
427           (eval (car items)))
428         (goto-char (- (point-max) to-end)))
429       (setq items (cdr items))
430       ))
431   )
432
433 (defun jde-wiz-check-signatures (sign1 sign2)
434   "Checks the signatures for equality"
435   (while (string-match "java.lang." sign1)
436     (setq sign1 (replace-match "" nil nil sign1)))
437
438   (while (string-match " param." sign2)
439     (setq sign2 (replace-match "" nil nil sign2)))
440   (string= sign1 sign2))
441
442
443 (defun jde-wiz-number-of-arguments (signature)
444   "Returns the number of arguments in this signature"
445   (let (pos (number-of-arguments 0))
446     (if (string-match "()" signature)
447         number-of-arguments
448       (if (not (string-match "," signature))
449           (setq number-of-arguments (+ 1 number-of-arguments))
450         (progn
451           (setq number-of-arguments 1)
452           (while (string-match "," signature)
453             (setq pos (string-match "," signature))
454             (setq number-of-arguments (+ 1 number-of-arguments))
455             (setq signature (substring signature (+ pos 1)))))))
456           number-of-arguments))
457
458 (defun jde-wiz-indent (pos)
459   "Indents the just inserted region without moving
460 the cursor"
461   (goto-char (scan-lists (point) -1 1))
462   (c-indent-exp)
463   (goto-char pos))
464
465 ;;
466 ;; Contributed by Javier Lopez and Paul Kinnucan
467 ;;
468 (defun jde-browse-class(&optional class-name)
469   "Browse class in the beanshell class browser"
470   (interactive)
471   (let* ((class
472          (or class-name
473              (read-from-minibuffer "Class: " (thing-at-point 'symbol))))
474          (fq-class-name
475           (jde-parse-select-qualified-class-name class)))
476     (if fq-class-name
477         (bsh-eval
478          (oref 'jde-bsh the-bsh)
479          (format "browseClass(\"%s\");" fq-class-name)))))
480
481 (defun jde-wiz-delegate (delegee)
482   "*Generate methods for the class in the current source buffer
483 that delegate tasks to an instance of another class. The delegator
484 class must have a field that references an instance of the delegee
485 class. DELEGEE is the name of the field in the delegator class that
486 references the delegee. This command generates methods in the current
487 buffer that invoke identically named methods of DELEGEE. For example,
488 if the current buffer contains class A and A has a field named b that
489 references an instance of class B, this command generates methods for
490 A that have the same signatures as the public methods of B. Each of
491 the generated A methods invokes the corresponding B method.
492
493 This function uses `jde-gen-method-template' as a template for
494 generating the skeleton code for each of the the delegated methods.
495 You can thus customize the format of the skeleton methods by
496 customizing `jde-gen-method-template' The template in turn invokes the
497 `jde-javadoc-autodoc-at-line' function to generate the skeleton
498 javadoc for each skeleton method. This function uses various templates
499 that you can customize to customize the skeleton javadoc. See the
500 function's documentation for more information."
501   (interactive
502    "sDelegee name: ")
503   (condition-case err
504       (let* ((pos (point))
505              (start nil)
506              (class-name
507               (or (jde-parse-get-qualified-name
508                    (car (jde-parse-declared-type-of delegee)) t)
509                   (read-string (concat "Enter fully qualified class name of "
510                                        delegee ": "))))
511              (code
512               (read
513                (jde-jeval
514                 (concat
515                  "jde.wizards.DelegateFactory.makeDelegatorMethods(\""
516                  delegee "\", \"" class-name "\", true);")))))
517         (if code
518             (let ((required-imports
519                    (jde-jeval-r
520                     "jde.wizards.DelegateFactory.getImportedClasses();")))
521               (font-lock-mode -1)
522               (setq start (point))
523               (eval code)
524               ;;indenting the new code
525               (jde-wiz-indent pos)
526               (if required-imports
527                   (jde-import-insert-imports-into-buffer required-imports t))
528               (font-lock-mode)
529               )))
530     (error
531      (message "%s" (error-message-string err)))))
532
533 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
534 ;; Method Abstract Implementation wizard                                   ;;
535 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
536
537 (defun jde-wiz-generate-abstract-class (class-name)
538   "*Generate a skeleton implementation of a specified abstract class."
539   (condition-case err
540       (let* ((code
541               (read
542                (jde-jeval
543                 (concat
544                  "jde.wizards.AbstractClassFactory.makeAbstractClassExpression(\""
545                  class-name "\", true);")))))
546         (if code
547             (let ((required-imports
548                    (jde-jeval-r
549                     "jde.wizards.AbstractClassFactory.getImportedClasses();")))
550               (eval code)
551               (if required-imports
552                   (jde-import-insert-imports-into-buffer required-imports t))
553               (jde-wiz-update-implements-clause class-name t))))
554     (message "%s" (error-message-string err))))
555
556 (defun jde-wiz-extend-abstract-class-internal (class-name)
557   "*Generate a skeleton implementation of the specified abstract class.
558 This command works only for interfaces defined by `jde-global-classpath', if
559 set, otherwise the CLASSPATH environment variable."
560   (interactive
561    "sAbstract classname: ")
562   (condition-case err
563       (let ((names
564              (jde-jeval-r
565               (format "jde.util.JdeUtilities.getQualifiedName(\"%s\");"
566                       class-name ))))
567         (if names
568             (if (> (length names) 1)
569                 (jde-wiz-generate-abstract-class
570                  (efc-query-options names nil
571                                     "class name dialog"))
572               (jde-wiz-generate-abstract-class (car names)))
573           (message "Cannot find abstract class %s on the current classpath."
574                    class-name)))
575     (message "%s" (error-message-string err))))
576
577 (defun jde-wiz-extend-abstract-class (class-name)
578   "*Generate a skeleton implementation of the abstract methods of the
579 a specified class. This command works only for abstract classes that exist
580 on the classpath defined by `jde-global-classpath', if set, otherwise
581 by the CLASSPATH environment variable.
582
583 This command uses `jde-gen-method-template' as a template for
584 generating the skeleton code for each of the abstract methods. You can
585 thus customize the format of the skeleton methods by customizing
586 `jde-gen-method-template' The template in turn invokes the
587 `jde-javadoc-autodoc-at-line' function to generate the skeleton
588 javadoc for each skeleton method. This function uses various templates
589 that you can customize to customize the skeleton javadoc. See the
590 function's documentation for more information."
591   (interactive
592    "sAbstract class name: ")
593   (jde-wiz-extend-abstract-class-internal class-name))
594
595 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
596 ;; Get Set Method Implementation wizard                                    ;;
597 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
598
599 (defcustom jde-wiz-include-javadoc t
600   "This variables specifies whether javadoc comments should be included in
601 skeletons created by the `jde-wiz-get-set-methods' function."
602   :group 'jde-wiz
603   :type 'boolean)
604
605 (defcustom jde-wiz-get-set-variable-prefix "arg"
606   "This variable defines a prefix to be added to argmument names
607 for the funtion `jde-wiz-get-set-methods'. For example if this
608 variable is set to \"arg\" the following variable
609 String name; will produce this method signature:
610 public String get(String argName)"
611   :group 'jde-wiz
612   :type 'string)
613
614 (defcustom jde-wiz-get-javadoc-template
615   (list "/**"
616         "* Gets the value of %n"
617         "*"
618         "* @return the value of %n"
619         "*/")
620   "Template used by `jde-wiz-get-set-method' to add the javadoc
621 to a get method. The %n are replaced by the variable name and
622 %t by the variable."
623   :group 'jde-wiz
624   :type '(repeat string))
625
626 (defcustom jde-wiz-set-javadoc-template
627   (list "/**"
628         "* Sets the value of %n"
629         "*"
630         "* @param %p Value to assign to this.%n"
631         "*/")
632   "Template used by `jde-wiz-get-set-method' to add the javadoc to a
633 set method. The %n are replaced by the variable name, %t by the variable
634 type and %p for the argument name. In most cases %n and %p are the same
635 except when `jde-wiz-get-set-variable-prefix' is non nil; in this case the
636 %p will pick up those changes as well."
637   :group 'jde-wiz
638   :type '(repeat string))
639
640 (defcustom jde-wiz-show-report t
641   "A non nil value will show a report of the existing get set methods
642 and the ones added"
643   :group 'jde-wiz
644   :type 'boolean)
645
646 (defcustom jde-wiz-get-set-variable-convention (cons "" nil)
647   "Use this variable to specify your coding conventions. This variable is used
648 by the `jde-wiz-get-set-method' to filter the convention from the variable
649 declared in the buffer from the name of the method. The are 3 options a prefix,
650  a postfix, and the first uppercase letter. For example, choosing a prefix and
651 setting it to '_' means that the '_' will be filtered from all the variable
652 containing it. So this variable private String _name;  will produce this get
653 method:
654 public getName(String name) {
655 this._name = name
656 }
657 A postfix works in a similar way, the third option behaves slighlty different.
658 For example if the variable is String _strName; this will get filter to name.
659 It will take everything after the first capitalize letter. A nil value will use
660 the variable name as it is defined in the buffer."
661   :group 'jde-wiz
662   :type '(cons (string :tag "Enter either the prefix or postfix")
663                (radio-button-choice (const "Prefix")
664                                     (const "Postfix")
665                                     (const "Everything after the first upcase letter")
666                                     (const nil))))
667
668 (defcustom jde-wiz-get-set-methods-include (list "Both")
669   "Use this variable to set what methods `jde-wiz-get-set-methods' will
670 insert in the buffer. The options are get methods only, set methods only,
671  and both."
672   :group 'jde-wiz
673   :type '(list (radio-button-choice (const "Get only")
674                                     (const "Set only")
675                                     (const "Both"))))
676
677 (defcustom jde-wiz-get-set-static-members t
678   "If on (nonnil), `jde-wiz-get-set-methods' generates getter/setter methods for
679 private static members of the class in the current buffer."
680   :group 'jde-wiz
681   :type 'boolean)
682
683 (defcustom jde-wiz-get-set-methods-order (list "Get followed by set for each field")
684   "Use this variable to set the order in which the
685 get and set methods are going to be inserted by
686 `jde-wiz-get-set-methods'"
687   :group 'jde-wiz
688   :type '(list (radio-button-choice
689                 (const "Get followed by set for each field")
690                 (const "Set followed by get for each field")
691                 (const "All get methods followed by all set methods")
692                 (const "All set methods followed by all get methods"))))
693
694 (defun jde-wiz-downcase-initials (obj)
695   "It downcase the first letter of obj"
696   (concat (downcase (substring obj 0 1)) (substring obj 1)))
697
698 (defun jde-wiz-get-class-parts (class-name tokens)
699   "Recurse through all the tokens in `tokens' looking for
700 the tokens of `class-name', returns nil if no token are found"
701   (let ((parts (jde-wiz-get-class-parts-helper class-name tokens))
702         temp-parts inner-classes)
703     (if (not parts)
704         (while tokens
705           (setq temp-parts (semantic-token-type-parts (car tokens)))
706           (setq inner-classes (semantic-find-nonterminal-by-token 'type temp-parts))
707           (setq parts (jde-wiz-get-class-parts class-name inner-classes))
708           (if parts
709               (setq tokens nil)
710             (setq tokens (cdr tokens)))))
711     parts))
712
713 (defun jde-wiz-get-class-parts-helper (class-name tokens)
714   "Checks the top level for the class name `class-name'
715 if one is found it returns the parts of it, nil is
716 return otherwise"
717   (let (parts current-class)
718     (while tokens
719       (setq current-class (car tokens))
720       (if (string= class-name (semantic-token-name current-class))
721           (progn
722             (setq parts (semantic-token-type-parts current-class))
723             (setq tokens nil)))
724       (setq tokens (cdr tokens)))
725     parts))
726
727 (defun jde-wiz-get-member-p (name functions)
728   "Returns t if the variable name has a get method defined in the
729 current buffer. Functions are semantic tokens for the functions
730 defined in the current buffer."
731   (or (member
732        (concat
733         "get"
734         (upcase-initials (jde-wiz-get-name name))) functions)
735       (member
736        (concat
737         "is"
738         (upcase-initials (jde-wiz-get-name name))) functions)))
739
740 (defun jde-wiz-set-member-p (name functions)
741   "Returns t if the variable name has a set method defined in the current buffer.
742 Functions are semantic tokens for the functions defined in the current buffer."
743   (member (concat "set" (upcase-initials (jde-wiz-get-name name))) functions))
744
745 (defun jde-wiz-get-set-methods()
746   "Generates get and set methods for all the private fields
747 defined in the current buffer."
748   (interactive)
749   (let* ((include (car jde-wiz-get-set-methods-include))
750          ;;Indicates if both get and set should be inserted
751          (bothp (string= "Both" include))
752          ;;only get methods should be inserted
753          (get-onlyp (string= "Get only" include))
754          ;;only set methods should be inserted
755          (set-onlyp (string= "Set only" include))
756          (order (car jde-wiz-get-set-methods-order))
757          (get-firstp
758           (or (string= "All get methods followed by all set methods" order)
759               (string= "Get followed by set for each field" order)))
760          (class (jde-parse-get-class-at-point));;class name
761          (classes (split-string class "\\."))
762          (class-name (nth (- (length classes) 1) classes))
763          (tokens (semantic-bovinate-toplevel t));;buffer tokens
764          (type (semantic-find-nonterminal-by-token 'type tokens));;class tokens
765          (parts (jde-wiz-get-class-parts class-name type))
766          (variables (semantic-find-nonterminal-by-token 'variable parts));;declared variables
767          ;;non public variables
768          (non-public-variables (jde-wiz-filter-variables-by-typemodifier variables))
769          (functions (semantic-find-nonterminal-by-token 'function parts));;functions
770          (set-get-functions (jde-wiz-get-get-set-methods functions));;get,set,is functions
771          var name staticp finalp report temp pos)
772
773     (setq
774      report
775      (concat
776       (format "%-60.60s" "Field")
777       (if get-firstp "\tGetter  \tSetter\n" "\tSetter  \tGetter\n")))
778
779     (setq
780      report
781      (concat
782       report
783       (format "%-60.60s" "------------------------------------------------------------")
784       "\t--------\t--------\n"))
785
786     (while non-public-variables
787       (setq var (car non-public-variables))
788       (setq name (semantic-token-name var));;variable name
789       (setq type (semantic-token-type var));;variable type i.e. boolean
790       (setq staticp (member "static" (semantic-token-variable-modifiers var)));;is it static
791       (setq finalp  (member "final" (semantic-token-variable-modifiers var)));;is it final
792
793       (setq
794        report
795        (concat
796         report
797         (format
798          "%-60.60s"
799          (concat
800           type " " name " "
801           (and (semantic-token-variable-modifiers var)
802                ;; only if some modifiers are present
803                ;; print them
804                (format "%s" (semantic-token-variable-modifiers var)))))))
805
806       (setq report (concat report "\t"))
807
808       ;;order in which the methods should be inserted
809       (cond ((string= "Get followed by set for each field" order)
810              ;;get method followed by its set method
811              ;;getting the get method if it does not exist in the buffer
812              (if (not (jde-wiz-get-member-p name set-get-functions))
813                  (if (and (or bothp get-onlyp)
814                           (or (not staticp) jde-wiz-get-set-static-members))
815                      (progn
816                        (insert (jde-wiz-get-get-method type name staticp class))
817                        (setq report (concat report "[Added  ]")))
818                    (setq report (concat report "[Skipped]")))
819                (setq report (concat report "[Exists ]")))
820
821              (setq report (concat report "\t"))
822
823              ;;getting the set method if it does not exist in the buffer
824              (if (and (not finalp);; it is final - can not have a setter
825                       (not (jde-wiz-set-member-p name set-get-functions)))
826                  (if (and (or bothp set-onlyp)
827                           (or (not staticp) jde-wiz-get-set-static-members))
828                      (progn
829                        (insert (jde-wiz-get-set-method type name staticp class))
830                        (setq report (concat report "[Added  ]")))
831                    (setq report (concat report "[Skipped]")))
832                (if (jde-wiz-set-member-p name set-get-functions)
833                    (setq report (concat report "[Exists ]"))
834                  (if finalp
835                      (setq report (concat report "[N/A    ]"))))))
836             ;;set method followed by its get method
837             ((string= "Set followed by get for each field" order)
838              ;;getting the set method if it does not exist in the buffer
839              (if (and (not finalp);; it is final - can not have a setter
840                       (not (jde-wiz-set-member-p name set-get-functions)))
841                  (if (and (or bothp set-onlyp)
842                           (or (not staticp) jde-wiz-get-set-static-members))
843                      (progn
844                        (insert (jde-wiz-get-set-method type name staticp class))
845                        (setq report (concat report "[Added  ]")))
846                    (setq report (concat report "[Skipped]")))
847                (if (jde-wiz-set-member-p name set-get-functions)
848                    (setq report (concat report "[Exists ]"))
849                  (if finalp
850                      (setq report (concat report "[N/A    ]")))))
851
852              (setq report (concat report "\t"))
853
854              ;;getting the get method if it does not exist in the buffer
855              (if (not (jde-wiz-get-member-p name set-get-functions))
856                  (if (and (or bothp get-onlyp)
857                           (or (not staticp) jde-wiz-get-set-static-members))
858                      (progn
859                        (insert (jde-wiz-get-get-method type name staticp class))
860                        (setq report (concat report "[Added  ]")))
861                    (setq report (concat report "[Skipped]")))
862                (setq report (concat report "[Exists ]"))))
863
864             ;;all the get method first
865             ((string= "All get methods followed by all set methods" order)
866              ;;getting the get method if it does not exist in the buffer
867              (if (not (jde-wiz-get-member-p name set-get-functions))
868                  (if (and (or bothp get-onlyp)
869                           (or (not staticp) jde-wiz-get-set-static-members))
870                      (progn
871                        (insert (jde-wiz-get-get-method type name staticp class))
872                        (setq report (concat report "[Added  ]")))
873                    (setq report (concat report "[Skipped]")))
874                (setq report (concat report "[Exists ]")))
875
876              (setq report (concat report "\t"))
877
878              ;;getting the set method if it does not exist in the buffer
879              (if (and (not finalp);; it is final - can not have a setter
880                       (not (jde-wiz-set-member-p name set-get-functions)))
881                  (if (and (or bothp set-onlyp)
882                           (or (not staticp) jde-wiz-get-set-static-members))
883                      (progn
884                        (setq temp (concat temp (jde-wiz-get-set-method type name staticp class)))
885                        (setq report (concat report "[Added  ]")))
886                    (setq report (concat report "[Skipped]")))
887                (if (jde-wiz-set-member-p name set-get-functions)
888                    (setq report (concat report "[Exists ]"))
889                  (if finalp
890                      (setq report (concat report "[N/A    ]"))))))
891
892             ;;all the set method first
893             ((string= "All set methods followed by all get methods" order)
894              ;;getting the set method if it does not exist in the buffer
895              (if (and (not finalp);; it is final - can not have a setter
896                       (not (jde-wiz-set-member-p name set-get-functions)))
897                  (if (and (or bothp set-onlyp)
898                           (or (not staticp) jde-wiz-get-set-static-members))
899                      (progn
900                        (insert (jde-wiz-get-set-method type name staticp class))
901                        (setq report (concat report "[Added  ]")))
902                    (setq report (concat report "[Skipped]")))
903                (if (jde-wiz-set-member-p name set-get-functions)
904                    (setq report (concat report "[Exists ]"))
905                  (if finalp
906                      (setq report (concat report "[N/A    ]")))))
907
908              (setq report (concat report "\t"))
909
910              ;;getting the get method if it does not exist in the buffer
911              (if (not (jde-wiz-get-member-p name set-get-functions))
912                  (if (and (or bothp get-onlyp)
913                           (or (not staticp) jde-wiz-get-set-static-members))
914                      (progn
915                        (setq temp (concat temp (jde-wiz-get-get-method type name staticp class)))
916                        (setq report (concat report "[Added  ]")))
917                    (setq report (concat report "[Skipped]")))
918                (setq report (concat report "[Exists ]")))))
919
920       (setq report (concat report "\n"))
921
922       (setq non-public-variables (cdr non-public-variables)))
923
924     (setq pos (point))
925     (if temp (insert temp))
926     (if jde-wiz-show-report
927         (with-output-to-temp-buffer (concat "*jde-wiz-get-set-methods report for " class "*")
928           (princ report)))
929     ;;indenting the new code
930     (jde-wiz-indent pos)))
931
932 (defun jde-wiz-get-get-set-methods(tokens)
933   "Returns a list of the methods that start with set, get or is."
934   (let (token name filtered-methods)
935     (while tokens
936       (setq token (car tokens))
937       (setq name (semantic-token-name token))
938       (if (or (string-match "^get" name)
939               (string-match "^set" name)
940               (string-match "^is" name))
941           (setq filtered-methods (append filtered-methods (list name))))
942       (setq tokens (cdr tokens)))
943     filtered-methods))
944
945 (defun jde-wiz-filter-variables-by-typemodifier(tokens)
946   "Returns a subsets of tokens. It returns the tokens that contains either private or
947 protected modifiers"
948   (let (token modifiers filtered-tokens)
949     (while tokens
950       (setq token (car tokens))
951       (setq modifiers (semantic-token-variable-modifiers token))
952       (if (not (member "public" modifiers))
953           (setq filtered-tokens (append filtered-tokens (list token))))
954       (setq tokens (cdr tokens)))
955     filtered-tokens))
956
957 (defun jde-wiz-get-name(variable)
958   "Gets the name of variable to be used in generation the get set
959 method templates. For Example if the variable is \"_Name\" and the variable
960 `jde-wiz-get-set-variable-convention' is set to prefix _ this method will
961 return \"Name\"."
962   (let (answer
963         (cfs case-fold-search)
964         (fix (car jde-wiz-get-set-variable-convention))
965         (convention (cdr jde-wiz-get-set-variable-convention)))
966     (setq case-fold-search nil)
967     (cond ((not convention)
968            (setq answer variable))
969           ((string= "Prefix" convention)
970            (progn
971              (if fix
972                  (let ((pos (string-match (concat "^" fix) variable)))
973                    (if pos
974                        (setq answer (substring variable (+ pos (length fix))))
975                      (setq answer variable)))
976                (setq answer variable))))
977           ((string= "Postfix" convention)
978            (progn
979              (if fix
980                  (let ((pos (string-match (concat fix "$") variable)))
981                    (if pos
982                        (setq answer (substring variable 0 pos))
983                      (setq answer variable)))
984                (setq answer variable))))
985           (t
986            (let ((pos (string-match "[A-Z]." variable)))
987              (if pos
988                  (let ((ans (substring variable pos)))
989                    (if ans
990                        (setq answer ans)
991                      (setq answer variable)))
992                (setq answer variable)))))
993     (setq case-fold-search cfs)
994     answer))
995
996
997 (defun jde-wiz-get-get-method(type name &optional staticp &optional class-name)
998   "Returns a string representing a get method"
999   (let ((filtered-name (jde-wiz-get-name name))
1000         get (javadoc "") temp temp2)
1001     (setq
1002      get
1003      (concat
1004       "\n"
1005       (if jde-wiz-include-javadoc
1006           (progn
1007             (setq temp2 jde-wiz-get-javadoc-template)
1008             (while temp2
1009               (setq temp (car temp2))
1010               (while (string-match "%n" temp)
1011                 (setq
1012                  temp
1013                  (replace-match
1014                   (jde-wiz-downcase-initials filtered-name) nil nil temp)))
1015               (while (string-match "%t" temp)
1016                 (setq temp (replace-match type nil nil temp)))
1017               (setq javadoc (concat javadoc temp "\n"))
1018               (setq temp2 (cdr temp2)))
1019             javadoc))
1020       (jde-gen-method-signature
1021        (concat "public" (if staticp " static"))
1022        type
1023        (concat
1024         (if (string= type "boolean") "is" "get")
1025         (upcase-initials filtered-name))
1026        nil)
1027       (if jde-gen-k&r "{" "\n{") "\n"
1028       "return " (if staticp (concat class-name ".") "this.")
1029       name ";\n}\n"))
1030     get))
1031
1032 (defun jde-wiz-get-set-method(type name &optional staticp class-name)
1033   "Returns a string representing a set method"
1034   (let ((filtered-name (jde-wiz-get-name name))
1035         set (javadoc "") arg-name temp temp2)
1036     (if jde-wiz-get-set-variable-prefix
1037         (setq
1038          arg-name
1039          (jde-wiz-downcase-initials
1040           (concat jde-wiz-get-set-variable-prefix (upcase-initials filtered-name))))
1041       (setq arg-name (jde-wiz-downcase-initials filtered-name)))
1042
1043     (setq
1044      set
1045      (concat
1046       "\n"
1047       (if jde-wiz-include-javadoc
1048           (progn
1049             (setq temp2 jde-wiz-set-javadoc-template)
1050             (while temp2
1051               (setq temp (car temp2))
1052               (while (string-match "%n" temp)
1053                 (setq temp
1054                       (replace-match
1055                        (jde-wiz-downcase-initials filtered-name) nil nil temp)))
1056               (while (string-match "%t" temp)
1057                 (setq temp (replace-match type nil nil temp)))
1058               (while (string-match "%p" temp)
1059                 (setq temp (replace-match arg-name nil nil temp)))
1060               (setq javadoc (concat javadoc temp "\n"))
1061               (setq temp2 (cdr temp2)))
1062             javadoc))
1063       (jde-gen-method-signature
1064        (concat "public" (if staticp " static"))
1065        "void"
1066        (concat "set" (upcase-initials filtered-name))
1067        (concat type " " arg-name))
1068       (if jde-gen-k&r "{" "\n{") "\n"
1069       (if staticp (concat class-name ".") "this.")
1070       name " = " arg-name ";\n}\n"))
1071     set))
1072
1073
1074 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1075 ;;                                                                               ;;
1076 ;;    ToString Wizard                                                            ;;
1077 ;;                                                                               ;;
1078 ;;    Contributed by Jeff Jensen                                                 ;;
1079 ;;                                                                               ;;
1080 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1081
1082 (defcustom jde-wiz-tostring-sort-variables nil
1083   "*Specifies whether or not to sort the list of variables in the
1084   generated method or list them in the order defined in the file."
1085   :group 'jde-wiz
1086   :type 'boolean)
1087
1088 (defcustom jde-wiz-tostring-stringbuffer-size "1000"
1089   "*Specifies the initial size of the StringBuffer used to create the
1090   result for the toString().  It is best to set this to a value large
1091   enough for most of your work to prevent expansion of the
1092   StringBuffer at runtime.  You can always change the value in the
1093   generated code to a smaller or larger one as needed."
1094   :group 'jde-wiz
1095   :type 'string)
1096
1097 (defcustom jde-wiz-tostring-variable-separator "\"  \""
1098   "*Specifies the string between each variable to separate them.
1099   Examples: 2 spaces (the default), a comma and a space, newline, or a
1100   method call (as long as the return value is a String).
1101
1102   Note: Remember this must result in a String in Java!"
1103   :group 'jde-wiz
1104   :type 'string)
1105
1106 (defcustom jde-wiz-tostring-prefix nil
1107   "*Specifies the string to prepend to the string result.
1108   Example: getClass().getName()
1109
1110   Note: Remember this must result in a String in Java!"
1111   :group 'jde-wiz
1112   :type '(repeat (string :tag "Text")))
1113
1114 (defcustom jde-wiz-tostring-postfix nil
1115   "*Specifies the string to append to the string result.
1116   Example: getClass().getName()
1117
1118   Note: Remember this must result in a String in Java!"
1119   :group 'jde-wiz
1120   :type '(repeat (string :tag "Text")))
1121
1122 (defcustom jde-wiz-tostring-static-members t
1123   "If on (nonnil), `jde-wiz-tostring' includes the values of the
1124  static members of the class in the current buffer."
1125   :group 'jde-wiz
1126   :type 'boolean)
1127
1128 (defun jde-wiz-tostring()
1129   "Generates a toString() method for tbe class at point. The method
1130 returns a string comprising the values of the member variables defined
1131 by the class. The string lists the variables in alphabetical
1132 order if `jde-wiz-tostring-sort-variables' is on. The string uses the
1133 string specified by `jde-wiz-tostring-variable-separator' to separate
1134 the variables. The generated method uses a string buffer of the size
1135 specified by `jde-wiz-tostring-stringbuffer-size' to build the string.
1136 If `jde-wiz-tostring-prefix' is defined, it is prepended to the string.
1137 If `jde-wiz-tostring-postfix' is defined, it is appended to the string. "
1138  (interactive)
1139  (let* ((class-name
1140          (jde-parse-get-unqualified-name
1141           (jde-parse-get-class-at-point)))
1142         (variables
1143          (semantic-find-nonterminal-by-token
1144           'variable
1145           (jde-wiz-get-class-parts
1146            class-name
1147            (semantic-find-nonterminal-by-token
1148             'type
1149             (semantic-bovinate-toplevel t)
1150             ))))
1151         (method
1152          (concat
1153           "/**\n"
1154           " * {@inheritDoc}\n"
1155           " */\n"
1156           ;; respect coding style - by yoonforh 2004-05-10 01:34:02
1157           "public String toString()"
1158           (if jde-gen-k&r " {\n" "\n{\n")
1159           "final int sbSize = " jde-wiz-tostring-stringbuffer-size  ";\n"
1160           "final String variableSeparator = " jde-wiz-tostring-variable-separator ";\n"
1161           "final StringBuffer sb = new StringBuffer(sbSize);\n\n"))
1162         (prefix jde-wiz-tostring-prefix)
1163         (postfix jde-wiz-tostring-postfix))
1164
1165    (setq variables (jde-wiz-filter-variables-by-typemodifier variables))
1166
1167    (if jde-wiz-tostring-sort-variables
1168        (setq variables (semantic-sort-tokens-by-name-increasing variables)))
1169
1170    ;; Remove static members.
1171    (unless jde-wiz-tostring-static-members
1172      (setq
1173       variables
1174       (delq
1175        nil
1176        (mapcar
1177         (lambda (var)
1178           (let ((staticp
1179                  (member
1180                   "static"
1181                   (semantic-token-variable-modifiers var))))
1182             (unless staticp var)))
1183         variables))))
1184
1185    (while prefix
1186      (setq method (concat method "sb.append(" (car prefix) ");\n")
1187            prefix (cdr prefix)))
1188
1189    (while variables
1190      (let* ((var (car variables))
1191            (name (semantic-token-name var))  ;;variable name
1192            (type (semantic-token-type var))) ;;variable type i.e. boolean
1193
1194        (setq
1195         method
1196         (concat
1197          method
1198          "sb.append(\"" name "=\").append(" name ");\n"))
1199
1200        (if (> (length variables) 1)
1201            (setq method (concat method "sb.append(variableSeparator);\n")))
1202
1203        (setq variables (cdr variables))))
1204
1205    (while postfix
1206      (setq method (concat method "sb.append(" (car postfix) ");\n")
1207            postfix (cdr postfix)))
1208
1209    (setq method
1210          (concat
1211           method "\nreturn sb.toString();\n}\n"))
1212
1213    (insert method))
1214
1215  (jde-wiz-indent (point)))
1216
1217
1218 (provide 'jde-wiz)
1219
1220
1221 ;;; Change History:
1222
1223 ;; $Log: jde-wiz.el,v $
1224 ;; Revision 1.91  2005/01/03 17:36:48  troy
1225 ;; Add prefix and postfix settings for jde-wiz-tostring
1226 ;;
1227 ;; Revision 1.90  2004/10/20 06:17:06  paulk
1228 ;; Update to support reloading classes from a single classpath entry. Thanks to Martin Schwamberger.
1229 ;;
1230 ;; Revision 1.89  2004/05/16 03:54:50  paulk
1231 ;; Fix various bugs in jde-wiz-tostring command.
1232 ;;
1233 ;; Revision 1.88  2004/05/14 03:44:43  paulk
1234 ;; - Remove extra space in generated get/set methods.
1235 ;; - Adds the customization variable jde-wiz-tostring-static-members.
1236 ;; - Enhances jde-wiz-tostring to respect the coding style specified
1237 ;;   by jde-gen-k&r.
1238 ;;
1239 ;; Thanks to Yoon Kyung Koo.
1240 ;;
1241 ;; Revision 1.87  2004/05/03 02:33:02  paulk
1242 ;; Initial implementation of jde-wiz-tostring command. Thanks to Jeff Jensen.
1243 ;;
1244 ;; Revision 1.86  2004/03/22 06:19:44  paulk
1245 ;; Enhance the get/set wizard to use jde-gen-method-signature. Thanks to Martin Schwamberger.
1246 ;;
1247 ;; Revision 1.85  2004/02/21 06:22:37  paulk
1248 ;; Adds jde-wiz-get-set-static-members option. Thanks to Petter  M\81Ã¥hl\81én.
1249 ;;
1250 ;; Revision 1.84  2004/02/21 06:03:37  paulk
1251 ;; Deleted spurious space in generated get method. Thanks to Petter Mahlen.
1252 ;;
1253 ;; Revision 1.83  2003/09/22 02:57:49  paulk
1254 ;; Cosmetic change.
1255 ;;
1256 ;; Revision 1.82  2003/09/07 05:21:12  paulk
1257 ;; Fix interface, abstract class, and method delegation wizards
1258 ;; to observe jde-import-excluded-classes. Thanks to Martin
1259 ;; Schwamberger.
1260 ;;
1261 ;; Revision 1.81  2003/04/09 02:24:42  paulk
1262 ;; Tiny docstring change.
1263 ;;
1264 ;; Revision 1.80  2003/03/28 05:33:30  andyp
1265 ;; XEmacs optimizations for JDEbug and efc.
1266 ;;
1267 ;; Revision 1.79  2003/03/19 04:11:06  paulk
1268 ;; Updated doc for jde-wiz-include-javadoc, jde-wiz-generate-interface, jde-wiz-delegate,
1269 ;; jde-wiz-generate-abstract-class commands.
1270 ;;
1271 ;; Revision 1.78  2003/02/25 15:01:01  jslopez
1272 ;; Modifies jde-parse-get-qualified-name to take an extra parameters.
1273 ;; If it does not find the qualified name it tries importing the class.
1274 ;; And updates a few places where it is call to do that.
1275 ;;
1276 ;; Revision 1.77  2003/02/18 02:09:40  jslopez
1277 ;; Fixes regression bugs.
1278 ;;
1279 ;; Revision 1.76  2003/02/17 08:13:05  paulk
1280 ;; Changes required to support new package-independent version of beanshell.el
1281 ;;
1282 ;; Revision 1.75  2002/09/16 04:04:50  paulk
1283 ;; Added require statement for semantic-util. Thanks to Andy Piper.
1284 ;;
1285 ;; Revision 1.74  2002/09/11 04:26:22  paulk
1286 ;; Removed low-level condition-case clauses from interface wizard that were burying error messages to user.
1287 ;;
1288 ;; Revision 1.73  2002/09/06 12:51:52  paulk
1289 ;; Fixed jde-wiz-override-method to allow entry only of a complete method signature or nil.
1290 ;; If nil, the command now aborts and issues an informative message instead of a Lisp
1291 ;; error.
1292 ;;
1293 ;; Revision 1.72  2002/05/31 18:59:29  mnl
1294 ;; Fixed handling of several imports resulting from one override (add all
1295 ;; instead of querying the user to select one).
1296 ;;
1297 ;; Revision 1.71  2002/05/14 06:29:55  paulk
1298 ;; Enhances code generation wizards for implementing interfaces, abstract
1299 ;; classes, etc., to use customizable templates to generate skeleton methods
1300 ;; instead of hard-wired skeletons. Thanks to "Dr. Michael Lipp" <lipp@danet.de>
1301 ;; for proposing and implementing this improvement.
1302 ;;
1303 ;; Revision 1.70  2002/05/13 05:23:04  paulk
1304 ;; Put a space between the argument list and the opening brace of generated get/set methods.
1305 ;; Thanks to "Molitor, Stephen" <SMolitor@erac.com>.
1306 ;;
1307 ;; Revision 1.69  2002/04/16 03:17:05  jslopez
1308 ;; Integrates jde-open-source.
1309 ;;
1310 ;; Revision 1.68  2001/12/04 05:30:11  paulk
1311 ;; Updated to reflect change in dialog class package name prefix from jde- to efc-.
1312 ;;
1313 ;; Revision 1.67  2001/11/28 20:44:19  jslopez
1314 ;; Fixes compilation warnings.
1315 ;; Fixes jde-wiz-update-implements-clause not to add an extra space.
1316 ;;
1317 ;; Revision 1.66  2001/11/05 00:47:57  jslopez
1318 ;; Fixed bug cause by previous enhancement to jde-wiz-override-method.
1319 ;;
1320 ;; Revision 1.65  2001/11/04 20:52:20  jslopez
1321 ;; Modified the method jde-wiz-override-method to show
1322 ;; a list of the possible methods to overwrite.
1323 ;;
1324 ;; Revision 1.64  2001/11/02 13:45:54  paulk
1325 ;; - fixed off-by-one bug in jde-wiz-update-implements-clause
1326 ;; - fixed description mistake in jde-wiz-get-name
1327 ;; Thanks to Greg Fenton.
1328 ;;
1329 ;; Revision 1.63  2001/10/30 06:43:39  paulk
1330 ;; Fixed some bugs in the event source wizard.
1331 ;;
1332 ;; Revision 1.62  2001/10/26 06:41:56  paulk
1333 ;; Updated to reflect the new modal behavior of jde-option-dialog.
1334 ;;
1335 ;; Revision 1.61  2001/10/24 11:20:47  paulk
1336 ;; Removed spurious line endings.
1337 ;;
1338 ;; Revision 1.60  2001/10/24 10:45:47  paulk
1339 ;; Fixed regression bug introduced by putting indentation
1340 ;; code into jde-wiz-generate-interface. All indentation
1341 ;; should be performed by higher-level functions, e.g.
1342 ;; jde-wiz-implement-interface.
1343 ;;
1344 ;; Revision 1.59  2001/10/14 00:02:46  jslopez
1345 ;; Now the following methods leave the cursor at point
1346 ;; after inserting the code, jde-method-implement-interface,
1347 ;; jde-wiz-override-method,jde-wiz-delegate,jde-wiz-extend-abstract-class,
1348 ;; and jde-wiz-get-set-methods.
1349 ;;
1350 ;; Revision 1.58  2001/09/27 15:10:10  jslopez
1351 ;; Fixing logic error when using jde-gen-k&r, it was backwards.
1352 ;;
1353 ;; Revision 1.57  2001/08/18 05:49:12  paulk
1354 ;; Fixed regression error in the method override wizard and reimplemented the method selection dialog to use jde-option-dialog. Also eliminated some dead code.
1355 ;;
1356 ;; Revision 1.56  2001/08/17 03:50:53  paulk
1357 ;; Fixes bugs caused by my rewording of jde-wiz-get-set-methods-order options. Thanks to Javier Lopez.
1358 ;;
1359 ;; Revision 1.55  2001/08/15 05:01:13  paulk
1360 ;; Fixed capitalization bug caused by setting the jde-wiz-get-set-convention
1361 ;; to Everything after the first upcase letter. Thanks to Javier Lopez.
1362 ;;
1363 ;; Revision 1.54  2001/08/14 06:05:49  paulk
1364 ;; Updated jde-browse-class to use jde-parse-select-qualified-class-name.
1365 ;;
1366 ;; Revision 1.53  2001/08/11 06:47:18  paulk
1367 ;; * Wizards now observe the jde-gen-k&r indentation preference.
1368 ;; * Adds jde-wiz-get-set-methods-include and jde-wiz-get-set-methods-order variables.
1369 ;;   Thanks to Javier Lopez.
1370 ;;
1371 ;; Revision 1.52  2001/08/05 06:02:12  paulk
1372 ;; Various fixes and improvements to the get-set method code generation command. Thanks to Javier Lopez.
1373 ;;
1374 ;; Revision 1.51  2001/08/04 03:42:04  paulk
1375 ;; Adds jde-wiz-extend-abstract-class command. Thanks to Javier Lopez.
1376 ;;
1377 ;; Revision 1.50  2001/07/31 05:07:39  paulk
1378 ;; Adds JDE->Wizards->Generate Get/Set Methods. Thanks to Javier Lopez and Sandip Chitale.
1379 ;;
1380 ;; Revision 1.49  2001/07/08 04:35:48  paulk
1381 ;; Added compatibility fixes for NT/XEmacs use of backslash as the
1382 ;; default directory sep character. Thanks to William Griswold <wgg@cs.ucsd.edu>
1383 ;;
1384 ;; Revision 1.48  2001/06/28 04:06:04  paulk
1385 ;; Fixed jde-wiz-update-classes so that it updates the classes list to the CLASSPATH environment variable if jde-global-classpath is not defined.
1386 ;;
1387 ;; Revision 1.47  2001/06/12 07:18:55  paulk
1388 ;; Changed jde-parse-declared-type-of to return a qualified type.
1389 ;; Thanks to "Evan Easton" <evan@eeaston.com> .
1390 ;;
1391 ;; Revision 1.46  2001/05/31 05:14:39  paulk
1392 ;; Provide support for per-project caching of class data in the Beanshell. Thanks to Matt Conway.
1393 ;;
1394 ;; Revision 1.45  2001/05/23 05:14:00  paulk
1395 ;; Updated jde-wiz-override-method-internal to intent the inserted code.
1396 ;;
1397 ;; Revision 1.44  2001/05/23 05:03:32  paulk
1398 ;; Updated jde-wiz-implement-interface to indent the inserted code.
1399 ;;
1400 ;; Revision 1.43  2001/05/21 06:45:39  paulk
1401 ;; Implement interface command now accepts unqualified interface names.
1402 ;;
1403 ;; Revision 1.42  2001/04/27 03:58:13  paulk
1404 ;; Fixes Override Method Wizard so that it does not require a compiled version of the base class.
1405 ;;
1406 ;; Revision 1.41  2001/04/16 06:02:27  paulk
1407 ;; Normalize paths. Thanks to Nick Sieger.
1408 ;;
1409 ;; Revision 1.40  2001/04/11 03:16:36  paulk
1410 ;; Updated to resolve relative paths relative to the project file that defines them. Thanks to Nick Seiger.
1411 ;;
1412 ;; Revision 1.39  2001/03/13 03:45:06  paulk
1413 ;; Cosmetic changes.
1414 ;;
1415 ;; Revision 1.38  2000/12/21 13:24:12  paulk
1416 ;; Changed jde-wiz-insert-imports to jde-import-insert-imports to reflect recent repackaging scheme.
1417 ;;
1418 ;; Revision 1.37  2000/12/18 05:22:46  paulk
1419 ;; *** empty log message ***
1420 ;;
1421 ;; Revision 1.36  2000/11/27 06:18:41  paulk
1422 ;; Miscellaneous bug fixes and minor enhancements.
1423 ;;
1424 ;; Revision 1.35  2000/11/20 05:15:16  paulk
1425 ;; Added jde-import-organize command. Moved all import-related code from
1426 ;; jde-wiz.el to a new package named jde-import.el.
1427 ;;
1428 ;; Revision 1.34  2000/11/17 04:02:24  paulk
1429 ;; jde-wiz-update-class-list now uses the current jde-global-classpath when building the class list. This eliminates the need to restart the beanshell when switching projects.
1430 ;;
1431 ;; Revision 1.33  2000/11/16 05:44:56  paulk
1432 ;; Fixed problem in jde-sort-imports command. The problem was that jde-sort-imports temporarily defined sort-fold-case just before invoking sort-lines. Invoking sort-lines caused the sort package to be loaded. Since sort-fold-case is already defined, the sort package did not bother to define it. Then sort-lines returns to jde-sort-lines which proceeded to destroy the temporary copy of sort-fold-case. The fix is to have jde-sort-lines require the sort package before invoking sort-lines.
1433 ;;
1434 ;; Revision 1.32  2000/11/16 04:53:26  paulk
1435 ;; Adds jde-wiz-kill-extra-imports command contributed by David Ponce.
1436 ;;
1437 ;; Revision 1.31  2000/10/25 04:35:20  paulk
1438 ;; Updated sort import function to reflect new bovinator syntax.
1439 ;;
1440 ;; Revision 1.30  2000/10/08 12:55:39  paulk
1441 ;; *** empty log message ***
1442 ;;
1443 ;; Revision 1.29  2000/09/24 08:42:52  paulk
1444 ;; Now sorts import list after adding an import. To disable this feature, set jde-auto-sort-imports off. Thanks to "Jason Stell" <Jason.Stell@globalone.net>
1445 ;;
1446 ;; Revision 1.28  2000/08/03 04:54:11  paulk
1447 ;; Restored use of the radio buttons by the import wizard. Somehow this functionality got deleted.
1448 ;;
1449 ;; Revision 1.27  2000/07/28 06:27:46  paulk
1450 ;; Committing all modified files.
1451 ;;
1452 ;; Revision 1.26  2000/07/14 05:22:57  paulk
1453 ;; Adds a delegation wizard contributed by Charles Hart.
1454 ;;
1455 ;; Revision 1.25  2000/07/13 07:18:24  paulk
1456 ;; * You can now specify a list of packages to exclude from import
1457 ;;   into a source file. See jde-wiz-import-excluded-packages for
1458 ;;   more information. Thanks to "Jim Loverde" <loverde@str.com>
1459 ;;   for this enhancement.
1460 ;;
1461 ;; * Changed name of jde-wiz-insert-excluded-packages-regexp to
1462 ;;   jde-wiz-import-excluded-packages.
1463 ;;
1464 ;; Revision 1.23  2000/06/22 02:50:25  paulk
1465 ;; The import wizard dialog now uses radio buttons rather than check boxes to select
1466 ;;  the class to import. Thanks to Mark Gibson for this enhancement.
1467 ;;
1468 ;; Revision 1.22  2000/06/01 06:01:14  paulk
1469 ;; Added jde-sort-imports command. Thanks to David Ponce <david_ponce@mail.schneider.fr>.
1470 ;;
1471 ;; Revision 1.21  2000/01/18 07:11:26  paulk
1472 ;; Added jde-show-class-source. Thanks to Phil Lord for the initial
1473 ;; implementation of this command.
1474 ;;
1475 ;; Revision 1.20  1999/12/19 07:02:30  paulk
1476 ;; Changed import wizard to use jde.util.JdeUtilities.getQualifiedName
1477 ;; eliminated redundancy. Thanks to Len Trigg <len@intelligenesis.net>
1478 ;; for this improvement.
1479 ;;
1480 ;; Revision 1.19  1999/11/01 03:11:42  paulk
1481 ;; Added jde-browse-class contributed by Rohit Namjoshi <Rohit_Namjoshi@trilogy.com>.
1482 ;;
1483 ;; Revision 1.18  1999/10/17 04:35:05  paulk
1484 ;; Fixed a line in jde-wiz.el, where an int is concat'd with some
1485 ;; strings.  This is not allowed by XEmacs 21.1.
1486 ;;
1487 ;; Revision 1.17  1999/10/01 05:58:14  paulk
1488 ;; Added jde-wiz-update-class-list function contributed by Phillip Lord.
1489 ;;
1490 ;; Revision 1.16  1999/09/17 06:52:50  paulk
1491 ;; Fixed regression error where the interface wizard was putting quotes
1492 ;; around the code inserted into the source buffer.
1493 ;;
1494 ;; Revision 1.15  1999/08/29 04:29:18  paulk
1495 ;; Patches provided by Michael Ernst <mernst@alum.mit.edu>
1496 ;;
1497 ;; Revision 1.14  1999/08/23 02:13:43  paulk
1498 ;; Fixed regression bug in jde-wiz-implement-interface caused by recent
1499 ;; change in jde-wiz-insert-imports.
1500 ;;
1501 ;; Revision 1.13  1999/06/22 21:12:20  paulk
1502 ;; Added variable to filter out unwanted classes from the list of classes being
1503 ;; considered for import command by jde-find-and-import. The jde-find-and-import
1504 ;; command now prompts the user if more than one class matches the specified
1505 ;; import name. Thanks to Phillip Lord <plord@hgmp.mrc.ac.uk> for these enhancements.
1506 ;;
1507 ;; Revision 1.12  1999/05/07 20:42:25  paulk
1508 ;; Cosmetic change.
1509 ;;
1510 ;; Revision 1.11  1999/05/07 20:40:49  paulk
1511 ;; Added new command, jde-wiz-find-and-import, that, given an unqualified class
1512 ;; name, generates and inserts an import statement for that class.
1513 ;;
1514 ;; Revision 1.10  1999/02/17 19:16:07  paulk
1515 ;; Provided more robust error handling for the interface wizard. The wizard
1516 ;; no longer kills the bsh when it cannot create an interface and provides
1517 ;; meaningfull error messages.
1518 ;;
1519 ;; Revision 1.9  1999/02/15 01:12:54  paulk
1520 ;; Fixed bug in jde-wiz-get-method-class that caused it to fail when the open bracket
1521 ;; for the class was not on the same line as the class keyworkd. Thanks to
1522 ;; P.Lord@mdx.ac.uk (Phillip Lord) for diagnosing this bug.
1523 ;;
1524 ;; Revision 1.8  1999/02/12 15:13:00  paulk
1525 ;; Added jde-wiz-import function.
1526 ;;
1527 ;; Revision 1.7  1999/02/11 19:14:50  paulk
1528 ;; Fixed bug in jde-wiz-update-implements-clause.
1529 ;;
1530 ;; Revision 1.6  1999/02/11 18:28:40  paulk
1531 ;; Corrected missing parentheses.
1532 ;;
1533 ;; Revision 1.5  1998/11/22 22:03:43  paulk
1534 ;; Fixed bug in interface wizard.
1535 ;;
1536 ;; Revision 1.4  1998/11/22 21:55:33  paulk
1537 ;; Fixed bug in interface wizard.
1538 ;;
1539 ;; Revision 1.3  1998/11/21 02:41:34  paulk
1540 ;; Fixed bug.
1541 ;; Added implements clause update function to interface implementation wizard.
1542 ;;
1543 ;; Revision 1.2  1998/11/10 00:46:39  paulk
1544 ;; Added smart import insertion to interface wizard.
1545 ;;
1546 ;; Revision 1.1  1998/11/08 00:39:24  paulk
1547 ;; Initial revision
1548 ;;
1549
1550
1551 ;; End of jde-wiz.el