author | Claus Gittinger <cg@exept.de> |
Sat, 08 Jun 2019 14:04:14 +0200 | |
changeset 4435 | 10a6786b7d87 |
parent 4434 | d04631202a76 |
child 4448 | e0dbd918bc2e |
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. |
|
4435 | 867 |
valString := self safeValueStringFor:val. |
4378 | 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. |
|
4435 | 880 |
valString := self safeValueStringFor:val. |
4378 | 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. |
|
4435 | 942 |
valString := self safeValueStringFor:val. |
4378 | 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" |
4435 | 1041 |
"Modified: / 08-06-2019 / 14:04:00 / 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 |
||
4435 | 1153 |
valText := self safeValueStringFor:val. |
2427 | 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" |
4435 | 1168 |
"Modified: / 08-06-2019 / 14:03:42 / Claus Gittinger" |
1188 | 1169 |
! |
1170 |
||
4378 | 1171 |
explainHereIn:aClassOrNil short:shortText |
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1172 |
"return an explanation" |
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1173 |
|
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1174 |
|className| |
1188 | 1175 |
|
4378 | 1176 |
aClassOrNil isNil ifTrue:[ |
1177 |
shortText ifTrue:[ |
|
1178 |
^ '"here" - message lookup always starts in the method''s class (always call local method).' |
|
1179 |
]. |
|
1180 |
^ 'like "self", "','here'allBold,'" refers to the object which received the message. |
|
1181 |
||
1182 |
However, when sending a message to "here", the search for methods |
|
1183 |
implementing this message will start in the defining class, |
|
1184 |
instead of the receiver''s class. |
|
1185 |
Thus, using "here", redefined methods will NOT be reached with a here-send and it is ensured, |
|
1186 |
that the local method is called.' |
|
1187 |
]. |
|
1188 |
||
1189 |
className := aClassOrNil name. |
|
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1190 |
shortText ifTrue:[ |
3810 | 1191 |
^ '"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
|
1192 |
]. |
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1193 |
^ '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
|
1194 |
|
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1195 |
However, when sending a message to "here", the search for methods |
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1196 |
implementing this message will start in the defining class (' , className , '), |
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1197 |
instead of the receiver''s class (' , className , ' or subclass). |
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1198 |
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
|
1199 |
that the local method is called.' |
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1200 |
|
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1201 |
"Created: / 28-02-2012 / 10:44:55 / cg" |
4378 | 1202 |
"Modified: / 04-03-2019 / 10:14:00 / Claus Gittinger" |
1188 | 1203 |
! |
1204 |
||
3798 | 1205 |
explainInstanceVariable:instVarName inClass:aClass short:shortText |
3853 | 1206 |
|varNameInText classNameInText template stringText setOfTypes typesDescription| |
3798 | 1207 |
|
4378 | 1208 |
aClass isNil ifTrue:[^ nil]. |
1209 |
||
3853 | 1210 |
varNameInText := instVarName allBold. |
1211 |
classNameInText := aClass name. |
|
1212 |
||
3798 | 1213 |
shortText ifTrue:[ |
3883 | 1214 |
template := '%1: instVar in %2'. |
3878 | 1215 |
varNameInText := self |
1216 |
asLink:varNameInText |
|
1217 |
info:('Click to browse references to %1' bindWith:instVarName) |
|
1218 |
to:(self actionToBrowseInstvarRefsTo:instVarName inClass:aClass). |
|
3866 | 1219 |
classNameInText := self asClassLink:classNameInText. |
3798 | 1220 |
] ifFalse:[ |
1221 |
template := '%1: an instance variable in %2' |
|
1222 |
]. |
|
3853 | 1223 |
stringText := template bindWith:varNameInText with:classNameInText. |
3798 | 1224 |
|
1225 |
"/ look for instances |
|
1226 |
setOfTypes := IdentitySet new. |
|
1227 |
self addTypesOfInstvar:instVarName inClass:aClass fromExistingInstancesTo:setOfTypes. |
|
1228 |
"/ look for assignments |
|
3878 | 1229 |
aClass withAllSubclassesDo:[:cls | |
1230 |
self addTypesAssignedToInstvar:instVarName inClass:cls to:setOfTypes |
|
1231 |
]. |
|
1232 |
||
1233 |
"/ generate a list of up-to 3 links |
|
3810 | 1234 |
typesDescription := self typeDescriptionFor:setOfTypes andSelector:nil. |
1235 |
typesDescription notNil ifTrue:[ |
|
1236 |
stringText := stringText,' (',typesDescription,')' |
|
1237 |
]. |
|
3798 | 1238 |
^ stringText |
4378 | 1239 |
|
1240 |
"Modified: / 04-03-2019 / 10:14:32 / Claus Gittinger" |
|
3798 | 1241 |
! |
1242 |
||
1188 | 1243 |
explainKnownSymbol:string inClass:aClass |
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1244 |
"return an explanation or nil" |
1188 | 1245 |
|
1246 |
^ self explainKnownSymbol:string inClass:aClass short:false |
|
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1247 |
|
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1248 |
"Modified (comment): / 28-02-2012 / 10:45:40 / cg" |
1188 | 1249 |
! |
1250 |
||
4378 | 1251 |
explainKnownSymbol:string inClass:aClassOrNil short:shortText |
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1252 |
"return an explanation or nil" |
1188 | 1253 |
|
2471 | 1254 |
|sym expl| |
1188 | 1255 |
|
1256 |
sym := string asSymbolIfInterned. |
|
1257 |
sym isNil ifTrue:[^ nil]. |
|
1258 |
||
2427 | 1259 |
"try globals and pools" |
1188 | 1260 |
(Smalltalk includesKey:sym) ifTrue:[ |
4378 | 1261 |
expl := self explainGlobalOrPoolVariable:string inClass:aClassOrNil short:shortText. |
3810 | 1262 |
expl notNil ifTrue:[^ expl]. |
1188 | 1263 |
]. |
1264 |
||
4378 | 1265 |
expl := self explainSelector:string inClass:aClassOrNil short:shortText. |
2471 | 1266 |
expl notNil ifTrue:[^ expl]. |
4378 | 1267 |
^ self explainGlobalOrPoolVariable:string inClass:aClassOrNil short:shortText. |
2427 | 1268 |
|
2471 | 1269 |
"Modified: / 18-01-2011 / 19:13:07 / cg" |
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1270 |
"Modified (comment): / 28-02-2012 / 10:46:06 / cg" |
1188 | 1271 |
! |
1272 |
||
1273 |
explainPseudoVariable:string in:aClass |
|
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1274 |
"return an explanation for the pseudoVariables self, super etc." |
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1275 |
|
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1276 |
<resource: #obsolete> |
1188 | 1277 |
|
1278 |
^ self explainPseudoVariable:string in:aClass short:false |
|
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1279 |
|
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1280 |
"Modified (format): / 28-02-2012 / 10:47:17 / cg" |
1188 | 1281 |
! |
1282 |
||
4378 | 1283 |
explainPseudoVariable:string in:aClassOrNil short:shortText |
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1284 |
"return an explanation for the pseudoVariables self, super etc." |
1188 | 1285 |
|
1286 |
(string = 'self') ifTrue:[ |
|
4378 | 1287 |
^ self explainSelfIn:aClassOrNil short:shortText |
1188 | 1288 |
]. |
1289 |
||
1290 |
(string = 'super') ifTrue:[ |
|
4378 | 1291 |
^ self explainSuperIn:aClassOrNil short:shortText |
1188 | 1292 |
]. |
1293 |
||
1294 |
(string = 'here') ifTrue:[ |
|
4378 | 1295 |
^ self explainHereIn:aClassOrNil short:shortText |
1188 | 1296 |
]. |
1297 |
||
1298 |
(string = 'thisContext') ifTrue:[ |
|
3810 | 1299 |
shortText ifTrue:[ |
1300 |
^ '''thisContext'' - the current stack frame as an object.' |
|
1301 |
]. |
|
1302 |
^ 'thisContext is a pseudo variable (i.e. it is built in). |
|
1188 | 1303 |
|
1304 |
ThisContext always refers to the context object for the currently executed method or |
|
1305 |
block (an instance of Context or BlockContext respectively). The calling chain and calling |
|
1306 |
receivers/selectors can be accessed via thisContext.' |
|
1307 |
]. |
|
1308 |
||
1309 |
(string = 'true') ifTrue:[ |
|
3810 | 1310 |
shortText ifTrue:[ |
1311 |
^ '''true'' - the truth and nothing but the truth.' |
|
1312 |
]. |
|
1313 |
^ 'true is a pseudo variable (i.e. it is built in). |
|
1188 | 1314 |
|
1315 |
True represents logical truth. It is the one and only instance of class True.' |
|
1316 |
]. |
|
1317 |
||
1318 |
(string = 'false') ifTrue:[ |
|
3810 | 1319 |
shortText ifTrue:[ |
1320 |
^ '''false'' - obvisously not true.' |
|
1321 |
]. |
|
1322 |
^ 'false is a pseudo variable (i.e. it is built in). |
|
1188 | 1323 |
|
1324 |
False represents logical falseness. It is the one and only instance of class False.' |
|
1325 |
]. |
|
1326 |
||
1327 |
(string = 'nil') ifTrue:[ |
|
3810 | 1328 |
shortText ifTrue:[ |
1329 |
^ '''nil'' - undefined, unknown, void or dont care.' |
|
1330 |
]. |
|
1331 |
^ 'nil is a pseudo variable (i.e. it is built in). |
|
1188 | 1332 |
|
1333 |
Nil is used for unitialized variables (among other uses). |
|
1334 |
Nil is the one and only instance of class UndefinedObject.' |
|
1335 |
]. |
|
1336 |
^ nil |
|
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1337 |
|
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1338 |
"Modified (comment): / 28-02-2012 / 10:46:18 / cg" |
1188 | 1339 |
! |
1340 |
||
4378 | 1341 |
explainSelector:string inClass:aClassOrNil short:shortText |
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1342 |
"return an explanation or nil" |
1188 | 1343 |
|
3810 | 1344 |
|selector listOfImplementingClasses listOfImplementingClassNames listOfSimilarSelectors |
3203 | 1345 |
firstImplementingClassOfSimilar count tmp commonSuperClass s s2 |
4143 | 1346 |
firstImplementingClass |
3798 | 1347 |
firstImplementingClassName secondImplementingClassName thirdImplementingClassName |
1348 |
classProvidingComment |
|
1349 |
cm msg t check| |
|
1188 | 1350 |
|
3810 | 1351 |
selector := string asSymbolIfInterned. |
1352 |
selector isNil ifTrue:[^ nil]. |
|
1188 | 1353 |
|
4143 | 1354 |
"/ look who implements it |
3798 | 1355 |
listOfImplementingClassNames := Set new. |
3174 | 1356 |
listOfImplementingClasses := Set new. |
1357 |
listOfSimilarSelectors := Set new. |
|
2288
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1358 |
|
3203 | 1359 |
check := |
3233 | 1360 |
[:sel :mthd :cls | |
3810 | 1361 |
sel == selector ifTrue:[ |
3798 | 1362 |
listOfImplementingClasses add:cls. |
1363 |
listOfImplementingClassNames add:(cls name). |
|
3233 | 1364 |
firstImplementingClass isNil ifTrue:[ |
3798 | 1365 |
firstImplementingClass := cls. |
1366 |
firstImplementingClassName := cls name. |
|
3233 | 1367 |
] |
1368 |
] ifFalse:[ |
|
3810 | 1369 |
(sel startsWith:selector) ifTrue:[ |
3233 | 1370 |
listOfSimilarSelectors add:sel. |
1371 |
firstImplementingClassOfSimilar isNil ifTrue:[ |
|
1372 |
firstImplementingClassOfSimilar := cls |
|
1373 |
] |
|
1374 |
] |
|
1375 |
] |
|
1376 |
]. |
|
2288
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1377 |
|
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1378 |
Smalltalk allClassesDo:[:c| |
3233 | 1379 |
c methodDictionary keysAndValuesDo:[:sel :mthd | |
1380 |
check value:sel value:mthd value:c |
|
1381 |
]. |
|
1382 |
c class methodDictionary keysAndValuesDo:[:sel :mthd | |
|
1383 |
check value:sel value:mthd value:c class |
|
1384 |
]. |
|
141 | 1385 |
]. |
1386 |
||
4378 | 1387 |
(aClassOrNil notNil and:[aClassOrNil canUnderstand:selector]) ifTrue:[ |
1388 |
s2 := ('Instances of ''' , aClassOrNil name , ''' respond to #') , selector "allBold" , '.'. |
|
3233 | 1389 |
shortText ifFalse:[ |
1390 |
s2 := '\\' , s2 |
|
1391 |
, '\- inherited from ' withCRs |
|
4378 | 1392 |
, (aClassOrNil whichClassIncludesSelector:selector) name "allBold". |
3233 | 1393 |
]. |
4378 | 1394 |
firstImplementingClass := (aClassOrNil whichClassIncludesSelector:selector) |
835 | 1395 |
] ifFalse:[ |
3233 | 1396 |
s2 := ''. |
835 | 1397 |
]. |
1398 |
||
3798 | 1399 |
count := listOfImplementingClassNames size. |
141 | 1400 |
(count ~~ 0) ifTrue:[ |
3233 | 1401 |
" |
1402 |
for up-to 4 implementing classes, |
|
1403 |
list them |
|
1404 |
" |
|
3798 | 1405 |
listOfImplementingClassNames := listOfImplementingClassNames asOrderedCollection sort. |
3233 | 1406 |
shortText ifTrue:[ |
1407 |
tmp := ' is implemented in '. |
|
1408 |
] ifFalse:[ |
|
1409 |
tmp := ' is a selector implemented in '. |
|
1410 |
]. |
|
3881 | 1411 |
"/ s := string allBold. |
3855 | 1412 |
count > 1 ifTrue:[ |
3881 | 1413 |
s := self asLink:selector to:(self actionToOpenMethodFinderFor:selector). |
4143 | 1414 |
] ifFalse:[ |
3885 | 1415 |
s := self asLink:selector to:(self actionToBrowseClass:listOfImplementingClasses first selector:selector). |
3842 | 1416 |
]. |
4143 | 1417 |
|
3810 | 1418 |
shortText ifTrue:[ |
1419 |
|typesDescription| |
|
4143 | 1420 |
|
3810 | 1421 |
msg := s , tmp. |
3842 | 1422 |
typesDescription := self typeDescriptionFor:listOfImplementingClasses andSelector:selector wordBetween:'and'. |
3810 | 1423 |
typesDescription notNil ifTrue:[ |
3842 | 1424 |
msg := msg,typesDescription |
3233 | 1425 |
]. |
1426 |
] ifFalse:[ |
|
3810 | 1427 |
(count == 1) ifTrue:[ |
1428 |
t := firstImplementingClassName. |
|
1429 |
firstImplementingClass isMeta ifTrue:[ |
|
1430 |
t := 'the ' , t |
|
1431 |
]. |
|
1432 |
msg := s , tmp , t , '.'. |
|
3233 | 1433 |
shortText ifFalse:[ |
1434 |
msg := msg , s2. |
|
3810 | 1435 |
] |
3233 | 1436 |
] ifFalse:[ |
3810 | 1437 |
firstImplementingClassName := listOfImplementingClassNames at:1. |
1438 |
secondImplementingClassName := listOfImplementingClassNames at:2. |
|
1439 |
(count == 2) ifTrue:[ |
|
1440 |
msg := s,tmp,firstImplementingClassName,' and ',secondImplementingClassName,'.'. |
|
3233 | 1441 |
shortText ifFalse:[ |
1442 |
msg := msg , s2. |
|
1443 |
]. |
|
1444 |
] ifFalse:[ |
|
3810 | 1445 |
thirdImplementingClassName := listOfImplementingClassNames at:3. |
1446 |
(count == 3) ifTrue:[ |
|
1447 |
msg := s,tmp,firstImplementingClassName,',',secondImplementingClassName,' and ',thirdImplementingClassName,'.'. |
|
1448 |
shortText ifFalse:[ |
|
1449 |
msg := msg , s2. |
|
1450 |
]. |
|
1451 |
] ifFalse:[ |
|
1452 |
false "shortText" ifTrue:[ |
|
1453 |
msg := s , tmp , count printString , ' classes'. |
|
1454 |
commonSuperClass := Class commonSuperclassOf:listOfImplementingClassNames. |
|
1455 |
commonSuperClass notNil ifTrue:[ |
|
1456 |
(commonSuperClass == Object |
|
1457 |
and:[commonSuperClass includesSelector:selector]) ifTrue:[ |
|
1458 |
msg := msg , ' (including ' , 'Object' "allBold", ')' |
|
1459 |
] ifFalse:[ |
|
1460 |
(commonSuperClass ~= Object) ifTrue:[ |
|
1461 |
msg := msg , ' (under ' , commonSuperClass name, ')' |
|
1462 |
] |
|
1463 |
]. |
|
3492 | 1464 |
]. |
3810 | 1465 |
msg := msg , '.'. |
1466 |
^ msg |
|
3233 | 1467 |
]. |
1183 | 1468 |
|
3810 | 1469 |
" |
1470 |
if there are more, look for a common |
|
1471 |
superclass and show it ... |
|
1472 |
" |
|
1473 |
commonSuperClass := (Behavior commonSuperclassOf:listOfImplementingClasses) ? Object. |
|
1474 |
(commonSuperClass ~~ Object |
|
1475 |
and:[commonSuperClass ~~ Behavior |
|
1476 |
and:[commonSuperClass ~~ Class |
|
1477 |
and:[commonSuperClass ~~ ClassDescription]]]) ifTrue:[ |
|
1478 |
(listOfImplementingClasses includes:commonSuperClass) ifTrue:[ |
|
1479 |
msg := s . tmp , count printString , commonSuperClass name |
|
1480 |
, ' and redefined in ' , (count - 1) printString |
|
1481 |
, ' subclasses' |
|
1482 |
, s2. |
|
1483 |
firstImplementingClass := commonSuperClass |
|
1484 |
] ifFalse:[ |
|
1485 |
msg := s , tmp, count printString , ' subclasses of ' , commonSuperClass name , s2 |
|
1486 |
] |
|
3233 | 1487 |
] ifFalse:[ |
3810 | 1488 |
(commonSuperClass == Object |
1489 |
and:[commonSuperClass includesSelector:selector]) ifTrue:[ |
|
1490 |
shortText ifTrue:[ |
|
1491 |
msg := s , tmp , count printString , ' classes (incl. Object)'. |
|
1492 |
] ifFalse:[ |
|
1493 |
msg := s , tmp , count printString , ' classes. |
|
4143 | 1494 |
|
3203 | 1495 |
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
|
1496 |
since there is an implementation in Object.' , s2. |
3810 | 1497 |
]. |
1498 |
firstImplementingClass := Object |
|
1499 |
] ifFalse:[ |
|
1500 |
((commonSuperClass == Behavior |
|
1501 |
or:[commonSuperClass == Class |
|
1502 |
or:[commonSuperClass == ClassDescription]]) |
|
1503 |
and:[commonSuperClass includesSelector:selector]) ifTrue:[ |
|
1504 |
shortText ifTrue:[ |
|
1505 |
msg := s , tmp , count printString , ' classes (incl. all classes)'. |
|
1506 |
] ifFalse:[ |
|
1507 |
msg := s , tmp , count printString , ' classes. |
|
913 | 1508 |
|
3203 | 1509 |
All classes seem to respond to that message, |
913 | 1510 |
since there is an implementation in ' , commonSuperClass name , '.' , s2. |
3810 | 1511 |
]. |
1512 |
firstImplementingClass := commonSuperClass |
|
1513 |
] ifFalse:[ |
|
1514 |
" |
|
1515 |
otherwise just give the number. |
|
1516 |
" |
|
1517 |
msg := s , tmp , count printString , ' classes.' , s2 |
|
1518 |
] |
|
3233 | 1519 |
] |
1520 |
] |
|
1521 |
] |
|
3810 | 1522 |
]. |
3233 | 1523 |
]. |
1524 |
]. |
|
3798 | 1525 |
"/ look for a comment... |
1526 |
count == 1 ifTrue:[ |
|
1527 |
classProvidingComment := firstImplementingClass. |
|
3233 | 1528 |
] ifFalse:[ |
3798 | 1529 |
commonSuperClass isNil ifTrue:[ |
1530 |
commonSuperClass := Behavior commonSuperclassOf:listOfImplementingClasses. |
|
1531 |
] . |
|
4100 | 1532 |
|
4143 | 1533 |
((listOfImplementingClasses includes:commonSuperClass) |
4100 | 1534 |
and:[ (commonSuperClass implements:selector) ] |
1535 |
) ifTrue:[ |
|
1536 |
classProvidingComment := commonSuperClass |
|
1537 |
] ifFalse:[ |
|
4143 | 1538 |
"/ avoid some obvious misleading paths... |
1539 |
classProvidingComment := { Number . Collection . Stream . View } |
|
4100 | 1540 |
detect:[:cls | (listOfImplementingClasses includes:cls) |
1541 |
or:[cls canUnderstand:selector] ] |
|
1542 |
ifNone:nil. |
|
1543 |
classProvidingComment notNil ifTrue:[ |
|
1544 |
classProvidingComment := classProvidingComment whichClassImplements:selector. |
|
4143 | 1545 |
] ifFalse:[ |
3810 | 1546 |
classProvidingComment := firstImplementingClass. |
4143 | 1547 |
[ |
4100 | 1548 |
classProvidingComment superclass notNil |
1549 |
and:[ classProvidingComment superclass implements:selector ] |
|
1550 |
] whileTrue:[ |
|
1551 |
classProvidingComment := classProvidingComment superclass |
|
1552 |
]. |
|
3810 | 1553 |
]. |
3798 | 1554 |
]. |
1555 |
]. |
|
1556 |
classProvidingComment notNil ifTrue:[ |
|
3885 | 1557 |
cm := self fetchDescriptionOfMethod:"fetchCommentOfMethod:"(classProvidingComment compiledMethodAt:selector). |
3798 | 1558 |
]. |
1559 |
cm isNil ifTrue:[ |
|
1560 |
"/ should: find the class with most subclasses from the list |
|
1561 |
(listOfImplementingClasses includes:Collection) ifTrue:[ |
|
1562 |
classProvidingComment := Collection |
|
1563 |
] ifFalse:[ |
|
1564 |
(listOfImplementingClasses includes:Stream) ifTrue:[ |
|
1565 |
classProvidingComment := Stream |
|
1566 |
] ifFalse:[ |
|
4143 | 1567 |
classProvidingComment := listOfImplementingClasses |
1568 |
detect:[:cls | |
|
3883 | 1569 |
|mthd| |
1570 |
(mthd := cls compiledMethodAt:selector) notNil |
|
3885 | 1571 |
and:[ (self fetchCommentOfMethod:mthd) notNil]] |
3883 | 1572 |
ifNone:nil. |
3798 | 1573 |
] |
1574 |
]. |
|
3883 | 1575 |
cm isNil ifTrue:[ |
1576 |
classProvidingComment notNil ifTrue:[ |
|
3885 | 1577 |
cm := self fetchDescriptionOfMethod:(classProvidingComment compiledMethodAt:selector). |
3883 | 1578 |
] |
4143 | 1579 |
]. |
3798 | 1580 |
]. |
1581 |
cm notNil ifTrue:[ |
|
4273 | 1582 |
cm := ('%1 says:\' withCRs bindWith:(self asClassLink:classProvidingComment name)),cm. |
4143 | 1583 |
|
3883 | 1584 |
"/ msg := msg,(msg last isSeparator ifTrue:[''] ifFalse:[' ']),cm |
1585 |
msg := msg,(Character cr),cm |
|
3233 | 1586 |
]. |
1587 |
^ msg |
|
141 | 1588 |
]. |
1589 |
||
3881 | 1590 |
"/ none implements it (typo?); |
3174 | 1591 |
count := listOfSimilarSelectors size. |
2288
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1592 |
(count ~~ 0) ifTrue:[ |
3233 | 1593 |
listOfSimilarSelectors := listOfSimilarSelectors asOrderedCollection sort. |
2288
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1594 |
|
3233 | 1595 |
(count == 1) ifTrue:[ |
3881 | 1596 |
|sel selLink clsLink implementors| |
1597 |
||
1598 |
sel := listOfSimilarSelectors first. |
|
1599 |
selLink := self asLink:sel to:(self actionToOpenMethodFinderFor:sel). |
|
1600 |
"/ clsLink := self asLink:firstImplementingClassOfSimilar name to:(self actionToBrowseClass:firstImplementingClassOfSimilar selector:sel). |
|
1601 |
implementors := Smalltalk allImplementorsOf:sel. |
|
1602 |
clsLink := self typeDescriptionFor:implementors andSelector:sel. |
|
1603 |
msg := selLink , ' is implemented in ' , clsLink , '.'. |
|
3233 | 1604 |
shortText ifFalse:[ |
1605 |
msg := msg , s2. |
|
1606 |
] |
|
1607 |
] ifFalse:[ |
|
3881 | 1608 |
|sel1 sel2| |
1609 |
sel1 := listOfSimilarSelectors first. |
|
1610 |
sel2 := listOfSimilarSelectors second. |
|
4143 | 1611 |
msg := 'similar selectors: %1, %2' |
1612 |
bindWith:(self asLink:sel1 to:(self actionToOpenMethodFinderFor:sel1)) |
|
3881 | 1613 |
with:(self asLink:sel2 to:(self actionToOpenMethodFinderFor:sel1)). |
3233 | 1614 |
count > 2 ifTrue:[ |
1615 |
msg := msg,'...'. |
|
1616 |
]. |
|
1617 |
]. |
|
1618 |
^ msg |
|
2288
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1619 |
]. |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1620 |
|
141 | 1621 |
^ nil |
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
1622 |
|
1909 | 1623 |
"Modified: / 17-06-1996 / 17:09:30 / stefan" |
1624 |
"Created: / 23-03-1999 / 13:29:33 / cg" |
|
3804 | 1625 |
"Modified: / 01-05-2016 / 15:42:24 / cg" |
4143 | 1626 |
"Modified: / 22-05-2017 / 11:35:31 / mawalch" |
4378 | 1627 |
"Modified: / 04-03-2019 / 10:16:07 / Claus Gittinger" |
141 | 1628 |
! |
1629 |
||
4378 | 1630 |
explainSelfIn:aClassOrNil short:shortText |
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1631 |
"return an explanation" |
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1632 |
|
3883 | 1633 |
|subClasses subNames selfString className nSubClasses |
1634 |
classLink classLink2 subclassesLink| |
|
1198 | 1635 |
|
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
1636 |
selfString := '''' , 'self' "allBold" , ''''. |
6 | 1637 |
|
4378 | 1638 |
aClassOrNil isNil ifTrue:[ |
1639 |
^ selfString , 'refers to the object which received the message.' |
|
1640 |
]. |
|
1641 |
||
1642 |
subClasses := aClassOrNil allSubclasses. |
|
3883 | 1643 |
nSubClasses := subClasses size. |
1244 | 1644 |
|
4378 | 1645 |
aClassOrNil isMeta ifTrue:[ |
1646 |
className := aClassOrNil theNonMetaclass name. |
|
3883 | 1647 |
subNames := subClasses collect:[:c | c theNonMetaclass name]. |
1648 |
shortText ifTrue:[ |
|
1649 |
classLink := (self asClassLink:className). |
|
1650 |
nSubClasses == 0 ifTrue:[ |
|
1651 |
^ selfString , (' - the %1 class.' bindWith:classLink) |
|
1652 |
]. |
|
1653 |
nSubClasses == 1 ifTrue:[ |
|
1654 |
classLink2 := self asClassLink:subNames first. |
|
1655 |
^ selfString , (' - the %1- or %2 class.' bindWith:classLink with:classLink2) |
|
1656 |
]. |
|
1657 |
subclassesLink := self |
|
1658 |
asLink:('%1 subclasses' bindWith:nSubClasses) |
|
1659 |
info:('Click to browse subclasses') |
|
1660 |
to:(self actionToBrowseClasses:subClasses). |
|
1661 |
||
1662 |
^ selfString , (' - the %1 class or one of its %2.' bindWith:classLink with:subclassesLink) |
|
1663 |
]. |
|
1664 |
||
3810 | 1665 |
nSubClasses == 0 ifTrue:[ |
1666 |
^ selfString , 'refers to the object which received the message. |
|
1244 | 1667 |
|
1668 |
In this case, it will be the ' , className , '-class itself.' |
|
3810 | 1669 |
]. |
1244 | 1670 |
|
3810 | 1671 |
nSubClasses <= 5 ifTrue:[ |
1672 |
^ selfString , ' refers to the object which received the message. |
|
1244 | 1673 |
|
1674 |
In this case, it will be the ' , className , '-class |
|
1675 |
or one of its subclasses: |
|
1676 |
||
1677 |
' , subNames asStringCollection asString |
|
3810 | 1678 |
]. |
1244 | 1679 |
|
3810 | 1680 |
^ selfString , ' refers to the object which received the message. |
1244 | 1681 |
|
1682 |
In this case, it will be the ' , className , '-class |
|
1683 |
or one of its ' , nSubClasses printString , ' subclasses.' |
|
1684 |
]. |
|
1685 |
||
4378 | 1686 |
subClasses := aClassOrNil allSubclasses. |
3883 | 1687 |
subNames := subClasses collect:[:c | c theNonMetaclass name]. |
4378 | 1688 |
className := aClassOrNil name. |
3883 | 1689 |
shortText ifTrue:[ |
1690 |
classLink := self asClassLink:className. |
|
1691 |
nSubClasses == 0 ifTrue:[ |
|
1692 |
^ selfString , (' - an instance of %1.' bindWith:classLink) |
|
1693 |
]. |
|
1694 |
nSubClasses == 1 ifTrue:[ |
|
1695 |
classLink2 := self asClassLink:subNames first. |
|
1696 |
^ selfString , (' - an instance of %1 or %2.' bindWith:classLink with:classLink2) |
|
1697 |
]. |
|
1698 |
subclassesLink := self |
|
1699 |
asLink:('%1 subclasses' bindWith:nSubClasses) |
|
1700 |
info:('Click to browse subclasses') |
|
1701 |
to:(self actionToBrowseClasses:subClasses). |
|
1702 |
^ selfString , (' - an instance of %1 or one of its %2.' bindWith:classLink with:subclassesLink) |
|
1703 |
]. |
|
1704 |
||
1244 | 1705 |
nSubClasses == 0 ifTrue:[ |
3810 | 1706 |
^ selfString , 'refers to the object which received the message. |
6 | 1707 |
|
1244 | 1708 |
In this case, it will be an instance of ' , className , '.' |
6 | 1709 |
]. |
1710 |
||
1244 | 1711 |
nSubClasses <= 5 ifTrue:[ |
3810 | 1712 |
^ selfString , ' refers to the object which received the message. |
6 | 1713 |
|
1244 | 1714 |
In this case, it will be an instance of ' , className , ' |
6 | 1715 |
or one of its subclasses: |
1716 |
||
1256 | 1717 |
' , subNames asStringCollection asString |
6 | 1718 |
]. |
1719 |
||
1198 | 1720 |
^ selfString , ' refers to the object which received the message. |
6 | 1721 |
|
1244 | 1722 |
In this case, it will be an instance of ' , className , ' |
1723 |
or one of its ' , nSubClasses printString , ' subclasses.' |
|
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
1724 |
|
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
1725 |
"Modified: / 09-10-2006 / 12:11:44 / cg" |
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1726 |
"Modified (comment): / 28-02-2012 / 10:47:06 / cg" |
6 | 1727 |
! |
1728 |
||
4378 | 1729 |
explainSuperIn:aClassOrNil short:shortText |
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1730 |
"return an explanation" |
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1731 |
|
1352 | 1732 |
|superName| |
1244 | 1733 |
|
4378 | 1734 |
aClassOrNil isNil ifTrue:[ |
1735 |
^ '"super" - message lookup starts in superclass (call redefined method).' |
|
1736 |
]. |
|
1737 |
||
1738 |
superName := aClassOrNil superclass name. |
|
1188 | 1739 |
|
1740 |
shortText ifTrue:[ |
|
3842 | 1741 |
^ '"super" - message lookup starts in superclass "%1" (call redefined method).' bindWith:(self asClassLink:superName) |
1188 | 1742 |
]. |
1743 |
||
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1744 |
^ 'like "self", "','super'allBold,'" refers to the object which received the message. |
6 | 1745 |
|
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1746 |
However, when sending a message to "super", the search for methods |
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1747 |
implementing this message will start in the superclass (' , superName , '), |
4378 | 1748 |
instead of the receiver''s class (' , aClassOrNil name , ' or subclass). |
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1749 |
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
|
1750 |
|
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1751 |
"Modified (comment): / 28-02-2012 / 10:47:03 / cg" |
4378 | 1752 |
"Modified: / 04-03-2019 / 10:17:44 / Claus Gittinger" |
6 | 1753 |
! |
2 | 1754 |
|
49 | 1755 |
explainSyntax:string |
1756 |
"try syntax ...; return explanation or nil" |
|
1757 |
||
1183 | 1758 |
^ self explainSyntax:string short:false |
1759 |
! |
|
1760 |
||
1761 |
explainSyntax:string short:shortText |
|
3842 | 1762 |
"try syntax ...; return explanation or nil. |
1763 |
This is meant for beginners..." |
|
1183 | 1764 |
|
3883 | 1765 |
|fullMsg stringWithoutSeparators| |
3881 | 1766 |
|
49 | 1767 |
((string = ':=') or:[string = '_']) ifTrue:[ |
3881 | 1768 |
fullMsg := '<variable> := <expression> |
49 | 1769 |
|
3233 | 1770 |
":=" and "_" (which is left-arrow in some fonts) mean assignment. |
3464 | 1771 |
The variable is bound to (i.e. points to) the value of <expression>. |
3881 | 1772 |
The "_" form is historic and should not be used with new code.'. |
1773 |
||
1774 |
shortText ifTrue:[ |
|
1775 |
string = '_' ifTrue:[ |
|
1776 |
^ (self |
|
1777 |
asLink:'"_"' |
|
1778 |
info:fullMsg |
|
1779 |
to:nil),' - old style for assignment. Consider changing to ":=".' |
|
1780 |
]. |
|
1781 |
^ (self |
|
1782 |
asLink:'":="' |
|
1783 |
info:fullMsg |
|
1784 |
to:nil),' - assign to variable on the left (syntax).' |
|
1785 |
]. |
|
1786 |
^ fullMsg |
|
49 | 1787 |
]. |
1788 |
||
1789 |
(string = '^') ifTrue:[ |
|
3233 | 1790 |
shortText ifTrue:[ |
3607 | 1791 |
^ '"^" - return value from method (syntax)'. |
3233 | 1792 |
]. |
1793 |
^ '^ <expression> |
|
49 | 1794 |
|
3319 | 1795 |
A return statement evaluates <expression> and returns its value from the method. |
1796 |
A return inside a block exits the method where the block is defined (not only the block).' |
|
49 | 1797 |
]. |
1798 |
||
1799 |
(string = ';') ifTrue:[ |
|
3233 | 1800 |
shortText ifTrue:[ |
3607 | 1801 |
^ '";" - a cascade expression (syntax)'. |
3233 | 1802 |
]. |
1803 |
^ '<expression> ; selector1 ; .... ; selectorN |
|
49 | 1804 |
|
3203 | 1805 |
a cascade expression; evaluate expression, and send messages |
1806 |
<selector1> ... <selectorN> to the first expression''s receiver. |
|
49 | 1807 |
Returns the value of the last send. The cascade sends may also have arguments.' |
1808 |
]. |
|
1809 |
||
1810 |
(string = '|') ifTrue:[ |
|
3233 | 1811 |
shortText ifTrue:[ |
3607 | 1812 |
^ '"|" - local variables (syntax)'. |
3233 | 1813 |
]. |
1814 |
^ '| locals | or: [:arg | statements] |
|
49 | 1815 |
|
3233 | 1816 |
"|" is used to mark a local variable declaration or separates arguments |
49 | 1817 |
from the statements in a block. Notice, that in a block-argument declaration |
3319 | 1818 |
these arg nams must be prefixed by a colon character. |
3233 | 1819 |
"|" is also a selector understood by Booleans.' |
49 | 1820 |
]. |
1821 |
||
3319 | 1822 |
(string startsWith:'$' ) ifTrue:[ |
1823 |
shortText ifTrue:[ |
|
3842 | 1824 |
^ '"$x" - ',(self asClassLink:'Character'),' literal (syntax)'. |
3319 | 1825 |
]. |
1826 |
^ 'is a Character literal constant. |
|
1827 |
||
1828 |
Character objects represent indivdual text cheracters in Unicode encoding. |
|
1829 |
For example, $a is the character "a" with an encoding of 97 "hex: 16r61". |
|
1830 |
Smalltalk/X supports unicode and uses this encoding internally for all characters |
|
1831 |
and strings. Notice, that not all Smalltalk implementations allow non-ascii (i.e. codes > 255).' |
|
1832 |
]. |
|
1833 |
||
2287
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1834 |
(string startsWith:'#' ) ifTrue:[ |
3233 | 1835 |
(string startsWith:'#(' ) ifTrue:[ |
1836 |
shortText ifTrue:[ |
|
3842 | 1837 |
^ '"#(..)" - ',(self asClassLink:'Array'),' literal (syntax)'. |
3233 | 1838 |
]. |
3607 | 1839 |
^ 'is a constant Array (literal). |
2287
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1840 |
|
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1841 |
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
|
1842 |
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
|
1843 |
The elements of a constant Array must be numbers, strings, symbols, nil, true or false, |
3194 | 1844 |
other array constants or byte-arrays. |
2287
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1845 |
(notice, that not all Smalltalk implementations allow true, false and nil as |
3194 | 1846 |
element in an Array-constant).' |
3233 | 1847 |
]. |
2287
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1848 |
|
3233 | 1849 |
(string startsWith:'#[') ifTrue:[ |
1850 |
shortText ifTrue:[ |
|
3842 | 1851 |
^ '"#[..]" - ',(self asClassLink:'ByteArray'),' literal (syntax)'. |
3233 | 1852 |
]. |
3607 | 1853 |
^ 'is a constant ByteArray (literal). |
2287
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1854 |
|
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1855 |
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
|
1856 |
0 .. 255. |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1857 |
(notice, that not all Smalltalk implementations support constant ByteArrays).' |
3233 | 1858 |
]. |
2287
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1859 |
|
3233 | 1860 |
(string startsWith:'#''') ifTrue:[ |
1861 |
shortText ifTrue:[ |
|
3842 | 1862 |
^ '"#''..''" - ',(self asClassLink:'Symbol'),' literal (syntax)'. |
3233 | 1863 |
]. |
1864 |
^ 'is a constant symbol containing non-alphanumeric characters. |
|
2287
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1865 |
|
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1866 |
Symbols are unique strings, meaning that there exists |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1867 |
exactly one instance of a given symbol. Therefore symbols can |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1868 |
be compared using == (identity compare) in addition to = (contents compare). |
3194 | 1869 |
Beside this, Symbols behave mostly like Strings but are immutable.' |
3233 | 1870 |
]. |
2287
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1871 |
|
3233 | 1872 |
shortText ifTrue:[ |
3842 | 1873 |
^ '"#.." - ',(self asClassLink:'Symbol'),' literal (syntax)'. |
3233 | 1874 |
]. |
3319 | 1875 |
^ 'is a constant symbol. |
2287
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1876 |
|
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1877 |
Symbols are unique strings, meaning that there exists |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1878 |
exactly one instance of a given symbol. Therefore symbols can |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1879 |
be compared using == (identity compare) in addition to = (contents compare). |
3194 | 1880 |
Beside this, Symbols behave mostly like Strings but are immutable.' |
2287
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1881 |
]. |
49 | 1882 |
((string startsWith:'(') or:[string endsWith:')']) ifTrue:[ |
3233 | 1883 |
shortText ifTrue:[ |
1884 |
^ ''. |
|
1885 |
]. |
|
1886 |
^ '( <expression> ) |
|
49 | 1887 |
|
3194 | 1888 |
expression grouping. Without them, expressions are evaluated left to right, |
1889 |
with unary messages preceeding binary messages, preceeding keyword mesages.' |
|
49 | 1890 |
]. |
1891 |
||
1892 |
((string startsWith:'[') or:[string endsWith:']']) ifTrue:[ |
|
3233 | 1893 |
shortText ifTrue:[ |
3842 | 1894 |
^ '"[..]" - a ',(self asClassLink:'Block'),' (aka lambda/closure for experts)'. |
3233 | 1895 |
]. |
1896 |
^ '[:arg1 .. :argN | statements] |
|
49 | 1897 |
|
3203 | 1898 |
defines a block. |
3194 | 1899 |
Blocks represent pieces of executable code. The definition of a block does |
4390 | 1900 |
not evaluate it, instead a reference to the block''s computation is created. |
3194 | 1901 |
The block can be evaluated later, by sending it a value/value: message |
1902 |
(it can be even evaluated multiple times). |
|
1903 |
Blocks are often passed as arguments to Booleans (i.e. "bool ifTrue:[...]"), |
|
1904 |
other blocks (i.e. "[...] whileTrue: [...]"]) or collections (i.e. "coll do:[...]"). |
|
1905 |
Blocks are also often used as callbacks from UI components or as exception handlers.' |
|
49 | 1906 |
]. |
1907 |
||
2286
cabf7db33a38
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2226
diff
changeset
|
1908 |
((string startsWith:'{') or:[string endsWith:'}']) ifTrue:[ |
3233 | 1909 |
shortText ifTrue:[ |
3842 | 1910 |
^ '"{..}" ',(self asClassLink:'Array'),' instantiation (syntax)'. |
3233 | 1911 |
]. |
1912 |
^ '{ <expr1>. .. <exprN> } |
|
2286
cabf7db33a38
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2226
diff
changeset
|
1913 |
|
3319 | 1914 |
This is syntactic sugar for "Array with:<expr1> .. with:<exprN>". |
1915 |
||
2286
cabf7db33a38
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2226
diff
changeset
|
1916 |
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
|
1917 |
The expressions are separated by a period statement separator. |
cabf7db33a38
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2226
diff
changeset
|
1918 |
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
|
1919 |
when executed (as opposed to an array literal, which is computed only once at |
3233 | 1920 |
compilation time) and which is shared. |
3319 | 1921 |
Notice that this construct is not supported by all Smalltalk dialects, so its use |
1922 |
makes your program somewhat dialect specific.' |
|
2286
cabf7db33a38
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2226
diff
changeset
|
1923 |
]. |
cabf7db33a38
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2226
diff
changeset
|
1924 |
|
49 | 1925 |
(string = ':') ifTrue:[ |
3233 | 1926 |
shortText ifTrue:[ |
1927 |
^ ''. |
|
1928 |
]. |
|
1929 |
^ 'colons have different meaning depending on context: |
|
49 | 1930 |
|
1931 |
1) they separate keyword-parts in symbols and keyword-messages as in: |
|
1932 |
||
1933 |
#at:put: a constant keyword symbol |
|
1934 |
||
1935 |
rec at:index put:value sends the #at:put: message to rec, |
|
3233 | 1936 |
passing index and value as arguments. |
49 | 1937 |
|
1938 |
2) within block-argument declarations as in: |
|
1939 |
||
1940 |
[:arg1 :arg2 | statements] |
|
834 | 1941 |
|
1942 |
3) within an identifier, they separate the nameSpace part from |
|
1943 |
the name part; as in: |
|
1944 |
||
1945 |
Smalltalk::Array - the Array class in the Smalltalk nameSpace. |
|
1946 |
Foo::Array - the Array class in the Foo nameSpace. |
|
49 | 1947 |
' |
1948 |
]. |
|
1949 |
||
1950 |
(string = '.') ifTrue:[ |
|
3233 | 1951 |
^ 'statement. "<- period here" |
49 | 1952 |
statement |
1953 |
||
1954 |
within a method or block, individual statements are separated by periods. |
|
1955 |
' |
|
1956 |
]. |
|
1957 |
||
3883 | 1958 |
stringWithoutSeparators := string withoutSeparators. |
1959 |
||
1960 |
(stringWithoutSeparators startsWith:'"') ifTrue:[ |
|
1961 |
(stringWithoutSeparators startsWith:'"/') ifTrue:[ |
|
3464 | 1962 |
shortText ifTrue:[ |
3607 | 1963 |
^ 'an end-of-line comment (syntax)'. |
3464 | 1964 |
]. |
1965 |
^ '"/ comment |
|
3193 | 1966 |
EOL (end-of-line) comment |
1967 |
||
1968 |
anything up to the end of line is a comment and ignored (but not inside a string). |
|
3233 | 1969 |
Notice that EOL-comments are only supported by Smalltalk/X (i.e. non-portable). |
3193 | 1970 |
' |
3464 | 1971 |
]. |
3883 | 1972 |
(stringWithoutSeparators startsWith:'"<<') ifTrue:[ |
3464 | 1973 |
shortText ifTrue:[ |
4175 | 1974 |
^ 'a token delimited comment; up to line starting with the token after ''<<''.'. |
3464 | 1975 |
]. |
1976 |
^ '"<<TOKEN |
|
1977 |
... |
|
1978 |
TOKEN |
|
1979 |
||
1980 |
Token delimited comment |
|
1981 |
||
4175 | 1982 |
anything up to a line which starts with the token is a comment and ignored (but not inside a string). |
3464 | 1983 |
Notice that Token-comments are only supported by Smalltalk/X (i.e. non-portable). |
1984 |
' |
|
1985 |
]. |
|
1986 |
||
3233 | 1987 |
shortText ifTrue:[ |
3607 | 1988 |
^ 'a comment (syntax)'. |
3233 | 1989 |
]. |
1990 |
^ '" comment ... " |
|
3193 | 1991 |
comment |
1992 |
||
1993 |
anything between double quotes is a comment and ignored (but not inside a string). |
|
1994 |
' |
|
1995 |
]. |
|
1996 |
||
49 | 1997 |
"/ is it a symbol without hash-character ? |
1998 |
"/ |
|
796 | 1999 |
"/ string knownAsSymbol ifTrue:[ |
2000 |
"/ ^ 'is nothing, but #' , string , ' is known as a symbol. |
|
2001 |
"/ |
|
2002 |
"/Symbols are unique strings, meaning that there exists |
|
2003 |
"/exactly one instance of a given symbol. Therefore symbols can |
|
2004 |
"/be compared using == (identity compare) in addition to = (contents compare). |
|
2005 |
"/Beside this, Symbols behave mostly like Strings.' |
|
2006 |
"/ ]. |
|
49 | 2007 |
|
3883 | 2008 |
((stringWithoutSeparators startsWith:'<') and:[stringWithoutSeparators endsWith:'>']) ifTrue:[ |
2009 |
shortText ifTrue:[ |
|
2010 |
(stringWithoutSeparators includesString:'resource:') ifTrue:[ |
|
2011 |
^ 'a ',(self |
|
2012 |
asLink:'resource annotation' |
|
2013 |
info:fullMsg |
|
2014 |
to:(self actionToBrowseClass:Annotation)),' (syntax)' |
|
2015 |
]. |
|
2016 |
^ 'an ',(self |
|
2017 |
asLink:'annotation / pragma' |
|
2018 |
info:fullMsg |
|
2019 |
to:(self actionToBrowseClass:Annotation)),' (syntax)' |
|
2020 |
]. |
|
2021 |
]. |
|
2022 |
||
49 | 2023 |
^ nil |
796 | 2024 |
|
4175 | 2025 |
"Modified: / 28-07-2017 / 10:32:11 / cg" |
4390 | 2026 |
"Modified: / 13-03-2019 / 10:25:48 / Claus Gittinger" |
2214 | 2027 |
! |
2028 |
||
4435 | 2029 |
safeValueStringFor:aValue |
2030 |
Error handle:[:ex | |
|
2031 |
^ 'Error in storeString: ',ex description |
|
2032 |
] do:[ |
|
2033 |
^ self valueStringFor:aValue |
|
2034 |
] |
|
2035 |
||
2036 |
"Created: / 08-06-2019 / 14:03:38 / Claus Gittinger" |
|
2037 |
! |
|
2038 |
||
3810 | 2039 |
typeDescriptionFor:setOfTypes andSelector:selectorOrNil |
2040 |
"up to 3 types are shown by name; more are simply counted" |
|
2041 |
||
3842 | 2042 |
^ self typeDescriptionFor:setOfTypes andSelector:selectorOrNil wordBetween:'or' |
2043 |
! |
|
2044 |
||
2045 |
typeDescriptionFor:setOfTypes andSelector:selectorOrNil wordBetween:wordbetween |
|
2046 |
"up to 3 types are shown by name; more are simply counted" |
|
2047 |
||
3810 | 2048 |
|types numTypes |
2049 |
type1 type2 type3 |
|
4206 | 2050 |
nm1 nm2 nm3 link stringForType| |
2051 |
||
2052 |
stringForType := |
|
2053 |
[:class | |
|
2054 |
class == UndefinedObject ifTrue:['nil'] |
|
2055 |
ifFalse:[ class == True ifTrue:['true'] |
|
2056 |
ifFalse:[ class == False ifTrue:['false'] |
|
2057 |
ifFalse:[ class == VoidObject ifTrue:['Void'] |
|
2058 |
ifFalse:[ class name ]]]] |
|
2059 |
]. |
|
2060 |
||
3810 | 2061 |
"/ reduce... |
2062 |
self compressSetOfTypes:setOfTypes. |
|
2063 |
setOfTypes isEmpty ifTrue:[^ nil]. |
|
2064 |
||
2065 |
types := setOfTypes asOrderedCollection. |
|
2066 |
types sortBySelector:#name. |
|
2067 |
||
2068 |
"/ now make this a nice string |
|
2069 |
numTypes := types size. |
|
2070 |
type1 := types first. |
|
4206 | 2071 |
|
2072 |
nm1 := self asLink:(stringForType value:type1) to:(self actionToBrowseClass:type1 selector:selectorOrNil). |
|
3810 | 2073 |
numTypes == 1 ifTrue:[ |
2074 |
^ nm1 |
|
2075 |
]. |
|
3842 | 2076 |
|
3810 | 2077 |
type2 := types second. |
4206 | 2078 |
nm2 := self asLink:(stringForType value:type2) to:(self actionToBrowseClass:type2 selector:selectorOrNil). |
3810 | 2079 |
numTypes == 2 ifTrue:[ |
3842 | 2080 |
^ nm1,' ',wordbetween,' ',nm2 |
3810 | 2081 |
]. |
2082 |
type3 := types third. |
|
4206 | 2083 |
nm3 := self asLink:(stringForType value:type3) to:(self actionToBrowseClass:type3 selector:selectorOrNil). |
3810 | 2084 |
numTypes == 3 ifTrue:[ |
3842 | 2085 |
^ nm1,', ',nm2,' ',wordbetween,' ',nm3 |
3810 | 2086 |
]. |
3855 | 2087 |
link := self actionToBrowseClasses:types. |
2088 |
"/ selectorOrNil notNil ifTrue:[ |
|
2089 |
"/ link := self actionToOpenMethodFinderFor:selectorOrNil. |
|
2090 |
"/ ]. |
|
3859 | 2091 |
^ self asLink:('%1 classes' bindWith:numTypes) to:link. |
4206 | 2092 |
|
2093 |
"Modified (format): / 11-11-2017 / 12:30:09 / cg" |
|
3810 | 2094 |
! |
2095 |
||
2214 | 2096 |
valueStringFor:aValue |
2097 |
|valString| |
|
2098 |
||
4287 | 2099 |
aValue isProtoObject ifTrue:[ |
2100 |
^ aValue printString |
|
2101 |
]. |
|
2102 |
||
2214 | 2103 |
"/ only show the value, if it is really short... |
3203 | 2104 |
(aValue isBoolean |
3708 | 2105 |
or:[aValue isNil |
2106 |
or:[aValue isString |
|
2107 |
or:[aValue isNumber |
|
2108 |
or:[aValue isPoint |
|
2109 |
or:[aValue isCharacter |
|
2110 |
]]]]]) ifTrue:[ |
|
4435 | 2111 |
^ aValue storeString. |
2226 | 2112 |
]. |
2427 | 2113 |
|
2226 | 2114 |
(aValue isColor) ifTrue:[ |
3708 | 2115 |
^ 'Color: ',(' ' emphasizeAllWith:(#backgroundColor->aValue)). |
2226 | 2116 |
]. |
2117 |
||
3203 | 2118 |
((aValue isKindOf:GUID) |
2119 |
or:[aValue isUUID]) ifTrue:[ |
|
3708 | 2120 |
valString := aValue printString. |
2427 | 2121 |
]. |
2122 |
||
3203 | 2123 |
(valString isEmptyOrNil |
2899
8b8701a65441
Avoid #isKindOf: where possible
Stefan Vogel <sv@exept.de>
parents:
2828
diff
changeset
|
2124 |
or:[ valString size > 50 |
8b8701a65441
Avoid #isKindOf: where possible
Stefan Vogel <sv@exept.de>
parents:
2828
diff
changeset
|
2125 |
or:[ valString includes:Character cr ]]) ifTrue:[ |
3708 | 2126 |
valString := aValue classNameWithArticle. |
2214 | 2127 |
]. |
2128 |
||
2129 |
^ valString |
|
2427 | 2130 |
|
2131 |
"Modified: / 14-10-2010 / 11:57:52 / cg" |
|
4435 | 2132 |
"Modified: / 08-06-2019 / 14:02:57 / Claus Gittinger" |
141 | 2133 |
! ! |
49 | 2134 |
|
3798 | 2135 |
!Explainer class methodsFor:'naive type inferer'! |
2136 |
||
2137 |
addTypeOfExpressionNode:expr forAssignmentTo:varName to:setOfTypes |
|
3842 | 2138 |
"pick up low hanging type information. |
2139 |
This is far from being complete, but often gives a hint good enough for code completion |
|
2140 |
and info in the browser." |
|
2141 |
||
2142 |
|val valClass| |
|
3798 | 2143 |
|
2144 |
"/ only look for wellknown types on the right side. |
|
3810 | 2145 |
expr isLiteral ifTrue:[ |
2146 |
val := expr value. |
|
3801 | 2147 |
valClass := val class. |
3798 | 2148 |
val isImmutable ifTrue:[ |
3801 | 2149 |
valClass := [ valClass mutableClass ] on:Error do:[ valClass ]. |
3798 | 2150 |
]. |
2151 |
self rememberType:valClass in:setOfTypes. |
|
3826 | 2152 |
^ setOfTypes. |
3798 | 2153 |
]. |
2154 |
||
2155 |
expr isMessage ifTrue:[ |
|
3842 | 2156 |
self addTypeOfMessageNode:expr forAssignmentTo:varName to:setOfTypes. |
2157 |
^ setOfTypes. |
|
3798 | 2158 |
]. |
3855 | 2159 |
|
3826 | 2160 |
^ setOfTypes |
2161 |
||
3798 | 2162 |
"Created: / 30-04-2016 / 15:28:59 / cg" |
3801 | 2163 |
"Modified: / 30-04-2016 / 20:17:35 / cg" |
3798 | 2164 |
! |
2165 |
||
3842 | 2166 |
addTypeOfMessageNode:expr forAssignmentTo:varName to:setOfTypes |
2167 |
"pick up low hanging type information. |
|
2168 |
This is far from being complete, but often gives a hint good enough for code completion |
|
2169 |
and info in the browser." |
|
2170 |
||
2171 |
|valClass msgSelector msgReceiver| |
|
2172 |
||
2173 |
msgSelector := expr selector. |
|
2174 |
msgReceiver := expr receiver. |
|
2175 |
||
2176 |
msgSelector == #? ifTrue:[ |
|
2177 |
self addTypeOfExpressionNode:(expr arg1) forAssignmentTo:varName to:setOfTypes. |
|
2178 |
^ setOfTypes |
|
2179 |
]. |
|
2180 |
||
2181 |
"/ really really only very low hanging fruit... |
|
2182 |
"/ ignore #/ here, because of filename |
|
2183 |
( #(+ - *) includes:msgSelector ) ifTrue:[ |
|
3885 | 2184 |
true "(msgReceiver isLiteralNumber or:[expr arg1 isLiteralNumber])" ifTrue:[ |
2185 |
self rememberType:Number in:setOfTypes. |
|
2186 |
^ setOfTypes. |
|
2187 |
]. |
|
2188 |
"/ "/ ignore foo := foo OP expr |
|
2189 |
"/ "/ ignore foo := expr OP foo |
|
2190 |
"/ (msgReceiver isVariable and:[msgReceiver name = varName]) ifFalse:[ |
|
2191 |
"/ (expr arg1 isVariable and:[expr arg1 name = varName]) ifFalse:[ |
|
2192 |
"/ self rememberType:Number in:setOfTypes. |
|
2193 |
"/ ] |
|
2194 |
"/ ]. |
|
3842 | 2195 |
^ setOfTypes. |
2196 |
]. |
|
2197 |
||
2198 |
( #(// size hash identityHash) includes:msgSelector ) ifTrue:[ |
|
2199 |
self rememberType:Integer in:setOfTypes. |
|
2200 |
^ setOfTypes. |
|
2201 |
]. |
|
2202 |
||
2203 |
( #(next next:) includes:msgSelector ) ifTrue:[ |
|
2204 |
|rcvrTypes| |
|
2205 |
||
2206 |
rcvrTypes := self addTypeOfExpressionNode:msgReceiver forAssignmentTo:nil to:Set new. |
|
2207 |
rcvrTypes notEmpty ifTrue:[ |
|
3885 | 2208 |
self breakPoint:#cg. |
3842 | 2209 |
self rememberType:Character in:setOfTypes. |
2210 |
]. |
|
2211 |
^ setOfTypes. |
|
2212 |
]. |
|
2213 |
||
2214 |
( msgSelector startsWith:'as') ifTrue:[ |
|
2215 |
valClass := Smalltalk classNamed:(msgSelector copyFrom:3). |
|
2216 |
valClass notNil ifTrue:[ |
|
2217 |
self rememberType:valClass in:setOfTypes. |
|
2218 |
^ setOfTypes. |
|
2219 |
]. |
|
2220 |
]. |
|
2221 |
||
2222 |
( #(copy shallowCopy) includes:msgSelector ) ifTrue:[ |
|
2223 |
msgReceiver isLiteral ifTrue:[ |
|
2224 |
self addTypeOfExpressionNode:msgReceiver forAssignmentTo:varName to:setOfTypes. |
|
2225 |
]. |
|
2226 |
^ setOfTypes |
|
2227 |
]. |
|
2228 |
||
2229 |
msgReceiver isGlobal ifTrue:[ |
|
3853 | 2230 |
|instCreatorMessages globalValue implMethod| |
3842 | 2231 |
|
3853 | 2232 |
instCreatorMessages := #(new new: basicNew basicNew:). |
2233 |
||
3842 | 2234 |
globalValue := msgReceiver value. |
2235 |
globalValue isBehavior ifTrue:[ |
|
3853 | 2236 |
( instCreatorMessages includes:msgSelector ) ifTrue:[ |
3842 | 2237 |
self rememberType:globalValue in:setOfTypes. |
2238 |
^ setOfTypes. |
|
2239 |
]. |
|
3853 | 2240 |
implMethod := globalValue class lookupMethodFor:msgSelector. |
2241 |
"/ mhmh - fuzzy; if the implementing message sends any of the above to itself... |
|
2242 |
"/ assume it is returning it. |
|
2243 |
implMethod isNil ifTrue:[ |
|
2244 |
"/ will not be understood |
|
3857 | 2245 |
self breakPoint:#cg. |
3853 | 2246 |
^ setOfTypes. |
2247 |
]. |
|
2248 |
(implMethod messagesSentToSelf includesAny:instCreatorMessages) ifTrue:[ |
|
3857 | 2249 |
self breakPoint:#cg. |
3853 | 2250 |
self rememberType:globalValue in:setOfTypes. |
2251 |
^ setOfTypes. |
|
2252 |
]. |
|
2253 |
"/ very fuzzy - if the implementing method is in the "instance creation" category... |
|
2254 |
((implMethod category ? '') startsWith:'instance creation') ifTrue:[ |
|
3857 | 2255 |
self breakPoint:#cg. |
3853 | 2256 |
self rememberType:globalValue in:setOfTypes. |
2257 |
^ setOfTypes. |
|
2258 |
]. |
|
3842 | 2259 |
]. |
4197 | 2260 |
"/ self breakPoint:#cg. |
3842 | 2261 |
^ setOfTypes |
2262 |
]. |
|
2263 |
||
4197 | 2264 |
"/ self breakPoint:#cg. |
3842 | 2265 |
^ setOfTypes |
4197 | 2266 |
|
2267 |
"Modified: / 10-10-2017 / 16:57:09 / cg" |
|
3842 | 2268 |
! |
2269 |
||
3798 | 2270 |
addTypesAssignedToInstvar:instVarName inClass:aClass method:aMethod to:setOfTypes |
2271 |
"look to asssignments to an instance variable, and pick up low hanging class information. |
|
3842 | 2272 |
This is far from being complete, but often gives a hint good enough for code completion |
3798 | 2273 |
and info in the browser." |
2274 |
||
2275 |
| code | |
|
2276 |
||
3902 | 2277 |
SourceCodeManagerError handle:[:ex | |
2278 |
] do:[ |
|
2279 |
code := aMethod source. |
|
2280 |
]. |
|
3798 | 2281 |
(code notNil) ifTrue:[ |
2282 |
self addTypesAssignedToInstvar:instVarName inClass:aClass source:code to:setOfTypes |
|
2283 |
] |
|
2284 |
||
2285 |
"Created: / 30-04-2016 / 15:07:33 / cg" |
|
2286 |
! |
|
2287 |
||
2288 |
addTypesAssignedToInstvar:instVarName inClass:aClass source:code to:setOfTypes |
|
2289 |
"look to asssignments to an instance variable, and pick up low hanging class information. |
|
3842 | 2290 |
This is far from being complete, but often gives a hint good enough for code completion |
3798 | 2291 |
and info in the browser." |
2292 |
||
3810 | 2293 |
|tree| |
3798 | 2294 |
|
2295 |
"/ quick check (avoids expensive parse) |
|
2296 |
(code includesString:instVarName) ifFalse:[ ^ self ]. |
|
2297 |
||
2298 |
tree := Parser parse:code class:aClass. |
|
2299 |
(tree isNil or:[tree == #Error]) ifTrue:[ ^ self ]. "/ unparsable |
|
2300 |
||
3810 | 2301 |
self addTypesAssignedToInstvar:instVarName inTree:tree to:setOfTypes. |
2302 |
||
2303 |
"Created: / 30-04-2016 / 15:09:18 / cg" |
|
2304 |
! |
|
2305 |
||
2306 |
addTypesAssignedToInstvar:instVarName inClass:aClass to:setOfTypes |
|
2307 |
"look to asssignments to an instance variable, and pick up low hanging class information. |
|
3842 | 2308 |
This is far from being complete, but often gives a hint good enough for code completion |
3810 | 2309 |
and info in the browser." |
2310 |
||
2311 |
aClass methodDictionary do:[:m | |
|
2312 |
self addTypesAssignedToInstvar:instVarName inClass:aClass method:m to:setOfTypes |
|
2313 |
]. |
|
2314 |
||
2315 |
"Created: / 30-04-2016 / 14:52:56 / cg" |
|
2316 |
! |
|
2317 |
||
2318 |
addTypesAssignedToInstvar:instVarName inTree:tree to:setOfTypes |
|
2319 |
"look to asssignments to an instance variable, and pick up low hanging class information. |
|
3842 | 2320 |
This is far from being complete, but often gives a hint good enough for code completion |
3810 | 2321 |
and info in the browser." |
2322 |
||
2323 |
|visitor| |
|
2324 |
||
3798 | 2325 |
visitor := PluggableParseNodeVisitor new. |
2326 |
visitor |
|
2327 |
actionForNodeClass:AssignmentNode |
|
2328 |
put:[:node | |
|
3853 | 2329 |
(node variable isInstanceVariableNamed:instVarName) ifTrue:[ |
2330 |
self addTypeOfExpressionNode:(node expression) forAssignmentTo:instVarName to:setOfTypes |
|
3798 | 2331 |
]. |
2332 |
true "/ yes - visit subnodes |
|
2333 |
]. |
|
2334 |
visitor visit:tree. |
|
2335 |
! |
|
2336 |
||
3810 | 2337 |
addTypesAssignedToLocal:localName inTree:tree to:setOfTypes |
3842 | 2338 |
"look to asssignments to a local variable, and pick up low hanging class information. |
2339 |
This is far from being complete, but often gives a hint good enough for code completion |
|
3798 | 2340 |
and info in the browser." |
2341 |
||
3810 | 2342 |
|visitor| |
2343 |
||
2344 |
"/ hack, allowing to deal with both types of AST (sigh) |
|
2345 |
(tree isKindOf:RBProgramNode) ifTrue:[ |
|
2346 |
visitor := RBPluggableProgramNodeVisitor new. |
|
2347 |
visitor |
|
2348 |
actionForNodeClass:RBAssignmentNode |
|
2349 |
put:[:node | |
|
3853 | 2350 |
|leftSide| |
3798 | 2351 |
|
3810 | 2352 |
leftSide := node variable. |
2353 |
(leftSide isTemporary and:[ leftSide name = localName ]) ifTrue:[ |
|
3853 | 2354 |
self addTypeOfExpressionNode:(node value) forAssignmentTo:localName to:setOfTypes |
3810 | 2355 |
]. |
2356 |
true "/ yes - visit subnodes |
|
2357 |
]. |
|
2358 |
visitor visitNode:tree. |
|
2359 |
] ifFalse:[ |
|
2360 |
visitor := PluggableParseNodeVisitor new. |
|
2361 |
visitor |
|
2362 |
actionForNodeClass:AssignmentNode |
|
2363 |
put:[:node | |
|
2364 |
|leftSide expr| |
|
2365 |
||
2366 |
leftSide := node variable. |
|
2367 |
(leftSide isLocalVariable and:[ leftSide name = localName ]) ifTrue:[ |
|
2368 |
expr := node expression. |
|
2369 |
self addTypeOfExpressionNode:expr forAssignmentTo:localName to:setOfTypes |
|
2370 |
]. |
|
2371 |
true "/ yes - visit subnodes |
|
2372 |
]. |
|
2373 |
visitor visit:tree. |
|
2374 |
]. |
|
3798 | 2375 |
! |
2376 |
||
2377 |
addTypesOfInstvar:instVarName inClass:aClass fromExistingInstancesTo:setOfTypes |
|
2378 |
"look for existing instances and see that type is there" |
|
2379 |
||
2380 |
|instIndex| |
|
2381 |
||
2382 |
instIndex := aClass instVarIndexFor:instVarName. |
|
2383 |
aClass allSubInstancesDo:[:i | |
|
3801 | 2384 |
|val varClass| |
3798 | 2385 |
|
3801 | 2386 |
val := (i instVarAt:instIndex). |
2387 |
val notNil ifTrue:[ |
|
2388 |
varClass := val class. |
|
2389 |
self rememberType:varClass in:setOfTypes. |
|
2390 |
]. |
|
3798 | 2391 |
]. |
2392 |
||
2393 |
"Created: / 30-04-2016 / 14:56:11 / cg" |
|
3801 | 2394 |
"Modified: / 30-04-2016 / 20:05:03 / cg" |
3798 | 2395 |
! |
2396 |
||
2397 |
compressSetOfTypes:setOfTypes |
|
2398 |
|toAdd toRemove| |
|
2399 |
||
2400 |
"/ reduce by eliminating common superclasses... |
|
2401 |
||
2402 |
toAdd := Set new. |
|
2403 |
toRemove := Set new. |
|
2404 |
setOfTypes do:[:type1 | |
|
2405 |
setOfTypes do:[:type2 | |
|
2406 |
|common| |
|
2407 |
||
2408 |
type1 superclass == type2 ifTrue:[ |
|
2409 |
toRemove add:type1. |
|
2410 |
] ifFalse:[ |
|
2411 |
type2 superclass == type1 ifTrue:[ |
|
2412 |
toRemove add:type2. |
|
2413 |
] ifFalse:[ |
|
2414 |
common := type1 commonSuperclass:type2. |
|
2415 |
common ~~ Object ifTrue:[ |
|
2416 |
toRemove add:type1. |
|
2417 |
toRemove add:type2. |
|
2418 |
toAdd add:common. |
|
2419 |
]. |
|
2420 |
]. |
|
2421 |
]. |
|
2422 |
] |
|
2423 |
]. |
|
2424 |
setOfTypes removeAll:toRemove. |
|
2425 |
setOfTypes addAll:toRemove. |
|
2426 |
||
2427 |
"/ hack |
|
2428 |
setOfTypes size == 2 ifTrue:[ |
|
2429 |
((setOfTypes includes:True) and:[setOfTypes includes:False]) ifTrue:[ |
|
2430 |
setOfTypes removeAll; add:Boolean. |
|
2431 |
^ self. |
|
2432 |
]. |
|
2433 |
((setOfTypes includes:SmallInteger) and:[setOfTypes includes:LargeInteger]) ifTrue:[ |
|
2434 |
setOfTypes removeAll; add:Integer. |
|
2435 |
^ self. |
|
2436 |
] |
|
2437 |
]. |
|
2438 |
||
2439 |
"Created: / 30-04-2016 / 15:37:38 / cg" |
|
2440 |
! |
|
2441 |
||
2442 |
rememberType:aClass in:setOfTypes |
|
2443 |
setOfTypes add:aClass |
|
2444 |
||
2445 |
"Created: / 30-04-2016 / 15:35:44 / cg" |
|
3801 | 2446 |
"Modified: / 30-04-2016 / 20:05:09 / cg" |
3798 | 2447 |
! ! |
2448 |
||
3838 | 2449 |
!Explainer class methodsFor:'utilities'! |
2450 |
||
3842 | 2451 |
actionToBrowseClass:class |
2452 |
^ self actionToBrowseClass:class selector:nil. |
|
2453 |
! |
|
2454 |
||
3838 | 2455 |
actionToBrowseClass:class selector:selectorOrNil |
3885 | 2456 |
^ self actionToBrowseClass:class selector:selectorOrNil info:nil |
3866 | 2457 |
! |
2458 |
||
2459 |
actionToBrowseClass:class selector:selectorOrNil info:info |
|
3885 | 2460 |
self assert:class isBehavior. |
3866 | 2461 |
^ ActionWithInfo |
2462 |
block: |
|
2463 |
[ |
|
2464 |
self thisOrNewBrowserInto:[:browser :openHow | |
|
2465 |
browser |
|
2466 |
spawnFullBrowserInClass:class selector:selectorOrNil in:openHow |
|
2467 |
] |
|
2468 |
] |
|
2469 |
info:info |
|
3838 | 2470 |
! |
2471 |
||
2472 |
actionToBrowseClasses:classes |
|
3868 | 2473 |
^ ActionWithInfo |
2474 |
block:[ |
|
2475 |
"/ Tools::NewSystemBrowser browseClasses:classes |
|
2476 |
self thisOrNewBrowserInto:[:browser :openHow | |
|
2477 |
browser spawnClassBrowserFor:classes in:openHow |
|
2478 |
] |
|
3855 | 2479 |
] |
3868 | 2480 |
info:nil |
3838 | 2481 |
! |
2482 |
||
3855 | 2483 |
actionToBrowseImplementorsOf:selector |
4032 | 2484 |
^ self actionToBrowseImplementorsOf:selector in:[Smalltalk allClasses] |
3866 | 2485 |
! |
2486 |
||
2487 |
actionToBrowseImplementorsOf:selector in:classes |
|
3868 | 2488 |
^ ActionWithInfo |
2489 |
block:[ |
|
2490 |
self thisOrNewBrowserInto:[:browser :openHow | |
|
2491 |
browser |
|
2492 |
spawnMethodImplementorsBrowserFor:{ selector } |
|
2493 |
match:false |
|
2494 |
in:openHow |
|
4032 | 2495 |
classes:classes value |
3868 | 2496 |
label:('Implementors of %1' bindWith:selector) |
2497 |
] |
|
3855 | 2498 |
] |
4032 | 2499 |
info:('Click to browse implementors') |
3842 | 2500 |
! |
2501 |
||
3853 | 2502 |
actionToBrowseInstvarRefsTo:instVarName inClass:class |
3868 | 2503 |
^ ActionWithInfo |
2504 |
block:[ |
|
2505 |
self thisOrNewBrowserInto:[:browser :openHow | |
|
2506 |
browser |
|
2507 |
browseVarRefsToAny:{ instVarName } |
|
2508 |
classes:{ class } |
|
2509 |
variables:#instVarNames access:#readOrWrite all:true |
|
2510 |
title:'references to ',instVarName |
|
2511 |
in:openHow |
|
2512 |
] |
|
2513 |
] |
|
2514 |
info:nil |
|
3853 | 2515 |
! |
2516 |
||
3842 | 2517 |
actionToBrowseMethod:mthd |
3885 | 2518 |
self assert:mthd isMethod. |
3842 | 2519 |
^ self actionToBrowseClass:(mthd mclass) selector:(mthd selector). |
2520 |
! |
|
2521 |
||
2522 |
actionToOpenMethodFinderFor:selector |
|
3838 | 2523 |
MethodFinderWindow notNil ifTrue:[ |
3868 | 2524 |
^ ActionWithInfo |
2525 |
block:[ |
|
2526 |
MethodFinderWindow openOnSelectorPattern:selector |
|
2527 |
] |
|
2528 |
info:nil. |
|
3838 | 2529 |
]. |
3842 | 2530 |
^ self actionToBrowseImplementorsOf:selector |
2531 |
! |
|
2532 |
||
2533 |
asClassLink:nameOfClass |
|
2534 |
"return text with a hyperlink to browse a class by that name" |
|
3838 | 2535 |
|
3842 | 2536 |
|cls| |
2537 |
||
2538 |
cls := Smalltalk classNamed:nameOfClass string asUppercaseFirst. |
|
2539 |
cls isNil ifTrue:[^ nameOfClass]. |
|
3859 | 2540 |
|
3866 | 2541 |
^ self |
2542 |
asLink:nameOfClass |
|
3878 | 2543 |
info:('Click to browse %1' bindWith:nameOfClass) |
3866 | 2544 |
to:(self actionToBrowseClass:cls) |
2545 |
! |
|
2546 |
||
2547 |
asLink:aString info:info to:actionOrNil |
|
2548 |
actionOrNil isNil ifTrue:[^ aString]. |
|
2549 |
^ aString asActionLinkTo:(ActionWithInfo block:actionOrNil info:info) |
|
2550 |
! |
|
2551 |
||
2552 |
asLink:aString to:actionOrNil |
|
2553 |
actionOrNil isNil ifTrue:[^ aString]. |
|
2554 |
^ aString asActionLinkTo:actionOrNil |
|
2555 |
! |
|
2556 |
||
3872 | 2557 |
infoStringForClasses:aCollectionOfClasses withPrefix:prefix |
2558 |
"get a nice user readable list for some classes. |
|
4399 | 2559 |
Up to 4 are listed by name, otherwise the count is presented. |
2560 |
The prefix can be sth like 'other ', 'sub', 'super', |
|
2561 |
'implementing ' etc. |
|
2562 |
Or it can be an empty string. |
|
2563 |
The returned string is meant to be shown in the info line at the bottom." |
|
2564 |
||
2565 |
|nClassNames sortedByName classNames |
|
2566 |
commonSuperClass link1 link2 link3 link4| |
|
3872 | 2567 |
|
2568 |
aCollectionOfClasses isEmpty ifTrue:[ |
|
2569 |
^ 'No %1classes' bindWith:prefix. |
|
2570 |
]. |
|
2571 |
||
4032 | 2572 |
classNames := aCollectionOfClasses asIdentitySet asOrderedCollection |
2573 |
collect:[:each | each theNonMetaclass name]. |
|
3872 | 2574 |
|
2575 |
nClassNames := classNames size. |
|
2576 |
||
2577 |
nClassNames <= 4 ifTrue:[ |
|
3885 | 2578 |
sortedByName := classNames sort. |
2579 |
link1 := self asClassLink:sortedByName first. |
|
3872 | 2580 |
nClassNames == 1 ifTrue:[ |
3885 | 2581 |
^ '%2' "'1 %1class: %2'" bindWith:prefix with:link1. |
3872 | 2582 |
]. |
3885 | 2583 |
link2 := self asClassLink:classNames second. |
3872 | 2584 |
nClassNames == 2 ifTrue:[ |
2585 |
^ '%2 and %3' "'2 %1classes: %2 and %3'" bindWith:prefix |
|
3885 | 2586 |
with:link1 |
2587 |
with:link2. |
|
3872 | 2588 |
]. |
3885 | 2589 |
link3 := self asClassLink:classNames third. |
3872 | 2590 |
nClassNames == 3 ifTrue:[ |
2591 |
^ '%2, %3 and %4' "'3 %1classes: %2, %3 and %4'" bindWith:prefix |
|
3885 | 2592 |
with:link1 |
2593 |
with:link2 |
|
2594 |
with:link3. |
|
3872 | 2595 |
]. |
3885 | 2596 |
link4 := self asClassLink:classNames fourth. |
3872 | 2597 |
nClassNames == 4 ifTrue:[ |
2598 |
^ '%2, %3, %4 and %5' "'4 %1classes: %2, %3, %4 and %5'" bindWith:prefix |
|
3885 | 2599 |
with:link1 |
2600 |
with:link2 |
|
2601 |
with:link3 |
|
2602 |
with:link4. |
|
3872 | 2603 |
]. |
2604 |
]. |
|
4399 | 2605 |
commonSuperClass := Class commonSuperclassOf:aCollectionOfClasses. |
2606 |
(aCollectionOfClasses includes:commonSuperClass) ifTrue:[ |
|
2607 |
^ self |
|
2608 |
asLink:('%1 and %2 additional %3classes' |
|
2609 |
bindWith:commonSuperClass theNonMetaclass name |
|
2610 |
with:(nClassNames - 1) |
|
2611 |
with:prefix) |
|
2612 |
info:'Browse classes' |
|
2613 |
to:(self actionToBrowseClasses:aCollectionOfClasses) |
|
2614 |
]. |
|
2615 |
||
3885 | 2616 |
^ self |
2617 |
asLink:('%1 %2classes' bindWith:nClassNames printString with:prefix) |
|
2618 |
info:'Browse classes' |
|
2619 |
to:(self actionToBrowseClasses:aCollectionOfClasses) |
|
3872 | 2620 |
|
4399 | 2621 |
" |
2622 |
self infoStringForClasses:{ Array } withPrefix:'sub' |
|
2623 |
self infoStringForClasses:{ Array . Point } withPrefix:'sub' |
|
2624 |
self infoStringForClasses:{ Array . Point . Integer . Float} withPrefix:'sub' |
|
2625 |
self infoStringForClasses:{ Array . Point . Integer . Float . Fraction} withPrefix:'sub' |
|
2626 |
self infoStringForClasses:{ Number . Integer . Float . Fraction . SmallInteger} withPrefix:'sub' |
|
2627 |
" |
|
2628 |
||
3872 | 2629 |
"Modified: / 27-07-2006 / 10:09:02 / cg" |
4399 | 2630 |
"Modified: / 27-03-2019 / 10:42:24 / Claus Gittinger" |
3872 | 2631 |
! |
2632 |
||
3866 | 2633 |
infoStringForClasses:aCollectionOfClasses withPrefix:prefix actionGenerator:actionGeneratorOrNil |
2634 |
"get a nice user readable list for some classes. |
|
2635 |
Up to 4 are named, otherwise the count is presented. |
|
2636 |
The prefix can be sth like ' other', ' sub', ' super', |
|
2637 |
' implementing' etc. Or it can be an empty string. |
|
2638 |
To be shown in the info line at the bottom." |
|
2639 |
||
2640 |
|nClassNames classes sortedByName classNames |
|
2641 |
link1 link2 link3 link4 actionGenerator| |
|
2642 |
||
2643 |
aCollectionOfClasses isEmpty ifTrue:[ |
|
2644 |
^ 'No %1classes' bindWith:prefix. |
|
2645 |
]. |
|
2646 |
||
2647 |
actionGenerator := actionGeneratorOrNil isNil |
|
2648 |
ifTrue:[ [:classes | self actionToBrowseClasses:classes] ] |
|
2649 |
ifFalse:[ actionGeneratorOrNil ]. |
|
2650 |
||
2651 |
classes := aCollectionOfClasses asIdentitySet asOrderedCollection. |
|
2652 |
classNames := classes collect:[:each | each theNonMetaclass name]. |
|
2653 |
||
2654 |
nClassNames := classNames size. |
|
2655 |
||
2656 |
nClassNames <= 4 ifTrue:[ |
|
2657 |
sortedByName := classNames sortWith:classes. |
|
2658 |
||
2659 |
link1 := self asLink:classNames first "allBold" |
|
2660 |
info:('Browse %1' bindWith:classNames first) |
|
2661 |
to:(actionGenerator value:{classes first}). |
|
2662 |
nClassNames == 1 ifTrue:[ |
|
2663 |
^ '%2' "'1 %1class: %2'" |
|
2664 |
bindWith:prefix |
|
2665 |
with:link1. |
|
2666 |
]. |
|
2667 |
link2 := self asLink:classNames second "allBold" to:(actionGenerator value:{classes second}). |
|
2668 |
nClassNames == 2 ifTrue:[ |
|
2669 |
^ '%2 and %3' "'2 %1classes: %2 and %3'" |
|
2670 |
bindWith:prefix |
|
2671 |
with:link1 |
|
2672 |
with:link2. |
|
2673 |
]. |
|
2674 |
link3 := self asLink:classNames third "allBold" to:(actionGenerator value:{classes third}). |
|
2675 |
nClassNames == 3 ifTrue:[ |
|
2676 |
^ '%2, %3 and %4' "'3 %1classes: %2, %3 and %4'" |
|
2677 |
bindWith:prefix |
|
2678 |
with:link1 |
|
2679 |
with:link2 |
|
2680 |
with:link3. |
|
2681 |
]. |
|
2682 |
link4 := self asLink:classNames fourth "allBold" to:(actionGenerator value:{classes fourth}). |
|
2683 |
nClassNames == 4 ifTrue:[ |
|
2684 |
^ '%2, %3, %4 and %5' "'4 %1classes: %2, %3, %4 and %5'" |
|
2685 |
bindWith:prefix |
|
2686 |
with:link1 |
|
2687 |
with:link2 |
|
2688 |
with:link3 |
|
2689 |
with:link4. |
|
2690 |
]. |
|
2691 |
]. |
|
2692 |
^ self |
|
2693 |
asLink:('%1 %2classes' bindWith:(nClassNames printString "allBold") with:prefix) |
|
2694 |
to:(actionGenerator value:classes) |
|
2695 |
||
2696 |
"Modified: / 27-07-2006 / 10:09:02 / cg" |
|
3842 | 2697 |
! |
2698 |
||
2699 |
infoStringForMethods:aCollectionOfMethods withPrefix:prefix |
|
2700 |
"get a nice user readable list for some methods. |
|
2701 |
Up to 3 are named, otherwise the count is presented. |
|
2702 |
The prefix can be sth like ' other', ' sender', ' implementor', |
|
2703 |
Or it can be an empty string. |
|
2704 |
Result is meant to be shown in the info line at the bottom of a browser." |
|
2705 |
||
2706 |
|nMethodNames sortedByName methodNames| |
|
2707 |
||
2708 |
aCollectionOfMethods isEmpty ifTrue:[ |
|
2709 |
^ 'No %1' bindWith:prefix. |
|
2710 |
]. |
|
2711 |
||
2712 |
methodNames := aCollectionOfMethods asOrderedCollection |
|
2713 |
collect:[:each | each whoString]. |
|
2714 |
||
2715 |
nMethodNames := methodNames size. |
|
2716 |
||
2717 |
nMethodNames <= 3 ifTrue:[ |
|
2718 |
nMethodNames == 1 ifTrue:[ |
|
2719 |
^ '%2' "'1 %1class: %2'" bindWith:prefix with:(methodNames first allBold). |
|
2720 |
]. |
|
2721 |
sortedByName := methodNames sort. |
|
2722 |
nMethodNames == 2 ifTrue:[ |
|
2723 |
^ '%2 and %3' "'2 %1classes: %2 and %3'" bindWith:prefix |
|
2724 |
with:(sortedByName first allBold) |
|
2725 |
with:(sortedByName second allBold). |
|
2726 |
]. |
|
2727 |
nMethodNames == 3 ifTrue:[ |
|
2728 |
^ '%2, %3 and %4' "'3 %1classes: %2, %3 and %4'" bindWith:prefix |
|
2729 |
with:(sortedByName first allBold) |
|
2730 |
with:(sortedByName second allBold) |
|
2731 |
with:(sortedByName third allBold). |
|
2732 |
]. |
|
2733 |
nMethodNames == 4 ifTrue:[ |
|
2734 |
^ '%2, %3, %4 and %5' "'4 %1classes: %2, %3, %4 and %5'" bindWith:prefix |
|
2735 |
with:(sortedByName first allBold) |
|
2736 |
with:(sortedByName second allBold) |
|
2737 |
with:(sortedByName third allBold) |
|
2738 |
with:(sortedByName fourth allBold). |
|
2739 |
]. |
|
2740 |
]. |
|
2741 |
^ '%1 %2methods' bindWith:nMethodNames printString allBold with:prefix. |
|
2742 |
||
2743 |
" |
|
2744 |
Time millisecondsToRun:[ |
|
2745 |
self infoStringForMethods:(SystemBrowser allCallsOn:#'at:put:') withPrefix:'' |
|
2746 |
]. |
|
2747 |
Time millisecondsToRun:[ |
|
2748 |
self infoStringForMethods:(SystemBrowser allCallsOn:#'actionToBrowseClasses:') withPrefix:'' |
|
2749 |
]. |
|
2750 |
" |
|
2751 |
! |
|
2752 |
||
3872 | 2753 |
methodImplementorsInfoFor:aMethod inEnvironment:environment |
2754 |
"get something about the implementors of aMethod |
|
2755 |
to be shown in the info line at the bottom" |
|
2756 |
||
2757 |
|implementors msg senders msg2| |
|
2758 |
||
2759 |
implementors := SystemBrowser |
|
2760 |
findImplementorsOf:aMethod selector |
|
2761 |
in:(environment allClasses) |
|
2762 |
ignoreCase:false. |
|
2763 |
||
2764 |
implementors notEmpty ifTrue:[ |
|
2765 |
msg := 'Only implemented here.'. |
|
2766 |
implementors remove:aMethod ifAbsent:nil. |
|
2767 |
implementors notEmpty ifTrue:[ |
|
2768 |
implementors := implementors collect:[:mthd | mthd mclass ? mthd getMclass]. |
|
2769 |
implementors notEmpty ifTrue:[ |
|
4032 | 2770 |
msg := 'Also ',(self asLink:'implemented' to:(self actionToBrowseImplementorsOf:aMethod selector)),' in '. |
3872 | 2771 |
msg := msg , (self infoStringForClasses:implementors withPrefix:'other '). |
2772 |
msg := msg , '.'. |
|
2773 |
] |
|
2774 |
]. |
|
2775 |
]. |
|
2776 |
||
2777 |
false ifTrue:[ "/ too slow |
|
2778 |
senders := SystemBrowser |
|
2779 |
findSendersOf:aMethod selector |
|
2780 |
in:(environment allClasses) |
|
2781 |
ignoreCase:false. |
|
2782 |
senders notEmpty ifTrue:[ |
|
2783 |
msg2 := 'Sent from ' , senders size printString, ' methods.'. |
|
2784 |
] ifFalse:[ |
|
2785 |
msg2 := 'No senders.'. |
|
2786 |
]. |
|
2787 |
msg := msg , '/' , msg2 |
|
2788 |
]. |
|
2789 |
||
2790 |
^ msg |
|
2791 |
! |
|
2792 |
||
3871 | 2793 |
methodInheritanceInfoFor:aMethod |
2794 |
|methodsSuperclass inheritedClass msg methodsClass sel mthd selectorString| |
|
2795 |
||
2796 |
methodsClass := aMethod mclass. |
|
2797 |
methodsClass isNil ifTrue:[^ nil]. |
|
2798 |
||
2799 |
methodsSuperclass := methodsClass superclass. |
|
2800 |
methodsSuperclass isNil ifTrue:[^ nil]. |
|
2801 |
||
2802 |
sel := aMethod selector. |
|
2803 |
inheritedClass := methodsSuperclass whichClassIncludesSelector:sel. |
|
2804 |
inheritedClass notNil ifTrue:[ |
|
2805 |
mthd := inheritedClass compiledMethodAt:sel. |
|
4110 | 2806 |
(mthd sendsSelector:#'subclassResponsibility') ifTrue:[ |
3871 | 2807 |
msg := '%1 overrides subclassResponsibility in %2'. |
2808 |
] ifFalse:[ |
|
2809 |
msg := '%1 overrides implementation in %2'. |
|
2810 |
]. |
|
2811 |
selectorString := sel contractTo:30. |
|
2812 |
^ msg |
|
2813 |
bindWith:(self |
|
2814 |
asLink:selectorString "allBold" |
|
2815 |
info:('Browse all implementors of %1' bindWith:selectorString) |
|
2816 |
to:(self actionToOpenMethodFinderFor:sel)) |
|
2817 |
with:(self |
|
2818 |
asLink:inheritedClass name "allBold" |
|
4399 | 2819 |
info:('Browse %1 » %2' bindWith:inheritedClass name with:sel) |
3871 | 2820 |
to:(self actionToBrowseClass:inheritedClass selector:sel)). |
2821 |
]. |
|
2822 |
||
2823 |
^ msg |
|
4110 | 2824 |
|
2825 |
"Modified: / 05-02-2017 / 01:24:25 / cg" |
|
3871 | 2826 |
! |
2827 |
||
2828 |
methodRedefinitionInfoFor:aMethod |
|
2829 |
"return a user readable string telling in how many subclasses |
|
2830 |
a method is redefined. |
|
2831 |
To be shown in the info line of a browser" |
|
2832 |
||
4060 | 2833 |
|redefiningClasses msg methodsClass| |
2834 |
||
2835 |
methodsClass := aMethod mclass. |
|
2836 |
methodsClass isNil ifTrue:[^ nil]. |
|
2837 |
||
2838 |
redefiningClasses := methodsClass allSubclasses select:[:eachClass | eachClass includesSelector:aMethod selector]. |
|
2839 |
redefiningClasses size ~~ 0 ifTrue:[ |
|
3871 | 2840 |
msg := 'redefined in '. |
2841 |
msg := msg , (self |
|
2842 |
infoStringForClasses:redefiningClasses |
|
2843 |
withPrefix:'sub' |
|
2844 |
actionGenerator:[:classes | |
|
3878 | 2845 |
classes size == 1 ifTrue:[ |
2846 |
|cls| |
|
4060 | 2847 |
|
3878 | 2848 |
cls := classes first. |
2849 |
self |
|
2850 |
actionToBrowseClass:cls |
|
2851 |
selector:aMethod selector |
|
2852 |
info:('Browse implementation in %1' bindWith:cls name) |
|
2853 |
] ifFalse:[ |
|
2854 |
self |
|
2855 |
actionToBrowseImplementorsOf:aMethod selector |
|
2856 |
in:classes |
|
2857 |
]. |
|
2858 |
]). |
|
3871 | 2859 |
msg := msg , '.'. |
2860 |
]. |
|
2861 |
||
2862 |
^ msg |
|
2863 |
! |
|
2864 |
||
3842 | 2865 |
methodSendersInfoFor:selector inEnvironment:environment |
2866 |
"get something about the senders of a message. |
|
2867 |
to be shown in the info line at the bottom. |
|
2868 |
This may be slow; so think about doing it in background..." |
|
2869 |
||
2870 |
|senders| |
|
2871 |
||
2872 |
senders := SystemBrowser |
|
2873 |
findSendersOf:selector |
|
2874 |
in:(environment allClasses) |
|
2875 |
ignoreCase:false |
|
2876 |
match:false. |
|
2877 |
||
2878 |
senders notEmpty ifTrue:[ |
|
2879 |
^ 'Sent from ' , senders size printString, ' methods.'. |
|
2880 |
] ifFalse:[ |
|
2881 |
^ 'No senders.'. |
|
2882 |
]. |
|
3859 | 2883 |
! |
2884 |
||
3872 | 2885 |
methodSpecialInfoFor:aMethod |
2886 |
"handles special cases - such as documentation methods" |
|
2887 |
||
2888 |
|cls sel| |
|
2889 |
||
2890 |
(cls := aMethod mclass) isNil ifTrue:[^ nil]. |
|
2891 |
(sel := aMethod selector) isNil ifTrue:[^ nil]. |
|
2892 |
||
2893 |
cls isMeta ifTrue:[ |
|
2894 |
(AbstractSourceCodeManager isVersionMethodSelector:sel) ifTrue:[ |
|
2895 |
^ 'The version method is required for the source code repository - do not modify.'. |
|
2896 |
]. |
|
2897 |
sel == #documentation ifTrue:[ |
|
2898 |
^ 'ST/X stores documentation in this method (not in comment slots)'. |
|
2899 |
]. |
|
2900 |
]. |
|
2901 |
^ nil |
|
2902 |
! |
|
2903 |
||
3859 | 2904 |
thisOrNewBrowserInto:aTwoArgBlock |
4269 | 2905 |
"I am inviked when user clicks on a link in the info line. |
2906 |
if I am invoked by a browser, |
|
4268 | 2907 |
invoke the twoArgBlock with it and a #newBuffer arg. |
3859 | 2908 |
Otherwise, create a new (invisible) browser and pass it to the block |
2909 |
with a #newBrowser arg." |
|
2910 |
||
2911 |
|windowGroupClass browserClass wg app| |
|
2912 |
||
2913 |
"/ stupid: I am in libcomp; should be in libtool |
|
4269 | 2914 |
"/ access by name, so we do not introduce new prerequisites on the package |
3859 | 2915 |
windowGroupClass := Smalltalk at:#WindowGroup. |
2916 |
windowGroupClass isNil ifTrue:[^ self]. |
|
4269 | 2917 |
browserClass := Smalltalk at:#'SystemBrowser'. |
2918 |
browserClass isNil ifTrue:[^ self]. |
|
2919 |
browserClass := browserClass default. |
|
3859 | 2920 |
browserClass isNil ifTrue:[^ self]. |
2921 |
||
2922 |
((wg := windowGroupClass activeGroup) notNil |
|
2923 |
and:[ (app := wg application) isKindOf:browserClass ] |
|
2924 |
) ifTrue:[ |
|
2925 |
^ aTwoArgBlock value:app value:#newBuffer |
|
2926 |
]. |
|
2927 |
^ aTwoArgBlock value:(browserClass basicNew) value:#newBrowser |
|
4268 | 2928 |
|
4269 | 2929 |
"Modified (comment): / 24-05-2018 / 15:01:01 / Claus Gittinger" |
3838 | 2930 |
! ! |
3826 | 2931 |
|
3866 | 2932 |
!Explainer::ActionWithInfo class methodsFor:'instance creation'! |
2933 |
||
2934 |
block:aBlock info:info |
|
2935 |
^ self new block:aBlock info:info |
|
2936 |
! ! |
|
2937 |
||
2938 |
!Explainer::ActionWithInfo methodsFor:'accessing'! |
|
2939 |
||
2940 |
block:blockArg info:infoArg |
|
2941 |
block := blockArg. |
|
2942 |
info := infoArg. |
|
2943 |
! |
|
2944 |
||
2945 |
info:something |
|
2946 |
info := something. |
|
2947 |
! ! |
|
2948 |
||
2949 |
!Explainer::ActionWithInfo methodsFor:'evaluation'! |
|
2950 |
||
2951 |
info |
|
2952 |
^ info |
|
2953 |
! |
|
2954 |
||
2955 |
value |
|
2956 |
^ block value |
|
2957 |
! |
|
2958 |
||
2959 |
value:arg |
|
2960 |
^ block value:arg |
|
2961 |
! ! |
|
2962 |
||
396 | 2963 |
!Explainer class methodsFor:'documentation'! |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
2964 |
|
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
2965 |
version |
3697 | 2966 |
^ '$Header$' |
2214 | 2967 |
! |
2968 |
||
2969 |
version_CVS |
|
3697 | 2970 |
^ '$Header$' |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
2971 |
! ! |
3209 | 2972 |