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