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