JDEE Resources
My JDEE emacs lisp functions
1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2 ;; ;;
3 ;; ToString Wizard - yoonforh edition ;;
4 ;; ;;
5 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6
7 (defcustom jde-wiz-tostring-sort-variables nil
8 "*Specifies whether or not to sort the list of variables in the
9 generated method or list them in the order defined in the file."
10 :group 'jde-wiz
11 :type 'boolean)
12
13 (defcustom jde-wiz-tostring-stringbuffer-size "100"
14 "*Specifies the initial size of the StringBuffer used to create the
15 result for the toString(). It is best to set this to a value large
16 enough for most of your work to prevent expansion of the
17 StringBuffer at runtime. You can always change the value in the
18 generated code to a smaller or larger one as needed."
19 :group 'jde-wiz-tostring
20 :type 'string)
21
22 (defcustom jde-wiz-tostring-variable-separator "\", \""
23 "*Specifies the string between each variable to separate them.
24 Examples: 2 spaces (the default), a comma and a space, newline, or a
25 method call (as long as the return value is a String).
26
27 Note: Remember this must result in a String in Java!"
28 :group 'jde-wiz-tostring
29 :type 'string)
30
31 (defcustom jde-wiz-tostring-static-members nil
32 "If on (nonnil), `jde-wiz-tostring' generates information of
33 static members of the class in the current buffer."
34 :group 'jde-wiz
35 :type 'boolean)
36
37 (defun jde-wiz-tostring()
38 "Generates a toString() method for tbe class at point. The method
39 returns a string comprising the values of the member variables defined
40 by the class. The string lists the variables in alphabetical
41 order if `jde-wiz-tostring-sort-variables' is on. The string uses the
42 string specified by `jde-wiz-tostring-variable-separator' to separate
43 the variables. The generated method uses a string buffer of the size
44 specified by `jde-wiz-tostring-stringbuffer-size' to build the string."
45 (interactive)
46 (let* ((class-name
47 (jde-parse-get-unqualified-name
48 (jde-parse-get-class-at-point)))
49 (variables
50 (semantic-find-nonterminal-by-token
51 'variable
52 (jde-wiz-get-class-parts
53 class-name
54 (semantic-find-nonterminal-by-token
55 'type
56 (semantic-bovinate-toplevel t)
57 ))))
58 (method
59 (concat
60 "/**\n"
61 " * {@inheritDoc}\n"
62 " */\n"
63 "public String toString()"
64 (if jde-gen-k&r " {\n" "\n{\n")
65 "return \"" class-name "(")))
66 ;; "final int sbSize = " jde-wiz-tostring-stringbuffer-size ";\n"
67 ;; "final String variableSeparator = " jde-wiz-tostring-variable-separator ";\n"
68 ;; "final StringBuffer sb = new StringBuffer(sbSize);\n\n")))
69
70 (setq variables (jde-wiz-filter-variables-by-typemodifier variables))
71
72 (if jde-wiz-tostring-sort-variables
73 (setq variables (semantic-sort-tokens-by-name-increasing variables)))
74
75 (setq size (length variables))
76
77 (while variables
78 (let* ((var (car variables))
79 (name (semantic-token-name var)) ;;variable name
80 (type (semantic-token-type var)) ;;variable type i.e. boolean
81 (staticp
82 (member "static"
83 (semantic-token-variable-modifiers var))) ;;is it static
84 (finalp
85 (member "final"
86 (semantic-token-variable-modifiers var)))) ;;is it final
87
88 (if (or (not staticp) jde-wiz-tostring-static-members)
89 (if (> (length variables) 1)
90 (setq method (concat method name " - \" + " name "\n+ \", "))
91 (setq method
92 (concat method name " - \" + " name "\n+ \")\";\n}\n")))
93 (setq size (- size 1))
94 )
95
96 (setq variables (cdr variables))))
97 ;; (setq method (concat method "[" (number-to-string size) "]"))
98 (if (= size 0)
99 (setq method
100 (concat method ")\";\n}\n")))
101
102 (insert method))
103
104 (jde-wiz-indent (point)))
105
106 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
107 ;; ;;
108 ;; jde-wiz-constructor - by yoonforh ;;
109 ;; ;;
110 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
111
112 (defun jde-wiz-constructor()
113 "Generates a constructor() method for tbe class at point. The method
114 returns a string comprising the values of the member variables defined
115 by the class."
116 (interactive)
117 (let* ((class-name
118 (jde-parse-get-unqualified-name
119 (jde-parse-get-class-at-point)))
120 (variables
121 (semantic-find-nonterminal-by-token
122 'variable
123 (jde-wiz-get-class-parts
124 class-name
125 (semantic-find-nonterminal-by-token
126 'type
127 (semantic-bovinate-toplevel t)
128 ))))
129 (method
130 (concat
131 "public " class-name "("))
132 (body)
133 )
134
135 (setq variables (jde-wiz-filter-variables-by-typemodifier variables))
136
137 (if jde-wiz-tostring-sort-variables
138 (setq variables (semantic-sort-tokens-by-name-increasing variables)))
139
140 (setq size (length variables))
141
142 (while variables
143 (let* ((var (car variables))
144 (name (semantic-token-name var)) ;;variable name
145 (type (semantic-token-type var)) ;;variable type i.e. boolean
146 (staticp
147 (member "static"
148 (semantic-token-variable-modifiers var))) ;;is it static
149 (finalp
150 (member "final"
151 (semantic-token-variable-modifiers var)))) ;;is it final
152
153 (if (or (not staticp) jde-wiz-tostring-static-members)
154 (progn
155 (if (> (length variables) 1)
156 (setq method (concat method type " " name ", "))
157 (setq method
158 (concat method type " " name (if jde-gen-k&r ") {\n" ")\n{\n")))
159 )
160 (setq body (concat body "this." name " = " name ";\n"))
161 ))
162 (if staticp (setq size (- size 1)))
163 (if finalp (setq size (- size 1)))
164
165 (setq variables (cdr variables))))
166 ;; (setq method (concat method "[" (number-to-string size) "]"))
167 (if (= size 0)
168 (setq method
169 (concat method (if jde-gen-k&r ") {\n" ")\n{\n"))))
170 (setq method
171 (concat method body "}\n"))
172
173 (insert method))
174
175 (jde-wiz-indent (point)))
176
177 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
178 ;; ;;
179 ;; jde-wiz-log-method - by yoonforh ;;
180 ;; ;;
181 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
182 ;;;###autoload
183 (defun jde-wiz-log-method()
184 "insert logger statement of a method or constructor"
185 (interactive)
186 (if (not (eq major-mode 'jde-mode))
187 (error "Major mode must be 'jde-mode'"))
188 (let ((found (jde-javadoc-nonterminal-at-line)))
189 (if (not found)
190 (error "No tag found at point")
191 (let* ((modifiers (semantic-tag-modifiers found))
192 (type (semantic-tag-type found))
193 (name (semantic-tag-name found))
194 (arguments (semantic-tag-function-arguments found))
195 (throws (semantic-tag-function-throws found))
196 (string
197 (concat
198 "if (logger.isLoggable(Level.FINEST))"
199 (if jde-gen-k&r " {\n" "\n{\n")
200 "logger.finest(\""
201 name
202 "(")))
203
204 (setq size (length arguments))
205
206 (while arguments
207 (let* ((arg (car arguments))
208 (name (semantic-tag-name arg)) ;;argument name
209 (type (semantic-tag-type arg)) ;;argument type i.e. boolean
210 )
211
212 (if (> (length arguments) 1)
213 (setq string (concat string name " - \" + " name " + \", "))
214 (setq string
215 (concat string name " - \" + " name " + \")\");\n}\n\n")))
216
217 (setq arguments (cdr arguments))))
218 ;; (setq string (concat string "[" (number-to-string size) "]"))
219 (if (= size 0)
220 (setq string
221 (concat string ")\");\n}\n\n")))
222 (insert string)
223 ))
224
225 (jde-wiz-indent (point))
226 ))
227
228 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
229 ;; ;;
230 ;; jde-wiz-logger-decl - by yoonforh ;;
231 ;; ;;
232 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
233 (defun jde-wiz-logger-decl()
234 "insert logger declaration statement of current class"
235 (interactive)
236 (if (not (eq major-mode 'jde-mode))
237 (error "Major mode must be 'jde-mode'"))
238 (let* ((class-name
239 (jde-parse-get-unqualified-name
240 (jde-parse-get-class-at-point)))
241 (package (jde-wiz-get-package-name)))
242 (progn
243 (if (not package)
244 (setq string (concat "private static Logger logger = Logger.getLogger(" class-name ".class.getName());\n\n"))
245 (setq string (concat "private static Logger logger = Logger.getLogger(\"" package "\");\n\n"))
246 (insert string)
247 (jde-wiz-indent (point)))
248 ))
249
250 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
251 ;; ;;
252 ;; jde-wiz-assign-args - by yoonforh ;;
253 ;; ;;
254 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
255 ;;;###autoload
256 (defun jde-wiz-assign-args()
257 "insert assign statements for each args of a method or constructor"
258 (interactive)
259 (if (not (eq major-mode 'jde-mode))
260 (error "Major mode must be 'jde-mode'"))
261 (let ((found (jde-yoonforh-nonterminal-at-line)))
262 (if (not found)
263 (error "No tag found at point")
264 (let* ((modifiers (semantic-tag-modifiers found))
265 (type (semantic-tag-type found))
266 (name (semantic-tag-name found))
267 (arguments (semantic-tag-function-arguments found))
268 (throws (semantic-tag-function-throws found)))
269 (while arguments
270 (let* ((arg (car arguments))
271 (name (semantic-tag-name arg)) ;;argument name
272 (type (semantic-tag-type arg)) ;;argument type i.e. boolean
273 )
274
275 (insert (concat "this." name " = " name ";\n"))
276 (setq arguments (cdr arguments))))
277 ;; (setq string (concat string "[" (number-to-string size) "]"))
278 ))
279
280 (jde-wiz-indent (point))
281 ))
282
283
284 (global-set-key [?\C-c?\C-v?l] 'jde-wiz-log-method)
285 (global-set-key [?\C-c?\C-v?s] 'jde-wiz-tostring)
286 (global-set-key [?\C-c?\C-v?a] 'jde-wiz-assign-args)
287 (global-set-key [?\C-c?\C-v?c] 'jde-wiz-constructor)
288 (global-set-key [?\C-c?\C-v?p] 'jde-wiz-logger-decl)
Binding for keymap jde-mode-map
As of JDEE 2.3.4
key binding --- ------- <f4> html-script-release-region C-c Prefix Command / c-electric-slash * c-electric-star , c-electric-semi&comma DEL c-electric-backspace C-d c-electric-delete-forward TAB c-indent-command ESC Prefix Command ) c-electric-paren ( c-electric-paren : c-electric-colon # c-electric-pound ; c-electric-semi&comma } c-electric-brace { c-electric-brace C-c C-v Prefix Command C-c . c-set-style C-c C-t c-toggle-auto-hungry-state C-c C-s c-show-syntactic-information C-c C-o c-set-offset C-c C-d c-toggle-hungry-state C-c C-c comment-region C-c C-b c-submit-bug-report C-c C-a c-toggle-auto-state C-c C-\ c-backslash-region C-c C-q c-indent-defun C-c C-u c-up-conditional C-c C-p c-backward-conditional C-c C-n c-forward-conditional ESC q c-fill-paragraph ESC j c-indent-new-comment-line ESC C-j c-indent-new-comment-line ESC e c-end-of-statement ESC a c-beginning-of-statement ESC C-q c-indent-exp ESC C-h c-mark-function C-c C-v . jde-complete-in-line C-c C-v C-. jde-complete C-c C-v C-] jde-run-etrace-next C-c C-v ESC jde-run-etrace-prev C-c C-v z jde-import-all C-c C-v t jde-gen-try-catch-wrapper C-c C-v o jde-wiz-override-method C-c C-v j jde-javadoc-autodoc-at-line C-c C-v i jde-wiz-implement-interface C-c C-v f jde-gen-try-finally-wrapper C-c C-v e jde-wiz-extend-abstract-class C-c C-v C-z jde-import-find-and-import C-c C-v C-y jde-open-class-at-point C-c C-v C-x jde-show-superclass-source C-c C-v C-w jde-help-symbol C-c C-v C-t jde-jdb-menu-debug-applet C-c C-v C-s speedbar-frame-mode C-c C-v C-r jde-run C-c C-v C-q jde-wiz-update-class-list C-c C-v C-p jde-save-project C-c C-v C-n jde-help-browse-jdk-doc C-c C-v C-l jde-gen-println C-c C-v C-k jde-bsh-run C-c C-v C-g jde-open-class-at-point C-c C-v C-f jde-find C-c C-v C-d jde-debug C-c C-v C-c jde-compile C-c C-v C-b jde-build C-c C-v C-a jde-run-menu-run-applet