author | Claus Gittinger <cg@exept.de> |
Mon, 14 Dec 2009 14:45:43 +0100 | |
changeset 2315 | 45f09cea2063 |
parent 2314 | 0c590d9937bd |
child 2316 | f09794e008f8 |
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 |
" |
|
20 | 39 |
a very simple explainer - much more should be added ... |
40 |
This one is involved, when the 'explain' function is used in a |
|
1728 | 41 |
codeView (popup or via CMD-E), or if the mouse button is clicked |
42 |
on some code construct in the new browser. |
|
263 | 43 |
|
44 |
[author:] |
|
45 |
Claus Gittinger |
|
2 | 46 |
" |
47 |
! ! |
|
48 |
||
396 | 49 |
!Explainer class methodsFor:'explaining'! |
2 | 50 |
|
2193
9416fc17ee62
pass the interval to the explainer
Claus Gittinger <cg@exept.de>
parents:
2191
diff
changeset
|
51 |
explainLiteralNode:node in:code forClass:cls short:short interval:intervalIfKnown |
2191
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
52 |
|expl literalValue findInnerMost| |
1728 | 53 |
|
54 |
literalValue := node value. |
|
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
55 |
expl := literalValue class name "allBold" , '-constant.'. |
1728 | 56 |
(literalValue isArray or:[ literalValue isByteArray ]) ifTrue:[ |
57 |
literalValue size == 0 ifTrue:[ |
|
58 |
^ 'empty ' , expl |
|
59 |
]. |
|
60 |
]. |
|
2191
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
61 |
node isLiteralArray ifTrue:[ |
2193
9416fc17ee62
pass the interval to the explainer
Claus Gittinger <cg@exept.de>
parents:
2191
diff
changeset
|
62 |
intervalIfKnown notNil ifTrue:[ |
9416fc17ee62
pass the interval to the explainer
Claus Gittinger <cg@exept.de>
parents:
2191
diff
changeset
|
63 |
findInnerMost := [:token | |
2191
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
64 |
token value do:[:eachToken | |
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
65 |
|selectorOrName| |
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
66 |
|
2193
9416fc17ee62
pass the interval to the explainer
Claus Gittinger <cg@exept.de>
parents:
2191
diff
changeset
|
67 |
((eachToken start to:eachToken stop) intersect:intervalIfKnown) notEmpty ifTrue:[ |
2191
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
68 |
eachToken value isArray ifTrue:[ |
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
69 |
findInnerMost value:eachToken. |
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
70 |
]. |
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
71 |
eachToken value isSymbol ifTrue:[ |
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
72 |
selectorOrName := eachToken value. |
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
73 |
selectorOrName isUppercaseFirst ifTrue:[ |
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
74 |
(Smalltalk includesKey:selectorOrName) ifTrue:[ |
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
75 |
^ expl, ' / ', (Explainer explainGlobal:selectorOrName inClass:cls short:short) |
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
76 |
]. |
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
77 |
]. |
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
78 |
|
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
79 |
^ expl, ' / ', (Explainer explainSelector:selectorOrName inClass:cls short:short) |
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
80 |
]. |
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
81 |
]. |
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
82 |
] |
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
83 |
]. |
2193
9416fc17ee62
pass the interval to the explainer
Claus Gittinger <cg@exept.de>
parents:
2191
diff
changeset
|
84 |
findInnerMost value:node token. |
9416fc17ee62
pass the interval to the explainer
Claus Gittinger <cg@exept.de>
parents:
2191
diff
changeset
|
85 |
]. |
2191
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
86 |
]. |
1728 | 87 |
^ expl |
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
88 |
|
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
89 |
"Modified: / 09-10-2006 / 12:09:43 / cg" |
1728 | 90 |
! |
91 |
||
2193
9416fc17ee62
pass the interval to the explainer
Claus Gittinger <cg@exept.de>
parents:
2191
diff
changeset
|
92 |
explainMessageNode:node in:code forClass:cls short:short interval:intervalIfKnown |
1771 | 93 |
"answer a string which explains node" |
94 |
||
1728 | 95 |
|receiver nm srchClass selector selectorString implClass |
96 |
boldSelectorString globalValue recClassSet |
|
1854 | 97 |
implMethod implMethodComment info implMethods comments definer |
98 |
instances classesOfInstVars implementingClasses canBeNil |
|
1909 | 99 |
bestMatches| |
1728 | 100 |
|
101 |
selector := node selector. |
|
102 |
selectorString := selector printString contractTo:30. |
|
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
103 |
boldSelectorString := selectorString "allBold". |
1728 | 104 |
|
1733 | 105 |
recClassSet := self guessPossibleImplementorClassesFor:(node receiver) in:code forClass:cls. |
106 |
recClassSet size == 1 ifTrue:[ |
|
107 |
srchClass := recClassSet first. |
|
2031
1ce5af7a6ba6
Do not try to store nil into Sets - avoid diagnostics.
Stefan Vogel <sv@exept.de>
parents:
2008
diff
changeset
|
108 |
"take care - Set cannot store nil!!" |
2190 | 109 |
implementingClasses := recClassSet collect:[:cls | cls whichClassIncludesSelector:selector] as:Array. |
1869 | 110 |
|
1733 | 111 |
(implementingClasses includes:nil) ifTrue:[ |
1869 | 112 |
implementingClasses size > 1 ifTrue:[ |
113 |
^ 'possibly not understood: %1 (%2 other implementors)' |
|
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
114 |
bindWith:selector "allBold" |
1869 | 115 |
with:(implementingClasses size - 1) |
116 |
]. |
|
117 |
||
118 |
bestMatches := Parser findBestSelectorsFor:selector in:srchClass. |
|
119 |
bestMatches size > 0 ifTrue:[ |
|
1979 | 120 |
^ 'NOT understood here: %1 (Best guess: %2)' |
1869 | 121 |
bindWith:selector |
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
122 |
with:(bestMatches first "allBold") |
1869 | 123 |
]. |
1979 | 124 |
^ 'NOT understood here: %1' bindWith:selector "allBold" |
1728 | 125 |
]. |
1733 | 126 |
]. |
127 |
||
128 |
implementingClasses isNil ifTrue:[ |
|
129 |
receiver := node receiver. |
|
130 |
receiver isVariable ifTrue:[ |
|
131 |
nm := receiver name. |
|
132 |
nm = 'self' ifTrue:[ |
|
133 |
srchClass := cls |
|
134 |
]. |
|
135 |
nm = 'super' ifTrue:[ |
|
136 |
srchClass := cls superclass |
|
137 |
]. |
|
138 |
definer := receiver whoDefines:nm. |
|
139 |
definer isNil ifTrue:[ |
|
140 |
"/ not a local or argument |
|
141 |
(cls instanceVariableNames includes:nm) ifTrue:[ |
|
142 |
"/ ok - an instVar; see what values we find... |
|
143 |
instances := cls allSubInstances. |
|
144 |
classesOfInstVars := instances collect:[:eachInst | (eachInst instVarNamed:nm) class]. |
|
145 |
classesOfInstVars := classesOfInstVars asSet. |
|
2031
1ce5af7a6ba6
Do not try to store nil into Sets - avoid diagnostics.
Stefan Vogel <sv@exept.de>
parents:
2008
diff
changeset
|
146 |
canBeNil := (classesOfInstVars remove:UndefinedObject ifAbsent:[]) notNil. |
1ce5af7a6ba6
Do not try to store nil into Sets - avoid diagnostics.
Stefan Vogel <sv@exept.de>
parents:
2008
diff
changeset
|
147 |
"take care - Set cannot store nil!!" |
1ce5af7a6ba6
Do not try to store nil into Sets - avoid diagnostics.
Stefan Vogel <sv@exept.de>
parents:
2008
diff
changeset
|
148 |
implementingClasses := classesOfInstVars collect:[:cls | (cls whichClassIncludesSelector:selector) ? 0]. |
1ce5af7a6ba6
Do not try to store nil into Sets - avoid diagnostics.
Stefan Vogel <sv@exept.de>
parents:
2008
diff
changeset
|
149 |
implementingClasses remove:0 ifAbsent:[]. |
1733 | 150 |
] ifFalse:[ |
151 |
nm isUppercaseFirst ifTrue:[ |
|
152 |
nm knownAsSymbol ifTrue:[ |
|
153 |
globalValue := Smalltalk at:nm asSymbol. |
|
154 |
globalValue isClass ifTrue:[ |
|
155 |
srchClass := globalValue class. |
|
156 |
]. |
|
157 |
] |
|
158 |
]. |
|
1728 | 159 |
]. |
160 |
]. |
|
161 |
]. |
|
162 |
||
1733 | 163 |
receiver isLiteral ifTrue:[ |
164 |
srchClass := receiver value class |
|
165 |
]. |
|
1728 | 166 |
|
1733 | 167 |
srchClass notNil ifTrue:[ |
1761 | 168 |
implClass := srchClass whichClassIncludesSelector:selector. |
1733 | 169 |
implClass isNil ifTrue:[ |
170 |
^ '%1 is NOT understood here.' bindWith:boldSelectorString |
|
171 |
]. |
|
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
172 |
info := '%1 >> %2' bindWith:implClass name "allBold" with:selectorString "allBold". |
1728 | 173 |
|
1733 | 174 |
implMethod := implClass compiledMethodAt:selector. |
1909 | 175 |
implMethodComment := self fetchCommentOfMethod:implMethod. |
1854 | 176 |
implMethodComment notNil ifTrue:[ |
177 |
info := info , ' ' , implMethodComment. |
|
1733 | 178 |
]. |
179 |
^ info |
|
1728 | 180 |
]. |
1733 | 181 |
implementingClasses isNil ifTrue:[ |
182 |
implementingClasses := Smalltalk allImplementorsOf:selector |
|
183 |
]. |
|
1728 | 184 |
]. |
185 |
||
186 |
implementingClasses size == 1 ifTrue:[ |
|
187 |
implClass := implementingClasses anElement. |
|
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
188 |
info := '%1 >> %2' bindWith:implClass name "allBold" with:selectorString. |
1733 | 189 |
srchClass isNil ifTrue:[ |
1854 | 190 |
"/ info := 'guess: ', info. |
191 |
info := info , ' (guess)'. |
|
1733 | 192 |
]. |
1728 | 193 |
] ifFalse:[ |
194 |
info := Explainer explainSelector:selector inClass:cls short:short. |
|
195 |
]. |
|
196 |
||
1771 | 197 |
implementingClasses notEmptyOrNil ifTrue:[ |
1728 | 198 |
implMethods := implementingClasses collect:[:implClass | implClass compiledMethodAt:selector]. |
199 |
implMethods size <= 5 ifTrue:[ |
|
1771 | 200 |
comments := implMethods collect:[:implMethod | implMethod comment ? '']. |
201 |
(comments includes:'') ifFalse:[ |
|
1854 | 202 |
comments := comments collect:[:implMethodComment | implMethodComment firstLine]. |
1728 | 203 |
comments asSet size == 1 ifTrue:[ |
1909 | 204 |
info := info , ' ' , (self fetchCommentOfMethod:implMethods first). |
1728 | 205 |
]. |
206 |
]. |
|
207 |
]. |
|
208 |
]. |
|
209 |
^ info |
|
1854 | 210 |
|
1979 | 211 |
"Modified: / 06-02-2007 / 19:26:11 / cg" |
1728 | 212 |
! |
213 |
||
2193
9416fc17ee62
pass the interval to the explainer
Claus Gittinger <cg@exept.de>
parents:
2191
diff
changeset
|
214 |
explainMethodNode:node in:code forClass:cls short:short interval:intervalIfKnown |
1728 | 215 |
|srchClass selector selectorString implClass |
216 |
"sendingMethods numSendingMethods sendingClasses" boldSelectorString| |
|
217 |
||
218 |
selector := node selector. |
|
219 |
selectorString := selector printString contractTo:30. |
|
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
220 |
boldSelectorString := selectorString "allBold". |
1728 | 221 |
|
222 |
(srchClass := cls superclass) notNil ifTrue:[ |
|
1761 | 223 |
implClass := srchClass whichClassIncludesSelector:selector. |
1728 | 224 |
implClass notNil ifTrue:[ |
225 |
^ '%1 hides implementation in %2.' |
|
226 |
bindWith:boldSelectorString |
|
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
227 |
with:implClass name "allBold" |
1728 | 228 |
]. |
229 |
]. |
|
2223
50b76baab48b
changed: #explainMethodNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2214
diff
changeset
|
230 |
(cls includesSelector:selector) ifFalse:[ |
1728 | 231 |
^ '%1: a new method.' bindWith:boldSelectorString |
232 |
]. |
|
233 |
"/ |
|
234 |
"/ sendingMethods := SystemBrowser |
|
235 |
"/ allCallsOn:selector |
|
236 |
"/ in:(cls withAllSubclasses , cls allSubclasses) |
|
237 |
"/ ignoreCase:false |
|
238 |
"/ match:false. |
|
239 |
"/ sendingMethods := sendingMethods select:[:eachMethod | eachMethod mclass notNil]. "/ remove unbound ones |
|
240 |
"/ |
|
241 |
"/ sendingClasses := (sendingMethods collect:[:eachMethod | eachMethod mclass]) asSet. |
|
242 |
"/ numSendingMethods := sendingMethods size. |
|
243 |
"/ numSendingMethods == 1 ifTrue:[ |
|
244 |
"/ sendingClasses first == cls ifTrue:[ |
|
245 |
"/ ^ '%1: sent locally from %2.' |
|
246 |
"/ bindWith:boldSelectorString |
|
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
247 |
"/ with:sendingMethods first selector "allBold" |
1728 | 248 |
"/ ]. |
249 |
"/ ^ '%1: sent in hierarchy from %2 in %3.' |
|
250 |
"/ bindWith:boldSelectorString |
|
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
251 |
"/ with:sendingMethods first selector "allBold" |
1728 | 252 |
"/ with:sendingClasses first name. |
253 |
"/ ]. |
|
254 |
"/ numSendingMethods == 2 ifTrue:[ |
|
255 |
"/ sendingClasses asIdentitySet size == 1 ifTrue:[ |
|
256 |
"/ sendingClasses first == cls ifTrue:[ |
|
257 |
"/ ^ '%1: sent locally from %2 and %3.' |
|
258 |
"/ bindWith:boldSelectorString |
|
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
259 |
"/ with:sendingMethods first selector "allBold" |
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
260 |
"/ with:sendingMethods second selector "allBold" |
1728 | 261 |
"/ ]. |
262 |
"/ ^ '%1: sent in hierarchy from %2 and %3 in %4.' |
|
263 |
"/ bindWith:boldSelectorString |
|
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
264 |
"/ with:sendingMethods first selector "allBold" |
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
265 |
"/ with:sendingMethods second selector "allBold" |
1728 | 266 |
"/ with:sendingClasses first name. |
267 |
"/ ]. |
|
268 |
"/ ]. |
|
269 |
"/ numSendingMethods == 0 ifTrue:[ |
|
270 |
"/"/ ^ '%1: no sender found.' |
|
271 |
"/"/ bindWith:boldSelectorString. |
|
272 |
"/ ^ nil |
|
273 |
"/ ]. |
|
274 |
"/ ^ '%1: %2 sending methods in hierarchy.' |
|
275 |
"/ bindWith:boldSelectorString |
|
276 |
"/ with:numSendingMethods. |
|
277 |
"/ |
|
278 |
"/ "/ the following is too expensive... |
|
279 |
"/"/ sendingMethods := SystemBrowser allCallsOn:selector in:Smalltalk allClasses. |
|
280 |
"/"/ numSendingMethods == 0 ifTrue:[ |
|
281 |
"/"/ ^ '%1: nowhere sent.' bindWith:boldSelectorString |
|
282 |
"/"/ ]. |
|
283 |
"/"/ numSendingMethods == 1 ifTrue:[ |
|
284 |
"/"/ sendingMethods first mclass == cls ifTrue:[ |
|
285 |
"/"/ ^ '%1: only sent from %2.' |
|
286 |
"/"/ bindWith:boldSelectorString |
|
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
287 |
"/"/ with:sendingMethods first selector "allBold" |
1728 | 288 |
"/"/ ]. |
289 |
"/"/ ^ '%1: only sent from %2 in %3.' |
|
290 |
"/"/ bindWith:boldSelectorString |
|
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
291 |
"/"/ with:sendingMethods first selector "allBold" |
1728 | 292 |
"/"/ with:sendingMethods first mclass name. |
293 |
"/"/ ]. |
|
294 |
"/"/ sendingClasses := (sendingMethods collect:[:eachMethod | eachMethod mclass]) asSet. |
|
295 |
"/"/ sendingClasses size == 1 ifTrue:[ |
|
296 |
"/"/ sendingClasses first == cls ifTrue:[ |
|
297 |
"/"/ ^ '%1: locally sent from %2 methods.' |
|
298 |
"/"/ bindWith:boldSelectorString |
|
299 |
"/"/ with:numSendingMethods |
|
300 |
"/"/ ]. |
|
301 |
"/"/ ^ '%1 only sent from %2 methods in %3.' |
|
302 |
"/"/ bindWith:boldSelectorString |
|
303 |
"/"/ with:numSendingMethods |
|
304 |
"/"/ with:sendingClasses first name. |
|
305 |
"/"/ ]. |
|
306 |
||
307 |
^ nil |
|
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
308 |
|
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
309 |
"Modified: / 09-10-2006 / 12:11:16 / cg" |
1728 | 310 |
! |
311 |
||
2193
9416fc17ee62
pass the interval to the explainer
Claus Gittinger <cg@exept.de>
parents:
2191
diff
changeset
|
312 |
explainNode:node in:code forClass:cls short:short |
9416fc17ee62
pass the interval to the explainer
Claus Gittinger <cg@exept.de>
parents:
2191
diff
changeset
|
313 |
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
|
314 |
! |
9416fc17ee62
pass the interval to the explainer
Claus Gittinger <cg@exept.de>
parents:
2191
diff
changeset
|
315 |
|
9416fc17ee62
pass the interval to the explainer
Claus Gittinger <cg@exept.de>
parents:
2191
diff
changeset
|
316 |
explainNode:node in:code forClass:cls short:short interval:intervalIfKnown |
1728 | 317 |
node isVariable ifTrue:[ |
2193
9416fc17ee62
pass the interval to the explainer
Claus Gittinger <cg@exept.de>
parents:
2191
diff
changeset
|
318 |
^ self explainVariableNode:node in:code forClass:cls short:short interval:intervalIfKnown. |
1728 | 319 |
]. |
320 |
||
321 |
node isLiteral ifTrue:[ |
|
2193
9416fc17ee62
pass the interval to the explainer
Claus Gittinger <cg@exept.de>
parents:
2191
diff
changeset
|
322 |
^ self explainLiteralNode:node in:code forClass:cls short:short interval:intervalIfKnown |
1728 | 323 |
]. |
324 |
||
325 |
node isMessage ifTrue:[ |
|
2193
9416fc17ee62
pass the interval to the explainer
Claus Gittinger <cg@exept.de>
parents:
2191
diff
changeset
|
326 |
^ self explainMessageNode:node in:code forClass:cls short:short interval:intervalIfKnown |
1728 | 327 |
]. |
328 |
||
329 |
node isMethod ifTrue:[ |
|
2193
9416fc17ee62
pass the interval to the explainer
Claus Gittinger <cg@exept.de>
parents:
2191
diff
changeset
|
330 |
^ self explainMethodNode:node in:code forClass:cls short:short interval:intervalIfKnown |
1728 | 331 |
]. |
332 |
||
333 |
^ nil |
|
334 |
! |
|
335 |
||
2193
9416fc17ee62
pass the interval to the explainer
Claus Gittinger <cg@exept.de>
parents:
2191
diff
changeset
|
336 |
explainVariableNode:node in:code forClass:cls short:short interval:intervalIfKnown |
1938 | 337 |
|expl nm nmBold definingNode namePart| |
1728 | 338 |
|
339 |
nm := node name. |
|
340 |
||
341 |
(#( 'self' 'super' 'thisContext' 'here') includes:nm) ifTrue:[ |
|
342 |
^ Explainer explainPseudoVariable:nm in:cls short:short |
|
343 |
]. |
|
344 |
||
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
345 |
nm notNil ifTrue:[ nmBold := nm "allBold" ]. |
1728 | 346 |
|
347 |
definingNode := node whoDefines:nm. |
|
348 |
definingNode notNil ifTrue:[ |
|
1938 | 349 |
namePart := '''' , nmBold , ''''. |
1728 | 350 |
definingNode isMethod ifTrue:[ |
351 |
(definingNode arguments contains:[:arg | arg name = nm]) ifTrue:[ |
|
1938 | 352 |
expl := namePart , ' is a method argument.' |
1728 | 353 |
]. |
354 |
]. |
|
1938 | 355 |
expl isNil ifTrue:[ |
356 |
definingNode isBlock ifTrue:[ |
|
357 |
(definingNode arguments contains:[:arg | arg name = nm]) ifTrue:[ |
|
358 |
expl := namePart , ' is a block argument.' |
|
359 |
]. |
|
1728 | 360 |
]. |
361 |
]. |
|
1938 | 362 |
expl isNil ifTrue:[ |
363 |
definingNode parent notNil ifTrue:[ |
|
364 |
definingNode parent isMethod ifTrue:[ |
|
365 |
expl := namePart , ' is a method temporary.'. |
|
366 |
] ifFalse:[ |
|
367 |
definingNode parent isBlock ifTrue:[ |
|
368 |
expl := namePart , ' is a block temporary.'. |
|
369 |
] |
|
370 |
] |
|
1728 | 371 |
]. |
1938 | 372 |
]. |
373 |
expl isNil ifTrue:[ |
|
374 |
expl := namePart , ' is a temporary.' |
|
1728 | 375 |
]. |
1938 | 376 |
(cls allInstanceVariableNames includes:nm) ifTrue:[ |
377 |
expl := expl , ' (Instance Variable is hidden)' |
|
378 |
]. |
|
379 |
^ expl. |
|
1728 | 380 |
]. |
1938 | 381 |
|
1728 | 382 |
^ 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
|
383 |
|
1938 | 384 |
"Modified: / 07-11-2006 / 12:22:09 / cg" |
1728 | 385 |
! |
386 |
||
1909 | 387 |
fetchCommentOfMethod:mthd |
388 |
|methodComment lines| |
|
389 |
||
390 |
methodComment := mthd comment. |
|
391 |
methodComment isNil ifTrue:[^ nil]. |
|
392 |
||
393 |
lines := methodComment asStringCollection. |
|
394 |
methodComment := lines first. |
|
395 |
methodComment := methodComment withoutSeparators. |
|
396 |
(methodComment endsWith:',') ifTrue:[ methodComment := methodComment copyWithoutLast:1]. |
|
397 |
methodComment := methodComment withoutSeparators. |
|
398 |
(lines size > 1) ifTrue:[ |
|
2133 | 399 |
methodComment := methodComment , ' ...' |
1909 | 400 |
]. |
2225
caacd294cddc
no need for #asText to emphasize a string
Claus Gittinger <cg@exept.de>
parents:
2223
diff
changeset
|
401 |
^ ('"' , methodComment , '"') colorizeAllWith:(UserPreferences current commentColor). |
1909 | 402 |
|
403 |
"Created: / 14-09-2006 / 14:11:58 / cg" |
|
404 |
! |
|
405 |
||
1728 | 406 |
guessPossibleImplementorClassesFor:node in:code forClass:cls |
2191
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
407 |
"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
|
408 |
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
|
409 |
|
2292
e5ccd3d7a805
changed: #guessPossibleImplementorClassesFor:in:forClass:
Stefan Vogel <sv@exept.de>
parents:
2288
diff
changeset
|
410 |
|nm globalValue definer instances classesOfInstVars| |
1728 | 411 |
|
412 |
node isVariable ifTrue:[ |
|
413 |
nm := node name. |
|
414 |
||
2292
e5ccd3d7a805
changed: #guessPossibleImplementorClassesFor:in:forClass:
Stefan Vogel <sv@exept.de>
parents:
2288
diff
changeset
|
415 |
nm = #self ifTrue:[ |
1728 | 416 |
^ cls withAllSubclasses |
417 |
]. |
|
2292
e5ccd3d7a805
changed: #guessPossibleImplementorClassesFor:in:forClass:
Stefan Vogel <sv@exept.de>
parents:
2288
diff
changeset
|
418 |
nm = #here ifTrue:[ |
1728 | 419 |
^ cls withAllSuperclasses |
420 |
]. |
|
2292
e5ccd3d7a805
changed: #guessPossibleImplementorClassesFor:in:forClass:
Stefan Vogel <sv@exept.de>
parents:
2288
diff
changeset
|
421 |
nm = #super ifTrue:[ |
1728 | 422 |
^ cls allSuperclasses |
423 |
]. |
|
424 |
||
425 |
definer := node whoDefines:nm. |
|
426 |
definer isNil ifTrue:[ |
|
427 |
"/ not a local or argument |
|
428 |
(cls instanceVariableNames includes:nm) ifTrue:[ |
|
429 |
"/ ok - an instVar; see what values we find... |
|
430 |
instances := cls allSubInstances. |
|
431 |
classesOfInstVars := instances collect:[:eachInst | (eachInst instVarNamed:nm) class]. |
|
432 |
classesOfInstVars := classesOfInstVars asSet. |
|
433 |
^ classesOfInstVars. |
|
434 |
]. |
|
2191
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
435 |
(cls classVariableNames includes:nm) ifTrue:[ |
2292
e5ccd3d7a805
changed: #guessPossibleImplementorClassesFor:in:forClass:
Stefan Vogel <sv@exept.de>
parents:
2288
diff
changeset
|
436 |
^ Array with:(cls classVarAt:nm asSymbol) class. |
2191
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
437 |
]. |
1728 | 438 |
nm isUppercaseFirst ifTrue:[ |
439 |
nm knownAsSymbol ifTrue:[ |
|
440 |
globalValue := Smalltalk at:nm asSymbol. |
|
441 |
globalValue isClass ifTrue:[ |
|
442 |
^ Array with:globalValue class. |
|
443 |
]. |
|
444 |
]. |
|
1732 | 445 |
(cls topNameSpace notNil and:[cls topNameSpace ~~ Smalltalk]) ifTrue:[ |
446 |
globalValue := cls topNameSpace at:nm asSymbol. |
|
1728 | 447 |
globalValue isClass ifTrue:[ |
448 |
^ Array with:globalValue class. |
|
449 |
]. |
|
450 |
] |
|
451 |
]. |
|
452 |
]. |
|
453 |
^ nil |
|
454 |
]. |
|
455 |
||
456 |
node isLiteral ifTrue:[ |
|
457 |
^ Array with:(node value class) |
|
458 |
]. |
|
459 |
||
2191
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
460 |
"/ node isMessage ifTrue:[ |
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
461 |
"/ 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
|
462 |
"/ recClassSet isNil ifTrue:[ ^ nil ]. |
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
463 |
"/ recClassSet isEmpty ifTrue:[ ^ nil ]. |
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
464 |
"/ |
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
465 |
"/ 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
|
466 |
"/ "/ 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
|
467 |
"/ ^ rsltClassSet. |
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
468 |
"/ ]. |
1731 | 469 |
^ nil |
1728 | 470 |
! ! |
471 |
||
472 |
!Explainer class methodsFor:'explaining-naive'! |
|
473 |
||
1316
30806ca08095
commonSuperClassOf: - allow for classes and names in arg
Claus Gittinger <cg@exept.de>
parents:
1289
diff
changeset
|
474 |
commonSuperClassOf:listOfClassesOrClassNames |
1637 | 475 |
^ Behavior commonSuperclassOf:listOfClassesOrClassNames |
141 | 476 |
! |
477 |
||
2 | 478 |
explain:someText in:source forClass:aClass |
6 | 479 |
"Given a source and a substring of it, return a string containing |
480 |
an explanation. |
|
49 | 481 |
This is just a q&d implementation - to be correct, it should use the parser, |
482 |
and explain from the parsetree (instead of doing string matches). |
|
483 |
This leads to some wrong explanations, for example if some string is |
|
839 | 484 |
used as selector within a string, or if a variable is named like a |
485 |
message selector. I.e. the explanation should be context sensitive. |
|
49 | 486 |
Also, there could be much more detailed explanations." |
2 | 487 |
|
2037
003d9b5a2788
explain shared pool variables
Claus Gittinger <cg@exept.de>
parents:
2031
diff
changeset
|
488 |
^ self explain:someText in:source forClass:aClass short:false |
003d9b5a2788
explain shared pool variables
Claus Gittinger <cg@exept.de>
parents:
2031
diff
changeset
|
489 |
|
003d9b5a2788
explain shared pool variables
Claus Gittinger <cg@exept.de>
parents:
2031
diff
changeset
|
490 |
"Modified: / 07-06-2007 / 11:34:05 / cg" |
1183 | 491 |
! |
492 |
||
493 |
explain:someText in:source forClass:aClass short:shortText |
|
494 |
"Given a source and a substring of it, return a string containing |
|
495 |
an explanation. |
|
496 |
This is just a q&d implementation - to be correct, it should use the parser, |
|
497 |
and explain from the parsetree (instead of doing string matches). |
|
498 |
This leads to some wrong explanations, for example if some string is |
|
499 |
used as selector within a string, or if a variable is named like a |
|
500 |
message selector. I.e. the explanation should be context sensitive. |
|
501 |
Also, there could be much more detailed explanations." |
|
502 |
||
1159 | 503 |
|parser variables c string tmp |
1289 | 504 |
spc sym sel stringText clsName val valString| |
2 | 505 |
|
675 | 506 |
string := someText string withoutSeparators. |
2314
0c590d9937bd
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2292
diff
changeset
|
507 |
string isEmpty ifTrue:[ ^ nil ]. |
0c590d9937bd
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2292
diff
changeset
|
508 |
|
2214 | 509 |
stringText := string allBold. |
1233 | 510 |
stringText := '''' , stringText , ''''. |
49 | 511 |
|
512 |
" |
|
513 |
ask parser for variable names |
|
514 |
" |
|
1357 | 515 |
ParseErrorSignal catch:[ |
516 |
parser := self parseMethod:source in:aClass ignoreErrors:true ignoreWarnings:true. |
|
517 |
]. |
|
2002 | 518 |
(parser notNil and:[parser ~~ #Error]) ifTrue:[ |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
519 |
"look for variables" |
2 | 520 |
|
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
521 |
variables := parser methodVars. |
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
522 |
(variables notNil and:[variables includes:string]) ifTrue:[ |
1233 | 523 |
^ stringText , ' is a method variable.' |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
524 |
]. |
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
525 |
variables := parser methodArgs. |
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
526 |
(variables notNil and:[variables includes:string]) ifTrue:[ |
1233 | 527 |
^ stringText , ' is a method argument.' |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
528 |
] |
2 | 529 |
]. |
49 | 530 |
|
2 | 531 |
parser isNil ifTrue:[ |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
532 |
parser := self for:(ReadStream on:source) in:aClass |
2 | 533 |
]. |
534 |
||
535 |
"instvars" |
|
84 | 536 |
c := aClass whichClassDefinesInstVar:string. |
537 |
c notNil ifTrue:[ |
|
396 | 538 |
c isMeta ifTrue:[ |
1211
91e94e294819
isMeta/soleInstance -> theMetaclass / theNonMetaclass
Claus Gittinger <cg@exept.de>
parents:
1210
diff
changeset
|
539 |
clsName := c theNonMetaclass name. |
1198 | 540 |
shortText ifTrue:[ |
1233 | 541 |
^ stringText , ' is a class instVar in ' , clsName , '.' |
1198 | 542 |
]. |
2008 | 543 |
^ stringText, ' is a class instance variable inherited from ' , clsName , '.' |
396 | 544 |
]. |
545 |
||
1233 | 546 |
clsName := c name. |
1198 | 547 |
shortText ifTrue:[ |
1233 | 548 |
^ stringText , ' is an instVar in ' , clsName , '.' |
1198 | 549 |
]. |
2008 | 550 |
^ stringText , ' is an instance variable inherited from ' , clsName , '.' |
2 | 551 |
]. |
552 |
||
2315
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
553 |
string bitsPerCharacter == 8 ifTrue:[ |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
554 |
"classvars" |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
555 |
c := parser inWhichClassIsClassVar:string. |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
556 |
c notNil ifTrue:[ |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
557 |
clsName := c name. |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
558 |
shortText ifTrue:[ |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
559 |
stringText := stringText , ' is a classVar in ' , clsName |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
560 |
] ifFalse:[ |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
561 |
stringText := stringText , ' is a class variable in ' , clsName |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
562 |
]. |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
563 |
|
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
564 |
val := c theNonMetaclass classVarAt:string. "/ Smalltalk at:(clsName , ':' , string) asSymbol. |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
565 |
valString := self valueStringFor:val. |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
566 |
^ stringText , ' (' , valString , ').' |
1198 | 567 |
]. |
1693 | 568 |
|
2315
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
569 |
"private classes" |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
570 |
c := aClass theNonMetaclass. |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
571 |
c privateClasses do:[:pClass | |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
572 |
(pClass name = string |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
573 |
or:[pClass nameWithoutPrefix = string]) ifTrue:[ |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
574 |
stringText := stringText , ' is a private class in ''' , c name , '''.'. |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
575 |
shortText ifFalse:[ |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
576 |
stringText := (stringText , '\\It is only visible locally.') withCRs |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
577 |
]. |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
578 |
^ stringText withCRs |
1183 | 579 |
]. |
422 | 580 |
]. |
581 |
||
2315
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
582 |
aClass theNonMetaclass sharedPools do:[:eachPoolName | |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
583 |
|sharedPool| |
2037
003d9b5a2788
explain shared pool variables
Claus Gittinger <cg@exept.de>
parents:
2031
diff
changeset
|
584 |
|
2315
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
585 |
sharedPool := Smalltalk classNamed:eachPoolName. |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
586 |
sharedPool notNil ifTrue:[ |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
587 |
(sharedPool includesKey:string asSymbol) ifTrue:[ |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
588 |
stringText := stringText , ' is a pool variable in ',sharedPool name. |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
589 |
val := sharedPool at:string. |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
590 |
valString := self valueStringFor:val. |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
591 |
^ stringText , ' (' , valString , ').' |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
592 |
]. |
2037
003d9b5a2788
explain shared pool variables
Claus Gittinger <cg@exept.de>
parents:
2031
diff
changeset
|
593 |
]. |
003d9b5a2788
explain shared pool variables
Claus Gittinger <cg@exept.de>
parents:
2031
diff
changeset
|
594 |
]. |
003d9b5a2788
explain shared pool variables
Claus Gittinger <cg@exept.de>
parents:
2031
diff
changeset
|
595 |
|
2315
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
596 |
"namespace & global variables" |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
597 |
(spc := aClass nameSpace) notNil ifTrue:[ |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
598 |
sym := (spc name , '::' , string) asSymbolIfInterned. |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
599 |
sym notNil ifTrue:[ |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
600 |
(Smalltalk at:sym) isBehavior ifTrue:[ |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
601 |
string := stringText , ': '. |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
602 |
(Smalltalk at:sym) name = sym ifFalse:[ |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
603 |
string := stringText , 'refers to ',(Smalltalk at:sym) name,', ' |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
604 |
]. |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
605 |
string := stringText , 'a class in the ''' , spc name , ''' nameSpace'. |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
606 |
string := string , ' (in "', (Smalltalk at:sym) category ,'")'. |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
607 |
shortText ifFalse:[ |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
608 |
string := (string |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
609 |
, '\\It is only visible within this nameSpace.' |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
610 |
, '\Access from the outside is possible' |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
611 |
, '\by the special name ''' , spc name , '::' , string , '''.') withCRs |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
612 |
]. |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
613 |
^ string withCRs |
1979 | 614 |
]. |
796 | 615 |
]. |
422 | 616 |
]. |
617 |
||
2315
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
618 |
"/ string knownAsSymbol ifTrue:[ |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
619 |
"globals & symbols" |
2 | 620 |
|
2315
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
621 |
tmp := self explainKnownSymbol:string inClass:aClass short:shortText. |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
622 |
tmp notNil ifTrue:[ ^ tmp]. |
839 | 623 |
|
2315
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
624 |
"/ try with added colon ... |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
625 |
sel := string , ':'. |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
626 |
Symbol allInstancesDo:[:sym | |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
627 |
(sym startsWith:sel) ifTrue:[ |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
628 |
tmp := self explainKnownSymbol:sym inClass:aClass short:shortText. |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
629 |
tmp notNil ifTrue:[ ^ tmp]. |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
630 |
] |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
631 |
]. |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
632 |
"/ ]. |
2 | 633 |
|
2315
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
634 |
"try for some obvious things" |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
635 |
tmp := self explainPseudoVariable:string in:aClass short:true. |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
636 |
tmp notNil ifTrue:[ ^ tmp]. |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
637 |
]. |
2 | 638 |
|
639 |
"try syntax ..." |
|
640 |
||
1183 | 641 |
tmp := self explainSyntax:string short:shortText. |
49 | 642 |
tmp notNil ifTrue:[ ^ tmp]. |
20 | 643 |
|
1183 | 644 |
shortText ifTrue:[ |
1438 | 645 |
^ 'no explanation' |
1183 | 646 |
]. |
647 |
||
2 | 648 |
parser isNil ifTrue:[ |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
649 |
^ 'parse error - no explanation' |
2 | 650 |
]. |
796 | 651 |
^ 'cannot explain this (could not figure out what this is).' |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
652 |
|
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
653 |
"Created: / 03-12-1995 / 12:47:37 / cg" |
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
654 |
"Modified: / 16-04-1997 / 12:46:11 / stefan" |
2037
003d9b5a2788
explain shared pool variables
Claus Gittinger <cg@exept.de>
parents:
2031
diff
changeset
|
655 |
"Modified: / 07-06-2007 / 11:45:22 / cg" |
2 | 656 |
! |
657 |
||
1188 | 658 |
explainGlobal:string inClass:aClass short:shortText |
1183 | 659 |
"return explanation or nil" |
660 |
||
1245 | 661 |
|sym stringText tmp val classCategory| |
141 | 662 |
|
1245 | 663 |
"if not even known as key, its definitely not a global" |
664 |
sym := string asSymbolIfInterned. |
|
796 | 665 |
sym isNil ifTrue:[^ nil]. |
141 | 666 |
|
667 |
"try globals" |
|
1245 | 668 |
(Smalltalk includesKey:sym) ifFalse:[ ^ nil]. |
141 | 669 |
|
2191
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
670 |
stringText := string allBold. |
1198 | 671 |
|
1245 | 672 |
"/ stringText := '''' , stringText , ''''. |
1979 | 673 |
stringText := stringText , ': '. |
674 |
tmp := stringText , 'a global variable.'. |
|
1183 | 675 |
|
1245 | 676 |
val := Smalltalk at:sym. |
677 |
val isBehavior ifTrue:[ |
|
678 |
"/ a class |
|
1979 | 679 |
val name = sym ifFalse:[ |
680 |
stringText := stringText , ' refers to ',val name,', '. |
|
681 |
]. |
|
682 |
||
1943 | 683 |
(val isRealNameSpace) ifTrue:[ |
1979 | 684 |
^ stringText , 'a namespace.' |
1330 | 685 |
]. |
686 |
||
687 |
classCategory := val category ? 'uncategorized'. |
|
1245 | 688 |
shortText ifTrue:[ |
1979 | 689 |
^ stringText , (val isLoaded ifTrue:['a'] ifFalse:['an autoloaded']) |
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
690 |
, ' class in ',val package,' {' , classCategory , '}.'. |
1245 | 691 |
]. |
692 |
||
693 |
val name = string ifTrue:[ |
|
1183 | 694 |
tmp := tmp , ' |
1245 | 695 |
' , string , ' is ' , (val isLoaded ifTrue:['a'] ifFalse:['an autoloaded']) |
696 |
, ' class categorized as ' , classCategory , ' |
|
697 |
in the ''' , val package , ''' package.'. |
|
1183 | 698 |
^ tmp. |
699 |
]. |
|
141 | 700 |
|
1183 | 701 |
tmp := tmp , ' |
702 |
||
1245 | 703 |
' , string , ' is bound to the class ' , val name , |
704 |
' in the ''' , classCategory , ''' category.'. |
|
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
705 |
^ tmp. |
141 | 706 |
]. |
707 |
||
1245 | 708 |
shortText ifTrue:[ |
1674 | 709 |
val isNil ifTrue:[ |
1979 | 710 |
^ stringText , 'a global, currently nil.'. |
1674 | 711 |
]. |
1979 | 712 |
^ stringText , 'a global, currently bound to ''' , val classNameWithArticle , '''.'. |
1245 | 713 |
]. |
714 |
tmp := tmp , ' |
|
715 |
||
716 |
Its current value is ''' , val classNameWithArticle , '''.'. |
|
717 |
^ tmp. |
|
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
718 |
|
1979 | 719 |
"Modified: / 06-02-2007 / 19:32:15 / cg" |
1188 | 720 |
! |
721 |
||
722 |
explainHereIn:aClass |
|
723 |
^ 'like self, here refers to the object which received the message. |
|
724 |
||
725 |
However, when sending a message to here the search for methods |
|
726 |
implementing this message will start in the defining class (' , aClass name , ') |
|
727 |
instead of the receivers class (' , aClass name , ' or subclass). |
|
728 |
Thus, using here, redefined methods will NOT be reached with a here-send.' |
|
729 |
! |
|
730 |
||
731 |
explainKnownSymbol:string inClass:aClass |
|
732 |
"return explanation or nil" |
|
733 |
||
734 |
^ self explainKnownSymbol:string inClass:aClass short:false |
|
735 |
! |
|
736 |
||
737 |
explainKnownSymbol:string inClass:aClass short:shortText |
|
738 |
"return explanation or nil" |
|
739 |
||
740 |
|sym| |
|
741 |
||
742 |
sym := string asSymbolIfInterned. |
|
743 |
sym isNil ifTrue:[^ nil]. |
|
744 |
||
745 |
"try globals" |
|
746 |
||
747 |
(Smalltalk includesKey:sym) ifTrue:[ |
|
748 |
^ self explainGlobal:string inClass:aClass short:shortText |
|
749 |
]. |
|
750 |
||
751 |
^ self explainSelector:string inClass:aClass short:shortText |
|
752 |
! |
|
753 |
||
754 |
explainPseudoVariable:string in:aClass |
|
755 |
"return explanation for the pseudoVariables self, super etc." |
|
756 |
||
757 |
^ self explainPseudoVariable:string in:aClass short:false |
|
758 |
! |
|
759 |
||
760 |
explainPseudoVariable:string in:aClass short:shortText |
|
761 |
"return explanation for the pseudoVariables self, super etc." |
|
762 |
||
763 |
(string = 'self') ifTrue:[ |
|
764 |
^ self explainSelfIn:aClass short:shortText |
|
765 |
]. |
|
766 |
||
767 |
(string = 'super') ifTrue:[ |
|
768 |
shortText ifTrue:[ |
|
769 |
^ '''super'' - message lookup starts in superclass ''' , aClass superclass name , '''.' |
|
770 |
]. |
|
771 |
^ self explainSuperIn:aClass short:shortText |
|
772 |
]. |
|
773 |
||
774 |
(string = 'here') ifTrue:[ |
|
775 |
shortText ifTrue:[ |
|
776 |
^ '''here'' - message lookup always starts in ''' , aClass name , '''.' |
|
777 |
]. |
|
778 |
^ self explainHereIn:aClass |
|
779 |
]. |
|
780 |
||
781 |
(string = 'thisContext') ifTrue:[ |
|
782 |
shortText ifTrue:[ |
|
783 |
^ '''thisContext'' - the current stack frame as an object.' |
|
784 |
]. |
|
785 |
^ 'thisContext is a pseudo variable (i.e. it is built in). |
|
786 |
||
787 |
ThisContext always refers to the context object for the currently executed method or |
|
788 |
block (an instance of Context or BlockContext respectively). The calling chain and calling |
|
789 |
receivers/selectors can be accessed via thisContext.' |
|
790 |
]. |
|
791 |
||
792 |
(string = 'true') ifTrue:[ |
|
793 |
shortText ifTrue:[ |
|
794 |
^ '''true'' - the truth and nothing but the truth.' |
|
795 |
]. |
|
796 |
^ 'true is a pseudo variable (i.e. it is built in). |
|
797 |
||
798 |
True represents logical truth. It is the one and only instance of class True.' |
|
799 |
]. |
|
800 |
||
801 |
(string = 'false') ifTrue:[ |
|
802 |
shortText ifTrue:[ |
|
803 |
^ '''false'' - obvisously not true.' |
|
804 |
]. |
|
805 |
^ 'false is a pseudo variable (i.e. it is built in). |
|
806 |
||
807 |
False represents logical falseness. It is the one and only instance of class False.' |
|
808 |
]. |
|
809 |
||
810 |
(string = 'nil') ifTrue:[ |
|
811 |
shortText ifTrue:[ |
|
812 |
^ '''nil'' - undefined, unknown, void or dont care.' |
|
813 |
]. |
|
814 |
^ 'nil is a pseudo variable (i.e. it is built in). |
|
815 |
||
816 |
Nil is used for unitialized variables (among other uses). |
|
817 |
Nil is the one and only instance of class UndefinedObject.' |
|
818 |
]. |
|
819 |
^ nil |
|
820 |
! |
|
821 |
||
822 |
explainSelector:string inClass:aClass short:shortText |
|
823 |
"return explanation or nil" |
|
824 |
||
2288
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
825 |
|sym list listSimilar firstImplementingClassOfSimilar count tmp commonSuperClass s s2 |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
826 |
firstImplementingClass cm msg t check| |
1188 | 827 |
|
828 |
sym := string asSymbolIfInterned. |
|
829 |
sym isNil ifTrue:[^ nil]. |
|
830 |
||
141 | 831 |
" |
832 |
try selectors |
|
833 |
look who implements it |
|
834 |
" |
|
835 |
list := Set new. |
|
2288
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
836 |
listSimilar := Set new. |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
837 |
|
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
838 |
check := |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
839 |
[:sel :mthd :cls | |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
840 |
sel == sym ifTrue:[ |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
841 |
list add:(cls name). |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
842 |
firstImplementingClass isNil ifTrue:[ |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
843 |
firstImplementingClass := cls |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
844 |
] |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
845 |
] ifFalse:[ |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
846 |
(sel startsWith:sym) ifTrue:[ |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
847 |
listSimilar add:sel. |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
848 |
firstImplementingClassOfSimilar isNil ifTrue:[ |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
849 |
firstImplementingClassOfSimilar := cls |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
850 |
] |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
851 |
] |
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
852 |
] |
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
853 |
]. |
2288
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
854 |
|
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
855 |
Smalltalk allClassesDo:[:c| |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
856 |
c methodDictionary keysAndValuesDo:[:sel :mthd | |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
857 |
check value:sel value:mthd value:c |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
858 |
]. |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
859 |
c class methodDictionary keysAndValuesDo:[:sel :mthd | |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
860 |
check value:sel value:mthd value:c class |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
861 |
]. |
141 | 862 |
]. |
863 |
||
835 | 864 |
(aClass canUnderstand:sym) ifTrue:[ |
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
865 |
s2 := ('Instances of ''' , aClass name , ''' respond to #') , sym "allBold" , '.'. |
1184 | 866 |
shortText ifFalse:[ |
867 |
s2 := '\\' , s2 |
|
868 |
, '\- inherited from ' withCRs |
|
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
869 |
, (aClass whichClassIncludesSelector:sym) name "allBold". |
1184 | 870 |
]. |
1761 | 871 |
firstImplementingClass := (aClass whichClassIncludesSelector:sym) |
835 | 872 |
] ifFalse:[ |
873 |
s2 := ''. |
|
874 |
]. |
|
875 |
||
141 | 876 |
count := list size. |
877 |
(count ~~ 0) ifTrue:[ |
|
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
878 |
" |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
879 |
for up-to 4 implementing classes, |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
880 |
list them |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
881 |
" |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
882 |
list := list asOrderedCollection sort. |
1185 | 883 |
shortText ifTrue:[ |
884 |
tmp := ' is implemented in '. |
|
885 |
] ifFalse:[ |
|
886 |
tmp := ' is a selector implemented in '. |
|
887 |
]. |
|
2191
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
888 |
s := "'#' ," string allBold. |
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
889 |
|
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
890 |
(count == 1) ifTrue:[ |
1183 | 891 |
(t := list first) isMeta ifTrue:[ |
892 |
t := 'the ' , t |
|
893 |
]. |
|
1184 | 894 |
msg := s , tmp , t , '.'. |
895 |
shortText ifFalse:[ |
|
896 |
msg := msg , s2. |
|
897 |
] |
|
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
898 |
] ifFalse:[ |
1185 | 899 |
(count == 2) ifTrue:[ |
900 |
msg := s , tmp , (list at:1) , ' and ' , (list at:2) , '.'. |
|
901 |
shortText ifFalse:[ |
|
902 |
msg := msg , s2. |
|
903 |
]. |
|
904 |
] ifFalse:[ |
|
905 |
shortText ifTrue:[ |
|
1428 | 906 |
msg := s , tmp , count printString , ' classes'. |
1637 | 907 |
commonSuperClass := Class commonSuperclassOf:list. |
1428 | 908 |
(commonSuperClass == Object |
909 |
and:[commonSuperClass includesSelector:sym]) ifTrue:[ |
|
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
910 |
msg := msg , ' (including ' , 'Object' "allBold", ')' |
1428 | 911 |
]. |
912 |
msg := msg , '.'. |
|
1185 | 913 |
^ msg |
914 |
]. |
|
1183 | 915 |
|
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
916 |
(count == 3) ifTrue:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
917 |
msg := s , tmp , ' |
835 | 918 |
' , (list at:1) , ', ' , (list at:2) , ' and ' , (list at:3) , '.' , s2 |
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
919 |
] ifFalse:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
920 |
(count == 4) ifTrue:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
921 |
msg := s , tmp , ' |
835 | 922 |
' , (list at:1) , ', ' , (list at:2) , ', ' , (list at:3), ' and ' , (list at:4) , '.' , s2 |
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
923 |
] ifFalse:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
924 |
" |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
925 |
if there are more, look for a common |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
926 |
superclass and show it ... |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
927 |
" |
1637 | 928 |
commonSuperClass := Behavior commonSuperclassOf:list. |
913 | 929 |
(commonSuperClass ~~ Object |
930 |
and:[commonSuperClass ~~ Behavior |
|
931 |
and:[commonSuperClass ~~ Class |
|
932 |
and:[commonSuperClass ~~ ClassDescription]]]) ifTrue:[ |
|
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
933 |
(list includes:commonSuperClass) ifTrue:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
934 |
msg := s . tmp , count printString , commonSuperClass name |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
935 |
, ' and redefined in ' , (count - 1) printString |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
936 |
, ' subclasses' |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
937 |
, s2. |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
938 |
firstImplementingClass := commonSuperClass |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
939 |
] ifFalse:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
940 |
msg := s , tmp, count printString , ' subclasses of ' , commonSuperClass name , s2 |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
941 |
] |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
942 |
] ifFalse:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
943 |
(commonSuperClass == Object |
1249
780b4a1a3967
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1245
diff
changeset
|
944 |
and:[commonSuperClass includesSelector:sym]) ifTrue:[ |
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
945 |
msg := s , tmp , count printString , ' classes. |
834 | 946 |
|
947 |
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
|
948 |
since there is an implementation in Object.' , s2. |
141 | 949 |
|
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
950 |
firstImplementingClass := Object |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
951 |
] ifFalse:[ |
913 | 952 |
((commonSuperClass == Behavior |
953 |
or:[commonSuperClass == Class |
|
954 |
or:[commonSuperClass == ClassDescription]]) |
|
1249
780b4a1a3967
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1245
diff
changeset
|
955 |
and:[commonSuperClass includesSelector:sym]) ifTrue:[ |
913 | 956 |
msg := s , tmp , count printString , ' classes. |
957 |
||
958 |
All classes seem to respond to that message, |
|
959 |
since there is an implementation in ' , commonSuperClass name , '.' , s2. |
|
960 |
||
961 |
firstImplementingClass := commonSuperClass |
|
962 |
] ifFalse:[ |
|
963 |
" |
|
964 |
otherwise just give the number. |
|
965 |
" |
|
966 |
msg := s , tmp , count printString , ' classes.' , s2 |
|
967 |
] |
|
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
968 |
] |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
969 |
] |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
970 |
] |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
971 |
] |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
972 |
]. |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
973 |
]. |
1909 | 974 |
shortText ifTrue:[ |
975 |
count == 1 ifTrue:[ |
|
1910 | 976 |
cm := self fetchCommentOfMethod:(firstImplementingClass compiledMethodAt:sym). |
977 |
cm notNil ifTrue:[ |
|
978 |
msg := msg,' ',cm |
|
979 |
]. |
|
1909 | 980 |
]. |
981 |
] ifFalse:[ |
|
1185 | 982 |
firstImplementingClass notNil ifTrue:[ |
983 |
WindowGroup activeGroup withWaitCursorDo:[ |
|
984 |
cm := firstImplementingClass compiledMethodAt:sym. |
|
985 |
cm notNil ifTrue:[ |
|
986 |
cm := cm methodComment. |
|
987 |
] |
|
988 |
]. |
|
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
989 |
cm notNil ifTrue:[ |
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
990 |
msg := msg , '\\The comment in ' withCRs , firstImplementingClass name "allBold" , ' is:\' withCRs , cm allItalic. |
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
991 |
] |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
992 |
]. |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
993 |
]. |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
994 |
^ msg |
141 | 995 |
]. |
996 |
||
2288
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
997 |
count := listSimilar size. |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
998 |
(count ~~ 0) ifTrue:[ |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
999 |
listSimilar := listSimilar asOrderedCollection sort. |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1000 |
shortText ifTrue:[ |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1001 |
tmp := ' is implemented in '. |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1002 |
] ifFalse:[ |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1003 |
tmp := ' is a selector implemented in '. |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1004 |
]. |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1005 |
|
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1006 |
(count == 1) ifTrue:[ |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1007 |
msg := listSimilar first allBold , tmp , firstImplementingClassOfSimilar name , '.'. |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1008 |
shortText ifFalse:[ |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1009 |
msg := msg , s2. |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1010 |
] |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1011 |
] ifFalse:[ |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1012 |
msg := 'similar selectors: %1, %2' bindWith:listSimilar first allBold with:listSimilar second allBold. |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1013 |
count > 2 ifTrue:[ |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1014 |
msg := msg,'...'. |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1015 |
]. |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1016 |
]. |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1017 |
^ msg |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1018 |
]. |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1019 |
|
141 | 1020 |
^ nil |
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
1021 |
|
1909 | 1022 |
"Modified: / 17-06-1996 / 17:09:30 / stefan" |
1023 |
"Created: / 23-03-1999 / 13:29:33 / cg" |
|
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
1024 |
"Modified: / 09-10-2006 / 12:11:58 / cg" |
141 | 1025 |
! |
1026 |
||
1183 | 1027 |
explainSelfIn:aClass short:shortText |
1244 | 1028 |
|sub subNames selfString className nSubClasses| |
1198 | 1029 |
|
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
1030 |
selfString := '''' , 'self' "allBold" , ''''. |
6 | 1031 |
|
1244 | 1032 |
sub := aClass allSubclasses. |
1033 |
nSubClasses := sub size. |
|
1034 |
||
1035 |
aClass isMeta ifTrue:[ |
|
1036 |
className := aClass theNonMetaclass name. |
|
1037 |
subNames := sub collect:[:c | c theNonMetaclass name]. |
|
1038 |
nSubClasses == 0 ifTrue:[ |
|
1039 |
shortText ifTrue:[ |
|
1040 |
^ selfString , ' - the ''' , className , '''-class.' |
|
1041 |
]. |
|
1042 |
^ selfString , 'refers to the object which received the message. |
|
1043 |
||
1044 |
In this case, it will be the ' , className , '-class itself.' |
|
1045 |
]. |
|
1046 |
||
1047 |
shortText ifTrue:[ |
|
1048 |
nSubClasses == 1 ifTrue:[ |
|
1049 |
^ selfString , ' - the ''' , className , '''- or ''' , subNames first , '''-class.' |
|
1050 |
]. |
|
1051 |
^ selfString , ' - the ''' , className , '''-class or one of its subclasses.' |
|
1052 |
]. |
|
1053 |
nSubClasses <= 5 ifTrue:[ |
|
1054 |
^ selfString , ' refers to the object which received the message. |
|
1055 |
||
1056 |
In this case, it will be the ' , className , '-class |
|
1057 |
or one of its subclasses: |
|
1058 |
||
1059 |
' , subNames asStringCollection asString |
|
1060 |
]. |
|
1061 |
||
1062 |
^ selfString , ' refers to the object which received the message. |
|
1063 |
||
1064 |
In this case, it will be the ' , className , '-class |
|
1065 |
or one of its ' , nSubClasses printString , ' subclasses.' |
|
1066 |
]. |
|
1067 |
||
1256 | 1068 |
subNames := aClass allSubclasses collect:[:c | c theNonMetaclass name]. |
1244 | 1069 |
className := aClass name. |
1070 |
nSubClasses == 0 ifTrue:[ |
|
1183 | 1071 |
shortText ifTrue:[ |
1244 | 1072 |
^ selfString , ' - an instance of ''' , className , '''.' |
1183 | 1073 |
]. |
1198 | 1074 |
^ selfString , 'refers to the object which received the message. |
6 | 1075 |
|
1244 | 1076 |
In this case, it will be an instance of ' , className , '.' |
6 | 1077 |
]. |
1078 |
||
1183 | 1079 |
shortText ifTrue:[ |
1244 | 1080 |
nSubClasses == 1 ifTrue:[ |
1256 | 1081 |
^ selfString , ' - an instance of ''' , className , ''' or ''' , subNames first , '''.' |
1185 | 1082 |
]. |
1244 | 1083 |
^ selfString , ' - an instance of ''' , className , ''' or one of its subclasses.' |
1183 | 1084 |
]. |
1244 | 1085 |
nSubClasses <= 5 ifTrue:[ |
1198 | 1086 |
^ selfString , ' refers to the object which received the message. |
6 | 1087 |
|
1244 | 1088 |
In this case, it will be an instance of ' , className , ' |
6 | 1089 |
or one of its subclasses: |
1090 |
||
1256 | 1091 |
' , subNames asStringCollection asString |
6 | 1092 |
]. |
1093 |
||
1198 | 1094 |
^ selfString , ' refers to the object which received the message. |
6 | 1095 |
|
1244 | 1096 |
In this case, it will be an instance of ' , className , ' |
1097 |
or one of its ' , nSubClasses printString , ' subclasses.' |
|
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
1098 |
|
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
1099 |
"Modified: / 09-10-2006 / 12:11:44 / cg" |
6 | 1100 |
! |
1101 |
||
1188 | 1102 |
explainSuperIn:aClass short:shortText |
1352 | 1103 |
|superName| |
1244 | 1104 |
|
1105 |
superName := aClass superclass name. |
|
1188 | 1106 |
|
1107 |
shortText ifTrue:[ |
|
1244 | 1108 |
^ '''super'' - message lookup starts in ' , superName , '.' |
1188 | 1109 |
]. |
1110 |
||
6 | 1111 |
^ 'like self, super refers to the object which received the message. |
1112 |
||
1113 |
However, when sending a message to super the search for methods |
|
1244 | 1114 |
implementing this message will start in the superclass (' , superName , ') |
84 | 1115 |
instead of the receivers class (' , aClass name , ' or subclass). |
49 | 1116 |
Thus, using super, a redefined method can call the original method in its superclass.' |
6 | 1117 |
! |
2 | 1118 |
|
49 | 1119 |
explainSyntax:string |
1120 |
"try syntax ...; return explanation or nil" |
|
1121 |
||
1183 | 1122 |
^ self explainSyntax:string short:false |
1123 |
! |
|
1124 |
||
1125 |
explainSyntax:string short:shortText |
|
1126 |
"try syntax ...; return explanation or nil" |
|
1127 |
||
49 | 1128 |
((string = ':=') or:[string = '_']) ifTrue:[ |
1183 | 1129 |
shortText ifTrue:[ |
1130 |
^ 'Assign to variable on the left side.'. |
|
1131 |
]. |
|
1132 |
||
796 | 1133 |
^ '<variable> := <expression> |
49 | 1134 |
|
834 | 1135 |
'':='' and ''_'' (which is left-arrow in some fonts) mean assignment. |
49 | 1136 |
The variable is bound to (i.e. points to) the value of <expression>.' |
1137 |
]. |
|
1138 |
||
1139 |
(string = '^') ifTrue:[ |
|
1183 | 1140 |
shortText ifTrue:[ |
1141 |
^ 'Return value from method.'. |
|
1142 |
]. |
|
796 | 1143 |
^ '^ <expression> |
49 | 1144 |
|
834 | 1145 |
returns the value of <expression> as value from the method. |
49 | 1146 |
A return from within a block exits the method where the block is defined.' |
1147 |
]. |
|
1148 |
||
1149 |
(string = ';') ifTrue:[ |
|
1183 | 1150 |
shortText ifTrue:[ |
1151 |
^ 'Cascade expression.'. |
|
1152 |
]. |
|
796 | 1153 |
^ '<expression> ; selector1 ; .... ; selectorN |
49 | 1154 |
|
1155 |
a cascade expression; evaluate expression, and send messages |
|
1156 |
<selector1> ... <selectorN> to the first expressions receiver. |
|
1157 |
Returns the value of the last send. The cascade sends may also have arguments.' |
|
1158 |
]. |
|
1159 |
||
1160 |
(string = '|') ifTrue:[ |
|
1183 | 1161 |
shortText ifTrue:[ |
1162 |
^ ''. |
|
1163 |
]. |
|
796 | 1164 |
^ '| locals | or: [:arg | statements] |
49 | 1165 |
|
834 | 1166 |
''|'' is used to mark a local variable declaration or separates arguments |
49 | 1167 |
from the statements in a block. Notice, that in a block-argument declaration |
1168 |
these must be prefixed by a colon character. |
|
834 | 1169 |
''|'' is also a selector understood by Booleans.' |
49 | 1170 |
]. |
1171 |
||
2287
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1172 |
(string startsWith:'#' ) ifTrue:[ |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1173 |
(string startsWith:'#(' ) ifTrue:[ |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1174 |
shortText ifTrue:[ |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1175 |
^ 'Array Literal.'. |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1176 |
]. |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1177 |
^ 'is a constant Array. |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1178 |
|
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1179 |
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
|
1180 |
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
|
1181 |
The elements of a constant Array must be numbers, strings, symbols, nil, true or false, |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1182 |
another array constant or a byte-array. |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1183 |
(notice, that not all Smalltalk implementations allow true, false and nil as |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1184 |
constant-Array elements).' |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1185 |
]. |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1186 |
|
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1187 |
(string startsWith:'#[') ifTrue:[ |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1188 |
shortText ifTrue:[ |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1189 |
^ 'ByteArray Literal.'. |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1190 |
]. |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1191 |
^ 'is a constant ByteArray. |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1192 |
|
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1193 |
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
|
1194 |
0 .. 255. |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1195 |
(notice, that not all Smalltalk implementations support constant ByteArrays).' |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1196 |
]. |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1197 |
|
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1198 |
(string startsWith:'#''') ifTrue:[ |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1199 |
shortText ifTrue:[ |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1200 |
^ 'Symbol Literal.'. |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1201 |
]. |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1202 |
^ 'is a constant symbol containing non-alphanumeric characters. |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1203 |
|
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1204 |
Symbols are unique strings, meaning that there exists |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1205 |
exactly one instance of a given symbol. Therefore symbols can |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1206 |
be compared using == (identity compare) in addition to = (contents compare). |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1207 |
Beside this, Symbols behave mostly like Strings. |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1208 |
|
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1209 |
Notice, that not all Smalltalk implementations support this kind of symbols.' |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1210 |
]. |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1211 |
|
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1212 |
shortText ifTrue:[ |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1213 |
^ 'Symbol Literal.'. |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1214 |
]. |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1215 |
^ 'is a symbol. |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1216 |
|
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1217 |
Symbols are unique strings, meaning that there exists |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1218 |
exactly one instance of a given symbol. Therefore symbols can |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1219 |
be compared using == (identity compare) in addition to = (contents compare). |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1220 |
Beside this, Symbols behave mostly like Strings.' |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1221 |
]. |
49 | 1222 |
((string startsWith:'(') or:[string endsWith:')']) ifTrue:[ |
1183 | 1223 |
shortText ifTrue:[ |
1224 |
^ ''. |
|
1225 |
]. |
|
796 | 1226 |
^ '(<expression>) |
49 | 1227 |
|
1228 |
expression grouping.' |
|
1229 |
]. |
|
1230 |
||
1231 |
((string startsWith:'[') or:[string endsWith:']']) ifTrue:[ |
|
1183 | 1232 |
shortText ifTrue:[ |
1233 |
^ ''. |
|
1234 |
]. |
|
834 | 1235 |
^ '[:arg1 .. :argN | statements] |
49 | 1236 |
|
1237 |
defines a block. |
|
1238 |
Blocks represent pieces of executable code. Definition of a block does |
|
1239 |
not evaluate it. The block is evaluated by sending it a value/value: |
|
1240 |
message. |
|
1241 |
Blocks are often passed as arguments to Booleans (i.e. ifTrue:[...]) or |
|
1242 |
collections (i.e. do:[...]).' |
|
1243 |
]. |
|
1244 |
||
2286
cabf7db33a38
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2226
diff
changeset
|
1245 |
((string startsWith:'{') or:[string endsWith:'}']) ifTrue:[ |
cabf7db33a38
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2226
diff
changeset
|
1246 |
shortText ifTrue:[ |
cabf7db33a38
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2226
diff
changeset
|
1247 |
^ 'array instantiation'. |
cabf7db33a38
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2226
diff
changeset
|
1248 |
]. |
cabf7db33a38
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2226
diff
changeset
|
1249 |
^ '{ <expr1>. .. <exprN> } |
cabf7db33a38
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2226
diff
changeset
|
1250 |
|
cabf7db33a38
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2226
diff
changeset
|
1251 |
is syntactic sugar for "Array with:<expr1> .. with:<exprN>". |
cabf7db33a38
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2226
diff
changeset
|
1252 |
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
|
1253 |
The expressions are separated by a period statement separator. |
cabf7db33a38
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2226
diff
changeset
|
1254 |
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
|
1255 |
when executed (as opposed to an array literal, which is computed only once at |
cabf7db33a38
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2226
diff
changeset
|
1256 |
compilation time) and which is shared.' |
cabf7db33a38
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2226
diff
changeset
|
1257 |
]. |
cabf7db33a38
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2226
diff
changeset
|
1258 |
|
49 | 1259 |
(string = ':') ifTrue:[ |
1183 | 1260 |
shortText ifTrue:[ |
1261 |
^ ''. |
|
1262 |
]. |
|
796 | 1263 |
^ 'colons have different meaning depending on context: |
49 | 1264 |
|
1265 |
1) they separate keyword-parts in symbols and keyword-messages as in: |
|
1266 |
||
1267 |
#at:put: a constant keyword symbol |
|
1268 |
||
1269 |
rec at:index put:value sends the #at:put: message to rec, |
|
796 | 1270 |
passing index and value as arguments. |
49 | 1271 |
|
1272 |
2) within block-argument declarations as in: |
|
1273 |
||
1274 |
[:arg1 :arg2 | statements] |
|
834 | 1275 |
|
1276 |
3) within an identifier, they separate the nameSpace part from |
|
1277 |
the name part; as in: |
|
1278 |
||
1279 |
Smalltalk::Array - the Array class in the Smalltalk nameSpace. |
|
1280 |
Foo::Array - the Array class in the Foo nameSpace. |
|
49 | 1281 |
' |
1282 |
]. |
|
1283 |
||
1284 |
(string = '.') ifTrue:[ |
|
796 | 1285 |
^ 'statement. "<- period here" |
49 | 1286 |
statement |
1287 |
||
1288 |
within a method or block, individual statements are separated by periods. |
|
1289 |
' |
|
1290 |
]. |
|
1291 |
||
1292 |
"/ is it a symbol without hash-character ? |
|
1293 |
"/ |
|
796 | 1294 |
"/ string knownAsSymbol ifTrue:[ |
1295 |
"/ ^ 'is nothing, but #' , string , ' is known as a symbol. |
|
1296 |
"/ |
|
1297 |
"/Symbols are unique strings, meaning that there exists |
|
1298 |
"/exactly one instance of a given symbol. Therefore symbols can |
|
1299 |
"/be compared using == (identity compare) in addition to = (contents compare). |
|
1300 |
"/Beside this, Symbols behave mostly like Strings.' |
|
1301 |
"/ ]. |
|
49 | 1302 |
|
1303 |
^ nil |
|
796 | 1304 |
|
1305 |
"Modified: / 31.10.1998 / 14:28:58 / cg" |
|
2214 | 1306 |
! |
1307 |
||
1308 |
valueStringFor:aValue |
|
1309 |
|valString| |
|
1310 |
||
1311 |
"/ only show the value, if it is really short... |
|
1312 |
(aValue isBoolean or:[aValue isNil]) ifTrue:[ |
|
2226 | 1313 |
^ aValue storeString. |
1314 |
]. |
|
1315 |
(aValue isNumber |
|
1316 |
or:[aValue isPoint]) ifTrue:[ |
|
1317 |
^ aValue storeString. |
|
1318 |
]. |
|
1319 |
(aValue isColor) ifTrue:[ |
|
1320 |
^ 'Color: ',(' ' emphasizeAllWith:(#backgroundColor->aValue)). |
|
1321 |
]. |
|
1322 |
||
1323 |
(aValue isString) ifTrue:[ |
|
2214 | 1324 |
valString := aValue storeString. |
2226 | 1325 |
"/ valString := aValue className, ' ' , aValue storeString . |
2214 | 1326 |
]. |
1327 |
||
1328 |
(valString isEmptyOrNil |
|
1329 |
or:[ valString size > 30 |
|
1330 |
or:[ valString includes:Character cr ]]) ifTrue:[ |
|
1331 |
valString := aValue classNameWithArticle. |
|
1332 |
]. |
|
1333 |
||
1334 |
^ valString |
|
141 | 1335 |
! ! |
49 | 1336 |
|
396 | 1337 |
!Explainer class methodsFor:'documentation'! |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
1338 |
|
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
1339 |
version |
2315
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
1340 |
^ '$Header: /cvs/stx/stx/libcomp/Explainer.st,v 1.100 2009-12-14 13:45:43 cg Exp $' |
2214 | 1341 |
! |
1342 |
||
1343 |
version_CVS |
|
2315
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
1344 |
^ '$Header: /cvs/stx/stx/libcomp/Explainer.st,v 1.100 2009-12-14 13:45:43 cg Exp $' |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
1345 |
! ! |