author | Claus Gittinger <cg@exept.de> |
Thu, 14 Oct 2010 11:58:06 +0200 | |
changeset 2427 | 565f6959c461 |
parent 2414 | 4da315c5bcf4 |
child 2466 | 75b29e4a34c0 |
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 |
||
2315
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
594 |
aClass theNonMetaclass sharedPools do:[:eachPoolName | |
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" |
2414
4da315c5bcf4
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2316
diff
changeset
|
667 |
"Modified: / 28-07-2010 / 09:39:52 / 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 |
|
2427 | 687 |
"a pool variable?" |
688 |
aClass notNil ifTrue:[ |
|
689 |
aClass theNonMetaclass sharedPools do:[:eachPoolName | |
|
690 |
pool := Smalltalk at:eachPoolName. |
|
691 |
(pool classVarNames includes:string) ifTrue:[ |
|
692 |
what := 'a pool variable in "%1".' bindWith:eachPoolName. |
|
693 |
val := pool classVarAt:sym. |
|
694 |
]. |
|
695 |
]. |
|
696 |
]. |
|
697 |
||
698 |
what isNil ifTrue:[ |
|
699 |
"try globals" |
|
700 |
(Smalltalk includesKey:sym) ifFalse:[ ^ nil]. |
|
701 |
what := 'a global variable.'. |
|
702 |
val := Smalltalk at:sym. |
|
703 |
]. |
|
141 | 704 |
|
2191
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
705 |
stringText := string allBold. |
1198 | 706 |
|
1245 | 707 |
"/ stringText := '''' , stringText , ''''. |
1979 | 708 |
stringText := stringText , ': '. |
2427 | 709 |
tmp := stringText , what. |
1183 | 710 |
|
1245 | 711 |
val isBehavior ifTrue:[ |
712 |
"/ a class |
|
1979 | 713 |
val name = sym ifFalse:[ |
714 |
stringText := stringText , ' refers to ',val name,', '. |
|
715 |
]. |
|
716 |
||
1943 | 717 |
(val isRealNameSpace) ifTrue:[ |
1979 | 718 |
^ stringText , 'a namespace.' |
1330 | 719 |
]. |
720 |
||
721 |
classCategory := val category ? 'uncategorized'. |
|
1245 | 722 |
shortText ifTrue:[ |
1979 | 723 |
^ stringText , (val isLoaded ifTrue:['a'] ifFalse:['an autoloaded']) |
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
724 |
, ' class in ',val package,' {' , classCategory , '}.'. |
1245 | 725 |
]. |
726 |
||
727 |
val name = string ifTrue:[ |
|
1183 | 728 |
tmp := tmp , ' |
1245 | 729 |
' , string , ' is ' , (val isLoaded ifTrue:['a'] ifFalse:['an autoloaded']) |
730 |
, ' class categorized as ' , classCategory , ' |
|
731 |
in the ''' , val package , ''' package.'. |
|
1183 | 732 |
^ tmp. |
733 |
]. |
|
141 | 734 |
|
1183 | 735 |
tmp := tmp , ' |
736 |
||
1245 | 737 |
' , string , ' is bound to the class ' , val name , |
738 |
' 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
|
739 |
^ tmp. |
141 | 740 |
]. |
741 |
||
2427 | 742 |
valText := self valueStringFor:val. |
743 |
||
1245 | 744 |
shortText ifTrue:[ |
2427 | 745 |
^ stringText,'currently ',valText. |
1245 | 746 |
]. |
747 |
tmp := tmp , ' |
|
748 |
||
2427 | 749 |
Its current value is ",valText,".'. |
1245 | 750 |
^ tmp. |
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
751 |
|
2427 | 752 |
"Created: / 14-10-2010 / 11:33:04 / cg" |
1188 | 753 |
! |
754 |
||
755 |
explainHereIn:aClass |
|
756 |
^ 'like self, here refers to the object which received the message. |
|
757 |
||
758 |
However, when sending a message to here the search for methods |
|
759 |
implementing this message will start in the defining class (' , aClass name , ') |
|
760 |
instead of the receivers class (' , aClass name , ' or subclass). |
|
761 |
Thus, using here, redefined methods will NOT be reached with a here-send.' |
|
762 |
! |
|
763 |
||
764 |
explainKnownSymbol:string inClass:aClass |
|
765 |
"return explanation or nil" |
|
766 |
||
767 |
^ self explainKnownSymbol:string inClass:aClass short:false |
|
768 |
! |
|
769 |
||
770 |
explainKnownSymbol:string inClass:aClass short:shortText |
|
771 |
"return explanation or nil" |
|
772 |
||
773 |
|sym| |
|
774 |
||
775 |
sym := string asSymbolIfInterned. |
|
776 |
sym isNil ifTrue:[^ nil]. |
|
777 |
||
2427 | 778 |
"try globals and pools" |
1188 | 779 |
(Smalltalk includesKey:sym) ifTrue:[ |
2427 | 780 |
^ self explainGlobalOrPoolVariable:string inClass:aClass short:shortText |
1188 | 781 |
]. |
782 |
||
783 |
^ self explainSelector:string inClass:aClass short:shortText |
|
2427 | 784 |
|
785 |
"Modified: / 14-10-2010 / 11:33:33 / cg" |
|
1188 | 786 |
! |
787 |
||
788 |
explainPseudoVariable:string in:aClass |
|
789 |
"return explanation for the pseudoVariables self, super etc." |
|
790 |
||
791 |
^ self explainPseudoVariable:string in:aClass short:false |
|
792 |
! |
|
793 |
||
794 |
explainPseudoVariable:string in:aClass short:shortText |
|
795 |
"return explanation for the pseudoVariables self, super etc." |
|
796 |
||
797 |
(string = 'self') ifTrue:[ |
|
798 |
^ self explainSelfIn:aClass short:shortText |
|
799 |
]. |
|
800 |
||
801 |
(string = 'super') ifTrue:[ |
|
802 |
shortText ifTrue:[ |
|
803 |
^ '''super'' - message lookup starts in superclass ''' , aClass superclass name , '''.' |
|
804 |
]. |
|
805 |
^ self explainSuperIn:aClass short:shortText |
|
806 |
]. |
|
807 |
||
808 |
(string = 'here') ifTrue:[ |
|
809 |
shortText ifTrue:[ |
|
810 |
^ '''here'' - message lookup always starts in ''' , aClass name , '''.' |
|
811 |
]. |
|
812 |
^ self explainHereIn:aClass |
|
813 |
]. |
|
814 |
||
815 |
(string = 'thisContext') ifTrue:[ |
|
816 |
shortText ifTrue:[ |
|
817 |
^ '''thisContext'' - the current stack frame as an object.' |
|
818 |
]. |
|
819 |
^ 'thisContext is a pseudo variable (i.e. it is built in). |
|
820 |
||
821 |
ThisContext always refers to the context object for the currently executed method or |
|
822 |
block (an instance of Context or BlockContext respectively). The calling chain and calling |
|
823 |
receivers/selectors can be accessed via thisContext.' |
|
824 |
]. |
|
825 |
||
826 |
(string = 'true') ifTrue:[ |
|
827 |
shortText ifTrue:[ |
|
828 |
^ '''true'' - the truth and nothing but the truth.' |
|
829 |
]. |
|
830 |
^ 'true is a pseudo variable (i.e. it is built in). |
|
831 |
||
832 |
True represents logical truth. It is the one and only instance of class True.' |
|
833 |
]. |
|
834 |
||
835 |
(string = 'false') ifTrue:[ |
|
836 |
shortText ifTrue:[ |
|
837 |
^ '''false'' - obvisously not true.' |
|
838 |
]. |
|
839 |
^ 'false is a pseudo variable (i.e. it is built in). |
|
840 |
||
841 |
False represents logical falseness. It is the one and only instance of class False.' |
|
842 |
]. |
|
843 |
||
844 |
(string = 'nil') ifTrue:[ |
|
845 |
shortText ifTrue:[ |
|
846 |
^ '''nil'' - undefined, unknown, void or dont care.' |
|
847 |
]. |
|
848 |
^ 'nil is a pseudo variable (i.e. it is built in). |
|
849 |
||
850 |
Nil is used for unitialized variables (among other uses). |
|
851 |
Nil is the one and only instance of class UndefinedObject.' |
|
852 |
]. |
|
853 |
^ nil |
|
854 |
! |
|
855 |
||
856 |
explainSelector:string inClass:aClass short:shortText |
|
857 |
"return explanation or nil" |
|
858 |
||
2288
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
859 |
|sym list listSimilar firstImplementingClassOfSimilar count tmp commonSuperClass s s2 |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
860 |
firstImplementingClass cm msg t check| |
1188 | 861 |
|
862 |
sym := string asSymbolIfInterned. |
|
863 |
sym isNil ifTrue:[^ nil]. |
|
864 |
||
141 | 865 |
" |
866 |
try selectors |
|
867 |
look who implements it |
|
868 |
" |
|
869 |
list := Set new. |
|
2288
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
870 |
listSimilar := Set new. |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
871 |
|
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
872 |
check := |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
873 |
[:sel :mthd :cls | |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
874 |
sel == sym ifTrue:[ |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
875 |
list add:(cls name). |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
876 |
firstImplementingClass isNil ifTrue:[ |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
877 |
firstImplementingClass := cls |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
878 |
] |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
879 |
] ifFalse:[ |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
880 |
(sel startsWith:sym) ifTrue:[ |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
881 |
listSimilar add:sel. |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
882 |
firstImplementingClassOfSimilar isNil ifTrue:[ |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
883 |
firstImplementingClassOfSimilar := cls |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
884 |
] |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
885 |
] |
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
886 |
] |
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
887 |
]. |
2288
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 |
Smalltalk allClassesDo:[:c| |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
890 |
c methodDictionary keysAndValuesDo:[:sel :mthd | |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
891 |
check value:sel value:mthd value:c |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
892 |
]. |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
893 |
c class methodDictionary keysAndValuesDo:[:sel :mthd | |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
894 |
check value:sel value:mthd value:c class |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
895 |
]. |
141 | 896 |
]. |
897 |
||
835 | 898 |
(aClass canUnderstand:sym) ifTrue:[ |
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
899 |
s2 := ('Instances of ''' , aClass name , ''' respond to #') , sym "allBold" , '.'. |
1184 | 900 |
shortText ifFalse:[ |
901 |
s2 := '\\' , s2 |
|
902 |
, '\- inherited from ' withCRs |
|
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
903 |
, (aClass whichClassIncludesSelector:sym) name "allBold". |
1184 | 904 |
]. |
1761 | 905 |
firstImplementingClass := (aClass whichClassIncludesSelector:sym) |
835 | 906 |
] ifFalse:[ |
907 |
s2 := ''. |
|
908 |
]. |
|
909 |
||
141 | 910 |
count := list size. |
911 |
(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
|
912 |
" |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
913 |
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
|
914 |
list them |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
915 |
" |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
916 |
list := list asOrderedCollection sort. |
1185 | 917 |
shortText ifTrue:[ |
918 |
tmp := ' is implemented in '. |
|
919 |
] ifFalse:[ |
|
920 |
tmp := ' is a selector implemented in '. |
|
921 |
]. |
|
2191
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
922 |
s := "'#' ," string allBold. |
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
923 |
|
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
924 |
(count == 1) ifTrue:[ |
1183 | 925 |
(t := list first) isMeta ifTrue:[ |
926 |
t := 'the ' , t |
|
927 |
]. |
|
1184 | 928 |
msg := s , tmp , t , '.'. |
929 |
shortText ifFalse:[ |
|
930 |
msg := msg , s2. |
|
931 |
] |
|
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
932 |
] ifFalse:[ |
1185 | 933 |
(count == 2) ifTrue:[ |
934 |
msg := s , tmp , (list at:1) , ' and ' , (list at:2) , '.'. |
|
935 |
shortText ifFalse:[ |
|
936 |
msg := msg , s2. |
|
937 |
]. |
|
938 |
] ifFalse:[ |
|
939 |
shortText ifTrue:[ |
|
1428 | 940 |
msg := s , tmp , count printString , ' classes'. |
1637 | 941 |
commonSuperClass := Class commonSuperclassOf:list. |
1428 | 942 |
(commonSuperClass == Object |
943 |
and:[commonSuperClass includesSelector:sym]) ifTrue:[ |
|
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
944 |
msg := msg , ' (including ' , 'Object' "allBold", ')' |
1428 | 945 |
]. |
946 |
msg := msg , '.'. |
|
1185 | 947 |
^ msg |
948 |
]. |
|
1183 | 949 |
|
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
950 |
(count == 3) ifTrue:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
951 |
msg := s , tmp , ' |
835 | 952 |
' , (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
|
953 |
] ifFalse:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
954 |
(count == 4) ifTrue:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
955 |
msg := s , tmp , ' |
835 | 956 |
' , (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
|
957 |
] ifFalse:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
958 |
" |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
959 |
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
|
960 |
superclass and show it ... |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
961 |
" |
1637 | 962 |
commonSuperClass := Behavior commonSuperclassOf:list. |
913 | 963 |
(commonSuperClass ~~ Object |
964 |
and:[commonSuperClass ~~ Behavior |
|
965 |
and:[commonSuperClass ~~ Class |
|
966 |
and:[commonSuperClass ~~ ClassDescription]]]) ifTrue:[ |
|
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
967 |
(list includes:commonSuperClass) ifTrue:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
968 |
msg := s . tmp , count printString , commonSuperClass name |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
969 |
, ' and redefined in ' , (count - 1) printString |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
970 |
, ' subclasses' |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
971 |
, s2. |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
972 |
firstImplementingClass := commonSuperClass |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
973 |
] ifFalse:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
974 |
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
|
975 |
] |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
976 |
] ifFalse:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
977 |
(commonSuperClass == Object |
1249
780b4a1a3967
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1245
diff
changeset
|
978 |
and:[commonSuperClass includesSelector:sym]) ifTrue:[ |
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
979 |
msg := s , tmp , count printString , ' classes. |
834 | 980 |
|
981 |
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
|
982 |
since there is an implementation in Object.' , s2. |
141 | 983 |
|
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
984 |
firstImplementingClass := Object |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
985 |
] ifFalse:[ |
913 | 986 |
((commonSuperClass == Behavior |
987 |
or:[commonSuperClass == Class |
|
988 |
or:[commonSuperClass == ClassDescription]]) |
|
1249
780b4a1a3967
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1245
diff
changeset
|
989 |
and:[commonSuperClass includesSelector:sym]) ifTrue:[ |
913 | 990 |
msg := s , tmp , count printString , ' classes. |
991 |
||
992 |
All classes seem to respond to that message, |
|
993 |
since there is an implementation in ' , commonSuperClass name , '.' , s2. |
|
994 |
||
995 |
firstImplementingClass := commonSuperClass |
|
996 |
] ifFalse:[ |
|
997 |
" |
|
998 |
otherwise just give the number. |
|
999 |
" |
|
1000 |
msg := s , tmp , count printString , ' classes.' , s2 |
|
1001 |
] |
|
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
1002 |
] |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
1003 |
] |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
1004 |
] |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
1005 |
] |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
1006 |
]. |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
1007 |
]. |
1909 | 1008 |
shortText ifTrue:[ |
1009 |
count == 1 ifTrue:[ |
|
1910 | 1010 |
cm := self fetchCommentOfMethod:(firstImplementingClass compiledMethodAt:sym). |
1011 |
cm notNil ifTrue:[ |
|
1012 |
msg := msg,' ',cm |
|
1013 |
]. |
|
1909 | 1014 |
]. |
1015 |
] ifFalse:[ |
|
1185 | 1016 |
firstImplementingClass notNil ifTrue:[ |
1017 |
WindowGroup activeGroup withWaitCursorDo:[ |
|
1018 |
cm := firstImplementingClass compiledMethodAt:sym. |
|
1019 |
cm notNil ifTrue:[ |
|
1020 |
cm := cm methodComment. |
|
1021 |
] |
|
1022 |
]. |
|
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
1023 |
cm notNil ifTrue:[ |
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
1024 |
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
|
1025 |
] |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
1026 |
]. |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
1027 |
]. |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
1028 |
^ msg |
141 | 1029 |
]. |
1030 |
||
2288
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1031 |
count := listSimilar size. |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1032 |
(count ~~ 0) ifTrue:[ |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1033 |
listSimilar := listSimilar asOrderedCollection sort. |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1034 |
shortText ifTrue:[ |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1035 |
tmp := ' is implemented in '. |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1036 |
] ifFalse:[ |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1037 |
tmp := ' is a selector implemented in '. |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1038 |
]. |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1039 |
|
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1040 |
(count == 1) ifTrue:[ |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1041 |
msg := listSimilar first allBold , tmp , firstImplementingClassOfSimilar name , '.'. |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1042 |
shortText ifFalse:[ |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1043 |
msg := msg , s2. |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1044 |
] |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1045 |
] ifFalse:[ |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1046 |
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
|
1047 |
count > 2 ifTrue:[ |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1048 |
msg := msg,'...'. |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1049 |
]. |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1050 |
]. |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1051 |
^ msg |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1052 |
]. |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1053 |
|
141 | 1054 |
^ nil |
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
1055 |
|
1909 | 1056 |
"Modified: / 17-06-1996 / 17:09:30 / stefan" |
1057 |
"Created: / 23-03-1999 / 13:29:33 / cg" |
|
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
1058 |
"Modified: / 09-10-2006 / 12:11:58 / cg" |
141 | 1059 |
! |
1060 |
||
1183 | 1061 |
explainSelfIn:aClass short:shortText |
1244 | 1062 |
|sub subNames selfString className nSubClasses| |
1198 | 1063 |
|
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
1064 |
selfString := '''' , 'self' "allBold" , ''''. |
6 | 1065 |
|
1244 | 1066 |
sub := aClass allSubclasses. |
1067 |
nSubClasses := sub size. |
|
1068 |
||
1069 |
aClass isMeta ifTrue:[ |
|
1070 |
className := aClass theNonMetaclass name. |
|
1071 |
subNames := sub collect:[:c | c theNonMetaclass name]. |
|
1072 |
nSubClasses == 0 ifTrue:[ |
|
1073 |
shortText ifTrue:[ |
|
1074 |
^ selfString , ' - the ''' , className , '''-class.' |
|
1075 |
]. |
|
1076 |
^ selfString , 'refers to the object which received the message. |
|
1077 |
||
1078 |
In this case, it will be the ' , className , '-class itself.' |
|
1079 |
]. |
|
1080 |
||
1081 |
shortText ifTrue:[ |
|
1082 |
nSubClasses == 1 ifTrue:[ |
|
1083 |
^ selfString , ' - the ''' , className , '''- or ''' , subNames first , '''-class.' |
|
1084 |
]. |
|
1085 |
^ selfString , ' - the ''' , className , '''-class or one of its subclasses.' |
|
1086 |
]. |
|
1087 |
nSubClasses <= 5 ifTrue:[ |
|
1088 |
^ selfString , ' refers to the object which received the message. |
|
1089 |
||
1090 |
In this case, it will be the ' , className , '-class |
|
1091 |
or one of its subclasses: |
|
1092 |
||
1093 |
' , subNames asStringCollection asString |
|
1094 |
]. |
|
1095 |
||
1096 |
^ selfString , ' refers to the object which received the message. |
|
1097 |
||
1098 |
In this case, it will be the ' , className , '-class |
|
1099 |
or one of its ' , nSubClasses printString , ' subclasses.' |
|
1100 |
]. |
|
1101 |
||
1256 | 1102 |
subNames := aClass allSubclasses collect:[:c | c theNonMetaclass name]. |
1244 | 1103 |
className := aClass name. |
1104 |
nSubClasses == 0 ifTrue:[ |
|
1183 | 1105 |
shortText ifTrue:[ |
1244 | 1106 |
^ selfString , ' - an instance of ''' , className , '''.' |
1183 | 1107 |
]. |
1198 | 1108 |
^ selfString , 'refers to the object which received the message. |
6 | 1109 |
|
1244 | 1110 |
In this case, it will be an instance of ' , className , '.' |
6 | 1111 |
]. |
1112 |
||
1183 | 1113 |
shortText ifTrue:[ |
1244 | 1114 |
nSubClasses == 1 ifTrue:[ |
1256 | 1115 |
^ selfString , ' - an instance of ''' , className , ''' or ''' , subNames first , '''.' |
1185 | 1116 |
]. |
1244 | 1117 |
^ selfString , ' - an instance of ''' , className , ''' or one of its subclasses.' |
1183 | 1118 |
]. |
1244 | 1119 |
nSubClasses <= 5 ifTrue:[ |
1198 | 1120 |
^ selfString , ' refers to the object which received the message. |
6 | 1121 |
|
1244 | 1122 |
In this case, it will be an instance of ' , className , ' |
6 | 1123 |
or one of its subclasses: |
1124 |
||
1256 | 1125 |
' , subNames asStringCollection asString |
6 | 1126 |
]. |
1127 |
||
1198 | 1128 |
^ selfString , ' refers to the object which received the message. |
6 | 1129 |
|
1244 | 1130 |
In this case, it will be an instance of ' , className , ' |
1131 |
or one of its ' , nSubClasses printString , ' subclasses.' |
|
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
1132 |
|
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
1133 |
"Modified: / 09-10-2006 / 12:11:44 / cg" |
6 | 1134 |
! |
1135 |
||
1188 | 1136 |
explainSuperIn:aClass short:shortText |
1352 | 1137 |
|superName| |
1244 | 1138 |
|
1139 |
superName := aClass superclass name. |
|
1188 | 1140 |
|
1141 |
shortText ifTrue:[ |
|
1244 | 1142 |
^ '''super'' - message lookup starts in ' , superName , '.' |
1188 | 1143 |
]. |
1144 |
||
6 | 1145 |
^ 'like self, super refers to the object which received the message. |
1146 |
||
1147 |
However, when sending a message to super the search for methods |
|
1244 | 1148 |
implementing this message will start in the superclass (' , superName , ') |
84 | 1149 |
instead of the receivers class (' , aClass name , ' or subclass). |
49 | 1150 |
Thus, using super, a redefined method can call the original method in its superclass.' |
6 | 1151 |
! |
2 | 1152 |
|
49 | 1153 |
explainSyntax:string |
1154 |
"try syntax ...; return explanation or nil" |
|
1155 |
||
1183 | 1156 |
^ self explainSyntax:string short:false |
1157 |
! |
|
1158 |
||
1159 |
explainSyntax:string short:shortText |
|
1160 |
"try syntax ...; return explanation or nil" |
|
1161 |
||
49 | 1162 |
((string = ':=') or:[string = '_']) ifTrue:[ |
1183 | 1163 |
shortText ifTrue:[ |
1164 |
^ 'Assign to variable on the left side.'. |
|
1165 |
]. |
|
1166 |
||
796 | 1167 |
^ '<variable> := <expression> |
49 | 1168 |
|
834 | 1169 |
'':='' and ''_'' (which is left-arrow in some fonts) mean assignment. |
49 | 1170 |
The variable is bound to (i.e. points to) the value of <expression>.' |
1171 |
]. |
|
1172 |
||
1173 |
(string = '^') ifTrue:[ |
|
1183 | 1174 |
shortText ifTrue:[ |
1175 |
^ 'Return value from method.'. |
|
1176 |
]. |
|
796 | 1177 |
^ '^ <expression> |
49 | 1178 |
|
834 | 1179 |
returns the value of <expression> as value from the method. |
49 | 1180 |
A return from within a block exits the method where the block is defined.' |
1181 |
]. |
|
1182 |
||
1183 |
(string = ';') ifTrue:[ |
|
1183 | 1184 |
shortText ifTrue:[ |
1185 |
^ 'Cascade expression.'. |
|
1186 |
]. |
|
796 | 1187 |
^ '<expression> ; selector1 ; .... ; selectorN |
49 | 1188 |
|
1189 |
a cascade expression; evaluate expression, and send messages |
|
1190 |
<selector1> ... <selectorN> to the first expressions receiver. |
|
1191 |
Returns the value of the last send. The cascade sends may also have arguments.' |
|
1192 |
]. |
|
1193 |
||
1194 |
(string = '|') ifTrue:[ |
|
1183 | 1195 |
shortText ifTrue:[ |
1196 |
^ ''. |
|
1197 |
]. |
|
796 | 1198 |
^ '| locals | or: [:arg | statements] |
49 | 1199 |
|
834 | 1200 |
''|'' is used to mark a local variable declaration or separates arguments |
49 | 1201 |
from the statements in a block. Notice, that in a block-argument declaration |
1202 |
these must be prefixed by a colon character. |
|
834 | 1203 |
''|'' is also a selector understood by Booleans.' |
49 | 1204 |
]. |
1205 |
||
2287
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1206 |
(string startsWith:'#' ) ifTrue:[ |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1207 |
(string startsWith:'#(' ) ifTrue:[ |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1208 |
shortText ifTrue:[ |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1209 |
^ 'Array Literal.'. |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1210 |
]. |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1211 |
^ 'is a constant Array. |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1212 |
|
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1213 |
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
|
1214 |
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
|
1215 |
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
|
1216 |
another array constant or a byte-array. |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1217 |
(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
|
1218 |
constant-Array elements).' |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1219 |
]. |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1220 |
|
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1221 |
(string startsWith:'#[') ifTrue:[ |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1222 |
shortText ifTrue:[ |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1223 |
^ 'ByteArray Literal.'. |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1224 |
]. |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1225 |
^ 'is a constant ByteArray. |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1226 |
|
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1227 |
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
|
1228 |
0 .. 255. |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1229 |
(notice, that not all Smalltalk implementations support constant ByteArrays).' |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1230 |
]. |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1231 |
|
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1232 |
(string startsWith:'#''') ifTrue:[ |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1233 |
shortText ifTrue:[ |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1234 |
^ 'Symbol Literal.'. |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1235 |
]. |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1236 |
^ 'is a constant symbol containing non-alphanumeric characters. |
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 |
Symbols are unique strings, meaning that there exists |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1239 |
exactly one instance of a given symbol. Therefore symbols can |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1240 |
be compared using == (identity compare) in addition to = (contents compare). |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1241 |
Beside this, Symbols behave mostly like Strings. |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1242 |
|
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1243 |
Notice, that not all Smalltalk implementations support this kind of symbols.' |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1244 |
]. |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1245 |
|
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1246 |
shortText ifTrue:[ |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1247 |
^ 'Symbol Literal.'. |
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 |
^ 'is a symbol. |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1250 |
|
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1251 |
Symbols are unique strings, meaning that there exists |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1252 |
exactly one instance of a given symbol. Therefore symbols can |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1253 |
be compared using == (identity compare) in addition to = (contents compare). |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1254 |
Beside this, Symbols behave mostly like Strings.' |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1255 |
]. |
49 | 1256 |
((string startsWith:'(') or:[string endsWith:')']) ifTrue:[ |
1183 | 1257 |
shortText ifTrue:[ |
1258 |
^ ''. |
|
1259 |
]. |
|
796 | 1260 |
^ '(<expression>) |
49 | 1261 |
|
1262 |
expression grouping.' |
|
1263 |
]. |
|
1264 |
||
1265 |
((string startsWith:'[') or:[string endsWith:']']) ifTrue:[ |
|
1183 | 1266 |
shortText ifTrue:[ |
1267 |
^ ''. |
|
1268 |
]. |
|
834 | 1269 |
^ '[:arg1 .. :argN | statements] |
49 | 1270 |
|
1271 |
defines a block. |
|
1272 |
Blocks represent pieces of executable code. Definition of a block does |
|
1273 |
not evaluate it. The block is evaluated by sending it a value/value: |
|
1274 |
message. |
|
1275 |
Blocks are often passed as arguments to Booleans (i.e. ifTrue:[...]) or |
|
1276 |
collections (i.e. do:[...]).' |
|
1277 |
]. |
|
1278 |
||
2286
cabf7db33a38
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2226
diff
changeset
|
1279 |
((string startsWith:'{') or:[string endsWith:'}']) ifTrue:[ |
cabf7db33a38
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2226
diff
changeset
|
1280 |
shortText ifTrue:[ |
cabf7db33a38
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2226
diff
changeset
|
1281 |
^ 'array instantiation'. |
cabf7db33a38
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2226
diff
changeset
|
1282 |
]. |
cabf7db33a38
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2226
diff
changeset
|
1283 |
^ '{ <expr1>. .. <exprN> } |
cabf7db33a38
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2226
diff
changeset
|
1284 |
|
cabf7db33a38
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2226
diff
changeset
|
1285 |
is syntactic sugar for "Array with:<expr1> .. with:<exprN>". |
cabf7db33a38
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2226
diff
changeset
|
1286 |
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
|
1287 |
The expressions are separated by a period statement separator. |
cabf7db33a38
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2226
diff
changeset
|
1288 |
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
|
1289 |
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
|
1290 |
compilation time) and which is shared.' |
cabf7db33a38
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2226
diff
changeset
|
1291 |
]. |
cabf7db33a38
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2226
diff
changeset
|
1292 |
|
49 | 1293 |
(string = ':') ifTrue:[ |
1183 | 1294 |
shortText ifTrue:[ |
1295 |
^ ''. |
|
1296 |
]. |
|
796 | 1297 |
^ 'colons have different meaning depending on context: |
49 | 1298 |
|
1299 |
1) they separate keyword-parts in symbols and keyword-messages as in: |
|
1300 |
||
1301 |
#at:put: a constant keyword symbol |
|
1302 |
||
1303 |
rec at:index put:value sends the #at:put: message to rec, |
|
796 | 1304 |
passing index and value as arguments. |
49 | 1305 |
|
1306 |
2) within block-argument declarations as in: |
|
1307 |
||
1308 |
[:arg1 :arg2 | statements] |
|
834 | 1309 |
|
1310 |
3) within an identifier, they separate the nameSpace part from |
|
1311 |
the name part; as in: |
|
1312 |
||
1313 |
Smalltalk::Array - the Array class in the Smalltalk nameSpace. |
|
1314 |
Foo::Array - the Array class in the Foo nameSpace. |
|
49 | 1315 |
' |
1316 |
]. |
|
1317 |
||
1318 |
(string = '.') ifTrue:[ |
|
796 | 1319 |
^ 'statement. "<- period here" |
49 | 1320 |
statement |
1321 |
||
1322 |
within a method or block, individual statements are separated by periods. |
|
1323 |
' |
|
1324 |
]. |
|
1325 |
||
1326 |
"/ is it a symbol without hash-character ? |
|
1327 |
"/ |
|
796 | 1328 |
"/ string knownAsSymbol ifTrue:[ |
1329 |
"/ ^ 'is nothing, but #' , string , ' is known as a symbol. |
|
1330 |
"/ |
|
1331 |
"/Symbols are unique strings, meaning that there exists |
|
1332 |
"/exactly one instance of a given symbol. Therefore symbols can |
|
1333 |
"/be compared using == (identity compare) in addition to = (contents compare). |
|
1334 |
"/Beside this, Symbols behave mostly like Strings.' |
|
1335 |
"/ ]. |
|
49 | 1336 |
|
1337 |
^ nil |
|
796 | 1338 |
|
1339 |
"Modified: / 31.10.1998 / 14:28:58 / cg" |
|
2214 | 1340 |
! |
1341 |
||
1342 |
valueStringFor:aValue |
|
1343 |
|valString| |
|
1344 |
||
1345 |
"/ only show the value, if it is really short... |
|
1346 |
(aValue isBoolean or:[aValue isNil]) ifTrue:[ |
|
2226 | 1347 |
^ aValue storeString. |
1348 |
]. |
|
2427 | 1349 |
|
2226 | 1350 |
(aValue isNumber |
1351 |
or:[aValue isPoint]) ifTrue:[ |
|
1352 |
^ aValue storeString. |
|
1353 |
]. |
|
1354 |
(aValue isColor) ifTrue:[ |
|
1355 |
^ 'Color: ',(' ' emphasizeAllWith:(#backgroundColor->aValue)). |
|
1356 |
]. |
|
1357 |
||
1358 |
(aValue isString) ifTrue:[ |
|
2214 | 1359 |
valString := aValue storeString. |
2226 | 1360 |
"/ valString := aValue className, ' ' , aValue storeString . |
2214 | 1361 |
]. |
1362 |
||
2427 | 1363 |
((aValue isKindOf:GUID) |
1364 |
or:[ aValue isKindOf:UUID ]) ifTrue:[ |
|
1365 |
valString := aValue printString. |
|
1366 |
]. |
|
1367 |
||
2214 | 1368 |
(valString isEmptyOrNil |
2427 | 1369 |
or:[ valString size > 50 |
2214 | 1370 |
or:[ valString includes:Character cr ]]) ifTrue:[ |
1371 |
valString := aValue classNameWithArticle. |
|
1372 |
]. |
|
1373 |
||
1374 |
^ valString |
|
2427 | 1375 |
|
1376 |
"Modified: / 14-10-2010 / 11:57:52 / cg" |
|
141 | 1377 |
! ! |
49 | 1378 |
|
396 | 1379 |
!Explainer class methodsFor:'documentation'! |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
1380 |
|
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
1381 |
version |
2427 | 1382 |
^ '$Header: /cvs/stx/stx/libcomp/Explainer.st,v 1.103 2010-10-14 09:58:06 cg Exp $' |
2214 | 1383 |
! |
1384 |
||
1385 |
version_CVS |
|
2427 | 1386 |
^ '$Header: /cvs/stx/stx/libcomp/Explainer.st,v 1.103 2010-10-14 09:58:06 cg Exp $' |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
1387 |
! ! |