author | Claus Gittinger <cg@exept.de> |
Mon, 27 May 2019 15:02:19 +0200 | |
changeset 4423 | bd0b9dbc30c2 |
parent 4399 | 4b80ef759ebe |
child 4434 | d04631202a76 |
permissions | -rw-r--r-- |
4399 | 1 |
"{ Encoding: utf8 }" |
2 |
||
2 | 3 |
" |
4 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
3810 | 5 |
All Rights Reserved |
2 | 6 |
|
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
1081 | 14 |
"{ Package: 'stx:libcomp' }" |
15 |
||
3548 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
141 | 18 |
Parser subclass:#Explainer |
3813 | 19 |
instanceVariableNames:'' |
20 |
classVariableNames:'' |
|
21 |
poolDictionaries:'' |
|
22 |
category:'System-Compiler' |
|
2 | 23 |
! |
24 |
||
3866 | 25 |
Object variableSubclass:#ActionWithInfo |
26 |
instanceVariableNames:'block info' |
|
27 |
classVariableNames:'' |
|
28 |
poolDictionaries:'' |
|
29 |
privateIn:Explainer |
|
30 |
! |
|
31 |
||
396 | 32 |
!Explainer class methodsFor:'documentation'! |
2 | 33 |
|
20 | 34 |
copyright |
35 |
" |
|
36 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
3810 | 37 |
All Rights Reserved |
20 | 38 |
|
39 |
This software is furnished under a license and may be used |
|
40 |
only in accordance with the terms of that license and with the |
|
41 |
inclusion of the above copyright notice. This software may not |
|
42 |
be provided or otherwise made available to, or used by, any |
|
43 |
other person. No title to or ownership of the software is |
|
44 |
hereby transferred. |
|
45 |
" |
|
46 |
! |
|
47 |
||
2 | 48 |
documentation |
49 |
" |
|
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
50 |
a very simple explainer - much more should be added... |
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
51 |
|
3608 | 52 |
This one is involved, when the 'explain' menu function is used in a |
1728 | 53 |
codeView (popup or via CMD-E), or if the mouse button is clicked |
3608 | 54 |
on some code construct in the new browser (then a short explanaition |
55 |
is shown in the lower info area). |
|
263 | 56 |
|
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
57 |
Most of the texts returned here are heuristically motivated, |
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
58 |
based on the experience with beginners and their frequently asked questions. |
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
59 |
|
3885 | 60 |
TODO: |
61 |
this is in an experimental stage; the naive type inferer replicates code |
|
62 |
found in DWIM support; it should use the code there. |
|
63 |
||
263 | 64 |
[author:] |
3608 | 65 |
Claus Gittinger |
2 | 66 |
" |
67 |
! ! |
|
68 |
||
396 | 69 |
!Explainer class methodsFor:'explaining'! |
2 | 70 |
|
2193
9416fc17ee62
pass the interval to the explainer
Claus Gittinger <cg@exept.de>
parents:
2191
diff
changeset
|
71 |
explainLiteralNode:node in:code forClass:cls short:short interval:intervalIfKnown |
3842 | 72 |
|expl literalValue literalsClass findInnerMost elementIndex codeOfCharacterBeforeCursor| |
1728 | 73 |
|
74 |
literalValue := node value. |
|
3842 | 75 |
literalsClass := literalValue class. |
76 |
expl := (self asClassLink:literalsClass name "allBold") , '-constant'. |
|
2954
0943337cfb73
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2940
diff
changeset
|
77 |
|
2316
f09794e008f8
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
78 |
(literalValue isInteger) ifTrue:[ |
3697 | 79 |
(literalValue ~~ 0 and:[literalValue ~~ 1]) ifTrue:[ |
3319 | 80 |
expl := expl , ' ('. |
3798 | 81 |
#(2 10 16) with:#('binary: ' 'decimal: ' 'hex: ') do:[:base :baseExpl | |
3319 | 82 |
|bStr| |
3203 | 83 |
|
3319 | 84 |
base ~= (node token radix ? 10) ifTrue:[ |
85 |
bStr := base==10 |
|
86 |
ifTrue:[literalValue printString] |
|
3798 | 87 |
ifFalse:[(literalValue printStringRadix:base) leftPaddedTo:2 with:$0]. "/ looks better: at least a size of 2 |
88 |
"/ oops - someone looks at a largeInteger |
|
89 |
bStr := bStr contractAtEndTo:40. |
|
3319 | 90 |
expl := expl , ' ' , baseExpl, bStr |
91 |
]. |
|
92 |
]. |
|
93 |
expl := expl , ' )'. |
|
3798 | 94 |
]. |
3319 | 95 |
^ expl. |
96 |
]. |
|
97 |
(literalValue isCharacter) ifTrue:[ |
|
98 |
expl := expl , ' ',literalValue storeString,' (code: ',literalValue codePoint printString,' hex: 16r',literalValue codePoint hexPrintString,')'. |
|
99 |
^ expl. |
|
2316
f09794e008f8
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
100 |
]. |
2954
0943337cfb73
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2940
diff
changeset
|
101 |
|
0943337cfb73
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2940
diff
changeset
|
102 |
(node isLiteralArray and:[intervalIfKnown notNil]) ifTrue:[ |
3319 | 103 |
"/ see which element we have to explain |
104 |
findInnerMost := |
|
105 |
[:token | |
|
106 |
token value keysAndValuesDo:[:index :eachToken | |
|
3810 | 107 |
|selectorOrName selectorExplanation| |
2954
0943337cfb73
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2940
diff
changeset
|
108 |
|
3319 | 109 |
((eachToken start to:eachToken stop) intersect:intervalIfKnown) notEmpty ifTrue:[ |
110 |
elementIndex := index. "/ see below |
|
2954
0943337cfb73
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2940
diff
changeset
|
111 |
|
3319 | 112 |
eachToken value isArray ifTrue:[ |
113 |
findInnerMost value:eachToken. |
|
114 |
]. |
|
115 |
eachToken value isSymbol ifTrue:[ |
|
116 |
selectorOrName := eachToken value. |
|
117 |
selectorOrName isUppercaseFirst ifTrue:[ |
|
118 |
(Smalltalk includesKey:selectorOrName) ifTrue:[ |
|
119 |
^ expl, ' / ', (Explainer explainGlobal:selectorOrName inClass:cls short:short) |
|
120 |
]. |
|
121 |
]. |
|
3810 | 122 |
selectorExplanation := (Explainer explainSelector:selectorOrName inClass:cls short:short). |
123 |
selectorExplanation isNil ifTrue:[^ expl]. |
|
124 |
^ expl, ' / ', selectorExplanation. |
|
3319 | 125 |
]. |
126 |
]. |
|
127 |
] |
|
128 |
]. |
|
129 |
findInnerMost value:node token. |
|
2954
0943337cfb73
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2940
diff
changeset
|
130 |
]. |
0943337cfb73
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2940
diff
changeset
|
131 |
|
4357 | 132 |
(literalValue isArray |
133 |
or:[ literalValue isByteArray |
|
134 |
or:[ literalValue isString ]] |
|
135 |
) ifTrue:[ |
|
3319 | 136 |
literalValue size == 0 ifTrue:[ |
137 |
^ 'empty ' , expl |
|
138 |
]. |
|
4357 | 139 |
(literalValue isString |
140 |
and:[ node token isLiteralCString ]) ifTrue:[ |
|
141 |
expl := expl,' (C-syntax)'. |
|
142 |
]. |
|
3319 | 143 |
elementIndex notNil ifTrue:[ |
144 |
^ expl , (' (size=%1; element=%2)' bindWith:literalValue size with:elementIndex) |
|
145 |
]. |
|
146 |
literalValue isString ifTrue:[ |
|
147 |
elementIndex := intervalIfKnown start - node token start. |
|
2955
d52a51930921
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2954
diff
changeset
|
148 |
|
3319 | 149 |
(elementIndex between:1 and:literalValue size) ifTrue:[ |
3601 | 150 |
codeOfCharacterBeforeCursor := (literalValue at:elementIndex) codePoint. |
151 |
^ expl , (' (size=%1; position=%2; codePoint=16r%3)' |
|
152 |
bindWith:literalValue size |
|
153 |
with:elementIndex |
|
154 |
with:codeOfCharacterBeforeCursor hexPrintString) |
|
3319 | 155 |
] |
156 |
]. |
|
157 |
^ expl , (' (size=%1)' bindWith:literalValue size) |
|
1728 | 158 |
]. |
2191
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
159 |
|
1728 | 160 |
^ expl |
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
161 |
|
3798 | 162 |
"Modified (format): / 30-04-2016 / 16:00:05 / cg" |
4357 | 163 |
"Modified: / 17-02-2019 / 12:52:23 / Claus Gittinger" |
1728 | 164 |
! |
165 |
||
4382 | 166 |
explainMessageNode:node in:code forClass:aClassOrNil short:short interval:intervalIfKnown |
1771 | 167 |
"answer a string which explains node" |
168 |
||
3203 | 169 |
|receiver nm srchClass selector selectorString implClass |
1728 | 170 |
boldSelectorString globalValue recClassSet |
3855 | 171 |
implMethod implMethodComment info definer |
1854 | 172 |
instances classesOfInstVars implementingClasses canBeNil |
3866 | 173 |
bestMatches hint redefiningClasses| |
1728 | 174 |
|
3538 | 175 |
selector := node buildSelectorString. |
3842 | 176 |
selectorString := selector printString contractTo:50. |
3548 | 177 |
selector := selector asSymbolIfInterned. "/ avoid creating new symbols. |
3810 | 178 |
selector isNil ifTrue:[ |
4370 | 179 |
^ '%1 is NOWHERE impemented.' bindWith:selectorString |
3810 | 180 |
]. |
181 |
||
3859 | 182 |
selectorString := self asLink:selectorString to:(self actionToBrowseImplementorsOf:selector). |
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
183 |
boldSelectorString := selectorString "allBold". |
3810 | 184 |
|
4382 | 185 |
recClassSet := self guessPossibleClassesFor:(node receiver) in:code forClass:aClassOrNil. |
1733 | 186 |
recClassSet size == 1 ifTrue:[ |
3209 | 187 |
srchClass := recClassSet first. |
4382 | 188 |
|
3209 | 189 |
"take care - Set cannot store nil!!" |
4382 | 190 |
implementingClasses := recClassSet |
191 |
collect:[:eachImplClassOrNil | |
|
192 |
eachImplClassOrNil whichClassIncludesSelector:selector] |
|
193 |
as:Array. |
|
1869 | 194 |
|
3209 | 195 |
(implementingClasses includes:nil) ifTrue:[ |
196 |
implementingClasses size > 1 ifTrue:[ |
|
197 |
^ 'possibly not understood: %1 (%2 other implementors)' |
|
198 |
bindWith:selector "allBold" |
|
199 |
with:(implementingClasses size - 1) |
|
200 |
]. |
|
1869 | 201 |
|
3209 | 202 |
(#('self' 'super' 'true' 'false' 'thisContext') includes:selector) ifTrue:[ |
3885 | 203 |
^ ('%1 is NOT understood here (missing period after previous statement?)' |
3854 | 204 |
bindWith:selector allBold) |
3209 | 205 |
]. |
3193 | 206 |
|
3854 | 207 |
hint := ''. |
4382 | 208 |
(recClassSet contains:[:eachRecClassOrNil | |
209 |
eachRecClassOrNil isMeta not |
|
210 |
and:[eachRecClassOrNil theMetaclass canUnderstand:selector]] |
|
211 |
) ifTrue:[ |
|
3209 | 212 |
hint := '. But class understands it - did you mean "rcvr class ',selector,'..." ?'. |
213 |
]. |
|
214 |
bestMatches := Parser findBestSelectorsFor:selector in:srchClass. |
|
3927 | 215 |
bestMatches notEmptyOrNil ifTrue:[ |
3928 | 216 |
|guessedClass| |
217 |
guessedClass := srchClass whichClassIncludesSelector:bestMatches first. |
|
218 |
guessedClass notNil ifTrue:[ |
|
3927 | 219 |
^ ('%1 is NOT understood here (best guess is: "%2" from %3)' |
220 |
bindWith:selector allBold |
|
221 |
with:(bestMatches first "allBold") |
|
3928 | 222 |
with:guessedClass name) , hint. |
3927 | 223 |
]. |
3209 | 224 |
]. |
3927 | 225 |
^ ('%1 is NOT understood here' bindWith:selector allBold), hint |
3209 | 226 |
]. |
1733 | 227 |
]. |
228 |
||
229 |
implementingClasses isNil ifTrue:[ |
|
4382 | 230 |
aClassOrNil notNil ifTrue:[ |
231 |
receiver := node receiver. |
|
232 |
receiver isVariable ifTrue:[ |
|
233 |
nm := receiver name. |
|
234 |
nm = 'self' ifTrue:[ |
|
235 |
srchClass := aClassOrNil |
|
236 |
]. |
|
237 |
nm = 'super' ifTrue:[ |
|
238 |
srchClass := aClassOrNil superclass |
|
239 |
]. |
|
240 |
definer := receiver whoDefines:nm. |
|
241 |
definer isNil ifTrue:[ |
|
242 |
"/ not a local or argument |
|
243 |
(aClassOrNil instanceVariableNames includes:nm) ifTrue:[ |
|
244 |
"/ ok - an instVar; see what values we find... |
|
245 |
instances := aClassOrNil allSubInstances select:[:eachInst| eachInst isProtoObject not]. |
|
246 |
classesOfInstVars := instances collect:[:eachInst | (eachInst instVarNamed:nm) class] as:Set. |
|
247 |
canBeNil := (classesOfInstVars remove:UndefinedObject ifAbsent:[]) notNil. |
|
248 |
"take care - Set cannot store nil!!" |
|
249 |
implementingClasses := classesOfInstVars collect:[:aClassOrNil | (aClassOrNil whichClassIncludesSelector:selector) ? 0]. |
|
250 |
implementingClasses remove:0 ifAbsent:[]. |
|
251 |
] ifFalse:[ |
|
252 |
nm isUppercaseFirst ifTrue:[ |
|
253 |
nm knownAsSymbol ifTrue:[ |
|
254 |
globalValue := Smalltalk at:nm asSymbol. |
|
255 |
globalValue isClass ifTrue:[ |
|
256 |
srchClass := globalValue class. |
|
257 |
]. |
|
258 |
] |
|
259 |
]. |
|
3209 | 260 |
]. |
261 |
]. |
|
262 |
]. |
|
4382 | 263 |
|
264 |
receiver isLiteral ifTrue:[ |
|
265 |
srchClass := receiver value class |
|
3209 | 266 |
]. |
4382 | 267 |
|
268 |
srchClass notNil ifTrue:[ |
|
269 |
implClass := srchClass whichClassIncludesSelector:selector. |
|
270 |
implClass isNil ifTrue:[ |
|
271 |
^ '%1 is NOT understood here.' bindWith:boldSelectorString |
|
272 |
]. |
|
273 |
redefiningClasses := srchClass allSubclasses select:[:aClassOrNil | aClassOrNil implements:selector]. |
|
274 |
] ifFalse:[ |
|
275 |
implementingClasses isNil ifTrue:[ |
|
276 |
implementingClasses := Smalltalk allImplementorsOf:selector |
|
277 |
]. |
|
3866 | 278 |
]. |
3209 | 279 |
]. |
1728 | 280 |
]. |
281 |
||
3866 | 282 |
implClass isNil ifTrue:[ |
283 |
implementingClasses size == 1 ifTrue:[ |
|
284 |
implClass := implementingClasses anElement. |
|
285 |
] |
|
286 |
]. |
|
287 |
implClass notNil ifTrue:[ |
|
288 |
|clsName action1 action2| |
|
3855 | 289 |
|
3810 | 290 |
implMethod := implClass compiledMethodAt:selector. |
291 |
clsName := implClass name. |
|
3859 | 292 |
clsName := self asLink:clsName to:(self actionToBrowseClass:implClass selector:selector). |
4399 | 293 |
info := '%1 » %2' bindWith:clsName "allBold" with:selectorString. |
3866 | 294 |
info := self asLink:info to:(action1 := self actionToBrowseClass:implClass selector:selector info:nil). |
295 |
||
4370 | 296 |
redefiningClasses size ~~ 0 ifTrue:[ |
3866 | 297 |
redefiningClasses size == 1 ifTrue:[ |
298 |
|redefiner| |
|
299 |
redefiner := redefiningClasses first. |
|
300 |
info := info,(' (redefined in %1)' |
|
301 |
bindWith:(self |
|
302 |
asLink:redefiner name |
|
303 |
to:(action2 := self actionToBrowseClass:redefiner selector:selector))). |
|
304 |
action2 info:((redefiner compiledMethodAt:selector) source) |
|
305 |
] ifFalse:[ |
|
306 |
info := info,' (redefined in ' |
|
307 |
,('%1 classes' |
|
308 |
bindWith:(self |
|
309 |
asLink:redefiningClasses size printString |
|
310 |
info:'Browse redefiners' |
|
311 |
to:(action2 := self actionToBrowseImplementorsOf:selector in:redefiningClasses))) |
|
312 |
,')'. |
|
313 |
action2 info:'Browse redefiners' |
|
314 |
]. |
|
315 |
]. |
|
316 |
||
3885 | 317 |
implMethodComment := self fetchDescriptionOfMethod:"fetchCommentOfMethod:"implMethod. |
3855 | 318 |
implMethodComment notNil ifTrue:[ |
3883 | 319 |
info := info , Character cr , implMethodComment. |
3866 | 320 |
action1 info:implMethod source. |
3855 | 321 |
]. |
322 |
^ info |
|
3842 | 323 |
"/ (srchClass isNil and:[(cls includesBehavior:implClass) not]) ifTrue:[ |
324 |
"/ "/ info := 'guess: ', info. |
|
325 |
"/ info := info , ' (guess)'. |
|
326 |
"/ ]. |
|
1728 | 327 |
] ifFalse:[ |
4382 | 328 |
info := Explainer explainSelector:selector inClass:aClassOrNil short:short. |
1728 | 329 |
]. |
330 |
||
3798 | 331 |
"/ implementingClasses notEmptyOrNil ifTrue:[ |
332 |
"/ implMethods := implementingClasses collect:[:implClass | implClass compiledMethodAt:selector]. |
|
333 |
"/ implMethods size <= 8 ifTrue:[ |
|
334 |
"/ implMethods size < 4 ifTrue:[ |
|
335 |
"/ "/ show full comments |
|
336 |
"/ comments := implMethods |
|
337 |
"/ collect:[:implMethod | implMethod comment] |
|
338 |
"/ thenSelect:[:comment | comment notEmptyOrNil]. |
|
339 |
"/ ] ifFalse:[ |
|
340 |
"/ "/ show first lines one |
|
341 |
"/ comments := implMethods |
|
342 |
"/ collect:[:implMethod | (self fetchCommentOfMethod:implMethod)] |
|
343 |
"/ thenSelect:[:comment | comment notEmptyOrNil]. |
|
344 |
"/ ]. |
|
345 |
"/ comments := comments collect:[:each | each colorizeAllWith:(UserPreferences current commentColor) ]. |
|
346 |
"/ short ifTrue:[ |
|
347 |
"/ comments := comments collect:[:implMethodComment | implMethodComment firstLine] as:Set. |
|
348 |
"/ comments size == 1 ifTrue:[ |
|
349 |
"/ ^ info , ' ' , (comments first). |
|
350 |
"/ ]. |
|
351 |
"/ ^ info |
|
352 |
"/ ]. |
|
353 |
"/ info := info,'\'withCRs. |
|
354 |
"/ comments |
|
355 |
"/ with:implementingClasses |
|
356 |
"/ do:[:eachComment :eachClass | |
|
357 |
"/ info := info,'\comment in ',eachClass name,':\',(eachComment asStringCollection asString) |
|
358 |
"/ ]. |
|
359 |
"/ ]. |
|
360 |
"/ ]. |
|
1728 | 361 |
^ info |
1854 | 362 |
|
3798 | 363 |
"Modified: / 30-04-2016 / 17:08:11 / cg" |
4382 | 364 |
"Modified: / 05-03-2019 / 02:19:39 / Claus Gittinger" |
1728 | 365 |
! |
366 |
||
2193
9416fc17ee62
pass the interval to the explainer
Claus Gittinger <cg@exept.de>
parents:
2191
diff
changeset
|
367 |
explainMethodNode:node in:code forClass:cls short:short interval:intervalIfKnown |
3203 | 368 |
|srchClass selector selectorString implClass |
3859 | 369 |
"sendingMethods numSendingMethods sendingClasses" | |
1728 | 370 |
|
4388 | 371 |
cls isNil ifTrue:[^ nil]. |
372 |
||
3203 | 373 |
selector := node selector. |
3549 | 374 |
selector := selector asSymbolIfInterned. "/ avoid creating new symbols. |
3842 | 375 |
selectorString := selector printString contractTo:50. |
1728 | 376 |
|
377 |
(srchClass := cls superclass) notNil ifTrue:[ |
|
3549 | 378 |
implClass := srchClass whichClassIncludesSelector:selector. |
379 |
implClass notNil ifTrue:[ |
|
3855 | 380 |
^ '%1 overrides implementation in %2.' |
3859 | 381 |
bindWith:(self asLink:selectorString "allBold" to:(self actionToOpenMethodFinderFor:selector)) |
382 |
with:(self asLink:implClass name "allBold" to:(self actionToBrowseClass:implClass selector:selector)) |
|
3549 | 383 |
]. |
1728 | 384 |
]. |
2223
50b76baab48b
changed: #explainMethodNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2214
diff
changeset
|
385 |
(cls includesSelector:selector) ifFalse:[ |
3859 | 386 |
^ '%1: a new method.' bindWith:selectorString "allBold" |
1728 | 387 |
]. |
388 |
"/ |
|
3203 | 389 |
"/ sendingMethods := SystemBrowser |
390 |
"/ allCallsOn:selector |
|
391 |
"/ in:(cls withAllSubclasses , cls allSubclasses) |
|
392 |
"/ ignoreCase:false |
|
1728 | 393 |
"/ match:false. |
394 |
"/ sendingMethods := sendingMethods select:[:eachMethod | eachMethod mclass notNil]. "/ remove unbound ones |
|
395 |
"/ |
|
396 |
"/ sendingClasses := (sendingMethods collect:[:eachMethod | eachMethod mclass]) asSet. |
|
397 |
"/ numSendingMethods := sendingMethods size. |
|
398 |
"/ numSendingMethods == 1 ifTrue:[ |
|
399 |
"/ sendingClasses first == cls ifTrue:[ |
|
3203 | 400 |
"/ ^ '%1: sent locally from %2.' |
1728 | 401 |
"/ bindWith:boldSelectorString |
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
402 |
"/ with:sendingMethods first selector "allBold" |
1728 | 403 |
"/ ]. |
3203 | 404 |
"/ ^ '%1: sent in hierarchy from %2 in %3.' |
1728 | 405 |
"/ bindWith:boldSelectorString |
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
406 |
"/ with:sendingMethods first selector "allBold" |
1728 | 407 |
"/ with:sendingClasses first name. |
408 |
"/ ]. |
|
409 |
"/ numSendingMethods == 2 ifTrue:[ |
|
410 |
"/ sendingClasses asIdentitySet size == 1 ifTrue:[ |
|
411 |
"/ sendingClasses first == cls ifTrue:[ |
|
3203 | 412 |
"/ ^ '%1: sent locally from %2 and %3.' |
1728 | 413 |
"/ bindWith:boldSelectorString |
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
414 |
"/ with:sendingMethods first selector "allBold" |
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
415 |
"/ with:sendingMethods second selector "allBold" |
1728 | 416 |
"/ ]. |
3203 | 417 |
"/ ^ '%1: sent in hierarchy from %2 and %3 in %4.' |
1728 | 418 |
"/ bindWith:boldSelectorString |
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
419 |
"/ with:sendingMethods first selector "allBold" |
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
420 |
"/ with:sendingMethods second selector "allBold" |
1728 | 421 |
"/ with:sendingClasses first name. |
422 |
"/ ]. |
|
423 |
"/ ]. |
|
424 |
"/ numSendingMethods == 0 ifTrue:[ |
|
3203 | 425 |
"/"/ ^ '%1: no sender found.' |
1728 | 426 |
"/"/ bindWith:boldSelectorString. |
427 |
"/ ^ nil |
|
428 |
"/ ]. |
|
3203 | 429 |
"/ ^ '%1: %2 sending methods in hierarchy.' |
1728 | 430 |
"/ bindWith:boldSelectorString |
431 |
"/ with:numSendingMethods. |
|
432 |
"/ |
|
433 |
"/ "/ the following is too expensive... |
|
434 |
"/"/ sendingMethods := SystemBrowser allCallsOn:selector in:Smalltalk allClasses. |
|
435 |
"/"/ numSendingMethods == 0 ifTrue:[ |
|
436 |
"/"/ ^ '%1: nowhere sent.' bindWith:boldSelectorString |
|
437 |
"/"/ ]. |
|
438 |
"/"/ numSendingMethods == 1 ifTrue:[ |
|
439 |
"/"/ sendingMethods first mclass == cls ifTrue:[ |
|
3203 | 440 |
"/"/ ^ '%1: only sent from %2.' |
1728 | 441 |
"/"/ bindWith:boldSelectorString |
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
442 |
"/"/ with:sendingMethods first selector "allBold" |
1728 | 443 |
"/"/ ]. |
3203 | 444 |
"/"/ ^ '%1: only sent from %2 in %3.' |
1728 | 445 |
"/"/ bindWith:boldSelectorString |
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
446 |
"/"/ with:sendingMethods first selector "allBold" |
1728 | 447 |
"/"/ with:sendingMethods first mclass name. |
448 |
"/"/ ]. |
|
449 |
"/"/ sendingClasses := (sendingMethods collect:[:eachMethod | eachMethod mclass]) asSet. |
|
450 |
"/"/ sendingClasses size == 1 ifTrue:[ |
|
451 |
"/"/ sendingClasses first == cls ifTrue:[ |
|
3203 | 452 |
"/"/ ^ '%1: locally sent from %2 methods.' |
1728 | 453 |
"/"/ bindWith:boldSelectorString |
454 |
"/"/ with:numSendingMethods |
|
455 |
"/"/ ]. |
|
3203 | 456 |
"/"/ ^ '%1 only sent from %2 methods in %3.' |
1728 | 457 |
"/"/ bindWith:boldSelectorString |
458 |
"/"/ with:numSendingMethods |
|
459 |
"/"/ with:sendingClasses first name. |
|
460 |
"/"/ ]. |
|
461 |
||
462 |
^ nil |
|
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
463 |
|
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
464 |
"Modified: / 09-10-2006 / 12:11:16 / cg" |
4388 | 465 |
"Modified: / 05-03-2019 / 03:30:22 / Claus Gittinger" |
1728 | 466 |
! |
467 |
||
3203 | 468 |
explainNode:node in:code forClass:cls short:short |
2193
9416fc17ee62
pass the interval to the explainer
Claus Gittinger <cg@exept.de>
parents:
2191
diff
changeset
|
469 |
self explainNode:node in:code forClass:cls short:short interval:nil |
9416fc17ee62
pass the interval to the explainer
Claus Gittinger <cg@exept.de>
parents:
2191
diff
changeset
|
470 |
! |
9416fc17ee62
pass the interval to the explainer
Claus Gittinger <cg@exept.de>
parents:
2191
diff
changeset
|
471 |
|
9416fc17ee62
pass the interval to the explainer
Claus Gittinger <cg@exept.de>
parents:
2191
diff
changeset
|
472 |
explainNode:node in:code forClass:cls short:short interval:intervalIfKnown |
4210 | 473 |
"parsetree based explanations" |
474 |
||
1728 | 475 |
node isVariable ifTrue:[ |
3810 | 476 |
^ self explainVariableNode:node in:code forClass:cls short:short interval:intervalIfKnown. |
1728 | 477 |
]. |
478 |
||
479 |
node isLiteral ifTrue:[ |
|
3810 | 480 |
^ self explainLiteralNode:node in:code forClass:cls short:short interval:intervalIfKnown |
1728 | 481 |
]. |
482 |
||
483 |
node isMessage ifTrue:[ |
|
3810 | 484 |
^ self explainMessageNode:node in:code forClass:cls short:short interval:intervalIfKnown |
1728 | 485 |
]. |
486 |
||
487 |
node isMethod ifTrue:[ |
|
3810 | 488 |
^ self explainMethodNode:node in:code forClass:cls short:short interval:intervalIfKnown |
1728 | 489 |
]. |
490 |
^ nil |
|
4210 | 491 |
|
492 |
"Modified (comment): / 27-11-2017 / 18:05:22 / cg" |
|
1728 | 493 |
! |
494 |
||
4381 | 495 |
explainVariableNode:node in:code forClass:aClassOrNil short:short interval:intervalIfKnown |
3842 | 496 |
|expl nm nmBold definingNode namePart argNode argClass argClassSet| |
1728 | 497 |
|
498 |
nm := node name. |
|
499 |
||
500 |
(#( 'self' 'super' 'thisContext' 'here') includes:nm) ifTrue:[ |
|
4381 | 501 |
^ Explainer explainPseudoVariable:nm in:aClassOrNil short:short |
1728 | 502 |
]. |
503 |
||
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
504 |
nm notNil ifTrue:[ nmBold := nm "allBold" ]. |
1728 | 505 |
|
506 |
definingNode := node whoDefines:nm. |
|
507 |
definingNode notNil ifTrue:[ |
|
3810 | 508 |
namePart := '''' , nmBold , ''''. |
509 |
definingNode isMethod ifTrue:[ |
|
3842 | 510 |
argNode := definingNode arguments detect:[:arg | arg name = nm] ifNone:nil. |
511 |
argNode notNil ifTrue:[ |
|
3883 | 512 |
expl := namePart , ': a method argument.'. |
3842 | 513 |
|
4381 | 514 |
argClassSet := self guessPossibleClassesFor:argNode in:code forClass:aClassOrNil. |
3842 | 515 |
argClassSet size == 1 ifTrue:[ |
516 |
argClass := argClassSet first. |
|
517 |
]. |
|
3810 | 518 |
]. |
519 |
]. |
|
520 |
expl isNil ifTrue:[ |
|
521 |
definingNode isBlock ifTrue:[ |
|
522 |
(definingNode arguments contains:[:arg | arg name = nm]) ifTrue:[ |
|
3883 | 523 |
expl := namePart , ': a block argument.' |
3810 | 524 |
]. |
525 |
]. |
|
526 |
]. |
|
527 |
expl isNil ifTrue:[ |
|
3885 | 528 |
| parentNode setOfTypes isLocal typesDescription | |
3810 | 529 |
|
530 |
(parentNode := definingNode parent) notNil ifTrue:[ |
|
531 |
(isLocal := parentNode isMethod) ifTrue:[ |
|
3883 | 532 |
expl := namePart , ': a method temporary.'. |
3810 | 533 |
] ifFalse:[ |
534 |
(isLocal := parentNode isBlock) ifTrue:[ |
|
3883 | 535 |
expl := namePart , ': a block temporary.'. |
3810 | 536 |
] |
537 |
]. |
|
538 |
isLocal ifTrue:[ |
|
539 |
setOfTypes := Set new. |
|
540 |
self addTypesAssignedToLocal:nm inTree:parentNode to:setOfTypes. |
|
3885 | 541 |
setOfTypes remove:UndefinedObject ifAbsent:[]. |
3810 | 542 |
typesDescription := self typeDescriptionFor:setOfTypes andSelector:nil. |
543 |
typesDescription notNil ifTrue:[ |
|
544 |
expl := expl,' (',typesDescription,')'. |
|
545 |
]. |
|
546 |
]. |
|
547 |
]. |
|
548 |
]. |
|
549 |
expl isNil ifTrue:[ |
|
3883 | 550 |
expl := namePart , ': temporary.' |
3810 | 551 |
]. |
4381 | 552 |
aClassOrNil notNil ifTrue:[ |
553 |
(aClassOrNil allInstanceVariableNames includes:nm) ifTrue:[ |
|
554 |
expl := expl , ' (instance variable is hidden)' |
|
555 |
]. |
|
3810 | 556 |
]. |
557 |
^ expl. |
|
1728 | 558 |
]. |
1938 | 559 |
|
4381 | 560 |
^ Explainer explain:node name in:code forClass:aClassOrNil short:short |
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
561 |
|
1938 | 562 |
"Modified: / 07-11-2006 / 12:22:09 / cg" |
4381 | 563 |
"Modified: / 05-03-2019 / 01:11:01 / Claus Gittinger" |
1728 | 564 |
! |
565 |
||
3203 | 566 |
fetchCommentOfMethod:mthd |
3885 | 567 |
"retrieve the comment of a method |
568 |
(if possible and there is one; otherwise, return nil)" |
|
569 |
||
570 |
|methodSource methodComment lines maxNumLines| |
|
571 |
||
572 |
self withWaitCursorDo:[ |
|
573 |
SourceCodeManagerError handle:[:ex | |
|
574 |
] do:[ |
|
575 |
methodSource := mthd source. |
|
576 |
methodComment := mthd comment |
|
3883 | 577 |
]. |
3885 | 578 |
]. |
3883 | 579 |
|
3885 | 580 |
methodComment isEmptyOrNil ifTrue:[^ nil]. |
581 |
||
582 |
lines := methodComment asStringCollection. |
|
583 |
maxNumLines := 1. |
|
584 |
true ifTrue:[ |
|
585 |
methodComment := (lines copyToMax:maxNumLines) asString. |
|
586 |
maxNumLines := 5. |
|
587 |
] ifFalse:[ |
|
588 |
methodComment := lines first. |
|
589 |
methodComment := methodComment withoutSeparators. |
|
590 |
(methodComment endsWith:',') ifTrue:[ methodComment := methodComment copyButLast:1]. |
|
591 |
methodComment := methodComment withoutSeparators. |
|
592 |
]. |
|
593 |
(lines size > maxNumLines) ifTrue:[ |
|
594 |
methodComment := methodComment , '\...' withCRs |
|
3233 | 595 |
]. |
3885 | 596 |
^ (methodComment) withColor:(UserPreferences current commentColor). |
597 |
||
598 |
"Created: / 14-09-2006 / 14:11:58 / cg" |
|
599 |
"Modified (comment): / 30-04-2016 / 16:17:18 / cg" |
|
600 |
! |
|
601 |
||
602 |
fetchDescriptionOfMethod:mthd |
|
603 |
"retrieve a desription of a method |
|
604 |
(if possible and there is one; otherwise, return nil)" |
|
605 |
||
3888 | 606 |
|methodDecl methodSource methodComment lines maxNumLines firstIndent| |
3885 | 607 |
|
608 |
self withWaitCursorDo:[ |
|
609 |
SourceCodeManagerError handle:[:ex | |
|
610 |
] do:[ |
|
611 |
methodSource := mthd source. |
|
3918 | 612 |
mthd selector isNil ifTrue:[ |
613 |
methodDecl := '??? (method removed from class)'. |
|
614 |
] ifFalse:[ |
|
615 |
methodDecl := mthd methodDefinitionTemplate. |
|
616 |
]. |
|
3885 | 617 |
methodComment := mthd comment. |
618 |
]. |
|
619 |
]. |
|
620 |
methodComment isEmptyOrNil ifTrue:[ |
|
621 |
^ methodDecl |
|
3888 | 622 |
]. |
3891 | 623 |
lines := methodComment asStringCollection withoutLeadingAndTrailingBlankLines. |
624 |
lines isEmptyOrNil ifTrue:[ |
|
625 |
^ methodDecl |
|
626 |
]. |
|
627 |
||
3888 | 628 |
firstIndent := 0. |
3889 | 629 |
lines size > 1 ifTrue:[ |
3888 | 630 |
|line2| |
3889 | 631 |
line2 := lines at:2. |
3888 | 632 |
line2 notEmpty ifTrue:[ |
4153 | 633 |
firstIndent := (line2 indexOfNonSeparator - 1) max:0. |
3888 | 634 |
]. |
3885 | 635 |
]. |
3889 | 636 |
lines := lines |
3888 | 637 |
collect:[:line | |
638 |
|l| |
|
639 |
l := line withTabsExpanded. |
|
640 |
l indexOfNonSeparator > firstIndent ifTrue:[ |
|
641 |
l := l copyFrom:firstIndent+1 |
|
642 |
]. |
|
643 |
l |
|
644 |
]. |
|
3889 | 645 |
methodComment := lines asString. |
3888 | 646 |
|
3885 | 647 |
^ methodDecl , Character cr , |
648 |
(methodComment withColor:(UserPreferences current commentColor)). |
|
3855 | 649 |
|
3888 | 650 |
"/ methodComment isEmptyOrNil ifTrue:[^ nil]. |
651 |
"/ |
|
652 |
"/ lines := methodComment asStringCollection. |
|
653 |
"/ maxNumLines := 1. |
|
654 |
"/true ifTrue:[ |
|
655 |
"/ methodComment := (lines copyToMax:maxNumLines) asString. |
|
656 |
"/ maxNumLines := 5. |
|
657 |
"/] ifFalse:[ |
|
658 |
"/ methodComment := lines first. |
|
659 |
"/ methodComment := methodComment withoutSeparators. |
|
660 |
"/ (methodComment endsWith:',') ifTrue:[ methodComment := methodComment copyButLast:1]. |
|
661 |
"/ methodComment := methodComment withoutSeparators. |
|
662 |
"/]. |
|
663 |
"/ (lines size > maxNumLines) ifTrue:[ |
|
664 |
"/ methodComment := methodComment , '\...' withCRs |
|
665 |
"/ ]. |
|
666 |
"/ ^ (methodComment) withColor:(UserPreferences current commentColor). |
|
1909 | 667 |
|
668 |
"Created: / 14-09-2006 / 14:11:58 / cg" |
|
4153 | 669 |
"Modified (format): / 20-06-2017 / 10:29:13 / cg" |
1909 | 670 |
! |
671 |
||
4381 | 672 |
guessPossibleClassesFor:node in:code forClass:aClassOrNil |
2191
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
673 |
"given a node of some code of a method in cls, |
3885 | 674 |
return a collection of possible types of the node." |
2191
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
675 |
|
2809
bbf42cc4d305
changed: #guessPossibleImplementorClassesFor:in:forClass:
Claus Gittinger <cg@exept.de>
parents:
2471
diff
changeset
|
676 |
|nm globalValue definer instances classesOfInstVars ns| |
1728 | 677 |
|
4381 | 678 |
node isLiteral ifTrue:[ |
679 |
^ Array with:(node value class) |
|
680 |
]. |
|
1728 | 681 |
node isVariable ifTrue:[ |
3549 | 682 |
nm := node name. |
1728 | 683 |
|
4381 | 684 |
(aClassOrNil isNil) ifTrue:[ |
685 |
(nm isUppercaseFirst and:[ nm knownAsSymbol ]) ifTrue:[ |
|
686 |
globalValue := Smalltalk at:nm asSymbol. |
|
687 |
globalValue isClass ifTrue:[ |
|
688 |
^ Array with:globalValue class. |
|
689 |
]. |
|
690 |
]. |
|
691 |
^ nil |
|
692 |
]. |
|
693 |
||
3549 | 694 |
nm = #self ifTrue:[ |
4381 | 695 |
^ aClassOrNil withAllSubclasses |
3549 | 696 |
]. |
697 |
nm = #here ifTrue:[ |
|
4381 | 698 |
^ aClassOrNil withAllSuperclasses |
3549 | 699 |
]. |
700 |
nm = #super ifTrue:[ |
|
4381 | 701 |
^ aClassOrNil allSuperclasses |
3549 | 702 |
]. |
1728 | 703 |
|
3549 | 704 |
definer := node whoDefines:nm. |
705 |
definer isNil ifTrue:[ |
|
706 |
"/ not a local or argument |
|
4381 | 707 |
(aClassOrNil instanceVariableNames includes:nm) ifTrue:[ |
3549 | 708 |
"/ ok - an instVar; see what values we find... |
4381 | 709 |
instances := aClassOrNil allSubInstances select:[:eachInst | eachInst isProtoObject not]. |
3549 | 710 |
classesOfInstVars := instances collect:[:eachInst | (eachInst instVarNamed:nm) class] as:Set. |
711 |
^ classesOfInstVars. |
|
712 |
]. |
|
4381 | 713 |
(aClassOrNil classVariableNames includes:nm) ifTrue:[ |
714 |
^ Array with:(aClassOrNil classVarAt:nm asSymbol) class. |
|
3549 | 715 |
]. |
716 |
nm isUppercaseFirst ifTrue:[ |
|
717 |
nm knownAsSymbol ifTrue:[ |
|
718 |
globalValue := Smalltalk at:nm asSymbol. |
|
719 |
globalValue isClass ifTrue:[ |
|
720 |
^ Array with:globalValue class. |
|
721 |
]. |
|
722 |
]. |
|
4381 | 723 |
((ns := aClassOrNil topNameSpace) notNil and:[ns ~~ Smalltalk]) ifTrue:[ |
3549 | 724 |
nm knownAsSymbol ifTrue:[ |
725 |
globalValue := ns at:nm asSymbol. |
|
726 |
globalValue isClass ifTrue:[ |
|
727 |
^ Array with:globalValue class. |
|
728 |
]. |
|
729 |
]. |
|
730 |
] |
|
731 |
]. |
|
732 |
]. |
|
3885 | 733 |
definer isMethod ifTrue:[ |
734 |
|callers argNr setOfTypes| |
|
735 |
||
736 |
argNr := definer arguments findFirst:[:arg | arg name = nm]. |
|
737 |
setOfTypes := IdentitySet new. |
|
738 |
"/ see who calls this message; are there any calls with an obvious type? |
|
739 |
callers := SystemBrowser allCallsOn:definer selector. |
|
740 |
callers do:[:eachCaller | |
|
741 |
|tree| |
|
3940 | 742 |
(tree := eachCaller parseTree) notNil ifTrue:[ |
743 |
tree allMessageNodesDo:[:msg | |
|
744 |
|argExpr| |
|
745 |
||
746 |
msg selector = definer selector ifTrue:[ |
|
747 |
argExpr := (msg arguments at:argNr). |
|
748 |
self addTypeOfExpressionNode:argExpr forAssignmentTo:nil to:setOfTypes. |
|
749 |
]. |
|
750 |
]. |
|
751 |
]. |
|
3885 | 752 |
]. |
753 |
setOfTypes notEmpty ifTrue:[ |
|
754 |
^ setOfTypes. |
|
755 |
]. |
|
756 |
]. |
|
3549 | 757 |
^ nil |
1728 | 758 |
]. |
759 |
||
2191
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
760 |
"/ node isMessage ifTrue:[ |
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
761 |
"/ recClassSet := self guessPossibleImplementorClassesFor:(node receiver) in:code forClass:cls. |
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
762 |
"/ recClassSet isNil ifTrue:[ ^ nil ]. |
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
763 |
"/ recClassSet isEmpty ifTrue:[ ^ nil ]. |
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
764 |
"/ |
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
765 |
"/ implSet := recClassSet collect:[:recClass | recClass whichClassIncludesSelector:node selector]. |
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
766 |
"/ "/ toDo: for each implementor, parse its method for possible return types. |
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
767 |
"/ ^ rsltClassSet. |
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
768 |
"/ ]. |
1731 | 769 |
^ nil |
2809
bbf42cc4d305
changed: #guessPossibleImplementorClassesFor:in:forClass:
Claus Gittinger <cg@exept.de>
parents:
2471
diff
changeset
|
770 |
|
bbf42cc4d305
changed: #guessPossibleImplementorClassesFor:in:forClass:
Claus Gittinger <cg@exept.de>
parents:
2471
diff
changeset
|
771 |
"Modified: / 07-02-2012 / 22:19:53 / cg" |
4381 | 772 |
"Modified: / 05-03-2019 / 01:09:49 / Claus Gittinger" |
3885 | 773 |
! |
774 |
||
775 |
withWaitCursorDo:aBlock |
|
776 |
"with wait cursor; |
|
777 |
however: this class is in libcomp (should be in libtool) |
|
778 |
so check if WindowGroup (from libview) is present" |
|
779 |
||
780 |
|windowGroup wg| |
|
781 |
||
782 |
windowGroup := Smalltalk at:#WindowGroup. |
|
783 |
windowGroup notNil ifTrue:[ |
|
784 |
(wg := windowGroup activeGroup) notNil ifTrue:[ |
|
785 |
^ wg withWaitCursorDo:aBlock. |
|
786 |
]. |
|
787 |
]. |
|
788 |
^ aBlock value. |
|
1728 | 789 |
! ! |
790 |
||
791 |
!Explainer class methodsFor:'explaining-naive'! |
|
792 |
||
4378 | 793 |
explain:someText in:source forClass:aClassOrNil |
6 | 794 |
"Given a source and a substring of it, return a string containing |
795 |
an explanation. |
|
49 | 796 |
This is just a q&d implementation - to be correct, it should use the parser, |
797 |
and explain from the parsetree (instead of doing string matches). |
|
798 |
This leads to some wrong explanations, for example if some string is |
|
839 | 799 |
used as selector within a string, or if a variable is named like a |
800 |
message selector. I.e. the explanation should be context sensitive. |
|
49 | 801 |
Also, there could be much more detailed explanations." |
2 | 802 |
|
4378 | 803 |
^ self explain:someText in:source forClass:aClassOrNil short:false |
2037
003d9b5a2788
explain shared pool variables
Claus Gittinger <cg@exept.de>
parents:
2031
diff
changeset
|
804 |
|
003d9b5a2788
explain shared pool variables
Claus Gittinger <cg@exept.de>
parents:
2031
diff
changeset
|
805 |
"Modified: / 07-06-2007 / 11:34:05 / cg" |
4378 | 806 |
"Modified (format): / 04-03-2019 / 10:09:46 / Claus Gittinger" |
1183 | 807 |
! |
808 |
||
4378 | 809 |
explain:someText in:source forClass:aClassOrNil short:shortText |
1183 | 810 |
"Given a source and a substring of it, return a string containing |
811 |
an explanation. |
|
812 |
This is just a q&d implementation - to be correct, it should use the parser, |
|
813 |
and explain from the parsetree (instead of doing string matches). |
|
814 |
This leads to some wrong explanations, for example if some string is |
|
815 |
used as selector within a string, or if a variable is named like a |
|
816 |
message selector. I.e. the explanation should be context sensitive. |
|
817 |
Also, there could be much more detailed explanations." |
|
818 |
||
3319 | 819 |
|explainer variables c string explanation tmp1 |
4187 | 820 |
spc sym sel stringText cls clsName val valString color| |
2 | 821 |
|
675 | 822 |
string := someText string withoutSeparators. |
2314
0c590d9937bd
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2292
diff
changeset
|
823 |
string isEmpty ifTrue:[ ^ nil ]. |
0c590d9937bd
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2292
diff
changeset
|
824 |
|
2214 | 825 |
stringText := string allBold. |
2414
4da315c5bcf4
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2316
diff
changeset
|
826 |
"/ stringText := '''' , stringText , ''''. |
49 | 827 |
|
828 |
" |
|
829 |
ask parser for variable names |
|
830 |
" |
|
3070 | 831 |
ParseError catch:[ |
4378 | 832 |
explainer := self parseMethod:source in:aClassOrNil ignoreErrors:true ignoreWarnings:true. |
1357 | 833 |
]. |
3320 | 834 |
"/ bad leftover from a stupid return value from ancient times |
3319 | 835 |
explainer == #Error ifTrue:[ explainer := nil ]. |
836 |
||
837 |
(explainer notNil) ifTrue:[ |
|
3233 | 838 |
"look for variables" |
2 | 839 |
|
3319 | 840 |
variables := explainer methodVars. |
3233 | 841 |
(variables notNil and:[variables includes:string]) ifTrue:[ |
842 |
^ stringText , ' a method variable.' |
|
843 |
]. |
|
3319 | 844 |
variables := explainer methodArgs. |
3233 | 845 |
(variables notNil and:[variables includes:string]) ifTrue:[ |
846 |
^ stringText , ' a method argument.' |
|
847 |
] |
|
2 | 848 |
]. |
49 | 849 |
|
3319 | 850 |
explainer isNil ifTrue:[ |
4378 | 851 |
explainer := self for:(ReadStream on:source) in:aClassOrNil |
2 | 852 |
]. |
853 |
||
4378 | 854 |
aClassOrNil notNil ifTrue:[ |
855 |
"instvars/class instVars" |
|
856 |
c := aClassOrNil whichClassDefinesInstVar:string. |
|
857 |
c notNil ifTrue:[ |
|
858 |
c isMeta ifTrue:[ |
|
859 |
clsName := c theNonMetaclass name. |
|
860 |
shortText ifTrue:[ |
|
861 |
clsName := self asClassLink:clsName. |
|
862 |
stringText := stringText , ': a class instVar in ' , clsName |
|
863 |
] ifFalse:[ |
|
864 |
stringText := stringText, ': a class instance variable inherited from ' , clsName |
|
865 |
]. |
|
866 |
val := aClassOrNil theNonMetaclass instVarNamed:string. |
|
867 |
valString := self valueStringFor:val. |
|
868 |
^ stringText , ' (' , valString , ').' |
|
3233 | 869 |
]. |
4378 | 870 |
^ self explainInstanceVariable:string inClass:c short:shortText. |
3233 | 871 |
]. |
2 | 872 |
]. |
4378 | 873 |
|
2986 | 874 |
string isWideString ifFalse:[ |
4378 | 875 |
aClassOrNil notNil ifTrue:[ |
876 |
"classvars" |
|
877 |
c := explainer inWhichClassIsClassVar:string. |
|
878 |
c notNil ifTrue:[ |
|
879 |
val := c theNonMetaclass classVarAt:string. "/ Smalltalk at:(clsName , ':' , string) asSymbol. |
|
880 |
valString := self valueStringFor:val. |
|
881 |
||
882 |
val == true ifTrue:[ |
|
4391 | 883 |
color := Color darkGreen. |
4187 | 884 |
] ifFalse:[ |
4378 | 885 |
val == false ifTrue:[ |
4391 | 886 |
color := Color darkRed |
4378 | 887 |
] ifFalse:[ |
888 |
val == nil ifTrue:[ |
|
889 |
color := Color darkGrey |
|
890 |
]. |
|
4187 | 891 |
]. |
892 |
]. |
|
4378 | 893 |
color notNil ifTrue:[ |
894 |
stringText := stringText withColor:color. |
|
895 |
valString := valString withColor:color. |
|
3233 | 896 |
]. |
4378 | 897 |
|
898 |
clsName := c name. |
|
899 |
shortText ifTrue:[ |
|
900 |
clsName := self asClassLink:clsName. |
|
901 |
stringText := stringText , ': a classVar in ' , clsName |
|
902 |
] ifFalse:[ |
|
903 |
stringText := stringText , ': a class variable in ' , clsName |
|
904 |
]. |
|
905 |
||
906 |
^ stringText , ' (' , valString , ').' |
|
3233 | 907 |
]. |
908 |
]. |
|
4378 | 909 |
|
910 |
aClassOrNil notNil ifTrue:[ |
|
911 |
"private classes" |
|
912 |
c := aClassOrNil theNonMetaclass. |
|
913 |
c privateClasses do:[:pClass | |
|
914 |
(pClass name = string |
|
915 |
or:[pClass nameWithoutPrefix = string]) ifTrue:[ |
|
916 |
stringText := self asClassLink:pClass name. |
|
917 |
stringText := stringText , ': a private class in ''' , c name , '''.'. |
|
918 |
shortText ifFalse:[ |
|
919 |
stringText := (stringText , '\\It is only visible locally.') withCRs |
|
3407 | 920 |
]. |
4378 | 921 |
^ stringText withCRs |
922 |
]. |
|
923 |
]. |
|
924 |
]. |
|
925 |
||
926 |
aClassOrNil notNil ifTrue:[ |
|
927 |
aClassOrNil theNonMetaclass sharedPoolNames do:[:eachPoolName | |
|
928 |
|sharedPool sharedPoolSym poolName| |
|
929 |
||
930 |
sharedPoolSym := string asSymbolIfInterned. |
|
931 |
sharedPoolSym notNil ifTrue:[ |
|
932 |
sharedPool := Smalltalk classNamed:eachPoolName. |
|
933 |
sharedPool notNil ifTrue:[ |
|
934 |
sharedPool isSharedPool ifFalse:[ |
|
935 |
^ 'oops - not a shared pool: ',eachPoolName |
|
936 |
]. |
|
937 |
(sharedPool includesKey:sharedPoolSym) ifTrue:[ |
|
938 |
poolName := sharedPool name. |
|
939 |
poolName := self asClassLink:eachPoolName. |
|
940 |
stringText := stringText , ': a pool variable in ',poolName. |
|
941 |
val := sharedPool at:sharedPoolSym. |
|
942 |
valString := self valueStringFor:val. |
|
943 |
^ stringText , ' (' , valString , ').' |
|
944 |
]. |
|
3407 | 945 |
]. |
3233 | 946 |
]. |
947 |
]. |
|
948 |
]. |
|
2037
003d9b5a2788
explain shared pool variables
Claus Gittinger <cg@exept.de>
parents:
2031
diff
changeset
|
949 |
|
4378 | 950 |
aClassOrNil notNil ifTrue:[ |
951 |
"namespace & global variables" |
|
952 |
(spc := aClassOrNil nameSpace) notNil ifTrue:[ |
|
953 |
sym := (spc name , '::' , string) asSymbolIfInterned. |
|
954 |
sym notNil ifTrue:[ |
|
955 |
(cls := Smalltalk at:sym) isBehavior ifTrue:[ |
|
956 |
stringText := self asClassLink:sym. |
|
957 |
string := stringText , ': '. |
|
958 |
cls name = sym ifFalse:[ |
|
959 |
string := string , 'refers to ',cls name,', ' |
|
960 |
]. |
|
961 |
cls isSharedPool ifTrue:[ |
|
962 |
string := string , 'a sharedPool'. |
|
963 |
] ifFalse:[ |
|
964 |
string := string , 'a class'. |
|
965 |
]. |
|
966 |
||
967 |
string := string , ' in the ''' , spc name , ''' nameSpace'. |
|
968 |
string := string , ' {', (cls category ? '* no category *') ,'}'. |
|
969 |
shortText ifFalse:[ |
|
970 |
string := (string |
|
971 |
, '\\It is only visible within this nameSpace.' |
|
972 |
, '\Access from the outside is possible' |
|
973 |
, '\by the special name ''' , spc name , '::' , string , '''.') withCRs |
|
974 |
]. |
|
975 |
^ string withCRs |
|
3233 | 976 |
]. |
977 |
]. |
|
978 |
]. |
|
979 |
]. |
|
422 | 980 |
|
3866 | 981 |
"/ string knownAsSymbol ifTrue:[ |
3233 | 982 |
"globals & symbols" |
839 | 983 |
|
4378 | 984 |
explanation := self explainKnownSymbol:string inClass:aClassOrNil short:shortText. |
3319 | 985 |
explanation notNil ifTrue:[ |
3233 | 986 |
string isBinarySelector ifTrue:[ |
987 |
"/ some are both known as syntax AND as selector (for example: #| ) |
|
988 |
tmp1 := self explainSyntax:string short:shortText. |
|
989 |
tmp1 notNil ifTrue:[ |
|
3319 | 990 |
^ tmp1 , '\\also:\\' withCRs , explanation |
3233 | 991 |
]. |
992 |
]. |
|
3319 | 993 |
^ explanation |
3233 | 994 |
]. |
995 |
||
996 |
"/ try with added colon ... |
|
997 |
sel := string , ':'. |
|
998 |
Symbol allInstancesDo:[:sym | |
|
999 |
(sym startsWith:sel) ifTrue:[ |
|
4378 | 1000 |
explanation := self explainKnownSymbol:sym inClass:aClassOrNil short:shortText. |
3319 | 1001 |
explanation notNil ifTrue:[ ^ explanation]. |
3233 | 1002 |
] |
1003 |
]. |
|
3866 | 1004 |
"/ ]. |
2 | 1005 |
|
3233 | 1006 |
"try for some obvious things" |
4378 | 1007 |
explanation := self explainPseudoVariable:string in:aClassOrNil short:true. |
3319 | 1008 |
explanation notNil ifTrue:[ ^ explanation]. |
2315
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
1009 |
]. |
2 | 1010 |
|
1011 |
"try syntax ..." |
|
1012 |
||
3319 | 1013 |
explanation := self explainSyntax:string short:shortText. |
1014 |
explanation notNil ifTrue:[ ^ explanation]. |
|
20 | 1015 |
|
1183 | 1016 |
shortText ifTrue:[ |
3883 | 1017 |
|selector| |
1018 |
||
1019 |
(selector := SystemBrowser extractSelectorFrom:string) notNil ifTrue:[ |
|
1020 |
selector ~= string string ifTrue:[ |
|
4378 | 1021 |
^ self explain:selector in:source forClass:aClassOrNil short:shortText |
3883 | 1022 |
]. |
4177 | 1023 |
]. |
1024 |
someText size == 1 ifTrue:[ |
|
1025 |
^ 'no explanation; character encoding: %1 (0x%2)' |
|
1026 |
bindWith:someText first codePoint |
|
1027 |
with:(someText first codePoint hexPrintString:4) |
|
3883 | 1028 |
]. |
3233 | 1029 |
^ 'no explanation' |
1183 | 1030 |
]. |
1031 |
||
3319 | 1032 |
explainer isNil ifTrue:[ |
3233 | 1033 |
^ 'parse error - no explanation' |
2 | 1034 |
]. |
3319 | 1035 |
^ 'Sorry, I cannot explain this (could not figure out what this is). |
1036 |
Please try again with an individual token selected.' |
|
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
1037 |
|
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
1038 |
"Created: / 03-12-1995 / 12:47:37 / cg" |
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
1039 |
"Modified: / 16-04-1997 / 12:46:11 / stefan" |
4187 | 1040 |
"Modified: / 23-08-2017 / 12:44:12 / cg" |
4391 | 1041 |
"Modified: / 13-03-2019 / 21:17:09 / Claus Gittinger" |
2 | 1042 |
! |
1043 |
||
4378 | 1044 |
explainGlobal:string inClass:aClassOrNil short:shortText |
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1045 |
"return an explanation or nil" |
1183 | 1046 |
|
4378 | 1047 |
^ self explainGlobalOrPoolVariable:string inClass:aClassOrNil short:shortText |
2427 | 1048 |
|
1049 |
"Modified: / 14-10-2010 / 11:33:17 / cg" |
|
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1050 |
"Modified (comment): / 28-02-2012 / 10:45:58 / cg" |
4378 | 1051 |
"Modified (format): / 04-03-2019 / 10:09:52 / Claus Gittinger" |
2427 | 1052 |
! |
1053 |
||
4378 | 1054 |
explainGlobalOrPoolVariable:varName inClass:aClassOrNil short:shortText |
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1055 |
"return an explanation or nil" |
2427 | 1056 |
|
4367 | 1057 |
|template shortTemplate bindings |
3972 | 1058 |
sym explanation val pool valText doc| |
141 | 1059 |
|
3878 | 1060 |
"if not even known as key, it's definitely not a global" |
1061 |
sym := varName asSymbolIfInterned. |
|
796 | 1062 |
sym isNil ifTrue:[^ nil]. |
3879 | 1063 |
|
4367 | 1064 |
template := shortTemplate := nil. |
3879 | 1065 |
bindings := Dictionary new. |
1066 |
||
2427 | 1067 |
"a pool variable?" |
4378 | 1068 |
aClassOrNil notNil ifTrue:[ |
1069 |
aClassOrNil theNonMetaclass sharedPoolNames do:[:eachPoolName | |
|
1070 |
pool := aClassOrNil theNonMetaclass nameSpace at:eachPoolName. |
|
4367 | 1071 |
pool isNil ifTrue:[ |
1072 |
pool := Smalltalk at:eachPoolName. |
|
1073 |
]. |
|
3319 | 1074 |
pool isNil ifTrue:[ |
3878 | 1075 |
"/ oops - on the fly we encountered a non existing pool... |
3319 | 1076 |
] ifFalse:[ |
3878 | 1077 |
(pool classVarNames includes:varName) ifTrue:[ |
3879 | 1078 |
template := '%(varName): pool variable in "%(poolName)"'. |
4367 | 1079 |
shortTemplate := '%1 in pool "%2"' bindWith:varName with:eachPoolName. |
3879 | 1080 |
bindings at:'poolName' put:eachPoolName. |
3319 | 1081 |
val := pool classVarAt:sym. |
1082 |
]. |
|
1083 |
]. |
|
1084 |
]. |
|
2427 | 1085 |
]. |
1086 |
||
3879 | 1087 |
bindings at:'varName' put:varName allBold. |
3810 | 1088 |
|
3879 | 1089 |
template isNil ifTrue:[ |
3319 | 1090 |
"try globals" |
3879 | 1091 |
(Smalltalk includesKey:sym) ifFalse:[ |
1092 |
^ '%(varName): an undefined variable.' bindWithArguments:bindings. |
|
1093 |
]. |
|
1094 |
template := '%(varName): global'. |
|
1095 |
val := Smalltalk at:sym. |
|
2427 | 1096 |
]. |
141 | 1097 |
|
1245 | 1098 |
val isBehavior ifTrue:[ |
3319 | 1099 |
"/ a class |
1100 |
val name = sym ifFalse:[ |
|
3879 | 1101 |
"/ an alias (such as OperatingSystem, Screen etc.) |
4040 | 1102 |
template := template,'. Refers to %(realName)'. |
3879 | 1103 |
bindings at:'realName' put:val name. |
3319 | 1104 |
]. |
1979 | 1105 |
|
3319 | 1106 |
(val isRealNameSpace) ifTrue:[ |
3879 | 1107 |
template := template,', a namespace.'. |
1108 |
^ template bindWithArguments:bindings. |
|
3319 | 1109 |
]. |
3879 | 1110 |
|
1111 |
"/ a real class |
|
1112 |
bindings at:'category' put:(val category ? 'uncategorized'). |
|
3319 | 1113 |
shortText ifTrue:[ |
3883 | 1114 |
template := template , ',' , (val isLoaded ifTrue:[' a'] ifFalse:[' an autoloaded']). |
3879 | 1115 |
template := template , (val isSharedPool ifTrue:[' pool'] ifFalse:[' class']). |
1116 |
template := template , ' in %(package) {%(category)}.'. |
|
1117 |
bindings at:'package' put:val package. |
|
4040 | 1118 |
bindings at:'varName' put:(self asClassLink:varName "val name"). |
3879 | 1119 |
^ template bindWithArguments:bindings |
3319 | 1120 |
]. |
1330 | 1121 |
|
3878 | 1122 |
val name = varName ifTrue:[ |
3322 | 1123 |
false ifTrue:[ |
1124 |
"/ TODO: generate a short documentation string (comment plus interface) |
|
1125 |
"/ and return { #html->htmlText . #text->regularText} |
|
3972 | 1126 |
"/ so caller can extract what he wants to see... |
3322 | 1127 |
^ (HTMLDocGenerator htmlDocOf:val). |
1128 |
]. |
|
3972 | 1129 |
explanation := varName , ' is '. |
3319 | 1130 |
explanation := explanation , (val isLoaded ifTrue:['a'] ifFalse:['an autoloaded']). |
1131 |
explanation := explanation , (val isSharedPool ifTrue:[' sharedPool'] ifFalse:[' class']). |
|
3972 | 1132 |
explanation := explanation , ' categorized as "' , val category , '"'. |
3319 | 1133 |
explanation := explanation , '\' withCRs , 'in the "' , val package , '" package.'. |
1134 |
(doc := val commentOrDocumentationString) notEmptyOrNil ifTrue:[ |
|
1135 |
doc := doc asStringCollection. |
|
1136 |
doc size > 25 ifTrue:[ |
|
1137 |
doc := doc copyTo:25. |
|
1138 |
doc add:''; add:' ... <more documentation cut off>'. |
|
1139 |
]. |
|
3864 | 1140 |
doc := doc asString withColor:(UserPreferences current commentColor). |
3319 | 1141 |
explanation := explanation,'\\' withCRs,val name,'''s documentation:\'withCRs, doc |
1142 |
]. |
|
1143 |
^ explanation. |
|
1144 |
]. |
|
1245 | 1145 |
|
3319 | 1146 |
explanation := explanation , ' |
1183 | 1147 |
|
3878 | 1148 |
' , varName , ' is bound to the class ' , val name , |
3972 | 1149 |
' in the "' , val category , '" category.'. |
3319 | 1150 |
^ explanation. |
141 | 1151 |
]. |
1152 |
||
2427 | 1153 |
valText := self valueStringFor:val. |
1154 |
||
1245 | 1155 |
shortText ifTrue:[ |
4367 | 1156 |
^ (shortTemplate ? '%1: a global (%2)') |
3881 | 1157 |
bindWith:varName |
1158 |
with:(self asLink:valText to:(self actionToBrowseClass:val class selector:nil)) |
|
1245 | 1159 |
]. |
3881 | 1160 |
|
3319 | 1161 |
explanation := explanation , ' |
1245 | 1162 |
|
2466
75b29e4a34c0
changed: #explainGlobalOrPoolVariable:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2427
diff
changeset
|
1163 |
Its current value is "%1".' bindWith:valText. |
3319 | 1164 |
^ explanation. |
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
1165 |
|
2427 | 1166 |
"Created: / 14-10-2010 / 11:33:04 / cg" |
4040 | 1167 |
"Modified: / 16-11-2016 / 13:08:07 / cg" |
4367 | 1168 |
"Modified: / 22-02-2019 / 11:17:20 / Claus Gittinger" |
4378 | 1169 |
"Modified (format): / 04-03-2019 / 10:10:10 / Claus Gittinger" |
1188 | 1170 |
! |
1171 |
||
4378 | 1172 |
explainHereIn:aClassOrNil short:shortText |
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1173 |
"return an explanation" |
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1174 |
|
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1175 |
|className| |
1188 | 1176 |
|
4378 | 1177 |
aClassOrNil isNil ifTrue:[ |
1178 |
shortText ifTrue:[ |
|
1179 |
^ '"here" - message lookup always starts in the method''s class (always call local method).' |
|
1180 |
]. |
|
1181 |
^ 'like "self", "','here'allBold,'" refers to the object which received the message. |
|
1182 |
||
1183 |
However, when sending a message to "here", the search for methods |
|
1184 |
implementing this message will start in the defining class, |
|
1185 |
instead of the receiver''s class. |
|
1186 |
Thus, using "here", redefined methods will NOT be reached with a here-send and it is ensured, |
|
1187 |
that the local method is called.' |
|
1188 |
]. |
|
1189 |
||
1190 |
className := aClassOrNil name. |
|
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1191 |
shortText ifTrue:[ |
3810 | 1192 |
^ '"here" - message lookup always starts in "%1" (always call local method).' bindWith:className |
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1193 |
]. |
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1194 |
^ 'like "self", "','here'allBold,'" refers to the object which received the message. |
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1195 |
|
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1196 |
However, when sending a message to "here", the search for methods |
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1197 |
implementing this message will start in the defining class (' , className , '), |
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1198 |
instead of the receiver''s class (' , className , ' or subclass). |
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1199 |
Thus, using "here", redefined methods will NOT be reached with a here-send and it is ensured, |
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1200 |
that the local method is called.' |
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1201 |
|
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1202 |
"Created: / 28-02-2012 / 10:44:55 / cg" |
4378 | 1203 |
"Modified: / 04-03-2019 / 10:14:00 / Claus Gittinger" |
1188 | 1204 |
! |
1205 |
||
3798 | 1206 |
explainInstanceVariable:instVarName inClass:aClass short:shortText |
3853 | 1207 |
|varNameInText classNameInText template stringText setOfTypes typesDescription| |
3798 | 1208 |
|
4378 | 1209 |
aClass isNil ifTrue:[^ nil]. |
1210 |
||
3853 | 1211 |
varNameInText := instVarName allBold. |
1212 |
classNameInText := aClass name. |
|
1213 |
||
3798 | 1214 |
shortText ifTrue:[ |
3883 | 1215 |
template := '%1: instVar in %2'. |
3878 | 1216 |
varNameInText := self |
1217 |
asLink:varNameInText |
|
1218 |
info:('Click to browse references to %1' bindWith:instVarName) |
|
1219 |
to:(self actionToBrowseInstvarRefsTo:instVarName inClass:aClass). |
|
3866 | 1220 |
classNameInText := self asClassLink:classNameInText. |
3798 | 1221 |
] ifFalse:[ |
1222 |
template := '%1: an instance variable in %2' |
|
1223 |
]. |
|
3853 | 1224 |
stringText := template bindWith:varNameInText with:classNameInText. |
3798 | 1225 |
|
1226 |
"/ look for instances |
|
1227 |
setOfTypes := IdentitySet new. |
|
1228 |
self addTypesOfInstvar:instVarName inClass:aClass fromExistingInstancesTo:setOfTypes. |
|
1229 |
"/ look for assignments |
|
3878 | 1230 |
aClass withAllSubclassesDo:[:cls | |
1231 |
self addTypesAssignedToInstvar:instVarName inClass:cls to:setOfTypes |
|
1232 |
]. |
|
1233 |
||
1234 |
"/ generate a list of up-to 3 links |
|
3810 | 1235 |
typesDescription := self typeDescriptionFor:setOfTypes andSelector:nil. |
1236 |
typesDescription notNil ifTrue:[ |
|
1237 |
stringText := stringText,' (',typesDescription,')' |
|
1238 |
]. |
|
3798 | 1239 |
^ stringText |
4378 | 1240 |
|
1241 |
"Modified: / 04-03-2019 / 10:14:32 / Claus Gittinger" |
|
3798 | 1242 |
! |
1243 |
||
1188 | 1244 |
explainKnownSymbol:string inClass:aClass |
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1245 |
"return an explanation or nil" |
1188 | 1246 |
|
1247 |
^ self explainKnownSymbol:string inClass:aClass short:false |
|
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1248 |
|
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1249 |
"Modified (comment): / 28-02-2012 / 10:45:40 / cg" |
1188 | 1250 |
! |
1251 |
||
4378 | 1252 |
explainKnownSymbol:string inClass:aClassOrNil short:shortText |
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1253 |
"return an explanation or nil" |
1188 | 1254 |
|
2471 | 1255 |
|sym expl| |
1188 | 1256 |
|
1257 |
sym := string asSymbolIfInterned. |
|
1258 |
sym isNil ifTrue:[^ nil]. |
|
1259 |
||
2427 | 1260 |
"try globals and pools" |
1188 | 1261 |
(Smalltalk includesKey:sym) ifTrue:[ |
4378 | 1262 |
expl := self explainGlobalOrPoolVariable:string inClass:aClassOrNil short:shortText. |
3810 | 1263 |
expl notNil ifTrue:[^ expl]. |
1188 | 1264 |
]. |
1265 |
||
4378 | 1266 |
expl := self explainSelector:string inClass:aClassOrNil short:shortText. |
2471 | 1267 |
expl notNil ifTrue:[^ expl]. |
4378 | 1268 |
^ self explainGlobalOrPoolVariable:string inClass:aClassOrNil short:shortText. |
2427 | 1269 |
|
2471 | 1270 |
"Modified: / 18-01-2011 / 19:13:07 / cg" |
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1271 |
"Modified (comment): / 28-02-2012 / 10:46:06 / cg" |
1188 | 1272 |
! |
1273 |
||
1274 |
explainPseudoVariable:string in:aClass |
|
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1275 |
"return an explanation for the pseudoVariables self, super etc." |
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1276 |
|
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1277 |
<resource: #obsolete> |
1188 | 1278 |
|
1279 |
^ self explainPseudoVariable:string in:aClass short:false |
|
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1280 |
|
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1281 |
"Modified (format): / 28-02-2012 / 10:47:17 / cg" |
1188 | 1282 |
! |
1283 |
||
4378 | 1284 |
explainPseudoVariable:string in:aClassOrNil short:shortText |
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1285 |
"return an explanation for the pseudoVariables self, super etc." |
1188 | 1286 |
|
1287 |
(string = 'self') ifTrue:[ |
|
4378 | 1288 |
^ self explainSelfIn:aClassOrNil short:shortText |
1188 | 1289 |
]. |
1290 |
||
1291 |
(string = 'super') ifTrue:[ |
|
4378 | 1292 |
^ self explainSuperIn:aClassOrNil short:shortText |
1188 | 1293 |
]. |
1294 |
||
1295 |
(string = 'here') ifTrue:[ |
|
4378 | 1296 |
^ self explainHereIn:aClassOrNil short:shortText |
1188 | 1297 |
]. |
1298 |
||
1299 |
(string = 'thisContext') ifTrue:[ |
|
3810 | 1300 |
shortText ifTrue:[ |
1301 |
^ '''thisContext'' - the current stack frame as an object.' |
|
1302 |
]. |
|
1303 |
^ 'thisContext is a pseudo variable (i.e. it is built in). |
|
1188 | 1304 |
|
1305 |
ThisContext always refers to the context object for the currently executed method or |
|
1306 |
block (an instance of Context or BlockContext respectively). The calling chain and calling |
|
1307 |
receivers/selectors can be accessed via thisContext.' |
|
1308 |
]. |
|
1309 |
||
1310 |
(string = 'true') ifTrue:[ |
|
3810 | 1311 |
shortText ifTrue:[ |
1312 |
^ '''true'' - the truth and nothing but the truth.' |
|
1313 |
]. |
|
1314 |
^ 'true is a pseudo variable (i.e. it is built in). |
|
1188 | 1315 |
|
1316 |
True represents logical truth. It is the one and only instance of class True.' |
|
1317 |
]. |
|
1318 |
||
1319 |
(string = 'false') ifTrue:[ |
|
3810 | 1320 |
shortText ifTrue:[ |
1321 |
^ '''false'' - obvisously not true.' |
|
1322 |
]. |
|
1323 |
^ 'false is a pseudo variable (i.e. it is built in). |
|
1188 | 1324 |
|
1325 |
False represents logical falseness. It is the one and only instance of class False.' |
|
1326 |
]. |
|
1327 |
||
1328 |
(string = 'nil') ifTrue:[ |
|
3810 | 1329 |
shortText ifTrue:[ |
1330 |
^ '''nil'' - undefined, unknown, void or dont care.' |
|
1331 |
]. |
|
1332 |
^ 'nil is a pseudo variable (i.e. it is built in). |
|
1188 | 1333 |
|
1334 |
Nil is used for unitialized variables (among other uses). |
|
1335 |
Nil is the one and only instance of class UndefinedObject.' |
|
1336 |
]. |
|
1337 |
^ nil |
|
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1338 |
|
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1339 |
"Modified (comment): / 28-02-2012 / 10:46:18 / cg" |
1188 | 1340 |
! |
1341 |
||
4378 | 1342 |
explainSelector:string inClass:aClassOrNil short:shortText |
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1343 |
"return an explanation or nil" |
1188 | 1344 |
|
3810 | 1345 |
|selector listOfImplementingClasses listOfImplementingClassNames listOfSimilarSelectors |
3203 | 1346 |
firstImplementingClassOfSimilar count tmp commonSuperClass s s2 |
4143 | 1347 |
firstImplementingClass |
3798 | 1348 |
firstImplementingClassName secondImplementingClassName thirdImplementingClassName |
1349 |
classProvidingComment |
|
1350 |
cm msg t check| |
|
1188 | 1351 |
|
3810 | 1352 |
selector := string asSymbolIfInterned. |
1353 |
selector isNil ifTrue:[^ nil]. |
|
1188 | 1354 |
|
4143 | 1355 |
"/ look who implements it |
3798 | 1356 |
listOfImplementingClassNames := Set new. |
3174 | 1357 |
listOfImplementingClasses := Set new. |
1358 |
listOfSimilarSelectors := Set new. |
|
2288
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1359 |
|
3203 | 1360 |
check := |
3233 | 1361 |
[:sel :mthd :cls | |
3810 | 1362 |
sel == selector ifTrue:[ |
3798 | 1363 |
listOfImplementingClasses add:cls. |
1364 |
listOfImplementingClassNames add:(cls name). |
|
3233 | 1365 |
firstImplementingClass isNil ifTrue:[ |
3798 | 1366 |
firstImplementingClass := cls. |
1367 |
firstImplementingClassName := cls name. |
|
3233 | 1368 |
] |
1369 |
] ifFalse:[ |
|
3810 | 1370 |
(sel startsWith:selector) ifTrue:[ |
3233 | 1371 |
listOfSimilarSelectors add:sel. |
1372 |
firstImplementingClassOfSimilar isNil ifTrue:[ |
|
1373 |
firstImplementingClassOfSimilar := cls |
|
1374 |
] |
|
1375 |
] |
|
1376 |
] |
|
1377 |
]. |
|
2288
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1378 |
|
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1379 |
Smalltalk allClassesDo:[:c| |
3233 | 1380 |
c methodDictionary keysAndValuesDo:[:sel :mthd | |
1381 |
check value:sel value:mthd value:c |
|
1382 |
]. |
|
1383 |
c class methodDictionary keysAndValuesDo:[:sel :mthd | |
|
1384 |
check value:sel value:mthd value:c class |
|
1385 |
]. |
|
141 | 1386 |
]. |
1387 |
||
4378 | 1388 |
(aClassOrNil notNil and:[aClassOrNil canUnderstand:selector]) ifTrue:[ |
1389 |
s2 := ('Instances of ''' , aClassOrNil name , ''' respond to #') , selector "allBold" , '.'. |
|
3233 | 1390 |
shortText ifFalse:[ |
1391 |
s2 := '\\' , s2 |
|
1392 |
, '\- inherited from ' withCRs |
|
4378 | 1393 |
, (aClassOrNil whichClassIncludesSelector:selector) name "allBold". |
3233 | 1394 |
]. |
4378 | 1395 |
firstImplementingClass := (aClassOrNil whichClassIncludesSelector:selector) |
835 | 1396 |
] ifFalse:[ |
3233 | 1397 |
s2 := ''. |
835 | 1398 |
]. |
1399 |
||
3798 | 1400 |
count := listOfImplementingClassNames size. |
141 | 1401 |
(count ~~ 0) ifTrue:[ |
3233 | 1402 |
" |
1403 |
for up-to 4 implementing classes, |
|
1404 |
list them |
|
1405 |
" |
|
3798 | 1406 |
listOfImplementingClassNames := listOfImplementingClassNames asOrderedCollection sort. |
3233 | 1407 |
shortText ifTrue:[ |
1408 |
tmp := ' is implemented in '. |
|
1409 |
] ifFalse:[ |
|
1410 |
tmp := ' is a selector implemented in '. |
|
1411 |
]. |
|
3881 | 1412 |
"/ s := string allBold. |
3855 | 1413 |
count > 1 ifTrue:[ |
3881 | 1414 |
s := self asLink:selector to:(self actionToOpenMethodFinderFor:selector). |
4143 | 1415 |
] ifFalse:[ |
3885 | 1416 |
s := self asLink:selector to:(self actionToBrowseClass:listOfImplementingClasses first selector:selector). |
3842 | 1417 |
]. |
4143 | 1418 |
|
3810 | 1419 |
shortText ifTrue:[ |
1420 |
|typesDescription| |
|
4143 | 1421 |
|
3810 | 1422 |
msg := s , tmp. |
3842 | 1423 |
typesDescription := self typeDescriptionFor:listOfImplementingClasses andSelector:selector wordBetween:'and'. |
3810 | 1424 |
typesDescription notNil ifTrue:[ |
3842 | 1425 |
msg := msg,typesDescription |
3233 | 1426 |
]. |
1427 |
] ifFalse:[ |
|
3810 | 1428 |
(count == 1) ifTrue:[ |
1429 |
t := firstImplementingClassName. |
|
1430 |
firstImplementingClass isMeta ifTrue:[ |
|
1431 |
t := 'the ' , t |
|
1432 |
]. |
|
1433 |
msg := s , tmp , t , '.'. |
|
3233 | 1434 |
shortText ifFalse:[ |
1435 |
msg := msg , s2. |
|
3810 | 1436 |
] |
3233 | 1437 |
] ifFalse:[ |
3810 | 1438 |
firstImplementingClassName := listOfImplementingClassNames at:1. |
1439 |
secondImplementingClassName := listOfImplementingClassNames at:2. |
|
1440 |
(count == 2) ifTrue:[ |
|
1441 |
msg := s,tmp,firstImplementingClassName,' and ',secondImplementingClassName,'.'. |
|
3233 | 1442 |
shortText ifFalse:[ |
1443 |
msg := msg , s2. |
|
1444 |
]. |
|
1445 |
] ifFalse:[ |
|
3810 | 1446 |
thirdImplementingClassName := listOfImplementingClassNames at:3. |
1447 |
(count == 3) ifTrue:[ |
|
1448 |
msg := s,tmp,firstImplementingClassName,',',secondImplementingClassName,' and ',thirdImplementingClassName,'.'. |
|
1449 |
shortText ifFalse:[ |
|
1450 |
msg := msg , s2. |
|
1451 |
]. |
|
1452 |
] ifFalse:[ |
|
1453 |
false "shortText" ifTrue:[ |
|
1454 |
msg := s , tmp , count printString , ' classes'. |
|
1455 |
commonSuperClass := Class commonSuperclassOf:listOfImplementingClassNames. |
|
1456 |
commonSuperClass notNil ifTrue:[ |
|
1457 |
(commonSuperClass == Object |
|
1458 |
and:[commonSuperClass includesSelector:selector]) ifTrue:[ |
|
1459 |
msg := msg , ' (including ' , 'Object' "allBold", ')' |
|
1460 |
] ifFalse:[ |
|
1461 |
(commonSuperClass ~= Object) ifTrue:[ |
|
1462 |
msg := msg , ' (under ' , commonSuperClass name, ')' |
|
1463 |
] |
|
1464 |
]. |
|
3492 | 1465 |
]. |
3810 | 1466 |
msg := msg , '.'. |
1467 |
^ msg |
|
3233 | 1468 |
]. |
1183 | 1469 |
|
3810 | 1470 |
" |
1471 |
if there are more, look for a common |
|
1472 |
superclass and show it ... |
|
1473 |
" |
|
1474 |
commonSuperClass := (Behavior commonSuperclassOf:listOfImplementingClasses) ? Object. |
|
1475 |
(commonSuperClass ~~ Object |
|
1476 |
and:[commonSuperClass ~~ Behavior |
|
1477 |
and:[commonSuperClass ~~ Class |
|
1478 |
and:[commonSuperClass ~~ ClassDescription]]]) ifTrue:[ |
|
1479 |
(listOfImplementingClasses includes:commonSuperClass) ifTrue:[ |
|
1480 |
msg := s . tmp , count printString , commonSuperClass name |
|
1481 |
, ' and redefined in ' , (count - 1) printString |
|
1482 |
, ' subclasses' |
|
1483 |
, s2. |
|
1484 |
firstImplementingClass := commonSuperClass |
|
1485 |
] ifFalse:[ |
|
1486 |
msg := s , tmp, count printString , ' subclasses of ' , commonSuperClass name , s2 |
|
1487 |
] |
|
3233 | 1488 |
] ifFalse:[ |
3810 | 1489 |
(commonSuperClass == Object |
1490 |
and:[commonSuperClass includesSelector:selector]) ifTrue:[ |
|
1491 |
shortText ifTrue:[ |
|
1492 |
msg := s , tmp , count printString , ' classes (incl. Object)'. |
|
1493 |
] ifFalse:[ |
|
1494 |
msg := s , tmp , count printString , ' classes. |
|
4143 | 1495 |
|
3203 | 1496 |
All objects seem to respond to that message, |
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
1497 |
since there is an implementation in Object.' , s2. |
3810 | 1498 |
]. |
1499 |
firstImplementingClass := Object |
|
1500 |
] ifFalse:[ |
|
1501 |
((commonSuperClass == Behavior |
|
1502 |
or:[commonSuperClass == Class |
|
1503 |
or:[commonSuperClass == ClassDescription]]) |
|
1504 |
and:[commonSuperClass includesSelector:selector]) ifTrue:[ |
|
1505 |
shortText ifTrue:[ |
|
1506 |
msg := s , tmp , count printString , ' classes (incl. all classes)'. |
|
1507 |
] ifFalse:[ |
|
1508 |
msg := s , tmp , count printString , ' classes. |
|
913 | 1509 |
|
3203 | 1510 |
All classes seem to respond to that message, |
913 | 1511 |
since there is an implementation in ' , commonSuperClass name , '.' , s2. |
3810 | 1512 |
]. |
1513 |
firstImplementingClass := commonSuperClass |
|
1514 |
] ifFalse:[ |
|
1515 |
" |
|
1516 |
otherwise just give the number. |
|
1517 |
" |
|
1518 |
msg := s , tmp , count printString , ' classes.' , s2 |
|
1519 |
] |
|
3233 | 1520 |
] |
1521 |
] |
|
1522 |
] |
|
3810 | 1523 |
]. |
3233 | 1524 |
]. |
1525 |
]. |
|
3798 | 1526 |
"/ look for a comment... |
1527 |
count == 1 ifTrue:[ |
|
1528 |
classProvidingComment := firstImplementingClass. |
|
3233 | 1529 |
] ifFalse:[ |
3798 | 1530 |
commonSuperClass isNil ifTrue:[ |
1531 |
commonSuperClass := Behavior commonSuperclassOf:listOfImplementingClasses. |
|
1532 |
] . |
|
4100 | 1533 |
|
4143 | 1534 |
((listOfImplementingClasses includes:commonSuperClass) |
4100 | 1535 |
and:[ (commonSuperClass implements:selector) ] |
1536 |
) ifTrue:[ |
|
1537 |
classProvidingComment := commonSuperClass |
|
1538 |
] ifFalse:[ |
|
4143 | 1539 |
"/ avoid some obvious misleading paths... |
1540 |
classProvidingComment := { Number . Collection . Stream . View } |
|
4100 | 1541 |
detect:[:cls | (listOfImplementingClasses includes:cls) |
1542 |
or:[cls canUnderstand:selector] ] |
|
1543 |
ifNone:nil. |
|
1544 |
classProvidingComment notNil ifTrue:[ |
|
1545 |
classProvidingComment := classProvidingComment whichClassImplements:selector. |
|
4143 | 1546 |
] ifFalse:[ |
3810 | 1547 |
classProvidingComment := firstImplementingClass. |
4143 | 1548 |
[ |
4100 | 1549 |
classProvidingComment superclass notNil |
1550 |
and:[ classProvidingComment superclass implements:selector ] |
|
1551 |
] whileTrue:[ |
|
1552 |
classProvidingComment := classProvidingComment superclass |
|
1553 |
]. |
|
3810 | 1554 |
]. |
3798 | 1555 |
]. |
1556 |
]. |
|
1557 |
classProvidingComment notNil ifTrue:[ |
|
3885 | 1558 |
cm := self fetchDescriptionOfMethod:"fetchCommentOfMethod:"(classProvidingComment compiledMethodAt:selector). |
3798 | 1559 |
]. |
1560 |
cm isNil ifTrue:[ |
|
1561 |
"/ should: find the class with most subclasses from the list |
|
1562 |
(listOfImplementingClasses includes:Collection) ifTrue:[ |
|
1563 |
classProvidingComment := Collection |
|
1564 |
] ifFalse:[ |
|
1565 |
(listOfImplementingClasses includes:Stream) ifTrue:[ |
|
1566 |
classProvidingComment := Stream |
|
1567 |
] ifFalse:[ |
|
4143 | 1568 |
classProvidingComment := listOfImplementingClasses |
1569 |
detect:[:cls | |
|
3883 | 1570 |
|mthd| |
1571 |
(mthd := cls compiledMethodAt:selector) notNil |
|
3885 | 1572 |
and:[ (self fetchCommentOfMethod:mthd) notNil]] |
3883 | 1573 |
ifNone:nil. |
3798 | 1574 |
] |
1575 |
]. |
|
3883 | 1576 |
cm isNil ifTrue:[ |
1577 |
classProvidingComment notNil ifTrue:[ |
|
3885 | 1578 |
cm := self fetchDescriptionOfMethod:(classProvidingComment compiledMethodAt:selector). |
3883 | 1579 |
] |
4143 | 1580 |
]. |
3798 | 1581 |
]. |
1582 |
cm notNil ifTrue:[ |
|
4273 | 1583 |
cm := ('%1 says:\' withCRs bindWith:(self asClassLink:classProvidingComment name)),cm. |
4143 | 1584 |
|
3883 | 1585 |
"/ msg := msg,(msg last isSeparator ifTrue:[''] ifFalse:[' ']),cm |
1586 |
msg := msg,(Character cr),cm |
|
3233 | 1587 |
]. |
1588 |
^ msg |
|
141 | 1589 |
]. |
1590 |
||
3881 | 1591 |
"/ none implements it (typo?); |
3174 | 1592 |
count := listOfSimilarSelectors size. |
2288
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1593 |
(count ~~ 0) ifTrue:[ |
3233 | 1594 |
listOfSimilarSelectors := listOfSimilarSelectors asOrderedCollection sort. |
2288
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1595 |
|
3233 | 1596 |
(count == 1) ifTrue:[ |
3881 | 1597 |
|sel selLink clsLink implementors| |
1598 |
||
1599 |
sel := listOfSimilarSelectors first. |
|
1600 |
selLink := self asLink:sel to:(self actionToOpenMethodFinderFor:sel). |
|
1601 |
"/ clsLink := self asLink:firstImplementingClassOfSimilar name to:(self actionToBrowseClass:firstImplementingClassOfSimilar selector:sel). |
|
1602 |
implementors := Smalltalk allImplementorsOf:sel. |
|
1603 |
clsLink := self typeDescriptionFor:implementors andSelector:sel. |
|
1604 |
msg := selLink , ' is implemented in ' , clsLink , '.'. |
|
3233 | 1605 |
shortText ifFalse:[ |
1606 |
msg := msg , s2. |
|
1607 |
] |
|
1608 |
] ifFalse:[ |
|
3881 | 1609 |
|sel1 sel2| |
1610 |
sel1 := listOfSimilarSelectors first. |
|
1611 |
sel2 := listOfSimilarSelectors second. |
|
4143 | 1612 |
msg := 'similar selectors: %1, %2' |
1613 |
bindWith:(self asLink:sel1 to:(self actionToOpenMethodFinderFor:sel1)) |
|
3881 | 1614 |
with:(self asLink:sel2 to:(self actionToOpenMethodFinderFor:sel1)). |
3233 | 1615 |
count > 2 ifTrue:[ |
1616 |
msg := msg,'...'. |
|
1617 |
]. |
|
1618 |
]. |
|
1619 |
^ msg |
|
2288
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1620 |
]. |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1621 |
|
141 | 1622 |
^ nil |
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
1623 |
|
1909 | 1624 |
"Modified: / 17-06-1996 / 17:09:30 / stefan" |
1625 |
"Created: / 23-03-1999 / 13:29:33 / cg" |
|
3804 | 1626 |
"Modified: / 01-05-2016 / 15:42:24 / cg" |
4143 | 1627 |
"Modified: / 22-05-2017 / 11:35:31 / mawalch" |
4378 | 1628 |
"Modified: / 04-03-2019 / 10:16:07 / Claus Gittinger" |
141 | 1629 |
! |
1630 |
||
4378 | 1631 |
explainSelfIn:aClassOrNil short:shortText |
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1632 |
"return an explanation" |
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1633 |
|
3883 | 1634 |
|subClasses subNames selfString className nSubClasses |
1635 |
classLink classLink2 subclassesLink| |
|
1198 | 1636 |
|
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
1637 |
selfString := '''' , 'self' "allBold" , ''''. |
6 | 1638 |
|
4378 | 1639 |
aClassOrNil isNil ifTrue:[ |
1640 |
^ selfString , 'refers to the object which received the message.' |
|
1641 |
]. |
|
1642 |
||
1643 |
subClasses := aClassOrNil allSubclasses. |
|
3883 | 1644 |
nSubClasses := subClasses size. |
1244 | 1645 |
|
4378 | 1646 |
aClassOrNil isMeta ifTrue:[ |
1647 |
className := aClassOrNil theNonMetaclass name. |
|
3883 | 1648 |
subNames := subClasses collect:[:c | c theNonMetaclass name]. |
1649 |
shortText ifTrue:[ |
|
1650 |
classLink := (self asClassLink:className). |
|
1651 |
nSubClasses == 0 ifTrue:[ |
|
1652 |
^ selfString , (' - the %1 class.' bindWith:classLink) |
|
1653 |
]. |
|
1654 |
nSubClasses == 1 ifTrue:[ |
|
1655 |
classLink2 := self asClassLink:subNames first. |
|
1656 |
^ selfString , (' - the %1- or %2 class.' bindWith:classLink with:classLink2) |
|
1657 |
]. |
|
1658 |
subclassesLink := self |
|
1659 |
asLink:('%1 subclasses' bindWith:nSubClasses) |
|
1660 |
info:('Click to browse subclasses') |
|
1661 |
to:(self actionToBrowseClasses:subClasses). |
|
1662 |
||
1663 |
^ selfString , (' - the %1 class or one of its %2.' bindWith:classLink with:subclassesLink) |
|
1664 |
]. |
|
1665 |
||
3810 | 1666 |
nSubClasses == 0 ifTrue:[ |
1667 |
^ selfString , 'refers to the object which received the message. |
|
1244 | 1668 |
|
1669 |
In this case, it will be the ' , className , '-class itself.' |
|
3810 | 1670 |
]. |
1244 | 1671 |
|
3810 | 1672 |
nSubClasses <= 5 ifTrue:[ |
1673 |
^ selfString , ' refers to the object which received the message. |
|
1244 | 1674 |
|
1675 |
In this case, it will be the ' , className , '-class |
|
1676 |
or one of its subclasses: |
|
1677 |
||
1678 |
' , subNames asStringCollection asString |
|
3810 | 1679 |
]. |
1244 | 1680 |
|
3810 | 1681 |
^ selfString , ' refers to the object which received the message. |
1244 | 1682 |
|
1683 |
In this case, it will be the ' , className , '-class |
|
1684 |
or one of its ' , nSubClasses printString , ' subclasses.' |
|
1685 |
]. |
|
1686 |
||
4378 | 1687 |
subClasses := aClassOrNil allSubclasses. |
3883 | 1688 |
subNames := subClasses collect:[:c | c theNonMetaclass name]. |
4378 | 1689 |
className := aClassOrNil name. |
3883 | 1690 |
shortText ifTrue:[ |
1691 |
classLink := self asClassLink:className. |
|
1692 |
nSubClasses == 0 ifTrue:[ |
|
1693 |
^ selfString , (' - an instance of %1.' bindWith:classLink) |
|
1694 |
]. |
|
1695 |
nSubClasses == 1 ifTrue:[ |
|
1696 |
classLink2 := self asClassLink:subNames first. |
|
1697 |
^ selfString , (' - an instance of %1 or %2.' bindWith:classLink with:classLink2) |
|
1698 |
]. |
|
1699 |
subclassesLink := self |
|
1700 |
asLink:('%1 subclasses' bindWith:nSubClasses) |
|
1701 |
info:('Click to browse subclasses') |
|
1702 |
to:(self actionToBrowseClasses:subClasses). |
|
1703 |
^ selfString , (' - an instance of %1 or one of its %2.' bindWith:classLink with:subclassesLink) |
|
1704 |
]. |
|
1705 |
||
1244 | 1706 |
nSubClasses == 0 ifTrue:[ |
3810 | 1707 |
^ selfString , 'refers to the object which received the message. |
6 | 1708 |
|
1244 | 1709 |
In this case, it will be an instance of ' , className , '.' |
6 | 1710 |
]. |
1711 |
||
1244 | 1712 |
nSubClasses <= 5 ifTrue:[ |
3810 | 1713 |
^ selfString , ' refers to the object which received the message. |
6 | 1714 |
|
1244 | 1715 |
In this case, it will be an instance of ' , className , ' |
6 | 1716 |
or one of its subclasses: |
1717 |
||
1256 | 1718 |
' , subNames asStringCollection asString |
6 | 1719 |
]. |
1720 |
||
1198 | 1721 |
^ selfString , ' refers to the object which received the message. |
6 | 1722 |
|
1244 | 1723 |
In this case, it will be an instance of ' , className , ' |
1724 |
or one of its ' , nSubClasses printString , ' subclasses.' |
|
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
1725 |
|
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
1726 |
"Modified: / 09-10-2006 / 12:11:44 / cg" |
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1727 |
"Modified (comment): / 28-02-2012 / 10:47:06 / cg" |
6 | 1728 |
! |
1729 |
||
4378 | 1730 |
explainSuperIn:aClassOrNil short:shortText |
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1731 |
"return an explanation" |
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1732 |
|
1352 | 1733 |
|superName| |
1244 | 1734 |
|
4378 | 1735 |
aClassOrNil isNil ifTrue:[ |
1736 |
^ '"super" - message lookup starts in superclass (call redefined method).' |
|
1737 |
]. |
|
1738 |
||
1739 |
superName := aClassOrNil superclass name. |
|
1188 | 1740 |
|
1741 |
shortText ifTrue:[ |
|
3842 | 1742 |
^ '"super" - message lookup starts in superclass "%1" (call redefined method).' bindWith:(self asClassLink:superName) |
1188 | 1743 |
]. |
1744 |
||
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1745 |
^ 'like "self", "','super'allBold,'" refers to the object which received the message. |
6 | 1746 |
|
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1747 |
However, when sending a message to "super", the search for methods |
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1748 |
implementing this message will start in the superclass (' , superName , '), |
4378 | 1749 |
instead of the receiver''s class (' , aClassOrNil name , ' or subclass). |
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1750 |
Thus, using "super", a redefined method can call the original (redefined) method of its superclass.' |
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1751 |
|
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1752 |
"Modified (comment): / 28-02-2012 / 10:47:03 / cg" |
4378 | 1753 |
"Modified: / 04-03-2019 / 10:17:44 / Claus Gittinger" |
6 | 1754 |
! |
2 | 1755 |
|
49 | 1756 |
explainSyntax:string |
1757 |
"try syntax ...; return explanation or nil" |
|
1758 |
||
1183 | 1759 |
^ self explainSyntax:string short:false |
1760 |
! |
|
1761 |
||
1762 |
explainSyntax:string short:shortText |
|
3842 | 1763 |
"try syntax ...; return explanation or nil. |
1764 |
This is meant for beginners..." |
|
1183 | 1765 |
|
3883 | 1766 |
|fullMsg stringWithoutSeparators| |
3881 | 1767 |
|
49 | 1768 |
((string = ':=') or:[string = '_']) ifTrue:[ |
3881 | 1769 |
fullMsg := '<variable> := <expression> |
49 | 1770 |
|
3233 | 1771 |
":=" and "_" (which is left-arrow in some fonts) mean assignment. |
3464 | 1772 |
The variable is bound to (i.e. points to) the value of <expression>. |
3881 | 1773 |
The "_" form is historic and should not be used with new code.'. |
1774 |
||
1775 |
shortText ifTrue:[ |
|
1776 |
string = '_' ifTrue:[ |
|
1777 |
^ (self |
|
1778 |
asLink:'"_"' |
|
1779 |
info:fullMsg |
|
1780 |
to:nil),' - old style for assignment. Consider changing to ":=".' |
|
1781 |
]. |
|
1782 |
^ (self |
|
1783 |
asLink:'":="' |
|
1784 |
info:fullMsg |
|
1785 |
to:nil),' - assign to variable on the left (syntax).' |
|
1786 |
]. |
|
1787 |
^ fullMsg |
|
49 | 1788 |
]. |
1789 |
||
1790 |
(string = '^') ifTrue:[ |
|
3233 | 1791 |
shortText ifTrue:[ |
3607 | 1792 |
^ '"^" - return value from method (syntax)'. |
3233 | 1793 |
]. |
1794 |
^ '^ <expression> |
|
49 | 1795 |
|
3319 | 1796 |
A return statement evaluates <expression> and returns its value from the method. |
1797 |
A return inside a block exits the method where the block is defined (not only the block).' |
|
49 | 1798 |
]. |
1799 |
||
1800 |
(string = ';') ifTrue:[ |
|
3233 | 1801 |
shortText ifTrue:[ |
3607 | 1802 |
^ '";" - a cascade expression (syntax)'. |
3233 | 1803 |
]. |
1804 |
^ '<expression> ; selector1 ; .... ; selectorN |
|
49 | 1805 |
|
3203 | 1806 |
a cascade expression; evaluate expression, and send messages |
1807 |
<selector1> ... <selectorN> to the first expression''s receiver. |
|
49 | 1808 |
Returns the value of the last send. The cascade sends may also have arguments.' |
1809 |
]. |
|
1810 |
||
1811 |
(string = '|') ifTrue:[ |
|
3233 | 1812 |
shortText ifTrue:[ |
3607 | 1813 |
^ '"|" - local variables (syntax)'. |
3233 | 1814 |
]. |
1815 |
^ '| locals | or: [:arg | statements] |
|
49 | 1816 |
|
3233 | 1817 |
"|" is used to mark a local variable declaration or separates arguments |
49 | 1818 |
from the statements in a block. Notice, that in a block-argument declaration |
3319 | 1819 |
these arg nams must be prefixed by a colon character. |
3233 | 1820 |
"|" is also a selector understood by Booleans.' |
49 | 1821 |
]. |
1822 |
||
3319 | 1823 |
(string startsWith:'$' ) ifTrue:[ |
1824 |
shortText ifTrue:[ |
|
3842 | 1825 |
^ '"$x" - ',(self asClassLink:'Character'),' literal (syntax)'. |
3319 | 1826 |
]. |
1827 |
^ 'is a Character literal constant. |
|
1828 |
||
1829 |
Character objects represent indivdual text cheracters in Unicode encoding. |
|
1830 |
For example, $a is the character "a" with an encoding of 97 "hex: 16r61". |
|
1831 |
Smalltalk/X supports unicode and uses this encoding internally for all characters |
|
1832 |
and strings. Notice, that not all Smalltalk implementations allow non-ascii (i.e. codes > 255).' |
|
1833 |
]. |
|
1834 |
||
2287
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1835 |
(string startsWith:'#' ) ifTrue:[ |
3233 | 1836 |
(string startsWith:'#(' ) ifTrue:[ |
1837 |
shortText ifTrue:[ |
|
3842 | 1838 |
^ '"#(..)" - ',(self asClassLink:'Array'),' literal (syntax)'. |
3233 | 1839 |
]. |
3607 | 1840 |
^ 'is a constant Array (literal). |
2287
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1841 |
|
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1842 |
The array-object is created at compilation time and a reference to this is |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1843 |
used at execution time (thus, the same object is referred to every time). |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1844 |
The elements of a constant Array must be numbers, strings, symbols, nil, true or false, |
3194 | 1845 |
other array constants or byte-arrays. |
2287
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1846 |
(notice, that not all Smalltalk implementations allow true, false and nil as |
3194 | 1847 |
element in an Array-constant).' |
3233 | 1848 |
]. |
2287
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1849 |
|
3233 | 1850 |
(string startsWith:'#[') ifTrue:[ |
1851 |
shortText ifTrue:[ |
|
3842 | 1852 |
^ '"#[..]" - ',(self asClassLink:'ByteArray'),' literal (syntax)'. |
3233 | 1853 |
]. |
3607 | 1854 |
^ 'is a constant ByteArray (literal). |
2287
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1855 |
|
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1856 |
The elements of a constant ByteArray must be Integer constants in the range |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1857 |
0 .. 255. |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1858 |
(notice, that not all Smalltalk implementations support constant ByteArrays).' |
3233 | 1859 |
]. |
2287
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1860 |
|
3233 | 1861 |
(string startsWith:'#''') ifTrue:[ |
1862 |
shortText ifTrue:[ |
|
3842 | 1863 |
^ '"#''..''" - ',(self asClassLink:'Symbol'),' literal (syntax)'. |
3233 | 1864 |
]. |
1865 |
^ 'is a constant symbol containing non-alphanumeric characters. |
|
2287
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1866 |
|
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1867 |
Symbols are unique strings, meaning that there exists |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1868 |
exactly one instance of a given symbol. Therefore symbols can |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1869 |
be compared using == (identity compare) in addition to = (contents compare). |
3194 | 1870 |
Beside this, Symbols behave mostly like Strings but are immutable.' |
3233 | 1871 |
]. |
2287
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1872 |
|
3233 | 1873 |
shortText ifTrue:[ |
3842 | 1874 |
^ '"#.." - ',(self asClassLink:'Symbol'),' literal (syntax)'. |
3233 | 1875 |
]. |
3319 | 1876 |
^ 'is a constant symbol. |
2287
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1877 |
|
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1878 |
Symbols are unique strings, meaning that there exists |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1879 |
exactly one instance of a given symbol. Therefore symbols can |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1880 |
be compared using == (identity compare) in addition to = (contents compare). |
3194 | 1881 |
Beside this, Symbols behave mostly like Strings but are immutable.' |
2287
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1882 |
]. |
49 | 1883 |
((string startsWith:'(') or:[string endsWith:')']) ifTrue:[ |
3233 | 1884 |
shortText ifTrue:[ |
1885 |
^ ''. |
|
1886 |
]. |
|
1887 |
^ '( <expression> ) |
|
49 | 1888 |
|
3194 | 1889 |
expression grouping. Without them, expressions are evaluated left to right, |
1890 |
with unary messages preceeding binary messages, preceeding keyword mesages.' |
|
49 | 1891 |
]. |
1892 |
||
1893 |
((string startsWith:'[') or:[string endsWith:']']) ifTrue:[ |
|
3233 | 1894 |
shortText ifTrue:[ |
3842 | 1895 |
^ '"[..]" - a ',(self asClassLink:'Block'),' (aka lambda/closure for experts)'. |
3233 | 1896 |
]. |
1897 |
^ '[:arg1 .. :argN | statements] |
|
49 | 1898 |
|
3203 | 1899 |
defines a block. |
3194 | 1900 |
Blocks represent pieces of executable code. The definition of a block does |
4390 | 1901 |
not evaluate it, instead a reference to the block''s computation is created. |
3194 | 1902 |
The block can be evaluated later, by sending it a value/value: message |
1903 |
(it can be even evaluated multiple times). |
|
1904 |
Blocks are often passed as arguments to Booleans (i.e. "bool ifTrue:[...]"), |
|
1905 |
other blocks (i.e. "[...] whileTrue: [...]"]) or collections (i.e. "coll do:[...]"). |
|
1906 |
Blocks are also often used as callbacks from UI components or as exception handlers.' |
|
49 | 1907 |
]. |
1908 |
||
2286
cabf7db33a38
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2226
diff
changeset
|
1909 |
((string startsWith:'{') or:[string endsWith:'}']) ifTrue:[ |
3233 | 1910 |
shortText ifTrue:[ |
3842 | 1911 |
^ '"{..}" ',(self asClassLink:'Array'),' instantiation (syntax)'. |
3233 | 1912 |
]. |
1913 |
^ '{ <expr1>. .. <exprN> } |
|
2286
cabf7db33a38
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2226
diff
changeset
|
1914 |
|
3319 | 1915 |
This is syntactic sugar for "Array with:<expr1> .. with:<exprN>". |
1916 |
||
2286
cabf7db33a38
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2226
diff
changeset
|
1917 |
A new array is created with N elements initialized from the N expressions. |
cabf7db33a38
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2226
diff
changeset
|
1918 |
The expressions are separated by a period statement separator. |
cabf7db33a38
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2226
diff
changeset
|
1919 |
The expressions are evaluated at execution time, and a new array is always created |
cabf7db33a38
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2226
diff
changeset
|
1920 |
when executed (as opposed to an array literal, which is computed only once at |
3233 | 1921 |
compilation time) and which is shared. |
3319 | 1922 |
Notice that this construct is not supported by all Smalltalk dialects, so its use |
1923 |
makes your program somewhat dialect specific.' |
|
2286
cabf7db33a38
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2226
diff
changeset
|
1924 |
]. |
cabf7db33a38
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2226
diff
changeset
|
1925 |
|
49 | 1926 |
(string = ':') ifTrue:[ |
3233 | 1927 |
shortText ifTrue:[ |
1928 |
^ ''. |
|
1929 |
]. |
|
1930 |
^ 'colons have different meaning depending on context: |
|
49 | 1931 |
|
1932 |
1) they separate keyword-parts in symbols and keyword-messages as in: |
|
1933 |
||
1934 |
#at:put: a constant keyword symbol |
|
1935 |
||
1936 |
rec at:index put:value sends the #at:put: message to rec, |
|
3233 | 1937 |
passing index and value as arguments. |
49 | 1938 |
|
1939 |
2) within block-argument declarations as in: |
|
1940 |
||
1941 |
[:arg1 :arg2 | statements] |
|
834 | 1942 |
|
1943 |
3) within an identifier, they separate the nameSpace part from |
|
1944 |
the name part; as in: |
|
1945 |
||
1946 |
Smalltalk::Array - the Array class in the Smalltalk nameSpace. |
|
1947 |
Foo::Array - the Array class in the Foo nameSpace. |
|
49 | 1948 |
' |
1949 |
]. |
|
1950 |
||
1951 |
(string = '.') ifTrue:[ |
|
3233 | 1952 |
^ 'statement. "<- period here" |
49 | 1953 |
statement |
1954 |
||
1955 |
within a method or block, individual statements are separated by periods. |
|
1956 |
' |
|
1957 |
]. |
|
1958 |
||
3883 | 1959 |
stringWithoutSeparators := string withoutSeparators. |
1960 |
||
1961 |
(stringWithoutSeparators startsWith:'"') ifTrue:[ |
|
1962 |
(stringWithoutSeparators startsWith:'"/') ifTrue:[ |
|
3464 | 1963 |
shortText ifTrue:[ |
3607 | 1964 |
^ 'an end-of-line comment (syntax)'. |
3464 | 1965 |
]. |
1966 |
^ '"/ comment |
|
3193 | 1967 |
EOL (end-of-line) comment |
1968 |
||
1969 |
anything up to the end of line is a comment and ignored (but not inside a string). |
|
3233 | 1970 |
Notice that EOL-comments are only supported by Smalltalk/X (i.e. non-portable). |
3193 | 1971 |
' |
3464 | 1972 |
]. |
3883 | 1973 |
(stringWithoutSeparators startsWith:'"<<') ifTrue:[ |
3464 | 1974 |
shortText ifTrue:[ |
4175 | 1975 |
^ 'a token delimited comment; up to line starting with the token after ''<<''.'. |
3464 | 1976 |
]. |
1977 |
^ '"<<TOKEN |
|
1978 |
... |
|
1979 |
TOKEN |
|
1980 |
||
1981 |
Token delimited comment |
|
1982 |
||
4175 | 1983 |
anything up to a line which starts with the token is a comment and ignored (but not inside a string). |
3464 | 1984 |
Notice that Token-comments are only supported by Smalltalk/X (i.e. non-portable). |
1985 |
' |
|
1986 |
]. |
|
1987 |
||
3233 | 1988 |
shortText ifTrue:[ |
3607 | 1989 |
^ 'a comment (syntax)'. |
3233 | 1990 |
]. |
1991 |
^ '" comment ... " |
|
3193 | 1992 |
comment |
1993 |
||
1994 |
anything between double quotes is a comment and ignored (but not inside a string). |
|
1995 |
' |
|
1996 |
]. |
|
1997 |
||
49 | 1998 |
"/ is it a symbol without hash-character ? |
1999 |
"/ |
|
796 | 2000 |
"/ string knownAsSymbol ifTrue:[ |
2001 |
"/ ^ 'is nothing, but #' , string , ' is known as a symbol. |
|
2002 |
"/ |
|
2003 |
"/Symbols are unique strings, meaning that there exists |
|
2004 |
"/exactly one instance of a given symbol. Therefore symbols can |
|
2005 |
"/be compared using == (identity compare) in addition to = (contents compare). |
|
2006 |
"/Beside this, Symbols behave mostly like Strings.' |
|
2007 |
"/ ]. |
|
49 | 2008 |
|
3883 | 2009 |
((stringWithoutSeparators startsWith:'<') and:[stringWithoutSeparators endsWith:'>']) ifTrue:[ |
2010 |
shortText ifTrue:[ |
|
2011 |
(stringWithoutSeparators includesString:'resource:') ifTrue:[ |
|
2012 |
^ 'a ',(self |
|
2013 |
asLink:'resource annotation' |
|
2014 |
info:fullMsg |
|
2015 |
to:(self actionToBrowseClass:Annotation)),' (syntax)' |
|
2016 |
]. |
|
2017 |
^ 'an ',(self |
|
2018 |
asLink:'annotation / pragma' |
|
2019 |
info:fullMsg |
|
2020 |
to:(self actionToBrowseClass:Annotation)),' (syntax)' |
|
2021 |
]. |
|
2022 |
]. |
|
2023 |
||
49 | 2024 |
^ nil |
796 | 2025 |
|
4175 | 2026 |
"Modified: / 28-07-2017 / 10:32:11 / cg" |
4390 | 2027 |
"Modified: / 13-03-2019 / 10:25:48 / Claus Gittinger" |
2214 | 2028 |
! |
2029 |
||
3810 | 2030 |
typeDescriptionFor:setOfTypes andSelector:selectorOrNil |
2031 |
"up to 3 types are shown by name; more are simply counted" |
|
2032 |
||
3842 | 2033 |
^ self typeDescriptionFor:setOfTypes andSelector:selectorOrNil wordBetween:'or' |
2034 |
! |
|
2035 |
||
2036 |
typeDescriptionFor:setOfTypes andSelector:selectorOrNil wordBetween:wordbetween |
|
2037 |
"up to 3 types are shown by name; more are simply counted" |
|
2038 |
||
3810 | 2039 |
|types numTypes |
2040 |
type1 type2 type3 |
|
4206 | 2041 |
nm1 nm2 nm3 link stringForType| |
2042 |
||
2043 |
stringForType := |
|
2044 |
[:class | |
|
2045 |
class == UndefinedObject ifTrue:['nil'] |
|
2046 |
ifFalse:[ class == True ifTrue:['true'] |
|
2047 |
ifFalse:[ class == False ifTrue:['false'] |
|
2048 |
ifFalse:[ class == VoidObject ifTrue:['Void'] |
|
2049 |
ifFalse:[ class name ]]]] |
|
2050 |
]. |
|
2051 |
||
3810 | 2052 |
"/ reduce... |
2053 |
self compressSetOfTypes:setOfTypes. |
|
2054 |
setOfTypes isEmpty ifTrue:[^ nil]. |
|
2055 |
||
2056 |
types := setOfTypes asOrderedCollection. |
|
2057 |
types sortBySelector:#name. |
|
2058 |
||
2059 |
"/ now make this a nice string |
|
2060 |
numTypes := types size. |
|
2061 |
type1 := types first. |
|
4206 | 2062 |
|
2063 |
nm1 := self asLink:(stringForType value:type1) to:(self actionToBrowseClass:type1 selector:selectorOrNil). |
|
3810 | 2064 |
numTypes == 1 ifTrue:[ |
2065 |
^ nm1 |
|
2066 |
]. |
|
3842 | 2067 |
|
3810 | 2068 |
type2 := types second. |
4206 | 2069 |
nm2 := self asLink:(stringForType value:type2) to:(self actionToBrowseClass:type2 selector:selectorOrNil). |
3810 | 2070 |
numTypes == 2 ifTrue:[ |
3842 | 2071 |
^ nm1,' ',wordbetween,' ',nm2 |
3810 | 2072 |
]. |
2073 |
type3 := types third. |
|
4206 | 2074 |
nm3 := self asLink:(stringForType value:type3) to:(self actionToBrowseClass:type3 selector:selectorOrNil). |
3810 | 2075 |
numTypes == 3 ifTrue:[ |
3842 | 2076 |
^ nm1,', ',nm2,' ',wordbetween,' ',nm3 |
3810 | 2077 |
]. |
3855 | 2078 |
link := self actionToBrowseClasses:types. |
2079 |
"/ selectorOrNil notNil ifTrue:[ |
|
2080 |
"/ link := self actionToOpenMethodFinderFor:selectorOrNil. |
|
2081 |
"/ ]. |
|
3859 | 2082 |
^ self asLink:('%1 classes' bindWith:numTypes) to:link. |
4206 | 2083 |
|
2084 |
"Modified (format): / 11-11-2017 / 12:30:09 / cg" |
|
3810 | 2085 |
! |
2086 |
||
2214 | 2087 |
valueStringFor:aValue |
2088 |
|valString| |
|
2089 |
||
4287 | 2090 |
aValue isProtoObject ifTrue:[ |
2091 |
^ aValue printString |
|
2092 |
]. |
|
2093 |
||
2214 | 2094 |
"/ only show the value, if it is really short... |
3203 | 2095 |
(aValue isBoolean |
3708 | 2096 |
or:[aValue isNil |
2097 |
or:[aValue isString |
|
2098 |
or:[aValue isNumber |
|
2099 |
or:[aValue isPoint |
|
2100 |
or:[aValue isCharacter |
|
2101 |
]]]]]) ifTrue:[ |
|
2102 |
^ aValue storeString. |
|
2226 | 2103 |
]. |
2427 | 2104 |
|
2226 | 2105 |
(aValue isColor) ifTrue:[ |
3708 | 2106 |
^ 'Color: ',(' ' emphasizeAllWith:(#backgroundColor->aValue)). |
2226 | 2107 |
]. |
2108 |
||
3203 | 2109 |
((aValue isKindOf:GUID) |
2110 |
or:[aValue isUUID]) ifTrue:[ |
|
3708 | 2111 |
valString := aValue printString. |
2427 | 2112 |
]. |
2113 |
||
3203 | 2114 |
(valString isEmptyOrNil |
2899
8b8701a65441
Avoid #isKindOf: where possible
Stefan Vogel <sv@exept.de>
parents:
2828
diff
changeset
|
2115 |
or:[ valString size > 50 |
8b8701a65441
Avoid #isKindOf: where possible
Stefan Vogel <sv@exept.de>
parents:
2828
diff
changeset
|
2116 |
or:[ valString includes:Character cr ]]) ifTrue:[ |
3708 | 2117 |
valString := aValue classNameWithArticle. |
2214 | 2118 |
]. |
2119 |
||
2120 |
^ valString |
|
2427 | 2121 |
|
2122 |
"Modified: / 14-10-2010 / 11:57:52 / cg" |
|
4287 | 2123 |
"Modified: / 24-07-2018 / 12:08:55 / Claus Gittinger" |
141 | 2124 |
! ! |
49 | 2125 |
|
3798 | 2126 |
!Explainer class methodsFor:'naive type inferer'! |
2127 |
||
2128 |
addTypeOfExpressionNode:expr forAssignmentTo:varName to:setOfTypes |
|
3842 | 2129 |
"pick up low hanging type information. |
2130 |
This is far from being complete, but often gives a hint good enough for code completion |
|
2131 |
and info in the browser." |
|
2132 |
||
2133 |
|val valClass| |
|
3798 | 2134 |
|
2135 |
"/ only look for wellknown types on the right side. |
|
3810 | 2136 |
expr isLiteral ifTrue:[ |
2137 |
val := expr value. |
|
3801 | 2138 |
valClass := val class. |
3798 | 2139 |
val isImmutable ifTrue:[ |
3801 | 2140 |
valClass := [ valClass mutableClass ] on:Error do:[ valClass ]. |
3798 | 2141 |
]. |
2142 |
self rememberType:valClass in:setOfTypes. |
|
3826 | 2143 |
^ setOfTypes. |
3798 | 2144 |
]. |
2145 |
||
2146 |
expr isMessage ifTrue:[ |
|
3842 | 2147 |
self addTypeOfMessageNode:expr forAssignmentTo:varName to:setOfTypes. |
2148 |
^ setOfTypes. |
|
3798 | 2149 |
]. |
3855 | 2150 |
|
3826 | 2151 |
^ setOfTypes |
2152 |
||
3798 | 2153 |
"Created: / 30-04-2016 / 15:28:59 / cg" |
3801 | 2154 |
"Modified: / 30-04-2016 / 20:17:35 / cg" |
3798 | 2155 |
! |
2156 |
||
3842 | 2157 |
addTypeOfMessageNode:expr forAssignmentTo:varName to:setOfTypes |
2158 |
"pick up low hanging type information. |
|
2159 |
This is far from being complete, but often gives a hint good enough for code completion |
|
2160 |
and info in the browser." |
|
2161 |
||
2162 |
|valClass msgSelector msgReceiver| |
|
2163 |
||
2164 |
msgSelector := expr selector. |
|
2165 |
msgReceiver := expr receiver. |
|
2166 |
||
2167 |
msgSelector == #? ifTrue:[ |
|
2168 |
self addTypeOfExpressionNode:(expr arg1) forAssignmentTo:varName to:setOfTypes. |
|
2169 |
^ setOfTypes |
|
2170 |
]. |
|
2171 |
||
2172 |
"/ really really only very low hanging fruit... |
|
2173 |
"/ ignore #/ here, because of filename |
|
2174 |
( #(+ - *) includes:msgSelector ) ifTrue:[ |
|
3885 | 2175 |
true "(msgReceiver isLiteralNumber or:[expr arg1 isLiteralNumber])" ifTrue:[ |
2176 |
self rememberType:Number in:setOfTypes. |
|
2177 |
^ setOfTypes. |
|
2178 |
]. |
|
2179 |
"/ "/ ignore foo := foo OP expr |
|
2180 |
"/ "/ ignore foo := expr OP foo |
|
2181 |
"/ (msgReceiver isVariable and:[msgReceiver name = varName]) ifFalse:[ |
|
2182 |
"/ (expr arg1 isVariable and:[expr arg1 name = varName]) ifFalse:[ |
|
2183 |
"/ self rememberType:Number in:setOfTypes. |
|
2184 |
"/ ] |
|
2185 |
"/ ]. |
|
3842 | 2186 |
^ setOfTypes. |
2187 |
]. |
|
2188 |
||
2189 |
( #(// size hash identityHash) includes:msgSelector ) ifTrue:[ |
|
2190 |
self rememberType:Integer in:setOfTypes. |
|
2191 |
^ setOfTypes. |
|
2192 |
]. |
|
2193 |
||
2194 |
( #(next next:) includes:msgSelector ) ifTrue:[ |
|
2195 |
|rcvrTypes| |
|
2196 |
||
2197 |
rcvrTypes := self addTypeOfExpressionNode:msgReceiver forAssignmentTo:nil to:Set new. |
|
2198 |
rcvrTypes notEmpty ifTrue:[ |
|
3885 | 2199 |
self breakPoint:#cg. |
3842 | 2200 |
self rememberType:Character in:setOfTypes. |
2201 |
]. |
|
2202 |
^ setOfTypes. |
|
2203 |
]. |
|
2204 |
||
2205 |
( msgSelector startsWith:'as') ifTrue:[ |
|
2206 |
valClass := Smalltalk classNamed:(msgSelector copyFrom:3). |
|
2207 |
valClass notNil ifTrue:[ |
|
2208 |
self rememberType:valClass in:setOfTypes. |
|
2209 |
^ setOfTypes. |
|
2210 |
]. |
|
2211 |
]. |
|
2212 |
||
2213 |
( #(copy shallowCopy) includes:msgSelector ) ifTrue:[ |
|
2214 |
msgReceiver isLiteral ifTrue:[ |
|
2215 |
self addTypeOfExpressionNode:msgReceiver forAssignmentTo:varName to:setOfTypes. |
|
2216 |
]. |
|
2217 |
^ setOfTypes |
|
2218 |
]. |
|
2219 |
||
2220 |
msgReceiver isGlobal ifTrue:[ |
|
3853 | 2221 |
|instCreatorMessages globalValue implMethod| |
3842 | 2222 |
|
3853 | 2223 |
instCreatorMessages := #(new new: basicNew basicNew:). |
2224 |
||
3842 | 2225 |
globalValue := msgReceiver value. |
2226 |
globalValue isBehavior ifTrue:[ |
|
3853 | 2227 |
( instCreatorMessages includes:msgSelector ) ifTrue:[ |
3842 | 2228 |
self rememberType:globalValue in:setOfTypes. |
2229 |
^ setOfTypes. |
|
2230 |
]. |
|
3853 | 2231 |
implMethod := globalValue class lookupMethodFor:msgSelector. |
2232 |
"/ mhmh - fuzzy; if the implementing message sends any of the above to itself... |
|
2233 |
"/ assume it is returning it. |
|
2234 |
implMethod isNil ifTrue:[ |
|
2235 |
"/ will not be understood |
|
3857 | 2236 |
self breakPoint:#cg. |
3853 | 2237 |
^ setOfTypes. |
2238 |
]. |
|
2239 |
(implMethod messagesSentToSelf includesAny:instCreatorMessages) ifTrue:[ |
|
3857 | 2240 |
self breakPoint:#cg. |
3853 | 2241 |
self rememberType:globalValue in:setOfTypes. |
2242 |
^ setOfTypes. |
|
2243 |
]. |
|
2244 |
"/ very fuzzy - if the implementing method is in the "instance creation" category... |
|
2245 |
((implMethod category ? '') startsWith:'instance creation') ifTrue:[ |
|
3857 | 2246 |
self breakPoint:#cg. |
3853 | 2247 |
self rememberType:globalValue in:setOfTypes. |
2248 |
^ setOfTypes. |
|
2249 |
]. |
|
3842 | 2250 |
]. |
4197 | 2251 |
"/ self breakPoint:#cg. |
3842 | 2252 |
^ setOfTypes |
2253 |
]. |
|
2254 |
||
4197 | 2255 |
"/ self breakPoint:#cg. |
3842 | 2256 |
^ setOfTypes |
4197 | 2257 |
|
2258 |
"Modified: / 10-10-2017 / 16:57:09 / cg" |
|
3842 | 2259 |
! |
2260 |
||
3798 | 2261 |
addTypesAssignedToInstvar:instVarName inClass:aClass method:aMethod to:setOfTypes |
2262 |
"look to asssignments to an instance variable, and pick up low hanging class information. |
|
3842 | 2263 |
This is far from being complete, but often gives a hint good enough for code completion |
3798 | 2264 |
and info in the browser." |
2265 |
||
2266 |
| code | |
|
2267 |
||
3902 | 2268 |
SourceCodeManagerError handle:[:ex | |
2269 |
] do:[ |
|
2270 |
code := aMethod source. |
|
2271 |
]. |
|
3798 | 2272 |
(code notNil) ifTrue:[ |
2273 |
self addTypesAssignedToInstvar:instVarName inClass:aClass source:code to:setOfTypes |
|
2274 |
] |
|
2275 |
||
2276 |
"Created: / 30-04-2016 / 15:07:33 / cg" |
|
2277 |
! |
|
2278 |
||
2279 |
addTypesAssignedToInstvar:instVarName inClass:aClass source:code to:setOfTypes |
|
2280 |
"look to asssignments to an instance variable, and pick up low hanging class information. |
|
3842 | 2281 |
This is far from being complete, but often gives a hint good enough for code completion |
3798 | 2282 |
and info in the browser." |
2283 |
||
3810 | 2284 |
|tree| |
3798 | 2285 |
|
2286 |
"/ quick check (avoids expensive parse) |
|
2287 |
(code includesString:instVarName) ifFalse:[ ^ self ]. |
|
2288 |
||
2289 |
tree := Parser parse:code class:aClass. |
|
2290 |
(tree isNil or:[tree == #Error]) ifTrue:[ ^ self ]. "/ unparsable |
|
2291 |
||
3810 | 2292 |
self addTypesAssignedToInstvar:instVarName inTree:tree to:setOfTypes. |
2293 |
||
2294 |
"Created: / 30-04-2016 / 15:09:18 / cg" |
|
2295 |
! |
|
2296 |
||
2297 |
addTypesAssignedToInstvar:instVarName inClass:aClass to:setOfTypes |
|
2298 |
"look to asssignments to an instance variable, and pick up low hanging class information. |
|
3842 | 2299 |
This is far from being complete, but often gives a hint good enough for code completion |
3810 | 2300 |
and info in the browser." |
2301 |
||
2302 |
aClass methodDictionary do:[:m | |
|
2303 |
self addTypesAssignedToInstvar:instVarName inClass:aClass method:m to:setOfTypes |
|
2304 |
]. |
|
2305 |
||
2306 |
"Created: / 30-04-2016 / 14:52:56 / cg" |
|
2307 |
! |
|
2308 |
||
2309 |
addTypesAssignedToInstvar:instVarName inTree:tree to:setOfTypes |
|
2310 |
"look to asssignments to an instance variable, and pick up low hanging class information. |
|
3842 | 2311 |
This is far from being complete, but often gives a hint good enough for code completion |
3810 | 2312 |
and info in the browser." |
2313 |
||
2314 |
|visitor| |
|
2315 |
||
3798 | 2316 |
visitor := PluggableParseNodeVisitor new. |
2317 |
visitor |
|
2318 |
actionForNodeClass:AssignmentNode |
|
2319 |
put:[:node | |
|
3853 | 2320 |
(node variable isInstanceVariableNamed:instVarName) ifTrue:[ |
2321 |
self addTypeOfExpressionNode:(node expression) forAssignmentTo:instVarName to:setOfTypes |
|
3798 | 2322 |
]. |
2323 |
true "/ yes - visit subnodes |
|
2324 |
]. |
|
2325 |
visitor visit:tree. |
|
2326 |
! |
|
2327 |
||
3810 | 2328 |
addTypesAssignedToLocal:localName inTree:tree to:setOfTypes |
3842 | 2329 |
"look to asssignments to a local variable, and pick up low hanging class information. |
2330 |
This is far from being complete, but often gives a hint good enough for code completion |
|
3798 | 2331 |
and info in the browser." |
2332 |
||
3810 | 2333 |
|visitor| |
2334 |
||
2335 |
"/ hack, allowing to deal with both types of AST (sigh) |
|
2336 |
(tree isKindOf:RBProgramNode) ifTrue:[ |
|
2337 |
visitor := RBPluggableProgramNodeVisitor new. |
|
2338 |
visitor |
|
2339 |
actionForNodeClass:RBAssignmentNode |
|
2340 |
put:[:node | |
|
3853 | 2341 |
|leftSide| |
3798 | 2342 |
|
3810 | 2343 |
leftSide := node variable. |
2344 |
(leftSide isTemporary and:[ leftSide name = localName ]) ifTrue:[ |
|
3853 | 2345 |
self addTypeOfExpressionNode:(node value) forAssignmentTo:localName to:setOfTypes |
3810 | 2346 |
]. |
2347 |
true "/ yes - visit subnodes |
|
2348 |
]. |
|
2349 |
visitor visitNode:tree. |
|
2350 |
] ifFalse:[ |
|
2351 |
visitor := PluggableParseNodeVisitor new. |
|
2352 |
visitor |
|
2353 |
actionForNodeClass:AssignmentNode |
|
2354 |
put:[:node | |
|
2355 |
|leftSide expr| |
|
2356 |
||
2357 |
leftSide := node variable. |
|
2358 |
(leftSide isLocalVariable and:[ leftSide name = localName ]) ifTrue:[ |
|
2359 |
expr := node expression. |
|
2360 |
self addTypeOfExpressionNode:expr forAssignmentTo:localName to:setOfTypes |
|
2361 |
]. |
|
2362 |
true "/ yes - visit subnodes |
|
2363 |
]. |
|
2364 |
visitor visit:tree. |
|
2365 |
]. |
|
3798 | 2366 |
! |
2367 |
||
2368 |
addTypesOfInstvar:instVarName inClass:aClass fromExistingInstancesTo:setOfTypes |
|
2369 |
"look for existing instances and see that type is there" |
|
2370 |
||
2371 |
|instIndex| |
|
2372 |
||
2373 |
instIndex := aClass instVarIndexFor:instVarName. |
|
2374 |
aClass allSubInstancesDo:[:i | |
|
3801 | 2375 |
|val varClass| |
3798 | 2376 |
|
3801 | 2377 |
val := (i instVarAt:instIndex). |
2378 |
val notNil ifTrue:[ |
|
2379 |
varClass := val class. |
|
2380 |
self rememberType:varClass in:setOfTypes. |
|
2381 |
]. |
|
3798 | 2382 |
]. |
2383 |
||
2384 |
"Created: / 30-04-2016 / 14:56:11 / cg" |
|
3801 | 2385 |
"Modified: / 30-04-2016 / 20:05:03 / cg" |
3798 | 2386 |
! |
2387 |
||
2388 |
compressSetOfTypes:setOfTypes |
|
2389 |
|toAdd toRemove| |
|
2390 |
||
2391 |
"/ reduce by eliminating common superclasses... |
|
2392 |
||
2393 |
toAdd := Set new. |
|
2394 |
toRemove := Set new. |
|
2395 |
setOfTypes do:[:type1 | |
|
2396 |
setOfTypes do:[:type2 | |
|
2397 |
|common| |
|
2398 |
||
2399 |
type1 superclass == type2 ifTrue:[ |
|
2400 |
toRemove add:type1. |
|
2401 |
] ifFalse:[ |
|
2402 |
type2 superclass == type1 ifTrue:[ |
|
2403 |
toRemove add:type2. |
|
2404 |
] ifFalse:[ |
|
2405 |
common := type1 commonSuperclass:type2. |
|
2406 |
common ~~ Object ifTrue:[ |
|
2407 |
toRemove add:type1. |
|
2408 |
toRemove add:type2. |
|
2409 |
toAdd add:common. |
|
2410 |
]. |
|
2411 |
]. |
|
2412 |
]. |
|
2413 |
] |
|
2414 |
]. |
|
2415 |
setOfTypes removeAll:toRemove. |
|
2416 |
setOfTypes addAll:toRemove. |
|
2417 |
||
2418 |
"/ hack |
|
2419 |
setOfTypes size == 2 ifTrue:[ |
|
2420 |
((setOfTypes includes:True) and:[setOfTypes includes:False]) ifTrue:[ |
|
2421 |
setOfTypes removeAll; add:Boolean. |
|
2422 |
^ self. |
|
2423 |
]. |
|
2424 |
((setOfTypes includes:SmallInteger) and:[setOfTypes includes:LargeInteger]) ifTrue:[ |
|
2425 |
setOfTypes removeAll; add:Integer. |
|
2426 |
^ self. |
|
2427 |
] |
|
2428 |
]. |
|
2429 |
||
2430 |
"Created: / 30-04-2016 / 15:37:38 / cg" |
|
2431 |
! |
|
2432 |
||
2433 |
rememberType:aClass in:setOfTypes |
|
2434 |
setOfTypes add:aClass |
|
2435 |
||
2436 |
"Created: / 30-04-2016 / 15:35:44 / cg" |
|
3801 | 2437 |
"Modified: / 30-04-2016 / 20:05:09 / cg" |
3798 | 2438 |
! ! |
2439 |
||
3838 | 2440 |
!Explainer class methodsFor:'utilities'! |
2441 |
||
3842 | 2442 |
actionToBrowseClass:class |
2443 |
^ self actionToBrowseClass:class selector:nil. |
|
2444 |
! |
|
2445 |
||
3838 | 2446 |
actionToBrowseClass:class selector:selectorOrNil |
3885 | 2447 |
^ self actionToBrowseClass:class selector:selectorOrNil info:nil |
3866 | 2448 |
! |
2449 |
||
2450 |
actionToBrowseClass:class selector:selectorOrNil info:info |
|
3885 | 2451 |
self assert:class isBehavior. |
3866 | 2452 |
^ ActionWithInfo |
2453 |
block: |
|
2454 |
[ |
|
2455 |
self thisOrNewBrowserInto:[:browser :openHow | |
|
2456 |
browser |
|
2457 |
spawnFullBrowserInClass:class selector:selectorOrNil in:openHow |
|
2458 |
] |
|
2459 |
] |
|
2460 |
info:info |
|
3838 | 2461 |
! |
2462 |
||
2463 |
actionToBrowseClasses:classes |
|
3868 | 2464 |
^ ActionWithInfo |
2465 |
block:[ |
|
2466 |
"/ Tools::NewSystemBrowser browseClasses:classes |
|
2467 |
self thisOrNewBrowserInto:[:browser :openHow | |
|
2468 |
browser spawnClassBrowserFor:classes in:openHow |
|
2469 |
] |
|
3855 | 2470 |
] |
3868 | 2471 |
info:nil |
3838 | 2472 |
! |
2473 |
||
3855 | 2474 |
actionToBrowseImplementorsOf:selector |
4032 | 2475 |
^ self actionToBrowseImplementorsOf:selector in:[Smalltalk allClasses] |
3866 | 2476 |
! |
2477 |
||
2478 |
actionToBrowseImplementorsOf:selector in:classes |
|
3868 | 2479 |
^ ActionWithInfo |
2480 |
block:[ |
|
2481 |
self thisOrNewBrowserInto:[:browser :openHow | |
|
2482 |
browser |
|
2483 |
spawnMethodImplementorsBrowserFor:{ selector } |
|
2484 |
match:false |
|
2485 |
in:openHow |
|
4032 | 2486 |
classes:classes value |
3868 | 2487 |
label:('Implementors of %1' bindWith:selector) |
2488 |
] |
|
3855 | 2489 |
] |
4032 | 2490 |
info:('Click to browse implementors') |
3842 | 2491 |
! |
2492 |
||
3853 | 2493 |
actionToBrowseInstvarRefsTo:instVarName inClass:class |
3868 | 2494 |
^ ActionWithInfo |
2495 |
block:[ |
|
2496 |
self thisOrNewBrowserInto:[:browser :openHow | |
|
2497 |
browser |
|
2498 |
browseVarRefsToAny:{ instVarName } |
|
2499 |
classes:{ class } |
|
2500 |
variables:#instVarNames access:#readOrWrite all:true |
|
2501 |
title:'references to ',instVarName |
|
2502 |
in:openHow |
|
2503 |
] |
|
2504 |
] |
|
2505 |
info:nil |
|
3853 | 2506 |
! |
2507 |
||
3842 | 2508 |
actionToBrowseMethod:mthd |
3885 | 2509 |
self assert:mthd isMethod. |
3842 | 2510 |
^ self actionToBrowseClass:(mthd mclass) selector:(mthd selector). |
2511 |
! |
|
2512 |
||
2513 |
actionToOpenMethodFinderFor:selector |
|
3838 | 2514 |
MethodFinderWindow notNil ifTrue:[ |
3868 | 2515 |
^ ActionWithInfo |
2516 |
block:[ |
|
2517 |
MethodFinderWindow openOnSelectorPattern:selector |
|
2518 |
] |
|
2519 |
info:nil. |
|
3838 | 2520 |
]. |
3842 | 2521 |
^ self actionToBrowseImplementorsOf:selector |
2522 |
! |
|
2523 |
||
2524 |
asClassLink:nameOfClass |
|
2525 |
"return text with a hyperlink to browse a class by that name" |
|
3838 | 2526 |
|
3842 | 2527 |
|cls| |
2528 |
||
2529 |
cls := Smalltalk classNamed:nameOfClass string asUppercaseFirst. |
|
2530 |
cls isNil ifTrue:[^ nameOfClass]. |
|
3859 | 2531 |
|
3866 | 2532 |
^ self |
2533 |
asLink:nameOfClass |
|
3878 | 2534 |
info:('Click to browse %1' bindWith:nameOfClass) |
3866 | 2535 |
to:(self actionToBrowseClass:cls) |
2536 |
! |
|
2537 |
||
2538 |
asLink:aString info:info to:actionOrNil |
|
2539 |
actionOrNil isNil ifTrue:[^ aString]. |
|
2540 |
^ aString asActionLinkTo:(ActionWithInfo block:actionOrNil info:info) |
|
2541 |
! |
|
2542 |
||
2543 |
asLink:aString to:actionOrNil |
|
2544 |
actionOrNil isNil ifTrue:[^ aString]. |
|
2545 |
^ aString asActionLinkTo:actionOrNil |
|
2546 |
! |
|
2547 |
||
3872 | 2548 |
infoStringForClasses:aCollectionOfClasses withPrefix:prefix |
2549 |
"get a nice user readable list for some classes. |
|
4399 | 2550 |
Up to 4 are listed by name, otherwise the count is presented. |
2551 |
The prefix can be sth like 'other ', 'sub', 'super', |
|
2552 |
'implementing ' etc. |
|
2553 |
Or it can be an empty string. |
|
2554 |
The returned string is meant to be shown in the info line at the bottom." |
|
2555 |
||
2556 |
|nClassNames sortedByName classNames |
|
2557 |
commonSuperClass link1 link2 link3 link4| |
|
3872 | 2558 |
|
2559 |
aCollectionOfClasses isEmpty ifTrue:[ |
|
2560 |
^ 'No %1classes' bindWith:prefix. |
|
2561 |
]. |
|
2562 |
||
4032 | 2563 |
classNames := aCollectionOfClasses asIdentitySet asOrderedCollection |
2564 |
collect:[:each | each theNonMetaclass name]. |
|
3872 | 2565 |
|
2566 |
nClassNames := classNames size. |
|
2567 |
||
2568 |
nClassNames <= 4 ifTrue:[ |
|
3885 | 2569 |
sortedByName := classNames sort. |
2570 |
link1 := self asClassLink:sortedByName first. |
|
3872 | 2571 |
nClassNames == 1 ifTrue:[ |
3885 | 2572 |
^ '%2' "'1 %1class: %2'" bindWith:prefix with:link1. |
3872 | 2573 |
]. |
3885 | 2574 |
link2 := self asClassLink:classNames second. |
3872 | 2575 |
nClassNames == 2 ifTrue:[ |
2576 |
^ '%2 and %3' "'2 %1classes: %2 and %3'" bindWith:prefix |
|
3885 | 2577 |
with:link1 |
2578 |
with:link2. |
|
3872 | 2579 |
]. |
3885 | 2580 |
link3 := self asClassLink:classNames third. |
3872 | 2581 |
nClassNames == 3 ifTrue:[ |
2582 |
^ '%2, %3 and %4' "'3 %1classes: %2, %3 and %4'" bindWith:prefix |
|
3885 | 2583 |
with:link1 |
2584 |
with:link2 |
|
2585 |
with:link3. |
|
3872 | 2586 |
]. |
3885 | 2587 |
link4 := self asClassLink:classNames fourth. |
3872 | 2588 |
nClassNames == 4 ifTrue:[ |
2589 |
^ '%2, %3, %4 and %5' "'4 %1classes: %2, %3, %4 and %5'" bindWith:prefix |
|
3885 | 2590 |
with:link1 |
2591 |
with:link2 |
|
2592 |
with:link3 |
|
2593 |
with:link4. |
|
3872 | 2594 |
]. |
2595 |
]. |
|
4399 | 2596 |
commonSuperClass := Class commonSuperclassOf:aCollectionOfClasses. |
2597 |
(aCollectionOfClasses includes:commonSuperClass) ifTrue:[ |
|
2598 |
^ self |
|
2599 |
asLink:('%1 and %2 additional %3classes' |
|
2600 |
bindWith:commonSuperClass theNonMetaclass name |
|
2601 |
with:(nClassNames - 1) |
|
2602 |
with:prefix) |
|
2603 |
info:'Browse classes' |
|
2604 |
to:(self actionToBrowseClasses:aCollectionOfClasses) |
|
2605 |
]. |
|
2606 |
||
3885 | 2607 |
^ self |
2608 |
asLink:('%1 %2classes' bindWith:nClassNames printString with:prefix) |
|
2609 |
info:'Browse classes' |
|
2610 |
to:(self actionToBrowseClasses:aCollectionOfClasses) |
|
3872 | 2611 |
|
4399 | 2612 |
" |
2613 |
self infoStringForClasses:{ Array } withPrefix:'sub' |
|
2614 |
self infoStringForClasses:{ Array . Point } withPrefix:'sub' |
|
2615 |
self infoStringForClasses:{ Array . Point . Integer . Float} withPrefix:'sub' |
|
2616 |
self infoStringForClasses:{ Array . Point . Integer . Float . Fraction} withPrefix:'sub' |
|
2617 |
self infoStringForClasses:{ Number . Integer . Float . Fraction . SmallInteger} withPrefix:'sub' |
|
2618 |
" |
|
2619 |
||
3872 | 2620 |
"Modified: / 27-07-2006 / 10:09:02 / cg" |
4399 | 2621 |
"Modified: / 27-03-2019 / 10:42:24 / Claus Gittinger" |
3872 | 2622 |
! |
2623 |
||
3866 | 2624 |
infoStringForClasses:aCollectionOfClasses withPrefix:prefix actionGenerator:actionGeneratorOrNil |
2625 |
"get a nice user readable list for some classes. |
|
2626 |
Up to 4 are named, otherwise the count is presented. |
|
2627 |
The prefix can be sth like ' other', ' sub', ' super', |
|
2628 |
' implementing' etc. Or it can be an empty string. |
|
2629 |
To be shown in the info line at the bottom." |
|
2630 |
||
2631 |
|nClassNames classes sortedByName classNames |
|
2632 |
link1 link2 link3 link4 actionGenerator| |
|
2633 |
||
2634 |
aCollectionOfClasses isEmpty ifTrue:[ |
|
2635 |
^ 'No %1classes' bindWith:prefix. |
|
2636 |
]. |
|
2637 |
||
2638 |
actionGenerator := actionGeneratorOrNil isNil |
|
2639 |
ifTrue:[ [:classes | self actionToBrowseClasses:classes] ] |
|
2640 |
ifFalse:[ actionGeneratorOrNil ]. |
|
2641 |
||
2642 |
classes := aCollectionOfClasses asIdentitySet asOrderedCollection. |
|
2643 |
classNames := classes collect:[:each | each theNonMetaclass name]. |
|
2644 |
||
2645 |
nClassNames := classNames size. |
|
2646 |
||
2647 |
nClassNames <= 4 ifTrue:[ |
|
2648 |
sortedByName := classNames sortWith:classes. |
|
2649 |
||
2650 |
link1 := self asLink:classNames first "allBold" |
|
2651 |
info:('Browse %1' bindWith:classNames first) |
|
2652 |
to:(actionGenerator value:{classes first}). |
|
2653 |
nClassNames == 1 ifTrue:[ |
|
2654 |
^ '%2' "'1 %1class: %2'" |
|
2655 |
bindWith:prefix |
|
2656 |
with:link1. |
|
2657 |
]. |
|
2658 |
link2 := self asLink:classNames second "allBold" to:(actionGenerator value:{classes second}). |
|
2659 |
nClassNames == 2 ifTrue:[ |
|
2660 |
^ '%2 and %3' "'2 %1classes: %2 and %3'" |
|
2661 |
bindWith:prefix |
|
2662 |
with:link1 |
|
2663 |
with:link2. |
|
2664 |
]. |
|
2665 |
link3 := self asLink:classNames third "allBold" to:(actionGenerator value:{classes third}). |
|
2666 |
nClassNames == 3 ifTrue:[ |
|
2667 |
^ '%2, %3 and %4' "'3 %1classes: %2, %3 and %4'" |
|
2668 |
bindWith:prefix |
|
2669 |
with:link1 |
|
2670 |
with:link2 |
|
2671 |
with:link3. |
|
2672 |
]. |
|
2673 |
link4 := self asLink:classNames fourth "allBold" to:(actionGenerator value:{classes fourth}). |
|
2674 |
nClassNames == 4 ifTrue:[ |
|
2675 |
^ '%2, %3, %4 and %5' "'4 %1classes: %2, %3, %4 and %5'" |
|
2676 |
bindWith:prefix |
|
2677 |
with:link1 |
|
2678 |
with:link2 |
|
2679 |
with:link3 |
|
2680 |
with:link4. |
|
2681 |
]. |
|
2682 |
]. |
|
2683 |
^ self |
|
2684 |
asLink:('%1 %2classes' bindWith:(nClassNames printString "allBold") with:prefix) |
|
2685 |
to:(actionGenerator value:classes) |
|
2686 |
||
2687 |
"Modified: / 27-07-2006 / 10:09:02 / cg" |
|
3842 | 2688 |
! |
2689 |
||
2690 |
infoStringForMethods:aCollectionOfMethods withPrefix:prefix |
|
2691 |
"get a nice user readable list for some methods. |
|
2692 |
Up to 3 are named, otherwise the count is presented. |
|
2693 |
The prefix can be sth like ' other', ' sender', ' implementor', |
|
2694 |
Or it can be an empty string. |
|
2695 |
Result is meant to be shown in the info line at the bottom of a browser." |
|
2696 |
||
2697 |
|nMethodNames sortedByName methodNames| |
|
2698 |
||
2699 |
aCollectionOfMethods isEmpty ifTrue:[ |
|
2700 |
^ 'No %1' bindWith:prefix. |
|
2701 |
]. |
|
2702 |
||
2703 |
methodNames := aCollectionOfMethods asOrderedCollection |
|
2704 |
collect:[:each | each whoString]. |
|
2705 |
||
2706 |
nMethodNames := methodNames size. |
|
2707 |
||
2708 |
nMethodNames <= 3 ifTrue:[ |
|
2709 |
nMethodNames == 1 ifTrue:[ |
|
2710 |
^ '%2' "'1 %1class: %2'" bindWith:prefix with:(methodNames first allBold). |
|
2711 |
]. |
|
2712 |
sortedByName := methodNames sort. |
|
2713 |
nMethodNames == 2 ifTrue:[ |
|
2714 |
^ '%2 and %3' "'2 %1classes: %2 and %3'" bindWith:prefix |
|
2715 |
with:(sortedByName first allBold) |
|
2716 |
with:(sortedByName second allBold). |
|
2717 |
]. |
|
2718 |
nMethodNames == 3 ifTrue:[ |
|
2719 |
^ '%2, %3 and %4' "'3 %1classes: %2, %3 and %4'" bindWith:prefix |
|
2720 |
with:(sortedByName first allBold) |
|
2721 |
with:(sortedByName second allBold) |
|
2722 |
with:(sortedByName third allBold). |
|
2723 |
]. |
|
2724 |
nMethodNames == 4 ifTrue:[ |
|
2725 |
^ '%2, %3, %4 and %5' "'4 %1classes: %2, %3, %4 and %5'" bindWith:prefix |
|
2726 |
with:(sortedByName first allBold) |
|
2727 |
with:(sortedByName second allBold) |
|
2728 |
with:(sortedByName third allBold) |
|
2729 |
with:(sortedByName fourth allBold). |
|
2730 |
]. |
|
2731 |
]. |
|
2732 |
^ '%1 %2methods' bindWith:nMethodNames printString allBold with:prefix. |
|
2733 |
||
2734 |
" |
|
2735 |
Time millisecondsToRun:[ |
|
2736 |
self infoStringForMethods:(SystemBrowser allCallsOn:#'at:put:') withPrefix:'' |
|
2737 |
]. |
|
2738 |
Time millisecondsToRun:[ |
|
2739 |
self infoStringForMethods:(SystemBrowser allCallsOn:#'actionToBrowseClasses:') withPrefix:'' |
|
2740 |
]. |
|
2741 |
" |
|
2742 |
! |
|
2743 |
||
3872 | 2744 |
methodImplementorsInfoFor:aMethod inEnvironment:environment |
2745 |
"get something about the implementors of aMethod |
|
2746 |
to be shown in the info line at the bottom" |
|
2747 |
||
2748 |
|implementors msg senders msg2| |
|
2749 |
||
2750 |
implementors := SystemBrowser |
|
2751 |
findImplementorsOf:aMethod selector |
|
2752 |
in:(environment allClasses) |
|
2753 |
ignoreCase:false. |
|
2754 |
||
2755 |
implementors notEmpty ifTrue:[ |
|
2756 |
msg := 'Only implemented here.'. |
|
2757 |
implementors remove:aMethod ifAbsent:nil. |
|
2758 |
implementors notEmpty ifTrue:[ |
|
2759 |
implementors := implementors collect:[:mthd | mthd mclass ? mthd getMclass]. |
|
2760 |
implementors notEmpty ifTrue:[ |
|
4032 | 2761 |
msg := 'Also ',(self asLink:'implemented' to:(self actionToBrowseImplementorsOf:aMethod selector)),' in '. |
3872 | 2762 |
msg := msg , (self infoStringForClasses:implementors withPrefix:'other '). |
2763 |
msg := msg , '.'. |
|
2764 |
] |
|
2765 |
]. |
|
2766 |
]. |
|
2767 |
||
2768 |
false ifTrue:[ "/ too slow |
|
2769 |
senders := SystemBrowser |
|
2770 |
findSendersOf:aMethod selector |
|
2771 |
in:(environment allClasses) |
|
2772 |
ignoreCase:false. |
|
2773 |
senders notEmpty ifTrue:[ |
|
2774 |
msg2 := 'Sent from ' , senders size printString, ' methods.'. |
|
2775 |
] ifFalse:[ |
|
2776 |
msg2 := 'No senders.'. |
|
2777 |
]. |
|
2778 |
msg := msg , '/' , msg2 |
|
2779 |
]. |
|
2780 |
||
2781 |
^ msg |
|
2782 |
! |
|
2783 |
||
3871 | 2784 |
methodInheritanceInfoFor:aMethod |
2785 |
|methodsSuperclass inheritedClass msg methodsClass sel mthd selectorString| |
|
2786 |
||
2787 |
methodsClass := aMethod mclass. |
|
2788 |
methodsClass isNil ifTrue:[^ nil]. |
|
2789 |
||
2790 |
methodsSuperclass := methodsClass superclass. |
|
2791 |
methodsSuperclass isNil ifTrue:[^ nil]. |
|
2792 |
||
2793 |
sel := aMethod selector. |
|
2794 |
inheritedClass := methodsSuperclass whichClassIncludesSelector:sel. |
|
2795 |
inheritedClass notNil ifTrue:[ |
|
2796 |
mthd := inheritedClass compiledMethodAt:sel. |
|
4110 | 2797 |
(mthd sendsSelector:#'subclassResponsibility') ifTrue:[ |
3871 | 2798 |
msg := '%1 overrides subclassResponsibility in %2'. |
2799 |
] ifFalse:[ |
|
2800 |
msg := '%1 overrides implementation in %2'. |
|
2801 |
]. |
|
2802 |
selectorString := sel contractTo:30. |
|
2803 |
^ msg |
|
2804 |
bindWith:(self |
|
2805 |
asLink:selectorString "allBold" |
|
2806 |
info:('Browse all implementors of %1' bindWith:selectorString) |
|
2807 |
to:(self actionToOpenMethodFinderFor:sel)) |
|
2808 |
with:(self |
|
2809 |
asLink:inheritedClass name "allBold" |
|
4399 | 2810 |
info:('Browse %1 » %2' bindWith:inheritedClass name with:sel) |
3871 | 2811 |
to:(self actionToBrowseClass:inheritedClass selector:sel)). |
2812 |
]. |
|
2813 |
||
2814 |
^ msg |
|
4110 | 2815 |
|
2816 |
"Modified: / 05-02-2017 / 01:24:25 / cg" |
|
3871 | 2817 |
! |
2818 |
||
2819 |
methodRedefinitionInfoFor:aMethod |
|
2820 |
"return a user readable string telling in how many subclasses |
|
2821 |
a method is redefined. |
|
2822 |
To be shown in the info line of a browser" |
|
2823 |
||
4060 | 2824 |
|redefiningClasses msg methodsClass| |
2825 |
||
2826 |
methodsClass := aMethod mclass. |
|
2827 |
methodsClass isNil ifTrue:[^ nil]. |
|
2828 |
||
2829 |
redefiningClasses := methodsClass allSubclasses select:[:eachClass | eachClass includesSelector:aMethod selector]. |
|
2830 |
redefiningClasses size ~~ 0 ifTrue:[ |
|
3871 | 2831 |
msg := 'redefined in '. |
2832 |
msg := msg , (self |
|
2833 |
infoStringForClasses:redefiningClasses |
|
2834 |
withPrefix:'sub' |
|
2835 |
actionGenerator:[:classes | |
|
3878 | 2836 |
classes size == 1 ifTrue:[ |
2837 |
|cls| |
|
4060 | 2838 |
|
3878 | 2839 |
cls := classes first. |
2840 |
self |
|
2841 |
actionToBrowseClass:cls |
|
2842 |
selector:aMethod selector |
|
2843 |
info:('Browse implementation in %1' bindWith:cls name) |
|
2844 |
] ifFalse:[ |
|
2845 |
self |
|
2846 |
actionToBrowseImplementorsOf:aMethod selector |
|
2847 |
in:classes |
|
2848 |
]. |
|
2849 |
]). |
|
3871 | 2850 |
msg := msg , '.'. |
2851 |
]. |
|
2852 |
||
2853 |
^ msg |
|
2854 |
! |
|
2855 |
||
3842 | 2856 |
methodSendersInfoFor:selector inEnvironment:environment |
2857 |
"get something about the senders of a message. |
|
2858 |
to be shown in the info line at the bottom. |
|
2859 |
This may be slow; so think about doing it in background..." |
|
2860 |
||
2861 |
|senders| |
|
2862 |
||
2863 |
senders := SystemBrowser |
|
2864 |
findSendersOf:selector |
|
2865 |
in:(environment allClasses) |
|
2866 |
ignoreCase:false |
|
2867 |
match:false. |
|
2868 |
||
2869 |
senders notEmpty ifTrue:[ |
|
2870 |
^ 'Sent from ' , senders size printString, ' methods.'. |
|
2871 |
] ifFalse:[ |
|
2872 |
^ 'No senders.'. |
|
2873 |
]. |
|
3859 | 2874 |
! |
2875 |
||
3872 | 2876 |
methodSpecialInfoFor:aMethod |
2877 |
"handles special cases - such as documentation methods" |
|
2878 |
||
2879 |
|cls sel| |
|
2880 |
||
2881 |
(cls := aMethod mclass) isNil ifTrue:[^ nil]. |
|
2882 |
(sel := aMethod selector) isNil ifTrue:[^ nil]. |
|
2883 |
||
2884 |
cls isMeta ifTrue:[ |
|
2885 |
(AbstractSourceCodeManager isVersionMethodSelector:sel) ifTrue:[ |
|
2886 |
^ 'The version method is required for the source code repository - do not modify.'. |
|
2887 |
]. |
|
2888 |
sel == #documentation ifTrue:[ |
|
2889 |
^ 'ST/X stores documentation in this method (not in comment slots)'. |
|
2890 |
]. |
|
2891 |
]. |
|
2892 |
^ nil |
|
2893 |
! |
|
2894 |
||
3859 | 2895 |
thisOrNewBrowserInto:aTwoArgBlock |
4269 | 2896 |
"I am inviked when user clicks on a link in the info line. |
2897 |
if I am invoked by a browser, |
|
4268 | 2898 |
invoke the twoArgBlock with it and a #newBuffer arg. |
3859 | 2899 |
Otherwise, create a new (invisible) browser and pass it to the block |
2900 |
with a #newBrowser arg." |
|
2901 |
||
2902 |
|windowGroupClass browserClass wg app| |
|
2903 |
||
2904 |
"/ stupid: I am in libcomp; should be in libtool |
|
4269 | 2905 |
"/ access by name, so we do not introduce new prerequisites on the package |
3859 | 2906 |
windowGroupClass := Smalltalk at:#WindowGroup. |
2907 |
windowGroupClass isNil ifTrue:[^ self]. |
|
4269 | 2908 |
browserClass := Smalltalk at:#'SystemBrowser'. |
2909 |
browserClass isNil ifTrue:[^ self]. |
|
2910 |
browserClass := browserClass default. |
|
3859 | 2911 |
browserClass isNil ifTrue:[^ self]. |
2912 |
||
2913 |
((wg := windowGroupClass activeGroup) notNil |
|
2914 |
and:[ (app := wg application) isKindOf:browserClass ] |
|
2915 |
) ifTrue:[ |
|
2916 |
^ aTwoArgBlock value:app value:#newBuffer |
|
2917 |
]. |
|
2918 |
^ aTwoArgBlock value:(browserClass basicNew) value:#newBrowser |
|
4268 | 2919 |
|
4269 | 2920 |
"Modified (comment): / 24-05-2018 / 15:01:01 / Claus Gittinger" |
3838 | 2921 |
! ! |
3826 | 2922 |
|
3866 | 2923 |
!Explainer::ActionWithInfo class methodsFor:'instance creation'! |
2924 |
||
2925 |
block:aBlock info:info |
|
2926 |
^ self new block:aBlock info:info |
|
2927 |
! ! |
|
2928 |
||
2929 |
!Explainer::ActionWithInfo methodsFor:'accessing'! |
|
2930 |
||
2931 |
block:blockArg info:infoArg |
|
2932 |
block := blockArg. |
|
2933 |
info := infoArg. |
|
2934 |
! |
|
2935 |
||
2936 |
info:something |
|
2937 |
info := something. |
|
2938 |
! ! |
|
2939 |
||
2940 |
!Explainer::ActionWithInfo methodsFor:'evaluation'! |
|
2941 |
||
2942 |
info |
|
2943 |
^ info |
|
2944 |
! |
|
2945 |
||
2946 |
value |
|
2947 |
^ block value |
|
2948 |
! |
|
2949 |
||
2950 |
value:arg |
|
2951 |
^ block value:arg |
|
2952 |
! ! |
|
2953 |
||
396 | 2954 |
!Explainer class methodsFor:'documentation'! |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
2955 |
|
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
2956 |
version |
3697 | 2957 |
^ '$Header$' |
2214 | 2958 |
! |
2959 |
||
2960 |
version_CVS |
|
3697 | 2961 |
^ '$Header$' |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
2962 |
! ! |
3209 | 2963 |