author | Stefan Vogel <sv@exept.de> |
Fri, 10 May 2013 15:35:10 +0200 | |
changeset 3164 | f11d0862c65e |
parent 3156 | b09c18add94f |
child 3174 | e3e1c0bde329 |
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 |
" |
|
1081 | 12 |
"{ Package: 'stx:libcomp' }" |
13 |
||
141 | 14 |
Parser subclass:#Explainer |
263 | 15 |
instanceVariableNames:'' |
16 |
classVariableNames:'' |
|
17 |
poolDictionaries:'' |
|
18 |
category:'System-Compiler' |
|
2 | 19 |
! |
20 |
||
396 | 21 |
!Explainer class methodsFor:'documentation'! |
2 | 22 |
|
20 | 23 |
copyright |
24 |
" |
|
25 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
49 | 26 |
All Rights Reserved |
20 | 27 |
|
28 |
This software is furnished under a license and may be used |
|
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
! |
|
36 |
||
2 | 37 |
documentation |
38 |
" |
|
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
39 |
a very simple explainer - much more should be added... |
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
40 |
|
20 | 41 |
This one is involved, when the 'explain' function is used in a |
1728 | 42 |
codeView (popup or via CMD-E), or if the mouse button is clicked |
43 |
on some code construct in the new browser. |
|
263 | 44 |
|
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
45 |
Most of the texts returned here are heuristically motivated, |
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
46 |
based on the experience with beginners and their frequently asked questions. |
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
47 |
|
263 | 48 |
[author:] |
49 |
Claus Gittinger |
|
2 | 50 |
" |
51 |
! ! |
|
52 |
||
396 | 53 |
!Explainer class methodsFor:'explaining'! |
2 | 54 |
|
2193
9416fc17ee62
pass the interval to the explainer
Claus Gittinger <cg@exept.de>
parents:
2191
diff
changeset
|
55 |
explainLiteralNode:node in:code forClass:cls short:short interval:intervalIfKnown |
2954
0943337cfb73
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2940
diff
changeset
|
56 |
|expl literalValue findInnerMost elementIndex| |
1728 | 57 |
|
58 |
literalValue := node value. |
|
2955
d52a51930921
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2954
diff
changeset
|
59 |
expl := literalValue class name "allBold" , '-constant'. |
2954
0943337cfb73
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2940
diff
changeset
|
60 |
|
2316
f09794e008f8
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
61 |
(literalValue isInteger) ifTrue:[ |
f09794e008f8
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
62 |
(literalValue ~= 0 and:[literalValue ~= 1]) ifTrue:[ |
f09794e008f8
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
63 |
expl := expl , '('. |
f09794e008f8
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
64 |
#(2 10 16) do:[:base | |
f09794e008f8
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
65 |
base ~= (node token radix ? 10) ifTrue:[ |
f09794e008f8
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
66 |
expl := expl , ' ' , (literalValue radixPrintStringRadix:base) |
f09794e008f8
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
67 |
]. |
f09794e008f8
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
68 |
]. |
f09794e008f8
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
69 |
expl := expl , ' )'. |
f09794e008f8
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
70 |
]. |
f09794e008f8
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
71 |
^ expl. |
f09794e008f8
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2315
diff
changeset
|
72 |
]. |
2954
0943337cfb73
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2940
diff
changeset
|
73 |
|
0943337cfb73
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2940
diff
changeset
|
74 |
(node isLiteralArray and:[intervalIfKnown notNil]) ifTrue:[ |
0943337cfb73
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2940
diff
changeset
|
75 |
"/ see which element we have to explay |
0943337cfb73
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2940
diff
changeset
|
76 |
findInnerMost := |
0943337cfb73
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2940
diff
changeset
|
77 |
[:token | |
0943337cfb73
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2940
diff
changeset
|
78 |
token value keysAndValuesDo:[:index :eachToken | |
0943337cfb73
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2940
diff
changeset
|
79 |
|selectorOrName| |
0943337cfb73
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2940
diff
changeset
|
80 |
|
0943337cfb73
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2940
diff
changeset
|
81 |
((eachToken start to:eachToken stop) intersect:intervalIfKnown) notEmpty ifTrue:[ |
0943337cfb73
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2940
diff
changeset
|
82 |
elementIndex := index. "/ see below |
0943337cfb73
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2940
diff
changeset
|
83 |
|
0943337cfb73
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2940
diff
changeset
|
84 |
eachToken value isArray ifTrue:[ |
0943337cfb73
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2940
diff
changeset
|
85 |
findInnerMost value:eachToken. |
0943337cfb73
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2940
diff
changeset
|
86 |
]. |
0943337cfb73
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2940
diff
changeset
|
87 |
eachToken value isSymbol ifTrue:[ |
0943337cfb73
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2940
diff
changeset
|
88 |
selectorOrName := eachToken value. |
0943337cfb73
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2940
diff
changeset
|
89 |
selectorOrName isUppercaseFirst ifTrue:[ |
0943337cfb73
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2940
diff
changeset
|
90 |
(Smalltalk includesKey:selectorOrName) ifTrue:[ |
0943337cfb73
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2940
diff
changeset
|
91 |
^ expl, ' / ', (Explainer explainGlobal:selectorOrName inClass:cls short:short) |
0943337cfb73
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2940
diff
changeset
|
92 |
]. |
0943337cfb73
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2940
diff
changeset
|
93 |
]. |
0943337cfb73
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2940
diff
changeset
|
94 |
^ expl, ' / ', (Explainer explainSelector:selectorOrName inClass:cls short:short) |
0943337cfb73
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2940
diff
changeset
|
95 |
]. |
0943337cfb73
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2940
diff
changeset
|
96 |
]. |
0943337cfb73
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2940
diff
changeset
|
97 |
] |
0943337cfb73
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2940
diff
changeset
|
98 |
]. |
0943337cfb73
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2940
diff
changeset
|
99 |
findInnerMost value:node token. |
0943337cfb73
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2940
diff
changeset
|
100 |
]. |
0943337cfb73
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2940
diff
changeset
|
101 |
|
2955
d52a51930921
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2954
diff
changeset
|
102 |
(literalValue isArray or:[ literalValue isByteArray or:[ literalValue isString ]]) ifTrue:[ |
1728 | 103 |
literalValue size == 0 ifTrue:[ |
104 |
^ 'empty ' , expl |
|
105 |
]. |
|
2954
0943337cfb73
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2940
diff
changeset
|
106 |
elementIndex notNil ifTrue:[ |
0943337cfb73
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2940
diff
changeset
|
107 |
^ expl , (' (size=%1; element=%2)' bindWith:literalValue size with:elementIndex) |
0943337cfb73
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2940
diff
changeset
|
108 |
]. |
2955
d52a51930921
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2954
diff
changeset
|
109 |
literalValue isString ifTrue:[ |
d52a51930921
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2954
diff
changeset
|
110 |
elementIndex := intervalIfKnown start - node token start. |
d52a51930921
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2954
diff
changeset
|
111 |
|
d52a51930921
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2954
diff
changeset
|
112 |
(elementIndex between:1 and:literalValue size) ifTrue:[ |
d52a51930921
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2954
diff
changeset
|
113 |
^ expl , (' (size=%1; position=%2)' bindWith:literalValue size with:elementIndex) |
d52a51930921
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2954
diff
changeset
|
114 |
] |
d52a51930921
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2954
diff
changeset
|
115 |
]. |
2940
5136fa086e6d
changed: #explainLiteralNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2899
diff
changeset
|
116 |
^ expl , (' (size=%1)' bindWith:literalValue size) |
1728 | 117 |
]. |
2191
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
118 |
|
1728 | 119 |
^ expl |
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
120 |
|
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
121 |
"Modified: / 09-10-2006 / 12:09:43 / cg" |
1728 | 122 |
! |
123 |
||
2193
9416fc17ee62
pass the interval to the explainer
Claus Gittinger <cg@exept.de>
parents:
2191
diff
changeset
|
124 |
explainMessageNode:node in:code forClass:cls short:short interval:intervalIfKnown |
1771 | 125 |
"answer a string which explains node" |
126 |
||
1728 | 127 |
|receiver nm srchClass selector selectorString implClass |
128 |
boldSelectorString globalValue recClassSet |
|
1854 | 129 |
implMethod implMethodComment info implMethods comments definer |
130 |
instances classesOfInstVars implementingClasses canBeNil |
|
1909 | 131 |
bestMatches| |
1728 | 132 |
|
133 |
selector := node selector. |
|
134 |
selectorString := selector printString contractTo:30. |
|
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
135 |
boldSelectorString := selectorString "allBold". |
1728 | 136 |
|
1733 | 137 |
recClassSet := self guessPossibleImplementorClassesFor:(node receiver) in:code forClass:cls. |
138 |
recClassSet size == 1 ifTrue:[ |
|
139 |
srchClass := recClassSet first. |
|
2031
1ce5af7a6ba6
Do not try to store nil into Sets - avoid diagnostics.
Stefan Vogel <sv@exept.de>
parents:
2008
diff
changeset
|
140 |
"take care - Set cannot store nil!!" |
3059
9143ab6cfada
Don't do collect:[] as:Array and select:[] as:Array
Stefan Vogel <sv@exept.de>
parents:
3058
diff
changeset
|
141 |
implementingClasses := (recClassSet collect:[:cls | cls whichClassIncludesSelector:selector]) asArray. |
1869 | 142 |
|
1733 | 143 |
(implementingClasses includes:nil) ifTrue:[ |
1869 | 144 |
implementingClasses size > 1 ifTrue:[ |
145 |
^ 'possibly not understood: %1 (%2 other implementors)' |
|
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
146 |
bindWith:selector "allBold" |
1869 | 147 |
with:(implementingClasses size - 1) |
148 |
]. |
|
149 |
||
150 |
bestMatches := Parser findBestSelectorsFor:selector in:srchClass. |
|
151 |
bestMatches size > 0 ifTrue:[ |
|
1979 | 152 |
^ 'NOT understood here: %1 (Best guess: %2)' |
1869 | 153 |
bindWith:selector |
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
154 |
with:(bestMatches first "allBold") |
1869 | 155 |
]. |
1979 | 156 |
^ 'NOT understood here: %1' bindWith:selector "allBold" |
1728 | 157 |
]. |
1733 | 158 |
]. |
159 |
||
160 |
implementingClasses isNil ifTrue:[ |
|
161 |
receiver := node receiver. |
|
162 |
receiver isVariable ifTrue:[ |
|
163 |
nm := receiver name. |
|
164 |
nm = 'self' ifTrue:[ |
|
165 |
srchClass := cls |
|
166 |
]. |
|
167 |
nm = 'super' ifTrue:[ |
|
168 |
srchClass := cls superclass |
|
169 |
]. |
|
170 |
definer := receiver whoDefines:nm. |
|
171 |
definer isNil ifTrue:[ |
|
172 |
"/ not a local or argument |
|
173 |
(cls instanceVariableNames includes:nm) ifTrue:[ |
|
174 |
"/ ok - an instVar; see what values we find... |
|
175 |
instances := cls allSubInstances. |
|
3058 | 176 |
classesOfInstVars := instances collect:[:eachInst | (eachInst instVarNamed:nm) class] as:Set. |
2031
1ce5af7a6ba6
Do not try to store nil into Sets - avoid diagnostics.
Stefan Vogel <sv@exept.de>
parents:
2008
diff
changeset
|
177 |
canBeNil := (classesOfInstVars remove:UndefinedObject ifAbsent:[]) notNil. |
1ce5af7a6ba6
Do not try to store nil into Sets - avoid diagnostics.
Stefan Vogel <sv@exept.de>
parents:
2008
diff
changeset
|
178 |
"take care - Set cannot store nil!!" |
1ce5af7a6ba6
Do not try to store nil into Sets - avoid diagnostics.
Stefan Vogel <sv@exept.de>
parents:
2008
diff
changeset
|
179 |
implementingClasses := classesOfInstVars collect:[:cls | (cls whichClassIncludesSelector:selector) ? 0]. |
1ce5af7a6ba6
Do not try to store nil into Sets - avoid diagnostics.
Stefan Vogel <sv@exept.de>
parents:
2008
diff
changeset
|
180 |
implementingClasses remove:0 ifAbsent:[]. |
1733 | 181 |
] ifFalse:[ |
182 |
nm isUppercaseFirst ifTrue:[ |
|
183 |
nm knownAsSymbol ifTrue:[ |
|
184 |
globalValue := Smalltalk at:nm asSymbol. |
|
185 |
globalValue isClass ifTrue:[ |
|
186 |
srchClass := globalValue class. |
|
187 |
]. |
|
188 |
] |
|
189 |
]. |
|
1728 | 190 |
]. |
191 |
]. |
|
192 |
]. |
|
193 |
||
1733 | 194 |
receiver isLiteral ifTrue:[ |
195 |
srchClass := receiver value class |
|
196 |
]. |
|
1728 | 197 |
|
1733 | 198 |
srchClass notNil ifTrue:[ |
1761 | 199 |
implClass := srchClass whichClassIncludesSelector:selector. |
1733 | 200 |
implClass isNil ifTrue:[ |
201 |
^ '%1 is NOT understood here.' bindWith:boldSelectorString |
|
202 |
]. |
|
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
203 |
info := '%1 >> %2' bindWith:implClass name "allBold" with:selectorString "allBold". |
1728 | 204 |
|
1733 | 205 |
implMethod := implClass compiledMethodAt:selector. |
1909 | 206 |
implMethodComment := self fetchCommentOfMethod:implMethod. |
1854 | 207 |
implMethodComment notNil ifTrue:[ |
208 |
info := info , ' ' , implMethodComment. |
|
1733 | 209 |
]. |
210 |
^ info |
|
1728 | 211 |
]. |
1733 | 212 |
implementingClasses isNil ifTrue:[ |
213 |
implementingClasses := Smalltalk allImplementorsOf:selector |
|
214 |
]. |
|
1728 | 215 |
]. |
216 |
||
217 |
implementingClasses size == 1 ifTrue:[ |
|
218 |
implClass := implementingClasses anElement. |
|
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
219 |
info := '%1 >> %2' bindWith:implClass name "allBold" with:selectorString. |
1733 | 220 |
srchClass isNil ifTrue:[ |
1854 | 221 |
"/ info := 'guess: ', info. |
222 |
info := info , ' (guess)'. |
|
1733 | 223 |
]. |
1728 | 224 |
] ifFalse:[ |
225 |
info := Explainer explainSelector:selector inClass:cls short:short. |
|
226 |
]. |
|
227 |
||
1771 | 228 |
implementingClasses notEmptyOrNil ifTrue:[ |
1728 | 229 |
implMethods := implementingClasses collect:[:implClass | implClass compiledMethodAt:selector]. |
230 |
implMethods size <= 5 ifTrue:[ |
|
1771 | 231 |
comments := implMethods collect:[:implMethod | implMethod comment ? '']. |
232 |
(comments includes:'') ifFalse:[ |
|
3058 | 233 |
comments := comments collect:[:implMethodComment | implMethodComment firstLine] as:Set. |
234 |
comments size == 1 ifTrue:[ |
|
1909 | 235 |
info := info , ' ' , (self fetchCommentOfMethod:implMethods first). |
1728 | 236 |
]. |
237 |
]. |
|
238 |
]. |
|
239 |
]. |
|
240 |
^ info |
|
1854 | 241 |
|
1979 | 242 |
"Modified: / 06-02-2007 / 19:26:11 / cg" |
1728 | 243 |
! |
244 |
||
2193
9416fc17ee62
pass the interval to the explainer
Claus Gittinger <cg@exept.de>
parents:
2191
diff
changeset
|
245 |
explainMethodNode:node in:code forClass:cls short:short interval:intervalIfKnown |
1728 | 246 |
|srchClass selector selectorString implClass |
247 |
"sendingMethods numSendingMethods sendingClasses" boldSelectorString| |
|
248 |
||
249 |
selector := node selector. |
|
250 |
selectorString := selector printString contractTo:30. |
|
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
251 |
boldSelectorString := selectorString "allBold". |
1728 | 252 |
|
253 |
(srchClass := cls superclass) notNil ifTrue:[ |
|
1761 | 254 |
implClass := srchClass whichClassIncludesSelector:selector. |
1728 | 255 |
implClass notNil ifTrue:[ |
256 |
^ '%1 hides implementation in %2.' |
|
257 |
bindWith:boldSelectorString |
|
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
258 |
with:implClass name "allBold" |
1728 | 259 |
]. |
260 |
]. |
|
2223
50b76baab48b
changed: #explainMethodNode:in:forClass:short:interval:
Claus Gittinger <cg@exept.de>
parents:
2214
diff
changeset
|
261 |
(cls includesSelector:selector) ifFalse:[ |
1728 | 262 |
^ '%1: a new method.' bindWith:boldSelectorString |
263 |
]. |
|
264 |
"/ |
|
265 |
"/ sendingMethods := SystemBrowser |
|
266 |
"/ allCallsOn:selector |
|
267 |
"/ in:(cls withAllSubclasses , cls allSubclasses) |
|
268 |
"/ ignoreCase:false |
|
269 |
"/ match:false. |
|
270 |
"/ sendingMethods := sendingMethods select:[:eachMethod | eachMethod mclass notNil]. "/ remove unbound ones |
|
271 |
"/ |
|
272 |
"/ sendingClasses := (sendingMethods collect:[:eachMethod | eachMethod mclass]) asSet. |
|
273 |
"/ numSendingMethods := sendingMethods size. |
|
274 |
"/ numSendingMethods == 1 ifTrue:[ |
|
275 |
"/ sendingClasses first == cls ifTrue:[ |
|
276 |
"/ ^ '%1: sent locally from %2.' |
|
277 |
"/ bindWith:boldSelectorString |
|
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
278 |
"/ with:sendingMethods first selector "allBold" |
1728 | 279 |
"/ ]. |
280 |
"/ ^ '%1: sent in hierarchy from %2 in %3.' |
|
281 |
"/ bindWith:boldSelectorString |
|
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
282 |
"/ with:sendingMethods first selector "allBold" |
1728 | 283 |
"/ with:sendingClasses first name. |
284 |
"/ ]. |
|
285 |
"/ numSendingMethods == 2 ifTrue:[ |
|
286 |
"/ sendingClasses asIdentitySet size == 1 ifTrue:[ |
|
287 |
"/ sendingClasses first == cls ifTrue:[ |
|
288 |
"/ ^ '%1: sent locally from %2 and %3.' |
|
289 |
"/ bindWith:boldSelectorString |
|
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
290 |
"/ with:sendingMethods first selector "allBold" |
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
291 |
"/ with:sendingMethods second selector "allBold" |
1728 | 292 |
"/ ]. |
293 |
"/ ^ '%1: sent in hierarchy from %2 and %3 in %4.' |
|
294 |
"/ bindWith:boldSelectorString |
|
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
295 |
"/ with:sendingMethods first selector "allBold" |
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
296 |
"/ with:sendingMethods second selector "allBold" |
1728 | 297 |
"/ with:sendingClasses first name. |
298 |
"/ ]. |
|
299 |
"/ ]. |
|
300 |
"/ numSendingMethods == 0 ifTrue:[ |
|
301 |
"/"/ ^ '%1: no sender found.' |
|
302 |
"/"/ bindWith:boldSelectorString. |
|
303 |
"/ ^ nil |
|
304 |
"/ ]. |
|
305 |
"/ ^ '%1: %2 sending methods in hierarchy.' |
|
306 |
"/ bindWith:boldSelectorString |
|
307 |
"/ with:numSendingMethods. |
|
308 |
"/ |
|
309 |
"/ "/ the following is too expensive... |
|
310 |
"/"/ sendingMethods := SystemBrowser allCallsOn:selector in:Smalltalk allClasses. |
|
311 |
"/"/ numSendingMethods == 0 ifTrue:[ |
|
312 |
"/"/ ^ '%1: nowhere sent.' bindWith:boldSelectorString |
|
313 |
"/"/ ]. |
|
314 |
"/"/ numSendingMethods == 1 ifTrue:[ |
|
315 |
"/"/ sendingMethods first mclass == cls ifTrue:[ |
|
316 |
"/"/ ^ '%1: only sent from %2.' |
|
317 |
"/"/ bindWith:boldSelectorString |
|
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
318 |
"/"/ with:sendingMethods first selector "allBold" |
1728 | 319 |
"/"/ ]. |
320 |
"/"/ ^ '%1: only sent from %2 in %3.' |
|
321 |
"/"/ bindWith:boldSelectorString |
|
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
322 |
"/"/ with:sendingMethods first selector "allBold" |
1728 | 323 |
"/"/ with:sendingMethods first mclass name. |
324 |
"/"/ ]. |
|
325 |
"/"/ sendingClasses := (sendingMethods collect:[:eachMethod | eachMethod mclass]) asSet. |
|
326 |
"/"/ sendingClasses size == 1 ifTrue:[ |
|
327 |
"/"/ sendingClasses first == cls ifTrue:[ |
|
328 |
"/"/ ^ '%1: locally sent from %2 methods.' |
|
329 |
"/"/ bindWith:boldSelectorString |
|
330 |
"/"/ with:numSendingMethods |
|
331 |
"/"/ ]. |
|
332 |
"/"/ ^ '%1 only sent from %2 methods in %3.' |
|
333 |
"/"/ bindWith:boldSelectorString |
|
334 |
"/"/ with:numSendingMethods |
|
335 |
"/"/ with:sendingClasses first name. |
|
336 |
"/"/ ]. |
|
337 |
||
338 |
^ nil |
|
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
339 |
|
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
340 |
"Modified: / 09-10-2006 / 12:11:16 / cg" |
1728 | 341 |
! |
342 |
||
2193
9416fc17ee62
pass the interval to the explainer
Claus Gittinger <cg@exept.de>
parents:
2191
diff
changeset
|
343 |
explainNode:node in:code forClass:cls short:short |
9416fc17ee62
pass the interval to the explainer
Claus Gittinger <cg@exept.de>
parents:
2191
diff
changeset
|
344 |
self explainNode:node in:code forClass:cls short:short interval:nil |
9416fc17ee62
pass the interval to the explainer
Claus Gittinger <cg@exept.de>
parents:
2191
diff
changeset
|
345 |
! |
9416fc17ee62
pass the interval to the explainer
Claus Gittinger <cg@exept.de>
parents:
2191
diff
changeset
|
346 |
|
9416fc17ee62
pass the interval to the explainer
Claus Gittinger <cg@exept.de>
parents:
2191
diff
changeset
|
347 |
explainNode:node in:code forClass:cls short:short interval:intervalIfKnown |
1728 | 348 |
node isVariable ifTrue:[ |
2193
9416fc17ee62
pass the interval to the explainer
Claus Gittinger <cg@exept.de>
parents:
2191
diff
changeset
|
349 |
^ self explainVariableNode:node in:code forClass:cls short:short interval:intervalIfKnown. |
1728 | 350 |
]. |
351 |
||
352 |
node isLiteral ifTrue:[ |
|
2193
9416fc17ee62
pass the interval to the explainer
Claus Gittinger <cg@exept.de>
parents:
2191
diff
changeset
|
353 |
^ self explainLiteralNode:node in:code forClass:cls short:short interval:intervalIfKnown |
1728 | 354 |
]. |
355 |
||
356 |
node isMessage ifTrue:[ |
|
2193
9416fc17ee62
pass the interval to the explainer
Claus Gittinger <cg@exept.de>
parents:
2191
diff
changeset
|
357 |
^ self explainMessageNode:node in:code forClass:cls short:short interval:intervalIfKnown |
1728 | 358 |
]. |
359 |
||
360 |
node isMethod ifTrue:[ |
|
2193
9416fc17ee62
pass the interval to the explainer
Claus Gittinger <cg@exept.de>
parents:
2191
diff
changeset
|
361 |
^ self explainMethodNode:node in:code forClass:cls short:short interval:intervalIfKnown |
1728 | 362 |
]. |
363 |
||
364 |
^ nil |
|
365 |
! |
|
366 |
||
2193
9416fc17ee62
pass the interval to the explainer
Claus Gittinger <cg@exept.de>
parents:
2191
diff
changeset
|
367 |
explainVariableNode:node in:code forClass:cls short:short interval:intervalIfKnown |
1938 | 368 |
|expl nm nmBold definingNode namePart| |
1728 | 369 |
|
370 |
nm := node name. |
|
371 |
||
372 |
(#( 'self' 'super' 'thisContext' 'here') includes:nm) ifTrue:[ |
|
373 |
^ Explainer explainPseudoVariable:nm in:cls short:short |
|
374 |
]. |
|
375 |
||
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
376 |
nm notNil ifTrue:[ nmBold := nm "allBold" ]. |
1728 | 377 |
|
378 |
definingNode := node whoDefines:nm. |
|
379 |
definingNode notNil ifTrue:[ |
|
1938 | 380 |
namePart := '''' , nmBold , ''''. |
1728 | 381 |
definingNode isMethod ifTrue:[ |
382 |
(definingNode arguments contains:[:arg | arg name = nm]) ifTrue:[ |
|
1938 | 383 |
expl := namePart , ' is a method argument.' |
1728 | 384 |
]. |
385 |
]. |
|
1938 | 386 |
expl isNil ifTrue:[ |
387 |
definingNode isBlock ifTrue:[ |
|
388 |
(definingNode arguments contains:[:arg | arg name = nm]) ifTrue:[ |
|
389 |
expl := namePart , ' is a block argument.' |
|
390 |
]. |
|
1728 | 391 |
]. |
392 |
]. |
|
1938 | 393 |
expl isNil ifTrue:[ |
394 |
definingNode parent notNil ifTrue:[ |
|
395 |
definingNode parent isMethod ifTrue:[ |
|
396 |
expl := namePart , ' is a method temporary.'. |
|
397 |
] ifFalse:[ |
|
398 |
definingNode parent isBlock ifTrue:[ |
|
399 |
expl := namePart , ' is a block temporary.'. |
|
400 |
] |
|
401 |
] |
|
1728 | 402 |
]. |
1938 | 403 |
]. |
404 |
expl isNil ifTrue:[ |
|
405 |
expl := namePart , ' is a temporary.' |
|
1728 | 406 |
]. |
1938 | 407 |
(cls allInstanceVariableNames includes:nm) ifTrue:[ |
408 |
expl := expl , ' (Instance Variable is hidden)' |
|
409 |
]. |
|
410 |
^ expl. |
|
1728 | 411 |
]. |
1938 | 412 |
|
1728 | 413 |
^ Explainer explain:node name in:code forClass:cls short:short |
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
414 |
|
1938 | 415 |
"Modified: / 07-11-2006 / 12:22:09 / cg" |
1728 | 416 |
! |
417 |
||
1909 | 418 |
fetchCommentOfMethod:mthd |
419 |
|methodComment lines| |
|
420 |
||
421 |
methodComment := mthd comment. |
|
3047 | 422 |
methodComment isEmptyOrNil ifTrue:[^ nil]. |
1909 | 423 |
|
424 |
lines := methodComment asStringCollection. |
|
425 |
methodComment := lines first. |
|
426 |
methodComment := methodComment withoutSeparators. |
|
3156
b09c18add94f
Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents:
3111
diff
changeset
|
427 |
(methodComment endsWith:',') ifTrue:[ methodComment := methodComment copyButLast:1]. |
1909 | 428 |
methodComment := methodComment withoutSeparators. |
429 |
(lines size > 1) ifTrue:[ |
|
2133 | 430 |
methodComment := methodComment , ' ...' |
1909 | 431 |
]. |
2225
caacd294cddc
no need for #asText to emphasize a string
Claus Gittinger <cg@exept.de>
parents:
2223
diff
changeset
|
432 |
^ ('"' , methodComment , '"') colorizeAllWith:(UserPreferences current commentColor). |
1909 | 433 |
|
434 |
"Created: / 14-09-2006 / 14:11:58 / cg" |
|
435 |
! |
|
436 |
||
1728 | 437 |
guessPossibleImplementorClassesFor:node in:code forClass:cls |
2191
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
438 |
"given a node of some code of a method in cls, |
2292
e5ccd3d7a805
changed: #guessPossibleImplementorClassesFor:in:forClass:
Stefan Vogel <sv@exept.de>
parents:
2288
diff
changeset
|
439 |
return a collection of possible receiver classes." |
2191
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
440 |
|
2809
bbf42cc4d305
changed: #guessPossibleImplementorClassesFor:in:forClass:
Claus Gittinger <cg@exept.de>
parents:
2471
diff
changeset
|
441 |
|nm globalValue definer instances classesOfInstVars ns| |
1728 | 442 |
|
443 |
node isVariable ifTrue:[ |
|
444 |
nm := node name. |
|
445 |
||
2292
e5ccd3d7a805
changed: #guessPossibleImplementorClassesFor:in:forClass:
Stefan Vogel <sv@exept.de>
parents:
2288
diff
changeset
|
446 |
nm = #self ifTrue:[ |
1728 | 447 |
^ cls withAllSubclasses |
448 |
]. |
|
2292
e5ccd3d7a805
changed: #guessPossibleImplementorClassesFor:in:forClass:
Stefan Vogel <sv@exept.de>
parents:
2288
diff
changeset
|
449 |
nm = #here ifTrue:[ |
1728 | 450 |
^ cls withAllSuperclasses |
451 |
]. |
|
2292
e5ccd3d7a805
changed: #guessPossibleImplementorClassesFor:in:forClass:
Stefan Vogel <sv@exept.de>
parents:
2288
diff
changeset
|
452 |
nm = #super ifTrue:[ |
1728 | 453 |
^ cls allSuperclasses |
454 |
]. |
|
455 |
||
456 |
definer := node whoDefines:nm. |
|
457 |
definer isNil ifTrue:[ |
|
458 |
"/ not a local or argument |
|
459 |
(cls instanceVariableNames includes:nm) ifTrue:[ |
|
460 |
"/ ok - an instVar; see what values we find... |
|
461 |
instances := cls allSubInstances. |
|
3058 | 462 |
classesOfInstVars := instances collect:[:eachInst | (eachInst instVarNamed:nm) class] as:Set. |
1728 | 463 |
^ classesOfInstVars. |
464 |
]. |
|
2191
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
465 |
(cls classVariableNames includes:nm) ifTrue:[ |
2292
e5ccd3d7a805
changed: #guessPossibleImplementorClassesFor:in:forClass:
Stefan Vogel <sv@exept.de>
parents:
2288
diff
changeset
|
466 |
^ Array with:(cls classVarAt:nm asSymbol) class. |
2191
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
467 |
]. |
1728 | 468 |
nm isUppercaseFirst ifTrue:[ |
469 |
nm knownAsSymbol ifTrue:[ |
|
470 |
globalValue := Smalltalk at:nm asSymbol. |
|
471 |
globalValue isClass ifTrue:[ |
|
472 |
^ Array with:globalValue class. |
|
473 |
]. |
|
474 |
]. |
|
2809
bbf42cc4d305
changed: #guessPossibleImplementorClassesFor:in:forClass:
Claus Gittinger <cg@exept.de>
parents:
2471
diff
changeset
|
475 |
((ns := cls topNameSpace) notNil and:[ns ~~ Smalltalk]) ifTrue:[ |
bbf42cc4d305
changed: #guessPossibleImplementorClassesFor:in:forClass:
Claus Gittinger <cg@exept.de>
parents:
2471
diff
changeset
|
476 |
globalValue := ns at:nm asSymbol. |
1728 | 477 |
globalValue isClass ifTrue:[ |
478 |
^ Array with:globalValue class. |
|
479 |
]. |
|
480 |
] |
|
481 |
]. |
|
482 |
]. |
|
483 |
^ nil |
|
484 |
]. |
|
485 |
||
486 |
node isLiteral ifTrue:[ |
|
487 |
^ Array with:(node value class) |
|
488 |
]. |
|
489 |
||
2191
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
490 |
"/ node isMessage ifTrue:[ |
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
491 |
"/ recClassSet := self guessPossibleImplementorClassesFor:(node receiver) in:code forClass:cls. |
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
492 |
"/ recClassSet isNil ifTrue:[ ^ nil ]. |
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
493 |
"/ recClassSet isEmpty ifTrue:[ ^ nil ]. |
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
494 |
"/ |
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
495 |
"/ implSet := recClassSet collect:[:recClass | recClass whichClassIncludesSelector:node selector]. |
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
496 |
"/ "/ toDo: for each implementor, parse its method for possible return types. |
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
497 |
"/ ^ rsltClassSet. |
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
498 |
"/ ]. |
1731 | 499 |
^ nil |
2809
bbf42cc4d305
changed: #guessPossibleImplementorClassesFor:in:forClass:
Claus Gittinger <cg@exept.de>
parents:
2471
diff
changeset
|
500 |
|
bbf42cc4d305
changed: #guessPossibleImplementorClassesFor:in:forClass:
Claus Gittinger <cg@exept.de>
parents:
2471
diff
changeset
|
501 |
"Modified: / 07-02-2012 / 22:19:53 / cg" |
1728 | 502 |
! ! |
503 |
||
504 |
!Explainer class methodsFor:'explaining-naive'! |
|
505 |
||
1316
30806ca08095
commonSuperClassOf: - allow for classes and names in arg
Claus Gittinger <cg@exept.de>
parents:
1289
diff
changeset
|
506 |
commonSuperClassOf:listOfClassesOrClassNames |
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
507 |
<resource: #obsolete> |
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
508 |
|
1637 | 509 |
^ Behavior commonSuperclassOf:listOfClassesOrClassNames |
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
510 |
|
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
511 |
"Modified (format): / 28-02-2012 / 09:00:37 / cg" |
141 | 512 |
! |
513 |
||
2 | 514 |
explain:someText in:source forClass:aClass |
6 | 515 |
"Given a source and a substring of it, return a string containing |
516 |
an explanation. |
|
49 | 517 |
This is just a q&d implementation - to be correct, it should use the parser, |
518 |
and explain from the parsetree (instead of doing string matches). |
|
519 |
This leads to some wrong explanations, for example if some string is |
|
839 | 520 |
used as selector within a string, or if a variable is named like a |
521 |
message selector. I.e. the explanation should be context sensitive. |
|
49 | 522 |
Also, there could be much more detailed explanations." |
2 | 523 |
|
2037
003d9b5a2788
explain shared pool variables
Claus Gittinger <cg@exept.de>
parents:
2031
diff
changeset
|
524 |
^ self explain:someText in:source forClass:aClass short:false |
003d9b5a2788
explain shared pool variables
Claus Gittinger <cg@exept.de>
parents:
2031
diff
changeset
|
525 |
|
003d9b5a2788
explain shared pool variables
Claus Gittinger <cg@exept.de>
parents:
2031
diff
changeset
|
526 |
"Modified: / 07-06-2007 / 11:34:05 / cg" |
1183 | 527 |
! |
528 |
||
529 |
explain:someText in:source forClass:aClass short:shortText |
|
530 |
"Given a source and a substring of it, return a string containing |
|
531 |
an explanation. |
|
532 |
This is just a q&d implementation - to be correct, it should use the parser, |
|
533 |
and explain from the parsetree (instead of doing string matches). |
|
534 |
This leads to some wrong explanations, for example if some string is |
|
535 |
used as selector within a string, or if a variable is named like a |
|
536 |
message selector. I.e. the explanation should be context sensitive. |
|
537 |
Also, there could be much more detailed explanations." |
|
538 |
||
1159 | 539 |
|parser variables c string tmp |
3049 | 540 |
spc sym sel stringText cls clsName val valString| |
2 | 541 |
|
675 | 542 |
string := someText string withoutSeparators. |
2314
0c590d9937bd
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2292
diff
changeset
|
543 |
string isEmpty ifTrue:[ ^ nil ]. |
0c590d9937bd
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2292
diff
changeset
|
544 |
|
2214 | 545 |
stringText := string allBold. |
2414
4da315c5bcf4
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2316
diff
changeset
|
546 |
"/ stringText := '''' , stringText , ''''. |
49 | 547 |
|
548 |
" |
|
549 |
ask parser for variable names |
|
550 |
" |
|
3070 | 551 |
ParseError catch:[ |
1357 | 552 |
parser := self parseMethod:source in:aClass ignoreErrors:true ignoreWarnings:true. |
553 |
]. |
|
2002 | 554 |
(parser notNil and:[parser ~~ #Error]) ifTrue:[ |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
555 |
"look for variables" |
2 | 556 |
|
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
557 |
variables := parser methodVars. |
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
558 |
(variables notNil and:[variables includes:string]) ifTrue:[ |
2815 | 559 |
^ stringText , ' a method variable.' |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
560 |
]. |
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
561 |
variables := parser methodArgs. |
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
562 |
(variables notNil and:[variables includes:string]) ifTrue:[ |
2815 | 563 |
^ stringText , ' a method argument.' |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
564 |
] |
2 | 565 |
]. |
49 | 566 |
|
2 | 567 |
parser isNil ifTrue:[ |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
568 |
parser := self for:(ReadStream on:source) in:aClass |
2 | 569 |
]. |
570 |
||
2988 | 571 |
"instvars/class instVars" |
84 | 572 |
c := aClass whichClassDefinesInstVar:string. |
573 |
c notNil ifTrue:[ |
|
396 | 574 |
c isMeta ifTrue:[ |
1211
91e94e294819
isMeta/soleInstance -> theMetaclass / theNonMetaclass
Claus Gittinger <cg@exept.de>
parents:
1210
diff
changeset
|
575 |
clsName := c theNonMetaclass name. |
1198 | 576 |
shortText ifTrue:[ |
2988 | 577 |
stringText := stringText , ': a class instVar in ' , clsName |
578 |
] ifFalse:[ |
|
579 |
stringText := stringText, ': a class instance variable inherited from ' , clsName |
|
1198 | 580 |
]. |
2988 | 581 |
val := aClass theNonMetaclass instVarNamed:string. |
582 |
valString := self valueStringFor:val. |
|
583 |
^ stringText , ' (' , valString , ').' |
|
396 | 584 |
]. |
585 |
||
1233 | 586 |
clsName := c name. |
1198 | 587 |
shortText ifTrue:[ |
2815 | 588 |
^ stringText , ': an instVar in ' , clsName , '.' |
1198 | 589 |
]. |
2815 | 590 |
^ stringText , ': an instance variable inherited from ' , clsName , '.' |
2 | 591 |
]. |
592 |
||
2986 | 593 |
string isWideString ifFalse:[ |
2315
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
594 |
"classvars" |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
595 |
c := parser inWhichClassIsClassVar:string. |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
596 |
c notNil ifTrue:[ |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
597 |
clsName := c name. |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
598 |
shortText ifTrue:[ |
2815 | 599 |
stringText := stringText , ': a classVar in ' , clsName |
2315
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
600 |
] ifFalse:[ |
2815 | 601 |
stringText := stringText , ': a class variable in ' , clsName |
2315
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
602 |
]. |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
603 |
|
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
604 |
val := c theNonMetaclass classVarAt:string. "/ Smalltalk at:(clsName , ':' , string) asSymbol. |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
605 |
valString := self valueStringFor:val. |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
606 |
^ stringText , ' (' , valString , ').' |
1198 | 607 |
]. |
1693 | 608 |
|
2315
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
609 |
"private classes" |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
610 |
c := aClass theNonMetaclass. |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
611 |
c privateClasses do:[:pClass | |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
612 |
(pClass name = string |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
613 |
or:[pClass nameWithoutPrefix = string]) ifTrue:[ |
2815 | 614 |
stringText := stringText , ': a private class in ''' , c name , '''.'. |
2315
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
615 |
shortText ifFalse:[ |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
616 |
stringText := (stringText , '\\It is only visible locally.') withCRs |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
617 |
]. |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
618 |
^ stringText withCRs |
1183 | 619 |
]. |
422 | 620 |
]. |
621 |
||
2470 | 622 |
aClass theNonMetaclass sharedPoolNames do:[:eachPoolName | |
2315
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
623 |
|sharedPool| |
2037
003d9b5a2788
explain shared pool variables
Claus Gittinger <cg@exept.de>
parents:
2031
diff
changeset
|
624 |
|
2315
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
625 |
sharedPool := Smalltalk classNamed:eachPoolName. |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
626 |
sharedPool notNil ifTrue:[ |
3111 | 627 |
sharedPool isSharedPool ifFalse:[ |
628 |
^ 'oops - not a shared pool: ',eachPoolName |
|
629 |
]. |
|
2315
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
630 |
(sharedPool includesKey:string asSymbol) ifTrue:[ |
2815 | 631 |
stringText := stringText , ': a pool variable in ',sharedPool name. |
2315
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
632 |
val := sharedPool at:string. |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
633 |
valString := self valueStringFor:val. |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
634 |
^ stringText , ' (' , valString , ').' |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
635 |
]. |
2037
003d9b5a2788
explain shared pool variables
Claus Gittinger <cg@exept.de>
parents:
2031
diff
changeset
|
636 |
]. |
003d9b5a2788
explain shared pool variables
Claus Gittinger <cg@exept.de>
parents:
2031
diff
changeset
|
637 |
]. |
003d9b5a2788
explain shared pool variables
Claus Gittinger <cg@exept.de>
parents:
2031
diff
changeset
|
638 |
|
2315
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
639 |
"namespace & global variables" |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
640 |
(spc := aClass nameSpace) notNil ifTrue:[ |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
641 |
sym := (spc name , '::' , string) asSymbolIfInterned. |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
642 |
sym notNil ifTrue:[ |
3049 | 643 |
(cls := Smalltalk at:sym) isBehavior ifTrue:[ |
2315
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
644 |
string := stringText , ': '. |
3049 | 645 |
cls name = sym ifFalse:[ |
646 |
string := string , 'refers to ',cls name,', ' |
|
2315
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
647 |
]. |
3049 | 648 |
cls isSharedPool ifTrue:[ |
649 |
string := string , 'a sharedPool'. |
|
650 |
] ifFalse:[ |
|
651 |
string := string , 'a class'. |
|
652 |
]. |
|
653 |
||
654 |
string := string , ' in the ''' , spc name , ''' nameSpace'. |
|
655 |
string := string , ' {', cls category ,'}'. |
|
2315
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
656 |
shortText ifFalse:[ |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
657 |
string := (string |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
658 |
, '\\It is only visible within this nameSpace.' |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
659 |
, '\Access from the outside is possible' |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
660 |
, '\by the special name ''' , spc name , '::' , string , '''.') withCRs |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
661 |
]. |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
662 |
^ string withCRs |
1979 | 663 |
]. |
796 | 664 |
]. |
422 | 665 |
]. |
666 |
||
2315
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
667 |
"/ string knownAsSymbol ifTrue:[ |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
668 |
"globals & symbols" |
2 | 669 |
|
2315
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
670 |
tmp := self explainKnownSymbol:string inClass:aClass short:shortText. |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
671 |
tmp notNil ifTrue:[ ^ tmp]. |
839 | 672 |
|
2315
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
673 |
"/ try with added colon ... |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
674 |
sel := string , ':'. |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
675 |
Symbol allInstancesDo:[:sym | |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
676 |
(sym startsWith:sel) ifTrue:[ |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
677 |
tmp := self explainKnownSymbol:sym inClass:aClass short:shortText. |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
678 |
tmp notNil ifTrue:[ ^ tmp]. |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
679 |
] |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
680 |
]. |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
681 |
"/ ]. |
2 | 682 |
|
2315
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
683 |
"try for some obvious things" |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
684 |
tmp := self explainPseudoVariable:string in:aClass short:true. |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
685 |
tmp notNil ifTrue:[ ^ tmp]. |
45f09cea2063
changed: #explain:in:forClass:short:
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
686 |
]. |
2 | 687 |
|
688 |
"try syntax ..." |
|
689 |
||
1183 | 690 |
tmp := self explainSyntax:string short:shortText. |
49 | 691 |
tmp notNil ifTrue:[ ^ tmp]. |
20 | 692 |
|
1183 | 693 |
shortText ifTrue:[ |
1438 | 694 |
^ 'no explanation' |
1183 | 695 |
]. |
696 |
||
2 | 697 |
parser isNil ifTrue:[ |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
698 |
^ 'parse error - no explanation' |
2 | 699 |
]. |
796 | 700 |
^ '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
|
701 |
|
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
702 |
"Created: / 03-12-1995 / 12:47:37 / cg" |
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
703 |
"Modified: / 16-04-1997 / 12:46:11 / stefan" |
2815 | 704 |
"Modified: / 14-02-2012 / 15:30:25 / cg" |
2 | 705 |
! |
706 |
||
1188 | 707 |
explainGlobal:string inClass:aClass short:shortText |
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
708 |
"return an explanation or nil" |
1183 | 709 |
|
2427 | 710 |
^ self explainGlobalOrPoolVariable:string inClass:aClass short:shortText |
711 |
||
712 |
"Modified: / 14-10-2010 / 11:33:17 / cg" |
|
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
713 |
"Modified (comment): / 28-02-2012 / 10:45:58 / cg" |
2427 | 714 |
! |
715 |
||
716 |
explainGlobalOrPoolVariable:string inClass:aClass short:shortText |
|
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
717 |
"return an explanation or nil" |
2427 | 718 |
|
719 |
|sym stringText tmp val classCategory what pool valText| |
|
141 | 720 |
|
1245 | 721 |
"if not even known as key, its definitely not a global" |
722 |
sym := string asSymbolIfInterned. |
|
796 | 723 |
sym isNil ifTrue:[^ nil]. |
141 | 724 |
|
2471 | 725 |
stringText := string allBold. |
726 |
"/ stringText := '''' , stringText , ''''. |
|
727 |
stringText := stringText , ': '. |
|
728 |
||
2427 | 729 |
"a pool variable?" |
730 |
aClass notNil ifTrue:[ |
|
2470 | 731 |
aClass theNonMetaclass sharedPoolNames do:[:eachPoolName | |
2427 | 732 |
pool := Smalltalk at:eachPoolName. |
2471 | 733 |
pool isNil ifTrue:[ |
734 |
] ifFalse:[ |
|
735 |
(pool classVarNames includes:string) ifTrue:[ |
|
736 |
what := 'a pool variable in "%1".' bindWith:eachPoolName. |
|
737 |
val := pool classVarAt:sym. |
|
738 |
]. |
|
2427 | 739 |
]. |
740 |
]. |
|
741 |
]. |
|
742 |
||
743 |
what isNil ifTrue:[ |
|
744 |
"try globals" |
|
2471 | 745 |
(Smalltalk includesKey:sym) ifTrue:[ |
746 |
what := 'a global variable.'. |
|
747 |
val := Smalltalk at:sym. |
|
748 |
] ifFalse:[ |
|
749 |
(aClass theNonMetaclass sharedPoolNames includes:string) ifTrue:[ |
|
750 |
pool := Smalltalk at:sym ifAbsent:nil. |
|
751 |
pool isNil ifTrue:[ |
|
752 |
^ stringText,'a missing pool'. |
|
753 |
]. |
|
754 |
] ifFalse:[ |
|
755 |
^ nil |
|
756 |
]. |
|
757 |
]. |
|
2427 | 758 |
]. |
141 | 759 |
|
2427 | 760 |
tmp := stringText , what. |
1183 | 761 |
|
1245 | 762 |
val isBehavior ifTrue:[ |
763 |
"/ a class |
|
1979 | 764 |
val name = sym ifFalse:[ |
2815 | 765 |
stringText := stringText , ' a global; refers to ',val name,', '. |
1979 | 766 |
]. |
767 |
||
1943 | 768 |
(val isRealNameSpace) ifTrue:[ |
1979 | 769 |
^ stringText , 'a namespace.' |
1330 | 770 |
]. |
771 |
||
772 |
classCategory := val category ? 'uncategorized'. |
|
1245 | 773 |
shortText ifTrue:[ |
3049 | 774 |
stringText := stringText , (val isLoaded ifTrue:['a'] ifFalse:['an autoloaded']). |
775 |
stringText := stringText , (val isSharedPool ifTrue:[' sharedPool'] ifFalse:[' class']). |
|
776 |
^ stringText , ' in ',val package,' {' , classCategory , '}.'. |
|
1245 | 777 |
]. |
778 |
||
779 |
val name = string ifTrue:[ |
|
3049 | 780 |
tmp := tmp , '\' withCRs , string , ' is '. |
781 |
tmp := tmp , (val isLoaded ifTrue:['a'] ifFalse:['an autoloaded']). |
|
782 |
tmp := tmp , (val isSharedPool ifTrue:[' sharedPool'] ifFalse:[' class']). |
|
783 |
tmp := tmp , ' categorized as "' , classCategory , '"'. |
|
784 |
tmp := tmp , '\' withCRs , 'in the "' , val package , '" package.'. |
|
1183 | 785 |
^ tmp. |
786 |
]. |
|
141 | 787 |
|
1183 | 788 |
tmp := tmp , ' |
789 |
||
1245 | 790 |
' , string , ' is bound to the class ' , val name , |
3049 | 791 |
' 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
|
792 |
^ tmp. |
141 | 793 |
]. |
794 |
||
2427 | 795 |
valText := self valueStringFor:val. |
796 |
||
1245 | 797 |
shortText ifTrue:[ |
2815 | 798 |
^ stringText,' a global (',valText,')'. |
1245 | 799 |
]. |
800 |
tmp := tmp , ' |
|
801 |
||
2466
75b29e4a34c0
changed: #explainGlobalOrPoolVariable:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2427
diff
changeset
|
802 |
Its current value is "%1".' bindWith:valText. |
1245 | 803 |
^ tmp. |
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
804 |
|
2427 | 805 |
"Created: / 14-10-2010 / 11:33:04 / cg" |
2815 | 806 |
"Modified: / 14-02-2012 / 15:31:28 / cg" |
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
807 |
"Modified (comment): / 28-02-2012 / 10:45:48 / cg" |
1188 | 808 |
! |
809 |
||
810 |
explainHereIn:aClass |
|
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
811 |
"return an explanation" |
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
812 |
|
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
813 |
<resource: #obsolete> |
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
814 |
|
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
815 |
^ self explainHereIn:aClass short:false |
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
816 |
|
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
817 |
"Modified (comment): / 28-02-2012 / 10:47:29 / cg" |
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
818 |
! |
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
819 |
|
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
820 |
explainHereIn:aClass short:shortText |
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
821 |
"return an explanation" |
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
822 |
|
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
823 |
|className| |
1188 | 824 |
|
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
825 |
className := aClass name. |
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
826 |
|
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
827 |
shortText ifTrue:[ |
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
828 |
^ '"here" - message lookup always starts in "%1" (always call local method).' bindWith:className |
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
829 |
]. |
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
830 |
|
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
831 |
^ 'like "self", "','here'allBold,'" refers to the object which received the message. |
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
832 |
|
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
833 |
However, when sending a message to "here", the search for methods |
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
834 |
implementing this message will start in the defining class (' , className , '), |
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
835 |
instead of the receiver''s class (' , className , ' or subclass). |
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
836 |
Thus, using "here", redefined methods will NOT be reached with a here-send and it is ensured, |
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
837 |
that the local method is called.' |
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
838 |
|
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
839 |
"Created: / 28-02-2012 / 10:44:55 / cg" |
1188 | 840 |
! |
841 |
||
842 |
explainKnownSymbol:string inClass:aClass |
|
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
843 |
"return an explanation or nil" |
1188 | 844 |
|
845 |
^ self explainKnownSymbol:string inClass:aClass short:false |
|
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
846 |
|
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
847 |
"Modified (comment): / 28-02-2012 / 10:45:40 / cg" |
1188 | 848 |
! |
849 |
||
850 |
explainKnownSymbol:string inClass:aClass short:shortText |
|
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
851 |
"return an explanation or nil" |
1188 | 852 |
|
2471 | 853 |
|sym expl| |
1188 | 854 |
|
855 |
sym := string asSymbolIfInterned. |
|
856 |
sym isNil ifTrue:[^ nil]. |
|
857 |
||
2427 | 858 |
"try globals and pools" |
1188 | 859 |
(Smalltalk includesKey:sym) ifTrue:[ |
2471 | 860 |
expl := self explainGlobalOrPoolVariable:string inClass:aClass short:shortText. |
861 |
expl notNil ifTrue:[^ expl]. |
|
1188 | 862 |
]. |
863 |
||
2471 | 864 |
expl := self explainSelector:string inClass:aClass short:shortText. |
865 |
expl notNil ifTrue:[^ expl]. |
|
866 |
^ self explainGlobalOrPoolVariable:string inClass:aClass short:shortText. |
|
2427 | 867 |
|
2471 | 868 |
"Modified: / 18-01-2011 / 19:13:07 / cg" |
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
869 |
"Modified (comment): / 28-02-2012 / 10:46:06 / cg" |
1188 | 870 |
! |
871 |
||
872 |
explainPseudoVariable:string in:aClass |
|
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
873 |
"return an explanation for the pseudoVariables self, super etc." |
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
874 |
|
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
875 |
<resource: #obsolete> |
1188 | 876 |
|
877 |
^ self explainPseudoVariable:string in:aClass short:false |
|
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
878 |
|
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
879 |
"Modified (format): / 28-02-2012 / 10:47:17 / cg" |
1188 | 880 |
! |
881 |
||
882 |
explainPseudoVariable:string in:aClass short:shortText |
|
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
883 |
"return an explanation for the pseudoVariables self, super etc." |
1188 | 884 |
|
885 |
(string = 'self') ifTrue:[ |
|
886 |
^ self explainSelfIn:aClass short:shortText |
|
887 |
]. |
|
888 |
||
889 |
(string = 'super') ifTrue:[ |
|
890 |
^ self explainSuperIn:aClass short:shortText |
|
891 |
]. |
|
892 |
||
893 |
(string = 'here') ifTrue:[ |
|
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
894 |
^ self explainHereIn:aClass short:shortText |
1188 | 895 |
]. |
896 |
||
897 |
(string = 'thisContext') ifTrue:[ |
|
898 |
shortText ifTrue:[ |
|
899 |
^ '''thisContext'' - the current stack frame as an object.' |
|
900 |
]. |
|
901 |
^ 'thisContext is a pseudo variable (i.e. it is built in). |
|
902 |
||
903 |
ThisContext always refers to the context object for the currently executed method or |
|
904 |
block (an instance of Context or BlockContext respectively). The calling chain and calling |
|
905 |
receivers/selectors can be accessed via thisContext.' |
|
906 |
]. |
|
907 |
||
908 |
(string = 'true') ifTrue:[ |
|
909 |
shortText ifTrue:[ |
|
910 |
^ '''true'' - the truth and nothing but the truth.' |
|
911 |
]. |
|
912 |
^ 'true is a pseudo variable (i.e. it is built in). |
|
913 |
||
914 |
True represents logical truth. It is the one and only instance of class True.' |
|
915 |
]. |
|
916 |
||
917 |
(string = 'false') ifTrue:[ |
|
918 |
shortText ifTrue:[ |
|
919 |
^ '''false'' - obvisously not true.' |
|
920 |
]. |
|
921 |
^ 'false is a pseudo variable (i.e. it is built in). |
|
922 |
||
923 |
False represents logical falseness. It is the one and only instance of class False.' |
|
924 |
]. |
|
925 |
||
926 |
(string = 'nil') ifTrue:[ |
|
927 |
shortText ifTrue:[ |
|
928 |
^ '''nil'' - undefined, unknown, void or dont care.' |
|
929 |
]. |
|
930 |
^ 'nil is a pseudo variable (i.e. it is built in). |
|
931 |
||
932 |
Nil is used for unitialized variables (among other uses). |
|
933 |
Nil is the one and only instance of class UndefinedObject.' |
|
934 |
]. |
|
935 |
^ nil |
|
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
936 |
|
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
937 |
"Modified (comment): / 28-02-2012 / 10:46:18 / cg" |
1188 | 938 |
! |
939 |
||
940 |
explainSelector:string inClass:aClass short:shortText |
|
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
941 |
"return an explanation or nil" |
1188 | 942 |
|
2288
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
943 |
|sym list listSimilar firstImplementingClassOfSimilar count tmp commonSuperClass s s2 |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
944 |
firstImplementingClass cm msg t check| |
1188 | 945 |
|
946 |
sym := string asSymbolIfInterned. |
|
947 |
sym isNil ifTrue:[^ nil]. |
|
948 |
||
141 | 949 |
" |
950 |
try selectors |
|
951 |
look who implements it |
|
952 |
" |
|
953 |
list := Set new. |
|
2288
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
954 |
listSimilar := Set new. |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
955 |
|
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
956 |
check := |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
957 |
[:sel :mthd :cls | |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
958 |
sel == sym ifTrue:[ |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
959 |
list add:(cls name). |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
960 |
firstImplementingClass isNil ifTrue:[ |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
961 |
firstImplementingClass := cls |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
962 |
] |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
963 |
] ifFalse:[ |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
964 |
(sel startsWith:sym) ifTrue:[ |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
965 |
listSimilar add:sel. |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
966 |
firstImplementingClassOfSimilar isNil ifTrue:[ |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
967 |
firstImplementingClassOfSimilar := cls |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
968 |
] |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
969 |
] |
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
970 |
] |
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
971 |
]. |
2288
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
972 |
|
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
973 |
Smalltalk allClassesDo:[:c| |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
974 |
c methodDictionary keysAndValuesDo:[:sel :mthd | |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
975 |
check value:sel value:mthd value:c |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
976 |
]. |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
977 |
c class methodDictionary keysAndValuesDo:[:sel :mthd | |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
978 |
check value:sel value:mthd value:c class |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
979 |
]. |
141 | 980 |
]. |
981 |
||
835 | 982 |
(aClass canUnderstand:sym) ifTrue:[ |
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
983 |
s2 := ('Instances of ''' , aClass name , ''' respond to #') , sym "allBold" , '.'. |
1184 | 984 |
shortText ifFalse:[ |
985 |
s2 := '\\' , s2 |
|
986 |
, '\- inherited from ' withCRs |
|
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
987 |
, (aClass whichClassIncludesSelector:sym) name "allBold". |
1184 | 988 |
]. |
1761 | 989 |
firstImplementingClass := (aClass whichClassIncludesSelector:sym) |
835 | 990 |
] ifFalse:[ |
991 |
s2 := ''. |
|
992 |
]. |
|
993 |
||
141 | 994 |
count := list size. |
995 |
(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
|
996 |
" |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
997 |
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
|
998 |
list them |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
999 |
" |
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
1000 |
list := list asOrderedCollection sort. |
1185 | 1001 |
shortText ifTrue:[ |
1002 |
tmp := ' is implemented in '. |
|
1003 |
] ifFalse:[ |
|
1004 |
tmp := ' is a selector implemented in '. |
|
1005 |
]. |
|
2191
87e08ab150e2
improved explain (symbol in an array literal)
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
1006 |
s := "'#' ," string allBold. |
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
1007 |
|
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
1008 |
(count == 1) ifTrue:[ |
1183 | 1009 |
(t := list first) isMeta ifTrue:[ |
1010 |
t := 'the ' , t |
|
1011 |
]. |
|
1184 | 1012 |
msg := s , tmp , t , '.'. |
1013 |
shortText ifFalse:[ |
|
1014 |
msg := msg , s2. |
|
1015 |
] |
|
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
1016 |
] ifFalse:[ |
1185 | 1017 |
(count == 2) ifTrue:[ |
1018 |
msg := s , tmp , (list at:1) , ' and ' , (list at:2) , '.'. |
|
1019 |
shortText ifFalse:[ |
|
1020 |
msg := msg , s2. |
|
1021 |
]. |
|
1022 |
] ifFalse:[ |
|
1023 |
shortText ifTrue:[ |
|
1428 | 1024 |
msg := s , tmp , count printString , ' classes'. |
1637 | 1025 |
commonSuperClass := Class commonSuperclassOf:list. |
1428 | 1026 |
(commonSuperClass == Object |
1027 |
and:[commonSuperClass includesSelector:sym]) ifTrue:[ |
|
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
1028 |
msg := msg , ' (including ' , 'Object' "allBold", ')' |
1428 | 1029 |
]. |
1030 |
msg := msg , '.'. |
|
1185 | 1031 |
^ msg |
1032 |
]. |
|
1183 | 1033 |
|
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
1034 |
(count == 3) ifTrue:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
1035 |
msg := s , tmp , ' |
835 | 1036 |
' , (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
|
1037 |
] ifFalse:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
1038 |
(count == 4) ifTrue:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
1039 |
msg := s , tmp , ' |
835 | 1040 |
' , (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
|
1041 |
] ifFalse:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
1042 |
" |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
1043 |
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
|
1044 |
superclass and show it ... |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
1045 |
" |
1637 | 1046 |
commonSuperClass := Behavior commonSuperclassOf:list. |
913 | 1047 |
(commonSuperClass ~~ Object |
1048 |
and:[commonSuperClass ~~ Behavior |
|
1049 |
and:[commonSuperClass ~~ Class |
|
1050 |
and:[commonSuperClass ~~ ClassDescription]]]) ifTrue:[ |
|
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
1051 |
(list includes:commonSuperClass) ifTrue:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
1052 |
msg := s . tmp , count printString , commonSuperClass name |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
1053 |
, ' and redefined in ' , (count - 1) printString |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
1054 |
, ' subclasses' |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
1055 |
, s2. |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
1056 |
firstImplementingClass := commonSuperClass |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
1057 |
] ifFalse:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
1058 |
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
|
1059 |
] |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
1060 |
] ifFalse:[ |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
1061 |
(commonSuperClass == Object |
1249
780b4a1a3967
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1245
diff
changeset
|
1062 |
and:[commonSuperClass includesSelector:sym]) ifTrue:[ |
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
1063 |
msg := s , tmp , count printString , ' classes. |
834 | 1064 |
|
1065 |
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
|
1066 |
since there is an implementation in Object.' , s2. |
141 | 1067 |
|
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
1068 |
firstImplementingClass := Object |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
1069 |
] ifFalse:[ |
913 | 1070 |
((commonSuperClass == Behavior |
1071 |
or:[commonSuperClass == Class |
|
1072 |
or:[commonSuperClass == ClassDescription]]) |
|
1249
780b4a1a3967
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1245
diff
changeset
|
1073 |
and:[commonSuperClass includesSelector:sym]) ifTrue:[ |
913 | 1074 |
msg := s , tmp , count printString , ' classes. |
1075 |
||
1076 |
All classes seem to respond to that message, |
|
1077 |
since there is an implementation in ' , commonSuperClass name , '.' , s2. |
|
1078 |
||
1079 |
firstImplementingClass := commonSuperClass |
|
1080 |
] ifFalse:[ |
|
1081 |
" |
|
1082 |
otherwise just give the number. |
|
1083 |
" |
|
1084 |
msg := s , tmp , count printString , ' classes.' , s2 |
|
1085 |
] |
|
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
1086 |
] |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
1087 |
] |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
1088 |
] |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
1089 |
] |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
1090 |
]. |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
1091 |
]. |
1909 | 1092 |
shortText ifTrue:[ |
1093 |
count == 1 ifTrue:[ |
|
1910 | 1094 |
cm := self fetchCommentOfMethod:(firstImplementingClass compiledMethodAt:sym). |
1095 |
cm notNil ifTrue:[ |
|
1096 |
msg := msg,' ',cm |
|
1097 |
]. |
|
1909 | 1098 |
]. |
1099 |
] ifFalse:[ |
|
1185 | 1100 |
firstImplementingClass notNil ifTrue:[ |
1101 |
WindowGroup activeGroup withWaitCursorDo:[ |
|
1102 |
cm := firstImplementingClass compiledMethodAt:sym. |
|
1103 |
cm notNil ifTrue:[ |
|
1104 |
cm := cm methodComment. |
|
1105 |
] |
|
1106 |
]. |
|
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
1107 |
cm notNil ifTrue:[ |
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1108 |
msg := msg , '\\The comment in ' withCRs |
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1109 |
, firstImplementingClass name "allBold" , ' is:\' withCRs |
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1110 |
, '"' , cm allItalic , '"'. |
911
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
1111 |
] |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
1112 |
]. |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
1113 |
]. |
be6ce6482a7f
extract the methods comment and show it.
Claus Gittinger <cg@exept.de>
parents:
839
diff
changeset
|
1114 |
^ msg |
141 | 1115 |
]. |
1116 |
||
2288
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1117 |
count := listSimilar size. |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1118 |
(count ~~ 0) ifTrue:[ |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1119 |
listSimilar := listSimilar asOrderedCollection sort. |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1120 |
shortText ifTrue:[ |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1121 |
tmp := ' is implemented in '. |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1122 |
] ifFalse:[ |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1123 |
tmp := ' is a selector implemented in '. |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1124 |
]. |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1125 |
|
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1126 |
(count == 1) ifTrue:[ |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1127 |
msg := listSimilar first allBold , tmp , firstImplementingClassOfSimilar name , '.'. |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1128 |
shortText ifFalse:[ |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1129 |
msg := msg , s2. |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1130 |
] |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1131 |
] ifFalse:[ |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1132 |
msg := 'similar selectors: %1, %2' bindWith:listSimilar first allBold with:listSimilar second allBold. |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1133 |
count > 2 ifTrue:[ |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1134 |
msg := msg,'...'. |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1135 |
]. |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1136 |
]. |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1137 |
^ msg |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1138 |
]. |
92c7e16d6916
changed: #explainSelector:inClass:short:
Claus Gittinger <cg@exept.de>
parents:
2287
diff
changeset
|
1139 |
|
141 | 1140 |
^ nil |
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
263
diff
changeset
|
1141 |
|
1909 | 1142 |
"Modified: / 17-06-1996 / 17:09:30 / stefan" |
1143 |
"Created: / 23-03-1999 / 13:29:33 / cg" |
|
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1144 |
"Modified: / 28-02-2012 / 10:49:08 / cg" |
141 | 1145 |
! |
1146 |
||
1183 | 1147 |
explainSelfIn:aClass short:shortText |
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1148 |
"return an explanation" |
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1149 |
|
1244 | 1150 |
|sub subNames selfString className nSubClasses| |
1198 | 1151 |
|
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
1152 |
selfString := '''' , 'self' "allBold" , ''''. |
6 | 1153 |
|
1244 | 1154 |
sub := aClass allSubclasses. |
1155 |
nSubClasses := sub size. |
|
1156 |
||
1157 |
aClass isMeta ifTrue:[ |
|
1158 |
className := aClass theNonMetaclass name. |
|
1159 |
subNames := sub collect:[:c | c theNonMetaclass name]. |
|
1160 |
nSubClasses == 0 ifTrue:[ |
|
1161 |
shortText ifTrue:[ |
|
1162 |
^ selfString , ' - the ''' , className , '''-class.' |
|
1163 |
]. |
|
1164 |
^ selfString , 'refers to the object which received the message. |
|
1165 |
||
1166 |
In this case, it will be the ' , className , '-class itself.' |
|
1167 |
]. |
|
1168 |
||
1169 |
shortText ifTrue:[ |
|
1170 |
nSubClasses == 1 ifTrue:[ |
|
1171 |
^ selfString , ' - the ''' , className , '''- or ''' , subNames first , '''-class.' |
|
1172 |
]. |
|
1173 |
^ selfString , ' - the ''' , className , '''-class or one of its subclasses.' |
|
1174 |
]. |
|
1175 |
nSubClasses <= 5 ifTrue:[ |
|
1176 |
^ selfString , ' refers to the object which received the message. |
|
1177 |
||
1178 |
In this case, it will be the ' , className , '-class |
|
1179 |
or one of its subclasses: |
|
1180 |
||
1181 |
' , subNames asStringCollection asString |
|
1182 |
]. |
|
1183 |
||
1184 |
^ selfString , ' refers to the object which received the message. |
|
1185 |
||
1186 |
In this case, it will be the ' , className , '-class |
|
1187 |
or one of its ' , nSubClasses printString , ' subclasses.' |
|
1188 |
]. |
|
1189 |
||
1256 | 1190 |
subNames := aClass allSubclasses collect:[:c | c theNonMetaclass name]. |
1244 | 1191 |
className := aClass name. |
1192 |
nSubClasses == 0 ifTrue:[ |
|
1183 | 1193 |
shortText ifTrue:[ |
1244 | 1194 |
^ selfString , ' - an instance of ''' , className , '''.' |
1183 | 1195 |
]. |
1198 | 1196 |
^ selfString , 'refers to the object which received the message. |
6 | 1197 |
|
1244 | 1198 |
In this case, it will be an instance of ' , className , '.' |
6 | 1199 |
]. |
1200 |
||
1183 | 1201 |
shortText ifTrue:[ |
1244 | 1202 |
nSubClasses == 1 ifTrue:[ |
1256 | 1203 |
^ selfString , ' - an instance of ''' , className , ''' or ''' , subNames first , '''.' |
1185 | 1204 |
]. |
1244 | 1205 |
^ selfString , ' - an instance of ''' , className , ''' or one of its subclasses.' |
1183 | 1206 |
]. |
1244 | 1207 |
nSubClasses <= 5 ifTrue:[ |
1198 | 1208 |
^ selfString , ' refers to the object which received the message. |
6 | 1209 |
|
1244 | 1210 |
In this case, it will be an instance of ' , className , ' |
6 | 1211 |
or one of its subclasses: |
1212 |
||
1256 | 1213 |
' , subNames asStringCollection asString |
6 | 1214 |
]. |
1215 |
||
1198 | 1216 |
^ selfString , ' refers to the object which received the message. |
6 | 1217 |
|
1244 | 1218 |
In this case, it will be an instance of ' , className , ' |
1219 |
or one of its ' , nSubClasses printString , ' subclasses.' |
|
1926
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
1220 |
|
935dbaeca76f
show class package in explanation
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
1221 |
"Modified: / 09-10-2006 / 12:11:44 / cg" |
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1222 |
"Modified (comment): / 28-02-2012 / 10:47:06 / cg" |
6 | 1223 |
! |
1224 |
||
1188 | 1225 |
explainSuperIn:aClass short:shortText |
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1226 |
"return an explanation" |
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1227 |
|
1352 | 1228 |
|superName| |
1244 | 1229 |
|
1230 |
superName := aClass superclass name. |
|
1188 | 1231 |
|
1232 |
shortText ifTrue:[ |
|
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1233 |
^ '"super" - message lookup starts in superclass "%1" (call redefined method).' bindWith:superName |
1188 | 1234 |
]. |
1235 |
||
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1236 |
^ 'like "self", "','super'allBold,'" refers to the object which received the message. |
6 | 1237 |
|
2828
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1238 |
However, when sending a message to "super", the search for methods |
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1239 |
implementing this message will start in the superclass (' , superName , '), |
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1240 |
instead of the receiver''s class (' , aClass name , ' or subclass). |
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1241 |
Thus, using "super", a redefined method can call the original (redefined) method of its superclass.' |
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1242 |
|
aa93cebd33e4
added: #explainHereIn:short:
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1243 |
"Modified (comment): / 28-02-2012 / 10:47:03 / cg" |
6 | 1244 |
! |
2 | 1245 |
|
49 | 1246 |
explainSyntax:string |
1247 |
"try syntax ...; return explanation or nil" |
|
1248 |
||
1183 | 1249 |
^ self explainSyntax:string short:false |
1250 |
! |
|
1251 |
||
1252 |
explainSyntax:string short:shortText |
|
1253 |
"try syntax ...; return explanation or nil" |
|
1254 |
||
49 | 1255 |
((string = ':=') or:[string = '_']) ifTrue:[ |
1183 | 1256 |
shortText ifTrue:[ |
1257 |
^ 'Assign to variable on the left side.'. |
|
1258 |
]. |
|
1259 |
||
796 | 1260 |
^ '<variable> := <expression> |
49 | 1261 |
|
834 | 1262 |
'':='' and ''_'' (which is left-arrow in some fonts) mean assignment. |
49 | 1263 |
The variable is bound to (i.e. points to) the value of <expression>.' |
1264 |
]. |
|
1265 |
||
1266 |
(string = '^') ifTrue:[ |
|
1183 | 1267 |
shortText ifTrue:[ |
1268 |
^ 'Return value from method.'. |
|
1269 |
]. |
|
796 | 1270 |
^ '^ <expression> |
49 | 1271 |
|
834 | 1272 |
returns the value of <expression> as value from the method. |
49 | 1273 |
A return from within a block exits the method where the block is defined.' |
1274 |
]. |
|
1275 |
||
1276 |
(string = ';') ifTrue:[ |
|
1183 | 1277 |
shortText ifTrue:[ |
1278 |
^ 'Cascade expression.'. |
|
1279 |
]. |
|
796 | 1280 |
^ '<expression> ; selector1 ; .... ; selectorN |
49 | 1281 |
|
1282 |
a cascade expression; evaluate expression, and send messages |
|
1283 |
<selector1> ... <selectorN> to the first expressions receiver. |
|
1284 |
Returns the value of the last send. The cascade sends may also have arguments.' |
|
1285 |
]. |
|
1286 |
||
1287 |
(string = '|') ifTrue:[ |
|
1183 | 1288 |
shortText ifTrue:[ |
1289 |
^ ''. |
|
1290 |
]. |
|
796 | 1291 |
^ '| locals | or: [:arg | statements] |
49 | 1292 |
|
834 | 1293 |
''|'' is used to mark a local variable declaration or separates arguments |
49 | 1294 |
from the statements in a block. Notice, that in a block-argument declaration |
1295 |
these must be prefixed by a colon character. |
|
834 | 1296 |
''|'' is also a selector understood by Booleans.' |
49 | 1297 |
]. |
1298 |
||
2287
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1299 |
(string startsWith:'#' ) ifTrue:[ |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1300 |
(string startsWith:'#(' ) ifTrue:[ |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1301 |
shortText ifTrue:[ |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1302 |
^ 'Array Literal.'. |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1303 |
]. |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1304 |
^ 'is a constant Array. |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1305 |
|
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1306 |
The array-object is created at compilation time and a reference to this is |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1307 |
used at execution time (thus, the same object is referred to every time). |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1308 |
The elements of a constant Array must be numbers, strings, symbols, nil, true or false, |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1309 |
another array constant or a byte-array. |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1310 |
(notice, that not all Smalltalk implementations allow true, false and nil as |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1311 |
constant-Array elements).' |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1312 |
]. |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1313 |
|
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1314 |
(string startsWith:'#[') ifTrue:[ |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1315 |
shortText ifTrue:[ |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1316 |
^ 'ByteArray Literal.'. |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1317 |
]. |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1318 |
^ 'is a constant ByteArray. |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1319 |
|
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1320 |
The elements of a constant ByteArray must be Integer constants in the range |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1321 |
0 .. 255. |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1322 |
(notice, that not all Smalltalk implementations support constant ByteArrays).' |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1323 |
]. |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1324 |
|
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1325 |
(string startsWith:'#''') ifTrue:[ |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1326 |
shortText ifTrue:[ |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1327 |
^ 'Symbol Literal.'. |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1328 |
]. |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1329 |
^ 'is a constant symbol containing non-alphanumeric characters. |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1330 |
|
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1331 |
Symbols are unique strings, meaning that there exists |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1332 |
exactly one instance of a given symbol. Therefore symbols can |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1333 |
be compared using == (identity compare) in addition to = (contents compare). |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1334 |
Beside this, Symbols behave mostly like Strings. |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1335 |
|
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1336 |
Notice, that not all Smalltalk implementations support this kind of symbols.' |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1337 |
]. |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1338 |
|
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1339 |
shortText ifTrue:[ |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1340 |
^ 'Symbol Literal.'. |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1341 |
]. |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1342 |
^ 'is a symbol. |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1343 |
|
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1344 |
Symbols are unique strings, meaning that there exists |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1345 |
exactly one instance of a given symbol. Therefore symbols can |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1346 |
be compared using == (identity compare) in addition to = (contents compare). |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1347 |
Beside this, Symbols behave mostly like Strings.' |
61f5dfccf2c0
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2286
diff
changeset
|
1348 |
]. |
49 | 1349 |
((string startsWith:'(') or:[string endsWith:')']) ifTrue:[ |
1183 | 1350 |
shortText ifTrue:[ |
1351 |
^ ''. |
|
1352 |
]. |
|
796 | 1353 |
^ '(<expression>) |
49 | 1354 |
|
1355 |
expression grouping.' |
|
1356 |
]. |
|
1357 |
||
1358 |
((string startsWith:'[') or:[string endsWith:']']) ifTrue:[ |
|
1183 | 1359 |
shortText ifTrue:[ |
1360 |
^ ''. |
|
1361 |
]. |
|
834 | 1362 |
^ '[:arg1 .. :argN | statements] |
49 | 1363 |
|
1364 |
defines a block. |
|
1365 |
Blocks represent pieces of executable code. Definition of a block does |
|
1366 |
not evaluate it. The block is evaluated by sending it a value/value: |
|
1367 |
message. |
|
1368 |
Blocks are often passed as arguments to Booleans (i.e. ifTrue:[...]) or |
|
1369 |
collections (i.e. do:[...]).' |
|
1370 |
]. |
|
1371 |
||
2286
cabf7db33a38
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2226
diff
changeset
|
1372 |
((string startsWith:'{') or:[string endsWith:'}']) ifTrue:[ |
cabf7db33a38
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2226
diff
changeset
|
1373 |
shortText ifTrue:[ |
cabf7db33a38
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2226
diff
changeset
|
1374 |
^ 'array instantiation'. |
cabf7db33a38
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2226
diff
changeset
|
1375 |
]. |
cabf7db33a38
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2226
diff
changeset
|
1376 |
^ '{ <expr1>. .. <exprN> } |
cabf7db33a38
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2226
diff
changeset
|
1377 |
|
cabf7db33a38
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2226
diff
changeset
|
1378 |
is syntactic sugar for "Array with:<expr1> .. with:<exprN>". |
cabf7db33a38
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2226
diff
changeset
|
1379 |
A new array is created with N elements initialized from the N expressions. |
cabf7db33a38
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2226
diff
changeset
|
1380 |
The expressions are separated by a period statement separator. |
cabf7db33a38
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2226
diff
changeset
|
1381 |
The expressions are evaluated at execution time, and a new array is always created |
cabf7db33a38
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2226
diff
changeset
|
1382 |
when executed (as opposed to an array literal, which is computed only once at |
cabf7db33a38
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2226
diff
changeset
|
1383 |
compilation time) and which is shared.' |
cabf7db33a38
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2226
diff
changeset
|
1384 |
]. |
cabf7db33a38
changed: #explainSyntax:short:
Claus Gittinger <cg@exept.de>
parents:
2226
diff
changeset
|
1385 |
|
49 | 1386 |
(string = ':') ifTrue:[ |
1183 | 1387 |
shortText ifTrue:[ |
1388 |
^ ''. |
|
1389 |
]. |
|
796 | 1390 |
^ 'colons have different meaning depending on context: |
49 | 1391 |
|
1392 |
1) they separate keyword-parts in symbols and keyword-messages as in: |
|
1393 |
||
1394 |
#at:put: a constant keyword symbol |
|
1395 |
||
1396 |
rec at:index put:value sends the #at:put: message to rec, |
|
796 | 1397 |
passing index and value as arguments. |
49 | 1398 |
|
1399 |
2) within block-argument declarations as in: |
|
1400 |
||
1401 |
[:arg1 :arg2 | statements] |
|
834 | 1402 |
|
1403 |
3) within an identifier, they separate the nameSpace part from |
|
1404 |
the name part; as in: |
|
1405 |
||
1406 |
Smalltalk::Array - the Array class in the Smalltalk nameSpace. |
|
1407 |
Foo::Array - the Array class in the Foo nameSpace. |
|
49 | 1408 |
' |
1409 |
]. |
|
1410 |
||
1411 |
(string = '.') ifTrue:[ |
|
796 | 1412 |
^ 'statement. "<- period here" |
49 | 1413 |
statement |
1414 |
||
1415 |
within a method or block, individual statements are separated by periods. |
|
1416 |
' |
|
1417 |
]. |
|
1418 |
||
1419 |
"/ is it a symbol without hash-character ? |
|
1420 |
"/ |
|
796 | 1421 |
"/ string knownAsSymbol ifTrue:[ |
1422 |
"/ ^ 'is nothing, but #' , string , ' is known as a symbol. |
|
1423 |
"/ |
|
1424 |
"/Symbols are unique strings, meaning that there exists |
|
1425 |
"/exactly one instance of a given symbol. Therefore symbols can |
|
1426 |
"/be compared using == (identity compare) in addition to = (contents compare). |
|
1427 |
"/Beside this, Symbols behave mostly like Strings.' |
|
1428 |
"/ ]. |
|
49 | 1429 |
|
1430 |
^ nil |
|
796 | 1431 |
|
1432 |
"Modified: / 31.10.1998 / 14:28:58 / cg" |
|
2214 | 1433 |
! |
1434 |
||
1435 |
valueStringFor:aValue |
|
1436 |
|valString| |
|
1437 |
||
1438 |
"/ only show the value, if it is really short... |
|
2899
8b8701a65441
Avoid #isKindOf: where possible
Stefan Vogel <sv@exept.de>
parents:
2828
diff
changeset
|
1439 |
(aValue isBoolean |
8b8701a65441
Avoid #isKindOf: where possible
Stefan Vogel <sv@exept.de>
parents:
2828
diff
changeset
|
1440 |
or:[aValue isNil |
8b8701a65441
Avoid #isKindOf: where possible
Stefan Vogel <sv@exept.de>
parents:
2828
diff
changeset
|
1441 |
or:[aValue isString |
8b8701a65441
Avoid #isKindOf: where possible
Stefan Vogel <sv@exept.de>
parents:
2828
diff
changeset
|
1442 |
or:[aValue isNumber |
8b8701a65441
Avoid #isKindOf: where possible
Stefan Vogel <sv@exept.de>
parents:
2828
diff
changeset
|
1443 |
or:[aValue isPoint |
8b8701a65441
Avoid #isKindOf: where possible
Stefan Vogel <sv@exept.de>
parents:
2828
diff
changeset
|
1444 |
]]]]) ifTrue:[ |
2226 | 1445 |
^ aValue storeString. |
1446 |
]. |
|
2427 | 1447 |
|
2226 | 1448 |
(aValue isColor) ifTrue:[ |
1449 |
^ 'Color: ',(' ' emphasizeAllWith:(#backgroundColor->aValue)). |
|
1450 |
]. |
|
1451 |
||
2427 | 1452 |
((aValue isKindOf:GUID) |
2899
8b8701a65441
Avoid #isKindOf: where possible
Stefan Vogel <sv@exept.de>
parents:
2828
diff
changeset
|
1453 |
or:[aValue isUUID]) ifTrue:[ |
2427 | 1454 |
valString := aValue printString. |
1455 |
]. |
|
1456 |
||
2214 | 1457 |
(valString isEmptyOrNil |
2899
8b8701a65441
Avoid #isKindOf: where possible
Stefan Vogel <sv@exept.de>
parents:
2828
diff
changeset
|
1458 |
or:[ valString size > 50 |
8b8701a65441
Avoid #isKindOf: where possible
Stefan Vogel <sv@exept.de>
parents:
2828
diff
changeset
|
1459 |
or:[ valString includes:Character cr ]]) ifTrue:[ |
2214 | 1460 |
valString := aValue classNameWithArticle. |
1461 |
]. |
|
1462 |
||
1463 |
^ valString |
|
2427 | 1464 |
|
1465 |
"Modified: / 14-10-2010 / 11:57:52 / cg" |
|
141 | 1466 |
! ! |
49 | 1467 |
|
396 | 1468 |
!Explainer class methodsFor:'documentation'! |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
1469 |
|
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
1470 |
version |
3156
b09c18add94f
Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents:
3111
diff
changeset
|
1471 |
^ '$Header: /cvs/stx/stx/libcomp/Explainer.st,v 1.122 2013-04-25 13:11:50 stefan Exp $' |
2214 | 1472 |
! |
1473 |
||
1474 |
version_CVS |
|
3156
b09c18add94f
Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents:
3111
diff
changeset
|
1475 |
^ '$Header: /cvs/stx/stx/libcomp/Explainer.st,v 1.122 2013-04-25 13:11:50 stefan Exp $' |
146
3d407ab8ac44
suppress messages on transcript when explaining
Claus Gittinger <cg@exept.de>
parents:
141
diff
changeset
|
1476 |
! ! |
3047 | 1477 |