author | Claus Gittinger <cg@exept.de> |
Fri, 24 Apr 1998 11:05:13 +0200 | |
changeset 693 | f8a474713980 |
parent 675 | a2f41004c24d |
child 796 | 65a547620ef4 |
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 |
|
96 |
used as selector within a string. |
|
97 |
Also, there could be much more detailed explanations." |
|
2 | 98 |
|
693 | 99 |
|parser variables v c string tmp |
100 |
spc| |
|
2 | 101 |
|
675 | 102 |
string := someText string withoutSeparators. |
49 | 103 |
|
104 |
" |
|
105 |
ask parser for variable names |
|
106 |
" |
|
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
107 |
parser := self parseMethod:source in:aClass ignoreErrors:true ignoreWarnings:true. |
2 | 108 |
parser notNil ifTrue:[ |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
109 |
"look for variables" |
2 | 110 |
|
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
111 |
variables := parser methodVars. |
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
112 |
(variables notNil and:[variables includes:string]) ifTrue:[ |
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
113 |
^ string , ' is a method variable' |
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
114 |
]. |
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
115 |
variables := parser methodArgs. |
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
116 |
(variables notNil and:[variables includes:string]) ifTrue:[ |
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
117 |
^ string , ' is a method argument' |
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
118 |
] |
2 | 119 |
]. |
49 | 120 |
|
2 | 121 |
parser isNil ifTrue:[ |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
122 |
parser := self for:(ReadStream on:source) in:aClass |
2 | 123 |
]. |
124 |
||
125 |
"instvars" |
|
84 | 126 |
c := aClass whichClassDefinesInstVar:string. |
127 |
c notNil ifTrue:[ |
|
396 | 128 |
c isMeta ifTrue:[ |
129 |
^ string , ' is a class instance variable in ' , c soleInstance name |
|
130 |
]. |
|
131 |
||
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
132 |
^ string , ' is an instance variable in ' , c name |
2 | 133 |
]. |
134 |
||
84 | 135 |
"/ variables := aClass allInstVarNames. |
136 |
"/ (variables notNil and:[variables includes:string]) ifTrue:[ |
|
137 |
"/ "where is it" |
|
138 |
"/ c := aClass. |
|
139 |
"/ [c notNil] whileTrue:[ |
|
140 |
"/ v := c instVarNames. |
|
141 |
"/ (v notNil and:[v includes:string]) ifTrue:[ |
|
142 |
"/ ^ string , ' is an instance variable in ' , c name |
|
143 |
"/ ]. |
|
144 |
"/ c := c superclass |
|
145 |
"/ ]. |
|
146 |
"/ self error:'oops' |
|
147 |
"/ ]. |
|
148 |
||
442 | 149 |
"/ "class instvars" |
150 |
"/ variables := aClass class allInstVarNames. |
|
151 |
"/ (variables notNil and:[variables includes:string]) ifTrue:[ |
|
152 |
"/ "where is it" |
|
153 |
"/ c := aClass. |
|
154 |
"/ [c notNil] whileTrue:[ |
|
155 |
"/ v := c class instVarNames. |
|
156 |
"/ (v notNil and:[v includes:string]) ifTrue:[ |
|
157 |
"/ ^ string , ' is a class instance variable in ' , c name |
|
158 |
"/ ]. |
|
159 |
"/ c := c superclass |
|
160 |
"/ ]. |
|
161 |
"/ self error:'oops' |
|
162 |
"/ ]. |
|
2 | 163 |
|
164 |
"classvars" |
|
165 |
c := parser inWhichClassIsClassVar:string. |
|
166 |
c notNil ifTrue:[ |
|
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
167 |
^ string , ' is a class variable in ' , c name |
2 | 168 |
]. |
169 |
||
509
d8475399ca3e
Correct handling of private classes.
Stefan Vogel <sv@exept.de>
parents:
503
diff
changeset
|
170 |
aClass isMeta ifTrue:[ |
d8475399ca3e
Correct handling of private classes.
Stefan Vogel <sv@exept.de>
parents:
503
diff
changeset
|
171 |
c := aClass soleInstance. |
d8475399ca3e
Correct handling of private classes.
Stefan Vogel <sv@exept.de>
parents:
503
diff
changeset
|
172 |
] ifFalse:[ |
d8475399ca3e
Correct handling of private classes.
Stefan Vogel <sv@exept.de>
parents:
503
diff
changeset
|
173 |
c := aClass. |
d8475399ca3e
Correct handling of private classes.
Stefan Vogel <sv@exept.de>
parents:
503
diff
changeset
|
174 |
]. |
d8475399ca3e
Correct handling of private classes.
Stefan Vogel <sv@exept.de>
parents:
503
diff
changeset
|
175 |
c privateClasses do:[:pClass | |
d8475399ca3e
Correct handling of private classes.
Stefan Vogel <sv@exept.de>
parents:
503
diff
changeset
|
176 |
(pClass name = string |
d8475399ca3e
Correct handling of private classes.
Stefan Vogel <sv@exept.de>
parents:
503
diff
changeset
|
177 |
or:[pClass nameWithoutPrefix = string]) ifTrue:[ |
422 | 178 |
^ (string , ' is a private class in ''' , c name , '''.' |
179 |
, '\\It is only visible locally.') withCRs |
|
180 |
]. |
|
181 |
]. |
|
182 |
||
456 | 183 |
(spc := aClass nameSpace) notNil ifTrue:[ |
422 | 184 |
(Smalltalk at:(spc name , '::' , string) asSymbol) isBehavior ifTrue:[ |
456 | 185 |
^ (string , ' is a class in the ''' , spc name , ''' nameSpace.' |
186 |
, '\\It is only visible within this nameSpace.' |
|
422 | 187 |
, '\Access from the outside is possible' |
188 |
, '\by the special name ''' , spc name , '::' , string , '''.') withCRs |
|
189 |
]. |
|
190 |
]. |
|
191 |
||
2 | 192 |
string knownAsSymbol ifTrue:[ |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
193 |
"globals & symbols" |
2 | 194 |
|
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
195 |
tmp := self explainKnownSymbol:string. |
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
196 |
tmp notNil ifTrue:[ ^ tmp]. |
2 | 197 |
]. |
198 |
||
199 |
"try for some obvious things" |
|
200 |
tmp := self explainPseudoVariable:string in:aClass. |
|
201 |
tmp notNil ifTrue:[ ^ tmp]. |
|
202 |
||
203 |
"try syntax ..." |
|
204 |
||
49 | 205 |
tmp := self explainSyntax:string. |
206 |
tmp notNil ifTrue:[ ^ tmp]. |
|
20 | 207 |
|
2 | 208 |
parser isNil ifTrue:[ |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
209 |
^ 'parse error - no explanation' |
2 | 210 |
]. |
211 |
^ 'cannot explain this - select individual tokens for an explanation.' |
|
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
212 |
|
675 | 213 |
"Created: / 3.12.1995 / 12:47:37 / cg" |
214 |
"Modified: / 16.4.1997 / 12:46:11 / stefan" |
|
215 |
"Modified: / 2.4.1998 / 11:55:05 / cg" |
|
2 | 216 |
! |
217 |
||
141 | 218 |
explainHereIn:aClass |
219 |
^ 'like self, here refers to the object which received the message. |
|
220 |
||
221 |
However, when sending a message to here the search for methods |
|
222 |
implementing this message will start in the defining class (' , aClass name , ') |
|
223 |
instead of the receivers class (' , aClass name , ' or subclass). |
|
224 |
Thus, using here, redefined methods will NOT be reached with a here-send.' |
|
225 |
! |
|
226 |
||
227 |
explainKnownSymbol:string |
|
228 |
"return explanation or nil" |
|
229 |
||
230 |
|sym list count tmp commonSuperClass val| |
|
231 |
||
232 |
sym := string asSymbol. |
|
233 |
||
234 |
"try globals" |
|
235 |
||
236 |
(Smalltalk includesKey:sym) ifTrue:[ |
|
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
237 |
tmp := string , ' is a global variable.'. |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
238 |
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
|
239 |
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
|
240 |
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
|
241 |
tmp := tmp , ' |
141 | 242 |
|
503
b0d10f53a820
show 'autoloaded' for classes
Claus Gittinger <cg@exept.de>
parents:
497
diff
changeset
|
243 |
' , string , ' is ' , (val isLoaded ifTrue:['a'] ifFalse:['an autoloaded']) |
b0d10f53a820
show 'autoloaded' for classes
Claus Gittinger <cg@exept.de>
parents:
497
diff
changeset
|
244 |
, ' class categorized as ' , val category , ' |
141 | 245 |
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
|
246 |
] ifFalse:[ |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
247 |
tmp := tmp , ' |
141 | 248 |
|
249 |
' , string , ' is bound to the class ' , val name , |
|
250 |
' 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
|
251 |
] |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
252 |
] ifFalse:[ |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
253 |
tmp := tmp , ' |
141 | 254 |
|
255 |
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
|
256 |
]. |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
257 |
^ tmp. |
141 | 258 |
]. |
259 |
||
260 |
" |
|
261 |
try selectors |
|
262 |
look who implements it |
|
263 |
" |
|
264 |
list := Set new. |
|
265 |
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
|
266 |
(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
|
267 |
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
|
268 |
]. |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
269 |
(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
|
270 |
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
|
271 |
] |
141 | 272 |
]. |
273 |
||
274 |
count := list size. |
|
275 |
(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
|
276 |
" |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
277 |
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
|
278 |
list them |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
279 |
" |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
280 |
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
|
281 |
tmp := ' is a selector implemented in '. |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
282 |
(count == 1) ifTrue:[ |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
283 |
^ string , tmp , (list at:1) , '.' |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
284 |
]. |
141 | 285 |
|
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
286 |
(count == 2) ifTrue:[ |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
287 |
^ string , tmp , (list at:1) , ' and ' , (list at:2) , '.' |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
288 |
]. |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
289 |
(count == 3) ifTrue:[ |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
290 |
^ string , tmp , ' |
141 | 291 |
' , (list at:1) , ', ' , (list at:2) , ' and ' , (list at:3) , '.' |
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 |
(count == 4) ifTrue:[ |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
294 |
^ string , tmp , ' |
141 | 295 |
' , (list at:1) , ', ' , (list at:2) , ', ' , (list at:3), ' and ' , (list at:4) , '.' |
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
296 |
]. |
141 | 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 |
" |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
299 |
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
|
300 |
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
|
301 |
" |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
302 |
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
|
303 |
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
|
304 |
(list includes:commonSuperClass) ifTrue:[ |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
305 |
^ string , tmp, count printString , commonSuperClass name |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
306 |
, ' 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
|
307 |
, ' subclasses' |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
308 |
]. |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
309 |
^ string , tmp, count printString , ' subclasses of ' , commonSuperClass name |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
310 |
]. |
141 | 311 |
|
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 |
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
|
314 |
" |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
315 |
^ string , tmp , count printString , ' classes.' |
141 | 316 |
]. |
317 |
||
318 |
^ nil |
|
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
319 |
|
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
320 |
"Modified: 17.6.1996 / 17:09:30 / stefan" |
503
b0d10f53a820
show 'autoloaded' for classes
Claus Gittinger <cg@exept.de>
parents:
497
diff
changeset
|
321 |
"Modified: 10.4.1997 / 17:53:58 / cg" |
141 | 322 |
! |
323 |
||
2 | 324 |
explainPseudoVariable:string in:aClass |
325 |
"return explanation for the pseudoVariables self, super etc." |
|
326 |
||
327 |
(string = 'self') ifTrue:[ |
|
49 | 328 |
^ self explainSelfIn:aClass |
2 | 329 |
]. |
330 |
||
331 |
(string = 'super') ifTrue:[ |
|
49 | 332 |
^ self explainSuperIn:aClass |
2 | 333 |
]. |
334 |
||
84 | 335 |
(string = 'here') ifTrue:[ |
336 |
^ self explainHereIn:aClass |
|
337 |
]. |
|
338 |
||
2 | 339 |
(string = 'thisContext') ifTrue:[ |
49 | 340 |
^ 'thisContext is a pseudo variable (i.e. it is built in). |
2 | 341 |
|
49 | 342 |
ThisContext always refers to the context object for the currently executed method or |
343 |
block (an instance of Context or BlockContext respectively). The calling chain and calling |
|
6 | 344 |
receivers/selectors can be accessed via thisContext.' |
345 |
]. |
|
346 |
||
347 |
(string = 'true') ifTrue:[ |
|
49 | 348 |
^ 'true is a pseudo variable (i.e. it is built in). |
6 | 349 |
|
350 |
True represents logical truth. It is the one and only instance of class True.' |
|
2 | 351 |
]. |
352 |
||
353 |
(string = 'false') ifTrue:[ |
|
49 | 354 |
^ 'false is a pseudo variable (i.e. it is built in). |
2 | 355 |
|
356 |
False represents logical falseness. It is the one and only instance of class False.' |
|
357 |
]. |
|
358 |
||
359 |
(string = 'nil') ifTrue:[ |
|
49 | 360 |
^ 'nil is a pseudo variable (i.e. it is built in). |
2 | 361 |
|
362 |
Nil is used for unitialized variables (among other uses). |
|
363 |
Nil is the one and only instance of class UndefinedObject.' |
|
364 |
]. |
|
365 |
^ nil |
|
366 |
! |
|
367 |
||
6 | 368 |
explainSelfIn:aClass |
369 |
|sub| |
|
370 |
||
371 |
sub := aClass allSubclasses collect:[:c | c name]. |
|
372 |
sub size == 0 ifTrue:[ |
|
49 | 373 |
^ 'self refers to the object which received the message. |
6 | 374 |
|
375 |
In this case, it will be an instance of ' , aClass name , '.' |
|
376 |
]. |
|
377 |
||
378 |
sub size <= 5 ifTrue:[ |
|
49 | 379 |
^ 'self refers to the object which received the message. |
6 | 380 |
|
381 |
In this case, it will be an instance of ' , aClass name , ' |
|
382 |
or one of its subclasses: |
|
383 |
||
58 | 384 |
' , sub asStringCollection asString |
6 | 385 |
]. |
386 |
||
387 |
^ 'self refers to the object which received the message. |
|
388 |
||
389 |
In this case, it will be an instance of ' , aClass name , ' |
|
390 |
or one of its ' , sub size printString , ' subclasses.' |
|
391 |
! |
|
392 |
||
393 |
explainSuperIn:aClass |
|
394 |
^ 'like self, super refers to the object which received the message. |
|
395 |
||
396 |
However, when sending a message to super the search for methods |
|
397 |
implementing this message will start in the superclass (' , aClass superclass name , ') |
|
84 | 398 |
instead of the receivers class (' , aClass name , ' or subclass). |
49 | 399 |
Thus, using super, a redefined method can call the original method in its superclass.' |
6 | 400 |
! |
2 | 401 |
|
49 | 402 |
explainSyntax:string |
403 |
"try syntax ...; return explanation or nil" |
|
404 |
||
405 |
((string = ':=') or:[string = '_']) ifTrue:[ |
|
406 |
^ '<variable> := <expression> |
|
407 |
||
408 |
:= and _ (which is left-arrow in some fonts) mean assignment. |
|
409 |
The variable is bound to (i.e. points to) the value of <expression>.' |
|
410 |
]. |
|
411 |
||
412 |
(string = '^') ifTrue:[ |
|
413 |
^ '^ <expression> |
|
414 |
||
415 |
return the value of <expression> as value from the method. |
|
416 |
A return from within a block exits the method where the block is defined.' |
|
417 |
]. |
|
418 |
||
419 |
(string = ';') ifTrue:[ |
|
420 |
^ '<expression> ; selector1 ; .... ; selectorN |
|
421 |
||
422 |
a cascade expression; evaluate expression, and send messages |
|
423 |
<selector1> ... <selectorN> to the first expressions receiver. |
|
424 |
Returns the value of the last send. The cascade sends may also have arguments.' |
|
425 |
]. |
|
426 |
||
427 |
(string = '|') ifTrue:[ |
|
428 |
^ '| locals | or: [:arg | statements] |
|
429 |
||
430 |
| is used to mark a local variable declaration or separates arguments |
|
431 |
from the statements in a block. Notice, that in a block-argument declaration |
|
432 |
these must be prefixed by a colon character. |
|
433 |
| is also a selector understood by Booleans.' |
|
434 |
]. |
|
435 |
||
436 |
((string startsWith:'(') or:[string endsWith:')']) ifTrue:[ |
|
437 |
^ '(<expression>) |
|
438 |
||
439 |
expression grouping.' |
|
440 |
]. |
|
441 |
||
442 |
((string startsWith:'[') or:[string endsWith:']']) ifTrue:[ |
|
443 |
^ '[arguments | statements] |
|
444 |
||
445 |
defines a block. |
|
446 |
Blocks represent pieces of executable code. Definition of a block does |
|
447 |
not evaluate it. The block is evaluated by sending it a value/value: |
|
448 |
message. |
|
449 |
Blocks are often passed as arguments to Booleans (i.e. ifTrue:[...]) or |
|
450 |
collections (i.e. do:[...]).' |
|
451 |
]. |
|
452 |
||
453 |
(string = ':') ifTrue:[ |
|
454 |
^ 'colons have different meaning depending on context: |
|
455 |
||
456 |
1) they separate keyword-parts in symbols and keyword-messages as in: |
|
457 |
||
458 |
#at:put: a constant keyword symbol |
|
459 |
||
460 |
rec at:index put:value sends the #at:put: message to rec, |
|
461 |
passing index and value as arguments. |
|
462 |
||
463 |
2) within block-argument declarations as in: |
|
464 |
||
465 |
[:arg1 :arg2 | statements] |
|
466 |
' |
|
467 |
]. |
|
468 |
||
469 |
(string = '.') ifTrue:[ |
|
470 |
^ 'statement. "<- period here" |
|
471 |
statement |
|
472 |
||
473 |
within a method or block, individual statements are separated by periods. |
|
474 |
' |
|
475 |
]. |
|
476 |
||
477 |
(string startsWith:'#' ) ifTrue:[ |
|
478 |
(string startsWith:'#(' ) ifTrue:[ |
|
479 |
^ 'is a constant Array. |
|
480 |
||
481 |
The elements of a constant Array must be Number-constants, nil, true or false. |
|
482 |
(notice, that not all Smalltalk implementations allow true, false and nil as |
|
483 |
constant-Array elements).' |
|
484 |
]. |
|
485 |
||
486 |
(string startsWith:'#[') ifTrue:[ |
|
487 |
^ 'is a constant ByteArray. |
|
488 |
||
489 |
The elements of a constant ByteArray must be Integer constants in the range |
|
490 |
0 .. 255. |
|
491 |
(notice, that not all Smalltalk implementations support constant ByteArrays).' |
|
492 |
]. |
|
493 |
||
494 |
(string startsWith:'#''') ifTrue:[ |
|
495 |
^ 'is a constant symbol containing non-alphanumeric characters. |
|
496 |
||
497 |
Symbols are unique strings, meaning that there exists |
|
498 |
exactly one instance of a given symbol. Therefore symbols can |
|
499 |
be compared using == (identity compare) in addition to = (contents compare). |
|
500 |
Beside this, Symbols behave mostly like Strings. |
|
501 |
||
502 |
Notice, that not all Smalltalk implementations support this kind of symbols.' |
|
503 |
]. |
|
504 |
||
505 |
^ 'is a symbol. |
|
506 |
||
507 |
Symbols are unique strings, meaning that there exists |
|
508 |
exactly one instance of a given symbol. Therefore symbols can |
|
509 |
be compared using == (identity compare) in addition to = (contents compare). |
|
510 |
Beside this, Symbols behave mostly like Strings.' |
|
511 |
]. |
|
512 |
||
513 |
"/ is it a symbol without hash-character ? |
|
514 |
"/ |
|
515 |
string knownAsSymbol ifTrue:[ |
|
516 |
^ 'is nothing, but #' , string , ' is known as a symbol. |
|
517 |
||
518 |
Symbols are unique strings, meaning that there exists |
|
519 |
exactly one instance of a given symbol. Therefore symbols can |
|
520 |
be compared using == (identity compare) in addition to = (contents compare). |
|
521 |
Beside this, Symbols behave mostly like Strings.' |
|
522 |
]. |
|
523 |
||
524 |
^ nil |
|
141 | 525 |
! ! |
49 | 526 |
|
396 | 527 |
!Explainer class methodsFor:'documentation'! |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
528 |
|
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
529 |
version |
693 | 530 |
^ '$Header: /cvs/stx/stx/libcomp/Explainer.st,v 1.28 1998-04-24 09:05:13 cg Exp $' |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
531 |
! ! |