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