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