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