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