author | Claus Gittinger <cg@exept.de> |
Sun, 03 Jul 2011 22:02:38 +0200 | |
changeset 10112 | 44ea589fbb3c |
parent 10111 | 97f2db2aca32 |
child 10126 | 4cf3c68412a7 |
permissions | -rw-r--r-- |
9988 | 1 |
" |
10097 | 2 |
Copyright (c) 2007-2010 Jan Vrany, SWING Research Group, Czech Technical University in Prague |
3 |
Copyright (c) 2009-2010 eXept Software AG |
|
9988 | 4 |
|
10097 | 5 |
Permission is hereby granted, free of charge, to any person |
6 |
obtaining a copy of this software and associated documentation |
|
7 |
files (the 'Software'), to deal in the Software without |
|
8 |
restriction, including without limitation the rights to use, |
|
9 |
copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
10 |
copies of the Software, and to permit persons to whom the |
|
11 |
Software is furnished to do so, subject to the following |
|
12 |
conditions: |
|
13 |
||
14 |
The above copyright notice and this permission notice shall be |
|
15 |
included in all copies or substantial portions of the Software. |
|
16 |
||
17 |
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, |
|
18 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
19 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
20 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
21 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
22 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
23 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|
24 |
OTHER DEALINGS IN THE SOFTWARE. |
|
9988 | 25 |
" |
26 |
"{ Package: 'stx:libtool' }" |
|
8776 | 27 |
|
28 |
"{ NameSpace: Tools }" |
|
29 |
||
30 |
ApplicationModel subclass:#MethodRewriter |
|
10097 | 31 |
instanceVariableNames:'replaceTextView classes searchTextView actionInProgresHolder |
32 |
infoHolder progressHolder templateSearchPatternHolder |
|
33 |
templateReplacePatternHolder selectedTemplateIndex templates |
|
34 |
selectedTabIndex selectedClassesHolder' |
|
35 |
classVariableNames:'' |
|
36 |
poolDictionaries:'' |
|
10112 | 37 |
category:'Interface-MethodRewriter' |
8776 | 38 |
! |
39 |
||
9988 | 40 |
!MethodRewriter class methodsFor:'documentation'! |
41 |
||
42 |
copyright |
|
43 |
" |
|
10097 | 44 |
Copyright (c) 2007-2010 Jan Vrany, SWING Research Group, Czech Technical University in Prague |
45 |
Copyright (c) 2009-2010 eXept Software AG |
|
46 |
||
47 |
Permission is hereby granted, free of charge, to any person |
|
48 |
obtaining a copy of this software and associated documentation |
|
49 |
files (the 'Software'), to deal in the Software without |
|
50 |
restriction, including without limitation the rights to use, |
|
51 |
copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
52 |
copies of the Software, and to permit persons to whom the |
|
53 |
Software is furnished to do so, subject to the following |
|
54 |
conditions: |
|
9988 | 55 |
|
10097 | 56 |
The above copyright notice and this permission notice shall be |
57 |
included in all copies or substantial portions of the Software. |
|
58 |
||
59 |
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, |
|
60 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
61 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
62 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
63 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
64 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
65 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|
66 |
OTHER DEALINGS IN THE SOFTWARE. |
|
9988 | 67 |
" |
68 |
! ! |
|
8776 | 69 |
|
70 |
!MethodRewriter class methodsFor:'examples'! |
|
71 |
||
72 |
templateReplaceAtIfAbsentByAtAifAbsentPut |
|
73 |
||
74 |
^Array |
|
75 |
with:'Replace Dictionary>>#at:ifAbsent: by #at:ifAbsentPut:' |
|
76 |
with: '``@dictionary |
|
77 |
at: ``@key |
|
78 |
ifAbsent: |
|
79 |
[| `@temps | |
|
80 |
`@.statements. |
|
81 |
``@dictionary at: ``@key put: ``@object]' |
|
82 |
with:'``@dictionary |
|
83 |
at: ``@key |
|
84 |
ifAbsentPut: |
|
85 |
[| `@temps | |
|
86 |
`@.statements. |
|
87 |
``@object]' |
|
88 |
||
89 |
"Created: / 12-12-2007 / 11:08:01 / janfrog" |
|
90 |
"Modified: / 17-02-2008 / 08:35:17 / janfrog" |
|
91 |
! |
|
92 |
||
10111
97f2db2aca32
added: #templateReplaceIsNilOrEmptyCollectionByIsEmptyOrNil
Claus Gittinger <cg@exept.de>
parents:
10110
diff
changeset
|
93 |
templateReplaceIsNilOrEmptyCollectionByIsEmptyOrNil |
97f2db2aca32
added: #templateReplaceIsNilOrEmptyCollectionByIsEmptyOrNil
Claus Gittinger <cg@exept.de>
parents:
10110
diff
changeset
|
94 |
|
97f2db2aca32
added: #templateReplaceIsNilOrEmptyCollectionByIsEmptyOrNil
Claus Gittinger <cg@exept.de>
parents:
10110
diff
changeset
|
95 |
^Array |
97f2db2aca32
added: #templateReplaceIsNilOrEmptyCollectionByIsEmptyOrNil
Claus Gittinger <cg@exept.de>
parents:
10110
diff
changeset
|
96 |
with:'Replace self halt by self error:''was: self halt''' |
97f2db2aca32
added: #templateReplaceIsNilOrEmptyCollectionByIsEmptyOrNil
Claus Gittinger <cg@exept.de>
parents:
10110
diff
changeset
|
97 |
with: '@receiver isNilOrEmptyCollection' |
97f2db2aca32
added: #templateReplaceIsNilOrEmptyCollectionByIsEmptyOrNil
Claus Gittinger <cg@exept.de>
parents:
10110
diff
changeset
|
98 |
with: '@receiver isEmptyOrNil''' |
97f2db2aca32
added: #templateReplaceIsNilOrEmptyCollectionByIsEmptyOrNil
Claus Gittinger <cg@exept.de>
parents:
10110
diff
changeset
|
99 |
|
97f2db2aca32
added: #templateReplaceIsNilOrEmptyCollectionByIsEmptyOrNil
Claus Gittinger <cg@exept.de>
parents:
10110
diff
changeset
|
100 |
"Created: / 03-07-2011 / 21:59:47 / cg" |
97f2db2aca32
added: #templateReplaceIsNilOrEmptyCollectionByIsEmptyOrNil
Claus Gittinger <cg@exept.de>
parents:
10110
diff
changeset
|
101 |
! |
97f2db2aca32
added: #templateReplaceIsNilOrEmptyCollectionByIsEmptyOrNil
Claus Gittinger <cg@exept.de>
parents:
10110
diff
changeset
|
102 |
|
8776 | 103 |
templateReplaceSelfHaltBySelfError |
104 |
||
105 |
^Array |
|
106 |
with:'Replace self halt by self error:''was: self halt''' |
|
107 |
with: 'self halt' |
|
108 |
with: 'self error:''was: self error''' |
|
109 |
||
110 |
"Created: / 12-12-2007 / 11:29:51 / janfrog" |
|
111 |
"Modified: / 17-02-2008 / 08:35:09 / janfrog" |
|
112 |
! |
|
113 |
||
114 |
templates |
|
115 |
||
116 |
|templateSelectors| |
|
117 |
||
118 |
templateSelectors := |
|
119 |
(self class selectors select:[:e|(e startsWith:'template') |
|
120 |
and:[e ~= #templates and:[e ~= #templatesSpec]]]). |
|
121 |
^templateSelectors |
|
122 |
collect:[:e|self perform:e] |
|
123 |
||
124 |
" |
|
125 |
self templates |
|
126 |
" |
|
127 |
||
128 |
"Created: / 12-12-2007 / 11:03:32 / janfrog" |
|
129 |
! ! |
|
130 |
||
131 |
!MethodRewriter class methodsFor:'interface specs'! |
|
132 |
||
133 |
classesSpec |
|
134 |
"This resource specification was automatically generated |
|
135 |
by the UIPainter of ST/X." |
|
136 |
||
137 |
"Do not manually edit this!! If it is corrupted, |
|
138 |
the UIPainter may not be able to read the specification." |
|
139 |
||
140 |
" |
|
141 |
UIPainter new openOnClass:Tools::MethodRewriter andSelector:#classesSpec |
|
142 |
Tools::MethodRewriter new openInterface:#classesSpec |
|
143 |
" |
|
144 |
||
145 |
<resource: #canvas> |
|
146 |
||
147 |
^ |
|
148 |
#(FullSpec |
|
149 |
name: classesSpec |
|
150 |
window: |
|
151 |
(WindowSpec |
|
152 |
label: 'Classes' |
|
153 |
name: 'Classes' |
|
154 |
min: (Point 10 10) |
|
155 |
bounds: (Rectangle 0 0 300 300) |
|
156 |
) |
|
157 |
component: |
|
158 |
(SpecCollection |
|
159 |
collection: ( |
|
160 |
(LabelSpec |
|
161 |
label: 'Hint: drag''n''drop classes from browser' |
|
162 |
name: 'HintLabel' |
|
163 |
layout: (LayoutFrame 0 0 0 0 0 1 30 0) |
|
164 |
translateLabel: true |
|
165 |
adjust: left |
|
166 |
) |
|
167 |
(SelectionInListModelViewSpec |
|
168 |
name: 'ClassesList' |
|
169 |
layout: (LayoutFrame 0 0 30 0 0 1 -30 1) |
|
170 |
model: selectedClassesHolder |
|
171 |
hasHorizontalScrollBar: true |
|
172 |
hasVerticalScrollBar: true |
|
173 |
listModel: classes |
|
174 |
multipleSelectOk: true |
|
175 |
useIndex: false |
|
176 |
highlightMode: line |
|
177 |
properties: |
|
178 |
(PropertyListDictionary |
|
179 |
dragArgument: nil |
|
180 |
dropArgument: nil |
|
181 |
canDropSelector: canDropClasses: |
|
182 |
dropSelector: doDropClasses: |
|
183 |
) |
|
184 |
) |
|
185 |
(ActionButtonSpec |
|
186 |
label: 'Remove selected classes' |
|
187 |
name: 'RemoveClassesButton' |
|
188 |
layout: (LayoutFrame 5 0 -25 1 -5 1 -5 1) |
|
189 |
translateLabel: true |
|
190 |
model: removeSeletedClassesAction |
|
191 |
) |
|
192 |
) |
|
193 |
||
194 |
) |
|
195 |
) |
|
196 |
||
197 |
"Modified: / 12-12-2007 / 12:07:17 / janfrog" |
|
198 |
! |
|
199 |
||
200 |
searchAndReplaceSpec |
|
201 |
"This resource specification was automatically generated |
|
202 |
by the UIPainter of ST/X." |
|
203 |
||
204 |
"Do not manually edit this!! If it is corrupted, |
|
205 |
the UIPainter may not be able to read the specification." |
|
206 |
||
207 |
" |
|
208 |
UIPainter new openOnClass:Tools::MethodRewriter andSelector:#searchAndReplaceSpec |
|
209 |
Tools::MethodRewriter new openInterface:#searchAndReplaceSpec |
|
210 |
" |
|
211 |
||
212 |
<resource: #canvas> |
|
213 |
||
214 |
^ |
|
215 |
#(FullSpec |
|
216 |
name: searchAndReplaceSpec |
|
217 |
window: |
|
218 |
(WindowSpec |
|
219 |
label: 'Method Rewriter' |
|
220 |
name: 'Method Rewriter' |
|
221 |
min: (Point 10 10) |
|
222 |
bounds: (Rectangle 0 0 418 294) |
|
223 |
) |
|
224 |
component: |
|
225 |
(SpecCollection |
|
226 |
collection: ( |
|
227 |
(VariableVerticalPanelSpec |
|
228 |
name: 'FindAndReplacePanel' |
|
229 |
layout: (LayoutFrame 0 0 0 0 0 1 -30 1) |
|
230 |
showHandle: true |
|
231 |
snapMode: both |
|
232 |
component: |
|
233 |
(SpecCollection |
|
234 |
collection: ( |
|
235 |
(ViewSpec |
|
236 |
name: 'FindBox' |
|
237 |
component: |
|
238 |
(SpecCollection |
|
239 |
collection: ( |
|
240 |
(LabelSpec |
|
241 |
label: 'Find:' |
|
242 |
name: 'FindLabel' |
|
243 |
layout: (LayoutFrame 0 0 0 0 0 1 20 0) |
|
244 |
translateLabel: true |
|
245 |
adjust: left |
|
246 |
) |
|
247 |
(TextEditorSpec |
|
248 |
name: 'FindText' |
|
249 |
layout: (LayoutFrame 0 0 20 0 0 1 0 1) |
|
250 |
hasHorizontalScrollBar: true |
|
251 |
hasVerticalScrollBar: true |
|
252 |
postBuildCallback: postBuildFindTextView: |
|
253 |
) |
|
254 |
) |
|
255 |
||
256 |
) |
|
257 |
) |
|
258 |
(ViewSpec |
|
259 |
name: 'ReplaceBox' |
|
260 |
component: |
|
261 |
(SpecCollection |
|
262 |
collection: ( |
|
263 |
(LabelSpec |
|
264 |
label: 'Replace with:' |
|
265 |
name: 'ReplaceLabel' |
|
266 |
layout: (LayoutFrame 0 0 0 0 0 1 20 0) |
|
267 |
translateLabel: true |
|
268 |
adjust: left |
|
269 |
) |
|
270 |
(TextEditorSpec |
|
271 |
name: 'ReplaceText' |
|
272 |
layout: (LayoutFrame 0 0 20 0 0 1 0 1) |
|
273 |
hasHorizontalScrollBar: true |
|
274 |
hasVerticalScrollBar: true |
|
275 |
postBuildCallback: postBuildReplaceTextView: |
|
276 |
) |
|
277 |
) |
|
278 |
||
279 |
) |
|
280 |
) |
|
281 |
) |
|
282 |
||
283 |
) |
|
284 |
handles: (Any 0.5 1.0) |
|
285 |
) |
|
286 |
(LabelSpec |
|
287 |
label: 'Enjoy' |
|
288 |
name: 'InfoLabel' |
|
289 |
layout: (LayoutFrame 5 0 -25 1 205 0 -5 1) |
|
290 |
visibilityChannel: actionInProgresHolder |
|
291 |
translateLabel: true |
|
292 |
labelChannel: infoHolder |
|
293 |
adjust: left |
|
294 |
) |
|
295 |
(ProgressIndicatorSpec |
|
296 |
name: 'ProgressIndicator' |
|
297 |
layout: (LayoutFrame 210 0 -25 1 -215 1 -5 1) |
|
298 |
visibilityChannel: actionInProgresHolder |
|
299 |
model: progressHolder |
|
300 |
) |
|
301 |
(ActionButtonSpec |
|
302 |
label: 'Search' |
|
303 |
name: 'SearchButton' |
|
304 |
layout: (LayoutFrame -210 1 -25 1 -110 1 -5 1) |
|
305 |
translateLabel: true |
|
306 |
model: doSearchAction |
|
307 |
) |
|
308 |
(ActionButtonSpec |
|
309 |
label: 'Rewrite' |
|
310 |
name: 'RewriteButton' |
|
311 |
layout: (LayoutFrame -105 1 -25 1 -5 1 -5 1) |
|
312 |
translateLabel: true |
|
313 |
model: doRewriteAction |
|
314 |
) |
|
315 |
) |
|
316 |
||
317 |
) |
|
318 |
) |
|
319 |
||
320 |
"Modified: / 12-12-2007 / 11:15:58 / janfrog" |
|
321 |
! |
|
322 |
||
323 |
templatesSpec |
|
324 |
"This resource specification was automatically generated |
|
325 |
by the UIPainter of ST/X." |
|
326 |
||
327 |
"Do not manually edit this!! If it is corrupted, |
|
328 |
the UIPainter may not be able to read the specification." |
|
329 |
||
330 |
" |
|
331 |
UIPainter new openOnClass:Tools::MethodRewriter andSelector:#templatesSpec |
|
332 |
Tools::MethodRewriter new openInterface:#templatesSpec |
|
333 |
" |
|
334 |
||
335 |
<resource: #canvas> |
|
336 |
||
337 |
^ |
|
338 |
#(FullSpec |
|
339 |
name: templatesSpec |
|
340 |
window: |
|
341 |
(WindowSpec |
|
342 |
label: 'Method Rewriter' |
|
343 |
name: 'Method Rewriter' |
|
344 |
min: (Point 10 10) |
|
345 |
bounds: (Rectangle 0 0 472 354) |
|
346 |
) |
|
347 |
component: |
|
348 |
(SpecCollection |
|
349 |
collection: ( |
|
350 |
(VariableVerticalPanelSpec |
|
351 |
name: 'FindAndReplacePanel' |
|
352 |
layout: (LayoutFrame 0 0 0 0 0 1 -30 1) |
|
353 |
showHandle: true |
|
354 |
snapMode: both |
|
355 |
component: |
|
356 |
(SpecCollection |
|
357 |
collection: ( |
|
358 |
(SelectionInListModelViewSpec |
|
359 |
name: 'SelectionInListModelView1' |
|
360 |
model: selectedTemplateIndex |
|
361 |
hasHorizontalScrollBar: true |
|
362 |
hasVerticalScrollBar: true |
|
363 |
listModel: templateNameList |
|
364 |
highlightMode: line |
|
365 |
) |
|
366 |
(ViewSpec |
|
367 |
name: 'FindBox' |
|
368 |
component: |
|
369 |
(SpecCollection |
|
370 |
collection: ( |
|
371 |
(LabelSpec |
|
372 |
label: 'Find:' |
|
373 |
name: 'FindLabel' |
|
374 |
layout: (LayoutFrame 0 0 0 0 0 1 20 0) |
|
375 |
translateLabel: true |
|
376 |
adjust: left |
|
377 |
) |
|
378 |
(TextEditorSpec |
|
379 |
name: 'FindText' |
|
380 |
layout: (LayoutFrame 0 0 20 0 0 1 0 1) |
|
381 |
model: templateSearchPatternHolder |
|
382 |
hasHorizontalScrollBar: true |
|
383 |
hasVerticalScrollBar: true |
|
384 |
) |
|
385 |
) |
|
386 |
||
387 |
) |
|
388 |
) |
|
389 |
(ViewSpec |
|
390 |
name: 'ReplaceBox' |
|
391 |
component: |
|
392 |
(SpecCollection |
|
393 |
collection: ( |
|
394 |
(LabelSpec |
|
395 |
label: 'Replace with:' |
|
396 |
name: 'ReplaceLabel' |
|
397 |
layout: (LayoutFrame 0 0 0 0 0 1 20 0) |
|
398 |
translateLabel: true |
|
399 |
adjust: left |
|
400 |
) |
|
401 |
(TextEditorSpec |
|
402 |
name: 'ReplaceText' |
|
403 |
layout: (LayoutFrame 0 0 20 0 0 1 0 1) |
|
404 |
model: templateReplacePatternHolder |
|
405 |
hasHorizontalScrollBar: true |
|
406 |
hasVerticalScrollBar: true |
|
407 |
) |
|
408 |
) |
|
409 |
||
410 |
) |
|
411 |
) |
|
412 |
) |
|
413 |
||
414 |
) |
|
415 |
handles: (Any 0.2 0.6 1.0) |
|
416 |
) |
|
417 |
(ActionButtonSpec |
|
418 |
label: 'Use as template' |
|
419 |
name: 'UseAsTemplateButton' |
|
420 |
layout: (LayoutFrame 0 0 -25 1 -5 1 -5 1) |
|
421 |
translateLabel: true |
|
422 |
model: useAsTemplateAction |
|
423 |
) |
|
424 |
) |
|
425 |
||
426 |
) |
|
427 |
) |
|
428 |
||
429 |
"Modified: / 12-12-2007 / 11:23:34 / janfrog" |
|
430 |
! |
|
431 |
||
432 |
windowSpec |
|
433 |
"This resource specification was automatically generated |
|
434 |
by the UIPainter of ST/X." |
|
435 |
||
436 |
"Do not manually edit this!! If it is corrupted, |
|
437 |
the UIPainter may not be able to read the specification." |
|
438 |
||
439 |
" |
|
440 |
UIPainter new openOnClass:Tools::MethodRewriter andSelector:#windowSpec |
|
441 |
Tools::MethodRewriter new openInterface:#windowSpec |
|
442 |
Tools::MethodRewriter open |
|
443 |
" |
|
444 |
||
445 |
<resource: #canvas> |
|
446 |
||
447 |
^ |
|
448 |
#(FullSpec |
|
449 |
name: windowSpec |
|
450 |
window: |
|
451 |
(WindowSpec |
|
452 |
label: 'Method Rewriter' |
|
453 |
name: 'Method Rewriter' |
|
454 |
min: (Point 10 10) |
|
455 |
bounds: (Rectangle 0 0 658 490) |
|
456 |
) |
|
457 |
component: |
|
458 |
(SpecCollection |
|
459 |
collection: ( |
|
460 |
(NoteBookViewSpec |
|
461 |
name: 'NoteBook' |
|
462 |
layout: (LayoutFrame 0 0 0 0 0 1 0 1) |
|
463 |
model: selectedTabIndex |
|
464 |
menu: tabList |
|
465 |
useIndex: true |
|
466 |
fitLastRow: false |
|
467 |
) |
|
468 |
) |
|
469 |
||
470 |
) |
|
471 |
) |
|
472 |
||
473 |
"Modified: / 12-12-2007 / 11:39:31 / janfrog" |
|
474 |
! ! |
|
475 |
||
476 |
!MethodRewriter class methodsFor:'list specs'! |
|
477 |
||
478 |
tabList |
|
479 |
"This resource specification was automatically generated |
|
480 |
by the TabListEditor of ST/X." |
|
481 |
||
482 |
"Do not manually edit this!! If it is corrupted, |
|
483 |
the TabListEditor may not be able to read the specification." |
|
484 |
||
485 |
" |
|
486 |
TabListEditor new openOnClass: self andSelector:#tabList |
|
487 |
" |
|
488 |
||
489 |
<resource: #tabList> |
|
490 |
||
491 |
^ #( |
|
492 |
(TabItem |
|
493 |
label: 'Search and Replace' |
|
494 |
createNewBuilder: false |
|
495 |
minorKey: searchAndReplaceSpec |
|
496 |
) |
|
497 |
(TabItem |
|
498 |
label: 'Classes' |
|
499 |
createNewBuilder: false |
|
500 |
minorKey: classesSpec |
|
501 |
) |
|
502 |
(TabItem |
|
503 |
label: 'Templates' |
|
504 |
createNewBuilder: false |
|
505 |
minorKey: templatesSpec |
|
506 |
) |
|
507 |
) |
|
508 |
||
509 |
collect:[:aTab| TabItem new fromLiteralArrayEncoding:aTab ] |
|
510 |
||
511 |
"Modified: / 12-12-2007 / 11:21:27 / janfrog" |
|
512 |
! ! |
|
513 |
||
514 |
!MethodRewriter methodsFor:'accessing'! |
|
515 |
||
516 |
actionInProgress: aBoolean |
|
517 |
||
518 |
^self actionInProgresHolder value: aBoolean |
|
519 |
||
520 |
"Created: / 12-12-2007 / 10:06:16 / janfrog" |
|
521 |
! |
|
522 |
||
523 |
classes |
|
524 |
^ classes ifNil:[classes := List new] |
|
525 |
||
526 |
"Created: / 20-07-2007 / 16:31:18 / janfrog" |
|
527 |
! |
|
528 |
||
529 |
classes: aCollection |
|
530 |
classes := (aCollection collect:[:cls|cls theNonMetaclass]) asList |
|
531 |
||
532 |
"Created: / 20-07-2007 / 16:31:18 / janfrog" |
|
533 |
"Modified: / 12-12-2007 / 09:47:01 / janfrog" |
|
534 |
! |
|
535 |
||
536 |
info: aString |
|
537 |
||
538 |
self infoHolder value: aString |
|
539 |
||
540 |
"Created: / 12-12-2007 / 10:00:50 / janfrog" |
|
541 |
! |
|
542 |
||
543 |
progress: anInteger |
|
544 |
||
545 |
self progressHolder value: anInteger |
|
546 |
||
547 |
"Created: / 12-12-2007 / 10:01:03 / janfrog" |
|
548 |
! |
|
549 |
||
550 |
replacePattern |
|
551 |
^ replaceTextView contents trimSeparators |
|
552 |
||
553 |
"Created: / 21-07-2007 / 06:29:22 / janfrog" |
|
554 |
! |
|
555 |
||
556 |
replacePattern: pattern |
|
557 |
^ replaceTextView contents: pattern trimSeparators |
|
558 |
||
559 |
"Created: / 12-12-2007 / 11:38:22 / janfrog" |
|
560 |
! |
|
561 |
||
562 |
searchPattern |
|
563 |
^ searchTextView contents trimSeparators |
|
564 |
||
565 |
"Created: / 20-07-2007 / 16:51:49 / janfrog" |
|
566 |
"Modified: / 21-07-2007 / 06:29:29 / janfrog" |
|
567 |
! |
|
568 |
||
569 |
searchPattern: pattern |
|
570 |
^ searchTextView contents: pattern trimSeparators |
|
571 |
||
572 |
"Created: / 12-12-2007 / 11:38:12 / janfrog" |
|
573 |
! |
|
574 |
||
575 |
selectedClasses |
|
576 |
||
577 |
^self selectedClassesHolder value |
|
578 |
||
579 |
"Created: / 12-12-2007 / 12:02:03 / janfrog" |
|
580 |
! |
|
581 |
||
582 |
selectedTemplate |
|
583 |
||
584 |
^self templates at:self selectedTemplateIndex value |
|
585 |
||
586 |
"Created: / 12-12-2007 / 11:20:32 / janfrog" |
|
587 |
! |
|
588 |
||
589 |
templates |
|
590 |
templates isNil ifTrue:[ |
|
591 |
templates := self class templates. |
|
592 |
]. |
|
593 |
^ templates |
|
594 |
||
595 |
"Created: / 12-12-2007 / 11:17:55 / janfrog" |
|
596 |
! ! |
|
597 |
||
598 |
!MethodRewriter methodsFor:'actions'! |
|
599 |
||
600 |
doRewrite |
|
601 |
||
602 |
| methodsMatching | |
|
603 |
methodsMatching := self methodsMatching. |
|
604 |
methodsMatching isNilOrEmptyCollection ifTrue:[^Dialog warn:'No methods matching']. |
|
605 |
methodsMatching do: |
|
606 |
[:mth| |
|
607 |
| newTree | |
|
608 |
newTree := ParseTreeRewriter new |
|
609 |
replace: self searchPattern with: self replacePattern; |
|
610 |
executeTree: mth parseTree; |
|
611 |
tree. |
|
612 |
mth mclass |
|
613 |
compile: newTree formattedCode |
|
614 |
classified: mth category |
|
615 |
]. |
|
616 |
||
617 |
"Created: / 20-07-2007 / 16:03:47 / janfrog" |
|
618 |
"Modified: / 21-07-2007 / 06:55:42 / janfrog" |
|
619 |
! |
|
620 |
||
621 |
doRewriteAction |
|
622 |
||
623 |
self |
|
624 |
doSearch: self searchPattern |
|
625 |
withResultDo: |
|
626 |
[:methodsMatching| |
|
627 |
self |
|
628 |
withMethods:methodsMatching |
|
629 |
do: |
|
630 |
[:mth| |
|
631 |
| newTree | |
|
632 |
newTree := ParseTreeRewriter new |
|
633 |
replace: self searchPattern with: self replacePattern; |
|
634 |
executeTree: mth parseTree; |
|
635 |
tree. |
|
636 |
mth mclass ifNotNil: |
|
637 |
[mth mclass |
|
638 |
compile: newTree formattedCode |
|
639 |
classified: mth category]] |
|
640 |
finallyDo:[]] |
|
641 |
||
642 |
"Created: / 12-12-2007 / 11:14:19 / janfrog" |
|
643 |
! |
|
644 |
||
645 |
doSearch |
|
646 |
|methods| |
|
647 |
||
648 |
methods := self methodsMatching. |
|
649 |
methods isEmpty |
|
650 |
ifTrue: |
|
651 |
[Dialog warn:'Nothing found'] |
|
652 |
ifFalse: |
|
653 |
[self showMethods:methods |
|
654 |
title:'Methods matching ' , self searchPattern] |
|
655 |
||
656 |
"Created: / 20-07-2007 / 16:08:08 / janfrog" |
|
657 |
"Modified: / 21-07-2007 / 06:51:58 / janfrog" |
|
658 |
! |
|
659 |
||
660 |
doSearchAction |
|
661 |
||
662 |
self |
|
663 |
doSearch: self searchPattern |
|
664 |
withResultDo: |
|
665 |
[:matchingMethods| |
|
666 |
matchingMethods isEmpty |
|
667 |
ifTrue:[Dialog warn:'No methods found'] |
|
668 |
ifFalse: |
|
669 |
[self |
|
670 |
showMethods: matchingMethods asArray |
|
671 |
title: 'Methods matching ', self searchPattern]] |
|
672 |
||
673 |
"Created: / 12-12-2007 / 11:14:25 / janfrog" |
|
674 |
! |
|
675 |
||
676 |
removeSeletedClassesAction |
|
677 |
||
678 |
self classes removeAll: self selectedClasses |
|
679 |
||
680 |
"Created: / 12-12-2007 / 12:05:15 / janfrog" |
|
681 |
! |
|
682 |
||
683 |
useAsTemplateAction |
|
684 |
||
685 |
self searchPattern: self templateSearchPatternHolder value. |
|
686 |
self replacePattern: self templateReplacePatternHolder value. |
|
687 |
self selectedTabIndex value:1 |
|
688 |
||
689 |
"Created: / 12-12-2007 / 11:14:15 / janfrog" |
|
690 |
! ! |
|
691 |
||
692 |
!MethodRewriter methodsFor:'aspects'! |
|
693 |
||
694 |
actionInProgresHolder |
|
695 |
"automatically generated by UIPainter ..." |
|
696 |
||
697 |
"*** the code below creates a default model when invoked." |
|
698 |
"*** (which may not be the one you wanted)" |
|
699 |
"*** Please change as required and accept it in the browser." |
|
700 |
"*** (and replace this comment by something more useful ;-)" |
|
701 |
||
702 |
actionInProgresHolder isNil ifTrue:[ |
|
703 |
actionInProgresHolder := true asValue. |
|
704 |
"/ if your app needs to be notified of changes, uncomment one of the lines below: |
|
705 |
"/ actionInProgresHolder addDependent:self. |
|
706 |
"/ actionInProgresHolder onChangeSend:#actionInProgresHolderChanged to:self. |
|
707 |
]. |
|
708 |
^ actionInProgresHolder. |
|
709 |
||
710 |
"Created: / 12-12-2007 / 10:00:05 / janfrog" |
|
711 |
! |
|
712 |
||
713 |
infoHolder |
|
714 |
"automatically generated by UIPainter ..." |
|
715 |
||
716 |
"*** the code below creates a default model when invoked." |
|
717 |
"*** (which may not be the one you wanted)" |
|
718 |
"*** Please change as required and accept it in the browser." |
|
719 |
"*** (and replace this comment by something more useful ;-)" |
|
720 |
||
721 |
infoHolder isNil ifTrue:[ |
|
722 |
infoHolder := 'Really cool tool!!' asValue. |
|
723 |
"/ if your app needs to be notified of changes, uncomment one of the lines below: |
|
724 |
"/ infoHolder addDependent:self. |
|
725 |
"/ infoHolder onChangeSend:#infoHolderChanged to:self. |
|
726 |
]. |
|
727 |
^ infoHolder. |
|
728 |
||
729 |
"Created: / 12-12-2007 / 10:00:05 / janfrog" |
|
730 |
"Modified: / 12-12-2007 / 11:40:17 / janfrog" |
|
731 |
! |
|
732 |
||
733 |
progressHolder |
|
734 |
"automatically generated by UIPainter ..." |
|
735 |
||
736 |
"*** the code below creates a default model when invoked." |
|
737 |
"*** (which may not be the one you wanted)" |
|
738 |
"*** Please change as required and accept it in the browser." |
|
739 |
"*** (and replace this comment by something more useful ;-)" |
|
740 |
||
741 |
progressHolder isNil ifTrue:[ |
|
742 |
progressHolder := 0 asValue |
|
743 |
"/ if your app needs to be notified of changes, uncomment one of the lines below: |
|
744 |
"/ progressHolder addDependent:self. |
|
745 |
"/ progressHolder onChangeSend:#progressHolderChanged to:self. |
|
746 |
]. |
|
747 |
^ progressHolder. |
|
748 |
||
749 |
"Created: / 12-12-2007 / 10:00:05 / janfrog" |
|
750 |
! |
|
751 |
||
752 |
selectedClassesHolder |
|
753 |
"automatically generated by UIPainter ..." |
|
754 |
||
755 |
"*** the code below creates a default model when invoked." |
|
756 |
"*** (which may not be the one you wanted)" |
|
757 |
"*** Please change as required and accept it in the browser." |
|
758 |
"*** (and replace this comment by something more useful ;-)" |
|
759 |
||
760 |
selectedClassesHolder isNil ifTrue:[ |
|
761 |
selectedClassesHolder := ValueHolder new. |
|
762 |
"/ if your app needs to be notified of changes, uncomment one of the lines below: |
|
763 |
"/ selectedClassesHolder addDependent:self. |
|
764 |
"/ selectedClassesHolder onChangeSend:#selectedClassesHolderChanged to:self. |
|
765 |
]. |
|
766 |
^ selectedClassesHolder. |
|
767 |
||
768 |
"Created: / 12-12-2007 / 12:01:40 / janfrog" |
|
769 |
! |
|
770 |
||
771 |
selectedTabIndex |
|
772 |
"automatically generated by UIPainter ..." |
|
773 |
||
774 |
"*** the code below creates a default model when invoked." |
|
775 |
"*** (which may not be the one you wanted)" |
|
776 |
"*** Please change as required and accept it in the browser." |
|
777 |
"*** (and replace this comment by something more useful ;-)" |
|
778 |
||
779 |
selectedTabIndex isNil ifTrue:[ |
|
780 |
selectedTabIndex := ValueHolder new. |
|
781 |
"/ if your app needs to be notified of changes, uncomment one of the lines below: |
|
782 |
"/ selectedTabIndex addDependent:self. |
|
783 |
"/ selectedTabIndex onChangeSend:#selectedTabIndexChanged to:self. |
|
784 |
]. |
|
785 |
^ selectedTabIndex. |
|
786 |
||
787 |
"Created: / 12-12-2007 / 11:39:29 / janfrog" |
|
788 |
! |
|
789 |
||
790 |
selectedTemplateIndex |
|
791 |
||
792 |
selectedTemplateIndex isNil ifTrue:[ |
|
793 |
selectedTemplateIndex := ValueHolder new. |
|
794 |
selectedTemplateIndex onChangeSend:#selectedTemplateIndexChanged to:self. |
|
795 |
]. |
|
796 |
^ selectedTemplateIndex. |
|
797 |
||
798 |
"Created: / 12-12-2007 / 11:17:16 / janfrog" |
|
799 |
! |
|
800 |
||
801 |
tabList |
|
802 |
"Generated by the TabListEditor" |
|
803 |
||
804 |
|list| |
|
805 |
||
806 |
(list := builder bindingAt:#tabList) isNil ifTrue:[ |
|
807 |
builder aspectAt:#tabList put:(list := self class tabList). |
|
808 |
]. |
|
809 |
^ list |
|
810 |
||
811 |
"Created: / 20-07-2007 / 16:54:27 / janfrog" |
|
812 |
! |
|
813 |
||
814 |
templateNameList |
|
815 |
||
816 |
^self templates collect:[:tmpl|tmpl first] |
|
817 |
||
818 |
"Created: / 12-12-2007 / 11:17:16 / janfrog" |
|
819 |
! |
|
820 |
||
821 |
templateReplacePatternHolder |
|
822 |
"automatically generated by UIPainter ..." |
|
823 |
||
824 |
"*** the code below creates a default model when invoked." |
|
825 |
"*** (which may not be the one you wanted)" |
|
826 |
"*** Please change as required and accept it in the browser." |
|
827 |
"*** (and replace this comment by something more useful ;-)" |
|
828 |
||
829 |
templateReplacePatternHolder isNil ifTrue:[ |
|
830 |
templateReplacePatternHolder := '' asValue. |
|
831 |
"/ if your app needs to be notified of changes, uncomment one of the lines below: |
|
832 |
"/ templateReplacePatternHolder addDependent:self. |
|
833 |
"/ templateReplacePatternHolder onChangeSend:#templateReplacePatternHolderChanged to:self. |
|
834 |
]. |
|
835 |
^ templateReplacePatternHolder. |
|
836 |
||
837 |
"Created: / 12-12-2007 / 11:17:16 / janfrog" |
|
838 |
! |
|
839 |
||
840 |
templateSearchPatternHolder |
|
841 |
"automatically generated by UIPainter ..." |
|
842 |
||
843 |
"*** the code below creates a default model when invoked." |
|
844 |
"*** (which may not be the one you wanted)" |
|
845 |
"*** Please change as required and accept it in the browser." |
|
846 |
"*** (and replace this comment by something more useful ;-)" |
|
847 |
||
848 |
templateSearchPatternHolder isNil ifTrue:[ |
|
849 |
templateSearchPatternHolder := '' asValue. |
|
850 |
"/ if your app needs to be notified of changes, uncomment one of the lines below: |
|
851 |
"/ templateSearchPatternHolder addDependent:self. |
|
852 |
"/ templateSearchPatternHolder onChangeSend:#templateSearchPatternHolderChanged to:self. |
|
853 |
]. |
|
854 |
^ templateSearchPatternHolder. |
|
855 |
||
856 |
"Created: / 12-12-2007 / 11:17:16 / janfrog" |
|
857 |
! ! |
|
858 |
||
859 |
!MethodRewriter methodsFor:'change & update'! |
|
860 |
||
861 |
selectedTemplateIndexChanged |
|
862 |
||
863 |
self templateSearchPatternHolder value: self selectedTemplate second. |
|
864 |
self templateReplacePatternHolder value: self selectedTemplate third. |
|
865 |
||
866 |
"Created: / 12-12-2007 / 11:20:16 / janfrog" |
|
867 |
! ! |
|
868 |
||
869 |
!MethodRewriter methodsFor:'drag & drop'! |
|
870 |
||
871 |
canDropClasses: dropContext |
|
872 |
||
873 |
^dropContext dropObjects allSatisfy: [:obj|obj isClassObject] |
|
874 |
||
875 |
"Created: / 20-07-2007 / 16:58:13 / janfrog" |
|
876 |
! |
|
877 |
||
878 |
doDropClasses: dropContext |
|
879 |
||
880 |
| newClasses | |
|
881 |
newClasses := dropContext dropObjects |
|
882 |
select:[:obj|obj isClassObject] |
|
883 |
thenCollect:[:obj|obj theObject]. |
|
884 |
newClasses := newClasses reject:[:cls|self classes includes:cls]. |
|
885 |
self classes |
|
886 |
addAll: newClasses; |
|
887 |
changed:#content |
|
888 |
||
889 |
"Created: / 20-07-2007 / 16:58:16 / janfrog" |
|
890 |
! ! |
|
891 |
||
892 |
!MethodRewriter methodsFor:'hooks'! |
|
893 |
||
894 |
postBuildFindTextView: scrollableView |
|
895 |
||
896 |
searchTextView := scrollableView scrolledView |
|
897 |
||
898 |
"Created: / 20-07-2007 / 15:55:16 / janfrog" |
|
899 |
! |
|
900 |
||
901 |
postBuildReplaceTextView: scrollableView |
|
902 |
||
903 |
replaceTextView := scrollableView scrolledView |
|
904 |
||
905 |
"Created: / 20-07-2007 / 15:55:29 / janfrog" |
|
906 |
! ! |
|
907 |
||
908 |
!MethodRewriter methodsFor:'private'! |
|
909 |
||
910 |
doSearch: pattern withResultDo: block |
|
911 |
||
912 |
| matchingMethods | |
|
913 |
matchingMethods := Set new. |
|
914 |
self |
|
915 |
withMethodsDo: |
|
9988 | 916 |
[:mth| | tree | |
917 |
tree := mth parseTree. |
|
918 |
tree ifNil:[self breakPoint: #jv] ifNotNil:[ |
|
8776 | 919 |
(ParseTreeSearcher new) |
920 |
matches:self searchPattern do:[:aNode :answer | matchingMethods add:mth ]; |
|
9988 | 921 |
executeTree: tree] |
922 |
] |
|
8776 | 923 |
finallyDo: |
924 |
[block value: matchingMethods] |
|
925 |
||
926 |
"Created: / 12-12-2007 / 10:34:50 / janfrog" |
|
9988 | 927 |
"Modified: / 07-04-2011 / 22:02:45 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
8776 | 928 |
! |
929 |
||
930 |
methods |
|
931 |
||
932 |
^self methodsFor: classes |
|
933 |
||
934 |
"Modified: / 21-07-2007 / 06:24:07 / janfrog" |
|
935 |
! |
|
936 |
||
937 |
methodsFor: aColletion |
|
938 |
||
939 |
^classes |
|
940 |
inject: Set new |
|
941 |
into: |
|
942 |
[:methods :cls| |
|
943 |
methods |
|
944 |
addAll: cls methodDictionary values; |
|
945 |
addAll: cls class methodDictionary values; |
|
946 |
yourself] |
|
947 |
||
948 |
"Created: / 21-07-2007 / 06:25:42 / janfrog" |
|
949 |
! |
|
950 |
||
951 |
methodsMatching |
|
952 |
||
953 |
^self methodsMatching: self searchPattern |
|
954 |
||
955 |
"Created: / 21-07-2007 / 06:26:44 / janfrog" |
|
956 |
! |
|
957 |
||
958 |
methodsMatching: searchPattern |
|
959 |
|matchingMethods| |
|
960 |
||
961 |
matchingMethods := OrderedCollection new. |
|
962 |
self methods do:[:mth | |
|
963 |
(ParseTreeSearcher new) |
|
964 |
matches:searchPattern do:[:aNode :answer | matchingMethods add:mth ]; |
|
965 |
executeTree:mth parseTree. |
|
966 |
]. |
|
967 |
^ matchingMethods |
|
968 |
||
969 |
"Created: / 21-07-2007 / 06:26:19 / janfrog" |
|
970 |
! |
|
971 |
||
972 |
showMethods: methods title: title |
|
973 |
||
974 |
NewSystemBrowser |
|
975 |
browseMethods:methods |
|
976 |
title:title |
|
977 |
sort:true |
|
978 |
||
979 |
"Created: / 21-07-2007 / 06:51:36 / janfrog" |
|
980 |
! |
|
981 |
||
982 |
withMethods: methods do: methodBlock finallyDo: finallyBlock |
|
983 |
||
984 |
[ |
|
985 |
self actionInProgress: true. |
|
986 |
methods asArray keysAndValuesDo: |
|
987 |
[:idx :mth| |
|
988 |
self info: mth selector storeString. |
|
989 |
methodBlock value: mth. |
|
990 |
self progress: ((100 / methods size) * idx) rounded]. |
|
991 |
finallyBlock value |
|
992 |
] ensure:[ |
|
993 |
"/self actionInProgress: false. |
|
994 |
self progress: 0. |
|
995 |
self info: '' |
|
996 |
] |
|
997 |
||
998 |
"Created: / 12-12-2007 / 10:32:16 / janfrog" |
|
999 |
! |
|
1000 |
||
1001 |
withMethodsDo: methodBlock finallyDo: finallyBlock |
|
1002 |
||
1003 |
^self |
|
1004 |
withMethods: self methods asArray |
|
1005 |
do: methodBlock |
|
1006 |
finallyDo: finallyBlock |
|
1007 |
||
1008 |
"Modified: / 12-12-2007 / 10:32:48 / janfrog" |
|
1009 |
! ! |
|
1010 |
||
1011 |
!MethodRewriter methodsFor:'testing method'! |
|
1012 |
||
1013 |
testXXX |
|
1014 |
self halt:'Was halt' |
|
1015 |
||
1016 |
"Created: / 21-07-2007 / 07:55:24 / janfrog" |
|
1017 |
"Modified: / 12-12-2007 / 10:45:20 / janfrog" |
|
1018 |
! ! |
|
1019 |
||
1020 |
!MethodRewriter class methodsFor:'documentation'! |
|
1021 |
||
8803 | 1022 |
version_CVS |
10112 | 1023 |
^ '$Header: /cvs/stx/stx/libtool/Tools__MethodRewriter.st,v 1.8 2011-07-03 20:02:38 cg Exp $' |
9988 | 1024 |
! |
1025 |
||
1026 |
version_SVN |
|
1027 |
^ '§Id: Tools__MethodRewriter.st 7486 2009-10-26 22:06:24Z vranyj1 §' |
|
8776 | 1028 |
! ! |