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