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