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
|
|
37 |
"
|
38
|
38 |
$Header: /cvs/stx/stx/libbasic3/ClassOrganizer.st,v 1.4 1995-08-10 13:19:38 claus Exp $
|
|
39 |
$Revision: 1.4 $
|
20
|
40 |
"
|
|
41 |
!
|
|
42 |
|
|
43 |
documentation
|
|
44 |
"
|
|
45 |
in contrast to other smalltalks, ST/X does not keep the
|
|
46 |
method <-> category associations in the class (as organization),
|
|
47 |
but instead keeps the category as an instance variable of method.
|
|
48 |
|
|
49 |
For compatibility with (fileOut-) files which include a class organization
|
27
|
50 |
message, 'aClass organization' returns an instance of this class, which
|
20
|
51 |
implements the category change functionality.
|
27
|
52 |
Also, some PD code seems to use & define methods for ClassOrganizers - having this
|
|
53 |
(somewhat dummy) around helps to fileIn that code.
|
|
54 |
|
|
55 |
Notice, that instances of ClassOrganizer are not used in the current ST/X
|
|
56 |
system; all is pure mimicri.
|
|
57 |
This may change in future versions.
|
20
|
58 |
"
|
|
59 |
! !
|
|
60 |
|
27
|
61 |
!ClassOrganizer class methodsFor:'instance creation'!
|
20
|
62 |
|
|
63 |
for:aClass
|
|
64 |
"create & return a new instance of myself, to organize aClass"
|
|
65 |
|
|
66 |
^ self new class:aClass
|
|
67 |
! !
|
|
68 |
|
27
|
69 |
!ClassOrganizer methodsFor:'accessing'!
|
|
70 |
|
|
71 |
classComment
|
|
72 |
^ class comment
|
|
73 |
|
|
74 |
"
|
|
75 |
Number organization classComment
|
|
76 |
"
|
|
77 |
!
|
|
78 |
|
|
79 |
categoryOfElement:aSelectorSymbol
|
|
80 |
|m|
|
|
81 |
|
|
82 |
m := class compiledMethodAt:aSelectorSymbol.
|
|
83 |
m isNil ifTrue:[^ nil].
|
|
84 |
^ m category
|
|
85 |
|
|
86 |
"
|
|
87 |
Number organization categoryOfElement:#foo.
|
|
88 |
Object organization categoryOfElement:#==
|
|
89 |
"
|
|
90 |
!
|
|
91 |
|
|
92 |
listAtCategoryNamed:aCategorySymbol
|
|
93 |
"return a collection of selectors whose methods are categorized
|
|
94 |
as aCategorySymbol"
|
|
95 |
|
|
96 |
|list|
|
|
97 |
|
|
98 |
list := OrderedCollection new.
|
|
99 |
class methodArray with:class selectorArray do:[:m :s |
|
|
100 |
m category == aCategorySymbol ifTrue:[list add:s]
|
|
101 |
].
|
|
102 |
^ list asArray
|
|
103 |
|
|
104 |
"
|
|
105 |
SmallInteger organization listAtCategoryNamed:#arithmetic
|
|
106 |
"
|
|
107 |
!
|
|
108 |
|
|
109 |
categories
|
|
110 |
"return a collection of categorySymbols"
|
|
111 |
|
|
112 |
|set|
|
|
113 |
|
|
114 |
set := IdentitySet new.
|
|
115 |
class methodArray do:[:m |
|
|
116 |
set add:m category
|
|
117 |
].
|
|
118 |
^ set asArray
|
|
119 |
|
|
120 |
"
|
|
121 |
SmallInteger organization categories
|
|
122 |
"
|
|
123 |
! !
|
|
124 |
|
|
125 |
!ClassOrganizer methodsFor:'printing & storing'!
|
|
126 |
|
|
127 |
printOn:aStream
|
|
128 |
|coll|
|
|
129 |
|
|
130 |
coll := IdentityDictionary new.
|
|
131 |
class methodArray with:class selectorArray do:[:m :s |
|
|
132 |
|cat list|
|
|
133 |
|
|
134 |
cat := m category.
|
|
135 |
list := coll at:cat ifAbsent:[].
|
|
136 |
list isNil ifTrue:[
|
|
137 |
coll at:cat put:(list := OrderedCollection new).
|
|
138 |
].
|
|
139 |
list add:s
|
|
140 |
].
|
|
141 |
coll keysAndValuesDo:[:category :list |
|
|
142 |
aStream nextPut:$(.
|
|
143 |
aStream nextPutAll:category asString storeString.
|
|
144 |
list do:[:selector |
|
|
145 |
aStream space.
|
|
146 |
selector storeOn:aStream
|
|
147 |
].
|
|
148 |
aStream nextPut:$).
|
|
149 |
aStream cr
|
|
150 |
]
|
|
151 |
|
|
152 |
"
|
|
153 |
Number organization printString
|
|
154 |
"
|
|
155 |
! !
|
|
156 |
|
|
157 |
!ClassOrganizer methodsFor:'private access'!
|
20
|
158 |
|
|
159 |
class:aClass
|
|
160 |
"set the class"
|
|
161 |
|
|
162 |
class := aClass
|
|
163 |
! !
|
|
164 |
|
27
|
165 |
!ClassOrganizer methodsFor:'changing'!
|
20
|
166 |
|
|
167 |
changeFromString:organizationString
|
|
168 |
"take category<->selector associations from aString, and change
|
|
169 |
the categories of those methods. Only required when filing in
|
|
170 |
ST-80 code."
|
|
171 |
|
33
|
172 |
|a category m|
|
20
|
173 |
|
|
174 |
"
|
|
175 |
(mis(use) parser for the scanning
|
|
176 |
"
|
|
177 |
a := Compiler evaluate:'#(' , organizationString , ')'.
|
|
178 |
(a isMemberOf:Array) ifFalse:[^ self error:'malformed argument'].
|
|
179 |
a do:[:row |
|
|
180 |
category := row at:1.
|
|
181 |
2 to:row size do:[:idx |
|
|
182 |
|selector|
|
|
183 |
|
|
184 |
selector := row at:idx.
|
|
185 |
m := class compiledMethodAt:selector.
|
|
186 |
m isNil ifTrue:[
|
|
187 |
Transcript showCr:'no method for ' , selector , ' in ', class name
|
|
188 |
] ifFalse:[
|
|
189 |
m category:category.
|
|
190 |
]
|
|
191 |
]
|
|
192 |
].
|
|
193 |
class changed:#organization
|
|
194 |
|
|
195 |
"
|
|
196 |
TestClass organization changeFromString:'( ''category1'' #foo1 #foo2 foo3)
|
|
197 |
( ''category2'' #bar1 #bar2)'
|
|
198 |
"
|
|
199 |
! !
|