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