author | Claus Gittinger <cg@exept.de> |
Tue, 29 Oct 2002 10:39:37 +0100 | |
changeset 1322 | da25e31f423c |
parent 1317 | 064ed982ddf8 |
child 1330 | 100f022924b6 |
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 |
|
1316
30806ca08095
commonSuperClassOf: - allow for classes and names in arg
Claus Gittinger <cg@exept.de>
parents:
1289
diff
changeset
|
51 |
commonSuperClassOf:listOfClassesOrClassNames |
141 | 52 |
|common found| |
53 |
||
1316
30806ca08095
commonSuperClassOf: - allow for classes and names in arg
Claus Gittinger <cg@exept.de>
parents:
1289
diff
changeset
|
54 |
listOfClassesOrClassNames do:[:classOrClassName | |
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 |
|
1316
30806ca08095
commonSuperClassOf: - allow for classes and names in arg
Claus Gittinger <cg@exept.de>
parents:
1289
diff
changeset
|
57 |
class := classOrClassName isBehavior |
30806ca08095
commonSuperClassOf: - allow for classes and names in arg
Claus Gittinger <cg@exept.de>
parents:
1289
diff
changeset
|
58 |
ifTrue:[classOrClassName] |
30806ca08095
commonSuperClassOf: - allow for classes and names in arg
Claus Gittinger <cg@exept.de>
parents:
1289
diff
changeset
|
59 |
ifFalse:[Smalltalk classNamed:classOrClassName].. |
1317
064ed982ddf8
commonSuperClassOf: easier (fixed ?)
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
60 |
|
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
61 |
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
|
62 |
common := class |
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 |
(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
|
65 |
"keep common" |
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 |
(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
|
68 |
common := class |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
69 |
] ifFalse:[ |
1317
064ed982ddf8
commonSuperClassOf: easier (fixed ?)
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
70 |
common := common commonSuperclass:class. |
1151 | 71 |
|
1317
064ed982ddf8
commonSuperClassOf: easier (fixed ?)
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
72 |
"/ "walk up, checking" |
064ed982ddf8
commonSuperClassOf: easier (fixed ?)
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
73 |
"/ found := false. |
064ed982ddf8
commonSuperClassOf: easier (fixed ?)
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
74 |
"/ |
064ed982ddf8
commonSuperClassOf: easier (fixed ?)
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
75 |
"/ common allSuperclassesDo:[:sup | |
064ed982ddf8
commonSuperClassOf: easier (fixed ?)
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
76 |
"/ (found not and:[class isSubclassOf:sup]) ifTrue:[ |
064ed982ddf8
commonSuperClassOf: easier (fixed ?)
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
77 |
"/ common := sup. |
064ed982ddf8
commonSuperClassOf: easier (fixed ?)
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
78 |
"/ found := true. |
064ed982ddf8
commonSuperClassOf: easier (fixed ?)
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
79 |
"/ ] |
064ed982ddf8
commonSuperClassOf: easier (fixed ?)
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
80 |
"/ ]. |
064ed982ddf8
commonSuperClassOf: easier (fixed ?)
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
81 |
"/ found ifFalse:[ |
064ed982ddf8
commonSuperClassOf: easier (fixed ?)
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
82 |
"/ class allSuperclassesDo:[:sup | |
064ed982ddf8
commonSuperClassOf: easier (fixed ?)
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
83 |
"/ (found not and:[common isSubclassOf:sup]) ifTrue:[ |
064ed982ddf8
commonSuperClassOf: easier (fixed ?)
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
84 |
"/ common := sup. |
064ed982ddf8
commonSuperClassOf: easier (fixed ?)
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
85 |
"/ found := true. |
064ed982ddf8
commonSuperClassOf: easier (fixed ?)
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
86 |
"/ ] |
064ed982ddf8
commonSuperClassOf: easier (fixed ?)
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
87 |
"/ ]. |
064ed982ddf8
commonSuperClassOf: easier (fixed ?)
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
88 |
"/ ]. |
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
89 |
] |
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 |
]. |
1317
064ed982ddf8
commonSuperClassOf: easier (fixed ?)
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
92 |
(common isNil or:[common == Object]) ifTrue:[^ common]. |
141 | 93 |
]. |
94 |
^ common |
|
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
95 |
|
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
96 |
"Modified: 17.6.1996 / 17:09:21 / stefan" |
336 | 97 |
"Modified: 5.9.1996 / 19:34:41 / cg" |
141 | 98 |
! |
99 |
||
2 | 100 |
explain:someText in:source forClass:aClass |
6 | 101 |
"Given a source and a substring of it, return a string containing |
102 |
an explanation. |
|
49 | 103 |
This is just a q&d implementation - to be correct, it should use the parser, |
104 |
and explain from the parsetree (instead of doing string matches). |
|
105 |
This leads to some wrong explanations, for example if some string is |
|
839 | 106 |
used as selector within a string, or if a variable is named like a |
107 |
message selector. I.e. the explanation should be context sensitive. |
|
49 | 108 |
Also, there could be much more detailed explanations." |
2 | 109 |
|
1183 | 110 |
^ self |
111 |
explain:someText in:source forClass:aClass short:false |
|
112 |
! |
|
113 |
||
114 |
explain:someText in:source forClass:aClass short:shortText |
|
115 |
"Given a source and a substring of it, return a string containing |
|
116 |
an explanation. |
|
117 |
This is just a q&d implementation - to be correct, it should use the parser, |
|
118 |
and explain from the parsetree (instead of doing string matches). |
|
119 |
This leads to some wrong explanations, for example if some string is |
|
120 |
used as selector within a string, or if a variable is named like a |
|
121 |
message selector. I.e. the explanation should be context sensitive. |
|
122 |
Also, there could be much more detailed explanations." |
|
123 |
||
1159 | 124 |
|parser variables c string tmp |
1289 | 125 |
spc sym sel stringText clsName val valString| |
2 | 126 |
|
675 | 127 |
string := someText string withoutSeparators. |
1198 | 128 |
stringText := string allBold. |
1233 | 129 |
stringText := '''' , stringText , ''''. |
49 | 130 |
|
131 |
" |
|
132 |
ask parser for variable names |
|
133 |
" |
|
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
134 |
parser := self parseMethod:source in:aClass ignoreErrors:true ignoreWarnings:true. |
2 | 135 |
parser notNil ifTrue:[ |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
136 |
"look for variables" |
2 | 137 |
|
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
138 |
variables := parser methodVars. |
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
139 |
(variables notNil and:[variables includes:string]) ifTrue:[ |
1233 | 140 |
^ stringText , ' is a method variable.' |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
141 |
]. |
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
142 |
variables := parser methodArgs. |
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
143 |
(variables notNil and:[variables includes:string]) ifTrue:[ |
1233 | 144 |
^ stringText , ' is a method argument.' |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
145 |
] |
2 | 146 |
]. |
49 | 147 |
|
2 | 148 |
parser isNil ifTrue:[ |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
149 |
parser := self for:(ReadStream on:source) in:aClass |
2 | 150 |
]. |
151 |
||
152 |
"instvars" |
|
84 | 153 |
c := aClass whichClassDefinesInstVar:string. |
154 |
c notNil ifTrue:[ |
|
396 | 155 |
c isMeta ifTrue:[ |
1211
91e94e294819
isMeta/soleInstance -> theMetaclass / theNonMetaclass
Claus Gittinger <cg@exept.de>
parents:
1210
diff
changeset
|
156 |
clsName := c theNonMetaclass name. |
1198 | 157 |
shortText ifTrue:[ |
1233 | 158 |
^ stringText , ' is a class instVar in ' , clsName , '.' |
1198 | 159 |
]. |
1233 | 160 |
^ stringText, ' is a class instance variable in ' , clsName , '.' |
396 | 161 |
]. |
162 |
||
1233 | 163 |
clsName := c name. |
1198 | 164 |
shortText ifTrue:[ |
1233 | 165 |
^ stringText , ' is an instVar in ' , clsName , '.' |
1198 | 166 |
]. |
1233 | 167 |
^ stringText , ' is an instance variable in ' , clsName , '.' |
2 | 168 |
]. |
169 |
||
84 | 170 |
"/ variables := aClass allInstVarNames. |
171 |
"/ (variables notNil and:[variables includes:string]) ifTrue:[ |
|
172 |
"/ "where is it" |
|
173 |
"/ c := aClass. |
|
1159 | 174 |
"/ [c notNil] whileTrue:[ |v| |
84 | 175 |
"/ v := c instVarNames. |
176 |
"/ (v notNil and:[v includes:string]) ifTrue:[ |
|
177 |
"/ ^ string , ' is an instance variable in ' , c name |
|
178 |
"/ ]. |
|
179 |
"/ c := c superclass |
|
180 |
"/ ]. |
|
181 |
"/ self error:'oops' |
|
182 |
"/ ]. |
|
183 |
||
442 | 184 |
"/ "class instvars" |
185 |
"/ variables := aClass class allInstVarNames. |
|
186 |
"/ (variables notNil and:[variables includes:string]) ifTrue:[ |
|
187 |
"/ "where is it" |
|
188 |
"/ c := aClass. |
|
1159 | 189 |
"/ [c notNil] whileTrue:[ |v| |
442 | 190 |
"/ v := c class instVarNames. |
191 |
"/ (v notNil and:[v includes:string]) ifTrue:[ |
|
192 |
"/ ^ string , ' is a class instance variable in ' , c name |
|
193 |
"/ ]. |
|
194 |
"/ c := c superclass |
|
195 |
"/ ]. |
|
196 |
"/ self error:'oops' |
|
197 |
"/ ]. |
|
2 | 198 |
|
199 |
"classvars" |
|
200 |
c := parser inWhichClassIsClassVar:string. |
|
201 |
c notNil ifTrue:[ |
|
1233 | 202 |
clsName := c name. |
1198 | 203 |
shortText ifTrue:[ |
1289 | 204 |
stringText := stringText , ' is a classVar in ' , clsName |
205 |
] ifFalse:[ |
|
206 |
stringText := stringText , ' is a class variable in ' , clsName |
|
1198 | 207 |
]. |
1289 | 208 |
val := Smalltalk at:(clsName , ':' , string) asSymbol. |
209 |
(val isBoolean or:[val isNil or:[val isSymbol]]) ifTrue:[ |
|
210 |
valString := val storeString. |
|
211 |
] ifFalse:[ |
|
212 |
valString := val classNameWithArticle. |
|
213 |
]. |
|
214 |
^ stringText , ' (' , valString , ').' |
|
2 | 215 |
]. |
216 |
||
1210
e3174ccbb5bb
isMeta/soleInstance -> theMetaclass / theNonMetaclass
Claus Gittinger <cg@exept.de>
parents:
1198
diff
changeset
|
217 |
c := aClass theNonMetaclass. |
509
d8475399ca3e
Correct handling of private classes.
Stefan Vogel <sv@exept.de>
parents:
503
diff
changeset
|
218 |
c privateClasses do:[:pClass | |
d8475399ca3e
Correct handling of private classes.
Stefan Vogel <sv@exept.de>
parents:
503
diff
changeset
|
219 |
(pClass name = string |
d8475399ca3e
Correct handling of private classes.
Stefan Vogel <sv@exept.de>
parents:
503
diff
changeset
|
220 |
or:[pClass nameWithoutPrefix = string]) ifTrue:[ |
1233 | 221 |
string := stringText , ' is a private class in ''' , c name , '''.'. |
222 |
shortText ifFalse:[ |
|
1183 | 223 |
string := (string , '\\It is only visible locally.') withCRs |
224 |
]. |
|
225 |
^ string withCRs |
|
422 | 226 |
]. |
227 |
]. |
|
228 |
||
456 | 229 |
(spc := aClass nameSpace) notNil ifTrue:[ |
796 | 230 |
sym := (spc name , '::' , string) asSymbolIfInterned. |
231 |
sym notNil ifTrue:[ |
|
232 |
(Smalltalk at:sym) isBehavior ifTrue:[ |
|
1233 | 233 |
string := stringText , ' is a class in the ''' , spc name , ''' nameSpace.'. |
1183 | 234 |
shortText ifFalse:[ |
235 |
string := (string |
|
796 | 236 |
, '\\It is only visible within this nameSpace.' |
237 |
, '\Access from the outside is possible' |
|
238 |
, '\by the special name ''' , spc name , '::' , string , '''.') withCRs |
|
1183 | 239 |
]. |
240 |
^ string withCRs |
|
796 | 241 |
]. |
422 | 242 |
]. |
243 |
]. |
|
244 |
||
796 | 245 |
"/ string knownAsSymbol ifTrue:[ |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
246 |
"globals & symbols" |
2 | 247 |
|
1183 | 248 |
tmp := self explainKnownSymbol:string inClass:aClass short:shortText. |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
249 |
tmp notNil ifTrue:[ ^ tmp]. |
839 | 250 |
|
251 |
"/ try with added colon ... |
|
252 |
sel := string , ':'. |
|
253 |
Symbol allInstancesDo:[:sym | |
|
254 |
(sym startsWith:sel) ifTrue:[ |
|
1183 | 255 |
tmp := self explainKnownSymbol:sym inClass:aClass short:shortText. |
839 | 256 |
tmp notNil ifTrue:[ ^ tmp]. |
257 |
] |
|
258 |
]. |
|
796 | 259 |
"/ ]. |
2 | 260 |
|
261 |
"try for some obvious things" |
|
1183 | 262 |
tmp := self explainPseudoVariable:string in:aClass short:true. |
2 | 263 |
tmp notNil ifTrue:[ ^ tmp]. |
264 |
||
265 |
"try syntax ..." |
|
266 |
||
1183 | 267 |
tmp := self explainSyntax:string short:shortText. |
49 | 268 |
tmp notNil ifTrue:[ ^ tmp]. |
20 | 269 |
|
1183 | 270 |
shortText ifTrue:[ |
271 |
^ '' |
|
272 |
]. |
|
273 |
||
2 | 274 |
parser isNil ifTrue:[ |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
275 |
^ 'parse error - no explanation' |
2 | 276 |
]. |
796 | 277 |
^ '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
|
278 |
|
675 | 279 |
"Created: / 3.12.1995 / 12:47:37 / cg" |
280 |
"Modified: / 16.4.1997 / 12:46:11 / stefan" |
|
1211
91e94e294819
isMeta/soleInstance -> theMetaclass / theNonMetaclass
Claus Gittinger <cg@exept.de>
parents:
1210
diff
changeset
|
281 |
"Modified: / 5.11.2001 / 16:54:23 / cg" |
2 | 282 |
! |
283 |
||
1188 | 284 |
explainGlobal:string inClass:aClass short:shortText |
1183 | 285 |
"return explanation or nil" |
286 |
||
1245 | 287 |
|sym stringText tmp val classCategory| |
141 | 288 |
|
1245 | 289 |
"if not even known as key, its definitely not a global" |
290 |
sym := string asSymbolIfInterned. |
|
796 | 291 |
sym isNil ifTrue:[^ nil]. |
141 | 292 |
|
293 |
"try globals" |
|
1245 | 294 |
(Smalltalk includesKey:sym) ifFalse:[ ^ nil]. |
141 | 295 |
|
1198 | 296 |
stringText := string allBold. |
297 |
||
1245 | 298 |
"/ stringText := '''' , stringText , ''''. |
299 |
tmp := stringText , ' is a global variable.'. |
|
1183 | 300 |
|
1245 | 301 |
val := Smalltalk at:sym. |
302 |
val isBehavior ifTrue:[ |
|
303 |
"/ a class |
|
304 |
classCategory := val category. |
|
305 |
shortText ifTrue:[ |
|
306 |
^ stringText , ' is ' , (val isLoaded ifTrue:['a'] ifFalse:['an autoloaded']) |
|
307 |
, ' class in the ''' , classCategory , ''' category.'. |
|
308 |
]. |
|
309 |
||
310 |
val name = string ifTrue:[ |
|
1183 | 311 |
tmp := tmp , ' |
1245 | 312 |
' , string , ' is ' , (val isLoaded ifTrue:['a'] ifFalse:['an autoloaded']) |
313 |
, ' class categorized as ' , classCategory , ' |
|
314 |
in the ''' , val package , ''' package.'. |
|
1183 | 315 |
^ tmp. |
316 |
]. |
|
141 | 317 |
|
1183 | 318 |
tmp := tmp , ' |
319 |
||
1245 | 320 |
' , string , ' is bound to the class ' , val name , |
321 |
' in the ''' , classCategory , ''' category.'. |
|
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
322 |
^ tmp. |
141 | 323 |
]. |
324 |
||
1245 | 325 |
shortText ifTrue:[ |
326 |
^ stringText , ' is a global, currently bound to ''' , val classNameWithArticle , '''.'. |
|
327 |
]. |
|
328 |
tmp := tmp , ' |
|
329 |
||
330 |
Its current value is ''' , val classNameWithArticle , '''.'. |
|
331 |
^ tmp. |
|
1188 | 332 |
! |
333 |
||
334 |
explainHereIn:aClass |
|
335 |
^ 'like self, here refers to the object which received the message. |
|
336 |
||
337 |
However, when sending a message to here the search for methods |
|
338 |
implementing this message will start in the defining class (' , aClass name , ') |
|
339 |
instead of the receivers class (' , aClass name , ' or subclass). |
|
340 |
Thus, using here, redefined methods will NOT be reached with a here-send.' |
|
341 |
! |
|
342 |
||
343 |
explainKnownSymbol:string inClass:aClass |
|
344 |
"return explanation or nil" |
|
345 |
||
346 |
^ self explainKnownSymbol:string inClass:aClass short:false |
|
347 |
! |
|
348 |
||
349 |
explainKnownSymbol:string inClass:aClass short:shortText |
|
350 |
"return explanation or nil" |
|
351 |
||
352 |
|sym| |
|
353 |
||
354 |
sym := string asSymbolIfInterned. |
|
355 |
sym isNil ifTrue:[^ nil]. |
|
356 |
||
357 |
"try globals" |
|
358 |
||
359 |
(Smalltalk includesKey:sym) ifTrue:[ |
|
360 |
^ self explainGlobal:string inClass:aClass short:shortText |
|
361 |
]. |
|
362 |
||
363 |
^ self explainSelector:string inClass:aClass short:shortText |
|
364 |
! |
|
365 |
||
366 |
explainPseudoVariable:string in:aClass |
|
367 |
"return explanation for the pseudoVariables self, super etc." |
|
368 |
||
369 |
^ self explainPseudoVariable:string in:aClass short:false |
|
370 |
! |
|
371 |
||
372 |
explainPseudoVariable:string in:aClass short:shortText |
|
373 |
"return explanation for the pseudoVariables self, super etc." |
|
374 |
||
375 |
(string = 'self') ifTrue:[ |
|
376 |
^ self explainSelfIn:aClass short:shortText |
|
377 |
]. |
|
378 |
||
379 |
(string = 'super') ifTrue:[ |
|
380 |
shortText ifTrue:[ |
|
381 |
^ '''super'' - message lookup starts in superclass ''' , aClass superclass name , '''.' |
|
382 |
]. |
|
383 |
^ self explainSuperIn:aClass short:shortText |
|
384 |
]. |
|
385 |
||
386 |
(string = 'here') ifTrue:[ |
|
387 |
shortText ifTrue:[ |
|
388 |
^ '''here'' - message lookup always starts in ''' , aClass name , '''.' |
|
389 |
]. |
|
390 |
^ self explainHereIn:aClass |
|
391 |
]. |
|
392 |
||
393 |
(string = 'thisContext') ifTrue:[ |
|
394 |
shortText ifTrue:[ |
|
395 |
^ '''thisContext'' - the current stack frame as an object.' |
|
396 |
]. |
|
397 |
^ 'thisContext is a pseudo variable (i.e. it is built in). |
|
398 |
||
399 |
ThisContext always refers to the context object for the currently executed method or |
|
400 |
block (an instance of Context or BlockContext respectively). The calling chain and calling |
|
401 |
receivers/selectors can be accessed via thisContext.' |
|
402 |
]. |
|
403 |
||
404 |
(string = 'true') ifTrue:[ |
|
405 |
shortText ifTrue:[ |
|
406 |
^ '''true'' - the truth and nothing but the truth.' |
|
407 |
]. |
|
408 |
^ 'true is a pseudo variable (i.e. it is built in). |
|
409 |
||
410 |
True represents logical truth. It is the one and only instance of class True.' |
|
411 |
]. |
|
412 |
||
413 |
(string = 'false') ifTrue:[ |
|
414 |
shortText ifTrue:[ |
|
415 |
^ '''false'' - obvisously not true.' |
|
416 |
]. |
|
417 |
^ 'false is a pseudo variable (i.e. it is built in). |
|
418 |
||
419 |
False represents logical falseness. It is the one and only instance of class False.' |
|
420 |
]. |
|
421 |
||
422 |
(string = 'nil') ifTrue:[ |
|
423 |
shortText ifTrue:[ |
|
424 |
^ '''nil'' - undefined, unknown, void or dont care.' |
|
425 |
]. |
|
426 |
^ 'nil is a pseudo variable (i.e. it is built in). |
|
427 |
||
428 |
Nil is used for unitialized variables (among other uses). |
|
429 |
Nil is the one and only instance of class UndefinedObject.' |
|
430 |
]. |
|
431 |
^ nil |
|
432 |
! |
|
433 |
||
434 |
explainSelector:string inClass:aClass short:shortText |
|
435 |
"return explanation or nil" |
|
436 |
||
437 |
|sym list count tmp commonSuperClass val s s2 |
|
438 |
firstImplementingClass cm msg t| |
|
439 |
||
440 |
sym := string asSymbolIfInterned. |
|
441 |
sym isNil ifTrue:[^ nil]. |
|
442 |
||
141 | 443 |
" |
444 |
try selectors |
|
445 |
look who implements it |
|
446 |
" |
|
447 |
list := Set new. |
|
1081 | 448 |
Smalltalk allClassesDo:[:c| |
1249
780b4a1a3967
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1245
diff
changeset
|
449 |
(c includesSelector:sym) ifTrue:[ |
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
450 |
list add:(c name). |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
451 |
firstImplementingClass isNil ifTrue:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
452 |
firstImplementingClass := c |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
453 |
] |
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
454 |
]. |
1249
780b4a1a3967
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1245
diff
changeset
|
455 |
(c class includesSelector:sym) ifTrue:[ |
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
456 |
list add:(c name , ' class'). |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
457 |
firstImplementingClass isNil ifTrue:[ |
912 | 458 |
firstImplementingClass := c class |
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
459 |
] |
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
460 |
] |
141 | 461 |
]. |
462 |
||
835 | 463 |
(aClass canUnderstand:sym) ifTrue:[ |
1184 | 464 |
s2 := ('Instances of ''' , aClass name , ''' respond to #') , sym asText allBold , '.'. |
465 |
shortText ifFalse:[ |
|
466 |
s2 := '\\' , s2 |
|
467 |
, '\- inherited from ' withCRs |
|
468 |
, (aClass whichClassImplements:sym) name asText allBold. |
|
469 |
]. |
|
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
470 |
firstImplementingClass := (aClass whichClassImplements:sym) |
835 | 471 |
] ifFalse:[ |
472 |
s2 := ''. |
|
473 |
]. |
|
474 |
||
141 | 475 |
count := list size. |
476 |
(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
|
477 |
" |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
478 |
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
|
479 |
list them |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
480 |
" |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
481 |
list := list asOrderedCollection sort. |
1185 | 482 |
shortText ifTrue:[ |
483 |
tmp := ' is implemented in '. |
|
484 |
] ifFalse:[ |
|
485 |
tmp := ' is a selector implemented in '. |
|
486 |
]. |
|
835 | 487 |
s := '#' , string asText allBold. |
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
488 |
|
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
489 |
(count == 1) ifTrue:[ |
1183 | 490 |
(t := list first) isMeta ifTrue:[ |
491 |
t := 'the ' , t |
|
492 |
]. |
|
1184 | 493 |
msg := s , tmp , t , '.'. |
494 |
shortText ifFalse:[ |
|
495 |
msg := msg , s2. |
|
496 |
] |
|
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
497 |
] ifFalse:[ |
1185 | 498 |
(count == 2) ifTrue:[ |
499 |
msg := s , tmp , (list at:1) , ' and ' , (list at:2) , '.'. |
|
500 |
shortText ifFalse:[ |
|
501 |
msg := msg , s2. |
|
502 |
]. |
|
503 |
] ifFalse:[ |
|
504 |
shortText ifTrue:[ |
|
505 |
msg := s , tmp , count printString , ' classes.'. |
|
506 |
^ msg |
|
507 |
]. |
|
1183 | 508 |
|
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
509 |
(count == 3) ifTrue:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
510 |
msg := s , tmp , ' |
835 | 511 |
' , (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
|
512 |
] ifFalse:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
513 |
(count == 4) ifTrue:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
514 |
msg := s , tmp , ' |
835 | 515 |
' , (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
|
516 |
] ifFalse:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
517 |
" |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
518 |
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
|
519 |
superclass and show it ... |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
520 |
" |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
521 |
commonSuperClass := self commonSuperClassOf:list. |
913 | 522 |
(commonSuperClass ~~ Object |
523 |
and:[commonSuperClass ~~ Behavior |
|
524 |
and:[commonSuperClass ~~ Class |
|
525 |
and:[commonSuperClass ~~ ClassDescription]]]) ifTrue:[ |
|
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
526 |
(list includes:commonSuperClass) ifTrue:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
527 |
msg := s . tmp , count printString , commonSuperClass name |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
528 |
, ' and redefined in ' , (count - 1) printString |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
529 |
, ' subclasses' |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
530 |
, s2. |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
531 |
firstImplementingClass := commonSuperClass |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
532 |
] ifFalse:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
533 |
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
|
534 |
] |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
535 |
] ifFalse:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
536 |
(commonSuperClass == Object |
1249
780b4a1a3967
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1245
diff
changeset
|
537 |
and:[commonSuperClass includesSelector:sym]) ifTrue:[ |
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
538 |
msg := s , tmp , count printString , ' classes. |
834 | 539 |
|
540 |
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
|
541 |
since there is an implementation in Object.' , s2. |
141 | 542 |
|
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
543 |
firstImplementingClass := Object |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
544 |
] ifFalse:[ |
913 | 545 |
((commonSuperClass == Behavior |
546 |
or:[commonSuperClass == Class |
|
547 |
or:[commonSuperClass == ClassDescription]]) |
|
1249
780b4a1a3967
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1245
diff
changeset
|
548 |
and:[commonSuperClass includesSelector:sym]) ifTrue:[ |
913 | 549 |
msg := s , tmp , count printString , ' classes. |
550 |
||
551 |
All classes seem to respond to that message, |
|
552 |
since there is an implementation in ' , commonSuperClass name , '.' , s2. |
|
553 |
||
554 |
firstImplementingClass := commonSuperClass |
|
555 |
] ifFalse:[ |
|
556 |
" |
|
557 |
otherwise just give the number. |
|
558 |
" |
|
559 |
msg := s , tmp , count printString , ' classes.' , s2 |
|
560 |
] |
|
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
561 |
] |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
562 |
] |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
563 |
] |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
564 |
] |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
565 |
]. |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
566 |
]. |
1185 | 567 |
shortText ifFalse:[ |
568 |
firstImplementingClass notNil ifTrue:[ |
|
569 |
WindowGroup activeGroup withWaitCursorDo:[ |
|
570 |
cm := firstImplementingClass compiledMethodAt:sym. |
|
571 |
cm notNil ifTrue:[ |
|
572 |
cm := cm methodComment. |
|
573 |
] |
|
574 |
]. |
|
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
575 |
cm notNil ifTrue:[ |
1185 | 576 |
msg := msg , '\\The comment in ' withCRs , firstImplementingClass name allBold , ' is:\' withCRs , cm allItalic. |
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
577 |
] |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
578 |
]. |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
579 |
]. |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
580 |
^ msg |
141 | 581 |
]. |
582 |
||
583 |
^ nil |
|
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
584 |
|
796 | 585 |
"Modified: / 17.6.1996 / 17:09:30 / stefan" |
835 | 586 |
"Created: / 23.3.1999 / 13:29:33 / cg" |
587 |
"Modified: / 23.3.1999 / 13:40:40 / cg" |
|
141 | 588 |
! |
589 |
||
1183 | 590 |
explainSelfIn:aClass short:shortText |
1244 | 591 |
|sub subNames selfString className nSubClasses| |
1198 | 592 |
|
593 |
selfString := '''' , 'self' allBold , ''''. |
|
6 | 594 |
|
1244 | 595 |
sub := aClass allSubclasses. |
596 |
nSubClasses := sub size. |
|
597 |
||
598 |
aClass isMeta ifTrue:[ |
|
599 |
className := aClass theNonMetaclass name. |
|
600 |
subNames := sub collect:[:c | c theNonMetaclass name]. |
|
601 |
nSubClasses == 0 ifTrue:[ |
|
602 |
shortText ifTrue:[ |
|
603 |
^ selfString , ' - the ''' , className , '''-class.' |
|
604 |
]. |
|
605 |
^ selfString , 'refers to the object which received the message. |
|
606 |
||
607 |
In this case, it will be the ' , className , '-class itself.' |
|
608 |
]. |
|
609 |
||
610 |
shortText ifTrue:[ |
|
611 |
nSubClasses == 1 ifTrue:[ |
|
612 |
^ selfString , ' - the ''' , className , '''- or ''' , subNames first , '''-class.' |
|
613 |
]. |
|
614 |
^ selfString , ' - the ''' , className , '''-class or one of its subclasses.' |
|
615 |
]. |
|
616 |
nSubClasses <= 5 ifTrue:[ |
|
617 |
^ selfString , ' refers to the object which received the message. |
|
618 |
||
619 |
In this case, it will be the ' , className , '-class |
|
620 |
or one of its subclasses: |
|
621 |
||
622 |
' , subNames asStringCollection asString |
|
623 |
]. |
|
624 |
||
625 |
^ selfString , ' refers to the object which received the message. |
|
626 |
||
627 |
In this case, it will be the ' , className , '-class |
|
628 |
or one of its ' , nSubClasses printString , ' subclasses.' |
|
629 |
]. |
|
630 |
||
1256 | 631 |
subNames := aClass allSubclasses collect:[:c | c theNonMetaclass name]. |
1244 | 632 |
className := aClass name. |
633 |
nSubClasses == 0 ifTrue:[ |
|
1183 | 634 |
shortText ifTrue:[ |
1244 | 635 |
^ selfString , ' - an instance of ''' , className , '''.' |
1183 | 636 |
]. |
1198 | 637 |
^ selfString , 'refers to the object which received the message. |
6 | 638 |
|
1244 | 639 |
In this case, it will be an instance of ' , className , '.' |
6 | 640 |
]. |
641 |
||
1183 | 642 |
shortText ifTrue:[ |
1244 | 643 |
nSubClasses == 1 ifTrue:[ |
1256 | 644 |
^ selfString , ' - an instance of ''' , className , ''' or ''' , subNames first , '''.' |
1185 | 645 |
]. |
1244 | 646 |
^ selfString , ' - an instance of ''' , className , ''' or one of its subclasses.' |
1183 | 647 |
]. |
1244 | 648 |
nSubClasses <= 5 ifTrue:[ |
1198 | 649 |
^ selfString , ' refers to the object which received the message. |
6 | 650 |
|
1244 | 651 |
In this case, it will be an instance of ' , className , ' |
6 | 652 |
or one of its subclasses: |
653 |
||
1256 | 654 |
' , subNames asStringCollection asString |
6 | 655 |
]. |
656 |
||
1198 | 657 |
^ selfString , ' refers to the object which received the message. |
6 | 658 |
|
1244 | 659 |
In this case, it will be an instance of ' , className , ' |
660 |
or one of its ' , nSubClasses printString , ' subclasses.' |
|
6 | 661 |
! |
662 |
||
1188 | 663 |
explainSuperIn:aClass short:shortText |
1244 | 664 |
|sub superName| |
665 |
||
666 |
superName := aClass superclass name. |
|
1188 | 667 |
|
668 |
"/ sub := aClass allSubclasses collect:[:c | c name]. |
|
669 |
"/ sub size == 0 ifTrue:[ |
|
670 |
"/ shortText ifTrue:[ |
|
671 |
"/ ^ '''super'' - an instance of ''' , aClass name , '''; message lookup starts in ' , aClass superclass name , '.' |
|
672 |
"/ ]. |
|
673 |
"/ ]. |
|
674 |
||
675 |
shortText ifTrue:[ |
|
1244 | 676 |
^ '''super'' - message lookup starts in ' , superName , '.' |
1188 | 677 |
]. |
678 |
||
6 | 679 |
^ 'like self, super refers to the object which received the message. |
680 |
||
681 |
However, when sending a message to super the search for methods |
|
1244 | 682 |
implementing this message will start in the superclass (' , superName , ') |
84 | 683 |
instead of the receivers class (' , aClass name , ' or subclass). |
49 | 684 |
Thus, using super, a redefined method can call the original method in its superclass.' |
6 | 685 |
! |
2 | 686 |
|
49 | 687 |
explainSyntax:string |
688 |
"try syntax ...; return explanation or nil" |
|
689 |
||
1183 | 690 |
^ self explainSyntax:string short:false |
691 |
! |
|
692 |
||
693 |
explainSyntax:string short:shortText |
|
694 |
"try syntax ...; return explanation or nil" |
|
695 |
||
49 | 696 |
((string = ':=') or:[string = '_']) ifTrue:[ |
1183 | 697 |
shortText ifTrue:[ |
698 |
^ 'Assign to variable on the left side.'. |
|
699 |
]. |
|
700 |
||
796 | 701 |
^ '<variable> := <expression> |
49 | 702 |
|
834 | 703 |
'':='' and ''_'' (which is left-arrow in some fonts) mean assignment. |
49 | 704 |
The variable is bound to (i.e. points to) the value of <expression>.' |
705 |
]. |
|
706 |
||
707 |
(string = '^') ifTrue:[ |
|
1183 | 708 |
shortText ifTrue:[ |
709 |
^ 'Return value from method.'. |
|
710 |
]. |
|
796 | 711 |
^ '^ <expression> |
49 | 712 |
|
834 | 713 |
returns the value of <expression> as value from the method. |
49 | 714 |
A return from within a block exits the method where the block is defined.' |
715 |
]. |
|
716 |
||
717 |
(string = ';') ifTrue:[ |
|
1183 | 718 |
shortText ifTrue:[ |
719 |
^ 'Cascade expression.'. |
|
720 |
]. |
|
796 | 721 |
^ '<expression> ; selector1 ; .... ; selectorN |
49 | 722 |
|
723 |
a cascade expression; evaluate expression, and send messages |
|
724 |
<selector1> ... <selectorN> to the first expressions receiver. |
|
725 |
Returns the value of the last send. The cascade sends may also have arguments.' |
|
726 |
]. |
|
727 |
||
728 |
(string = '|') ifTrue:[ |
|
1183 | 729 |
shortText ifTrue:[ |
730 |
^ ''. |
|
731 |
]. |
|
796 | 732 |
^ '| locals | or: [:arg | statements] |
49 | 733 |
|
834 | 734 |
''|'' is used to mark a local variable declaration or separates arguments |
49 | 735 |
from the statements in a block. Notice, that in a block-argument declaration |
736 |
these must be prefixed by a colon character. |
|
834 | 737 |
''|'' is also a selector understood by Booleans.' |
49 | 738 |
]. |
739 |
||
740 |
((string startsWith:'(') or:[string endsWith:')']) ifTrue:[ |
|
1183 | 741 |
shortText ifTrue:[ |
742 |
^ ''. |
|
743 |
]. |
|
796 | 744 |
^ '(<expression>) |
49 | 745 |
|
746 |
expression grouping.' |
|
747 |
]. |
|
748 |
||
749 |
((string startsWith:'[') or:[string endsWith:']']) ifTrue:[ |
|
1183 | 750 |
shortText ifTrue:[ |
751 |
^ ''. |
|
752 |
]. |
|
834 | 753 |
^ '[:arg1 .. :argN | statements] |
49 | 754 |
|
755 |
defines a block. |
|
756 |
Blocks represent pieces of executable code. Definition of a block does |
|
757 |
not evaluate it. The block is evaluated by sending it a value/value: |
|
758 |
message. |
|
759 |
Blocks are often passed as arguments to Booleans (i.e. ifTrue:[...]) or |
|
760 |
collections (i.e. do:[...]).' |
|
761 |
]. |
|
762 |
||
763 |
(string = ':') ifTrue:[ |
|
1183 | 764 |
shortText ifTrue:[ |
765 |
^ ''. |
|
766 |
]. |
|
796 | 767 |
^ 'colons have different meaning depending on context: |
49 | 768 |
|
769 |
1) they separate keyword-parts in symbols and keyword-messages as in: |
|
770 |
||
771 |
#at:put: a constant keyword symbol |
|
772 |
||
773 |
rec at:index put:value sends the #at:put: message to rec, |
|
796 | 774 |
passing index and value as arguments. |
49 | 775 |
|
776 |
2) within block-argument declarations as in: |
|
777 |
||
778 |
[:arg1 :arg2 | statements] |
|
834 | 779 |
|
780 |
3) within an identifier, they separate the nameSpace part from |
|
781 |
the name part; as in: |
|
782 |
||
783 |
Smalltalk::Array - the Array class in the Smalltalk nameSpace. |
|
784 |
Foo::Array - the Array class in the Foo nameSpace. |
|
49 | 785 |
' |
786 |
]. |
|
787 |
||
788 |
(string = '.') ifTrue:[ |
|
796 | 789 |
^ 'statement. "<- period here" |
49 | 790 |
statement |
791 |
||
792 |
within a method or block, individual statements are separated by periods. |
|
793 |
' |
|
794 |
]. |
|
795 |
||
796 |
(string startsWith:'#' ) ifTrue:[ |
|
796 | 797 |
(string startsWith:'#(' ) ifTrue:[ |
1183 | 798 |
shortText ifTrue:[ |
799 |
^ 'Array Literal.'. |
|
800 |
]. |
|
796 | 801 |
^ 'is a constant Array. |
49 | 802 |
|
803 |
The elements of a constant Array must be Number-constants, nil, true or false. |
|
804 |
(notice, that not all Smalltalk implementations allow true, false and nil as |
|
805 |
constant-Array elements).' |
|
796 | 806 |
]. |
49 | 807 |
|
796 | 808 |
(string startsWith:'#[') ifTrue:[ |
1183 | 809 |
shortText ifTrue:[ |
810 |
^ 'ByteArray Literal.'. |
|
811 |
]. |
|
796 | 812 |
^ 'is a constant ByteArray. |
49 | 813 |
|
814 |
The elements of a constant ByteArray must be Integer constants in the range |
|
815 |
0 .. 255. |
|
816 |
(notice, that not all Smalltalk implementations support constant ByteArrays).' |
|
796 | 817 |
]. |
49 | 818 |
|
796 | 819 |
(string startsWith:'#''') ifTrue:[ |
1183 | 820 |
shortText ifTrue:[ |
821 |
^ 'Symbol Literal.'. |
|
822 |
]. |
|
796 | 823 |
^ 'is a constant symbol containing non-alphanumeric characters. |
49 | 824 |
|
825 |
Symbols are unique strings, meaning that there exists |
|
826 |
exactly one instance of a given symbol. Therefore symbols can |
|
827 |
be compared using == (identity compare) in addition to = (contents compare). |
|
828 |
Beside this, Symbols behave mostly like Strings. |
|
829 |
||
830 |
Notice, that not all Smalltalk implementations support this kind of symbols.' |
|
796 | 831 |
]. |
49 | 832 |
|
1232 | 833 |
shortText ifTrue:[ |
834 |
^ 'Symbol Literal.'. |
|
835 |
]. |
|
796 | 836 |
^ 'is a symbol. |
49 | 837 |
|
838 |
Symbols are unique strings, meaning that there exists |
|
839 |
exactly one instance of a given symbol. Therefore symbols can |
|
840 |
be compared using == (identity compare) in addition to = (contents compare). |
|
841 |
Beside this, Symbols behave mostly like Strings.' |
|
842 |
]. |
|
843 |
||
844 |
"/ is it a symbol without hash-character ? |
|
845 |
"/ |
|
796 | 846 |
"/ string knownAsSymbol ifTrue:[ |
847 |
"/ ^ 'is nothing, but #' , string , ' is known as a symbol. |
|
848 |
"/ |
|
849 |
"/Symbols are unique strings, meaning that there exists |
|
850 |
"/exactly one instance of a given symbol. Therefore symbols can |
|
851 |
"/be compared using == (identity compare) in addition to = (contents compare). |
|
852 |
"/Beside this, Symbols behave mostly like Strings.' |
|
853 |
"/ ]. |
|
49 | 854 |
|
855 |
^ nil |
|
796 | 856 |
|
857 |
"Modified: / 31.10.1998 / 14:28:58 / cg" |
|
141 | 858 |
! ! |
49 | 859 |
|
396 | 860 |
!Explainer class methodsFor:'documentation'! |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
861 |
|
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
862 |
version |
1317
064ed982ddf8
commonSuperClassOf: easier (fixed ?)
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
863 |
^ '$Header: /cvs/stx/stx/libcomp/Explainer.st,v 1.55 2002-09-12 09:14:05 cg Exp $' |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
864 |
! ! |