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