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