author | Claus Gittinger <cg@exept.de> |
Sat, 11 Nov 1995 16:41:09 +0100 | |
changeset 165 | df29ee4514c1 |
parent 142 | 1af2cc5f26f5 |
child 194 | 93155825c7a0 |
permissions | -rw-r--r-- |
36 | 1 |
" |
2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
45 | 3 |
All Rights Reserved |
36 | 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 |
||
75 | 13 |
'From Smalltalk/X, Version:2.10.4 on 24-feb-1995 at 5:09:20 am'! |
52 | 14 |
|
85 | 15 |
ApplicationModel subclass:#SystemBrowser |
75 | 16 |
instanceVariableNames:'currentClass currentMethodCategory currentMethod currentSelector |
17 |
showInstance actualClasslastMethodCategory aspect lockUpdates |
|
18 |
autoSearch myLabel acceptClass' |
|
52 | 19 |
classVariableNames:'CheckForInstancesWhenRemovingClasses' |
20 |
poolDictionaries:'' |
|
21 |
category:'Interface-Browsers' |
|
36 | 22 |
! |
23 |
||
75 | 24 |
!SystemBrowser class methodsFor:'initialization'! |
25 |
||
26 |
initialize |
|
27 |
"Browser configuration; |
|
28 |
(values can be changed from your private startup file)" |
|
45 | 29 |
|
85 | 30 |
self classResources. |
31 |
||
75 | 32 |
" |
33 |
setting this to false, the removeClass function will remove |
|
34 |
classes WITHOUT checking for instances. Otherwise, |
|
35 |
it will check and let you confirm in case there are instances. |
|
36 |
Checking for instances may be a bit time consuming, though. |
|
37 |
The default is true - therefore, it will check |
|
38 |
" |
|
39 |
CheckForInstancesWhenRemovingClasses := true |
|
40 |
||
41 |
" |
|
42 |
CheckForInstancesWhenRemovingClasses := true |
|
43 |
CheckForInstancesWhenRemovingClasses := false |
|
44 |
||
85 | 45 |
SystemBrowser initialize |
75 | 46 |
" |
47 |
! ! |
|
36 | 48 |
|
49 |
!SystemBrowser class methodsFor:'documentation'! |
|
50 |
||
51 |
copyright |
|
52 |
" |
|
53 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
45 | 54 |
All Rights Reserved |
36 | 55 |
|
56 |
This software is furnished under a license and may be used |
|
57 |
only in accordance with the terms of that license and with the |
|
58 |
inclusion of the above copyright notice. This software may not |
|
59 |
be provided or otherwise made available to, or used by, any |
|
60 |
other person. No title to or ownership of the software is |
|
61 |
hereby transferred. |
|
62 |
" |
|
63 |
! |
|
64 |
||
65 |
version |
|
165
df29ee4514c1
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
142
diff
changeset
|
66 |
^ '$Header: /cvs/stx/stx/libtool/SystemBrowser.st,v 1.41 1995-11-11 15:41:09 cg Exp $' |
36 | 67 |
! |
68 |
||
69 |
documentation |
|
70 |
" |
|
71 |
this class implements all kinds of class browsers. |
|
52 | 72 |
Typically, it is started with 'SystemBrowser open', but there are many other |
73 |
startup messages, to launch special browsers. |
|
74 |
See the categories 'startup' and 'special search startup' in the classes |
|
75 |
protocol. |
|
76 |
||
77 |
Alse, see the extra document 'doc/misc/sbrowser.doc' or the HTML online doc |
|
78 |
for how to use the browser. |
|
36 | 79 |
|
93 | 80 |
written winter 89 by claus. |
81 |
||
82 |
Notice: SystemBrowser is currently being rewritten to be an instance |
|
83 |
of ApplicationModel - this transition is not yet complete and you see |
|
106 | 84 |
here an intermediate version. The instance variables defined here are NOT |
93 | 85 |
currently used - instead, everything is really done in the BrowserView |
106 | 86 |
which (currently) keeps the real state of the browser. |
93 | 87 |
This will certainly change ... |
36 | 88 |
" |
89 |
! ! |
|
90 |
||
75 | 91 |
!SystemBrowser class methodsFor:'instance creation'! |
52 | 92 |
|
93 | 93 |
openOnDevice:aDisplay |
75 | 94 |
"launch a standard browser on another display. |
95 |
Does not work currently - still being developped." |
|
96 |
||
85 | 97 |
^ self newWithLabel:(self classResources string:'System Browser') |
75 | 98 |
setupBlock:[:browser | browser setupForAll] |
93 | 99 |
onDevice:aDisplay |
100 |
||
101 |
"|d| |
|
36 | 102 |
|
93 | 103 |
d := XWorkstation new initializeFor:'porty:0'. |
104 |
d startDispatch. |
|
105 |
SystemBrowser openOnDevice:d |
|
52 | 106 |
" |
75 | 107 |
! |
52 | 108 |
|
75 | 109 |
open |
110 |
"launch a standard browser" |
|
111 |
||
105 | 112 |
^ self openOnDevice:(Screen current) |
75 | 113 |
|
93 | 114 |
" |
115 |
SystemBrowser open |
|
116 |
" |
|
36 | 117 |
! ! |
118 |
||
119 |
!SystemBrowser class methodsFor:'startup'! |
|
120 |
||
121 |
browseMethods:aList title:aString |
|
52 | 122 |
"launch a browser for an explicit list of class/selectors. |
123 |
Each entry in the list must consist of the classes name and the selector, |
|
124 |
separated by spaces. For class methods, the string 'class' must be |
|
125 |
appended to the classname." |
|
36 | 126 |
|
127 |
(aList size == 0) ifTrue:[ |
|
45 | 128 |
self showNoneFound:aString. |
129 |
^ nil |
|
36 | 130 |
]. |
131 |
aList sort. |
|
93 | 132 |
^ self |
133 |
newWithLabel:aString |
|
134 |
setupSelector:#setupForList: |
|
135 |
arg:aList |
|
36 | 136 |
|
137 |
" |
|
93 | 138 |
SystemBrowser |
139 |
browseMethods:#('Object printOn:' 'Collection add:') |
|
140 |
title:'some methods' |
|
36 | 141 |
" |
142 |
" |
|
93 | 143 |
SystemBrowser |
144 |
browseMethods:#('Behavior new:' 'Setclass new:') |
|
145 |
title:'some new: methods' |
|
52 | 146 |
" |
36 | 147 |
! |
148 |
||
149 |
browseMethodsIn:aCollectionOfClasses inst:wantInst class:wantClass where:aBlock title:title |
|
150 |
"launch a browser for all instance- (if wantInst is true) and/or |
|
151 |
classmethods (if wantClass is true) from classes in aCollectionOfClasses, |
|
152 |
where aBlock evaluates to true. |
|
153 |
The block is called with 3 arguments, class, method and seelctor." |
|
154 |
||
45 | 155 |
|list| |
36 | 156 |
|
157 |
" |
|
158 |
since this may take a long time, lower my priority ... |
|
159 |
" |
|
45 | 160 |
Processor activeProcess withLowerPriorityDo:[ |
161 |
|checkedClasses checkBlock| |
|
162 |
||
163 |
checkedClasses := IdentitySet new. |
|
164 |
list := OrderedCollection new. |
|
165 |
||
166 |
checkBlock := [:cls | |
|
167 |
|methodArray selectorArray| |
|
168 |
||
169 |
(checkedClasses includes:cls) ifFalse:[ |
|
170 |
methodArray := cls methodArray. |
|
171 |
selectorArray := cls selectorArray. |
|
172 |
||
173 |
1 to:methodArray size do:[:index | |
|
174 |
|method sel| |
|
175 |
||
176 |
method := methodArray at:index. |
|
177 |
sel := selectorArray at:index. |
|
178 |
(aBlock value:cls value:method value:sel) ifTrue:[ |
|
179 |
list add:(cls name , ' ' , sel) |
|
180 |
] |
|
181 |
]. |
|
182 |
checkedClasses add:cls. |
|
183 |
] |
|
184 |
]. |
|
185 |
||
186 |
aCollectionOfClasses do:[:aClass | |
|
52 | 187 |
" |
188 |
output disabled - it slows down things too much (when searching for |
|
189 |
implementors or senders) |
|
190 |
" |
|
108 | 191 |
wantInst ifTrue:[ |
192 |
"/ Transcript show:'searching '; show:aClass name; showCr:' ...'; endEntry. |
|
193 |
checkBlock value:aClass |
|
194 |
]. |
|
195 |
wantClass ifTrue:[ |
|
196 |
"/ Transcript show:'searching '; show:aClass class name; showCr:' ...'; endEntry. |
|
197 |
checkBlock value:(aClass class) |
|
198 |
]. |
|
45 | 199 |
Processor yield |
200 |
] |
|
36 | 201 |
]. |
202 |
||
203 |
^ self browseMethods:list title:title |
|
204 |
! |
|
205 |
||
52 | 206 |
browseMethodsIn:aCollectionOfClasses where:aBlock title:title |
207 |
"launch a browser for all instance- and classmethods from |
|
208 |
all classes in aCollectionOfClasses where aBlock evaluates to true. |
|
209 |
The block is called with 3 arguments, class, method and seelctor." |
|
210 |
||
211 |
^ self browseMethodsIn:aCollectionOfClasses inst:true class:true where:aBlock title:title |
|
75 | 212 |
|
52 | 213 |
! |
214 |
||
215 |
browseClassCategory:aClassCategory |
|
216 |
"launch a browser for all classes under aCategory" |
|
217 |
||
93 | 218 |
^ self |
219 |
newWithLabel:aClassCategory |
|
220 |
setupSelector:#setupForClassCategory: |
|
221 |
arg:aClassCategory |
|
52 | 222 |
|
223 |
"SystemBrowser browseClassCategory:'Kernel-Objects'" |
|
224 |
! |
|
225 |
||
226 |
browseFullClasses |
|
227 |
"launch a browser showing all methods at once" |
|
228 |
||
93 | 229 |
^ self |
230 |
newWithLabel:'Full Class Browser' |
|
231 |
setupBlock:[:newBrowser | newBrowser setupForFullClass] |
|
52 | 232 |
|
233 |
"SystemBrowser browseFullClasses" |
|
234 |
! |
|
235 |
||
236 |
browseClass:aClass |
|
237 |
"launch a browser for aClass" |
|
238 |
||
93 | 239 |
^ self |
240 |
newWithLabel:aClass name |
|
241 |
setupSelector:#setupForClass: |
|
242 |
arg:aClass |
|
52 | 243 |
|
244 |
"SystemBrowser browseClass:Object" |
|
245 |
! |
|
246 |
||
247 |
browseClass:aClass selector:selector |
|
248 |
"launch a browser for the method at selector in aClass" |
|
249 |
||
250 |
^ self |
|
251 |
newWithLabel:(aClass name , ' ' , selector , ' ' , selector) |
|
93 | 252 |
setupBlock:[:newBrowser | newBrowser setupForClass:aClass selector:selector] |
52 | 253 |
|
254 |
" |
|
255 |
SystemBrowser browseClass:Object selector:#printString |
|
256 |
" |
|
257 |
! |
|
258 |
||
259 |
browseClassHierarchy:aClass |
|
260 |
"launch a browser for aClass and all its superclasses. |
|
261 |
this is different from the fullProtocol browser." |
|
262 |
||
93 | 263 |
^ self |
264 |
newWithLabel:(aClass name , '-' , 'hierarchy') |
|
265 |
setupSelector:#setupForClassHierarchy: |
|
266 |
arg:aClass |
|
52 | 267 |
|
268 |
" |
|
269 |
SystemBrowser browseClassHierarchy:Number |
|
270 |
" |
|
271 |
! |
|
272 |
||
273 |
browseFullClassProtocol:aClass |
|
274 |
"launch a browser for aClasses full protocol. |
|
275 |
This is different from hierarchy browsing." |
|
276 |
||
93 | 277 |
^ self |
278 |
newWithLabel:(aClass name , '-' , 'full protocol') |
|
279 |
setupSelector:#setupForFullClassProtocol: |
|
280 |
arg:aClass |
|
52 | 281 |
|
282 |
" |
|
283 |
SystemBrowser browseFullClassProtocol:Number |
|
284 |
" |
|
285 |
! |
|
286 |
||
287 |
browseClasses:aList title:title |
|
288 |
"launch a browser for all classes in aList" |
|
289 |
||
93 | 290 |
^ self |
291 |
newWithLabel:title |
|
292 |
setupSelector:#setupForClassList: |
|
293 |
arg:aList |
|
52 | 294 |
|
295 |
" |
|
296 |
SystemBrowser browseClasses:(Array with:Object |
|
297 |
with:Float) |
|
298 |
title:'two classes' |
|
299 |
" |
|
300 |
! |
|
301 |
||
302 |
browseClass:aClass methodCategory:aCategory |
|
303 |
"launch a browser for all methods under aCategory in aClass" |
|
304 |
||
305 |
^ self newWithLabel:(aClass name , ' ' , aCategory) |
|
306 |
setupBlock:[:browser | browser setupForClass:aClass methodCategory:aCategory] |
|
307 |
||
308 |
"SystemBrowser browseClass:String methodCategory:'copying'" |
|
309 |
! |
|
310 |
||
311 |
browseMethodCategory:aCategory |
|
312 |
"launch a browser for all methods where category = aCategory" |
|
313 |
||
314 |
|searchBlock| |
|
315 |
||
316 |
aCategory includesMatchCharacters ifTrue:[ |
|
317 |
searchBlock := [:c :m :s | aCategory match:m category]. |
|
318 |
] ifFalse:[ |
|
319 |
searchBlock := [:c :m :s | m category = aCategory] |
|
320 |
]. |
|
321 |
||
322 |
self browseMethodsWhere:searchBlock title:('all methods with category of ' , aCategory) |
|
323 |
||
324 |
" |
|
325 |
SystemBrowser browseMethodCategory:'printing & storing' |
|
326 |
SystemBrowser browseMethodCategory:'print*' |
|
327 |
" |
|
328 |
! |
|
329 |
||
330 |
browseAllSelect:aBlock |
|
331 |
"launch a browser for all methods where aBlock returns true. |
|
332 |
The block is called with 3 arguments, class, method and seelctor." |
|
333 |
||
334 |
^ self browseMethodsWhere:aBlock title:'selected messages' |
|
335 |
||
336 |
" |
|
337 |
SystemBrowser browseAllSelect:[:aClass :aMethod :selector | selector numArgs == 3] |
|
338 |
" |
|
339 |
! |
|
340 |
||
341 |
browseMethodsWhere:aBlock title:title |
|
342 |
"launch a browser for all methods where aBlock returns true. |
|
343 |
The block is called with 3 arguments, class, method and seelctor." |
|
344 |
||
345 |
^ self browseMethodsIn:(Smalltalk allClasses) where:aBlock title:title |
|
346 |
! |
|
347 |
||
348 |
browseMethodsOf:aClass where:aBlock title:title |
|
349 |
"launch a browser for all instance- and classmethods in aClass |
|
350 |
where aBlock evaluates to true. |
|
351 |
The block is called with 3 arguments, class, method and seelctor." |
|
352 |
||
353 |
^ self browseMethodsIn:(Array with:aClass) where:aBlock title:title |
|
354 |
! |
|
355 |
||
356 |
browseMethodsFrom:aClass where:aBlock title:title |
|
357 |
"launch a browser for all instance- and classmethods in aClass |
|
358 |
and all its subclasses where aBlock evaluates to true. |
|
359 |
The block is called with 3 arguments, class, method and seelctor." |
|
360 |
||
361 |
^ self browseMethodsIn:(aClass withAllSubclasses) where:aBlock title:title |
|
362 |
! |
|
363 |
||
36 | 364 |
browseInstMethodsOf:aClass where:aBlock title:title |
365 |
"launch a browser for all instance methods in aClass |
|
366 |
where aBlock evaluates to true" |
|
367 |
||
368 |
^ self browseMethodsIn:(Array with:aClass) inst:true class:false where:aBlock title:title |
|
369 |
! |
|
370 |
||
371 |
browseInstMethodsIn:aCollectionOfClasses where:aBlock title:title |
|
372 |
"launch a browser for all instance methods of all classes in |
|
373 |
aCollectionOfClasses where aBlock evaluates to true" |
|
374 |
||
375 |
^ self browseMethodsIn:aCollectionOfClasses inst:true class:false |
|
45 | 376 |
where:aBlock title:title |
52 | 377 |
! |
378 |
||
379 |
browseInstMethodsFrom:aClass where:aBlock title:title |
|
380 |
"launch a browser for all instance methods in aClass and all subclasses |
|
381 |
where aBlock evaluates to true" |
|
382 |
||
383 |
^ self browseMethodsIn:(aClass withAllSubclasses) inst:true class:false where:aBlock title:title |
|
36 | 384 |
! ! |
385 |
||
90 | 386 |
!SystemBrowser class methodsFor:'startup with query'! |
387 |
||
388 |
getClassThenPerform:aSelector |
|
389 |
|enterBox| |
|
390 |
||
391 |
enterBox := EnterBox title:(self classResources at:'Browse which class:') withCRs. |
|
392 |
enterBox okText:(self classResources at:'browse'). |
|
142 | 393 |
enterBox entryCompletionBlock:[:contents | |
118 | 394 |
|s what m| |
395 |
||
142 | 396 |
s := contents withoutSpaces. |
118 | 397 |
what := Smalltalk classnameCompletion:s. |
398 |
enterBox contents:what first. |
|
399 |
]. |
|
90 | 400 |
enterBox action:[:className | |
401 |
|cls| |
|
402 |
||
403 |
cls := Smalltalk classNamed:className. |
|
404 |
cls isNil ifTrue:[ |
|
405 |
self warn:(self classResources at:'no such class'). |
|
406 |
] ifFalse:[ |
|
407 |
self perform:aSelector with:cls |
|
408 |
] |
|
409 |
]. |
|
410 |
enterBox showAtPointer |
|
411 |
||
412 |
" |
|
413 |
SystemBrowser getClassThenPerform:#browseClass: |
|
414 |
" |
|
415 |
! |
|
416 |
||
417 |
askThenBrowseClass |
|
418 |
self getClassThenPerform:#browseClass: |
|
419 |
||
420 |
" |
|
421 |
SystemBrowser askThenBrowseClass |
|
422 |
" |
|
423 |
! |
|
424 |
||
425 |
askThenBrowseClassHierarchy |
|
426 |
self getClassThenPerform:#browseClassHierarchy: |
|
427 |
||
428 |
" |
|
429 |
SystemBrowser askThenBrowseClassHierarchy |
|
430 |
" |
|
431 |
! |
|
432 |
||
433 |
askThenBrowseFullClassProtocol |
|
434 |
self getClassThenPerform:#browseFullClassProtocol: |
|
435 |
||
436 |
" |
|
437 |
SystemBrowser askThenBrowseFullClassProtocol |
|
438 |
" |
|
439 |
! ! |
|
440 |
||
36 | 441 |
!SystemBrowser class methodsFor:'special search startup'! |
442 |
||
52 | 443 |
browseAllCallsOn:aSelectorString in:aCollectionOfClasses title:title |
444 |
"launch a browser for all senders of aSelector in aCollectionOfClasses" |
|
445 |
||
446 |
|sel browser searchBlock| |
|
447 |
||
448 |
((aSelectorString ~= '*') and:[aSelectorString includesMatchCharacters]) ifTrue:[ |
|
449 |
"a matchString" |
|
93 | 450 |
searchBlock := [:class :method :s | |
451 |
|lits found| |
|
52 | 452 |
|
93 | 453 |
lits := method literals. |
52 | 454 |
found := false. |
455 |
lits notNil ifTrue:[ |
|
456 |
lits do:[:aLiteral | |
|
457 |
found ifFalse:[ |
|
458 |
(aLiteral isMemberOf:Symbol) ifTrue:[ |
|
459 |
found := (aSelectorString match:aLiteral) |
|
460 |
] |
|
461 |
] |
|
462 |
] |
|
463 |
]. |
|
464 |
found |
|
465 |
]. |
|
466 |
] ifFalse:[ |
|
66 | 467 |
sel := aSelectorString asSymbolIfInterned. |
468 |
sel isNil ifTrue:[ |
|
52 | 469 |
" |
470 |
Transcript showCr:'none found.'. |
|
471 |
" |
|
472 |
self showNoneFound:title. |
|
473 |
^ nil |
|
474 |
]. |
|
93 | 475 |
searchBlock := [:class :method :s | method sends:sel]. |
52 | 476 |
]. |
93 | 477 |
browser := self browseMethodsIn:aCollectionOfClasses |
478 |
where:searchBlock |
|
479 |
title:title. |
|
52 | 480 |
|
481 |
browser notNil ifTrue:[ |
|
482 |
|s| |
|
483 |
||
484 |
" |
|
485 |
kludge for now, if its a multipart selector, |
|
486 |
no easy search is (as yet) possible |
|
487 |
" |
|
488 |
s := aSelectorString. |
|
489 |
(s includes:$:) ifTrue:[ |
|
490 |
s := s copyTo:(s indexOf:$:) |
|
491 |
]. |
|
492 |
browser autoSearch:s |
|
493 |
]. |
|
494 |
^ browser |
|
495 |
! |
|
496 |
||
497 |
browseImplementorsOf:aSelectorString |
|
498 |
"launch a browser for all implementors of aSelector" |
|
499 |
||
500 |
^ self browseImplementorsOf:aSelectorString |
|
501 |
in:(Smalltalk allClasses) |
|
502 |
title:('implementors of: ' , aSelectorString) |
|
503 |
||
504 |
" |
|
505 |
SystemBrowser browseImplementorsOf:#+ |
|
506 |
" |
|
507 |
! |
|
508 |
||
36 | 509 |
browseImplementorsOf:aSelectorString in:aCollectionOfClasses title:title |
510 |
"launch a browser for all implementors of aSelector in |
|
511 |
the classes contained in aCollectionOfClasses and its metaclasses" |
|
512 |
||
513 |
|list sel| |
|
514 |
||
515 |
list := OrderedCollection new. |
|
516 |
||
517 |
((aSelectorString ~= '*') and:[aSelectorString includesMatchCharacters]) ifTrue:[ |
|
45 | 518 |
"a matchString" |
519 |
||
520 |
aCollectionOfClasses do:[:aClass | |
|
521 |
aClass selectorArray do:[:aSelector | |
|
522 |
(aSelectorString match:aSelector) ifTrue:[ |
|
523 |
list add:(aClass name , ' ' , aSelector) |
|
524 |
] |
|
525 |
]. |
|
132 | 526 |
aClass isMeta ifFalse:[ |
527 |
aClass class selectorArray do:[:aSelector | |
|
528 |
(aSelectorString match:aSelector) ifTrue:[ |
|
529 |
list add:(aClass name , 'class ' , aSelector) |
|
530 |
] |
|
45 | 531 |
] |
532 |
] |
|
533 |
] |
|
36 | 534 |
] ifFalse:[ |
45 | 535 |
"can do a faster search" |
536 |
||
66 | 537 |
sel := aSelectorString asSymbolIfInterned. |
538 |
sel isNil ifTrue:[ |
|
45 | 539 |
self showNoneFound:title. |
540 |
^ nil |
|
541 |
]. |
|
542 |
||
543 |
aCollectionOfClasses do:[:aClass | |
|
544 |
(aClass implements:sel) ifTrue:[ |
|
545 |
list add:(aClass name , ' ' , aSelectorString) |
|
546 |
]. |
|
132 | 547 |
aClass isMeta ifFalse:[ |
548 |
(aClass class implements:sel) ifTrue:[ |
|
549 |
list add:(aClass name , 'class ' , aSelectorString) |
|
550 |
] |
|
45 | 551 |
] |
552 |
] |
|
36 | 553 |
]. |
554 |
^ self browseMethods:list title:title |
|
555 |
||
556 |
" |
|
557 |
SystemBrowser browseImplementorsOf:#+ |
|
45 | 558 |
in:(Array with:Number |
559 |
with:Float |
|
560 |
with:SmallInteger) |
|
561 |
title:'some implementors of +' |
|
36 | 562 |
" |
132 | 563 |
|
564 |
"Modified: 4.9.1995 / 17:33:39 / claus" |
|
36 | 565 |
! |
566 |
||
567 |
browseAllCallsOn:aSelectorString |
|
568 |
"launch a browser for all senders of aSelector" |
|
569 |
||
570 |
^ self browseAllCallsOn:aSelectorString |
|
45 | 571 |
in:(Smalltalk allClasses) |
572 |
title:('senders of ' , aSelectorString) |
|
36 | 573 |
|
574 |
" |
|
575 |
SystemBrowser browseAllCallsOn:#+ |
|
576 |
" |
|
577 |
! |
|
578 |
||
579 |
browseCallsOn:aSelectorString under:aClass |
|
580 |
"launch a browser for all senders of aSelector in aClass and subclasses" |
|
581 |
||
582 |
^ self browseAllCallsOn:aSelectorString |
|
45 | 583 |
in:(aClass withAllSubclasses) |
584 |
title:('senders of: ' , |
|
585 |
aSelectorString , |
|
586 |
' (in or below ' , aClass name , ')') |
|
36 | 587 |
|
588 |
" |
|
589 |
SystemBrowser browseAllCallsOn:#+ under:Number |
|
590 |
" |
|
591 |
! |
|
592 |
||
52 | 593 |
browseImplementorsOf:aSelectorString under:aClass |
594 |
"launch a browser for all implementors of aSelector in aClass |
|
595 |
and its subclasses" |
|
596 |
||
597 |
^ self browseImplementorsOf:aSelectorString |
|
598 |
in:(aClass withAllSubclasses) |
|
599 |
title:('implementors of: ' , |
|
600 |
aSelectorString , |
|
601 |
' (in or below ' , aClass name , ')') |
|
602 |
||
603 |
" |
|
604 |
SystemBrowser browseImplementorsOf:#+ under:Integer |
|
605 |
" |
|
606 |
! |
|
607 |
||
36 | 608 |
browseForSymbol:aSymbol title:title warnIfNone:doWarn |
609 |
"launch a browser for all methods referencing aSymbol" |
|
610 |
||
611 |
|browser searchBlock sym| |
|
612 |
||
613 |
(aSymbol includesMatchCharacters) ifTrue:[ |
|
45 | 614 |
"a matchString" |
93 | 615 |
searchBlock := [:c :m :s | |
616 |
|found lits| |
|
45 | 617 |
|
93 | 618 |
lits := m literals. |
45 | 619 |
found := false. |
620 |
lits notNil ifTrue:[ |
|
621 |
lits do:[:aLiteral | |
|
622 |
found ifFalse:[ |
|
623 |
(aLiteral isMemberOf:Symbol) ifTrue:[ |
|
624 |
found := (aSymbol match:aLiteral) |
|
625 |
] |
|
626 |
] |
|
627 |
] |
|
628 |
]. |
|
629 |
found |
|
630 |
]. |
|
36 | 631 |
] ifFalse:[ |
45 | 632 |
" |
633 |
can do a faster search |
|
634 |
" |
|
66 | 635 |
sym := aSymbol asSymbolIfInterned. |
636 |
sym isNil ifTrue:[ |
|
45 | 637 |
self showNoneFound:title. |
638 |
^ nil |
|
639 |
]. |
|
640 |
||
93 | 641 |
searchBlock := [:c :m :s | |
642 |
|found lits| |
|
45 | 643 |
|
93 | 644 |
lits := m literals. |
45 | 645 |
found := false. |
646 |
lits notNil ifTrue:[ |
|
647 |
lits do:[:aLiteral | |
|
648 |
found ifFalse:[ |
|
649 |
(aLiteral isMemberOf:Symbol) ifTrue:[ |
|
650 |
found := (sym == aLiteral) |
|
651 |
] |
|
652 |
] |
|
653 |
] |
|
654 |
]. |
|
655 |
found |
|
656 |
]. |
|
36 | 657 |
]. |
93 | 658 |
browser := self browseMethodsWhere:searchBlock title:title. |
36 | 659 |
browser notNil ifTrue:[ |
52 | 660 |
browser autoSearch:aSymbol |
36 | 661 |
]. |
662 |
^ browser |
|
663 |
! |
|
664 |
||
93 | 665 |
filterToSearchRefsTo:varName classVars:classVars modificationsOnly:modsOnly |
666 |
"return a searchblock for variable references" |
|
52 | 667 |
|
668 |
|searchBlock| |
|
669 |
||
670 |
searchBlock := [:c :m :s | |
|
93 | 671 |
|src result parser vars needMatch| |
52 | 672 |
|
673 |
needMatch := varName includesMatchCharacters. |
|
674 |
||
675 |
src := m source. |
|
676 |
src isNil ifTrue:[ |
|
677 |
result := false |
|
678 |
] ifFalse:[ |
|
679 |
needMatch ifFalse:[ |
|
680 |
" |
|
681 |
before doing a slow parse, quickly scan the |
|
682 |
methods source for the variables name ... |
|
683 |
" |
|
684 |
result := (src findString:varName) ~~ 0. |
|
685 |
] ifTrue:[ |
|
686 |
result := true. |
|
687 |
]. |
|
688 |
result ifTrue:[ |
|
689 |
result := false. |
|
53 | 690 |
parser := Parser parseMethod:src in:c warnings:false. |
52 | 691 |
parser notNil ifTrue:[ |
93 | 692 |
classVars ifFalse:[ |
693 |
modsOnly ifTrue:[ |
|
694 |
vars := parser modifiedInstVars |
|
695 |
] ifFalse:[ |
|
696 |
vars := parser usedInstVars |
|
697 |
]. |
|
698 |
] ifTrue:[ |
|
699 |
modsOnly ifTrue:[ |
|
700 |
vars := parser modifiedClassVars |
|
701 |
] ifFalse:[ |
|
702 |
vars := parser usedClassVars |
|
703 |
]. |
|
52 | 704 |
]. |
93 | 705 |
vars notNil ifTrue:[ |
52 | 706 |
needMatch ifTrue:[ |
93 | 707 |
vars do:[:cv | |
708 |
(varName match:cv) ifTrue:[result := true] |
|
52 | 709 |
] |
710 |
] ifFalse:[ |
|
93 | 711 |
result := vars includes:varName |
52 | 712 |
] |
713 |
] |
|
93 | 714 |
]. |
52 | 715 |
]. |
716 |
]. |
|
717 |
Processor yield. |
|
718 |
result |
|
719 |
]. |
|
720 |
^ searchBlock |
|
721 |
! |
|
722 |
||
36 | 723 |
browseForSymbol:aSymbol |
724 |
"launch a browser for all methods referencing aSymbol" |
|
725 |
||
726 |
^ self browseForSymbol:aSymbol title:('users of ' , aSymbol) warnIfNone:true |
|
727 |
! |
|
728 |
||
729 |
browseReferendsOf:aGlobalName warnIfNone:doWarn |
|
730 |
"launch a browser for all methods referencing a global |
|
731 |
named aGlobalName. |
|
732 |
" |
|
733 |
||
734 |
^ self browseForSymbol:aGlobalName title:('users of: ' , aGlobalName) warnIfNone:doWarn |
|
75 | 735 |
|
36 | 736 |
! |
737 |
||
738 |
browseReferendsOf:aGlobalName |
|
739 |
"launch a browser for all methods referencing a global |
|
740 |
named aGlobalName. |
|
741 |
" |
|
742 |
||
743 |
^ self browseReferendsOf:aGlobalName warnIfNone:true |
|
744 |
||
745 |
" |
|
746 |
Browser browseReferendsOf:#Transcript |
|
747 |
" |
|
75 | 748 |
|
36 | 749 |
! |
750 |
||
52 | 751 |
browseUsesOf:aClass |
752 |
|dict owners offsets |
|
753 |
sz "{ Class: SmallInteger }" |
|
754 |
n "{ Class: SmallInteger }" |
|
755 |
removeSet newDict| |
|
756 |
||
757 |
owners := ObjectMemory whoReferencesInstancesOf:aClass. |
|
758 |
||
759 |
" |
|
760 |
collect set of offsets in dict; key is class |
|
761 |
" |
|
762 |
dict := IdentityDictionary new. |
|
763 |
owners do:[:someObject | |
|
764 |
|cls create| |
|
765 |
||
766 |
someObject isContext ifFalse:[ |
|
767 |
" |
|
768 |
someObject refers to an instance of aClass; |
|
769 |
find out, which instVar(s) |
|
770 |
" |
|
771 |
cls := someObject class. |
|
772 |
cls ~~ Array ifTrue:[ |
|
773 |
n := cls instSize. |
|
774 |
create := [|s| s := Set new. dict at:cls put:s. s]. |
|
775 |
||
776 |
1 to:n do:[:i | |
|
777 |
|ref| |
|
778 |
||
779 |
ref := someObject instVarAt:i. |
|
780 |
(ref isMemberOf:aClass) ifTrue:[ |
|
781 |
offsets := dict at:cls ifAbsent:create. |
|
782 |
offsets add:i. |
|
783 |
] |
|
784 |
]. |
|
785 |
cls isVariable ifTrue:[ |
|
786 |
cls isPointers ifTrue:[ |
|
787 |
| idx "{ Class: SmallInteger }" | |
|
788 |
||
789 |
sz := someObject basicSize. |
|
790 |
idx := 1. |
|
791 |
[idx <= sz] whileTrue:[ |
|
792 |
|ref| |
|
793 |
||
794 |
ref := someObject basicAt:idx. |
|
795 |
(ref isMemberOf:aClass) ifTrue:[ |
|
796 |
offsets := dict at:cls ifAbsent:create. |
|
797 |
offsets add:0. |
|
798 |
idx := sz |
|
799 |
]. |
|
800 |
idx := idx + 1 |
|
801 |
] |
|
802 |
] |
|
803 |
] |
|
804 |
] |
|
805 |
] |
|
806 |
]. |
|
807 |
||
808 |
" |
|
809 |
merge with superclass refs |
|
810 |
" |
|
811 |
dict keysAndValuesDo:[:cls :set | |
|
812 |
cls allSuperclasses do:[:aSuperclass | |
|
813 |
|superSet| |
|
814 |
||
815 |
superSet := dict at:aSuperclass ifAbsent:[]. |
|
816 |
superSet notNil ifTrue:[ |
|
817 |
|removeSet| |
|
818 |
||
819 |
superSet := dict at:aSuperclass. |
|
820 |
removeSet := Set new. |
|
821 |
set do:[:offset | |
|
822 |
(superSet includes:offset) ifTrue:[ |
|
823 |
removeSet add:offset |
|
824 |
] |
|
825 |
]. |
|
826 |
set removeAll:removeSet |
|
827 |
] |
|
828 |
] |
|
829 |
]. |
|
830 |
||
831 |
" |
|
832 |
remove empty ones |
|
833 |
" |
|
834 |
removeSet := Set new. |
|
835 |
dict keysAndValuesDo:[:cls :set | |
|
836 |
set isEmpty ifTrue:[ |
|
837 |
removeSet add:cls |
|
838 |
] |
|
839 |
]. |
|
840 |
removeSet do:[:cls | |
|
841 |
dict removeKey:cls |
|
842 |
]. |
|
843 |
||
844 |
" |
|
845 |
replace the indices by real names |
|
846 |
" |
|
847 |
newDict := IdentityDictionary new. |
|
848 |
dict keysAndValuesDo:[:cls :set | |
|
849 |
|newSet names| |
|
850 |
||
851 |
names := cls allInstVarNames. |
|
852 |
newSet := set collect:[:index | |
|
853 |
index == 0 ifTrue:['*indexed*'] ifFalse:[names at:index]. |
|
854 |
]. |
|
855 |
newDict at:cls put:newSet |
|
856 |
]. |
|
857 |
||
858 |
newDict inspect |
|
859 |
||
75 | 860 |
|
52 | 861 |
! |
862 |
||
36 | 863 |
browseForString:aString in:aCollectionOfClasses |
45 | 864 |
"launch a browser for all methods in aCollectionOfClasses |
53 | 865 |
containing a string in their source. |
866 |
This may be slow, since source-code has to be scanned." |
|
867 |
||
868 |
|browser searchBlock title s| |
|
36 | 869 |
|
870 |
title := 'methods containing: ' , aString displayString. |
|
871 |
||
872 |
(aString includesMatchCharacters) ifTrue:[ |
|
53 | 873 |
s := '*' , aString , '*'. |
45 | 874 |
"a matchString" |
93 | 875 |
searchBlock := [:c :m :sel | s match:m source] |
36 | 876 |
] ifFalse:[ |
93 | 877 |
searchBlock := [:c :m :sel | (m source findString:aString) ~~ 0] |
36 | 878 |
]. |
93 | 879 |
browser := self browseMethodsIn:aCollectionOfClasses where:searchBlock title:title. |
36 | 880 |
|
881 |
browser notNil ifTrue:[ |
|
52 | 882 |
browser autoSearch:aString |
36 | 883 |
]. |
884 |
^ browser |
|
885 |
||
53 | 886 |
" |
887 |
SystemBrowser browseForString:'all' in:(Array with:Object) |
|
888 |
SystemBrowser browseForString:'should' in:(Array with:Object) |
|
889 |
SystemBrowser browseForString:'[eE]rror' in:(Array with:Object) |
|
890 |
" |
|
75 | 891 |
|
36 | 892 |
! |
893 |
||
894 |
browseForString:aString |
|
53 | 895 |
"launch a browser for all methods containing a string in their source. |
896 |
This may be slow, since source-code has to be scanned." |
|
36 | 897 |
|
898 |
^ self browseForString:aString in:(Smalltalk allClasses) |
|
52 | 899 |
! |
900 |
||
36 | 901 |
aproposSearch:aString in:aCollectionOfClasses |
902 |
"browse all methods, which have aString in their selector or |
|
903 |
in the methods comment. |
|
904 |
This is relatively slow, since all source must be processed." |
|
905 |
||
53 | 906 |
|matchString list s searchBlock browser| |
36 | 907 |
|
908 |
matchString := '*' , aString , '*'. |
|
909 |
||
910 |
list := OrderedCollection new. |
|
911 |
||
53 | 912 |
(aString includesMatchCharacters) ifTrue:[ |
913 |
s := '*' , aString , '*'. |
|
914 |
"a matchString" |
|
95 | 915 |
searchBlock := [:text | (text asCollectionOfLinesfindFirst:[:line | s match:line]) ~~ 0]. |
53 | 916 |
] ifFalse:[ |
917 |
searchBlock := [:source | (source findString:aString) ~~ 0] |
|
918 |
]. |
|
919 |
||
920 |
browser := self browseMethodsIn:aCollectionOfClasses |
|
45 | 921 |
where:[:class :method :sel | |
53 | 922 |
|comment| |
923 |
||
924 |
Processor yield. |
|
925 |
(searchBlock value:sel) ifTrue:[ |
|
926 |
true |
|
45 | 927 |
] ifFalse:[ |
53 | 928 |
comment := method comment. |
929 |
comment notNil |
|
930 |
and:[searchBlock value:method comment] |
|
45 | 931 |
]. |
932 |
] |
|
53 | 933 |
title:('apropos: ' , aString). |
934 |
||
935 |
browser notNil ifTrue:[ |
|
936 |
browser autoSearch:aString |
|
937 |
]. |
|
938 |
^ browser |
|
939 |
||
940 |
" |
|
941 |
SystemBrowser aproposSearch:'append' in:(Collection withAllSubclasses) |
|
942 |
SystemBrowser aproposSearch:'add' in:(Collection withAllSubclasses) |
|
943 |
SystemBrowser aproposSearch:'sort' in:(Collection withAllSubclasses) |
|
944 |
SystemBrowser aproposSearch:'[Aa]bsent' in:(Collection withAllSubclasses) |
|
945 |
" |
|
75 | 946 |
|
53 | 947 |
! |
948 |
||
949 |
aproposSearch:aString |
|
950 |
"browse all methods, which have aString in their selector or |
|
951 |
in the methods comment. |
|
952 |
This is relatively slow, since all source must be processed." |
|
953 |
||
954 |
^ self aproposSearch:aString in:(Smalltalk allClasses) |
|
75 | 955 |
|
36 | 956 |
! |
957 |
||
93 | 958 |
browseRefsTo:varName classVars:classVars in:aCollectionOfClasses modificationsOnly:modsOnly title:title |
959 |
"launch a browser for all methods in aClass where the instVar/classVar named |
|
960 |
varName is referenced; if modsOnly is true, browse only methods where the |
|
961 |
instvar is modified" |
|
962 |
||
963 |
|filter browser pattern| |
|
964 |
||
965 |
filter := self filterToSearchRefsTo:varName classVars:classVars modificationsOnly:modsOnly. |
|
108 | 966 |
browser := self browseMethodsIn:aCollectionOfClasses |
967 |
inst:true class:classVars where:filter title:title. |
|
93 | 968 |
|
969 |
browser notNil ifTrue:[ |
|
970 |
modsOnly ifTrue:[ |
|
971 |
pattern := varName , ' :=' |
|
972 |
] ifFalse:[ |
|
973 |
pattern := varName |
|
974 |
]. |
|
975 |
browser autoSearch:pattern |
|
976 |
]. |
|
977 |
^ browser |
|
978 |
! |
|
979 |
||
980 |
browseInstRefsTo:varName in:aCollectionOfClasses modificationsOnly:modsOnly title:title |
|
36 | 981 |
"launch a browser for all methods in aClass where the instVar named |
93 | 982 |
varName is referenced; if modsOnly is true, browse only methods where the |
983 |
instvar is modified" |
|
984 |
||
985 |
^ self browseRefsTo:varName classVars:false in:aCollectionOfClasses modificationsOnly:modsOnly title:title |
|
986 |
! |
|
987 |
||
988 |
browseClassRefsTo:varName in:aCollectionOfClasses modificationsOnly:modsOnly title:title |
|
989 |
"launch a browser for all methods in aCollectionOfClasses, |
|
990 |
where the classVar named aString is referenced; |
|
991 |
if modsOnly is true, browse only methods where the classvar is modified" |
|
992 |
||
993 |
^ self browseRefsTo:varName classVars:true in:aCollectionOfClasses modificationsOnly:modsOnly title:title |
|
994 |
! |
|
995 |
||
996 |
browseRefsTo:aString classVars:classVars in:aCollectionOfClasses modificationsOnly:modsOnly |
|
997 |
"launch a browser for all methods in aClass where the instVar/classVar named |
|
36 | 998 |
aString is referenced; if modsOnly is true, browse only methods where the |
999 |
instvar is modified" |
|
1000 |
||
1001 |
|title| |
|
1002 |
||
1003 |
modsOnly ifTrue:[ |
|
45 | 1004 |
title := 'modifications of ' |
36 | 1005 |
] ifFalse:[ |
45 | 1006 |
title := 'references to ' |
36 | 1007 |
]. |
108 | 1008 |
^ self |
1009 |
browseRefsTo:aString |
|
1010 |
classVars:classVars |
|
1011 |
in:aCollectionOfClasses |
|
1012 |
modificationsOnly:modsOnly |
|
1013 |
title:(title , aString) |
|
93 | 1014 |
! |
75 | 1015 |
|
93 | 1016 |
browseInstRefsTo:aString in:aCollectionOfClasses modificationsOnly:modsOnly |
1017 |
"launch a browser for all methods in aClass where the instVar named |
|
1018 |
aString is referenced; if modsOnly is true, browse only methods where the |
|
1019 |
instvar is modified" |
|
1020 |
||
1021 |
^ self browseRefsTo:aString classVars:false in:aCollectionOfClasses modificationsOnly:modsOnly |
|
36 | 1022 |
! |
1023 |
||
1024 |
browseInstRefsTo:aString under:aClass modificationsOnly:modsOnly |
|
1025 |
"launch a browser for all methods in aClass and subclasses |
|
1026 |
where the instVar named aString is referenced; |
|
1027 |
if modsOnly is true, browse only methods where the instvar is modified" |
|
1028 |
||
1029 |
^ self browseInstRefsTo:aString in:(aClass withAllSubclasses) modificationsOnly:modsOnly |
|
52 | 1030 |
! |
1031 |
||
1032 |
browseClassRefsTo:aString in:aCollectionOfClasses modificationsOnly:modsOnly |
|
1033 |
"launch a browser for all methods in aClass where the classVar named |
|
1034 |
aString is referenced; if modsOnly is true, browse only methods where the |
|
1035 |
classvar is modified" |
|
1036 |
||
93 | 1037 |
^ self browseRefsTo:aString classVars:true in:aCollectionOfClasses modificationsOnly:modsOnly |
52 | 1038 |
! |
1039 |
||
1040 |
browseClassRefsTo:aString under:aClass modificationsOnly:modsOnly |
|
1041 |
"launch a browser for all methods in aClass and subclasses |
|
1042 |
where the classVar named aString is referenced; |
|
1043 |
if modsOnly is true, browse only methods where the classvar is modified" |
|
1044 |
||
1045 |
^ self browseClassRefsTo:aString in:(aClass withAllSubclasses) modificationsOnly:modsOnly |
|
75 | 1046 |
|
36 | 1047 |
! ! |
1048 |
||
75 | 1049 |
!SystemBrowser class methodsFor:'private instance creation'! |
36 | 1050 |
|
93 | 1051 |
newWithLabel:aString setupBlock:aBlock onDevice:aWorkstation |
36 | 1052 |
"common helper method for all creation methods" |
1053 |
||
1054 |
|newBrowser| |
|
1055 |
||
93 | 1056 |
newBrowser := BrowserView onDevice:aWorkstation. |
52 | 1057 |
newBrowser title:aString. |
36 | 1058 |
aBlock value:newBrowser. |
1059 |
||
1060 |
newBrowser open. |
|
1061 |
^ newBrowser |
|
1062 |
! |
|
1063 |
||
1064 |
newWithLabel:aString setupBlock:aBlock |
|
1065 |
"common helper method for all creation methods" |
|
1066 |
||
106 | 1067 |
^ self newWithLabel:aString setupBlock:aBlock onDevice:Screen current |
93 | 1068 |
! |
1069 |
||
1070 |
newWithLabel:aString setupSelector:aSymbol arg:arg onDevice:aWorkstation |
|
1071 |
"common helper method for all creation methods" |
|
1072 |
||
1073 |
|newBrowser| |
|
1074 |
||
1075 |
newBrowser := BrowserView onDevice:aWorkstation. |
|
1076 |
newBrowser title:aString. |
|
1077 |
newBrowser perform:aSymbol with:arg. |
|
1078 |
newBrowser open. |
|
1079 |
^ newBrowser |
|
1080 |
! |
|
1081 |
||
1082 |
newWithLabel:aString setupSelector:aSymbol arg:arg |
|
1083 |
"common helper method for all creation methods" |
|
1084 |
||
106 | 1085 |
^ self newWithLabel:aString setupSelector:aSymbol arg:arg onDevice:Screen current |
36 | 1086 |
! ! |
1087 |
||
75 | 1088 |
!SystemBrowser class methodsFor:'private helpers'! |
52 | 1089 |
|
75 | 1090 |
showNoneFound:what |
100 | 1091 |
Dialog warn:(self classResources string:(what , '...\\... none found') withCRs). |
52 | 1092 |
! |
1093 |
||
75 | 1094 |
showNoneFound |
85 | 1095 |
Dialog warn:(self classResources string:'None found'). |
52 | 1096 |
! ! |
1097 |