author | Claus Gittinger <cg@exept.de> |
Thu, 22 Oct 2009 14:42:13 +0200 | |
changeset 2225 | caacd294cddc |
parent 2223 | 50b76baab48b |
child 2226 | d628e2ef289e |
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, |
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
408 |
return a collection of possible receiver classes. |
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
409 |
" |
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
410 |
|
1728 | 411 |
|nm globalValue recClassSet rsltClassSet implSet definer instances classesOfInstVars| |
412 |
||
413 |
node isVariable ifTrue:[ |
|
414 |
nm := node name. |
|
415 |
||
416 |
nm = 'self' ifTrue:[ |
|
417 |
^ cls withAllSubclasses |
|
418 |
]. |
|
419 |
nm = 'here' ifTrue:[ |
|
420 |
^ cls withAllSuperclasses |
|
421 |
]. |
|
422 |
nm = 'super' ifTrue:[ |
|
423 |
^ cls allSuperclasses |
|
424 |
]. |
|
425 |
||
426 |
definer := node whoDefines:nm. |
|
427 |
definer isNil ifTrue:[ |
|
428 |
"/ not a local or argument |
|
429 |
(cls instanceVariableNames includes:nm) ifTrue:[ |
|
430 |
"/ ok - an instVar; see what values we find... |
|
431 |
instances := cls allSubInstances. |
|
432 |
classesOfInstVars := instances collect:[:eachInst | (eachInst instVarNamed:nm) class]. |
|
433 |
classesOfInstVars := classesOfInstVars asSet. |
|
434 |
^ classesOfInstVars. |
|
435 |
]. |
|
2191
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
436 |
(cls classVariableNames includes:nm) ifTrue:[ |
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
437 |
self halt. |
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
438 |
]. |
1728 | 439 |
nm isUppercaseFirst ifTrue:[ |
440 |
nm knownAsSymbol ifTrue:[ |
|
441 |
globalValue := Smalltalk at:nm asSymbol. |
|
442 |
globalValue isClass ifTrue:[ |
|
443 |
^ Array with:globalValue class. |
|
444 |
]. |
|
445 |
]. |
|
1732 | 446 |
(cls topNameSpace notNil and:[cls topNameSpace ~~ Smalltalk]) ifTrue:[ |
447 |
globalValue := cls topNameSpace at:nm asSymbol. |
|
1728 | 448 |
globalValue isClass ifTrue:[ |
449 |
^ Array with:globalValue class. |
|
450 |
]. |
|
451 |
] |
|
452 |
]. |
|
453 |
]. |
|
454 |
^ nil |
|
455 |
]. |
|
456 |
||
457 |
node isLiteral ifTrue:[ |
|
458 |
^ Array with:(node value class) |
|
459 |
]. |
|
460 |
||
2191
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
461 |
"/ node isMessage ifTrue:[ |
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
462 |
"/ 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
|
463 |
"/ recClassSet isNil ifTrue:[ ^ nil ]. |
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
464 |
"/ recClassSet isEmpty ifTrue:[ ^ nil ]. |
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
465 |
"/ |
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
466 |
"/ 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
|
467 |
"/ "/ 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
|
468 |
"/ ^ rsltClassSet. |
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
469 |
"/ ]. |
1731 | 470 |
^ nil |
1728 | 471 |
! ! |
472 |
||
473 |
!Explainer class methodsFor:'explaining-naive'! |
|
474 |
||
1316
30806ca08095
commonSuperClassOf: - allow for classes and names in arg
Claus Gittinger <cg@exept.de>
parents:
1289
diff
changeset
|
475 |
commonSuperClassOf:listOfClassesOrClassNames |
1637 | 476 |
^ Behavior commonSuperclassOf:listOfClassesOrClassNames |
141 | 477 |
! |
478 |
||
2 | 479 |
explain:someText in:source forClass:aClass |
6 | 480 |
"Given a source and a substring of it, return a string containing |
481 |
an explanation. |
|
49 | 482 |
This is just a q&d implementation - to be correct, it should use the parser, |
483 |
and explain from the parsetree (instead of doing string matches). |
|
484 |
This leads to some wrong explanations, for example if some string is |
|
839 | 485 |
used as selector within a string, or if a variable is named like a |
486 |
message selector. I.e. the explanation should be context sensitive. |
|
49 | 487 |
Also, there could be much more detailed explanations." |
2 | 488 |
|
2037
003d9b5a2788
explain shared pool variables
Claus Gittinger <cg@exept.de>
parents:
2031
diff
changeset
|
489 |
^ self explain:someText in:source forClass:aClass short:false |
003d9b5a2788
explain shared pool variables
Claus Gittinger <cg@exept.de>
parents:
2031
diff
changeset
|
490 |
|
003d9b5a2788
explain shared pool variables
Claus Gittinger <cg@exept.de>
parents:
2031
diff
changeset
|
491 |
"Modified: / 07-06-2007 / 11:34:05 / cg" |
1183 | 492 |
! |
493 |
||
494 |
explain:someText in:source forClass:aClass short:shortText |
|
495 |
"Given a source and a substring of it, return a string containing |
|
496 |
an explanation. |
|
497 |
This is just a q&d implementation - to be correct, it should use the parser, |
|
498 |
and explain from the parsetree (instead of doing string matches). |
|
499 |
This leads to some wrong explanations, for example if some string is |
|
500 |
used as selector within a string, or if a variable is named like a |
|
501 |
message selector. I.e. the explanation should be context sensitive. |
|
502 |
Also, there could be much more detailed explanations." |
|
503 |
||
1159 | 504 |
|parser variables c string tmp |
1289 | 505 |
spc sym sel stringText clsName val valString| |
2 | 506 |
|
675 | 507 |
string := someText string withoutSeparators. |
2214 | 508 |
stringText := string allBold. |
1233 | 509 |
stringText := '''' , stringText , ''''. |
49 | 510 |
|
511 |
" |
|
512 |
ask parser for variable names |
|
513 |
" |
|
1357 | 514 |
ParseErrorSignal catch:[ |
515 |
parser := self parseMethod:source in:aClass ignoreErrors:true ignoreWarnings:true. |
|
516 |
]. |
|
2002 | 517 |
(parser notNil and:[parser ~~ #Error]) ifTrue:[ |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
518 |
"look for variables" |
2 | 519 |
|
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
520 |
variables := parser methodVars. |
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
521 |
(variables notNil and:[variables includes:string]) ifTrue:[ |
1233 | 522 |
^ stringText , ' is a method variable.' |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
523 |
]. |
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
524 |
variables := parser methodArgs. |
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
525 |
(variables notNil and:[variables includes:string]) ifTrue:[ |
1233 | 526 |
^ stringText , ' is a method argument.' |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
527 |
] |
2 | 528 |
]. |
49 | 529 |
|
2 | 530 |
parser isNil ifTrue:[ |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
531 |
parser := self for:(ReadStream on:source) in:aClass |
2 | 532 |
]. |
533 |
||
534 |
"instvars" |
|
84 | 535 |
c := aClass whichClassDefinesInstVar:string. |
536 |
c notNil ifTrue:[ |
|
396 | 537 |
c isMeta ifTrue:[ |
1211
91e94e294819
isMeta/soleInstance -> theMetaclass / theNonMetaclass
Claus Gittinger <cg@exept.de>
parents:
1210
diff
changeset
|
538 |
clsName := c theNonMetaclass name. |
1198 | 539 |
shortText ifTrue:[ |
1233 | 540 |
^ stringText , ' is a class instVar in ' , clsName , '.' |
1198 | 541 |
]. |
2008 | 542 |
^ stringText, ' is a class instance variable inherited from ' , clsName , '.' |
396 | 543 |
]. |
544 |
||
1233 | 545 |
clsName := c name. |
1198 | 546 |
shortText ifTrue:[ |
1233 | 547 |
^ stringText , ' is an instVar in ' , clsName , '.' |
1198 | 548 |
]. |
2008 | 549 |
^ stringText , ' is an instance variable inherited from ' , clsName , '.' |
2 | 550 |
]. |
551 |
||
552 |
"classvars" |
|
553 |
c := parser inWhichClassIsClassVar:string. |
|
554 |
c notNil ifTrue:[ |
|
1233 | 555 |
clsName := c name. |
1198 | 556 |
shortText ifTrue:[ |
1289 | 557 |
stringText := stringText , ' is a classVar in ' , clsName |
558 |
] ifFalse:[ |
|
559 |
stringText := stringText , ' is a class variable in ' , clsName |
|
1198 | 560 |
]. |
1693 | 561 |
|
2214 | 562 |
val := c theNonMetaclass classVarAt:string. "/ Smalltalk at:(clsName , ':' , string) asSymbol. |
563 |
valString := self valueStringFor:val. |
|
1289 | 564 |
^ stringText , ' (' , valString , ').' |
2 | 565 |
]. |
566 |
||
2037
003d9b5a2788
explain shared pool variables
Claus Gittinger <cg@exept.de>
parents:
2031
diff
changeset
|
567 |
"private classes" |
1210
e3174ccbb5bb
isMeta/soleInstance -> theMetaclass / theNonMetaclass
Claus Gittinger <cg@exept.de>
parents:
1198
diff
changeset
|
568 |
c := aClass theNonMetaclass. |
509
d8475399ca3e
Correct handling of private classes.
Stefan Vogel <sv@exept.de>
parents:
503
diff
changeset
|
569 |
c privateClasses do:[:pClass | |
d8475399ca3e
Correct handling of private classes.
Stefan Vogel <sv@exept.de>
parents:
503
diff
changeset
|
570 |
(pClass name = string |
d8475399ca3e
Correct handling of private classes.
Stefan Vogel <sv@exept.de>
parents:
503
diff
changeset
|
571 |
or:[pClass nameWithoutPrefix = string]) ifTrue:[ |
2214 | 572 |
stringText := stringText , ' is a private class in ''' , c name , '''.'. |
1233 | 573 |
shortText ifFalse:[ |
2214 | 574 |
stringText := (stringText , '\\It is only visible locally.') withCRs |
1183 | 575 |
]. |
2214 | 576 |
^ stringText withCRs |
422 | 577 |
]. |
578 |
]. |
|
579 |
||
2037
003d9b5a2788
explain shared pool variables
Claus Gittinger <cg@exept.de>
parents:
2031
diff
changeset
|
580 |
aClass theNonMetaclass sharedPools do:[:eachPoolName | |
003d9b5a2788
explain shared pool variables
Claus Gittinger <cg@exept.de>
parents:
2031
diff
changeset
|
581 |
|sharedPool| |
003d9b5a2788
explain shared pool variables
Claus Gittinger <cg@exept.de>
parents:
2031
diff
changeset
|
582 |
|
003d9b5a2788
explain shared pool variables
Claus Gittinger <cg@exept.de>
parents:
2031
diff
changeset
|
583 |
sharedPool := Smalltalk classNamed:eachPoolName. |
003d9b5a2788
explain shared pool variables
Claus Gittinger <cg@exept.de>
parents:
2031
diff
changeset
|
584 |
sharedPool notNil ifTrue:[ |
003d9b5a2788
explain shared pool variables
Claus Gittinger <cg@exept.de>
parents:
2031
diff
changeset
|
585 |
(sharedPool includesKey:string asSymbol) ifTrue:[ |
2214 | 586 |
stringText := stringText , ' is a pool variable in ',sharedPool name. |
587 |
val := sharedPool at:string. |
|
588 |
valString := self valueStringFor:val. |
|
589 |
^ stringText , ' (' , valString , ').' |
|
2037
003d9b5a2788
explain shared pool variables
Claus Gittinger <cg@exept.de>
parents:
2031
diff
changeset
|
590 |
]. |
003d9b5a2788
explain shared pool variables
Claus Gittinger <cg@exept.de>
parents:
2031
diff
changeset
|
591 |
]. |
003d9b5a2788
explain shared pool variables
Claus Gittinger <cg@exept.de>
parents:
2031
diff
changeset
|
592 |
]. |
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 |
"namespace & global variables" |
456 | 595 |
(spc := aClass nameSpace) notNil ifTrue:[ |
796 | 596 |
sym := (spc name , '::' , string) asSymbolIfInterned. |
597 |
sym notNil ifTrue:[ |
|
598 |
(Smalltalk at:sym) isBehavior ifTrue:[ |
|
1979 | 599 |
string := stringText , ': '. |
600 |
(Smalltalk at:sym) name = sym ifFalse:[ |
|
601 |
string := stringText , 'refers to ',(Smalltalk at:sym) name,', ' |
|
602 |
]. |
|
603 |
string := stringText , 'a class in the ''' , spc name , ''' nameSpace'. |
|
1763 | 604 |
string := string , ' (in "', (Smalltalk at:sym) category ,'")'. |
1183 | 605 |
shortText ifFalse:[ |
606 |
string := (string |
|
796 | 607 |
, '\\It is only visible within this nameSpace.' |
608 |
, '\Access from the outside is possible' |
|
609 |
, '\by the special name ''' , spc name , '::' , string , '''.') withCRs |
|
1183 | 610 |
]. |
611 |
^ string withCRs |
|
796 | 612 |
]. |
422 | 613 |
]. |
614 |
]. |
|
615 |
||
796 | 616 |
"/ string knownAsSymbol ifTrue:[ |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
617 |
"globals & symbols" |
2 | 618 |
|
1183 | 619 |
tmp := self explainKnownSymbol:string inClass:aClass short:shortText. |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
620 |
tmp notNil ifTrue:[ ^ tmp]. |
839 | 621 |
|
622 |
"/ try with added colon ... |
|
623 |
sel := string , ':'. |
|
624 |
Symbol allInstancesDo:[:sym | |
|
625 |
(sym startsWith:sel) ifTrue:[ |
|
1183 | 626 |
tmp := self explainKnownSymbol:sym inClass:aClass short:shortText. |
839 | 627 |
tmp notNil ifTrue:[ ^ tmp]. |
628 |
] |
|
629 |
]. |
|
796 | 630 |
"/ ]. |
2 | 631 |
|
632 |
"try for some obvious things" |
|
1183 | 633 |
tmp := self explainPseudoVariable:string in:aClass short:true. |
2 | 634 |
tmp notNil ifTrue:[ ^ tmp]. |
635 |
||
636 |
"try syntax ..." |
|
637 |
||
1183 | 638 |
tmp := self explainSyntax:string short:shortText. |
49 | 639 |
tmp notNil ifTrue:[ ^ tmp]. |
20 | 640 |
|
1183 | 641 |
shortText ifTrue:[ |
1438 | 642 |
^ 'no explanation' |
1183 | 643 |
]. |
644 |
||
2 | 645 |
parser isNil ifTrue:[ |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
646 |
^ 'parse error - no explanation' |
2 | 647 |
]. |
796 | 648 |
^ '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
|
649 |
|
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
650 |
"Created: / 03-12-1995 / 12:47:37 / cg" |
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
651 |
"Modified: / 16-04-1997 / 12:46:11 / stefan" |
2037
003d9b5a2788
explain shared pool variables
Claus Gittinger <cg@exept.de>
parents:
2031
diff
changeset
|
652 |
"Modified: / 07-06-2007 / 11:45:22 / cg" |
2 | 653 |
! |
654 |
||
1188 | 655 |
explainGlobal:string inClass:aClass short:shortText |
1183 | 656 |
"return explanation or nil" |
657 |
||
1245 | 658 |
|sym stringText tmp val classCategory| |
141 | 659 |
|
1245 | 660 |
"if not even known as key, its definitely not a global" |
661 |
sym := string asSymbolIfInterned. |
|
796 | 662 |
sym isNil ifTrue:[^ nil]. |
141 | 663 |
|
664 |
"try globals" |
|
1245 | 665 |
(Smalltalk includesKey:sym) ifFalse:[ ^ nil]. |
141 | 666 |
|
2191
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
667 |
stringText := string allBold. |
1198 | 668 |
|
1245 | 669 |
"/ stringText := '''' , stringText , ''''. |
1979 | 670 |
stringText := stringText , ': '. |
671 |
tmp := stringText , 'a global variable.'. |
|
1183 | 672 |
|
1245 | 673 |
val := Smalltalk at:sym. |
674 |
val isBehavior ifTrue:[ |
|
675 |
"/ a class |
|
1979 | 676 |
val name = sym ifFalse:[ |
677 |
stringText := stringText , ' refers to ',val name,', '. |
|
678 |
]. |
|
679 |
||
1943 | 680 |
(val isRealNameSpace) ifTrue:[ |
1979 | 681 |
^ stringText , 'a namespace.' |
1330 | 682 |
]. |
683 |
||
684 |
classCategory := val category ? 'uncategorized'. |
|
1245 | 685 |
shortText ifTrue:[ |
1979 | 686 |
^ stringText , (val isLoaded ifTrue:['a'] ifFalse:['an autoloaded']) |
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
687 |
, ' class in ',val package,' {' , classCategory , '}.'. |
1245 | 688 |
]. |
689 |
||
690 |
val name = string ifTrue:[ |
|
1183 | 691 |
tmp := tmp , ' |
1245 | 692 |
' , string , ' is ' , (val isLoaded ifTrue:['a'] ifFalse:['an autoloaded']) |
693 |
, ' class categorized as ' , classCategory , ' |
|
694 |
in the ''' , val package , ''' package.'. |
|
1183 | 695 |
^ tmp. |
696 |
]. |
|
141 | 697 |
|
1183 | 698 |
tmp := tmp , ' |
699 |
||
1245 | 700 |
' , string , ' is bound to the class ' , val name , |
701 |
' 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
|
702 |
^ tmp. |
141 | 703 |
]. |
704 |
||
1245 | 705 |
shortText ifTrue:[ |
1674 | 706 |
val isNil ifTrue:[ |
1979 | 707 |
^ stringText , 'a global, currently nil.'. |
1674 | 708 |
]. |
1979 | 709 |
^ stringText , 'a global, currently bound to ''' , val classNameWithArticle , '''.'. |
1245 | 710 |
]. |
711 |
tmp := tmp , ' |
|
712 |
||
713 |
Its current value is ''' , val classNameWithArticle , '''.'. |
|
714 |
^ tmp. |
|
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
715 |
|
1979 | 716 |
"Modified: / 06-02-2007 / 19:32:15 / cg" |
1188 | 717 |
! |
718 |
||
719 |
explainHereIn:aClass |
|
720 |
^ 'like self, here refers to the object which received the message. |
|
721 |
||
722 |
However, when sending a message to here the search for methods |
|
723 |
implementing this message will start in the defining class (' , aClass name , ') |
|
724 |
instead of the receivers class (' , aClass name , ' or subclass). |
|
725 |
Thus, using here, redefined methods will NOT be reached with a here-send.' |
|
726 |
! |
|
727 |
||
728 |
explainKnownSymbol:string inClass:aClass |
|
729 |
"return explanation or nil" |
|
730 |
||
731 |
^ self explainKnownSymbol:string inClass:aClass short:false |
|
732 |
! |
|
733 |
||
734 |
explainKnownSymbol:string inClass:aClass short:shortText |
|
735 |
"return explanation or nil" |
|
736 |
||
737 |
|sym| |
|
738 |
||
739 |
sym := string asSymbolIfInterned. |
|
740 |
sym isNil ifTrue:[^ nil]. |
|
741 |
||
742 |
"try globals" |
|
743 |
||
744 |
(Smalltalk includesKey:sym) ifTrue:[ |
|
745 |
^ self explainGlobal:string inClass:aClass short:shortText |
|
746 |
]. |
|
747 |
||
748 |
^ self explainSelector:string inClass:aClass short:shortText |
|
749 |
! |
|
750 |
||
751 |
explainPseudoVariable:string in:aClass |
|
752 |
"return explanation for the pseudoVariables self, super etc." |
|
753 |
||
754 |
^ self explainPseudoVariable:string in:aClass short:false |
|
755 |
! |
|
756 |
||
757 |
explainPseudoVariable:string in:aClass short:shortText |
|
758 |
"return explanation for the pseudoVariables self, super etc." |
|
759 |
||
760 |
(string = 'self') ifTrue:[ |
|
761 |
^ self explainSelfIn:aClass short:shortText |
|
762 |
]. |
|
763 |
||
764 |
(string = 'super') ifTrue:[ |
|
765 |
shortText ifTrue:[ |
|
766 |
^ '''super'' - message lookup starts in superclass ''' , aClass superclass name , '''.' |
|
767 |
]. |
|
768 |
^ self explainSuperIn:aClass short:shortText |
|
769 |
]. |
|
770 |
||
771 |
(string = 'here') ifTrue:[ |
|
772 |
shortText ifTrue:[ |
|
773 |
^ '''here'' - message lookup always starts in ''' , aClass name , '''.' |
|
774 |
]. |
|
775 |
^ self explainHereIn:aClass |
|
776 |
]. |
|
777 |
||
778 |
(string = 'thisContext') ifTrue:[ |
|
779 |
shortText ifTrue:[ |
|
780 |
^ '''thisContext'' - the current stack frame as an object.' |
|
781 |
]. |
|
782 |
^ 'thisContext is a pseudo variable (i.e. it is built in). |
|
783 |
||
784 |
ThisContext always refers to the context object for the currently executed method or |
|
785 |
block (an instance of Context or BlockContext respectively). The calling chain and calling |
|
786 |
receivers/selectors can be accessed via thisContext.' |
|
787 |
]. |
|
788 |
||
789 |
(string = 'true') ifTrue:[ |
|
790 |
shortText ifTrue:[ |
|
791 |
^ '''true'' - the truth and nothing but the truth.' |
|
792 |
]. |
|
793 |
^ 'true is a pseudo variable (i.e. it is built in). |
|
794 |
||
795 |
True represents logical truth. It is the one and only instance of class True.' |
|
796 |
]. |
|
797 |
||
798 |
(string = 'false') ifTrue:[ |
|
799 |
shortText ifTrue:[ |
|
800 |
^ '''false'' - obvisously not true.' |
|
801 |
]. |
|
802 |
^ 'false is a pseudo variable (i.e. it is built in). |
|
803 |
||
804 |
False represents logical falseness. It is the one and only instance of class False.' |
|
805 |
]. |
|
806 |
||
807 |
(string = 'nil') ifTrue:[ |
|
808 |
shortText ifTrue:[ |
|
809 |
^ '''nil'' - undefined, unknown, void or dont care.' |
|
810 |
]. |
|
811 |
^ 'nil is a pseudo variable (i.e. it is built in). |
|
812 |
||
813 |
Nil is used for unitialized variables (among other uses). |
|
814 |
Nil is the one and only instance of class UndefinedObject.' |
|
815 |
]. |
|
816 |
^ nil |
|
817 |
! |
|
818 |
||
819 |
explainSelector:string inClass:aClass short:shortText |
|
820 |
"return explanation or nil" |
|
821 |
||
1352 | 822 |
|sym list count tmp commonSuperClass s s2 |
1188 | 823 |
firstImplementingClass cm msg t| |
824 |
||
825 |
sym := string asSymbolIfInterned. |
|
826 |
sym isNil ifTrue:[^ nil]. |
|
827 |
||
141 | 828 |
" |
829 |
try selectors |
|
830 |
look who implements it |
|
831 |
" |
|
832 |
list := Set new. |
|
1081 | 833 |
Smalltalk allClassesDo:[:c| |
1249
780b4a1a3967
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1245
diff
changeset
|
834 |
(c includesSelector:sym) ifTrue:[ |
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
835 |
list add:(c name). |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
836 |
firstImplementingClass isNil ifTrue:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
837 |
firstImplementingClass := c |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
838 |
] |
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
839 |
]. |
1249
780b4a1a3967
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1245
diff
changeset
|
840 |
(c class includesSelector:sym) ifTrue:[ |
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
841 |
list add:(c name , ' class'). |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
842 |
firstImplementingClass isNil ifTrue:[ |
912 | 843 |
firstImplementingClass := c class |
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
844 |
] |
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
845 |
] |
141 | 846 |
]. |
847 |
||
835 | 848 |
(aClass canUnderstand:sym) ifTrue:[ |
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
849 |
s2 := ('Instances of ''' , aClass name , ''' respond to #') , sym "allBold" , '.'. |
1184 | 850 |
shortText ifFalse:[ |
851 |
s2 := '\\' , s2 |
|
852 |
, '\- inherited from ' withCRs |
|
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
853 |
, (aClass whichClassIncludesSelector:sym) name "allBold". |
1184 | 854 |
]. |
1761 | 855 |
firstImplementingClass := (aClass whichClassIncludesSelector:sym) |
835 | 856 |
] ifFalse:[ |
857 |
s2 := ''. |
|
858 |
]. |
|
859 |
||
141 | 860 |
count := list size. |
861 |
(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
|
862 |
" |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
863 |
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
|
864 |
list them |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
865 |
" |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
866 |
list := list asOrderedCollection sort. |
1185 | 867 |
shortText ifTrue:[ |
868 |
tmp := ' is implemented in '. |
|
869 |
] ifFalse:[ |
|
870 |
tmp := ' is a selector implemented in '. |
|
871 |
]. |
|
2191
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
872 |
s := "'#' ," string allBold. |
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
873 |
|
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
874 |
(count == 1) ifTrue:[ |
1183 | 875 |
(t := list first) isMeta ifTrue:[ |
876 |
t := 'the ' , t |
|
877 |
]. |
|
1184 | 878 |
msg := s , tmp , t , '.'. |
879 |
shortText ifFalse:[ |
|
880 |
msg := msg , s2. |
|
881 |
] |
|
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
882 |
] ifFalse:[ |
1185 | 883 |
(count == 2) ifTrue:[ |
884 |
msg := s , tmp , (list at:1) , ' and ' , (list at:2) , '.'. |
|
885 |
shortText ifFalse:[ |
|
886 |
msg := msg , s2. |
|
887 |
]. |
|
888 |
] ifFalse:[ |
|
889 |
shortText ifTrue:[ |
|
1428 | 890 |
msg := s , tmp , count printString , ' classes'. |
1637 | 891 |
commonSuperClass := Class commonSuperclassOf:list. |
1428 | 892 |
(commonSuperClass == Object |
893 |
and:[commonSuperClass includesSelector:sym]) ifTrue:[ |
|
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
894 |
msg := msg , ' (including ' , 'Object' "allBold", ')' |
1428 | 895 |
]. |
896 |
msg := msg , '.'. |
|
1185 | 897 |
^ msg |
898 |
]. |
|
1183 | 899 |
|
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
900 |
(count == 3) ifTrue:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
901 |
msg := s , tmp , ' |
835 | 902 |
' , (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
|
903 |
] ifFalse:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
904 |
(count == 4) ifTrue:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
905 |
msg := s , tmp , ' |
835 | 906 |
' , (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
|
907 |
] ifFalse:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
908 |
" |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
909 |
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
|
910 |
superclass and show it ... |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
911 |
" |
1637 | 912 |
commonSuperClass := Behavior commonSuperclassOf:list. |
913 | 913 |
(commonSuperClass ~~ Object |
914 |
and:[commonSuperClass ~~ Behavior |
|
915 |
and:[commonSuperClass ~~ Class |
|
916 |
and:[commonSuperClass ~~ ClassDescription]]]) ifTrue:[ |
|
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
917 |
(list includes:commonSuperClass) ifTrue:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
918 |
msg := s . tmp , count printString , commonSuperClass name |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
919 |
, ' and redefined in ' , (count - 1) printString |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
920 |
, ' subclasses' |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
921 |
, s2. |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
922 |
firstImplementingClass := commonSuperClass |
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 |
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
|
925 |
] |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
926 |
] ifFalse:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
927 |
(commonSuperClass == Object |
1249
780b4a1a3967
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1245
diff
changeset
|
928 |
and:[commonSuperClass includesSelector:sym]) ifTrue:[ |
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
929 |
msg := s , tmp , count printString , ' classes. |
834 | 930 |
|
931 |
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
|
932 |
since there is an implementation in Object.' , s2. |
141 | 933 |
|
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
934 |
firstImplementingClass := Object |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
935 |
] ifFalse:[ |
913 | 936 |
((commonSuperClass == Behavior |
937 |
or:[commonSuperClass == Class |
|
938 |
or:[commonSuperClass == ClassDescription]]) |
|
1249
780b4a1a3967
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1245
diff
changeset
|
939 |
and:[commonSuperClass includesSelector:sym]) ifTrue:[ |
913 | 940 |
msg := s , tmp , count printString , ' classes. |
941 |
||
942 |
All classes seem to respond to that message, |
|
943 |
since there is an implementation in ' , commonSuperClass name , '.' , s2. |
|
944 |
||
945 |
firstImplementingClass := commonSuperClass |
|
946 |
] ifFalse:[ |
|
947 |
" |
|
948 |
otherwise just give the number. |
|
949 |
" |
|
950 |
msg := s , tmp , count printString , ' classes.' , s2 |
|
951 |
] |
|
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
952 |
] |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
953 |
] |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
954 |
] |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
955 |
] |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
956 |
]. |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
957 |
]. |
1909 | 958 |
shortText ifTrue:[ |
959 |
count == 1 ifTrue:[ |
|
1910 | 960 |
cm := self fetchCommentOfMethod:(firstImplementingClass compiledMethodAt:sym). |
961 |
cm notNil ifTrue:[ |
|
962 |
msg := msg,' ',cm |
|
963 |
]. |
|
1909 | 964 |
]. |
965 |
] ifFalse:[ |
|
1185 | 966 |
firstImplementingClass notNil ifTrue:[ |
967 |
WindowGroup activeGroup withWaitCursorDo:[ |
|
968 |
cm := firstImplementingClass compiledMethodAt:sym. |
|
969 |
cm notNil ifTrue:[ |
|
970 |
cm := cm methodComment. |
|
971 |
] |
|
972 |
]. |
|
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
973 |
cm notNil ifTrue:[ |
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
974 |
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
|
975 |
] |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
976 |
]. |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
977 |
]. |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
978 |
^ msg |
141 | 979 |
]. |
980 |
||
981 |
^ nil |
|
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
982 |
|
1909 | 983 |
"Modified: / 17-06-1996 / 17:09:30 / stefan" |
984 |
"Created: / 23-03-1999 / 13:29:33 / cg" |
|
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
985 |
"Modified: / 09-10-2006 / 12:11:58 / cg" |
141 | 986 |
! |
987 |
||
1183 | 988 |
explainSelfIn:aClass short:shortText |
1244 | 989 |
|sub subNames selfString className nSubClasses| |
1198 | 990 |
|
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
991 |
selfString := '''' , 'self' "allBold" , ''''. |
6 | 992 |
|
1244 | 993 |
sub := aClass allSubclasses. |
994 |
nSubClasses := sub size. |
|
995 |
||
996 |
aClass isMeta ifTrue:[ |
|
997 |
className := aClass theNonMetaclass name. |
|
998 |
subNames := sub collect:[:c | c theNonMetaclass name]. |
|
999 |
nSubClasses == 0 ifTrue:[ |
|
1000 |
shortText ifTrue:[ |
|
1001 |
^ selfString , ' - the ''' , className , '''-class.' |
|
1002 |
]. |
|
1003 |
^ selfString , 'refers to the object which received the message. |
|
1004 |
||
1005 |
In this case, it will be the ' , className , '-class itself.' |
|
1006 |
]. |
|
1007 |
||
1008 |
shortText ifTrue:[ |
|
1009 |
nSubClasses == 1 ifTrue:[ |
|
1010 |
^ selfString , ' - the ''' , className , '''- or ''' , subNames first , '''-class.' |
|
1011 |
]. |
|
1012 |
^ selfString , ' - the ''' , className , '''-class or one of its subclasses.' |
|
1013 |
]. |
|
1014 |
nSubClasses <= 5 ifTrue:[ |
|
1015 |
^ selfString , ' refers to the object which received the message. |
|
1016 |
||
1017 |
In this case, it will be the ' , className , '-class |
|
1018 |
or one of its subclasses: |
|
1019 |
||
1020 |
' , subNames asStringCollection asString |
|
1021 |
]. |
|
1022 |
||
1023 |
^ selfString , ' refers to the object which received the message. |
|
1024 |
||
1025 |
In this case, it will be the ' , className , '-class |
|
1026 |
or one of its ' , nSubClasses printString , ' subclasses.' |
|
1027 |
]. |
|
1028 |
||
1256 | 1029 |
subNames := aClass allSubclasses collect:[:c | c theNonMetaclass name]. |
1244 | 1030 |
className := aClass name. |
1031 |
nSubClasses == 0 ifTrue:[ |
|
1183 | 1032 |
shortText ifTrue:[ |
1244 | 1033 |
^ selfString , ' - an instance of ''' , className , '''.' |
1183 | 1034 |
]. |
1198 | 1035 |
^ selfString , 'refers to the object which received the message. |
6 | 1036 |
|
1244 | 1037 |
In this case, it will be an instance of ' , className , '.' |
6 | 1038 |
]. |
1039 |
||
1183 | 1040 |
shortText ifTrue:[ |
1244 | 1041 |
nSubClasses == 1 ifTrue:[ |
1256 | 1042 |
^ selfString , ' - an instance of ''' , className , ''' or ''' , subNames first , '''.' |
1185 | 1043 |
]. |
1244 | 1044 |
^ selfString , ' - an instance of ''' , className , ''' or one of its subclasses.' |
1183 | 1045 |
]. |
1244 | 1046 |
nSubClasses <= 5 ifTrue:[ |
1198 | 1047 |
^ selfString , ' refers to the object which received the message. |
6 | 1048 |
|
1244 | 1049 |
In this case, it will be an instance of ' , className , ' |
6 | 1050 |
or one of its subclasses: |
1051 |
||
1256 | 1052 |
' , subNames asStringCollection asString |
6 | 1053 |
]. |
1054 |
||
1198 | 1055 |
^ selfString , ' refers to the object which received the message. |
6 | 1056 |
|
1244 | 1057 |
In this case, it will be an instance of ' , className , ' |
1058 |
or one of its ' , nSubClasses printString , ' subclasses.' |
|
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
1059 |
|
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
1060 |
"Modified: / 09-10-2006 / 12:11:44 / cg" |
6 | 1061 |
! |
1062 |
||
1188 | 1063 |
explainSuperIn:aClass short:shortText |
1352 | 1064 |
|superName| |
1244 | 1065 |
|
1066 |
superName := aClass superclass name. |
|
1188 | 1067 |
|
1068 |
shortText ifTrue:[ |
|
1244 | 1069 |
^ '''super'' - message lookup starts in ' , superName , '.' |
1188 | 1070 |
]. |
1071 |
||
6 | 1072 |
^ 'like self, super refers to the object which received the message. |
1073 |
||
1074 |
However, when sending a message to super the search for methods |
|
1244 | 1075 |
implementing this message will start in the superclass (' , superName , ') |
84 | 1076 |
instead of the receivers class (' , aClass name , ' or subclass). |
49 | 1077 |
Thus, using super, a redefined method can call the original method in its superclass.' |
6 | 1078 |
! |
2 | 1079 |
|
49 | 1080 |
explainSyntax:string |
1081 |
"try syntax ...; return explanation or nil" |
|
1082 |
||
1183 | 1083 |
^ self explainSyntax:string short:false |
1084 |
! |
|
1085 |
||
1086 |
explainSyntax:string short:shortText |
|
1087 |
"try syntax ...; return explanation or nil" |
|
1088 |
||
49 | 1089 |
((string = ':=') or:[string = '_']) ifTrue:[ |
1183 | 1090 |
shortText ifTrue:[ |
1091 |
^ 'Assign to variable on the left side.'. |
|
1092 |
]. |
|
1093 |
||
796 | 1094 |
^ '<variable> := <expression> |
49 | 1095 |
|
834 | 1096 |
'':='' and ''_'' (which is left-arrow in some fonts) mean assignment. |
49 | 1097 |
The variable is bound to (i.e. points to) the value of <expression>.' |
1098 |
]. |
|
1099 |
||
1100 |
(string = '^') ifTrue:[ |
|
1183 | 1101 |
shortText ifTrue:[ |
1102 |
^ 'Return value from method.'. |
|
1103 |
]. |
|
796 | 1104 |
^ '^ <expression> |
49 | 1105 |
|
834 | 1106 |
returns the value of <expression> as value from the method. |
49 | 1107 |
A return from within a block exits the method where the block is defined.' |
1108 |
]. |
|
1109 |
||
1110 |
(string = ';') ifTrue:[ |
|
1183 | 1111 |
shortText ifTrue:[ |
1112 |
^ 'Cascade expression.'. |
|
1113 |
]. |
|
796 | 1114 |
^ '<expression> ; selector1 ; .... ; selectorN |
49 | 1115 |
|
1116 |
a cascade expression; evaluate expression, and send messages |
|
1117 |
<selector1> ... <selectorN> to the first expressions receiver. |
|
1118 |
Returns the value of the last send. The cascade sends may also have arguments.' |
|
1119 |
]. |
|
1120 |
||
1121 |
(string = '|') ifTrue:[ |
|
1183 | 1122 |
shortText ifTrue:[ |
1123 |
^ ''. |
|
1124 |
]. |
|
796 | 1125 |
^ '| locals | or: [:arg | statements] |
49 | 1126 |
|
834 | 1127 |
''|'' is used to mark a local variable declaration or separates arguments |
49 | 1128 |
from the statements in a block. Notice, that in a block-argument declaration |
1129 |
these must be prefixed by a colon character. |
|
834 | 1130 |
''|'' is also a selector understood by Booleans.' |
49 | 1131 |
]. |
1132 |
||
1133 |
((string startsWith:'(') or:[string endsWith:')']) ifTrue:[ |
|
1183 | 1134 |
shortText ifTrue:[ |
1135 |
^ ''. |
|
1136 |
]. |
|
796 | 1137 |
^ '(<expression>) |
49 | 1138 |
|
1139 |
expression grouping.' |
|
1140 |
]. |
|
1141 |
||
1142 |
((string startsWith:'[') or:[string endsWith:']']) ifTrue:[ |
|
1183 | 1143 |
shortText ifTrue:[ |
1144 |
^ ''. |
|
1145 |
]. |
|
834 | 1146 |
^ '[:arg1 .. :argN | statements] |
49 | 1147 |
|
1148 |
defines a block. |
|
1149 |
Blocks represent pieces of executable code. Definition of a block does |
|
1150 |
not evaluate it. The block is evaluated by sending it a value/value: |
|
1151 |
message. |
|
1152 |
Blocks are often passed as arguments to Booleans (i.e. ifTrue:[...]) or |
|
1153 |
collections (i.e. do:[...]).' |
|
1154 |
]. |
|
1155 |
||
1156 |
(string = ':') ifTrue:[ |
|
1183 | 1157 |
shortText ifTrue:[ |
1158 |
^ ''. |
|
1159 |
]. |
|
796 | 1160 |
^ 'colons have different meaning depending on context: |
49 | 1161 |
|
1162 |
1) they separate keyword-parts in symbols and keyword-messages as in: |
|
1163 |
||
1164 |
#at:put: a constant keyword symbol |
|
1165 |
||
1166 |
rec at:index put:value sends the #at:put: message to rec, |
|
796 | 1167 |
passing index and value as arguments. |
49 | 1168 |
|
1169 |
2) within block-argument declarations as in: |
|
1170 |
||
1171 |
[:arg1 :arg2 | statements] |
|
834 | 1172 |
|
1173 |
3) within an identifier, they separate the nameSpace part from |
|
1174 |
the name part; as in: |
|
1175 |
||
1176 |
Smalltalk::Array - the Array class in the Smalltalk nameSpace. |
|
1177 |
Foo::Array - the Array class in the Foo nameSpace. |
|
49 | 1178 |
' |
1179 |
]. |
|
1180 |
||
1181 |
(string = '.') ifTrue:[ |
|
796 | 1182 |
^ 'statement. "<- period here" |
49 | 1183 |
statement |
1184 |
||
1185 |
within a method or block, individual statements are separated by periods. |
|
1186 |
' |
|
1187 |
]. |
|
1188 |
||
1189 |
(string startsWith:'#' ) ifTrue:[ |
|
796 | 1190 |
(string startsWith:'#(' ) ifTrue:[ |
1183 | 1191 |
shortText ifTrue:[ |
1192 |
^ 'Array Literal.'. |
|
1193 |
]. |
|
796 | 1194 |
^ 'is a constant Array. |
49 | 1195 |
|
1196 |
The elements of a constant Array must be Number-constants, nil, true or false. |
|
1197 |
(notice, that not all Smalltalk implementations allow true, false and nil as |
|
1198 |
constant-Array elements).' |
|
796 | 1199 |
]. |
49 | 1200 |
|
796 | 1201 |
(string startsWith:'#[') ifTrue:[ |
1183 | 1202 |
shortText ifTrue:[ |
1203 |
^ 'ByteArray Literal.'. |
|
1204 |
]. |
|
796 | 1205 |
^ 'is a constant ByteArray. |
49 | 1206 |
|
1207 |
The elements of a constant ByteArray must be Integer constants in the range |
|
1208 |
0 .. 255. |
|
1209 |
(notice, that not all Smalltalk implementations support constant ByteArrays).' |
|
796 | 1210 |
]. |
49 | 1211 |
|
796 | 1212 |
(string startsWith:'#''') ifTrue:[ |
1183 | 1213 |
shortText ifTrue:[ |
1214 |
^ 'Symbol Literal.'. |
|
1215 |
]. |
|
796 | 1216 |
^ 'is a constant symbol containing non-alphanumeric characters. |
49 | 1217 |
|
1218 |
Symbols are unique strings, meaning that there exists |
|
1219 |
exactly one instance of a given symbol. Therefore symbols can |
|
1220 |
be compared using == (identity compare) in addition to = (contents compare). |
|
1221 |
Beside this, Symbols behave mostly like Strings. |
|
1222 |
||
1223 |
Notice, that not all Smalltalk implementations support this kind of symbols.' |
|
796 | 1224 |
]. |
49 | 1225 |
|
1232 | 1226 |
shortText ifTrue:[ |
1227 |
^ 'Symbol Literal.'. |
|
1228 |
]. |
|
796 | 1229 |
^ 'is a symbol. |
49 | 1230 |
|
1231 |
Symbols are unique strings, meaning that there exists |
|
1232 |
exactly one instance of a given symbol. Therefore symbols can |
|
1233 |
be compared using == (identity compare) in addition to = (contents compare). |
|
1234 |
Beside this, Symbols behave mostly like Strings.' |
|
1235 |
]. |
|
1236 |
||
1237 |
"/ is it a symbol without hash-character ? |
|
1238 |
"/ |
|
796 | 1239 |
"/ string knownAsSymbol ifTrue:[ |
1240 |
"/ ^ 'is nothing, but #' , string , ' is known as a symbol. |
|
1241 |
"/ |
|
1242 |
"/Symbols are unique strings, meaning that there exists |
|
1243 |
"/exactly one instance of a given symbol. Therefore symbols can |
|
1244 |
"/be compared using == (identity compare) in addition to = (contents compare). |
|
1245 |
"/Beside this, Symbols behave mostly like Strings.' |
|
1246 |
"/ ]. |
|
49 | 1247 |
|
1248 |
^ nil |
|
796 | 1249 |
|
1250 |
"Modified: / 31.10.1998 / 14:28:58 / cg" |
|
2214 | 1251 |
! |
1252 |
||
1253 |
valueStringFor:aValue |
|
1254 |
|valString| |
|
1255 |
||
1256 |
"/ only show the value, if it is really short... |
|
1257 |
(aValue isBoolean or:[aValue isNil]) ifTrue:[ |
|
1258 |
valString := aValue storeString. |
|
1259 |
] ifFalse:[ |
|
1260 |
(aValue isString or:[aValue isNumber or:[aValue isPoint]]) ifTrue:[ |
|
1261 |
valString := aValue storeString . |
|
1262 |
"/ valString := aValue className, ' ' , aValue storeString . |
|
1263 |
]. |
|
1264 |
]. |
|
1265 |
||
1266 |
(valString isEmptyOrNil |
|
1267 |
or:[ valString size > 30 |
|
1268 |
or:[ valString includes:Character cr ]]) ifTrue:[ |
|
1269 |
valString := aValue classNameWithArticle. |
|
1270 |
]. |
|
1271 |
||
1272 |
^ valString |
|
141 | 1273 |
! ! |
49 | 1274 |
|
396 | 1275 |
!Explainer class methodsFor:'documentation'! |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
1276 |
|
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
1277 |
version |
2225
caacd294cddc
no need for #asText to emphasize a string
Claus Gittinger <cg@exept.de>
parents:
2223
diff
changeset
|
1278 |
^ '$Header: /cvs/stx/stx/libcomp/Explainer.st,v 1.93 2009-10-22 12:42:13 cg Exp $' |
2214 | 1279 |
! |
1280 |
||
1281 |
version_CVS |
|
2225
caacd294cddc
no need for #asText to emphasize a string
Claus Gittinger <cg@exept.de>
parents:
2223
diff
changeset
|
1282 |
^ '$Header: /cvs/stx/stx/libcomp/Explainer.st,v 1.93 2009-10-22 12:42:13 cg Exp $' |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
1283 |
! ! |