author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Tue, 29 Jan 2013 14:40:26 +0000 | |
branch | jv |
changeset 3121 | 19723298dd2c |
parent 3042 | 48e76977cdc3 |
child 3128 | 87750af738dc |
permissions | -rw-r--r-- |
20 | 1 |
" |
2 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
249 | 3 |
All Rights Reserved |
20 | 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 |
" |
|
975 | 12 |
"{ Package: 'stx:libbasic3' }" |
13 |
||
27 | 14 |
Object subclass:#ClassOrganizer |
593 | 15 |
instanceVariableNames:'globalComment categoryArray categoryStops elementArray class |
16 |
categories' |
|
249 | 17 |
classVariableNames:'' |
18 |
poolDictionaries:'' |
|
19 |
category:'Kernel-Support' |
|
20 | 20 |
! |
21 |
||
27 | 22 |
!ClassOrganizer class methodsFor:'documentation'! |
20 | 23 |
|
24 |
copyright |
|
25 |
" |
|
26 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
27 |
All Rights Reserved |
|
28 |
||
29 |
This software is furnished under a license and may be used |
|
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
37 |
||
38 |
documentation |
|
39 |
" |
|
40 |
in contrast to other smalltalks, ST/X does not keep the |
|
41 |
method <-> category associations in the class (as organization), |
|
249 | 42 |
but instead keeps the category as an instance variable of methods. |
20 | 43 |
|
44 |
For compatibility with (fileOut-) files which include a class organization |
|
27 | 45 |
message, 'aClass organization' returns an instance of this class, which |
20 | 46 |
implements the category change functionality. |
249 | 47 |
Also, some PD code seems to use & define methods for ClassOrganizers |
48 |
- having this (somewhat dummy) class around helps to fileIn that code. |
|
27 | 49 |
|
249 | 50 |
Notice, that instances of ClassOrganizer are NOT used in the current ST/X |
51 |
system; all of this is pure compatibility mimicri. |
|
52 |
||
593 | 53 |
|
54 |
This is an additional goody class; therefore: |
|
55 |
||
56 |
THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTOR ``AS IS'' AND |
|
57 |
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
58 |
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
59 |
ARE DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTOR BE LIABLE |
|
60 |
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
|
61 |
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
|
62 |
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
|
63 |
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
64 |
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
|
65 |
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
|
66 |
SUCH DAMAGE. |
|
67 |
||
249 | 68 |
[author:] |
69 |
Claus Gittinger |
|
20 | 70 |
" |
71 |
! ! |
|
72 |
||
27 | 73 |
!ClassOrganizer class methodsFor:'instance creation'! |
20 | 74 |
|
75 |
for:aClass |
|
76 |
"create & return a new instance of myself, to organize aClass" |
|
77 |
||
1086 | 78 |
^ super new class:aClass |
79 |
||
80 |
"Modified: / 31.10.2001 / 08:58:49 / cg" |
|
20 | 81 |
! ! |
82 |
||
914 | 83 |
!ClassOrganizer class methodsFor:'defaults'! |
84 |
||
85 |
defaultProtocol |
|
86 |
^ 'as yet unspecified' |
|
87 |
! ! |
|
88 |
||
3012 | 89 |
|
249 | 90 |
!ClassOrganizer methodsFor:'accessing'! |
91 |
||
658 | 92 |
addCategory:aCategory |
93 |
"ignored." |
|
94 |
||
95 |
||
96 |
" |
|
97 |
Number organization addCategory:'foo'. |
|
98 |
" |
|
99 |
||
100 |
"Created: / 17.4.1998 / 14:42:16 / cg" |
|
101 |
! |
|
102 |
||
975 | 103 |
addCategory:aCategory before:symbolOrNil |
104 |
"ignored." |
|
105 |
! |
|
106 |
||
249 | 107 |
categories |
108 |
"return a collection of my classes method-categorySymbols" |
|
27 | 109 |
|
249 | 110 |
|set| |
111 |
||
687
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
112 |
categoryArray isNil ifTrue:[ |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
113 |
set := IdentitySet new. |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
114 |
class methodDictionary keysAndValuesDo:[:sel :m | |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
115 |
set add:m category |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
116 |
]. |
975 | 117 |
categoryArray := set asArray sort |
249 | 118 |
]. |
687
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
119 |
^ categoryArray |
27 | 120 |
|
121 |
" |
|
249 | 122 |
SmallInteger organization categories |
27 | 123 |
" |
592 | 124 |
|
687
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
125 |
"Modified: / 20.6.1998 / 12:26:49 / cg" |
27 | 126 |
! |
127 |
||
128 |
categoryOfElement:aSelectorSymbol |
|
249 | 129 |
"return the category for the method specified by aSelectorSymbol. |
130 |
Return nil, if there is no such method." |
|
131 |
||
27 | 132 |
|m| |
133 |
||
134 |
m := class compiledMethodAt:aSelectorSymbol. |
|
135 |
m isNil ifTrue:[^ nil]. |
|
136 |
^ m category |
|
137 |
||
138 |
" |
|
139 |
Number organization categoryOfElement:#foo. |
|
140 |
Object organization categoryOfElement:#== |
|
141 |
" |
|
142 |
! |
|
143 |
||
249 | 144 |
classComment |
145 |
"return the classes comment" |
|
146 |
||
147 |
^ class comment |
|
148 |
||
149 |
" |
|
150 |
Number organization classComment |
|
151 |
" |
|
152 |
! |
|
153 |
||
631 | 154 |
elements |
155 |
"return a collection of my classes selectors" |
|
156 |
||
157 |
|set| |
|
158 |
||
687
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
159 |
elementArray isNil ifTrue:[ |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
160 |
set := IdentitySet new. |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
161 |
class methodDictionary keysAndValuesDo:[:sel :m | |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
162 |
set add:sel |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
163 |
]. |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
164 |
elementArray := set asArray |
631 | 165 |
]. |
687
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
166 |
^ elementArray |
631 | 167 |
|
168 |
" |
|
169 |
SmallInteger organization elements |
|
170 |
" |
|
171 |
||
687
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
172 |
"Modified: / 20.6.1998 / 12:27:23 / cg" |
631 | 173 |
! |
174 |
||
27 | 175 |
listAtCategoryNamed:aCategorySymbol |
176 |
"return a collection of selectors whose methods are categorized |
|
177 |
as aCategorySymbol" |
|
178 |
||
179 |
|list| |
|
180 |
||
181 |
list := OrderedCollection new. |
|
556 | 182 |
class methodDictionary keysAndValuesDo:[:sel :mthd | |
183 |
mthd category == aCategorySymbol ifTrue:[list add:sel] |
|
27 | 184 |
]. |
903 | 185 |
^ list asOrderedCollection |
27 | 186 |
|
187 |
" |
|
188 |
SmallInteger organization listAtCategoryNamed:#arithmetic |
|
189 |
" |
|
900 | 190 |
! |
191 |
||
192 |
removeCategory:aCategory |
|
193 |
"remove a categories assignments - dummy here " |
|
194 |
||
195 |
"Modified: / 3.2.2000 / 23:49:27 / cg" |
|
249 | 196 |
! ! |
27 | 197 |
|
687
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
198 |
!ClassOrganizer methodsFor:'change & update'! |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
199 |
|
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
200 |
update:something with:parameter from:changedObject |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
201 |
changedObject == class ifTrue:[ |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
202 |
something == #methodTrap ifFalse:[ |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
203 |
categoryArray := elementArray := categories := nil |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
204 |
] |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
205 |
]. |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
206 |
|
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
207 |
"Created: / 20.6.1998 / 12:28:37 / cg" |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
208 |
"Modified: / 20.6.1998 / 12:30:14 / cg" |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
209 |
! ! |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
210 |
|
249 | 211 |
!ClassOrganizer methodsFor:'changing'! |
27 | 212 |
|
249 | 213 |
changeFromString:organizationString |
214 |
"take category<->selector associations from aString, and change |
|
215 |
the categories of those methods. |
|
216 |
Only required when filing in ST-80 code, which changes the categorization |
|
217 |
this way." |
|
27 | 218 |
|
249 | 219 |
|a category m| |
27 | 220 |
|
221 |
" |
|
249 | 222 |
(mis(use) parser for the scanning |
223 |
" |
|
224 |
a := Compiler evaluate:'#(' , organizationString , ')'. |
|
225 |
(a isMemberOf:Array) ifFalse:[^ self error:'malformed argument']. |
|
226 |
a do:[:row | |
|
227 |
category := row at:1. |
|
228 |
2 to:row size do:[:idx | |
|
229 |
|selector| |
|
230 |
||
231 |
selector := row at:idx. |
|
232 |
m := class compiledMethodAt:selector. |
|
233 |
m isNil ifTrue:[ |
|
258 | 234 |
Transcript showCR:'no method for ' , selector , ' in ', class name |
249 | 235 |
] ifFalse:[ |
236 |
m category:category. |
|
237 |
] |
|
238 |
] |
|
239 |
]. |
|
240 |
||
241 |
" |
|
242 |
TestClass |
|
243 |
organization |
|
244 |
changeFromString:'( ''category1'' #foo1 #foo2 foo3) |
|
245 |
( ''category2'' #bar1 #bar2)' |
|
27 | 246 |
" |
593 | 247 |
! |
248 |
||
249 |
classify:aSelector under:aCategory |
|
250 |
"change the category of the method stored under aSelector |
|
251 |
to aCategory." |
|
252 |
||
253 |
|m list| |
|
254 |
||
255 |
class isNil ifTrue:[ |
|
256 |
"/ sigh used without a class ... |
|
257 |
categories isNil ifTrue:[ |
|
258 |
categories := Dictionary new. |
|
259 |
]. |
|
260 |
list := categories at:aCategory ifAbsent:nil. |
|
261 |
list isNil ifTrue:[ |
|
262 |
list := OrderedCollection new. |
|
263 |
categories at:aCategory put:list. |
|
264 |
]. |
|
265 |
list add:aSelector. |
|
266 |
^ self. |
|
267 |
]. |
|
268 |
||
269 |
m := class compiledMethodAt:aSelector. |
|
270 |
m notNil ifTrue:[ |
|
271 |
m category:aCategory |
|
272 |
]. |
|
273 |
||
274 |
"Created: 20.6.1997 / 18:01:18 / cg" |
|
275 |
"Modified: 20.6.1997 / 18:09:37 / cg" |
|
27 | 276 |
! ! |
277 |
||
278 |
!ClassOrganizer methodsFor:'printing & storing'! |
|
279 |
||
280 |
printOn:aStream |
|
281 |
|coll| |
|
282 |
||
593 | 283 |
class notNil ifTrue:[ |
284 |
coll := IdentityDictionary new. |
|
285 |
class methodDictionary keysAndValuesDo:[:sel :mthd | |
|
286 |
|cat list| |
|
27 | 287 |
|
593 | 288 |
cat := mthd category. |
289 |
list := coll at:cat ifAbsent:[]. |
|
290 |
list isNil ifTrue:[ |
|
291 |
coll at:cat put:(list := OrderedCollection new). |
|
292 |
]. |
|
293 |
list add:sel |
|
556 | 294 |
]. |
593 | 295 |
] ifFalse:[ |
296 |
coll := categories |
|
27 | 297 |
]. |
1086 | 298 |
coll notNil ifTrue:[ |
299 |
coll keysAndValuesDo:[:category :list | |
|
300 |
aStream nextPut:$(. |
|
301 |
aStream nextPutAll:category asString storeString. |
|
302 |
list do:[:selector | |
|
303 |
aStream space. |
|
304 |
selector storeOn:aStream |
|
305 |
]. |
|
306 |
aStream nextPut:$). |
|
307 |
aStream cr |
|
308 |
] |
|
27 | 309 |
] |
310 |
||
311 |
" |
|
312 |
Number organization printString |
|
313 |
" |
|
593 | 314 |
|
1086 | 315 |
"Modified: / 30.10.2001 / 17:58:50 / cg" |
27 | 316 |
! ! |
317 |
||
318 |
!ClassOrganizer methodsFor:'private access'! |
|
20 | 319 |
|
320 |
class:aClass |
|
321 |
"set the class" |
|
322 |
||
687
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
323 |
class := aClass. |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
324 |
aClass addDependent:self. |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
325 |
|
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
326 |
" |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
327 |
ClassOrganizer organization |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
328 |
" |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
329 |
|
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
330 |
"Modified: / 20.6.1998 / 12:29:16 / cg" |
20 | 331 |
! ! |
332 |
||
249 | 333 |
!ClassOrganizer class methodsFor:'documentation'! |
20 | 334 |
|
249 | 335 |
version |
3121
19723298dd2c
Bugfix: reading of Java class extensions methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3042
diff
changeset
|
336 |
^ '$Header: ClassOrganizer.st 1909 2012-03-31 00:14:49Z vranyj1 $' |
19723298dd2c
Bugfix: reading of Java class extensions methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3042
diff
changeset
|
337 |
! |
19723298dd2c
Bugfix: reading of Java class extensions methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3042
diff
changeset
|
338 |
|
19723298dd2c
Bugfix: reading of Java class extensions methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3042
diff
changeset
|
339 |
version_HG |
19723298dd2c
Bugfix: reading of Java class extensions methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3042
diff
changeset
|
340 |
|
19723298dd2c
Bugfix: reading of Java class extensions methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3042
diff
changeset
|
341 |
^ '$Changeset: <not expanded> $' |
3012 | 342 |
! |
343 |
||
344 |
version_SVN |
|
3121
19723298dd2c
Bugfix: reading of Java class extensions methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3042
diff
changeset
|
345 |
^ '§Id: ClassOrganizer.st 1909 2012-03-31 00:14:49Z vranyj1 §' |
3012 | 346 |
! ! |
3121
19723298dd2c
Bugfix: reading of Java class extensions methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3042
diff
changeset
|
347 |