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