author | Claus Gittinger <cg@exept.de> |
Mon, 07 Feb 2000 17:07:34 +0100 | |
changeset 903 | 2319988d0b9f |
parent 900 | 318651783940 |
child 914 | 8b9e00e7a4ba |
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 |
||
249 | 80 |
!ClassOrganizer methodsFor:'accessing'! |
81 |
||
658 | 82 |
addCategory:aCategory |
83 |
"ignored." |
|
84 |
||
85 |
||
86 |
" |
|
87 |
Number organization addCategory:'foo'. |
|
88 |
" |
|
89 |
||
90 |
"Created: / 17.4.1998 / 14:42:16 / cg" |
|
91 |
! |
|
92 |
||
249 | 93 |
categories |
94 |
"return a collection of my classes method-categorySymbols" |
|
27 | 95 |
|
249 | 96 |
|set| |
97 |
||
687
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
98 |
categoryArray isNil ifTrue:[ |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
99 |
set := IdentitySet new. |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
100 |
class methodDictionary keysAndValuesDo:[:sel :m | |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
101 |
set add:m category |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
102 |
]. |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
103 |
categoryArray := set asArray |
249 | 104 |
]. |
687
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
105 |
^ categoryArray |
27 | 106 |
|
107 |
" |
|
249 | 108 |
SmallInteger organization categories |
27 | 109 |
" |
592 | 110 |
|
687
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
111 |
"Modified: / 20.6.1998 / 12:26:49 / cg" |
27 | 112 |
! |
113 |
||
114 |
categoryOfElement:aSelectorSymbol |
|
249 | 115 |
"return the category for the method specified by aSelectorSymbol. |
116 |
Return nil, if there is no such method." |
|
117 |
||
27 | 118 |
|m| |
119 |
||
120 |
m := class compiledMethodAt:aSelectorSymbol. |
|
121 |
m isNil ifTrue:[^ nil]. |
|
122 |
^ m category |
|
123 |
||
124 |
" |
|
125 |
Number organization categoryOfElement:#foo. |
|
126 |
Object organization categoryOfElement:#== |
|
127 |
" |
|
128 |
! |
|
129 |
||
249 | 130 |
classComment |
131 |
"return the classes comment" |
|
132 |
||
133 |
^ class comment |
|
134 |
||
135 |
" |
|
136 |
Number organization classComment |
|
137 |
" |
|
138 |
! |
|
139 |
||
631 | 140 |
elements |
141 |
"return a collection of my classes selectors" |
|
142 |
||
143 |
|set| |
|
144 |
||
687
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
145 |
elementArray isNil ifTrue:[ |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
146 |
set := IdentitySet new. |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
147 |
class methodDictionary keysAndValuesDo:[:sel :m | |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
148 |
set add:sel |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
149 |
]. |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
150 |
elementArray := set asArray |
631 | 151 |
]. |
687
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
152 |
^ elementArray |
631 | 153 |
|
154 |
" |
|
155 |
SmallInteger organization elements |
|
156 |
" |
|
157 |
||
687
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
158 |
"Modified: / 20.6.1998 / 12:27:23 / cg" |
631 | 159 |
! |
160 |
||
27 | 161 |
listAtCategoryNamed:aCategorySymbol |
162 |
"return a collection of selectors whose methods are categorized |
|
163 |
as aCategorySymbol" |
|
164 |
||
165 |
|list| |
|
166 |
||
167 |
list := OrderedCollection new. |
|
556 | 168 |
class methodDictionary keysAndValuesDo:[:sel :mthd | |
169 |
mthd category == aCategorySymbol ifTrue:[list add:sel] |
|
27 | 170 |
]. |
903 | 171 |
^ list asOrderedCollection |
27 | 172 |
|
173 |
" |
|
174 |
SmallInteger organization listAtCategoryNamed:#arithmetic |
|
175 |
" |
|
900 | 176 |
! |
177 |
||
178 |
removeCategory:aCategory |
|
179 |
"remove a categories assignments - dummy here " |
|
180 |
||
181 |
"Modified: / 3.2.2000 / 23:49:27 / cg" |
|
249 | 182 |
! ! |
27 | 183 |
|
687
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
184 |
!ClassOrganizer methodsFor:'change & update'! |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
185 |
|
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
186 |
update:something with:parameter from:changedObject |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
187 |
changedObject == class ifTrue:[ |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
188 |
something == #methodTrap ifFalse:[ |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
189 |
categoryArray := elementArray := categories := nil |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
190 |
] |
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 |
|
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
193 |
"Created: / 20.6.1998 / 12:28:37 / cg" |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
194 |
"Modified: / 20.6.1998 / 12:30:14 / cg" |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
195 |
! ! |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
196 |
|
249 | 197 |
!ClassOrganizer methodsFor:'changing'! |
27 | 198 |
|
249 | 199 |
changeFromString:organizationString |
200 |
"take category<->selector associations from aString, and change |
|
201 |
the categories of those methods. |
|
202 |
Only required when filing in ST-80 code, which changes the categorization |
|
203 |
this way." |
|
27 | 204 |
|
249 | 205 |
|a category m| |
27 | 206 |
|
207 |
" |
|
249 | 208 |
(mis(use) parser for the scanning |
209 |
" |
|
210 |
a := Compiler evaluate:'#(' , organizationString , ')'. |
|
211 |
(a isMemberOf:Array) ifFalse:[^ self error:'malformed argument']. |
|
212 |
a do:[:row | |
|
213 |
category := row at:1. |
|
214 |
2 to:row size do:[:idx | |
|
215 |
|selector| |
|
216 |
||
217 |
selector := row at:idx. |
|
218 |
m := class compiledMethodAt:selector. |
|
219 |
m isNil ifTrue:[ |
|
258 | 220 |
Transcript showCR:'no method for ' , selector , ' in ', class name |
249 | 221 |
] ifFalse:[ |
222 |
m category:category. |
|
223 |
] |
|
224 |
] |
|
225 |
]. |
|
226 |
class changed:#organization |
|
227 |
||
228 |
" |
|
229 |
TestClass |
|
230 |
organization |
|
231 |
changeFromString:'( ''category1'' #foo1 #foo2 foo3) |
|
232 |
( ''category2'' #bar1 #bar2)' |
|
27 | 233 |
" |
593 | 234 |
! |
235 |
||
236 |
classify:aSelector under:aCategory |
|
237 |
"change the category of the method stored under aSelector |
|
238 |
to aCategory." |
|
239 |
||
240 |
|m list| |
|
241 |
||
242 |
class isNil ifTrue:[ |
|
243 |
"/ sigh used without a class ... |
|
244 |
categories isNil ifTrue:[ |
|
245 |
categories := Dictionary new. |
|
246 |
]. |
|
247 |
list := categories at:aCategory ifAbsent:nil. |
|
248 |
list isNil ifTrue:[ |
|
249 |
list := OrderedCollection new. |
|
250 |
categories at:aCategory put:list. |
|
251 |
]. |
|
252 |
list add:aSelector. |
|
253 |
^ self. |
|
254 |
]. |
|
255 |
||
256 |
m := class compiledMethodAt:aSelector. |
|
257 |
m notNil ifTrue:[ |
|
258 |
m category:aCategory |
|
259 |
]. |
|
260 |
class changed:#organization |
|
261 |
||
262 |
"Created: 20.6.1997 / 18:01:18 / cg" |
|
263 |
"Modified: 20.6.1997 / 18:09:37 / cg" |
|
27 | 264 |
! ! |
265 |
||
266 |
!ClassOrganizer methodsFor:'printing & storing'! |
|
267 |
||
268 |
printOn:aStream |
|
269 |
|coll| |
|
270 |
||
593 | 271 |
class notNil ifTrue:[ |
272 |
coll := IdentityDictionary new. |
|
273 |
class methodDictionary keysAndValuesDo:[:sel :mthd | |
|
274 |
|cat list| |
|
27 | 275 |
|
593 | 276 |
cat := mthd category. |
277 |
list := coll at:cat ifAbsent:[]. |
|
278 |
list isNil ifTrue:[ |
|
279 |
coll at:cat put:(list := OrderedCollection new). |
|
280 |
]. |
|
281 |
list add:sel |
|
556 | 282 |
]. |
593 | 283 |
] ifFalse:[ |
284 |
coll := categories |
|
27 | 285 |
]. |
286 |
coll keysAndValuesDo:[:category :list | |
|
556 | 287 |
aStream nextPut:$(. |
288 |
aStream nextPutAll:category asString storeString. |
|
289 |
list do:[:selector | |
|
290 |
aStream space. |
|
291 |
selector storeOn:aStream |
|
292 |
]. |
|
293 |
aStream nextPut:$). |
|
294 |
aStream cr |
|
27 | 295 |
] |
296 |
||
297 |
" |
|
298 |
Number organization printString |
|
299 |
" |
|
593 | 300 |
|
301 |
"Modified: 20.6.1997 / 18:08:15 / cg" |
|
27 | 302 |
! ! |
303 |
||
304 |
!ClassOrganizer methodsFor:'private access'! |
|
20 | 305 |
|
306 |
class:aClass |
|
307 |
"set the class" |
|
308 |
||
687
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
309 |
class := aClass. |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
310 |
aClass addDependent:self. |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
311 |
|
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
312 |
" |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
313 |
ClassOrganizer organization |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
314 |
" |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
315 |
|
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
316 |
"Modified: / 20.6.1998 / 12:29:16 / cg" |
20 | 317 |
! ! |
318 |
||
249 | 319 |
!ClassOrganizer class methodsFor:'documentation'! |
20 | 320 |
|
249 | 321 |
version |
903 | 322 |
^ '$Header: /cvs/stx/stx/libbasic3/ClassOrganizer.st,v 1.16 2000-02-07 16:07:34 cg Exp $' |
20 | 323 |
! ! |