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