author | Claus Gittinger <cg@exept.de> |
Tue, 20 Feb 2001 18:06:56 +0100 | |
changeset 1151 | a1173e82de18 |
parent 1081 | 6e6255672d68 |
child 1159 | 24a034278a55 |
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 |
|
84 | 42 |
codeView (popup or via CMD-E). |
263 | 43 |
|
44 |
[author:] |
|
45 |
Claus Gittinger |
|
2 | 46 |
" |
47 |
! ! |
|
48 |
||
396 | 49 |
!Explainer class methodsFor:'explaining'! |
2 | 50 |
|
141 | 51 |
commonSuperClassOf:listOfClassNames |
52 |
|common found| |
|
53 |
||
54 |
listOfClassNames do:[:className | |
|
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
55 |
|class| |
141 | 56 |
|
336 | 57 |
class := Smalltalk classNamed:className. |
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
58 |
common isNil ifTrue:[ |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
59 |
common := class |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
60 |
] ifFalse:[ |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
61 |
(class isSubclassOf:common) ifTrue:[ |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
62 |
"keep common" |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
63 |
] ifFalse:[ |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
64 |
(common isSubclassOf:class) ifTrue:[ |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
65 |
common := class |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
66 |
] ifFalse:[ |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
67 |
"walk up, checking" |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
68 |
found := false. |
1151 | 69 |
|
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
70 |
common allSuperclassesDo:[:sup | |
1151 | 71 |
(found not and:[class isSubclassOf:sup]) ifTrue:[ |
72 |
common := sup. |
|
73 |
found := true. |
|
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
74 |
] |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
75 |
]. |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
76 |
found ifFalse:[ |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
77 |
class allSuperclassesDo:[:sup | |
1151 | 78 |
(found not and:[common isSubclassOf:sup]) ifTrue:[ |
79 |
common := sup. |
|
80 |
found := true. |
|
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
81 |
] |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
82 |
]. |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
83 |
]. |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
84 |
] |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
85 |
]. |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
86 |
]. |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
87 |
common == Object ifTrue:[^ common] |
141 | 88 |
]. |
89 |
^ common |
|
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
90 |
|
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
91 |
"Modified: 17.6.1996 / 17:09:21 / stefan" |
336 | 92 |
"Modified: 5.9.1996 / 19:34:41 / cg" |
141 | 93 |
! |
94 |
||
2 | 95 |
explain:someText in:source forClass:aClass |
6 | 96 |
"Given a source and a substring of it, return a string containing |
97 |
an explanation. |
|
49 | 98 |
This is just a q&d implementation - to be correct, it should use the parser, |
99 |
and explain from the parsetree (instead of doing string matches). |
|
100 |
This leads to some wrong explanations, for example if some string is |
|
839 | 101 |
used as selector within a string, or if a variable is named like a |
102 |
message selector. I.e. the explanation should be context sensitive. |
|
49 | 103 |
Also, there could be much more detailed explanations." |
2 | 104 |
|
693 | 105 |
|parser variables v c string tmp |
839 | 106 |
spc sym sel stringText| |
2 | 107 |
|
675 | 108 |
string := someText string withoutSeparators. |
839 | 109 |
stringText := string asText allBold. |
49 | 110 |
|
111 |
" |
|
112 |
ask parser for variable names |
|
113 |
" |
|
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
114 |
parser := self parseMethod:source in:aClass ignoreErrors:true ignoreWarnings:true. |
2 | 115 |
parser notNil ifTrue:[ |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
116 |
"look for variables" |
2 | 117 |
|
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
118 |
variables := parser methodVars. |
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
119 |
(variables notNil and:[variables includes:string]) ifTrue:[ |
839 | 120 |
^ '''' , stringText , ''' is a method variable' |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
121 |
]. |
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
122 |
variables := parser methodArgs. |
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
123 |
(variables notNil and:[variables includes:string]) ifTrue:[ |
839 | 124 |
^ '''' , stringText , ''' is a method argument' |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
125 |
] |
2 | 126 |
]. |
49 | 127 |
|
2 | 128 |
parser isNil ifTrue:[ |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
129 |
parser := self for:(ReadStream on:source) in:aClass |
2 | 130 |
]. |
131 |
||
132 |
"instvars" |
|
84 | 133 |
c := aClass whichClassDefinesInstVar:string. |
134 |
c notNil ifTrue:[ |
|
396 | 135 |
c isMeta ifTrue:[ |
839 | 136 |
^ '''' , stringText , ''' is a class instance variable in ' , c soleInstance name |
396 | 137 |
]. |
138 |
||
839 | 139 |
^ '''' , stringText , ''' is an instance variable in ' , c name |
2 | 140 |
]. |
141 |
||
84 | 142 |
"/ variables := aClass allInstVarNames. |
143 |
"/ (variables notNil and:[variables includes:string]) ifTrue:[ |
|
144 |
"/ "where is it" |
|
145 |
"/ c := aClass. |
|
146 |
"/ [c notNil] whileTrue:[ |
|
147 |
"/ v := c instVarNames. |
|
148 |
"/ (v notNil and:[v includes:string]) ifTrue:[ |
|
149 |
"/ ^ string , ' is an instance variable in ' , c name |
|
150 |
"/ ]. |
|
151 |
"/ c := c superclass |
|
152 |
"/ ]. |
|
153 |
"/ self error:'oops' |
|
154 |
"/ ]. |
|
155 |
||
442 | 156 |
"/ "class instvars" |
157 |
"/ variables := aClass class allInstVarNames. |
|
158 |
"/ (variables notNil and:[variables includes:string]) ifTrue:[ |
|
159 |
"/ "where is it" |
|
160 |
"/ c := aClass. |
|
161 |
"/ [c notNil] whileTrue:[ |
|
162 |
"/ v := c class instVarNames. |
|
163 |
"/ (v notNil and:[v includes:string]) ifTrue:[ |
|
164 |
"/ ^ string , ' is a class instance variable in ' , c name |
|
165 |
"/ ]. |
|
166 |
"/ c := c superclass |
|
167 |
"/ ]. |
|
168 |
"/ self error:'oops' |
|
169 |
"/ ]. |
|
2 | 170 |
|
171 |
"classvars" |
|
172 |
c := parser inWhichClassIsClassVar:string. |
|
173 |
c notNil ifTrue:[ |
|
839 | 174 |
^ '''' , stringText , ''' is a class variable in ' , c name |
2 | 175 |
]. |
176 |
||
509
d8475399ca3e
Correct handling of private classes.
Stefan Vogel <sv@exept.de>
parents:
503
diff
changeset
|
177 |
aClass isMeta ifTrue:[ |
d8475399ca3e
Correct handling of private classes.
Stefan Vogel <sv@exept.de>
parents:
503
diff
changeset
|
178 |
c := aClass soleInstance. |
d8475399ca3e
Correct handling of private classes.
Stefan Vogel <sv@exept.de>
parents:
503
diff
changeset
|
179 |
] ifFalse:[ |
d8475399ca3e
Correct handling of private classes.
Stefan Vogel <sv@exept.de>
parents:
503
diff
changeset
|
180 |
c := aClass. |
d8475399ca3e
Correct handling of private classes.
Stefan Vogel <sv@exept.de>
parents:
503
diff
changeset
|
181 |
]. |
d8475399ca3e
Correct handling of private classes.
Stefan Vogel <sv@exept.de>
parents:
503
diff
changeset
|
182 |
c privateClasses do:[:pClass | |
d8475399ca3e
Correct handling of private classes.
Stefan Vogel <sv@exept.de>
parents:
503
diff
changeset
|
183 |
(pClass name = string |
d8475399ca3e
Correct handling of private classes.
Stefan Vogel <sv@exept.de>
parents:
503
diff
changeset
|
184 |
or:[pClass nameWithoutPrefix = string]) ifTrue:[ |
839 | 185 |
^ ('''' , stringText , ''' is a private class in ''' , c name , '''.' |
422 | 186 |
, '\\It is only visible locally.') withCRs |
187 |
]. |
|
188 |
]. |
|
189 |
||
456 | 190 |
(spc := aClass nameSpace) notNil ifTrue:[ |
796 | 191 |
sym := (spc name , '::' , string) asSymbolIfInterned. |
192 |
sym notNil ifTrue:[ |
|
193 |
(Smalltalk at:sym) isBehavior ifTrue:[ |
|
839 | 194 |
^ ('''' , stringText , ''' is a class in the ''' , spc name , ''' nameSpace.' |
796 | 195 |
, '\\It is only visible within this nameSpace.' |
196 |
, '\Access from the outside is possible' |
|
197 |
, '\by the special name ''' , spc name , '::' , string , '''.') withCRs |
|
198 |
]. |
|
422 | 199 |
]. |
200 |
]. |
|
201 |
||
796 | 202 |
"/ string knownAsSymbol ifTrue:[ |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
203 |
"globals & symbols" |
2 | 204 |
|
835 | 205 |
tmp := self explainKnownSymbol:string inClass:aClass. |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
206 |
tmp notNil ifTrue:[ ^ tmp]. |
839 | 207 |
|
208 |
"/ try with added colon ... |
|
209 |
sel := string , ':'. |
|
210 |
Symbol allInstancesDo:[:sym | |
|
211 |
(sym startsWith:sel) ifTrue:[ |
|
212 |
tmp := self explainKnownSymbol:sym inClass:aClass. |
|
213 |
tmp notNil ifTrue:[ ^ tmp]. |
|
214 |
] |
|
215 |
]. |
|
796 | 216 |
"/ ]. |
2 | 217 |
|
218 |
"try for some obvious things" |
|
219 |
tmp := self explainPseudoVariable:string in:aClass. |
|
220 |
tmp notNil ifTrue:[ ^ tmp]. |
|
221 |
||
222 |
"try syntax ..." |
|
223 |
||
49 | 224 |
tmp := self explainSyntax:string. |
225 |
tmp notNil ifTrue:[ ^ tmp]. |
|
20 | 226 |
|
2 | 227 |
parser isNil ifTrue:[ |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
228 |
^ 'parse error - no explanation' |
2 | 229 |
]. |
796 | 230 |
^ '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
|
231 |
|
675 | 232 |
"Created: / 3.12.1995 / 12:47:37 / cg" |
233 |
"Modified: / 16.4.1997 / 12:46:11 / stefan" |
|
835 | 234 |
"Modified: / 23.3.1999 / 13:29:56 / cg" |
2 | 235 |
! |
236 |
||
141 | 237 |
explainHereIn:aClass |
238 |
^ 'like self, here refers to the object which received the message. |
|
239 |
||
240 |
However, when sending a message to here the search for methods |
|
241 |
implementing this message will start in the defining class (' , aClass name , ') |
|
242 |
instead of the receivers class (' , aClass name , ' or subclass). |
|
243 |
Thus, using here, redefined methods will NOT be reached with a here-send.' |
|
244 |
! |
|
245 |
||
835 | 246 |
explainKnownSymbol:string inClass:aClass |
141 | 247 |
"return explanation or nil" |
248 |
||
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
249 |
|sym list count tmp commonSuperClass val s s2 |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
250 |
firstImplementingClass cm msg| |
141 | 251 |
|
796 | 252 |
sym := string asSymbolIfInterned. |
253 |
sym isNil ifTrue:[^ nil]. |
|
141 | 254 |
|
255 |
"try globals" |
|
256 |
||
257 |
(Smalltalk includesKey:sym) ifTrue:[ |
|
839 | 258 |
tmp := '''' , string asText allBold , ''' is a global variable.'. |
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
259 |
val := Smalltalk at:sym. |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
260 |
val isBehavior ifTrue:[ |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
261 |
val name = string ifTrue:[ |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
262 |
tmp := tmp , ' |
141 | 263 |
|
503
b0d10f53a820
show 'autoloaded' for classes
Claus Gittinger <cg@exept.de>
parents:
497
diff
changeset
|
264 |
' , string , ' is ' , (val isLoaded ifTrue:['a'] ifFalse:['an autoloaded']) |
b0d10f53a820
show 'autoloaded' for classes
Claus Gittinger <cg@exept.de>
parents:
497
diff
changeset
|
265 |
, ' class categorized as ' , val category , ' |
141 | 266 |
in the ''' , val package , ''' package.' |
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
267 |
] ifFalse:[ |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
268 |
tmp := tmp , ' |
141 | 269 |
|
270 |
' , string , ' is bound to the class ' , val name , |
|
271 |
' in category ' , val category , '.' |
|
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
272 |
] |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
273 |
] ifFalse:[ |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
274 |
tmp := tmp , ' |
141 | 275 |
|
276 |
Its current value is ' , val classNameWithArticle , '.' |
|
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
277 |
]. |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
278 |
^ tmp. |
141 | 279 |
]. |
280 |
||
281 |
" |
|
282 |
try selectors |
|
283 |
look who implements it |
|
284 |
" |
|
285 |
list := Set new. |
|
1081 | 286 |
Smalltalk allClassesDo:[:c| |
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
287 |
(c implements:sym) ifTrue:[ |
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
288 |
list add:(c name). |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
289 |
firstImplementingClass isNil ifTrue:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
290 |
firstImplementingClass := c |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
291 |
] |
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
292 |
]. |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
293 |
(c class implements:sym) ifTrue:[ |
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
294 |
list add:(c name , ' class'). |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
295 |
firstImplementingClass isNil ifTrue:[ |
912 | 296 |
firstImplementingClass := c class |
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
297 |
] |
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
298 |
] |
141 | 299 |
]. |
300 |
||
835 | 301 |
(aClass canUnderstand:sym) ifTrue:[ |
302 |
s2 := ('\\Instances of ''' , aClass name , ''' respond to #') withCRs , sym asText allBold |
|
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
303 |
, '\- inherited from ' withCRs, (aClass whichClassImplements:sym) name asText allBold. |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
304 |
|
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
305 |
firstImplementingClass := (aClass whichClassImplements:sym) |
835 | 306 |
] ifFalse:[ |
307 |
s2 := ''. |
|
308 |
]. |
|
309 |
||
141 | 310 |
count := list size. |
311 |
(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
|
312 |
" |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
313 |
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
|
314 |
list them |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
315 |
" |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
316 |
list := list asOrderedCollection sort. |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
317 |
tmp := ' is a selector implemented in '. |
835 | 318 |
s := '#' , string asText allBold. |
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
319 |
|
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
320 |
(count == 1) ifTrue:[ |
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
321 |
msg := s , tmp , (list at:1) , '.' , s2. |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
322 |
] ifFalse:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
323 |
(count == 2) ifTrue:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
324 |
msg := s , tmp , (list at:1) , ' and ' , (list at:2) , '.' , s2 |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
325 |
] ifFalse:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
326 |
(count == 3) ifTrue:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
327 |
msg := s , tmp , ' |
835 | 328 |
' , (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
|
329 |
] ifFalse:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
330 |
(count == 4) ifTrue:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
331 |
msg := s , tmp , ' |
835 | 332 |
' , (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
|
333 |
] ifFalse:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
334 |
" |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
335 |
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
|
336 |
superclass and show it ... |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
337 |
" |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
338 |
commonSuperClass := self commonSuperClassOf:list. |
913 | 339 |
(commonSuperClass ~~ Object |
340 |
and:[commonSuperClass ~~ Behavior |
|
341 |
and:[commonSuperClass ~~ Class |
|
342 |
and:[commonSuperClass ~~ ClassDescription]]]) ifTrue:[ |
|
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
343 |
(list includes:commonSuperClass) ifTrue:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
344 |
msg := s . tmp , count printString , commonSuperClass name |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
345 |
, ' and redefined in ' , (count - 1) printString |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
346 |
, ' subclasses' |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
347 |
, s2. |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
348 |
firstImplementingClass := commonSuperClass |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
349 |
] ifFalse:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
350 |
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
|
351 |
] |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
352 |
] ifFalse:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
353 |
(commonSuperClass == Object |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
354 |
and:[commonSuperClass implements:sym]) ifTrue:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
355 |
msg := s , tmp , count printString , ' classes. |
834 | 356 |
|
357 |
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
|
358 |
since there is an implementation in Object.' , s2. |
141 | 359 |
|
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
360 |
firstImplementingClass := Object |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
361 |
] ifFalse:[ |
913 | 362 |
((commonSuperClass == Behavior |
363 |
or:[commonSuperClass == Class |
|
364 |
or:[commonSuperClass == ClassDescription]]) |
|
365 |
and:[commonSuperClass implements:sym]) ifTrue:[ |
|
366 |
msg := s , tmp , count printString , ' classes. |
|
367 |
||
368 |
All classes seem to respond to that message, |
|
369 |
since there is an implementation in ' , commonSuperClass name , '.' , s2. |
|
370 |
||
371 |
firstImplementingClass := commonSuperClass |
|
372 |
] ifFalse:[ |
|
373 |
" |
|
374 |
otherwise just give the number. |
|
375 |
" |
|
376 |
msg := s , tmp , count printString , ' classes.' , s2 |
|
377 |
] |
|
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
378 |
] |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
379 |
] |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
380 |
] |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
381 |
] |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
382 |
]. |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
383 |
]. |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
384 |
firstImplementingClass notNil ifTrue:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
385 |
WindowGroup activeGroup withWaitCursorDo:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
386 |
cm := firstImplementingClass compiledMethodAt:sym. |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
387 |
cm notNil ifTrue:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
388 |
cm := cm methodComment. |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
389 |
] |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
390 |
]. |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
391 |
cm notNil ifTrue:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
392 |
msg := msg , '\\The comment in ' withCRs , firstImplementingClass name asText allBold , ' is:\' withCRs , cm asText allItalic. |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
393 |
] |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
394 |
]. |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
395 |
^ msg |
141 | 396 |
]. |
397 |
||
398 |
^ nil |
|
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
399 |
|
796 | 400 |
"Modified: / 17.6.1996 / 17:09:30 / stefan" |
835 | 401 |
"Created: / 23.3.1999 / 13:29:33 / cg" |
402 |
"Modified: / 23.3.1999 / 13:40:40 / cg" |
|
141 | 403 |
! |
404 |
||
2 | 405 |
explainPseudoVariable:string in:aClass |
406 |
"return explanation for the pseudoVariables self, super etc." |
|
407 |
||
408 |
(string = 'self') ifTrue:[ |
|
49 | 409 |
^ self explainSelfIn:aClass |
2 | 410 |
]. |
411 |
||
412 |
(string = 'super') ifTrue:[ |
|
49 | 413 |
^ self explainSuperIn:aClass |
2 | 414 |
]. |
415 |
||
84 | 416 |
(string = 'here') ifTrue:[ |
417 |
^ self explainHereIn:aClass |
|
418 |
]. |
|
419 |
||
2 | 420 |
(string = 'thisContext') ifTrue:[ |
49 | 421 |
^ 'thisContext is a pseudo variable (i.e. it is built in). |
2 | 422 |
|
49 | 423 |
ThisContext always refers to the context object for the currently executed method or |
424 |
block (an instance of Context or BlockContext respectively). The calling chain and calling |
|
6 | 425 |
receivers/selectors can be accessed via thisContext.' |
426 |
]. |
|
427 |
||
428 |
(string = 'true') ifTrue:[ |
|
49 | 429 |
^ 'true is a pseudo variable (i.e. it is built in). |
6 | 430 |
|
431 |
True represents logical truth. It is the one and only instance of class True.' |
|
2 | 432 |
]. |
433 |
||
434 |
(string = 'false') ifTrue:[ |
|
49 | 435 |
^ 'false is a pseudo variable (i.e. it is built in). |
2 | 436 |
|
437 |
False represents logical falseness. It is the one and only instance of class False.' |
|
438 |
]. |
|
439 |
||
440 |
(string = 'nil') ifTrue:[ |
|
49 | 441 |
^ 'nil is a pseudo variable (i.e. it is built in). |
2 | 442 |
|
443 |
Nil is used for unitialized variables (among other uses). |
|
444 |
Nil is the one and only instance of class UndefinedObject.' |
|
445 |
]. |
|
446 |
^ nil |
|
447 |
! |
|
448 |
||
6 | 449 |
explainSelfIn:aClass |
450 |
|sub| |
|
451 |
||
452 |
sub := aClass allSubclasses collect:[:c | c name]. |
|
453 |
sub size == 0 ifTrue:[ |
|
49 | 454 |
^ 'self refers to the object which received the message. |
6 | 455 |
|
456 |
In this case, it will be an instance of ' , aClass name , '.' |
|
457 |
]. |
|
458 |
||
459 |
sub size <= 5 ifTrue:[ |
|
49 | 460 |
^ 'self refers to the object which received the message. |
6 | 461 |
|
462 |
In this case, it will be an instance of ' , aClass name , ' |
|
463 |
or one of its subclasses: |
|
464 |
||
58 | 465 |
' , sub asStringCollection asString |
6 | 466 |
]. |
467 |
||
468 |
^ 'self refers to the object which received the message. |
|
469 |
||
470 |
In this case, it will be an instance of ' , aClass name , ' |
|
471 |
or one of its ' , sub size printString , ' subclasses.' |
|
472 |
! |
|
473 |
||
474 |
explainSuperIn:aClass |
|
475 |
^ 'like self, super refers to the object which received the message. |
|
476 |
||
477 |
However, when sending a message to super the search for methods |
|
478 |
implementing this message will start in the superclass (' , aClass superclass name , ') |
|
84 | 479 |
instead of the receivers class (' , aClass name , ' or subclass). |
49 | 480 |
Thus, using super, a redefined method can call the original method in its superclass.' |
6 | 481 |
! |
2 | 482 |
|
49 | 483 |
explainSyntax:string |
484 |
"try syntax ...; return explanation or nil" |
|
485 |
||
486 |
((string = ':=') or:[string = '_']) ifTrue:[ |
|
796 | 487 |
^ '<variable> := <expression> |
49 | 488 |
|
834 | 489 |
'':='' and ''_'' (which is left-arrow in some fonts) mean assignment. |
49 | 490 |
The variable is bound to (i.e. points to) the value of <expression>.' |
491 |
]. |
|
492 |
||
493 |
(string = '^') ifTrue:[ |
|
796 | 494 |
^ '^ <expression> |
49 | 495 |
|
834 | 496 |
returns the value of <expression> as value from the method. |
49 | 497 |
A return from within a block exits the method where the block is defined.' |
498 |
]. |
|
499 |
||
500 |
(string = ';') ifTrue:[ |
|
796 | 501 |
^ '<expression> ; selector1 ; .... ; selectorN |
49 | 502 |
|
503 |
a cascade expression; evaluate expression, and send messages |
|
504 |
<selector1> ... <selectorN> to the first expressions receiver. |
|
505 |
Returns the value of the last send. The cascade sends may also have arguments.' |
|
506 |
]. |
|
507 |
||
508 |
(string = '|') ifTrue:[ |
|
796 | 509 |
^ '| locals | or: [:arg | statements] |
49 | 510 |
|
834 | 511 |
''|'' is used to mark a local variable declaration or separates arguments |
49 | 512 |
from the statements in a block. Notice, that in a block-argument declaration |
513 |
these must be prefixed by a colon character. |
|
834 | 514 |
''|'' is also a selector understood by Booleans.' |
49 | 515 |
]. |
516 |
||
517 |
((string startsWith:'(') or:[string endsWith:')']) ifTrue:[ |
|
796 | 518 |
^ '(<expression>) |
49 | 519 |
|
520 |
expression grouping.' |
|
521 |
]. |
|
522 |
||
523 |
((string startsWith:'[') or:[string endsWith:']']) ifTrue:[ |
|
834 | 524 |
^ '[:arg1 .. :argN | statements] |
49 | 525 |
|
526 |
defines a block. |
|
527 |
Blocks represent pieces of executable code. Definition of a block does |
|
528 |
not evaluate it. The block is evaluated by sending it a value/value: |
|
529 |
message. |
|
530 |
Blocks are often passed as arguments to Booleans (i.e. ifTrue:[...]) or |
|
531 |
collections (i.e. do:[...]).' |
|
532 |
]. |
|
533 |
||
534 |
(string = ':') ifTrue:[ |
|
796 | 535 |
^ 'colons have different meaning depending on context: |
49 | 536 |
|
537 |
1) they separate keyword-parts in symbols and keyword-messages as in: |
|
538 |
||
539 |
#at:put: a constant keyword symbol |
|
540 |
||
541 |
rec at:index put:value sends the #at:put: message to rec, |
|
796 | 542 |
passing index and value as arguments. |
49 | 543 |
|
544 |
2) within block-argument declarations as in: |
|
545 |
||
546 |
[:arg1 :arg2 | statements] |
|
834 | 547 |
|
548 |
3) within an identifier, they separate the nameSpace part from |
|
549 |
the name part; as in: |
|
550 |
||
551 |
Smalltalk::Array - the Array class in the Smalltalk nameSpace. |
|
552 |
Foo::Array - the Array class in the Foo nameSpace. |
|
49 | 553 |
' |
554 |
]. |
|
555 |
||
556 |
(string = '.') ifTrue:[ |
|
796 | 557 |
^ 'statement. "<- period here" |
49 | 558 |
statement |
559 |
||
560 |
within a method or block, individual statements are separated by periods. |
|
561 |
' |
|
562 |
]. |
|
563 |
||
564 |
(string startsWith:'#' ) ifTrue:[ |
|
796 | 565 |
(string startsWith:'#(' ) ifTrue:[ |
566 |
^ 'is a constant Array. |
|
49 | 567 |
|
568 |
The elements of a constant Array must be Number-constants, nil, true or false. |
|
569 |
(notice, that not all Smalltalk implementations allow true, false and nil as |
|
570 |
constant-Array elements).' |
|
796 | 571 |
]. |
49 | 572 |
|
796 | 573 |
(string startsWith:'#[') ifTrue:[ |
574 |
^ 'is a constant ByteArray. |
|
49 | 575 |
|
576 |
The elements of a constant ByteArray must be Integer constants in the range |
|
577 |
0 .. 255. |
|
578 |
(notice, that not all Smalltalk implementations support constant ByteArrays).' |
|
796 | 579 |
]. |
49 | 580 |
|
796 | 581 |
(string startsWith:'#''') ifTrue:[ |
582 |
^ 'is a constant symbol containing non-alphanumeric characters. |
|
49 | 583 |
|
584 |
Symbols are unique strings, meaning that there exists |
|
585 |
exactly one instance of a given symbol. Therefore symbols can |
|
586 |
be compared using == (identity compare) in addition to = (contents compare). |
|
587 |
Beside this, Symbols behave mostly like Strings. |
|
588 |
||
589 |
Notice, that not all Smalltalk implementations support this kind of symbols.' |
|
796 | 590 |
]. |
49 | 591 |
|
796 | 592 |
^ 'is a symbol. |
49 | 593 |
|
594 |
Symbols are unique strings, meaning that there exists |
|
595 |
exactly one instance of a given symbol. Therefore symbols can |
|
596 |
be compared using == (identity compare) in addition to = (contents compare). |
|
597 |
Beside this, Symbols behave mostly like Strings.' |
|
598 |
]. |
|
599 |
||
600 |
"/ is it a symbol without hash-character ? |
|
601 |
"/ |
|
796 | 602 |
"/ string knownAsSymbol ifTrue:[ |
603 |
"/ ^ 'is nothing, but #' , string , ' is known as a symbol. |
|
604 |
"/ |
|
605 |
"/Symbols are unique strings, meaning that there exists |
|
606 |
"/exactly one instance of a given symbol. Therefore symbols can |
|
607 |
"/be compared using == (identity compare) in addition to = (contents compare). |
|
608 |
"/Beside this, Symbols behave mostly like Strings.' |
|
609 |
"/ ]. |
|
49 | 610 |
|
611 |
^ nil |
|
796 | 612 |
|
613 |
"Modified: / 31.10.1998 / 14:28:58 / cg" |
|
141 | 614 |
! ! |
49 | 615 |
|
396 | 616 |
!Explainer class methodsFor:'documentation'! |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
617 |
|
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
618 |
version |
1151 | 619 |
^ '$Header: /cvs/stx/stx/libcomp/Explainer.st,v 1.37 2001-02-20 17:06:56 cg Exp $' |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
620 |
! ! |