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