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