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