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