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