Initial Commit
[packages] / xemacs-packages / jde / lisp / jde-gen.el
1 ;;; jde-gen.el -- Integrated Development Environment for Java.
2 ;; $Revision: 1.86 $ 
3
4 ;; Author: Paul Kinnucan <paulk@mathworks.com>
5 ;; Maintainer: Paul Kinnucan
6 ;; Keywords: java, tools
7
8 ;; Copyright (C) 1997, 1998, 2000, 2001, 2002, 2003, 2004 Paul Kinnucan.
9
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; Gnu Emacs 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.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24 ;;
25
26 (require 'tempo)
27
28 (defgroup jde-gen nil
29   "JDE Autocoder"
30   :group 'jde
31   :prefix "jde-gen-")
32
33 (defcustom jde-gen-k&r t
34   "*If non-nil, use braces in Original Kernighan & Ritchie Style.
35 The Creators of C started using brace placement style:
36
37     class Some {
38
39     }
40
41 But there is also the alternative line-up style:
42
43     class Some
44     {
45
46     }
47
48 Setting this variable to t, uses K&R style in skeletons and tempaltes.
49
50 Note: According to the Java Code Convention [section 6.4], this value should
51       be non-nil."
52   :group 'jde-gen
53   :type  'boolean)
54
55 ; There must be some cleverer way to do this ...
56 (defun jde-gen-delete-preceding-whitespace ()
57   "Delete any syntactical whitespace (including newlines)
58 before point."
59   (while (and (not (bobp)) 
60               (or (bolp) 
61                   (re-search-backward "\\s-\\=" nil t)))
62     (delete-char -1)))
63
64 (defun jde-gen-extract-ids-from-params (params)
65   "Given a parameter lsit \"Type1 id1, Type2, id2, ...\" extract the
66 ids and return as \"id1, id2, ...\"."
67   (mapconcat 
68    (lambda (arg) 
69      (nth 1 (split-string 
70              (replace-in-string 
71               (replace-in-string arg "^[ \t\n\f\l]+" "")
72               "[ \t\n\f\l]+$" ""))))
73    (split-string params "[,]") ", "))
74
75 (defun jde-gen-lookup-named (name)
76   "Lookup some saved data under the name NAME.
77 Returns the data if NAME was found, and nil otherwise."
78   (cdr (assq name tempo-named-insertions)))
79
80 (defun jde-gen-read-template (strings)
81   "Converts an autocode template represented as a list
82 of strings to a list of Lisp objects as required by
83 tempo."
84   (let ((template-string "")
85         (n (length strings))
86         (i 0))
87     (while (< i n)
88       (setq template-string
89             (concat template-string (nth i strings) "\n"))
90       (setq i (1+ i)))
91     (setq template-string
92           (concat "'(" template-string ")"))
93     (eval (car (read-from-string template-string)))))
94
95 (defcustom jde-gen-buffer-boilerplate nil
96   "*Lines of boilerplate text to put at the head of a buffer template."
97   :group 'jde-gen
98   :type '(repeat (string :tag "Line")))
99
100 (defcustom jde-gen-boilerplate-function 'jde-gen-create-buffer-boilerplate
101   "*Specifes buffer boilerplate text function.
102 This variable specifies a function to create boilerplate text for
103 insertion at the head of Java source buffers generated by JDE
104 templates. The specified function should take no arguments and should
105 return a text string.  The default value is
106 `jde-gen-create-buffer-boilerplate', which returns the lines of text
107 specified by `jde-gen-buffer-boilerplate'."
108   :group 'jde-gen
109   :type 'function)
110
111 (defun jde-gen-create-buffer-boilerplate ()
112   "This function creates buffer boilerplate from the
113 variable `jde-gen-buffer-boilerplate'."
114   (if jde-gen-buffer-boilerplate
115       (let ((bp "")
116             (n (length jde-gen-buffer-boilerplate))
117             (i 0))
118         (while (< i n)
119           (setq bp
120                 (concat bp (elt jde-gen-buffer-boilerplate i) "\n"))
121           (setq i (1+ i)))
122         bp)))
123
124 (defun jde-gen-get-extend-class ()
125   (let ((super-class (read-from-minibuffer "extends: ")))
126     (if (not (string= super-class ""))
127         (progn 
128           (jde-import-find-and-import super-class)
129           (concat "extends " super-class " ")))))
130
131 (defcustom jde-gen-final-arguments t
132   "Specifies whether to add final modifiers to method arguments.
133 If this variable is t, `jde-gen-method-signature' automatically
134 adds final modifiers to each method argument."
135   :group 'jde-gen
136   :type 'boolean)
137
138 (defcustom jde-gen-final-methods t
139   "Specifies whether to add final method modifier.
140 If this variable is t, `jde-gen-method-signature' automatically adds
141 the final method modifier. This option is ignored within final classes.
142 Note that anonymous classes are implicitly final."
143   :group 'jde-gen
144   :type 'boolean)
145
146 (defun jde-gen-final-argument-modifier (method-args)
147   "Inserts the final modifier depending on `jde-gen-final-arguments'."
148   (if jde-gen-final-arguments
149       (let ((comma nil)
150             (arg-list (split-string method-args ",")))
151         (setq method-args "")
152         (mapcar
153          (lambda (arg)
154            (if (string-match "\\<final\\>" arg)
155                (setq method-args (concat method-args comma arg))
156              (setq method-args
157                    (concat method-args 
158                            comma
159                            (if (string-match "^[ \t]" arg) " ")
160                            "final"
161                            (if (string-match "^[^ \t]" arg) " ")
162                            arg)))
163            (setq comma ","))
164          arg-list)))
165   method-args)
166
167 (defun jde-gen-final-method-modifier (method-modifiers)
168   "Insert final modifier according to `jde-gen-final-methods'."
169   (let ((class-info (jde-parse-get-class-modifiers)))
170     ;; Anonymous classes are implicitly final. See:
171     ;; Java Language specification, section 15.9.5.
172     ;; http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html
173     (unless (or (member "final" class-info) ; explicit final modifier?
174                 (save-excursion
175                   (and class-info
176                        (goto-char (cdar class-info))
177                        (looking-at "new")))) ; anonymous class?
178       (if (and jde-gen-final-methods
179                (not (string-match "final" method-modifiers))
180                (not (string-match "private" method-modifiers))
181                (not (string-match "abstract" method-modifiers)))
182           ;; Find correct position according to
183           ;; Java Language specification, section 8.4.3.
184           ;; http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html
185           (let* ((pos (max (if (string-match "public" method-modifiers) (match-end 0) 0)
186                            (if (string-match "protected" method-modifiers) (match-end 0) 0)
187                            (if (string-match "static" method-modifiers) (match-end 0) 0)))
188                  (left (substring method-modifiers 0 pos))
189                  (right (substring method-modifiers pos)))
190             (setq method-modifiers (concat
191                              left
192                              (if (> (length left) 0) " ")
193                              "final"
194                              (if (and (= (length left) 0) (> (length right) 0)) " ")
195                              right))))))
196   method-modifiers)
197
198 (defmacro jde-gen-save-excursion (&rest body)
199   "Evaluate BODY within a let form.
200 Protects `tempo-marks', `tempo-named-insertions', `tempo-region-start'
201 and `tempo-region-stop' against modifications by invoked template.
202 Those tempo vars will be set to their default values.
203 This allows to invoke tempo-templates within tempo-templates
204 without having mutual interference of those templates.
205 Returns nil."
206   `(progn
207      (let ((tempo-marks)
208            (tempo-named-insertions)
209            (tempo-region-start (make-marker))
210            (tempo-region-stop (make-marker)))
211        (progn ,@body))
212      nil))
213
214 (defun jde-gen-electric-brace (&optional padding)
215   "Insert a brace according to `jde-gen-k&r'.
216 Optional argument PADDING is inserted before brace
217 if jde-gen-k&r is enabled."
218   (if jde-gen-k&r
219       (if padding (insert padding))
220     (progn
221       (indent-according-to-mode)
222       (insert "\n")))
223   (insert "{")
224   (indent-according-to-mode)
225   (insert "\n")
226   nil)
227
228 (defun jde-gen-indent ()
229   "Indent current line if it is not empty.
230 Removes indentation if the current line contains only whitespaces.
231 The purpose of this function is to avoid trailing whitespaces
232 in generated java code. Returns nil."
233   (if (save-excursion
234         (beginning-of-line)
235         (looking-at "\\s-+$"))
236       (replace-match ""))
237   (if (not (and (bolp) (eolp)))
238       (c-indent-line))
239   nil) ;; must return nil to prevent template insertion.
240
241 (defun jde-gen-blank-lines (n &optional m)
242   "Ensure exactly N blank lines.
243 Leaves point at the beginning of the line following blank lines.
244 If M is non-nil, (`forward-line' M) will be called after inserting.
245 If point is at the beginning of a non-blank line, blank lines will appear before that line.
246 If point is at the end of a non-blank line, blank lines will appear after that line.
247 If point is in the middle of a non-blank line, this line will be split at point.
248 Indentation and trailing whitespace of surrounding non-blank lines will stay unchanged.
249 Returns nil."
250   (interactive "*")
251   (if (or (bolp) (eolp)
252           (save-excursion
253             (beginning-of-line)
254             (looking-at "\\s-*$")))
255       (delete-region
256        (+ (point) (skip-chars-backward " \t\n") (skip-chars-forward  " \t"))
257        (+ (point) (skip-chars-forward  " \t\n") (skip-chars-backward " \t"))))
258   (while (>= n 0)
259     (insert "\n")
260     (setq n (1- n)))
261   (if m
262       (forward-line m))
263   nil)
264
265 ; In order to avoid problems with recursive tempo-template invocations
266 ; interface generation has been split in two parts. 
267 ; jde-gen-get-interface-implementation prompts for the
268 ; interface and stores point-marker and interface name in buffer local
269 ; variables.  jde-gen-insert-interface-implementation is invoked after
270 ; the template for class or inner class and generates the interface 
271 ; implementation.
272
273 (defvar jde-gen-interface-to-gen nil
274   "Insertion marker and name (MARKER . NAME) of interface
275 implemented by the most recently generated class template.
276 Used by `jde-gen-get-interface-implementation' to
277 store name and location of interface to be inserted
278 by `jde-gen-insert-interface-implementation'.")
279
280 (defun jde-gen-get-interface-implementation (&optional insert-immediately)
281   "Prompts the user to enter the name of an interface
282 implemented by a class being generated by a tempo template.
283 If the user enters a name, stores the current point as marker in
284 the buffer and the interface name as a cons (MARKER . NAME)
285 in the global variable `jde-gen-interface-to-gen'. Otherwise
286 it sets this variable to nil. If INSERT-IMMEDIATELY is non-nil,
287 `jde-gen-insert-interface-implementation' will be called immediately
288 and jde-gen-interface-to-gen will be set to nil."
289   (let ((interface (read-from-minibuffer "implements: ")))
290     (if (not (string= interface ""))
291         (progn
292           (setq jde-gen-interface-to-gen
293                 (cons (point-marker) interface))
294           (if insert-immediately
295               (progn
296                 (jde-gen-insert-interface-implementation)
297                 (setq jde-gen-interface-to-gen nil))))
298       (setq jde-gen-interface-to-gen nil)))
299   nil) ;; must return nil to prevent template insertion.
300
301 (defun jde-gen-insert-interface-implementation ()
302   "Generates the interface specified by the cdr of `jde-gen-interface-to-gen'
303 and inserts it in the current buffer at the location specified
304 by the car of `jde-gen-interface-to-gen'."
305   (if jde-gen-interface-to-gen
306       (let ((ins-pos (marker-position (car jde-gen-interface-to-gen)))
307             (interface (cdr jde-gen-interface-to-gen)))
308         (save-excursion
309           (goto-char ins-pos)
310           (jde-wiz-implement-interface-internal interface)))))
311
312 (defun jde-gen-get-package-statement ()
313   (require 'jde-package)
314   (let* ((package-dir (jde-package-get-package-directory))
315          (suggested-package-name
316           (if (or
317                (string= package-dir jde-package-unknown-package-name)
318                (string= package-dir ""))
319               nil
320             (jde-package-convert-directory-to-package package-dir)))
321          (package-name
322           (read-from-minibuffer "Package: " suggested-package-name)))
323     (if (and
324          package-name
325          (not (string= package-name "")))
326         (format "package %s;\n\n" package-name))))
327
328
329 (defcustom jde-gen-method-signature-padding-1 ""
330   "String that comes just after the function name and just before
331 the opening parenthesis of the argument list for a method call or definition.
332 For example, if set to a single space [\" \"], then a generated method might
333 look like:
334
335     void setXxxx () {
336                 ^
337 If not set, the same generated method would look like:
338
339     void setXxxx() {
340                 ^
341 Note: According to the Java Code Convention [section 6.4], this value should
342       be the empty string."
343   :group 'jde-gen
344   :type 'string)
345
346
347 (defcustom jde-gen-method-signature-padding-2 ""
348   "String which comes just after the opening parenthesis and just before
349 the closing parenthesis of an argument list for a method call or definition.
350 For example, if set to a single space [\" \"], then a generated method might
351 look like:
352
353     void setXxxx( boolean newValue ) {
354                  ^                ^
355 If not set, the same generated method would look like:
356
357     void setXxxx(boolean newValue) {
358                  ^              ^
359 Note: According to the Java Code Convention [section 6.4], this value should
360       be the empty string."
361   :group 'jde-gen
362   :type 'string)
363
364
365 (defcustom jde-gen-method-signature-padding-3 " "
366   "String which comes just after the closing parenthesis of an
367 argument list for a method call or definition.  For example, if set to
368 a single space [\" \"], then a generated method might look like:
369
370     void setXxxx(boolean newValue) {
371                                   ^
372 If not set, the same generated method would look like:
373
374     void setXxxx(boolean newValue){
375                                   ^
376 Note: According to the Java Code Convention [section 6.4], this value should
377       be a single space."
378   :group 'jde-gen
379   :type 'string)
380
381
382 (defcustom jde-gen-conditional-padding-1 " "
383   "The string to be inserted between a conditional keyword (if, while, etc.)
384 and the opening parenthesis for its conditional expression:
385
386     <keyword><1>(<2><expression><2>)<3>{
387
388 also:  <3>else<3>{
389
390 where <1> is jde-gen-conditional-padding-1
391   and <2> is jde-gen-conditional-padding-2
392   and <3> is jde-gen-conditional-padding-3.
393
394 For example, if <1> is a space, <2> is nil and <3> is a space, then a while
395 clause might look like:
396
397     while (true) {
398
399 Note: According to the Java Code Convention [section 7.4], this value should
400       be a single space."
401   :group 'jde-gen
402   :type 'string)
403
404
405 (defcustom jde-gen-conditional-padding-2 ""
406   "The string to be inserted before and after a conditional expression
407 between the parentheses.  See `jde-gen-conditional-padding-1' for details.
408
409 Note: According to the Java Code Convention [section 7.4], this value should
410       be the empty string."
411   :group 'jde-gen
412   :type 'string)
413
414
415 (defcustom jde-gen-conditional-padding-3 " "
416   "The string to be inserted after the closing parenthesis of the
417 conditional expression and before the opening brace.  See
418 `jde-gen-conditional-padding-1' for details.
419
420 Note: According to the Java Code Convention [section 7.4], this value should
421       be a single space."
422   :group 'jde-gen
423   :type 'string)
424
425
426 (defun jde-gen-method-signature (access type name arglist &optional throwslist)
427   "This function generates method signatures with a consistent format.
428 All jde-gen functions and/or templates should use this function when
429 creating Java methods and constructors.
430
431 The signature is of the format:
432
433   <access> <type> <name><1>(<2><arglist><2>) throws <throwslist><3>
434
435 where <1> is the value of jde-gen-method-signature-padding-1
436   and <2> is the value of jde-gen-method-signature-padding-2
437   and <3> is the value of jde-gen-method-signature-padding-3.
438
439 <3> will not be used if `jde-gen-k&r' is nil.
440
441 This function takes care of `jde-gen-final-methods' and
442 `jde-gen-final-arguments'. final modifiers will be added
443 according to those flags.
444
445 If a parameter to this function is empty or nil, then it is omitted
446 (as well as the corresponding padding, whitespace and/or Java keywords)."
447
448 (if (> (length type) 0) ; ordinary method?
449     (setq access (jde-gen-final-method-modifier access)))
450 (let ((sig
451        (concat
452         (if (> (length access) 0)
453             (concat access " ")
454           ());; if no access (e.g. "public static"), then nothing
455         (if (> (length type) 0)
456             (concat type " ")
457           ());; if no type (e.g. "boolean" or "void"), then nothing
458         name
459         jde-gen-method-signature-padding-1
460         "("
461         (if (> (length arglist) 0)
462             (concat jde-gen-method-signature-padding-2 (jde-gen-final-argument-modifier arglist)
463                     jde-gen-method-signature-padding-2 )
464           ())
465         ")"
466         (if (> (length throwslist) 0)
467             (concat " throws " throwslist)
468           ())
469         (if jde-gen-k&r
470             jde-gen-method-signature-padding-3
471           ()))))
472   sig))
473
474 ;;(makunbound 'jde-gen-class-buffer-template)
475 (defcustom jde-gen-class-buffer-template
476   (list
477    "(funcall jde-gen-boilerplate-function)"
478    "(jde-gen-get-package-statement)"
479    "(progn (require 'jde-javadoc) (jde-javadoc-insert-start-block))"
480    "\" * Describe class \""
481    "(file-name-sans-extension (file-name-nondirectory buffer-file-name))"
482    "\" here.\" 'n"
483    "\" \" (jde-javadoc-insert-empty-line)"
484    "\" \" (jde-javadoc-insert-empty-line)"
485    "\" * Created: \" (current-time-string) 'n"
486    "\" \" (jde-javadoc-insert-empty-line)"
487    "\" \" (jde-gen-save-excursion (jde-javadoc-insert 'tempo-template-jde-javadoc-author-tag))"
488    "\" \" (jde-gen-save-excursion (jde-javadoc-insert 'tempo-template-jde-javadoc-version-tag))"
489    "\" \" (jde-javadoc-insert-end-block)"
490    "\"public class \""
491    "(file-name-sans-extension (file-name-nondirectory buffer-file-name))"
492    "\" \" (jde-gen-get-extend-class)"
493    "(jde-gen-electric-brace)"
494    "'p'n"
495    "\"}\">"
496    "(if jde-gen-comments (concat \" // \""
497    "  (file-name-sans-extension (file-name-nondirectory buffer-file-name))))"
498    "'>'n"
499    ";; Here comes the stuff that needs a fully generated class."
500    ";; We jump back and add those things retrospectively."
501    "(progn (tempo-backward-mark)"
502    " (jde-gen-save-excursion"
503    "  (jde-gen-get-interface-implementation t))"
504    " (jde-gen-save-excursion"
505    "  (jde-wiz-gen-method \"public\" \"\""
506    "   (file-name-sans-extension (file-name-nondirectory buffer-file-name)) \"\" \"\" \"\")))"
507    ";; Move to constructor body. Set tempo-marks to nil in order to prevent tempo moving to mark."
508    "(progn (re-search-forward \"^[ \\t]*$\") (setq tempo-marks nil) nil)")
509   "*Template for new Java class.
510 Setting this variable defines a template instantiation
511 command `jde-gen-class', as a side-effect."
512   :group 'jde-gen
513   :type '(repeat string)
514   :set '(lambda (sym val)
515           (tempo-define-template "java-class-buffer-template"
516                                  (jde-gen-read-template val)
517                                  nil
518                                  "Insert a generic Java class buffer skeleton.")
519           (defalias 'jde-gen-class
520             (list 'lambda (list)
521                   (list 'interactive)
522                   (list 'tempo-template-java-class-buffer-template)
523                   (list 'jde-gen-insert-interface-implementation)))
524           (set-default sym val)))
525
526 ;;;###autoload
527 (defun jde-gen-class-buffer (file)
528   "Create a new Java buffer containing a class of the same name.
529 This command inserts the class template generated by `jde-gen-class'.
530 "
531   (interactive "F")
532   (find-file file)
533   (jde-gen-class))
534
535 ;;(makunbound 'jde-gen-interface-buffer-template)
536 (defcustom jde-gen-interface-buffer-template
537   (list
538    "(funcall jde-gen-boilerplate-function)"
539    "(jde-gen-get-package-statement)"
540    "(progn (require 'jde-javadoc) (jde-javadoc-insert-start-block))"
541    "\" * Describe interface \""
542    "(file-name-sans-extension (file-name-nondirectory buffer-file-name))"
543    "\" here.\" 'n"
544    "\" \" (jde-javadoc-insert-empty-line)"
545    "\" \" (jde-javadoc-insert-empty-line)"
546    "\" * Created: \" (current-time-string) 'n"
547    "\" \" (jde-javadoc-insert-empty-line)"
548    "\" \" (jde-gen-save-excursion (jde-javadoc-insert 'tempo-template-jde-javadoc-author-tag))"
549    "\" \" (jde-gen-save-excursion (jde-javadoc-insert 'tempo-template-jde-javadoc-version-tag))"
550    "\" \" (jde-javadoc-insert-end-block)"
551    "\"public interface \""
552    "(file-name-sans-extension (file-name-nondirectory buffer-file-name))"
553    "\" \" (jde-gen-get-extend-class)"
554    "(jde-gen-electric-brace)"
555    "'p'n"
556    "\"}\">"
557    "(if jde-gen-comments (concat \" // \""
558    "  (file-name-sans-extension (file-name-nondirectory buffer-file-name))))"
559    "'>'n")
560   "*Template for new Java interface.
561 Setting this variable defines a template instantiation
562 command `jde-gen-interface', as a side-effect."
563   :group 'jde-gen
564   :type '(repeat string)
565   :set '(lambda (sym val)
566           (tempo-define-template "java-interface-buffer-template"
567                                  (jde-gen-read-template val)
568                                  nil
569                                  "Insert a generic Java interface buffer skeleton.")
570           (defalias 'jde-gen-interface
571             (list 'lambda (list)
572                   (list 'interactive)
573                   (list 'tempo-template-java-interface-buffer-template)))
574           (set-default sym val)))
575
576 ;;;###autoload
577 (defun jde-gen-interface-buffer (file)
578   "Create a new Java buffer containing an interface of the same name.
579 This command inserts the interface template generated by `jde-gen-interface'.
580 It then moves the point to the location of the first method."
581   (interactive "F")
582   (find-file file)
583   (jde-gen-interface))
584
585 ;;(makunbound 'jde-gen-console-buffer-template)
586 (defcustom jde-gen-console-buffer-template
587   (list
588    "(funcall jde-gen-boilerplate-function)"
589    "(jde-gen-get-package-statement)"
590    "(progn (require 'jde-javadoc) (jde-javadoc-insert-start-block))"
591    "\" * Describe class \""
592    "(file-name-sans-extension (file-name-nondirectory buffer-file-name))"
593    "\" here.\" 'n"
594    "\" \" (jde-javadoc-insert-empty-line)"
595    "\" \" (jde-javadoc-insert-empty-line)"
596    "\" * Created: \" (current-time-string) 'n"
597    "\" \" (jde-javadoc-insert-empty-line)"
598    "\" \" (jde-gen-save-excursion (jde-javadoc-insert 'tempo-template-jde-javadoc-author-tag))"
599    "\" \" (jde-gen-save-excursion (jde-javadoc-insert 'tempo-template-jde-javadoc-version-tag))"
600    "\" \" (jde-javadoc-insert-end-block)"
601    "\"public final class \""
602    "(file-name-sans-extension (file-name-nondirectory buffer-file-name))"
603    "(jde-gen-electric-brace \" \")"
604    "'p'n"
605    "\"}\">"
606    "(if jde-gen-comments (concat \" // \""
607    "  (file-name-sans-extension (file-name-nondirectory buffer-file-name))))"
608    "'>'n"
609    ";; Here comes the stuff that needs a fully generated class."
610    ";; We jump back and add those things retrospectively."
611    "(progn (tempo-backward-mark)"
612    " (jde-gen-save-excursion"
613    "  (jde-gen-main-method))"
614    " (tempo-backward-mark)"
615    " (jde-gen-save-excursion"
616    "  (jde-wiz-gen-method \"private\" \"\""
617    "   (file-name-sans-extension (file-name-nondirectory buffer-file-name)) \"\" \"\" \"\")))"
618    ";; Move to constructor body. Set tempo-marks to nil in order to prevent tempo moving to mark."
619    "(progn (re-search-forward \"^[ \\t]*$\") (setq tempo-marks nil) nil)")
620   "*Template for new Java console app main class buffer.
621 Setting this variable defines a template instantiation
622 command `jde-gen-console', as a side-effect."
623   :group 'jde-gen
624   :type '(repeat string)
625   :set '(lambda (sym val)
626           (defalias 'jde-gen-console
627             (tempo-define-template "java-console-buffer-template"
628                                    (jde-gen-read-template val)
629                                    nil
630                                    "Insert skeleton for a new Java console buffer"))
631           (set-default sym val)))
632
633 ;;;###autoload
634 (defun jde-gen-console-buffer (file)
635   "Create a new Java buffer containing a console class of the same name.
636 This command inserts the class template generated by `jde-gen-class'.
637 It then moves the point to the location to the constructor."
638   (interactive "F")
639   (find-file file)
640   (jde-gen-console))
641
642 ;;(makunbound 'jde-gen-deep-clone-template)
643 (defcustom jde-gen-deep-clone-template
644   '(
645     "(jde-wiz-generate-interface \"java.lang.Cloneable\")"
646
647     "'&'> (progn (require 'jde-javadoc) nil)"
648
649     ;; create the javadoc (todo: only generate if turned on)
650     "(jde-javadoc-insert-start-block)"
651     "\"* Create a deep clone of this object.\" '>'n"
652     "\"*\" '>'n"
653     "\"* @return a deep clone of this object.\" '>'n"
654     "'> (jde-javadoc-insert-end-block)"
655
656     ;; create method declaration
657     "(let (jde-gen-final-methods)"
658     " (jde-gen-method-signature"
659     "   \"public\""
660     "   \"Object\""
661     "   \"clone\""
662     "   nil"
663     " ))"
664     "'>"
665     "(jde-gen-electric-brace)"
666
667     ;; return declaration
668     "(file-name-sans-extension (file-name-nondirectory buffer-file-name))"
669     "\" ret = null;\" '>'n'n"
670
671     ;; must catch CloneNotSupported exception
672     "(let ((beg (point)))"
673     "  (insert \"ret = (\")"
674     "  (insert (file-name-sans-extension"
675     "    (file-name-nondirectory buffer-file-name)))"
676     "  (insert \") super.clone();\")"
677     "  (jde-gen-try-catch-wrapper beg (point))"
678     ;; at this point we are at the place to add what exception to catch
679     "  (insert \"CloneNotSupportedException\")"
680     "  nil)"
681
682     "(progn"
683     ;; first go out of the catch exception ()s
684     " (goto-char (scan-lists (point) 1 1))"
685     ;; now go into the catch {}s definition part
686     " (goto-char (scan-lists (point) 1 -1))"
687     " (end-of-line)"
688     " 'n)"
689     "\"throw new InternalError(\\\"clone should be supported (forgot?)\\\");\""
690     "'>'%"
691
692     "(progn (goto-char (scan-lists (point) 1 1)) (end-of-line) '(l n))"
693
694     ;; todo: detect which members need cloning and generate assignments
695     "(if jde-gen-comments "
696     " '(l \" // add non-immutable member clone assignments here\" '>'n))"
697     "'p'n"
698     ;; add return statement and finish method
699     "\"return ret;\" '>'n"
700     "\"}\" '>'n"
701     )
702   "*Template for creating a deep clone method.
703 Setting this variable defines a template instantiation
704 command `jde-gen-deep-clone', as a side-effect."
705   :group 'jde-gen
706   :type '(repeat string)
707   :set '(lambda (sym val)
708           (defalias 'jde-gen-deep-clone
709             (tempo-define-template
710              "java-deep-clone-method"
711              (jde-gen-read-template val)
712              nil
713              "Create a deep clone method at the current point."))
714           (set-default sym val)))
715
716 ;; TO DO: Add support for style that puts member declarations at the bottom
717 ;; of a class.
718 (defun jde-gen-get-next-member-pos (modifiers &optional no-move-to-point)
719   "Return the position to add the next member in a class.  Return
720 the point at end of a group of modifiers at the end of the line in a class
721 definition, or the top of the class if there are no variables with the
722 modifiers we supply.  This assumes a style where modifiers always are at the
723 top of the class like:
724
725 public class Person {
726
727   public static final String RACE = \"HUMAN\";
728
729   private String name;
730   private int age;
731 ...
732
733 MODIFIERS is a set of modifiers to put the point after.
734 NO-MOVE-POINT if nil move the point, either way, we return the position.
735 "
736   (if (stringp modifiers) (setq modifiers (split-string modifiers ",")))
737   (let* ((pair (jde-parse-get-innermost-class-at-point))
738          (class-name (if pair (car pair)))
739          pos)
740     (if (null pair) (error "point is not in a class definition"))
741     (semantic-fetch-tags)
742     (setq pos (jde-parse-get-nth-member class-name modifiers
743                                         nil -1 nil 'subset))
744
745     (if (null pos) (setq pos (jde-parse-get-top-of-class class-name)))
746     (if (and pos (not no-move-to-point)) (goto-char pos))
747     pos))
748
749
750 (defun jde-gen-insert-at-class-top (&optional class-regexp
751                                                      no-move-point)
752   "Position point at top of class, inserting space if needed.
753
754 CLASS-REGEXP the symbol used to find the class to find the top of.  See
755 `jde-parse-get-top-of-class' for more information.
756
757 NO-MOVE-POINT if non-nil just the position is returned, otherwise the point is
758 moved also."
759   (if (= (point) (jde-parse-get-top-of-class class-regexp no-move-point))
760       (insert "\n"))
761   (insert "\n")
762   (backward-char 1))
763
764 ;;(makunbound 'jde-gen-get-set-var-template)
765 (defcustom jde-gen-get-set-var-template
766   '(
767     ;; position point at top of class, inserting space if needed
768     "(jde-gen-insert-at-class-top nil t)"
769
770     ;; remember where we are for later, then go to the end of the private
771     ;; declarations first found from the top of the class
772     "(progn (tempo-save-named 'mypos (point-marker)) nil)"
773     "(progn"
774     "  (jde-gen-get-next-member-pos '(\"private\")) nil)"
775
776     ;; add class member
777     "(P \"Variable type: \" type t)"
778     "(P \"Variable name: \" name t)"
779     "'&'n'>"
780     "(progn (require 'jde-javadoc) (jde-javadoc-insert-start-block))"
781     "\"* Describe \" (s name) \" here.\" '>'n"
782     "'> (jde-javadoc-insert-end-block)"
783     "'& \"private \" (s type) \" \""
784     "(s name) \";\" '>"
785     "(progn (goto-char (marker-position (tempo-lookup-named 'mypos))) nil)"
786
787     "(jde-gen-blank-lines 2 -1)"
788     ;;we begin by the getter
789     "'> (jde-javadoc-insert-start-block)"
790     "\"* Get the <code>\" (jde-gen-lookup-and-capitalize 'name) \"</code> value.\" '>'n"
791     "'> (jde-javadoc-insert-empty-line)"
792     "'>"
793     "(let ((type (tempo-lookup-named 'type)))"
794     "  (jde-gen-save-excursion (jde-javadoc-insert 'tempo-template-jde-javadoc-return-tag)))"
795     "'> (jde-javadoc-insert-end-block)"
796     "(jde-gen-method-signature"
797     "  \"public\""
798     "  (jde-gen-lookup-named 'type)"
799     "  (if (string= \"boolean\" (jde-gen-lookup-named 'type) ) "
800     "    (concat \"is\" (jde-gen-lookup-and-capitalize 'name))"
801     "   (concat \"get\" (jde-gen-lookup-and-capitalize 'name)))"
802     "  nil"
803     " )"
804
805     "(jde-gen-electric-brace)"
806
807     "\"return \" (s name) \";\" '>'n \"}\"'>'n"
808     ;; leave a blank line with no indentation
809     "'n"
810
811     ;;we continue with the setter
812     "'> (jde-javadoc-insert-start-block)"
813     "\"* Set the <code>\" (jde-gen-lookup-and-capitalize 'name) \"</code> value.\" '>'n"
814     "\"*\" '>'n"
815     ;; ToDo: use jde-wiz-get-set-variable-prefix
816     "\"* @param new\" (jde-gen-lookup-and-capitalize 'name)"
817     "\" The new \" (jde-gen-lookup-and-capitalize 'name) \" value.\" '>'n"
818     "'> (jde-javadoc-insert-end-block)"
819     ;; name the method
820     "(jde-gen-method-signature "
821     "  \"public\""
822     "  \"void\""
823     "  (concat \"set\" (jde-gen-lookup-and-capitalize 'name))"
824     "  (concat (jde-gen-lookup-named 'type) \" new\" "
825     "          (jde-gen-lookup-and-capitalize 'name))"
826     " )"
827
828    "(jde-gen-electric-brace)"
829
830     "'>\"this.\" (s name) \" = new\" (jde-gen-lookup-and-capitalize 'name)"
831     "\";\" '>'n \"}\" '>"
832     "(when (looking-at \"\\\\s-*\\n\\\\s-*$\")"
833     "  (forward-line 1) (end-of-line) nil)"
834     )
835   "*Template for creating a variable at the top of the class and
836 a get/set method pair for the variable at point.
837 Setting this variable defines a template instantiation
838 command `jde-gen-get-set', as a side-effect."
839   :group 'jde-gen
840   :type '(repeat string)
841   :set '(lambda (sym val)
842           (defalias 'jde-gen-get-set
843             (tempo-define-template
844              "java-get-set-pair"
845              (jde-gen-read-template val)
846              nil
847              "Insert variable at the top of the class and get-set method pair at point."))
848           (set-default sym val)))
849
850 (defun jde-gen-get-set-methods (duples)
851   "Generate variables at the top of the class and get and set methods for
852 the variables at point.
853
854 DUPLES is either a list of list type name pairs or a string.  If it is a
855 string, the string has the form:
856
857   type1,name1;type2,name2;...;typeN,nameN
858
859 where type is the primitive or class name of the getter setter and name is the
860 name of the property (getter/setter).
861
862 If DUPLES is a lisp object it must a list with the form:
863
864   ((\"type1\" \"name1\") (\"type2\" \"name2\") ... )"
865   (interactive "sGets/Sets (type1,name1;type2,name2;...): ")
866   (if (stringp duples) (setq duples (split-string duples "[ \t]*;[ \t]*")))
867   (dolist (elt duples)
868     (let ((pair (if (stringp elt) (split-string elt "[ \t]*,[ \t]*") elt)))
869       (tempo-save-named 'type (car pair))
870       (tempo-save-named 'name (car (cdr pair)))
871       (jde-gen-get-set))))
872
873 ;; (makunbound 'jde-gen-bean-template)
874 (defcustom jde-gen-bean-template
875   '(
876     ;; add class shell
877     ";; generate class and save point which is in body of the constructor"
878     "(jde-gen-class) 'p"
879
880     ;; position point at end of class.
881     "(progn (end-of-buffer) (search-backward \"}\") (backward-char 1)) 'n"
882     "(jde-gen-blank-lines 2 -1)"
883
884     "(jde-gen-save-excursion"
885
886     ;; import Java, per spec, bean stuff
887     " (jde-wiz-generate-interface \"java.io.Serializable\")"
888     " (jde-import-insert-import '(\"java.io.Serializable\"))"
889
890     ;; add getters and setters
891     " (call-interactively 'jde-gen-get-set-methods))"
892     )
893   "*Template for creating a Java bean.
894 Setting this variable defines a template instantiation
895 command `jde-gen-bean', as a side-effect."
896   :group 'jde-gen
897   :type '(repeat string)
898   :set '(lambda (sym val)
899           (defalias 'jde-gen-bean
900             (tempo-define-template
901              "java-bean-template"
902              (jde-gen-read-template val)
903              nil
904              "Create a Java bean."))
905           (set-default sym val)))
906
907 ;;;###autoload
908 (defun jde-gen-bean-buffer (file)
909   "Create a new Java buffer containing a Java bean of the same name.
910 This command inserts the class template generated by `jde-gen-bean'.
911 It then moves the point to the location of the constructor."
912   (interactive "F")
913   (find-file file)
914   (jde-gen-bean))
915
916 (defcustom jde-gen-jfc-app-buffer-template
917   (list
918    "(funcall jde-gen-boilerplate-function)"
919    "(jde-gen-get-package-statement)"
920    "\"import java.awt.Dimension;\" '>'n"
921    "\"import java.awt.Graphics;\" '>'n"
922    "\"import java.awt.Graphics2D;\" '>'n"
923    "\"import java.awt.Color;\" '>'n"
924    "\"import java.awt.geom.Ellipse2D;\" '>'n"
925    "\"import java.awt.event.WindowAdapter;\" '>'n"
926    "\"import java.awt.event.WindowEvent;\" '>'n"
927    "\"import javax.swing.JFrame;\" '>'n"
928    "\"import javax.swing.JPanel;\" '>'n"
929    "\"import javax.swing.JScrollPane;\" '>'n"
930    "\"import javax.swing.JMenuBar;\" '>'n"
931    "\"import javax.swing.JMenu;\" '>'n"
932    "\"import java.awt.event.ActionEvent;\" '>'n"
933    "\"import javax.swing.AbstractAction;\" '>'n '>'n"
934    "(progn (require 'jde-javadoc) (jde-javadoc-insert-start-block))"
935    "\" * \""
936    "(file-name-nondirectory buffer-file-name) '>'n"
937    "\" \" (jde-javadoc-insert-empty-line)"
938    "\" \" (jde-javadoc-insert-empty-line)"
939    "\" * Created: \" (current-time-string) '>'n"
940    "\" \" (jde-javadoc-insert-empty-line)"
941    "\" \" (jde-javadoc-insert 'tempo-template-jde-javadoc-author-tag)"
942    "\" \" (jde-javadoc-insert 'tempo-template-jde-javadoc-version-tag)"
943    "\" \" (jde-javadoc-insert 'tempo-template-jde-javadoc-end-block \"*/\")"
944    "'>'n"
945    "\"public class \""
946    "(file-name-sans-extension (file-name-nondirectory buffer-file-name))"
947    "\" extends JFrame\""
948
949    "(if jde-gen-k&r "
950    "()"
951    "'>'n)"
952    "\"{\"'>'n"
953
954    "\"class Canvas extends JPanel\""
955
956    "(if jde-gen-k&r "
957    "()"
958    "'>'n)"
959    "\"{\"'>'n"
960
961    "(jde-gen-method-signature"
962    "  \"public\""
963    "  \"\""
964    "  \"Canvas\""
965    "  \"\""
966    " )"
967    "'>"
968
969    "(if jde-gen-k&r "
970    " ()"
971    " 'n)"
972    "\"{\"'>'n"
973
974    "\"setSize(getPreferredSize());\" '>'n"
975    "\"Canvas.this.setBackground(Color.white);\" '>'n"
976    "\"}\"'>'n '>'n"
977
978    "(jde-gen-method-signature"
979    "  \"public\""
980    "  \"Dimension\""
981    "  \"getPreferredSize\""
982    "  \"\""
983    " )"
984    "'>"
985
986    "(if jde-gen-k&r "
987    " ()"
988    " 'n)"
989    "\"{\"'>'n"
990
991    "\"return new Dimension(600, 600);\" '>'n"
992    "\"}\"'>'n '>'n"
993
994    "(jde-gen-method-signature"
995    "  \"public\""
996    "  \"void\""
997    "  \"paintComponent\""
998    "  \"Graphics g\""
999    " )"
1000    "'>"
1001
1002    "(if jde-gen-k&r "
1003    " ()"
1004    " 'n)"
1005    "\"{\"'>'n"
1006
1007    "\"super.paintComponent(g);\" '>'n"
1008    "\"Graphics2D g2d = (Graphics2D) g;\" '>'n"
1009    "\"Ellipse2D circle = new Ellipse2D.Double(0d, 0d, 100d, 100d);\" '>'n"
1010    "\"g2d.setColor(Color.red);\" '>'n"
1011    "\"g2d.translate(10, 10);\" '>'n"
1012    "\"g2d.draw(circle);\" '>'n"
1013    "\"g2d.fill(circle);\" '>'n"
1014    "\"}\"'>'n "
1015
1016    "\"}\"'>'n '>'n"
1017
1018
1019    ;; Constructor
1020    "(jde-gen-method-signature"
1021    "  \"public\""
1022    "  \"\""
1023    "  (file-name-sans-extension (file-name-nondirectory buffer-file-name))"
1024    "  \"\""
1025    " )"
1026    "'>"
1027
1028    "(if jde-gen-k&r "
1029    " ()"
1030    " 'n)"
1031    "\"{\"'>'n"
1032
1033
1034    "\"super(\\\"\" (P \"Enter app title: \") \"\\\");\" '>'n"
1035    "\"setSize(300, 300);\" '>'n"
1036    "\"addWindowListener(new WindowAdapter() \""
1037
1038    "(if jde-gen-k&r "
1039    "()"
1040    "'>'n)"
1041    "\"{\"'>'n"
1042
1043
1044    "\"public void windowClosing(WindowEvent e) {System.exit(0);}\" '>'n"
1045    "\"public void windowOpened(WindowEvent e) {}\" '>'n"
1046    "\"});\"'>'n"
1047
1048
1049    "\"setJMenuBar(createMenu());\" '>'n"
1050    "\"getContentPane().add(new JScrollPane(new Canvas()));\" '>'n"
1051    "\"}\"'>'n"
1052    "'>'n"
1053
1054    ;; Main method
1055    "(jde-gen-method-signature"
1056    "   \"public static\""
1057    "   \"void\""
1058    "   \"main\""
1059    "   \"String[] args\""
1060    " )"
1061
1062    "(if jde-gen-k&r "
1063    "()"
1064    "'>'n)"
1065    "\"{\"'>'n"
1066
1067    "'>'n"
1068    "(file-name-sans-extension (file-name-nondirectory buffer-file-name))"
1069    "\" f = new \""
1070    "(file-name-sans-extension (file-name-nondirectory buffer-file-name))"
1071    "\"();\" '>'n"
1072    "\"f.show();\" '>'n"
1073    "\"}\"'>'n '>'n"
1074    ;; createMenu method
1075    "\"protected JMenuBar createMenu() \""
1076
1077
1078    "(if jde-gen-k&r "
1079    "()"
1080    "'>'n)"
1081    "\"{\"'>'n"
1082
1083
1084    "\"JMenuBar mb = new JMenuBar();\" '>'n"
1085    "\"JMenu menu = new JMenu(\\\"File\\\");\" '>'n"
1086    "\"menu.add(new AbstractAction(\\\"Exit\\\") \""
1087
1088    "(if jde-gen-k&r "
1089    "()"
1090    "'>'n)"
1091    "\"{\"'>'n"
1092
1093
1094    "(jde-gen-method-signature"
1095    "  \"public\""
1096    "  \"void\""
1097    "  \"actionPerformed\""
1098    "  \"ActionEvent e\""
1099    " )"
1100    "'>"
1101
1102    "(if jde-gen-k&r "
1103    " ()"
1104    " 'n)"
1105    "\"{\"'>'n"
1106
1107
1108    "\"System.exit(0);\" '>'n"
1109    "\"}\" '>'n"
1110    "\"});\" '>'n"
1111    "\"mb.add(menu);\" '>'n"
1112    "\"return mb;\" '>'n"
1113    "\"}\"'>'n "
1114    "\"} // \"'>"
1115    "(file-name-sans-extension (file-name-nondirectory buffer-file-name))"
1116    "'>'n")
1117   "*Template for JFC (Swing) application buffer.
1118 Setting this variable defines a template instantiation
1119 command `jde-gen-jfc-app', as a side-effect."
1120   :group 'jde-gen
1121   :type '(repeat string)
1122   :set '(lambda (sym val)
1123           (defalias 'jde-gen-jfc-app
1124             (tempo-define-template "java-jfc-app-buffer-template"
1125                                    (jde-gen-read-template val)
1126                                    nil
1127                                    "Insert skeleton for a JFC app buffer"))
1128           (set-default sym val)))
1129
1130 ;;;###autoload
1131 (defun jde-gen-jfc-app-buffer (file)
1132   "Create a new Java buffer containing a JFC application class.
1133 This command inserts the class template generated by `jde-gen-jfc-app'.
1134 It then moves the point to the location to the constructor."
1135   (interactive "F")
1136   (find-file file)
1137   (jde-gen-jfc-app)
1138   (beginning-of-buffer)
1139   (search-forward "{")
1140   (backward-char 1)
1141   (c-indent-exp)
1142   (tempo-forward-mark))
1143
1144
1145 (defcustom jde-gen-buffer-templates
1146   (list (cons "Class" 'jde-gen-class)
1147         (cons "Interface" 'jde-gen-interface)
1148         (cons "Exception Class" 'jde-gen-exception)
1149         (cons "Console" 'jde-gen-console)
1150         (cons "Swing App" 'jde-gen-jfc-app)
1151         (cons "Unit Test" 'jde-junit-test-class))
1152   "*Specifies available autocode templates for creating buffers.
1153 The value of this variable is an association list. The car of
1154 each element specifies the template's title. The cdr specifies
1155 a command that inserts the template into a buffer. See the function
1156 `tempo-define-template' for any easy way to create a template
1157 insertion command."
1158   :group 'jde-gen
1159   :type '(repeat
1160           (cons :tag "Template"
1161                 (string :tag "Title")
1162                 (function :tag "Command")))
1163   :set '(lambda (sym val)
1164           (let ((n (length val))
1165                 (i 0))
1166             (setq jde-gen-buffer-template-names (list))
1167             (while (< i n)
1168               (setq jde-gen-buffer-template-names
1169                     (append
1170                      jde-gen-buffer-template-names
1171                      (list (cons (car (nth i val)) (1+ i)))))
1172               (setq i (1+ i))))
1173           (set-default sym val)))
1174
1175 ;;;###autoload
1176 (defun jde-gen-buffer (template file)
1177   "Create a new Java buffer containing a code template.
1178 This command inserts the specified template at the beginning
1179 of the buffer."
1180   (interactive
1181    (list (completing-read "Template: " jde-gen-buffer-template-names)
1182          (read-file-name "File: ")))
1183   (find-file file)
1184   (funcall (cdr (assoc template jde-gen-buffer-templates)))
1185   (beginning-of-buffer)
1186   (search-forward "{")
1187   (backward-char 1)
1188   (c-indent-exp))
1189
1190
1191 (defun jde-gen-lookup-and-capitalize (val)
1192   "If the given value (val) is the name of saved data, the data is
1193 stripped of its prefix/suffix (see `jde-wiz-get-name') and it is
1194 capitalized.  Otherwise, the given value is stripped and capitalized."
1195   (if (jde-gen-lookup-named val)
1196       (upcase-initials (jde-wiz-get-name (jde-gen-lookup-named val)))
1197     (upcase-initials (jde-wiz-get-name val))))
1198
1199
1200 (defcustom jde-gen-section-comment-template
1201   '(
1202     "(p \"Comment: \" comment-line 'noinsert)"
1203     "'n"
1204     "\"// \" (s comment-line) '>'n'n'>"
1205     )
1206   "*Template for generating a section comment. Used as an introductory
1207 comment to a source code section by code generating functions."
1208   :group 'jde-gen
1209   :type '(repeat string)
1210   :set '(lambda (sym val)
1211           (defalias 'jde-gen-section-comment
1212             (tempo-define-template
1213              "section comment"
1214              (jde-gen-read-template val)
1215              nil
1216              "Insert section comment."))
1217           (set-default sym val)))
1218
1219 (defcustom jde-gen-inner-class-template
1220   '(
1221     "(end-of-line) '& \"class \" (P \"Class name: \" class) '>"
1222     "\" \" (jde-gen-get-extend-class)"
1223
1224     ;;we open the bracket according to k&r style or not
1225     "(if jde-gen-k&r "
1226     " ()"
1227     " '>'n)"
1228     "\"{\" '>'n"
1229
1230     "(jde-gen-method-signature"
1231     "  \"public\""
1232     "  nil"
1233     "  (jde-gen-lookup-named 'class)"
1234     "  nil"
1235     " )"
1236
1237     ;;we open the bracket according to k&r style or not
1238     "(if jde-gen-k&r "
1239     " ()"
1240     " '>'n)"
1241     "\"{\"'>'n"
1242     "\"}\"'>'n"
1243
1244     "'>'n"
1245     "(jde-gen-get-interface-implementation)"
1246     "'>'n"
1247
1248     "\"}\" '>'n'>"
1249     )
1250   "*Template that creates an empty private class at point."
1251   :group 'jde-gen
1252   :type '(repeat string)
1253   :set '(lambda (sym val)
1254           (tempo-define-template "java-inner-class"
1255                                  (jde-gen-read-template val)
1256                                  nil
1257                                  "Insert inner class.")
1258           (defalias 'jde-gen-inner-class-internal
1259             (list 'lambda (list)
1260                   (list 'tempo-template-java-inner-class)
1261                   (list 'jde-gen-insert-interface-implementation)))
1262           (set-default sym val)))
1263
1264 (defun jde-gen-inner-class ()
1265   (interactive)
1266   (jde-gen-inner-class-internal)
1267   (goto-char (scan-lists (point) -1 0))
1268   (c-indent-exp))
1269
1270 (defcustom jde-gen-action-listener-template
1271   '(
1272     "'& (P \"Component name: \")"
1273     "\".addActionListener(\" jde-gen-method-signature-padding-2 "
1274     "\"new ActionListener\" jde-gen-method-signature-padding-1 \"()\" '>"
1275
1276     ;;we open the bracket according to k&r style or not
1277     "(if jde-gen-k&r "
1278     " jde-gen-method-signature-padding-3"
1279     " 'n)"
1280
1281     "\"{\"'>'n"
1282
1283     "(jde-gen-method-signature"
1284     "  \"public\""
1285     "  \"void\""
1286     "  \"actionPerformed\""
1287     "  \"ActionEvent e\""
1288     " )"
1289     "'>"
1290
1291     ;;we open the bracket according to k&r style or not
1292     "(if jde-gen-k&r "
1293     " ()"
1294     " 'n)"
1295     "\"{\"'>'n"
1296     "\"}\"'>'n"
1297
1298     "\"}\" jde-gen-method-signature-padding-2 \");\"'>'n'>'n'>"
1299     )
1300   "*Template for generating an action listener.
1301 Setting this variable defines a template instantiation
1302 command, `jde-gen-action-listener', as a side-effect."
1303   :group 'jde-gen
1304   :type '(repeat string)
1305   :set '(lambda (sym val)
1306           (defalias 'jde-gen-action-listener
1307             (tempo-define-template
1308              "java-action-listener"
1309              (jde-gen-read-template val)
1310              nil
1311              "Insert skeleton action listener."))
1312           (set-default sym val)))
1313
1314 (defcustom jde-gen-window-listener-template
1315   '(
1316     "(end-of-line) '& (P \"Window name: \")"
1317     "\".addWindowListener(\" jde-gen-method-signature-padding-2 "
1318     "\"new WindowAdapter\" jde-gen-method-signature-padding-1 \"()\"'>"
1319
1320     ;;we open the bracket according to k&r style or not
1321     "(if jde-gen-k&r "
1322     " jde-gen-method-signature-padding-3"
1323     " 'n)"
1324     "\"{\"'>'n"
1325
1326     "(jde-gen-method-signature"
1327     "  \"public\""
1328     "  \"void\""
1329     "  \"windowActivated\""
1330     "  \"WindowEvent e\""
1331     " )"
1332     "'>"
1333
1334     ;;we open the bracket according to k&r style or not
1335     "(if jde-gen-k&r "
1336     " ()"
1337     " 'n)"
1338     "\"{\"'>'n"
1339     "\"}\"'>'n"
1340
1341     "(jde-gen-method-signature"
1342     "  \"public\""
1343     "  \"void\""
1344     "  \"windowClosed\""
1345     "  \"WindowEvent e\""
1346     " )"
1347     "'>"
1348
1349     ;;we open the bracket according to k&r style or not
1350     "(if jde-gen-k&r "
1351     " ()"
1352     " 'n)"
1353     "\"{\"'>'n"
1354     "\"}\"'>'n"
1355
1356     "(jde-gen-method-signature"
1357     "  \"public\""
1358     "  \"void\""
1359     "  \"windowClosing\""
1360     "  \"WindowEvent e\""
1361     " )"
1362     "'>"
1363
1364     ;;we open the bracket according to k&r style or not
1365     "(if jde-gen-k&r "
1366     " ()"
1367     " 'n)"
1368     "\"{\"'>'n"
1369     " \"System.exit(0);\" '>'n \"}\""
1370     "'>'n"
1371
1372     "(jde-gen-method-signature"
1373     "  \"public\""
1374     "  \"void\""
1375     "  \"windowDeactivated\""
1376     "  \"WindowEvent e\""
1377     " )"
1378     "'>"
1379
1380     ;;we open the bracket according to k&r style or not
1381     "(if jde-gen-k&r "
1382     " ()"
1383     " 'n)"
1384     "\"{\"'>'n"
1385     "\"}\"'>'n"
1386
1387     "(jde-gen-method-signature"
1388     "  \"public\""
1389     "  \"void\""
1390     "  \"windowDeiconified\""
1391     "  \"WindowEvent e\""
1392     " )"
1393     "'>"
1394
1395     ;;we open the bracket according to k&r style or not
1396     "(if jde-gen-k&r "
1397     " ()"
1398     " 'n)"
1399     "\"{\"'>'n"
1400     "\"}\"'>'n"
1401
1402     "(jde-gen-method-signature"
1403     "  \"public\""
1404     "  \"void\""
1405     "  \"windowIconified\""
1406     "  \"WindowEvent e\""
1407     " )"
1408     "'>"
1409
1410     ;;we open the bracket according to k&r style or not
1411     "(if jde-gen-k&r "
1412     " ()"
1413     " 'n)"
1414     "\"{\"'>'n"
1415     "\"}\"'>'n"
1416
1417     "(jde-gen-method-signature"
1418     "  \"public\""
1419     "  \"void\""
1420     "  \"windowOpened\""
1421     "  \"WindowEvent e\""
1422     " )"
1423     "'>"
1424
1425     ;;we open the bracket according to k&r style or not
1426     "(if jde-gen-k&r "
1427     " ()"
1428     " 'n)"
1429     "\"{\"'>'n"
1430     "\"}\"'>'n"
1431
1432     "\"}\" jde-gen-method-signature-padding-2 \");\" '>'n'>"
1433     )
1434   "*Template for generating a window listener.
1435 Setting this variable defines a template instantiation
1436 command, `jde-gen-window-listener', as a side-effect."
1437   :group 'jde-gen
1438   :type '(repeat string)
1439   :set '(lambda (sym val)
1440           (defalias 'jde-gen-window-listener
1441             (tempo-define-template
1442              "java-window-listener"
1443              (jde-gen-read-template val)
1444              nil
1445              "Insert skeleton window listener."))
1446           (set-default sym val)))
1447
1448
1449
1450 (defcustom jde-gen-mouse-listener-template
1451   '(
1452     "(end-of-line) '& (P \"Component name: \")"
1453     "\".addMouseListener(\" jde-gen-method-signature-padding-2 "
1454     "\"new MouseAdapter\" jde-gen-method-signature-padding-1 \"()\" '>"
1455
1456     ;;we open the bracket according to k&r style or not
1457     "(if jde-gen-k&r "
1458     " jde-gen-method-signature-padding-3"
1459     " 'n)"
1460     "\"{\"'>'n "
1461
1462     "(jde-gen-method-signature"
1463     "  \"public\""
1464     "  \"void\""
1465     "  \"mouseClicked\""
1466     "  \"MouseEvent e\""
1467     " )"
1468     "'>"
1469
1470     ;;we open the bracket according to k&r style or not
1471     "(if jde-gen-k&r "
1472     " ()"
1473     " 'n)"
1474     "\"{\"'>'n"
1475     "\"}\"'>'n"
1476
1477     "(jde-gen-method-signature"
1478     "  \"public\""
1479     "  \"void\""
1480     "  \"mouseEntered\""
1481     "  \"MouseEvent e\""
1482     " )"
1483     "'>"
1484
1485     ;;we open the bracket according to k&r style or not
1486     "(if jde-gen-k&r "
1487     " ()"
1488     " 'n)"
1489     "\"{\"'>'n"
1490     "\"}\"'>'n"
1491
1492     "(jde-gen-method-signature"
1493     "  \"public\""
1494     "  \"void\""
1495     "  \"mouseExited\""
1496     "  \"MouseEvent e\""
1497     " )"
1498     "'>"
1499
1500     ;;we open the bracket according to k&r style or not
1501     "(if jde-gen-k&r "
1502     " ()"
1503     " 'n)"
1504     "\"{\"'>'n"
1505     "\"}\"'>'n"
1506
1507     "(jde-gen-method-signature"
1508     "  \"public\""
1509     "  \"void\""
1510     "  \"mousePressed\""
1511     "  \"MouseEvent e\""
1512     " )"
1513     "'>"
1514
1515     ;;we open the bracket according to k&r style or not
1516     "(if jde-gen-k&r "
1517     " ()"
1518     " 'n)"
1519     "\"{\"'>'n"
1520     "\"}\"'>'n"
1521
1522     "(jde-gen-method-signature"
1523     "  \"public\""
1524     "  \"void\""
1525     "  \"mouseReleased\""
1526     "  \"MouseEvent e\""
1527     " )"
1528     "'>"
1529
1530     ;;we open the bracket according to k&r style or not
1531     "(if jde-gen-k&r "
1532     " ()"
1533     " 'n)"
1534     "\"{\"'>'n"
1535     "\"}\"'>'n"
1536
1537     "\"}\" jde-gen-method-signature-padding-2 \");\"'>'n'>"
1538     )
1539   "*Template for generating a mouse listener.
1540 Setting this variable defines a template instantiation
1541 command, `jde-gen-mouse-listener', as a side-effect."
1542   :group 'jde-gen
1543   :type '(repeat string)
1544   :set '(lambda (sym val)
1545           (defalias 'jde-gen-mouse-listener
1546             (tempo-define-template
1547              "java-mouse-listener"
1548              (jde-gen-read-template val)
1549              nil
1550              "Insert skeleton mouse listener."))
1551           (set-default sym val)))
1552
1553 (defcustom jde-gen-mouse-motion-listener-template
1554   '(
1555     "(end-of-line) '& (P \"Component name: \")"
1556     "\".addMouseMotionListener(\" jde-gen-method-signature-padding-2 "
1557     "\"new MouseMotionAdapter\" jde-gen-method-signature-padding-1 \"()\" '>"
1558
1559     ;;we open the bracket according to k&r style or not
1560     "(if jde-gen-k&r "
1561     " jde-gen-method-signature-padding-3"
1562     " 'n)"
1563     "\"{\"'>'n"
1564
1565     "(jde-gen-method-signature"
1566     "  \"public\""
1567     "  \"void\""
1568     "  \"mouseDragged\""
1569     "  \"MouseEvent e\""
1570     " )"
1571     "'>"
1572
1573     ;;we open the bracket according to k&r style or not
1574     "(if jde-gen-k&r "
1575     " ()"
1576     " 'n)"
1577     "\"{\"'>'n"
1578     "\"}\"'>'n"
1579
1580     "(jde-gen-method-signature"
1581     "  \"public\""
1582     "  \"void\""
1583     "  \"mouseMoved\""
1584     "  \"MouseEvent e\""
1585     " )"
1586     "'>"
1587
1588     ;;we open the bracket according to k&r style or not
1589     "(if jde-gen-k&r "
1590     " ()"
1591     " 'n)"
1592     "\"{\"'>'n"
1593     "\"}\"'>'n"
1594
1595     "\"}\" jde-gen-method-signature-padding-2 \");\"'>'n'>"
1596     )
1597   "*Template for generating a mouse listener.
1598 Setting this variable defines a template instantiation
1599 command, `jde-gen-mouse-motion-listener', as a side-effect."
1600   :group 'jde-gen
1601   :type '(repeat string)
1602   :set '(lambda (sym val)
1603           (defalias 'jde-gen-mouse-motion-listener
1604             (tempo-define-template
1605              "java-mouse-motion-listener"
1606              (jde-gen-read-template val)
1607              nil
1608              "Insert skeleton mouse motion listener."))
1609           (set-default sym val)))
1610
1611 (defcustom jde-gen-change-listener-template
1612   '(
1613     "'& (P \"Component name: \")"
1614     "\".addChangeListener(\" jde-gen-method-signature-padding-2 "
1615     "\"new ChangeListener\" jde-gen-method-signature-padding-1 \"()\" '>"
1616
1617     ;;we open the bracket according to k&r style or not
1618     "(if jde-gen-k&r "
1619     " jde-gen-method-signature-padding-3"
1620     " 'n)"
1621
1622     "\"{\"'>'n"
1623
1624     "(jde-gen-method-signature"
1625     "  \"public\""
1626     "  \"void\""
1627     "  \"stateChanged\""
1628     "  \"ChangeEvent e\""
1629     " )"
1630     "'>"
1631
1632     ;;we open the bracket according to k&r style or not
1633     "(if jde-gen-k&r "
1634     " ()"
1635     " 'n)"
1636     "\"{\"'>'n"
1637     "\"}\"'>'n"
1638
1639     "\"}\" jde-gen-method-signature-padding-2 \");\"'>'n'>'n'>"
1640     )
1641   "*Template for generating a change listener.
1642 Setting this variable defines a template instantiation
1643 command, `jde-gen-change-listener', as a side-effect."
1644   :group 'jde-gen
1645   :type '(repeat string)
1646   :set '(lambda (sym val)
1647           (defalias 'jde-gen-change-listener
1648             (tempo-define-template
1649              "java-change-listener"
1650              (jde-gen-read-template val)
1651              nil
1652              "Insert skeleton change listener."))
1653           (set-default sym val)))
1654
1655 (defcustom jde-gen-main-method-template
1656   '(
1657     "(jde-gen-save-excursion"
1658     " (jde-wiz-gen-method"
1659     "   \"public static\""
1660     "   \"void\""
1661     "   \"main\""
1662     "   \"String[] args\""
1663     "   \"\" \"\"))"
1664     ";; don't move point"
1665     "(setq tempo-marks nil)"
1666     )
1667   "Template for generating the main method.
1668 Setting this variable defines a template instantiation
1669 command, `jde-gen-main-method', as a side-effect."
1670   :group 'jde-gen
1671   :type '(repeat string)
1672   :set '(lambda (sym val)
1673           (defalias 'jde-gen-main-method
1674             (tempo-define-template
1675              "main-method"
1676              (jde-gen-read-template val)
1677              nil
1678              "Insert skeleton main method."))
1679           (set-default sym val)))
1680
1681
1682 (defcustom  jde-gen-println
1683   '(
1684     "(end-of-line) '&"
1685     "\"System.out.println(\" (P \"Print out: \") \");\" '>'n'>"
1686     )
1687   "*Template for generating a System.out.println statement."
1688   :group 'jde-gen
1689   :type '(repeat string)
1690   :set '(lambda (sym val)
1691           (defalias 'jde-gen-println
1692             (tempo-define-template
1693              "println"
1694              (jde-gen-read-template val)
1695              nil
1696              "Insert println statement."))
1697           (set-default sym val)))
1698
1699 (defcustom  jde-gen-beep
1700   '(
1701     "(end-of-line) '&"
1702     "\"Toolkit.getDefaultToolkit().beep();\"'>'n'>"
1703     )
1704   "*Template for generating a Toolkit.getDefaultToolkit().beep() statement."
1705   :group 'jde-gen
1706   :type '(repeat string)
1707   :set '(lambda (sym val)
1708           (defalias 'jde-gen-beep
1709             (tempo-define-template
1710              "beep statement"
1711              (jde-gen-read-template val)
1712              nil
1713              "Insert beep statement."))
1714           (set-default sym val)))
1715
1716 (defcustom  jde-gen-property-change-support
1717   '(
1718     "(end-of-line) '&"
1719
1720     "\"protected PropertyChangeSupport pcs =  new PropertyChangeSupport(this);\" '>'n '>'n"
1721
1722
1723     "\"/**\" '>'n"
1724     "\"* Adds a PropertyChangeListener to the listener list.\" '>'n"
1725     "\"* The listener is registered for all properties.\" '>'n"
1726     "\"*\" '>'n"
1727     "\"* @param listener The PropertyChangeListener to be added\" '>'n"
1728     "\"*/\" '>'n"
1729
1730     "(jde-gen-method-signature"
1731     "  \"public\""
1732     "  \"void\""
1733     "  \"addPropertyChangeListener\""
1734     "  \"PropertyChangeListener listener\""
1735     " )"
1736     "'>"
1737
1738     ;;we open the bracket according to k&r style or not
1739     "(if jde-gen-k&r "
1740     " ()"
1741     " 'n)"
1742     "\"{\"'>'n"
1743
1744     "\"pcs.addPropertyChangeListener(listener);\" '>'n \"}\" '>'n '>'n"
1745
1746     "\"/**\" '>'n"
1747     "\"* Removes a PropertyChangeListener from the listener list.\" '>'n"
1748     "\"* This removes a PropertyChangeListener that was registered\" '>'n"
1749     "\"* for all properties.\" '>'n"
1750     "\"*\" '>'n "
1751     "\"* @param listener The PropertyChangeListener to be removed\" '>'n"
1752     "\"*/\" '>'n"
1753
1754     "(jde-gen-method-signature"
1755     "  \"public\""
1756     "  \"void\""
1757     "  \"removePropertyChangeListener\""
1758     "  \"PropertyChangeListener listener\""
1759     " )"
1760     "'>"
1761
1762     ;;we open the bracket according to k&r style or not
1763     "(if jde-gen-k&r "
1764     " ()"
1765     " 'n)"
1766     "\"{\"'>'n"
1767
1768     "'>\"pcs.removePropertyChangeListener(listener);\" '>'n \"}\" '>'n '>'n"
1769
1770     "\"/**\" '>'n"
1771     "\"* Adds a PropertyChangeListener for a specific property.\" '>'n"
1772     "\"* The listener will be invoked only when a call on firePropertyChange\" '>'n"
1773     "\"* names that specific property.\" '>'n"
1774     "\"*\" '>'n"
1775     "\"* @param propertyName The name of the property to listen on\" '>'n"
1776     "\"* @param listener The PropertyChangeListener to be added\" '>'n"
1777     "\"*/\" '>'n"
1778
1779     "(jde-gen-method-signature"
1780     "  \"public\""
1781     "  \"void\""
1782     "  \"addPropertyChangeListener\""
1783     "  \"String propertyName, PropertyChangeListener listener\""
1784     " )"
1785     "'>"
1786
1787     ;;we open the bracket according to k&r style or not
1788     "(if jde-gen-k&r "
1789     " ()"
1790     " 'n)"
1791     "\"{\"'>'n"
1792
1793     "'> \"pcs.addPropertyChangeListener(propertyName, listener);\" '>'n"
1794     "\"}\" '>'n '>'n"
1795
1796     "\"/**\" '>'n"
1797     "\"* Removes a PropertyChangeListener for a specific property.\" '>'n"
1798     "\"*\" '>'n"
1799     "\"* @param propertyName The name of the property that was listened on\" '>'n"
1800     "\"* @param listener The PropertyChangeListener to be removed\"'>'n"
1801     "\"*/\" '>'n"
1802
1803     "(jde-gen-method-signature"
1804     "  \"public\""
1805     "  \"void\""
1806     "  \"removePropertyChangeListener\""
1807     "  \"String propertyName, PropertyChangeListener listener\""
1808     " )"
1809     "'>"
1810
1811     ;;we open the bracket according to k&r style or not
1812     "(if jde-gen-k&r "
1813     " ()"
1814     " 'n)"
1815     "\"{\"'>'n"
1816
1817     "'> \"pcs.removePropertyChangeListener(propertyName, listener);\" '>'n"
1818     "\"}\" '>'n '>'n"
1819
1820     "\"/**\" '>'n"
1821     "\"* Reports a bound property update to any registered listeners. \" '>'n"
1822     "\"* No event is fired if old and new are equal and non-null.\" '>'n"
1823     "\"*\" '>'n"
1824     "\"* @param propertyName The programmatic name of the property\" '>'n"
1825     "\"*                     that was changed\" '>'n"
1826     "\"* @param oldValue The old value of the property\" '>'n"
1827     "\"* @param newValue The new value of the property.\" '>'n \"*/\" '>'n"
1828
1829     "(jde-gen-method-signature"
1830     "  \"public\""
1831     "  \"void\""
1832     "  \"firePropertyChange\""
1833     "  \"String propertyName, Object oldValue, Object newValue\""
1834     " )"
1835     "'>"
1836
1837     ;;we open the bracket according to k&r style or not
1838     "(if jde-gen-k&r "
1839     " ()"
1840     " 'n)"
1841     "\"{\"'>'n"
1842
1843     "'> \"pcs.firePropertyChange(propertyName, oldValue, newValue);\" '>'n"
1844     "\"}\" '>'n '>'n"
1845
1846     "\"/**\" '>'n"
1847     "\"* Reports a bound property update to any registered listeners. \" '>'n"
1848     "\"* No event is fired if old and new are equal and non-null.\" '>'n"
1849     "\"* This is merely a convenience wrapper around the more general\" '>'n"
1850     "\"* firePropertyChange method that takes Object values.\" '>'n"
1851     "\"* No event is fired if old and new are equal and non-null.\" '>'n"
1852     "\"*\" '>'n"
1853     "\"* @param propertyName The programmatic name of the property\" '>'n"
1854     "\"*                     that was changed\" '>'n"
1855     "\"* @param oldValue The old value of the property\" '>'n"
1856     "\"* @param newValue The new value of the property.\" '>'n \"*/\" '>'n"
1857
1858     "(jde-gen-method-signature"
1859     "  \"public\""
1860     "  \"void\""
1861     "  \"firePropertyChange\""
1862     "  \"String propertyName, int oldValue, int newValue\""
1863     " )"
1864     "'>"
1865
1866     ;;we open the bracket according to k&r style or not
1867     "(if jde-gen-k&r "
1868     " ()"
1869     " 'n)"
1870     "\"{\"'>'n"
1871
1872     "'> \"pcs.firePropertyChange(propertyName, oldValue, newValue);\" '>'n"
1873     "\"}\" '>'n '>'n"
1874
1875     "\"/**\" '>'n"
1876     "\"* Reports a bound property update to any registered listeners. \" '>'n"
1877     "\"* No event is fired if old and new are equal and non-null.\" '>'n"
1878     "\"* This is merely a convenience wrapper around the more general\" '>'n"
1879     "\"* firePropertyChange method that takes Object values.\" '>'n"
1880     "\"* No event is fired if old and new are equal and non-null.\" '>'n"
1881     "\"*\" '>'n"
1882     "\"* @param propertyName The programmatic name of the property\" '>'n"
1883     "\"*                     that was changed\" '>'n"
1884     "\"* @param oldValue The old value of the property\" '>'n"
1885     "\"* @param newValue The new value of the property.\" '>'n \"*/\" '>'n"
1886
1887     "(jde-gen-method-signature"
1888     "  \"public\""
1889     "  \"void\""
1890     "  \"firePropertyChange\""
1891     "  \"String propertyName, boolean oldValue, boolean newValue\""
1892     " )"
1893     "'>"
1894
1895     ;;we open the bracket according to k&r style or not
1896     "(if jde-gen-k&r "
1897     " ()"
1898     " 'n)"
1899     "\"{\"'>'n"
1900
1901     "'> \"pcs.firePropertyChange(propertyName, oldValue, newValue);\" '>'n"
1902     "\"}\" '>'n '>'n"
1903
1904     "\"/**\" '>'n"
1905     "\"* Fires an existing PropertyChangeEvent to any registered listeners.\" '>'n"
1906     "\"* No event is fired if the given event's old and new values are\"'>'n"
1907     "\"* equal and non-null. \" '>'n"
1908     "\"*\" '>'n"
1909     "\"* @param evt The PropertyChangeEvent object.\" '>'n\"*/\" '>'n"
1910
1911     "(jde-gen-method-signature"
1912     "  \"public\""
1913     "  \"void\""
1914     "  \"firePropertyChange\""
1915     "  \"PropertyChangeEvent evt\""
1916     " )"
1917     "'>"
1918
1919     ;;we open the bracket according to k&r style or not
1920     "(if jde-gen-k&r "
1921     " ()"
1922     " 'n)"
1923     "\"{\"'>'n"
1924
1925     "'> \"pcs.firePropertyChange(evt);\" '>'n \"}\" '>'n '>'n"
1926
1927     "\"/**\" '>'n"
1928     "\"* Checks if there are any listeners for a specific property.\" '>'n"
1929     "\"*\" '>'n"
1930     "\"* @param evt The PropertyChangeEvent object.\" '>'n"
1931     "\"* @return <code>true</code>if there are one or more listeners\"'>'n"
1932     "\"*             for the given property\" '>'n"
1933     "\"*/\" '>'n"
1934
1935     "(jde-gen-method-signature"
1936     "  \"public\""
1937     "  \"boolean\""
1938     "  \"hasListeners\""
1939     "  \"String propertyName\""
1940     " )"
1941     "'>"
1942
1943     ;;we open the bracket according to k&r style or not
1944     "(if jde-gen-k&r "
1945     " ()"
1946     " 'n)"
1947     "\"{\"'>'n"
1948
1949     "'> \"return pcs.hasListeners(propertyName);\" '>'n \"}\" '>'n '>'n'>"
1950     )
1951   "*Template for adding property change support to a class."
1952   :group 'jde-gen
1953   :type '(repeat string)
1954   :set '(lambda (sym val)
1955           (defalias 'jde-gen-property-change-support
1956             (tempo-define-template
1957              "property change support template"
1958              (jde-gen-read-template val)
1959              nil
1960              "Insert property change support template."))
1961           (set-default sym val)))
1962
1963 (defcustom  jde-gen-listener-registry
1964   '(
1965     "(p \"Listener class (fully qualified): \" listenerFQN 'noinsert)"
1966     "(tempo-save-named 'listener-class "
1967     " (replace-in-string (tempo-lookup-named 'listenerFQN)"
1968     "                    \"[^\\\\.]+\\\\.\" \"\"))"
1969     "(tempo-save-named 'listener-vector "
1970     " (concat (jde-wiz-downcase-initials (tempo-lookup-named 'listener-class))"
1971     "         \"s\"))"
1972
1973     "(end-of-line) '&"
1974     "\"protected Vector \" (s listener-vector) \" = new Vector();\" '>'n '>'n"
1975
1976     "\"/**\" '>'n"
1977     "\"* The method <CODE>add\" (s listener-class)"
1978     "\"</CODE> allows to \" '>'n"
1979     "\"* add a new <CODE>\" (s listener-class) \"</CODE>\" '>'n"
1980     "\"* that will be notified of incoming events.\" '>'n"
1981     "\"*\" '>'n"
1982     "\"* @see \" (s listenerFQN) '>'n"
1983     "\"*/\" '>'n"
1984
1985     "(jde-gen-method-signature"
1986     "  \"public\""
1987     "  \"void\""
1988     "  (concat \"add\" (tempo-lookup-named 'listener-class))"
1989     "  (concat (tempo-lookup-named 'listener-class) \" l\")"
1990     " )"
1991     "'>"
1992
1993     ;;we open the bracket according to k&r style or not
1994     "(if jde-gen-k&r "
1995     " ()"
1996     " 'n)"
1997     "\"{\"'>'n"
1998
1999     "(s listener-vector) \".addElement(l);\" '> 'n"
2000
2001     "\"}\" '>'n '>'n"
2002
2003     "\"/**\" '>'n"
2004     "\"* The method <CODE>remove\" (s listener-class)"
2005     "\"</CODE> allows to \" '>'n"
2006     "\"* remove a <CODE>\" (s listener-class) \"</CODE> that was\" '>'n"
2007     "\"* previously registered to be notified of incoming events.\" '>'n"
2008     "\"*\" '>'n"
2009     "\"* @see \" (s listenerFQN) '>'n"
2010     "\"*/\" '>'n"
2011
2012     "(jde-gen-method-signature"
2013     "  \"public\""
2014     "  \"void\""
2015     "  (concat \"remove\" (tempo-lookup-named 'listener-class))"
2016     "  (concat (tempo-lookup-named 'listener-class) \" l\")"
2017     " )"
2018     "'>"
2019
2020     ;;we open the bracket according to k&r style or not
2021     "(if jde-gen-k&r "
2022     " ()"
2023     " 'n)"
2024     "\"{\"'>'n"
2025
2026     "(s listener-vector) \".removeElement(l);\" '> 'n"
2027
2028     "\"}\" '>'n '>'n"
2029     )
2030   "*Template for adding a registry for a class of listeners."
2031   :group 'jde-gen
2032   :type '(repeat string)
2033   :set '(lambda (sym val)
2034           (defalias 'jde-gen-listener-registry
2035             (tempo-define-template
2036              "listener registry template"
2037              (jde-gen-read-template val)
2038              nil
2039              "Insert listener registry template."))
2040           (set-default sym val)))
2041
2042 (defcustom  jde-gen-event-source-fire-method-template
2043   '(
2044     "(p \"Listener class (fully qualified): \" listenerFQN 'noinsert)"
2045     "(p \"Listener method name: \" method-name 'noinsert)"
2046     "(p \"Method name: \" return-type 'noinsert)"
2047     "(p \"Method name: \" params 'noinsert)"
2048     "(tempo-save-named 'listener-class "
2049     " (replace-in-string (tempo-lookup-named 'listenerFQN)"
2050     "                    \"[^\\\\.]+\\\\.\" \"\"))"
2051     "(tempo-save-named 'listener-vector "
2052     " (concat (jde-wiz-downcase-initials (tempo-lookup-named 'listener-class))"
2053     "         \"s\"))"
2054     "(tempo-save-named 'fire-method "
2055     " (concat \"fire\" (upcase-initials (tempo-lookup-named 'method-name))))"
2056     "(tempo-save-named 'param-ids "
2057     " (jde-gen-extract-ids-from-params (tempo-lookup-named 'params)))"
2058
2059     "(end-of-line) '&"
2060     "\"/**\" '>'n"
2061     "\"* The method <CODE>\" (s fire-method)"
2062     "\"</CODE> is used \" '>'n"
2063     "\"* to call the <CODE>\" (s method-name) \"</CODE> method of\" '>'n"
2064     "\"* every previously registered <CODE>\" (s listener-class) \"</CODE>.\" '>'n"
2065     "\"*\" '>'n"
2066     "\"* @see \" (s listenerFQN) '>'n"
2067     "\"*/\" '>'n"
2068
2069     "(jde-gen-method-signature"
2070     "  \"public\""
2071     "  (tempo-lookup-named 'return-type)"
2072     "  (tempo-lookup-named 'fire-method)"
2073     "  (tempo-lookup-named 'params)"
2074     " )"
2075     "'>"
2076
2077     ;;we open the bracket according to k&r style or not
2078     "(if jde-gen-k&r "
2079     " ()"
2080     " 'n)"
2081     "\"{\"'>'n"
2082
2083     " \"for(int i = 0; i < \" (s listener-vector) \".size(); i++)\" '>"
2084     ;;we open the bracket according to k&r style or not
2085     "(if jde-gen-k&r "
2086     " ()"
2087     " 'n)"
2088     "\"{\"'>'n"
2089     "\"((\" (s listener-class) \")\" (s listener-vector)"
2090     "\".elementAt (i)).\" (s method-name) \" (\" (s param-ids) \");\" '> 'n"
2091     "\"}\" '>'n"
2092
2093     "\"}\" '>'n '>'n"
2094     )
2095   "*Template for adding a registry for a class of listeners."
2096   :group 'jde-gen
2097   :type '(repeat string)
2098   :set '(lambda (sym val)
2099           (defalias 'jde-gen-event-source-fire-method
2100             (tempo-define-template
2101              "event source fire method template"
2102              (jde-gen-read-template val)
2103              nil
2104              "Insert event source fire method template."))
2105           (set-default sym val)))
2106
2107 ;; (makunbound 'jde-gen-enity-bean-template)
2108 (defcustom jde-gen-entity-bean-template
2109   '(
2110     "(jde-import-insert-imports-into-buffer "
2111     "  (list \"javax.ejb.*\""
2112     "        \"java.rmi.RemoteException\"))"
2113     "'>"
2114
2115     "(jde-gen-method-signature"
2116     "   \"public\""
2117     "  \"void\""
2118     "  \"ejbActivate\""
2119     "  nil"
2120     "  \"RemoteException\""
2121     " )"
2122     "'>"
2123
2124     ;;we open the bracket according to k&r style or not
2125     "(if jde-gen-k&r "
2126     " ()"
2127     " 'n)"
2128     "\"{\"'>'n"
2129     "\"}\"'>'n 'n"
2130
2131     "'>"
2132     "(jde-gen-method-signature"
2133     "  \"public\""
2134     "  \"void\""
2135     "  \"ejbPassivate\""
2136     "  nil"
2137     "  \"RemoteException\""
2138     " )"
2139
2140     "(if jde-gen-k&r "
2141     " ()"
2142     " 'n)"
2143     "\"{\"'>'n"
2144     "\"}\"'>'n 'n"
2145
2146     "'>"
2147     "(jde-gen-method-signature"
2148     "  \"public\""
2149     "  \"void\""
2150     "  \"ejbLoad\""
2151     "  nil"
2152     "  \"RemoteException\""
2153     " )"
2154
2155     "(if jde-gen-k&r "
2156     " ()"
2157     " 'n)"
2158     "\"{\"'>'n"
2159     "\"}\"'>'n 'n"
2160
2161     "'>"
2162     "(jde-gen-method-signature"
2163     "  \"public\""
2164     "  \"void\""
2165     "  \"ejbStore\""
2166     "  nil"
2167     "  \"RemoteException\""
2168     " )"
2169
2170     "(if jde-gen-k&r "
2171     " ()"
2172     " 'n)"
2173     "\"{\"'>'n"
2174     "\"}\"'>'n 'n"
2175
2176     "'>"
2177     "(jde-gen-method-signature"
2178     "  \"public\""
2179     "  \"void\""
2180     "  \"ejbRemove\""
2181     "  nil"
2182     "  \"RemoteException\""
2183     " )"
2184
2185     "(if jde-gen-k&r "
2186     " ()"
2187     " 'n)"
2188     "\"{\"'>'n"
2189     "\"}\"'>'n 'n"
2190
2191     "'>"
2192     "(jde-gen-method-signature"
2193     "  \"public\""
2194     "  \"void\""
2195     "  \"setEntityContext\""
2196     "  \"EntityContext ctx\""
2197     "  \"RemoteException\""
2198     " )"
2199
2200     "(if jde-gen-k&r "
2201     " ()"
2202     " 'n)"
2203     "\"{\"'>'n"
2204     "\"}\"'>'n 'n"
2205
2206     "'>"
2207     "(jde-gen-method-signature"
2208     "  \"public\""
2209     "  \"void\""
2210     "  \"unsetEntityContext\""
2211     "  nil"
2212     "  \"RemoteException\""
2213     " )"
2214
2215     "(if jde-gen-k&r "
2216     " ()"
2217     " 'n)"
2218     "\"{\"'>'n"
2219     "\"}\"'>'n 'n '>"
2220     )
2221   "*Template that creates an empty implementation of an EJB Entity Bean."
2222   :group 'jde-gen
2223   :type '(repeat string)
2224   :set '(lambda (sym val)
2225           (defalias 'jde-gen-entity-bean
2226             (tempo-define-template
2227              "ejb-entity-bean"
2228              (jde-gen-read-template val)
2229              nil
2230              "Adds an implementation of the EJB Entity Bean interface to the 
2231 class in the current buffer at the current point in the buffer. Before invoking
2232 this command,  position point at the point in the buffer where you want the first 
2233 Entity Bean method to appear. Use `jde-ejb-entity-bean-buffer' to create a complete
2234 skeleton entity bean implementation from scratch."))
2235           (set-default sym val)))
2236
2237
2238 ;; (makunbound 'jde-gen-session-bean-template)
2239 (defcustom jde-gen-session-bean-template
2240   '(
2241     "(jde-import-insert-imports-into-buffer "
2242     "  (list \"javax.ejb.*\""
2243     "        \"java.rmi.RemoteException\"))"
2244     "'>"
2245
2246     "(jde-wiz-update-implements-clause \"SessionBean\")"
2247     "'>"
2248
2249     "(jde-gen-method-signature"
2250     "  \"public\""
2251     "  \"void\""
2252     "  \"ejbActivate\""
2253     "  nil"
2254     "  \"RemoteException\""
2255     " )"
2256     "'>"
2257
2258     ;;we open the bracket according to k&r style or not
2259     "(if jde-gen-k&r "
2260     " ()"
2261     " 'n)"
2262     "\"{\"'>'n"
2263     "\"}\"'>'n 'n"
2264
2265     "(jde-gen-method-signature"
2266     "  \"public\""
2267     "  \"void\""
2268     "  \"ejbPassivate\""
2269     "  nil"
2270     "  \"RemoteException\""
2271     " )"
2272     "'>"
2273
2274     ;;we open the bracket according to k&r style or not
2275     "(if jde-gen-k&r "
2276     " ()"
2277     " 'n)"
2278     "\"{\"'>'n"
2279     "\"}\"'>'n 'n"
2280
2281     "(jde-gen-method-signature"
2282     "  \"public\""
2283     "  \"void\""
2284     "  \"ejbRemove\""
2285     "  nil"
2286     "  \"RemoteException\""
2287     " )"
2288     "'>"
2289
2290     ;;we open the bracket according to k&r style or not
2291     "(if jde-gen-k&r "
2292     " ()"
2293     " 'n)"
2294     "\"{\"'>'n"
2295     "\"}\"'>'n 'n"
2296
2297     "(jde-gen-method-signature"
2298     "  \"public\""
2299     "  \"void\""
2300     "  \"setSessionContext\""
2301     "  \"SessionContext ctx\""
2302     "  \"RemoteException\""
2303     " )"
2304     "'>"
2305
2306     ;;we open the bracket according to k&r style or not
2307     "(if jde-gen-k&r "
2308     " ()"
2309     " 'n)"
2310     "\"{\"'>'n"
2311     "\"}\"'>'n 'n"
2312
2313     "(jde-gen-method-signature"
2314     "  \"public\""
2315     "  \"void\""
2316     "  \"unsetSessionContext\""
2317     "  nil"
2318     "  \"RemoteException\""
2319     " )"
2320     "'>"
2321
2322     ;;we open the bracket according to k&r style or not
2323     "(if jde-gen-k&r "
2324     " ()"
2325     " 'n)"
2326     "\"{\"'>'n"
2327     "\"}\"'>'n 'n"
2328     "'>"
2329     )
2330   "*Template that creates an empty implementation of an EJB Session Bean."
2331   :group 'jde-gen
2332   :type '(repeat string)
2333   :set '(lambda (sym val)
2334           (defalias 'jde-gen-session-bean
2335             (tempo-define-template
2336              "ejb-session-bean"
2337              (jde-gen-read-template val)
2338              nil
2339              "Adds an implementation of the EJB Session Bean interface to the 
2340 class in the current buffer at the current point in the buffer. Before invoking
2341 this command,  position point at the point in the buffer where you want the first 
2342 Session Bean method to appear. Use `jde-ejb-session-bean-buffer' to create a complete
2343 skeleton session bean implementation from scratch."))
2344           (set-default sym val)))
2345
2346
2347         
2348 ;; (makunbound 'jde-gen-method-javadoc-comment) 
2349 (defcustom jde-gen-method-javadoc-comment "template"
2350   "Specifies the type of javadoc comment generated by
2351 the `jde-gen-method-template'. The choices are
2352
2353    * Template 
2354
2355      Uses `jde-javadoc-autodoc-at-line' function to generate
2356      the documentation.
2357
2358    * Inherit
2359
2360      Generates a javadoc comment containing only the 
2361      javadoc (@inheritDoc) tag. This tag causes javadoc
2362      to copy the javadoc comment from the abstract 
2363      method that the generated method implements but
2364      only if the javadoc for the abstract method is
2365      also being generated.
2366
2367    * None
2368
2369      Specifies that the method template not generate
2370      a javadoc comment. In this case, javadoc copies
2371      the comment from the abstract method if its doc
2372      is also being generated in the same run."
2373   :group 'jde-gen
2374   :type '(choice
2375           (const :tag "Template" "template")
2376           (const :tag "Inherit Tag" "inherit")
2377           (const :tag "None" "none")))
2378
2379   
2380 ;; (makunbound 'jde-gen-method-template)
2381 (defcustom jde-gen-method-template
2382   '(
2383     "(p \"Method modifiers: \" modifiers 'noinsert)"
2384     "(p \"Method return type: \" return-type 'noinsert)"
2385     "(p \"Method name: \" name 'noinsert)"
2386     "(p \"Method parameters: \" parameters 'noinsert)"
2387     "(p \"Method exceptions: \" exceptions 'noinsert)"
2388     "(p \"Method body: \" default-body 'noinsert)"
2389     "(jde-gen-delete-preceding-whitespace) 'n 'n 'p"
2390
2391     ;; Insert inherit javadoc comment if specified.
2392     "(if (string= jde-gen-method-javadoc-comment \"inherit\")"
2393     "'(l \"/*\" 'n>"
2394     "\"* (@inheritDoc)\" 'n>"
2395     "\"*/\" 'n>"
2396     "))"
2397
2398     ;; Insert method signature.
2399     "(jde-gen-method-signature"
2400     "  (tempo-lookup-named 'modifiers)"
2401     "  (tempo-lookup-named 'return-type)"
2402     "  (tempo-lookup-named 'name)"
2403     "  (tempo-lookup-named 'parameters)"
2404     "  (tempo-lookup-named 'exceptions)"
2405     " )"
2406     "'>"
2407
2408     "(jde-gen-electric-brace)"
2409     "(s default-body) (jde-gen-indent) 'p'n"
2410     "\"}\"'>'n"
2411     "(if (string= jde-gen-method-javadoc-comment \"template\")"
2412     " (progn (tempo-backward-mark) (tempo-backward-mark) (beginning-of-line)"
2413     "   (jde-gen-save-excursion (jde-javadoc-autodoc-at-line))"
2414     "   (tempo-forward-mark) nil)"
2415     "  (progn (tempo-backward-mark) nil))"
2416     "(setq tempo-marks nil) ;; prevent tempo from moving point"
2417     )
2418   "*Template for generating a skeleton method. The
2419 `jde-gen-method-javadoc-comment' variable controls whether this
2420 template generates a javadoc comment for the method, and, if so, what
2421 kind of comment. Setting this variable defines a template
2422 instantiation command, `jde-gen-method', as a side-effect."
2423   :group 'jde-gen
2424   :type '(repeat string)
2425   :set '(lambda (sym val)
2426           (defalias 'jde-gen-method
2427             (tempo-define-template
2428              "method"
2429              (jde-gen-read-template val)
2430              nil
2431              "Insert skeleton method."))
2432           (set-default sym val)))
2433
2434
2435 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2436 ;;;_* equals method generator
2437 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2438
2439 ;;;###autoload
2440 (defcustom jde-gen-equals-trailing-and-operators nil
2441   "Specifies whether the '&&' operators in a generated equals
2442 method are added at the end of the line or at the beginning.  If
2443 this variable is t, the operator will be added at the end of the
2444 line, else on the next line before the comparison.  With
2445 `jde-gen-equals-trailing-and-operators' set to nil:
2446
2447     return (a == o.a)
2448         && (b == o.b)
2449         && (s == null ? o.s == null : s.equals(o.s));
2450
2451 Or, with `jde-gen-equals-trailing-and-operators' set to t:
2452
2453     return (a == o.a) &&
2454         (b == o.b) &&
2455         (s == null ? o.s == null : s.equals(o.s));
2456 "
2457   :group 'jde-gen
2458   :type 'boolean)
2459
2460 ;;;###autoload
2461 (defcustom jde-gen-equals-parens-around-expression nil
2462   "Specifies whether the generated equals expression should be 
2463 surrounded by parentheses.
2464 With `jde-gen-equals-trailing-and-operators' set to nil:
2465
2466     return ((a == o.a)
2467             && (b == o.b)
2468             && (s == null ? o.s == null : s.equals(o.s)));
2469
2470 Or, with `jde-gen-equals-trailing-and-operators' set to t:
2471
2472     return ((a == o.a) &&
2473             (b == o.b) &&
2474             (s == null ? o.s == null : s.equals(o.s)));
2475 "
2476   :group 'jde-gen
2477   :type 'boolean)
2478
2479 ;;;###autoload
2480 (defcustom jde-gen-equals-method-template
2481   '("'>"
2482     "\"/**\" '> 'n"
2483     "\" * Check if this object is equal to another object.\" '> 'n"
2484     "\" * \" '> 'n"
2485     "\" * <p>For the definition of the object equivalence relation\" '> 'n"
2486     "\" * see {@link java.lang.Object#equals(Object)}.</p>\" '> 'n"
2487     "\" * \" '> 'n"
2488     "\" * @param obj another, possibly equal object.\" '> 'n"
2489     "\" * \" '> 'n"
2490     "\" * @return true if the objects are equal, false otherwise.\" '> 'n"
2491     "\" * \" '> 'n"
2492     "\" * @see java.lang.Object#equals(Object)\" '> 'n"
2493     "\" */\" '> 'n"
2494     "(jde-gen-method-signature \"public\" \"boolean\" \"equals\" \"Object obj\")"
2495     "(jde-gen-electric-brace)"
2496     "\"if (obj == this)\" '> 'n"
2497     "\"return true;\" '> 'n '> 'n"
2498     "\"if (obj == null || getClass() != obj.getClass())\" '> 'n"
2499     "\"return false;\" '> 'n '> 'n"
2500     "(jde-gen-equals-return \"obj\" \"o\") '> 'n"
2501     "\"}\" '> 'n '>")
2502   "*Template for creating an equals method.
2503 Setting this variable defines a template instantiation command
2504 `jde-gen-equals-method', as a side-effect."
2505   :group 'jde-gen
2506   :type '(repeat string)
2507   :set '(lambda (sym val)
2508           (defalias 'jde-gen-equals-method
2509             (tempo-define-template
2510              "java-equals-method"
2511              (jde-gen-read-template val)
2512              nil
2513              "Create an equals method at the current point."))
2514           (set-default sym val)))
2515
2516 ;;;###autoload
2517 (defun jde-gen-equals-return (&optional parm-name var-name class)
2518   "Generate a body of an appropriate override for the
2519 java.lang.Object#equals(Object) function. This function gets the
2520 list of member variables from`jde-parse-get-serializable-members'.
2521
2522 The first optional parameter `parm-name' is the parameter name of
2523 the Object argument of the equals function.  Default is \"obj\".
2524
2525 The second optional parameter `var-name' denotes the variable
2526 name used to cast the \"obj\" argument to. The default is \"o\".
2527
2528 The third optional parameter `class' can be a semantic tag, which
2529 is then used instead of the result of `semantic-current-tag'.
2530
2531 Example:
2532     class Bean {
2533         int a;
2534         long b;
2535         String s;
2536     } 
2537
2538 Result:
2539     Bean o = (Bean) obj;
2540
2541     return (a == o.a)
2542         && (b == o.b)
2543         && (s == null ? o.s == null : s.equals(o.s));
2544
2545 Or, with `jde-gen-equals-trailing-and-operators' set to t:
2546     Bean o = (Bean) obj;
2547
2548     return (a == o.a) &&
2549         (b == o.b) &&
2550         (s == null ? o.s == null : s.equals(o.s));
2551 "
2552   (interactive)
2553   (let* ((parm (or parm-name "obj"))
2554          (var (or var-name "o"))
2555          (class-tag (or class (semantic-current-tag)))
2556          (class-name (semantic-tag-name class-tag))
2557          (members (sort (jde-parse-get-serializable-members class-tag)
2558                         'jde-parse-compare-member-types))
2559          (super (car (semantic-tag-type-superclasses class-tag)))
2560          (extends (and super (not (string= "Object" super)))))
2561     (list 'l '>
2562           class-name " " var " = (" class-name ") " parm ";" '>'n '>'n
2563           "return "
2564           (if jde-gen-equals-parens-around-expression "(")
2565           (if extends (list 'l "super.equals(" var ")")) '>
2566           (cons 'l (mapcar
2567               (lambda (tag)
2568                 (let ((name (semantic-tag-name tag))
2569                       (type (semantic-tag-type tag)))
2570                   (list 'l (if extends (jde-gen-equals-add-and-operator)
2571                              (setq extends t) nil)
2572                         (cond
2573                          ;; primitive arrays
2574                          ((and (string-match "\\`\\(byte\\|char\\|short\\|int\\|long\\|float\\|double\\|boolean\\)" type)
2575                              (or (string-match "\\[.*\\]" name) (string-match "\\[.*\\]" type)))
2576                           (let ((array (replace-regexp-in-string "\\[.*\\]" "" name)))
2577                             (concat "java.util.Arrays.equals(" array ", " var "." array ")")))
2578
2579                          ;; object arrays
2580                          ((or (string-match "\\[.*\\]" name) (string-match "\\[.*\\]" type))
2581                           (let ((array (replace-regexp-in-string "\\[.*\\]" "" name)))
2582                             (concat "java.util.Arrays.deepEquals(" array ", " var "." array ")")))
2583
2584                          ;; primitives
2585                          ((or (semantic-tag-of-type-p tag "byte")
2586                               (semantic-tag-of-type-p tag "char")
2587                               (semantic-tag-of-type-p tag "short")
2588                               (semantic-tag-of-type-p tag "int")
2589                               (semantic-tag-of-type-p tag "long")
2590                               (semantic-tag-of-type-p tag "boolean"))
2591                           (concat "(" name " == " var "." name ")"))
2592
2593                          ;; floating point; use epsilon?
2594                          ((or (semantic-tag-of-type-p tag "float")
2595                               (semantic-tag-of-type-p tag "double"))
2596                           (concat "(" name " == " var "." name ")"))
2597
2598                          ;; object references
2599                          (t (concat "(" name " == null ? " var "." name " == null : "
2600                                     name ".equals(" var "." name "))" )))
2601                         '>))) members))
2602           (if jde-gen-equals-parens-around-expression ")") ";")))
2603
2604 (defun jde-gen-equals-add-and-operator ()
2605   (if jde-gen-equals-trailing-and-operators
2606       (list 'l " &&" '> 'n '>)
2607     (list 'l '> 'n '> "&& ")))
2608
2609 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2610 ;;;_* hashCode method generator
2611 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2612
2613 ;;;###autoload
2614 (defcustom jde-gen-hashcode-method-template
2615   '("'>"
2616     "\"/**\" '> 'n"
2617     "\" * Calculate the hash code for this object.\" '> 'n"
2618     "\" * \" '> 'n"
2619     "\" * <p>The rules laid out in J. Blosh's Effective Java are used\" '> 'n"
2620     "\" * for the hash code calculation.</p>\" '> 'n"
2621     "\" * \" '> 'n"
2622     "\" * @return the hash code.\" '> 'n"
2623     "\" * \" '> 'n"
2624     "\" * @see java.lang.Object#hashCode\" '> 'n"
2625     "\" */\" '> 'n"
2626     "(jde-gen-method-signature \"public\"\ \"int\" \"hashCode\" nil)"
2627     "(jde-gen-electric-brace)"
2628     "(jde-gen-hashcode-body) '> 'n"
2629     "\"}\" '> 'n '>" )
2630   "*Template for creating a hashCode method.
2631 Setting this variable defines a template instantiation command
2632 `jde-gen-hashcode-method', as a side-effect."
2633   :group 'jde-gen
2634   :type '(repeat string)
2635   :set '(lambda (sym val)
2636           (defalias 'jde-gen-hashcode-method
2637             (tempo-define-template
2638              "java-hashcode-method"
2639              (jde-gen-read-template val)
2640              nil
2641              "Create a hashCode method at the current point."))
2642           (set-default sym val)))
2643
2644 (defvar jde-gen-hashcode-primes
2645   '(11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97)
2646     "a list of all two digit prime numbers")
2647
2648 (defvar jde-gen-hashcode-current-prime 0
2649   "a prime number")
2650
2651 (defun jde-gen-hashcode-next-prime ()
2652   "Get the next prime number"
2653   (let ((last jde-gen-hashcode-current-prime))
2654     (setq jde-gen-hashcode-current-prime (% (+ 1 last)
2655                                             (length jde-gen-hashcode-primes)))
2656     (int-to-string (nth last jde-gen-hashcode-primes))))
2657
2658 ;;;###autoload
2659 (defun jde-gen-hashcode-body (&optional var-name class)
2660   "Generate a body of a hashCode function.
2661 This function gets the list of member variables of the current
2662 class from `jde-parse-get-serializable-members'.
2663
2664 The first optional parameter `var-name' denotes the variable name used
2665 to calculate the hash code, the default is \"code\".
2666
2667 The second optional parameter `class' can be a semantic tag, which is
2668 then used instead of the result of `semantic-current-tag'.
2669 "
2670   (interactive)
2671   (let* ((var (or var-name "code"))
2672          (class-tag (or class (semantic-current-tag)))
2673          (members (sort (jde-parse-get-serializable-members class-tag)
2674                         'jde-parse-compare-member-types))
2675          (super (car (semantic-tag-type-superclasses class-tag)))
2676          (extends (and super (not (string= "Object" super)))))
2677     (list 'l "int " var " = "
2678           (if extends "super.hashCode()" (jde-gen-hashcode-next-prime)) ";"
2679           '> 'n '> 'n
2680           (cons
2681            'l
2682            (mapcar
2683             (lambda (tag)
2684               (let ((name (semantic-tag-name tag))
2685                     (type (semantic-tag-type tag)))
2686                 (list 'l var " = " var " * 37 + "
2687                       (cond
2688                        ;; arrays must be first
2689
2690                        ;; primitive arrays
2691                        ((and (string-match "\\`\\(byte\\|char\\|short\\|int\\|long\\|float\\|double\\|boolean\\)" type)
2692                              (or (string-match "\\[.*\\]" name) (string-match "\\[.*\\]" type)))
2693                         (let ((array (replace-regexp-in-string "\\[.*\\]" "" name)))
2694                           (concat "java.util.Arrays.hashCode(" array ")")))
2695                        ;; object arrays
2696                        ((or (string-match "\\[.*\\]" name) (string-match "\\[\\]" type))
2697                         (let ((array (replace-regexp-in-string "\\[.*\\]" "" name)))
2698                           (concat "java.util.Arrays.deepHashCode(" array ")")))
2699
2700                        ;; smaller types
2701                        ((or (semantic-tag-of-type-p tag "byte")
2702                             (semantic-tag-of-type-p tag "char")
2703                             (semantic-tag-of-type-p tag "short"))
2704                         (concat "(int) " name))
2705                        ;; integers
2706                        ((semantic-tag-of-type-p tag "int") name)
2707                        ((semantic-tag-of-type-p tag "long")
2708                         (concat "(int) (" name " ^ (" name " >> 32))" ))
2709                        ;; booleans
2710                        ((semantic-tag-of-type-p tag "boolean")
2711                         (concat "(" name " ? 1 : 0)"))
2712
2713                        ;; floating point
2714                        ((semantic-tag-of-type-p tag "float")
2715                         (concat "Float.floatToIntBits(" name ")" ))
2716                        ((semantic-tag-of-type-p tag "double")
2717                         (concat "(int) (Double.doubleToLongBits(" name ") ^ (Double.doubleToLongBits(" name ") >> 32))" ))
2718
2719
2720                        ;; object references
2721                        (t
2722                         (concat "(" name " == null ? " (jde-gen-hashcode-next-prime)
2723                                 " : " name ".hashCode())"))) ";"
2724                       '> 'n))) members))
2725           '> 'n
2726           "return " var ";")))
2727
2728 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2729 ;;;_* toString method generator
2730 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2731
2732 ;;;###autoload
2733 (defcustom jde-gen-tostring-method-template
2734   '("'>"
2735     "\"/**\" '> 'n"
2736     "\" * Get a string representation of this object.\" '> 'n"
2737     "\" * \" '> 'n"
2738     "\" * @return a string representation of this object.\" '> 'n"
2739     "\" * \" '> 'n"
2740     "\" * @see java.lang.Object#toString\" '> 'n"
2741     "\" */\" '> 'n"
2742     "(jde-gen-method-signature \"public\" \"String\" \"toString\" \"\")"
2743     "(jde-gen-electric-brace)"
2744     "(jde-gen-tostring-return) '> 'n"
2745     "\"}\" '> 'n '>"
2746     "(jde-import-one-class \"org.apache.commons.lang.builder.ToStringBuilder\")")
2747   "*Template for creating an toString method.
2748 Setting this variable defines a template instantiation
2749 command `jde-gen-tostring-method', as a side-effect."
2750   :group 'jde-gen
2751   :type '(repeat string)
2752   :set '(lambda (sym val)
2753           (defalias 'jde-gen-tostring-method
2754             (tempo-define-template
2755              "java-tostring-method"
2756              (jde-gen-read-template val)
2757              nil
2758              "Create an toString method at the current point."))
2759           (set-default sym val)))
2760
2761 ;;;###autoload
2762 (defun jde-gen-tostring-return (&optional class)
2763   "Generate a body of an appropriate override for the
2764 java.lang.Object#toString function. This gets the member variables
2765 of the current class from semantic via `semantic-current-tag'.
2766
2767 This uses the ToStringBuilder class from the jakarta commons lang project.
2768 "
2769   (interactive)
2770   (let* ((class-tag (or class (semantic-current-tag)))
2771          (class-name (semantic-tag-name class-tag))
2772          (members (jde-parse-get-member-variables class-tag))
2773          (super (car (semantic-tag-type-superclasses class-tag)))
2774          (extends (and super (not (string= "Object" super)))))
2775     (list 'l '>
2776           "return new ToStringBuilder(this)" ' > 'n
2777           (if extends (list 'l ".appendSuper(super.toString())" '> 'n))
2778           (cons 'l (mapcar
2779               (lambda (tag)
2780                 (let ((name (semantic-tag-name tag)))
2781                   (list 'l ".append(\"" name "\", " name ")" '> 'n))) members))
2782           ".toString();")))
2783
2784 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2785 ;;;_* Generate all object methods
2786 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2787
2788 ;;;###autoload
2789 (defun jde-gen-object-methods ()
2790   "Generates an equals(), a hashCode() and a toString method."
2791   (interactive)
2792   (jde-gen-equals-method)
2793   (newline-and-indent)
2794   (jde-gen-hashcode-method)
2795   (newline-and-indent)
2796   (jde-gen-tostring-method))
2797
2798
2799 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2800 ;;;_* Exception class wizard
2801 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2802
2803 ;;;###autoload
2804 (defcustom jde-gen-exception-buffer-template
2805   (list
2806    "(open-line 1) (funcall jde-gen-boilerplate-function)"
2807    "(jde-gen-get-package-statement)"
2808    "(progn (require 'jde-javadoc) (jde-javadoc-insert-start-block))"
2809    "\" * Exception <code>\" (jde-parse-get-buffer-unqualified-class) \"</code>.\" '> 'n"
2810    "\" \" (jde-javadoc-insert-empty-line)"
2811    "\" * Created: \" (current-time-string) '> 'n"
2812    "\" \" (jde-javadoc-insert-empty-line)"
2813    "\" \" (jde-gen-save-excursion (jde-javadoc-insert 'tempo-template-jde-javadoc-author-tag))"
2814    "\" \" (jde-gen-save-excursion (jde-javadoc-insert 'tempo-template-jde-javadoc-version-tag))"
2815    "\" \" (jde-javadoc-insert-end-block)"
2816    "\"public class \""
2817    "(jde-parse-get-buffer-unqualified-class)" "\" \" (jde-gen-get-extend-class)"
2818    "(jde-gen-electric-brace)"
2819    "'p'n"
2820
2821    ;; Default constructor
2822    "'> (jde-javadoc-insert-start-block)"
2823     "\"* Constructs a new <code>\" (jde-parse-get-buffer-unqualified-class) \"</code> with\" '>'n"
2824     "\"* <code>null</code> as its detail message.\" '>'n"
2825     "'> (jde-javadoc-insert-end-block)"
2826     "(jde-gen-method-signature \"public\" nil (jde-parse-get-buffer-unqualified-class) nil)" 
2827     "(jde-gen-electric-brace)"
2828     "\"}\"'>'n"
2829     ;; leave a blank line with no indentation
2830     "'n"
2831
2832    ;; Constructor with message
2833    "'> (jde-javadoc-insert-start-block)"
2834     "\"* Constructs a new <code>\" (jde-parse-get-buffer-unqualified-class) \"</code> with\" '>'n"
2835     "\"* the specified detail message.\" '>'n"
2836     "'> (jde-javadoc-insert-empty-line)"
2837     "\"* @param message the detail message string.\" '> 'n"
2838     "'> (jde-javadoc-insert-end-block)"
2839     "(jde-gen-method-signature \"public\" nil (jde-parse-get-buffer-unqualified-class) \"String message\")" 
2840     "(jde-gen-electric-brace)"
2841     "\"super(message);\" '> 'n"
2842     "\"}\" '> 'n"
2843     ;; leave a blank line with no indentation
2844     "'n"
2845
2846    ;; Constructor with a cause
2847    "'> (jde-javadoc-insert-start-block)"
2848     "\"* Constructs a new <code>\" (jde-parse-get-buffer-unqualified-class) \"</code> with\" '>'n"
2849     "\"* the specified cause and a detail message of\" '> 'n"
2850     "\"* <code>(cause == null ? null : cause.toString())</code>\" '> 'n"
2851     "\"* (which typically contains the class and detail message of cause).\" '> 'n"
2852     "'> (jde-javadoc-insert-empty-line)"
2853     "\"* @param cause the causing throwable. A null value is permitted\" '> 'n"
2854     "\"*     and indicates that the cause is nonexistent or unknown.\" '> 'n"
2855     "'> (jde-javadoc-insert-end-block)"
2856     "(jde-gen-method-signature \"public\" nil (jde-parse-get-buffer-unqualified-class) \"Throwable cause\")" 
2857     "(jde-gen-electric-brace)"
2858     "\"super(cause == null ? (String) null : cause.toString());\" '> 'n"
2859     "\"initCause(cause);\" '> 'n"
2860     "\"}\" '> 'n"
2861     ;; leave a blank line with no indentation
2862     "'n"
2863
2864     ;; Constructor with a message and a cause
2865    "'> (jde-javadoc-insert-start-block)"
2866     "\"* Constructs a new <code>\" (jde-parse-get-buffer-unqualified-class) \"</code> with\" '>'n"
2867     "\"* the specified cause and message.\" '> 'n"
2868     "'> (jde-javadoc-insert-empty-line)"
2869     "\"* @param message the detail message string.\" '> 'n"
2870     "\"* @param cause the causing throwable. A null value is permitted\" '> 'n"
2871     "\"*     and indicates that the cause is nonexistent or unknown.\" '> 'n"
2872     "'> (jde-javadoc-insert-end-block)"
2873     "(jde-gen-method-signature \"public\" nil (jde-parse-get-buffer-unqualified-class) \"String message,Throwable cause\")" 
2874     "(jde-gen-electric-brace)"
2875     "\"super(message);\" '> 'n"
2876     "\"initCause(cause);\" '> 'n"
2877     "\"}\" '> 'n"
2878     ;; leave a blank line with no indentation
2879
2880     "\"}\" '>" "(if jde-gen-comments (concat \" // \" (jde-parse-get-buffer-unqualified-class)))"
2881    "'>'n")
2882   "*Template for a new exception class.
2883 Setting this variable defines a template instantiation
2884 command `jde-gen-exception', as a side-effect."
2885   :group 'jde-gen
2886   :type '(repeat string)
2887   :set '(lambda (sym val)
2888           (tempo-define-template "java-exception-buffer-template"
2889                                  (jde-gen-read-template val)
2890                                  nil
2891                                  "Insert a generic Java exception buffer skeleton.")
2892           (defalias 'jde-gen-exception
2893             (list 'lambda (list)
2894                   (list 'interactive)
2895                   (list 'tempo-template-java-exception-buffer-template)))
2896           (set-default sym val)))
2897
2898 ;;;###autoload
2899 (defun jde-gen-exception-buffer (file)
2900   "Create a new Java buffer containing an exception class of the same name.
2901 This command inserts the template generated by `jde-gen-exception'.
2902 It then moves the point to the location of the first method."
2903   (interactive "F")
2904   (find-file file)
2905   (jde-gen-exception))
2906
2907
2908 (defcustom jde-gen-code-templates
2909   (list (cons "Get Set Pair" 'jde-gen-get-set)
2910         (cons "main method" 'jde-gen-main-method)
2911         (cons "toString Method (Apache)" 'jde-gen-tostring-method)
2912         (cons "Equals Method" 'jde-gen-equals-method)
2913         (cons "Hash Code Method" 'jde-gen-hashcode-method)
2914         (cons "Deep clone" 'jde-gen-deep-clone)
2915         (cons "Action Listener" 'jde-gen-action-listener)
2916         (cons "Change Listener" 'jde-gen-change-listener)
2917         (cons "Window Listener" 'jde-gen-window-listener)
2918         (cons "Mouse Listener" 'jde-gen-mouse-listener)
2919         (cons "Mouse Motion Listener" 'jde-gen-mouse-motion-listener)
2920         (cons "Inner Class" 'jde-gen-inner-class)
2921         (cons "println" 'jde-gen-println)
2922         (cons "beep" 'jde-gen-beep)
2923         (cons "property change support" 'jde-gen-property-change-support)
2924         (cons "EJB Entity Bean" 'jde-gen-entity-bean)
2925         (cons "EJB Session Bean" 'jde-gen-session-bean)
2926         )
2927   "*Specifies available autocode templates.
2928 The value of this variable is an association list. The car of
2929 each element specifies a template name. The cdr specifies
2930 a command that inserts the template into a buffer. See the function
2931 `tempo-define-template' for any easy way to create a template
2932 insertion command."
2933   :group 'jde-gen
2934   :type '(repeat
2935           (cons :tag "Template"
2936                 (string :tag "Name")
2937                 (function :tag "Command")))
2938   :set '(lambda (sym val)
2939           (let ((n (length val))
2940                 (i 0))
2941             (setq jde-gen-template-names (list))
2942             (while (< i n)
2943               (setq jde-gen-template-names
2944                     (append
2945                      jde-gen-template-names
2946                      (list (cons (car (nth i val)) (1+ i)))))
2947               (setq i (1+ i))))
2948           (set-default sym val)))
2949
2950 (defun jde-gen-code (name)
2951   "Insert the code template specified by NAME at point.
2952 The template must be one of those specified by the
2953 variable `jde-gen-code-templates'."
2954   (interactive
2955    (list
2956     (completing-read "Template name: " jde-gen-template-names)))
2957   (funcall (cdr (assoc name jde-gen-code-templates))))
2958
2959
2960
2961 ;;; Control Flow Templates
2962 ;;; Contributed by Eric D. Friedman <friedman@lmi.net>
2963
2964 (defvar jde-gen-abbrev-templates nil
2965   "List of abbreviation templates defined by
2966 `jde-gen-define-abbrev-template'.")
2967
2968 (defun jde-gen-define-abbrev-template (abbrev template)
2969   "Defines a TEMPLATE that replaces ABBREV when you type ABBREV
2970 in a JDE source buffer. TEMPLATE is a list of tempo template
2971 elements. See `tempo-define-template' for information on
2972 template elements. The resulting template is added to the
2973 list bound to `jde-gen-abbrev-templates'. "
2974   (let ((template-name (concat "jde-gen-" abbrev)))
2975     (defalias (intern template-name)
2976       (tempo-define-template
2977        template-name
2978        template 
2979        abbrev 
2980        (format "JDE template for %s control flow abbreviation." abbrev)
2981        'jde-gen-abbrev-templates))))
2982
2983 (defcustom jde-gen-cflow-enable t
2984   "Enables abbreviations for Java control flow constructs."
2985   :group 'jde-gen
2986   :type 'boolean)
2987
2988
2989 (defcustom jde-gen-comments nil
2990   "*If no-nil, use comments, else do not use comments.
2991 with comments:
2992
2993       try {
2994
2995       } catch (Exception e) {
2996
2997       } // end of try-catch
2998
2999
3000 witout comments:
3001
3002       try {
3003
3004       } catch (Exception e) {
3005
3006       }
3007
3008 Setting this variable to t, uses comments in skeletons and templates."
3009   :group 'jde-gen
3010   :type 'boolean)
3011
3012 ;; (makunbound 'jde-gen-cflow-if)
3013 (defcustom jde-gen-cflow-if
3014   '(
3015     "'> \"if\" jde-gen-conditional-padding-1 "
3016     "\"(\" jde-gen-conditional-padding-2 (p \"if-clause: \" clause)"
3017     "      jde-gen-conditional-padding-2 \")\""
3018     "(jde-gen-electric-brace jde-gen-conditional-padding-3)"
3019     "'r'n"
3020     "\"}\""
3021     "(if jde-gen-comments "
3022     "'(l \" // end of if (\" (s clause) \")\"))"
3023     "'>'n"
3024     )
3025   "Skeleton if statement. To insert the if statement at point, type if
3026 and then space. Note that abbrev mode must be enabled. See
3027 `jde-enable-abbrev-mode'"
3028   :group 'jde-gen
3029   :type '(repeat string)
3030   :set '(lambda (sym val)
3031           (jde-gen-define-abbrev-template
3032            "if"
3033            (jde-gen-read-template val))
3034           (set-default sym val)))
3035
3036 (defcustom jde-gen-cflow-else
3037   '(
3038     "'> \"else\""
3039     "(jde-gen-electric-brace jde-gen-conditional-padding-3)"
3040     "'r'n"
3041     "\"}\""
3042     "(if jde-gen-comments "
3043     " '(l \" // end of else\"))"
3044     "'>'n"
3045     )
3046   "Skeleton else statement. To insert the statement at point, type else
3047 and then space. Note that abbrev mode must be enabled. See
3048 `jde-enable-abbrev-mode' for more information."
3049   :group 'jde-gen
3050   :type '(repeat string)
3051   :set '(lambda (sym val)
3052           (jde-gen-define-abbrev-template
3053            "else"
3054            (jde-gen-read-template val))
3055           (set-default sym val)))
3056
3057 (defcustom jde-gen-cflow-if-else
3058   '(
3059     "'> \"if\" jde-gen-conditional-padding-1 "
3060     "\"(\" jde-gen-conditional-padding-2 (p \"if-clause: \" clause)"
3061     "      jde-gen-conditional-padding-2 \")\""
3062     "(jde-gen-electric-brace jde-gen-conditional-padding-3)"
3063     "'r'n"
3064     "\"}\" '>"
3065     "(if jde-gen-comments "
3066     " '(l \" // end of if (\" (s clause) \")\" '>'n)"
3067     " (if jde-gen-k&r "
3068     "  jde-gen-conditional-padding-3 "
3069     "  'n))"
3070     "'> \"else\""
3071     "(jde-gen-electric-brace jde-gen-conditional-padding-3)"
3072     "'r'n"
3073     "\"}\""
3074     "(if jde-gen-comments "
3075     " '(l \" // end of if (\" (s clause) \") else\"))"
3076     "'>'n"
3077     )
3078   "Skeleton if-else statement. To insert the statement at point, type ife
3079 and then space. Note that abbrev mode must be enabled. See
3080 `jde-enable-abbrev-mode' for more information."
3081   :group 'jde-gen
3082   :type '(repeat string)
3083   :set '(lambda (sym val)
3084           (jde-gen-define-abbrev-template
3085            "ife"
3086            (jde-gen-read-template val))
3087           (set-default sym val)))
3088
3089 (defcustom jde-gen-cflow-else-if
3090   '(
3091     "'> \"else if\" jde-gen-conditional-padding-1 "
3092     "\"(\" jde-gen-conditional-padding-2 (p \"else-if-clause: \" clause) "
3093     "      jde-gen-conditional-padding-2 \")\""
3094     "(jde-gen-electric-brace jde-gen-conditional-padding-3)"
3095     "'r'n"
3096     "\"}\""
3097     "(if jde-gen-comments "
3098     " '(l \" // end of else if (\" (s clause) \")\"))"
3099     "'>'n"
3100     )
3101   "Skeleton else-if statement. To insert the statement at point, type eif
3102 and then space. Note that abbrev mode must be enabled. See
3103 `jde-enable-abbrev-mode' for more information."
3104   :group 'jde-gen
3105   :type '(repeat string)
3106   :set '(lambda (sym val)
3107           (jde-gen-define-abbrev-template
3108            "eif"
3109            (jde-gen-read-template val))
3110           (set-default sym val)))
3111
3112 ;; (makunbound 'jde-gen-cflow-while)
3113 (defcustom jde-gen-cflow-while
3114   '(
3115     "'> \"while\" jde-gen-conditional-padding-1 "
3116     "\"(\" jde-gen-conditional-padding-2 (p \"while-clause: \" clause) "
3117     "      jde-gen-conditional-padding-2 \")\""
3118     "(jde-gen-electric-brace jde-gen-conditional-padding-3)"
3119     "'r'n"
3120     "\"}\""
3121     "(if jde-gen-comments "
3122     " '(l \" // end of while (\" (s clause) \")\"))"
3123     "'>'n"
3124     )
3125   "Skeleton while statement. To insert the statement at point, type while
3126 and then space. Note that abbrev mode must be enabled. See
3127 `jde-enable-abbrev-mode' for more information."
3128   :group 'jde-gen
3129   :type '(repeat string)
3130   :set '(lambda (sym val)
3131           (jde-gen-define-abbrev-template
3132            "while"
3133            (jde-gen-read-template val))
3134           (set-default sym val)))
3135
3136 (defcustom jde-gen-cflow-for
3137   '(
3138     "'> \"for\" jde-gen-conditional-padding-1 "
3139     "\"(\" jde-gen-conditional-padding-2 (p \"for-clause: \" clause) "
3140     "      jde-gen-conditional-padding-2 \")\""
3141     "(jde-gen-electric-brace jde-gen-conditional-padding-3)"
3142     "'r'n"
3143     "\"}\""
3144     "(if jde-gen-comments "
3145     " '(l \" // end of for (\" (s clause) \")\"))"
3146     "'>'n"
3147     )
3148   "Skeleton for statement. To insert the statement at point, type for
3149 and then space. Note that abbrev mode must be enabled. See
3150 `jde-enable-abbrev-mode' for more information."
3151   :group 'jde-gen
3152   :type '(repeat string)
3153   :set '(lambda (sym val)
3154           (jde-gen-define-abbrev-template
3155            "for"
3156            (jde-gen-read-template val))
3157           (set-default sym val)))
3158
3159 (defcustom jde-gen-cflow-for-i
3160   '(
3161     "'> \"for\" jde-gen-conditional-padding-1 "
3162     "\"(\" jde-gen-conditional-padding-2 \"int \" (p \"variable: \" var) "
3163     "\" = 0; \" (s var) \" < \" (p \"upper bound: \" upper-bound) \"; \" (s var) \"++\""
3164     "      jde-gen-conditional-padding-2 \")\""
3165     "(jde-gen-electric-brace jde-gen-conditional-padding-3)"
3166     "'r'n"
3167     "\"}\""
3168     "(if jde-gen-comments "
3169     " '(l \" // end of for (int \" (s var) \" = 0; \""
3170     "(s var) \" < \" (s upper-bound) \"; \" (s var) \"++)\"))"
3171     "'>'n"
3172     )
3173   "Skeleton for i statement. To insert the statement at point, type fori
3174 and then space. Note that abbrev mode must be enabled. See
3175 `jde-enable-abbrev-mode' for more information.
3176
3177 Note: `tempo-interactive' must be set to a non-nil value to be prompted
3178       for variable name and upper-bounds information."
3179   :group 'jde-gen
3180   :type '(repeat string)
3181   :set '(lambda (sym val)
3182           (jde-gen-define-abbrev-template
3183            "fori"
3184            (jde-gen-read-template val))
3185           (set-default sym val)))
3186
3187 (defcustom jde-gen-cflow-for-iter
3188   '(
3189     "'> \"for\" jde-gen-conditional-padding-1 "
3190     "\"(\" jde-gen-conditional-padding-2 \"Iterator \" (p \"variable: \" var) "
3191     "\" = \" (p \"collection: \" coll) \".iterator(); \""
3192     "(s var) \".hasNext();\""
3193     "      jde-gen-conditional-padding-2 \")\""
3194     "(jde-gen-electric-brace jde-gen-conditional-padding-3)"
3195     "'r"
3196     "(s var) \".next();\" '>'n'>"
3197     "\"}\""
3198     "(if jde-gen-comments "
3199     " '(l \" // end of for (Iterator \" (s var) \" = \" (s coll)"
3200     " \".iterator(); \" (s var) \".hasNext();)\"))"
3201     "'>'n"
3202     )
3203   "Skeleton for iterator statement. To insert the statement at point,
3204 type foriter and then space.  Note that abbrev mode must be
3205 enabled. See `jde-enable-abbrev-mode' for more information.
3206
3207 Note: `tempo-interactive' must be set to a non-nil value to be prompted
3208       for variable name and collection name information."
3209   :group 'jde-gen
3210   :type '(repeat string)
3211   :set '(lambda (sym val)
3212           (jde-gen-define-abbrev-template
3213            "foriter"
3214            (jde-gen-read-template val))
3215           (set-default sym val)))
3216
3217 (defcustom jde-gen-cflow-switch
3218   '(
3219     "'> \"switch\" jde-gen-conditional-padding-1 "
3220     " \"(\" jde-gen-conditional-padding-2 (p \"switch-condition: \" clause) "
3221     "       jde-gen-conditional-padding-2 \")\""
3222     "'>"
3223     "(jde-gen-electric-brace jde-gen-conditional-padding-3)"
3224     "\"case \" (p \"first value: \" first-value) \":\"'>'n"
3225     "'p'n"            ;; point will end up here
3226     "\"break;\"'>'n"
3227     "\"default:\"'>'n'>"
3228     "\"break;\"'>'n"
3229     "\"}\""
3230     "(if jde-gen-comments "
3231     " '(l \" // end of switch (\" (s clause) \")\"))"
3232     "'>'n"
3233     )
3234   "Skeleton switch statement. To insert the statement at point, type switch
3235 and then space. Note that abbrev mode must be enabled. See
3236 `jde-enable-abbrev-mode' for more information."
3237   :group 'jde-gen
3238   :type '(repeat string)
3239   :set '(lambda (sym val)
3240           (jde-gen-define-abbrev-template
3241            "switch"
3242            (jde-gen-read-template val))
3243           (set-default sym val)))
3244
3245 (defcustom jde-gen-cflow-case
3246   '(
3247     "\"case \" (p \"value: \" value) \":\"'>'n"
3248     "'p'n"           ;; point will end up here
3249     "\"break;\"'>"
3250     )
3251   "Skeleton case statement. To insert the statement at point, type case
3252 and then space. Note that abbrev mode must be enabled. See
3253 `jde-enable-abbrev-mode' for more information."
3254   :group 'jde-gen
3255   :type '(repeat string)
3256   :set '(lambda (sym val)
3257           (jde-gen-define-abbrev-template
3258            "case"
3259            (jde-gen-read-template val))
3260           (set-default sym val)))
3261
3262 ;; (makunbound 'jde-gen-cflow-try-catch)
3263 (defcustom jde-gen-cflow-try-catch
3264   '(
3265     "'> \"try \""
3266     "(jde-gen-electric-brace)"
3267     "'r'n"
3268     "\"}\" '>"
3269
3270     ;; "(if jde-gen-k&r "
3271     ;; "  jde-gen-conditional-padding-3 "
3272     ;; " 'n)"
3273
3274     "(if jde-gen-comments "
3275     " '(l \" // end of try\" '>'n)"
3276     " (if jde-gen-k&r "
3277     "  jde-gen-conditional-padding-3 "
3278     "  'n))"
3279
3280     "\"catch\" jde-gen-conditional-padding-1 "
3281     "\"(\" jde-gen-conditional-padding-2 (p \"catch what: \" clause) \" e\""
3282     "      jde-gen-conditional-padding-2 \")\" '>"
3283     "(jde-gen-electric-brace jde-gen-conditional-padding-3)"
3284     "'p'n"
3285     "\"}\""
3286     " (if jde-gen-comments "
3287     "   '(l \" // end of try-catch\"))"
3288     "'>'n"
3289     )
3290   "Skeleton try-catch statement. To insert the statement at point, type try
3291 and then space. Note that abbrev mode must be enabled. See
3292 `jde-enable-abbrev-mode' for more information."
3293   :group 'jde-gen
3294   :type '(repeat string)
3295   :set '(lambda (sym val)
3296           (jde-gen-define-abbrev-template
3297            "try"
3298            (jde-gen-read-template val))
3299           (set-default sym val)))
3300
3301 (defcustom jde-gen-cflow-catch
3302   '(
3303     "'> \"catch\" jde-gen-conditional-padding-1  "
3304     "\"(\" jde-gen-conditional-padding-2 (p \"catch what: \" clause) \" e\""
3305     "      jde-gen-conditional-padding-2 \")\""
3306     "(jde-gen-electric-brace jde-gen-conditional-padding-3)"
3307     "'r'n"
3308     "\"}\""
3309     "(if jde-gen-comments "
3310     " '(l \" // end of catch\"))"
3311     "'>'n"
3312     )
3313   "Skeleton catch statement. To insert the statement at point, type catch
3314 and then space. Note that abbrev mode must be enabled. See
3315 `jde-enable-abbrev-mode' for more information."
3316   :group 'jde-gen
3317   :type '(repeat string)
3318   :set '(lambda (sym val)
3319           (jde-gen-define-abbrev-template
3320            "catch"
3321            (jde-gen-read-template val))
3322           (set-default sym val)))
3323
3324 (defcustom jde-gen-cflow-try-finally
3325   '(
3326     "'> \"try \""
3327     "(jde-gen-electric-brace)"
3328     "'r'n"
3329     "\"}\" '>"
3330     "(if jde-gen-k&r "
3331     "  jde-gen-conditional-padding-3 "
3332     " 'n)"
3333     "\"catch\" jde-gen-conditional-padding-1 "
3334     "\"(\" jde-gen-conditional-padding-2 (p \"catch what: \" clause) \" e\""
3335     "      jde-gen-conditional-padding-2 \")\" '>"
3336     "(jde-gen-electric-brace jde-gen-conditional-padding-3)"
3337     "'r'n"
3338     "\"}\" '> "
3339     "(if jde-gen-k&r "
3340     "  jde-gen-conditional-padding-3 "
3341     " 'n)"
3342     "\"finally\" '>"
3343     "(jde-gen-electric-brace jde-gen-conditional-padding-3)"
3344     "'r'n"
3345     "\"}\""
3346     "(if jde-gen-comments "
3347     " '(l \" // end of try-finally\"))"
3348     "'>'n"
3349     )
3350   "Skeleton try-catch-finally statement. To insert the statement at point, type
3351 tryf and then space. Note that abbrev mode must be enabled. See
3352 `jde-enable-abbrev-mode' for more information."
3353   :group 'jde-gen
3354   :type '(repeat string)
3355   :set '(lambda (sym val)
3356           (jde-gen-define-abbrev-template
3357            "tryf"
3358            (jde-gen-read-template val))
3359           (set-default sym val)))
3360
3361 (defcustom jde-gen-cflow-finally
3362   '(
3363     "'> \"finally\""
3364     "(jde-gen-electric-brace jde-gen-conditional-padding-3)"
3365     "'r'n"
3366     "\"}\""
3367     "(if jde-gen-comments "
3368     " '(l \" // end of finally\"))"
3369     "'>'n"
3370     )
3371   "Skeleton finally statement. To insert the statement at point, type finally
3372 and then space. Note that abbrev mode must be enabled. See
3373 `jde-enable-abbrev-mode' for more information."
3374   :group 'jde-gen
3375   :type '(repeat string)
3376   :set '(lambda (sym val)
3377           (jde-gen-define-abbrev-template
3378            "finally"
3379            (jde-gen-read-template val))
3380           (set-default sym val)))
3381
3382 (defun jde-gen-abbrev-hook ()
3383   "Abbreviation hook. Inserts an abbreviation template.
3384 Abbreviation name is deleted from buffer before the template is inserted.
3385 This function does nothing, if point is in a comment or string.
3386 Returns t, if the template has been inserted, otherwise nil."
3387   (unless (jde-parse-comment-or-quoted-p)
3388     (let* ((abbrev-start
3389             (or abbrev-start-location
3390                 (save-excursion (re-search-backward "\\<.*\\="))))
3391            (abbrev
3392             (buffer-substring-no-properties abbrev-start (point)))
3393            (template (assoc-ignore-case abbrev jde-gen-abbrev-templates)))
3394       (if template
3395           (progn
3396             (delete-backward-char (length abbrev))
3397             ;; Following let avoids infinite expansion.
3398             ;; Infinite expansions could be caused by
3399             ;; (newline) in templates.
3400             ;; e.g. "else" (newline)
3401             (let (local-abbrev-table)
3402               (funcall (cdr template)))
3403             t) ; don't insert self-inserting input character that triggered the expansion.
3404         (error "Template for abbreviation %s not found!" abbrev)))))
3405
3406 ;; The following enables the hook to control the treatment of the
3407 ;; self-inserting input character that triggered the expansion.
3408 (put 'jde-gen-abbrev-hook 'no-self-insert t)
3409
3410 (defun jde-gen-load-abbrev-templates ()
3411   "Defines jde-mode abbrevs for the control flow templates."
3412   (loop for template in jde-gen-abbrev-templates do
3413         (let ((abbrev (car template)))
3414           (define-abbrev
3415             local-abbrev-table
3416             abbrev
3417             (if (featurep 'xemacs) abbrev t) ;; Hack (see note below)
3418             'jde-gen-abbrev-hook
3419             0))))
3420
3421 ;; Note: the previous function uses the following hack to address the
3422 ;; problem of preventing expansion of control flow abbreviations in
3423 ;; comments and strings. The hack defines the abbreviation such that
3424 ;; abbrev-mode doesn't replace the abbreviation.
3425 ;; If the abbreviation is not in a string or comment, the hook
3426 ;; then erases the abbreviation and replaces it with the corresponding
3427 ;; control flow expansion. If the abbreviation is in a string or
3428 ;; comment, the hook does nothing, simply leaving the abbreviation
3429 ;; as the user typed it.
3430
3431 (defun jde-gen-test-cflow-templates ()
3432    (interactive)
3433    (set-buffer (get-buffer-create "*jde-cflow-test*"))
3434    (jde-mode)
3435    (erase-buffer)
3436    (insert "public class Test {\n\n}")
3437    (backward-char 2)
3438    (loop for flags in '((t . t) (t . nil) (nil . t) (nil . nil)) do
3439          (let ((jde-gen-k&r (car flags))
3440                (jde-gen-comments (cdr flags)))
3441            (insert (format "/**** jde-gen-comments: %S jde-gen-k&r: %S ****/\n\n"
3442                            jde-gen-comments jde-gen-k&r))
3443            (loop for abbrev in
3444                  '(("if"      (clause . "true"))
3445                    ("else")
3446                    ("ife"     (clause . "true"))
3447                    ("eif"     (clause . "true"))
3448                    ("while"   (clause . "true"))
3449                    ("for"     (clause . "int i = 0; i < 10; i++"))
3450                    ("fori"    (var . "i") (upper-bound . "10"))
3451                    ("foriter" (var . "iter") (coll . "list"))
3452                    ("switch"  (clause . "digit") (first-value . "1"))
3453                    ("case"    (value . "2"))
3454                    ("try"     (clause . "Exception"))
3455                    ("catch"   (clause . "Exception"))
3456                    ("tryf"    (clause . "Exception"))
3457                    ("finally"))
3458                  do
3459                  (let (insertations
3460                        (abbrev-start-location (point)))
3461                    (insert (car abbrev))
3462                    (while (setq abbrev (cdr abbrev))
3463                      (setq insertations (car abbrev))
3464                      (tempo-save-named (car insertations) (cdr insertations)))
3465                    (jde-gen-abbrev-hook)
3466                    (goto-char (- (point-max) 2))
3467                    (insert "\n"))))))
3468
3469
3470
3471 (defun jde-gen-try-catch-wrapper (beg end)
3472   "Wrap the region from BEG to END into a try/catch block.
3473 BEG and END are modified so the region only contains complete lines."
3474   (interactive "r")
3475   (jde-gen-generic-wrapper beg end "try" "catch"))
3476
3477 (defun jde-gen-try-finally-wrapper (beg end)
3478   "Wrap the region from BEG to END into a try/finally block.
3479 BEG and END are modified so the region only contains complete lines."
3480   (interactive "r")
3481   (jde-gen-generic-wrapper beg end "try" "finally"))
3482
3483 (defun jde-gen-if-wrapper (beg end) 
3484   "Wraps the region from beg to end into an if block."
3485   (interactive "r")
3486   (jde-gen-generic-wrapper beg end "if"))
3487
3488 (defun jde-gen-if-else-wrapper (beg end) 
3489   "Wraps the region from beg to end into an if block."
3490   (interactive "r")
3491   (jde-gen-generic-wrapper beg end "if" "else"))
3492
3493 ;;This code is a modified version of the method qflib-make-try-wrapper
3494 (defun jde-gen-generic-wrapper (beg end expr1 &optional expr2)
3495   "Wrap the region from BEG to END into a EXPR1 and EXPR2 block. if EXPR2 is
3496 nil it is omitted. BEG and END are modified so the region only contains
3497 complete lines."
3498   (let ((to (make-marker))
3499         indent-region-function)
3500     (set-marker to
3501                 (save-excursion
3502                   (goto-char end)
3503                   (if (and (bolp)
3504                            (not (= beg end)))
3505                       (point)
3506                     (end-of-line)
3507                     (1+ (point)))))
3508     (goto-char beg)
3509     (beginning-of-line)
3510     (insert expr1)
3511     (if (string= expr1 "if")
3512         (insert (concat jde-gen-conditional-padding-1
3513                         "(" jde-gen-conditional-padding-2 ")")))
3514     (if jde-gen-k&r
3515         (insert " ")
3516       (insert "\n"))
3517     (insert "{\n")
3518     (if jde-gen-k&r
3519         (forward-char -1)
3520       (forward-char -4))
3521     (indent-for-tab-command)
3522     (indent-region (point) to nil)
3523     (goto-char to)
3524     (insert "}")
3525     (if expr2
3526         (progn
3527           (if jde-gen-k&r
3528               (insert jde-gen-conditional-padding-3)
3529             (insert "\n"))
3530           (if (string= expr2 "catch")
3531               (insert (concat expr2 jde-gen-conditional-padding-1
3532                               "(" jde-gen-conditional-padding-2 " e"
3533                               jde-gen-conditional-padding-2 ")")) 
3534             (insert expr2))
3535           (if jde-gen-k&r 
3536               (insert jde-gen-conditional-padding-3)
3537             (insert "\n"))
3538           (insert "{\n}")
3539           (if jde-gen-comments
3540               (insert " // end of " expr1 
3541                       (if expr2
3542                           (concat "-" expr2))))))
3543     (insert "\n")
3544     (indent-region (marker-position to) (point) nil)
3545     (goto-char to)
3546     (if (string= expr1 "if")
3547         (search-backward (concat "(" jde-gen-conditional-padding-2 ")")))
3548     (if (string= expr2 "catch")
3549         (search-forward "("))))
3550
3551
3552 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3553 ;;                                                                           ;;
3554 ;;  Electric Return Mode                                                     ;;
3555 ;;                                                                           ;;
3556 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3557
3558 (defcustom jde-electric-return-p nil
3559   "Specifies whether the JDEE's electric return mode is 
3560 enabled for this session or project. This mode causes the JDEE to
3561 match an open brace at the end of a line with a closing
3562 brace. You can use `jde-toggle-electric-return' at any
3563 time to enable or disable eelctric return mode."
3564   :group 'jde-gen
3565   :type 'boolean
3566   :set '(lambda (sym val)
3567           (if (featurep 'jde)
3568             (let ((curr-project
3569                    (with-current-buffer jde-current-buffer
3570                      jde-current-project)))
3571               (mapc 
3572                (lambda (buf)
3573                  (with-current-buffer buf
3574                    (let ((key (car (read-from-string "[return]"))))
3575                        (if val
3576                            (define-key (current-local-map) key 'jde-electric-return)
3577                          (local-unset-key key)))))
3578                (jde-get-project-source-buffers))))
3579           (setq jde-electric-return-mode val)
3580           (set-default sym val)))
3581
3582 (defcustom jde-newline-function  '(newline)
3583   "Indent command that `jde-electric-return' calls."
3584   :group 'jde-gen
3585   :type '(list
3586           (radio-button-choice
3587            :format "%t \n%v"
3588            :tag "Function: "
3589            :entry-format " %b %v"
3590            (const newline)
3591            (const newline-and-indent)
3592            (const align-newline-and-indent)
3593            (function my-custom-newline-function))))
3594
3595 (defun jde-gen-embrace()
3596   "Match an open brace at the end of a line
3597 with a closing brace (if required), put point on a
3598 empty line between the braces, and indent the new lines.
3599
3600 So if before
3601 you had:
3602
3603    pubic void function () {
3604                            ^
3605 You now have:
3606
3607    pubic void function () {
3608                                     
3609    } ^
3610
3611 Point must be at the end of the line, or at a } character
3612 followed by the end of the line.
3613
3614 If it thinks a matching close brace already exists a new one is not inserted.
3615 Before:
3616    pubic void function () {
3617    }                       ^
3618 After:
3619    pubic void function () {
3620                                     
3621    } ^"
3622   (interactive)
3623   (if (or (eq (point) (point-min))
3624           (save-excursion
3625             (backward-char)
3626             (not (looking-at "{}?$"))))
3627       (newline-and-indent)
3628     ;; else
3629     (progn
3630       (newline-and-indent)
3631       (newline-and-indent)
3632       (when (not (looking-at "}"))
3633         (insert "}")
3634         (c-indent-command))
3635       (previous-line 1)
3636       (c-indent-command))))
3637
3638 (defun jde-electric-return ()
3639 "Invokes `jde-gen-embrace' to close an open brace at the end of a line."
3640   (interactive)
3641   (if  ;; the current line ends at an open brace.
3642        (and 
3643         (save-excursion
3644           (re-search-backward "{\\s-*" (line-beginning-position) t))  
3645         (looking-at "}?\\s-*$"))
3646       (jde-gen-embrace)
3647     (call-interactively (car jde-newline-function))))
3648
3649 (defvar jde-electric-return-mode nil 
3650   "Nonnil indicates that electric return mode is on.")
3651
3652 (defun jde-electric-return-mode ()
3653   "Toggles the JDEE's electric return mode. In electric
3654 return mode, pressing the Enter key causes the JDEE to
3655 close open braces at the end of a line. This command enables
3656 eletric return mode by binding `jde-electric-return' to the
3657 Return key on your keyboard. It disables electric return mode
3658 by rebinding the Return key to its original binding."
3659   (interactive)
3660   (when (boundp 'jde-mode-map)
3661     (let ((key (car (read-from-string "[return]"))))
3662            (if jde-electric-return-mode
3663                (local-unset-key key)
3664              (define-key (current-local-map) key 'jde-electric-return))))
3665   (setq jde-electric-return-mode (not jde-electric-return-mode))
3666   (if jde-electric-return-mode
3667       (message "electric return mode on")
3668     (message "electric return mode off")))
3669
3670
3671
3672 (provide 'jde-gen)
3673
3674 ;; Unit Test Table for JDE Gen Methods
3675 ;; -----------------------------------
3676
3677 ;;         Comm = jde-gen-comments|Comm t|Comm nil|Comm t  |Comm nil
3678 ;;          K&R = jde-gen-k&r     |K&R  t|K&R  t  |K&R  nil|K&R  nil
3679 ;; -------------------------------+------+--------+--------+--------
3680 ;; jde-gen-get-set                |      |        |        |        
3681 ;; jde-gen-inner-class            |      |        |        |        
3682 ;; jde-gen-action-listener        |      |        |        |        
3683 ;; jde-gen-change-listener        |      |        |        |        
3684 ;; jde-gen-window-listener        |      |        |        |        
3685 ;; jde-gen-mouse-listener         |      |        |        |        
3686 ;; jde-gen-mouse-motion-listener  |      |        |        |        
3687 ;; jde-gen-to-string-method       |      |        |        |        
3688 ;; jde-gen-property-change-support|      |        |        |        
3689 ;; jde-gen-entity-bean            |      |        |        |        
3690 ;; jde-gen-session-bean           |      |        |        |        
3691 ;; jde-gen-cflow-if               |      |        |        |        
3692 ;; jde-gen-cflow-else             |      |        |        |        
3693 ;; jde-gen-cflow-if-else          |      |        |        |        
3694 ;; jde-gen-cflow-else-if          |      |        |        |        
3695 ;; jde-gen-cflow-while            |      |        |        |        
3696 ;; jde-gen-cflow-for              |      |        |        |        
3697 ;; jde-gen-cflow-for-I            |      |        |        |        
3698 ;; jde-gen-cflow-for-iter         |      |        |        |        
3699 ;; jde-gen-cflow-main             |      |        |        |        
3700 ;; jde-gen-cflow-switch           |      |        |        |        
3701 ;; jde-gen-cflow-case             |      |        |        |        
3702 ;; jde-gen-cflow-try-catch        |      |        |        |        
3703 ;; jde-gen-cflow-catch            |      |        |        |        
3704 ;; jde-gen-cflow-try-finally      |      |        |        |        
3705 ;; jde-gen-cflow-finally          |      |        |        |        
3706
3707 ;; $Log: jde-gen.el,v $
3708 ;; Revision 1.86  2004/12/12 14:27:02  paulk
3709 ;; Add templates provided by Ole Arndt.
3710 ;;
3711 ;; Revision 1.85  2004/11/17 04:56:16  paulk
3712 ;; Update several templates to conform to CheckStyle requirements. Thanks to Martin Schwamberger.
3713 ;;
3714 ;; Revision 1.84  2004/10/11 03:40:23  paulk
3715 ;; Moved JUnit templates to jde-junit.el.
3716 ;;
3717 ;; Revision 1.83  2004/07/06 05:07:27  paulk
3718 ;; Move require for jde-package to jde-compat.el el allow autoloading of
3719 ;; jde-package without causing compile errors.
3720 ;;
3721 ;; Revision 1.82  2004/07/06 04:17:13  paulk
3722 ;; Require jde-package and other changes intended to eliminate byte-compilation errors.
3723 ;;
3724 ;; Revision 1.81  2004/07/06 01:43:55  paulk
3725 ;; Fix bug that caused inconsistent enabling of electric return mode.
3726 ;;
3727 ;; Revision 1.80  2004/06/29 03:39:29  paulk
3728 ;; Cosmetic change.
3729 ;;
3730 ;; Revision 1.79  2004/05/28 11:40:12  paulk
3731 ;; Add jde-gen-main-method to jde-gen-code-templates.
3732 ;;
3733 ;; Revision 1.78  2004/05/14 03:24:01  paulk
3734 ;; - Compatibility fix to make cflow abbreviations work in XEmacs.
3735 ;;   Thanks to Martin Schwamberger.
3736 ;; - Provide a new JDE->Code Generation->Modes menu with items for
3737 ;;   enabling abbrev mode and electric return mode.
3738 ;;
3739 ;; Revision 1.77  2004/05/14 02:13:04  paulk
3740 ;; Add jde-gen-test-cflow-templates command.
3741 ;;
3742 ;; Revision 1.76  2004/05/04 04:35:09  paulk
3743 ;; - Reworks the cflow templates so that tempo is no longer invoked if point is in an comment or string.
3744 ;; - jde-gen-comments now defaults to nil to permit control flow templates to conform to style guidelines.
3745 ;; - Cosmetic changes.
3746 ;;
3747 ;;   Thanks to Martin Schwamberger.
3748 ;;
3749 ;; Revision 1.75  2004/04/30 05:42:59  paulk
3750 ;; Implements electric return mode.
3751 ;;
3752 ;; Revision 1.74  2004/03/24 02:32:59  paulk
3753 ;; Correct version of jde-gen-save-excursion from Martin Schwamberger.
3754 ;;
3755 ;; Revision 1.73  2004/03/22 06:11:32  paulk
3756 ;; Changes by made Martin Schwamberg as part of his project to make the JDEE templates
3757 ;; conform to CheckStyle default style:
3758 ;;
3759 ;; jde-gen-read-template
3760 ;; - separates lines by newline in order to allow lisp comments.
3761 ;;
3762 ;; jde-gen-final-argument-modifier
3763 ;; - inserts final modifier to each method argument
3764 ;;    if jde-gen-final-arguments is t.
3765 ;;
3766 ;; jde-gen-final-method-modifier
3767 ;; - inserts final modifier to methods if jde-gen-final-methods is t
3768 ;;    and the class itself is not final.
3769 ;;
3770 ;; jde-gen-save-excursion
3771 ;; - allows invocation of tempo-templates within tempo-templates.
3772 ;;
3773 ;; jde-gen-electric-brace
3774 ;; - named after c-electric-brace, which is a candidate
3775 ;;    as a replacement of the current code once all
3776 ;;    templates use this function.
3777 ;; - inserts brace according to jde-gen-k&r.
3778 ;;    so far, used by
3779 ;;    jde-gen-class-buffer-template
3780 ;;    jde-gen-interface-buffer-template
3781 ;;    jde-gen-get-set-var-template
3782 ;;    jde-gen-method-template
3783 ;;
3784 ;; jde-gen-indent
3785 ;; - indents a line only if it is empty
3786 ;;
3787 ;; jde-gen-get-interface-implementation
3788 ;; - new argument insert-immediately.
3789 ;; - made insertion point a marker.
3790 ;;
3791 ;; jde-gen-method-signature
3792 ;; - inserts final modifiers using jde-gen-final-argument-modifier
3793 ;;    and jde-gen-final-methods.
3794 ;;
3795 ;; jde-gen-class-buffer-template
3796 ;; - completely reworked.
3797 ;;
3798 ;; jde-gen-class-buffer
3799 ;; - subsequent template manipulation removed.
3800 ;;
3801 ;; jde-gen-interface-buffer-template
3802 ;; - completely reworked.
3803 ;;
3804 ;; jde-gen-interface-buffer
3805 ;; - subsequent template manipulation removed.
3806 ;;
3807 ;; jde-gen-get-set-var-template
3808 ;; - rework
3809 ;;
3810 ;; jde-gen-method-template
3811 ;; - rework
3812 ;;
3813 ;; jde-gen-section-comment-template
3814 ;; - removed: "(end-of-line) '&"
3815 ;;
3816 ;; Revision 1.72  2004/03/04 05:19:38  paulk
3817 ;; Adds the jde-gen-embrace command. Thanks to Suraj Acharya.
3818 ;;
3819 ;; Revision 1.71  2004/02/02 07:31:13  paulk
3820 ;; Adds jde-gen-bean-template. Thanks to Paul Landes.
3821 ;;
3822 ;; Revision 1.70  2003/11/30 05:00:50  paulk
3823 ;; Fix control flow templates to preserve case of unexpanded
3824 ;; abbreviations in comments and strings.
3825 ;;
3826 ;; Revision 1.69  2003/09/22 03:14:55  paulk
3827 ;; Restore missing parentheses.
3828 ;;
3829 ;; Revision 1.68  2003/09/22 02:44:04  paulk
3830 ;; Fix bug that was causing an extraneous space to be inserted in the
3831 ;; condition clause of control flow expansions, such as if. Thanks to
3832 ;; Sandip Chitale.
3833 ;;
3834 ;; Revision 1.67  2003/09/01 03:04:23  paulk
3835 ;; Updates docstring for jde-gen-method-template to document its
3836 ;; dependence on the new jde-gen-method-javadoc-comment variable.
3837 ;;
3838 ;; Revision 1.66  2003/09/01 02:53:30  paulk
3839 ;; Adds a customization variable, jde-gen-method-javadoc-comment,
3840 ;; that enables you to specify the type of javadoc comment
3841 ;; that the jde-gen-method-template generates for a skeleton method.
3842 ;;
3843 ;; Revision 1.65  2003/07/26 04:22:46  paulk
3844 ;; Removed superfluous c-indent-function from control flow templates.
3845 ;;
3846 ;; Revision 1.64  2003/06/13 12:11:30  paulk
3847 ;; Fix typo. Update copyright.
3848 ;;
3849 ;; Revision 1.63  2003/03/03 14:51:26  jslopez
3850 ;; Fixes a few formatting problems with jde-gen-generic-wrapper.
3851 ;;
3852 ;; Revision 1.62  2003/03/01 00:04:29  jslopez
3853 ;; Add jde-gen-if-wrapper and jde-gen-if-else-wrapper.
3854 ;;
3855 ;; Revision 1.61  2003/02/17 21:39:43  jslopez
3856 ;; Fixes bug with jde-gen-change-listener-template.
3857 ;;
3858 ;; Revision 1.60  2003/01/21 14:15:53  jslopez
3859 ;; Adds jde-gen-change-listener template.
3860 ;;
3861 ;; Revision 1.59  2002/12/19 06:36:00  paulk
3862 ;; Changed to permit autoloading of jde-package.el file.
3863 ;;
3864 ;; Revision 1.58  2002/12/13 08:33:23  paulk
3865 ;; Enhance the following code templates
3866 ;;
3867 ;;   - jde-gen-interface-buffer-template
3868 ;;   - jde-gen-console-buffer-template
3869 ;;   - jde-gen-jfc-app-buffer-template
3870 ;;   - jde-gen-junit-test-class-buffer-template
3871 ;;
3872 ;; to use the following javadoc templates instead of
3873 ;; literal text:
3874 ;;
3875 ;;   - jde-javadoc-author-tag-template
3876 ;;   - jde-javadoc-version-tag-template
3877 ;;   - jde-javadoc-end-block-template
3878 ;;
3879 ;; Thanks to Peter Dobratz <dobratzp@ele.uri.edu>.
3880 ;;
3881 ;; Revision 1.57  2002/11/30 03:59:27  paulk
3882 ;; Changes the default value for jde-gen-class-buffer-template to use the
3883 ;; relevant tempo-template-jde-javadoc instead of literal text. This way
3884 ;; jde-gen-class-buffer reflects, for example, a change to
3885 ;; tempo-template-jde-javadoc-author-tag. Thanks to Peter Dobratz <dobratzp@ele.uri.edu>.
3886 ;;
3887 ;; Revision 1.56  2002/09/30 04:22:45  paulk
3888 ;; Expanded doc strings for jde-gen-entity/session-bean template commands to
3889 ;; explain their usage and to mention the existence of the more complete
3890 ;; jde-ejb-session/entity-buffer commands.
3891 ;;
3892 ;; Revision 1.55  2002/08/30 14:52:24  jslopez
3893 ;; Adds new method jde-gen-try-catch-wrapper and jde-gen-try-finally-wrapper.
3894 ;; You can select a region and call this method to wrap the area withing a
3895 ;; try/wrap.
3896 ;;
3897 ;; Revision 1.54  2002/08/11 14:03:53  paulk
3898 ;; Expanded doc for jde-gen-junit-test-class-buffer.
3899 ;;
3900 ;; Revision 1.53  2002/08/11 13:34:18  paulk
3901 ;; Add jde-gen-junit-test-class to list of class buffer templates.
3902 ;;
3903 ;; Revision 1.52  2002/06/21 06:42:20  paulk
3904 ;; Fixed bug in interface implementation code for class templates. Thanks to
3905 ;; Phillip Lord for reporting the bug.
3906 ;;
3907 ;; Revision 1.51  2002/05/31 19:02:27  mnl
3908 ;; Added new template to generate a new interface from scratch.
3909 ;;
3910 ;; Revision 1.50  2002/05/14 06:29:56  paulk
3911 ;; Enhances code generation wizards for implementing interfaces, abstract
3912 ;; classes, etc., to use customizable templates to generate skeleton methods
3913 ;; instead of hard-wired skeletons. Thanks to "Dr. Michael Lipp" <lipp@danet.de>
3914 ;; for proposing and implementing this improvement.
3915 ;;
3916 ;; Revision 1.49  2002/04/10 04:18:28  paulk
3917 ;; The JDEE now imports the superclasses of classes that it creates. Thanks
3918 ;; to "Timothy Babin"<tbabin@nortelnetworks.com>.
3919 ;;
3920 ;; Revision 1.48  2002/02/03 07:51:16  paulk
3921 ;; Fixes spacing bug in jde-gen-class-buffer-template.
3922 ;; Thanks to Petter Mahlen.
3923 ;;
3924 ;; Revision 1.47  2002/01/06 05:59:32  paulk
3925 ;; Changed the name of the println and toString templates to println
3926 ;; and to-string-method, respectively, thereby eliminating the
3927 ;; spaces that were in the previous names.
3928 ;;
3929 ;; Revision 1.46  2001/11/21 06:48:09  paulk
3930 ;; Fixed typo jde-gen-signature-padding-3. Thanks to David A. Ventimiglia.
3931 ;;
3932 ;; Revision 1.45  2001/11/05 05:01:51  paulk
3933 ;; Removed debugging form.
3934 ;;
3935 ;; Revision 1.44  2001/11/03 06:32:11  paulk
3936 ;; Restore JUnit templates.
3937 ;;
3938 ;; Revision 1.43  2001/11/02 06:59:58  paulk
3939 ;; Revamps code generation templates to make them more
3940 ;; consistent among themselves and with Java coding
3941 ;; conventions. Specific changes include:
3942 ;;
3943 ;;   - Generates consistent formats for method signatures.
3944 ;;   - Strips prefix and suffix of variable names (if configured)
3945 ;;   - Adds jde-gen-conditional-padding-1 to -3 to allow for
3946 ;;     configurability of the jde-gen-cflow-* templates
3947 ;;   - Changes many default templates to conform to Java code
3948 ;;     conventions
3949 ;;   - Fixes many subtle inconsistencies in templates when used
3950 ;;     with different values for jde-gen-comments and jde-gen-k&r
3951 ;;   - All templates now have consistent coding structure
3952 ;;     and indentation, as well as reduced insertion of white-space.
3953 ;;   - Modifies Javadoc comments to be less descriptive of implementation
3954 ;;     (e.g. instead of "Get the value of _flag", now is
3955 ;;     "Get the Flag value")
3956 ;;
3957 ;;     Thanks to Greg Fenton.
3958 ;;
3959 ;; Revision 1.42  2001/10/25 15:08:30  jslopez
3960 ;; Fixing hard coded strings in the javadoc
3961 ;; for the junit test class template.
3962 ;;
3963 ;; Revision 1.41  2001/10/25 02:58:34  jslopez
3964 ;; Fixing bug in JUnit template caused by a class
3965 ;; whose name does not contain the word Test.
3966 ;;
3967 ;; Revision 1.40  2001/10/25 02:14:45  jslopez
3968 ;; Adds JUnit supports
3969 ;; Add templates jde-gen-junit-test-class
3970 ;; and jde-gen-junit-add-test-to-suite
3971 ;;
3972 ;; Revision 1.39  2001/10/21 06:10:40  paulk
3973 ;; Extends the jde-gen-comments flag to all cflow templates.
3974 ;; Thanks to Robert Mecklenburg <mecklen@cimsoft.com>.
3975 ;;
3976 ;; Revision 1.38  2001/08/26 02:14:37  paulk
3977 ;; Fixed catch and tryf templates. Thanks to Javier Lopes.
3978 ;;
3979 ;; Revision 1.37  2001/06/30 12:35:28  paulk
3980 ;; Adds jde-gen-define-abbrev-template function.
3981 ;;
3982 ;; Revision 1.36  2001/06/10 04:07:05  paulk
3983 ;; Adds a control flow template for a for iterator loop. Thanks to Robert Mecklenburg <mecklen@cimsoft.com>.
3984 ;;
3985 ;; Revision 1.35  2001/06/05 05:33:10  paulk
3986 ;; Added else-f control flow template. Thanks to "Javier Lopez" <jlopez@cellexchange.com>.
3987 ;;
3988 ;; Revision 1.34  2001/06/05 04:54:49  paulk
3989 ;; Minor updates.
3990 ;;
3991 ;; Revision 1.33  2001/05/21 06:48:16  paulk
3992 ;; The class buffer template now generates skeletal implementations of interfaces that the class implements. Thanks to Javier Lopez for this enhancement.
3993 ;;
3994 ;; The inner class template now generates skeletal implementations of interfaces implemented by the class.
3995 ;;
3996 ;; Revision 1.32  2001/03/16 03:57:37  paulk
3997 ;; Fixed author line in javadoc comments. Thanks to Karel.Sprenger@compaq.com.
3998 ;;
3999 ;; Revision 1.31  2001/02/22 05:05:29  paulk
4000 ;; The class, console app, and Swing app templates now prompt you to enter a package name. The prompt includes a suggested package name based on the location of the current directory in the classpath.
4001 ;;
4002 ;; Revision 1.30  2001/01/19 04:28:09  paulk
4003 ;; Adds cflow expansions for try, catch, and finally. Thanks to Venkatesh Prasad Ranganath <rvprasad@ksu.edu> for these expansions.
4004 ;;
4005 ;; Revision 1.29  2000/12/18 05:22:45  paulk
4006 ;; *** empty log message ***
4007 ;;
4008 ;; Revision 1.28  2000/09/30 16:50:20  paulk
4009 ;; Correct type in jde-gen-cflow-enable.
4010 ;;
4011 ;; Revision 1.27  2000/09/07 04:37:28  paulk
4012 ;; Tweaked get-set pair template to indent correctly. Thanks to Lou Aloia <xlxa@rims.com> for this fix.
4013 ;;
4014 ;; Revision 1.26  2000/08/19 05:10:05  paulk
4015 ;; Adds jde-gen-cflow-enable variable.
4016 ;;
4017 ;; Revision 1.25  2000/07/23 02:44:44  paulk
4018 ;; Templates now indent correctly when inserted in a buffer. Thanks to el mono <mono@utp.edu.co> for this enhancement.
4019 ;;
4020 ;; Revision 1.24  2000/07/20 06:08:59  paulk
4021 ;; Extended K&R coding style to all templates. Thanks to Stephane Nicolas <s.nicolas@videotron.ca> for doing this.
4022 ;;
4023 ;; Revision 1.23  2000/06/28 02:46:48  paulk
4024 ;; Get/set pair template now generates correct method name for getting the value of boolean variables. Thanks to Stephane <s.nicolas@videotron.ca> for contributing this fix.
4025 ;;
4026 ;; Revision 1.22  2000/06/01 06:43:01  paulk
4027 ;; Added control flow templates contributed by Eric D. Friedman <friedman@lmi.net>.
4028 ;;
4029 ;; Revision 1.21  2000/02/01 05:22:51  paulk
4030 ;; Provide choice of coding styles for code generated by templates. Thanks to Jari Aalto for this enhancement.
4031 ;;
4032 ;; Revision 1.20  1999/09/23 03:23:41  paulk
4033 ;; Added code templates implementing EJB EntityBean and SessionBean
4034 ;; interfaces. Thanks to Brendan.Burns@tfsma-ims.tfn.com for contributing
4035 ;; the templates.
4036 ;;
4037 ;; Revision 1.19  1999/08/29 04:29:18  paulk
4038 ;; Patches provided by Michael Ernst <mernst@alum.mit.edu>
4039 ;;
4040 ;; Revision 1.18  1999/02/11 17:03:00  paulk
4041 ;; Updated the Swing application template to the JDK 1.2 Swing package
4042 ;; scheme and expanded the template to provide a menu and scrollable
4043 ;; canvas.
4044 ;;
4045 ;; Revision 1.17  1998/09/16 22:55:51  paulk
4046 ;; Added template for Java bean property change support.
4047 ;;
4048 ;; Revision 1.16  1998/09/13 00:34:28  paulk
4049 ;; Added a template for generating a System.out.println statement.
4050 ;;
4051 ;; Revision 1.15  1998/07/22 00:28:04  paulk
4052 ;; Modified class buffer creation templates to use tempo-marks
4053 ;; to mark initial position for user to insert code. Thanks
4054 ;; to David Hull <david.hull@trw.com> for suggesting this.
4055 ;;
4056 ;; Revision 1.14  1998/07/06 06:39:42  paulk
4057 ;; class buffer template now prompts for super class and
4058 ;; interface
4059 ;;
4060 ;; Revision 1.13  1998/07/06 05:06:13  paulk
4061 ;; Added boilerlate to other buffer generation templates.
4062 ;;
4063 ;; Revision 1.12  1998/07/01 03:54:40  paulk
4064 ;; Added source file boilerplate support.
4065 ;;
4066 ;; Revision 1.11  1998/06/27 03:04:46  paulk
4067 ;; Fixed capitalization on get-set method pair. Thanks to Jere_McDevitt@HomeDepot.COM
4068 ;;
4069 ;; Revision 1.10  1998/06/17 03:49:21  paulk
4070 ;; Fixed bug that caused jfc-app to be generated instead of console app.
4071 ;; Added a mouse motion listener template.
4072 ;; Added a toString method template.
4073 ;;
4074 ;; Revision 1.9  1998/05/27 05:55:20  paulk
4075 ;; Added autoload comments.
4076 ;;
4077 ;; Revision 1.8  1998/05/27 05:51:20  paulk
4078 ;; *** empty log message ***
4079 ;;
4080 ;; Revision 1.7  1998/05/17 06:20:37  paulk
4081 ;; Added templates for a Swing application and an inner class.
4082 ;;
4083 ;; Fixed a bug in jde-gen-buffer
4084 ;;
4085 ;; Revision 1.6  1998/04/18 14:08:55  kinnucan
4086 ;; Fixes some bugs in the generated code.
4087 ;;
4088 ;; Revision 1.5  1998/04/10 02:55:00  kinnucan
4089 ;; * Updated some of the doc strings.
4090 ;;
4091 ;; Revision 1.4  1998/04/09 04:51:09  kinnucan
4092 ;; * Added the capability to define your own custom autocode templates.
4093 ;;   The facility consists of the following items:
4094 ;;
4095 ;;   - jde-gen-code-templates
4096 ;;
4097 ;;     Defines a list of templates for code inserted at point. The
4098 ;;     list by default contains the templates defined by the JDE.
4099 ;;     You can define your own templates and add them to the list,
4100 ;;     using the Emacs customization feature. See tempo.el for
4101 ;;     information on creating templates.
4102 ;;
4103 ;;   - jde-gen-buffer-templates
4104 ;;
4105 ;;     Defines a list of templates for code to be inserted in a
4106 ;;     newly created Java buffer.
4107 ;;
4108 ;;   - jde-gen-code (JDE->Generate->Custom)
4109
4110 ;;
4111 ;;     This command inserts a specified code template at point.
4112 ;;
4113 ;;   - jde-gen-buffer (Files->JDE New->Custom)
4114 ;;
4115 ;;     This command creates the specified buffer and inserts
4116 ;;     a specified template at the beginning of the buffer.
4117 ;;
4118 ;; Revision 1.3  1998/04/08 04:38:16  kinnucan
4119 ;; * Provided each template variable with a set function that regenerates
4120 ;;   the corresponding template command whenever the template is changed.
4121 ;;
4122 ;; Revision 1.2  1998/04/06 03:47:20  kinnucan
4123 ;; * Added jde-gen-class-buffer and jde-gen-console-buffer functions.
4124 ;;
4125 ;; Revision 1.1  1998/04/01 05:33:43  kinnucan
4126 ;; Initial revision
4127 ;;
4128
4129 ;; End of jde-gen.el