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