author | Claus Gittinger <cg@exept.de> |
Sat, 11 Nov 1995 16:20:50 +0100 | |
changeset 68 | 5f7ac0b5c903 |
parent 39 | e36b38a77856 |
child 249 | ea8e2098fa29 |
permissions | -rw-r--r-- |
20 | 1 |
" |
2 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
3 |
All Rights Reserved |
|
4 |
||
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
27 | 13 |
Object subclass:#ClassOrganizer |
14 |
instanceVariableNames:'globalComment categoryArray categoryStops elementArray class' |
|
20 | 15 |
classVariableNames:'' |
16 |
poolDictionaries:'' |
|
27 | 17 |
category:'Kernel-Support' |
20 | 18 |
! |
19 |
||
27 | 20 |
!ClassOrganizer class methodsFor:'documentation'! |
20 | 21 |
|
22 |
copyright |
|
23 |
" |
|
24 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
25 |
All Rights Reserved |
|
26 |
||
27 |
This software is furnished under a license and may be used |
|
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
35 |
||
36 |
version |
|
68
5f7ac0b5c903
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
39
diff
changeset
|
37 |
^ '$Header: /cvs/stx/stx/libbasic3/ClassOrganizer.st,v 1.6 1995-11-11 15:20:28 cg Exp $' |
20 | 38 |
! |
39 |
||
40 |
documentation |
|
41 |
" |
|
42 |
in contrast to other smalltalks, ST/X does not keep the |
|
43 |
method <-> category associations in the class (as organization), |
|
44 |
but instead keeps the category as an instance variable of method. |
|
45 |
||
46 |
For compatibility with (fileOut-) files which include a class organization |
|
27 | 47 |
message, 'aClass organization' returns an instance of this class, which |
20 | 48 |
implements the category change functionality. |
27 | 49 |
Also, some PD code seems to use & define methods for ClassOrganizers - having this |
50 |
(somewhat dummy) around helps to fileIn that code. |
|
51 |
||
52 |
Notice, that instances of ClassOrganizer are not used in the current ST/X |
|
53 |
system; all is pure mimicri. |
|
54 |
This may change in future versions. |
|
20 | 55 |
" |
56 |
! ! |
|
57 |
||
27 | 58 |
!ClassOrganizer class methodsFor:'instance creation'! |
20 | 59 |
|
60 |
for:aClass |
|
61 |
"create & return a new instance of myself, to organize aClass" |
|
62 |
||
63 |
^ self new class:aClass |
|
64 |
! ! |
|
65 |
||
27 | 66 |
!ClassOrganizer methodsFor:'accessing'! |
67 |
||
68 |
classComment |
|
69 |
^ class comment |
|
70 |
||
71 |
" |
|
72 |
Number organization classComment |
|
73 |
" |
|
74 |
! |
|
75 |
||
76 |
categoryOfElement:aSelectorSymbol |
|
77 |
|m| |
|
78 |
||
79 |
m := class compiledMethodAt:aSelectorSymbol. |
|
80 |
m isNil ifTrue:[^ nil]. |
|
81 |
^ m category |
|
82 |
||
83 |
" |
|
84 |
Number organization categoryOfElement:#foo. |
|
85 |
Object organization categoryOfElement:#== |
|
86 |
" |
|
87 |
! |
|
88 |
||
89 |
listAtCategoryNamed:aCategorySymbol |
|
90 |
"return a collection of selectors whose methods are categorized |
|
91 |
as aCategorySymbol" |
|
92 |
||
93 |
|list| |
|
94 |
||
95 |
list := OrderedCollection new. |
|
96 |
class methodArray with:class selectorArray do:[:m :s | |
|
97 |
m category == aCategorySymbol ifTrue:[list add:s] |
|
98 |
]. |
|
99 |
^ list asArray |
|
100 |
||
101 |
" |
|
102 |
SmallInteger organization listAtCategoryNamed:#arithmetic |
|
103 |
" |
|
104 |
! |
|
105 |
||
106 |
categories |
|
107 |
"return a collection of categorySymbols" |
|
108 |
||
109 |
|set| |
|
110 |
||
111 |
set := IdentitySet new. |
|
112 |
class methodArray do:[:m | |
|
113 |
set add:m category |
|
114 |
]. |
|
115 |
^ set asArray |
|
116 |
||
117 |
" |
|
118 |
SmallInteger organization categories |
|
119 |
" |
|
120 |
! ! |
|
121 |
||
122 |
!ClassOrganizer methodsFor:'printing & storing'! |
|
123 |
||
124 |
printOn:aStream |
|
125 |
|coll| |
|
126 |
||
127 |
coll := IdentityDictionary new. |
|
128 |
class methodArray with:class selectorArray do:[:m :s | |
|
129 |
|cat list| |
|
130 |
||
131 |
cat := m category. |
|
132 |
list := coll at:cat ifAbsent:[]. |
|
133 |
list isNil ifTrue:[ |
|
134 |
coll at:cat put:(list := OrderedCollection new). |
|
135 |
]. |
|
136 |
list add:s |
|
137 |
]. |
|
138 |
coll keysAndValuesDo:[:category :list | |
|
139 |
aStream nextPut:$(. |
|
140 |
aStream nextPutAll:category asString storeString. |
|
141 |
list do:[:selector | |
|
142 |
aStream space. |
|
143 |
selector storeOn:aStream |
|
144 |
]. |
|
145 |
aStream nextPut:$). |
|
146 |
aStream cr |
|
147 |
] |
|
148 |
||
149 |
" |
|
150 |
Number organization printString |
|
151 |
" |
|
152 |
! ! |
|
153 |
||
154 |
!ClassOrganizer methodsFor:'private access'! |
|
20 | 155 |
|
156 |
class:aClass |
|
157 |
"set the class" |
|
158 |
||
159 |
class := aClass |
|
160 |
! ! |
|
161 |
||
27 | 162 |
!ClassOrganizer methodsFor:'changing'! |
20 | 163 |
|
164 |
changeFromString:organizationString |
|
165 |
"take category<->selector associations from aString, and change |
|
166 |
the categories of those methods. Only required when filing in |
|
167 |
ST-80 code." |
|
168 |
||
33 | 169 |
|a category m| |
20 | 170 |
|
171 |
" |
|
172 |
(mis(use) parser for the scanning |
|
173 |
" |
|
174 |
a := Compiler evaluate:'#(' , organizationString , ')'. |
|
175 |
(a isMemberOf:Array) ifFalse:[^ self error:'malformed argument']. |
|
176 |
a do:[:row | |
|
177 |
category := row at:1. |
|
178 |
2 to:row size do:[:idx | |
|
179 |
|selector| |
|
180 |
||
181 |
selector := row at:idx. |
|
182 |
m := class compiledMethodAt:selector. |
|
183 |
m isNil ifTrue:[ |
|
184 |
Transcript showCr:'no method for ' , selector , ' in ', class name |
|
185 |
] ifFalse:[ |
|
186 |
m category:category. |
|
187 |
] |
|
188 |
] |
|
189 |
]. |
|
190 |
class changed:#organization |
|
191 |
||
192 |
" |
|
193 |
TestClass organization changeFromString:'( ''category1'' #foo1 #foo2 foo3) |
|
194 |
( ''category2'' #bar1 #bar2)' |
|
195 |
" |
|
196 |
! ! |