author | Patrik Svestka <patrik.svestka@gmail.com> |
Wed, 17 Feb 2021 15:24:09 +0100 | |
branch | jv |
changeset 4568 | 524471ef6575 |
parent 4567 | b40d0360dbdc |
permissions | -rw-r--r-- |
20 | 1 |
" |
2 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
4567
b40d0360dbdc
Add missing `ClassOrganizer >> #selectorsFor:`
Jan Vrany <jan.vrany@labware.com>
parents:
4384
diff
changeset
|
3 |
COPYRIGHT (c) 2021 LabWare |
249 | 4 |
All Rights Reserved |
20 | 5 |
|
6 |
This software is furnished under a license and may be used |
|
7 |
only in accordance with the terms of that license and with the |
|
8 |
inclusion of the above copyright notice. This software may not |
|
9 |
be provided or otherwise made available to, or used by, any |
|
10 |
other person. No title to or ownership of the software is |
|
11 |
hereby transferred. |
|
12 |
" |
|
975 | 13 |
"{ Package: 'stx:libbasic3' }" |
14 |
||
4567
b40d0360dbdc
Add missing `ClassOrganizer >> #selectorsFor:`
Jan Vrany <jan.vrany@labware.com>
parents:
4384
diff
changeset
|
15 |
"{ NameSpace: Smalltalk }" |
b40d0360dbdc
Add missing `ClassOrganizer >> #selectorsFor:`
Jan Vrany <jan.vrany@labware.com>
parents:
4384
diff
changeset
|
16 |
|
27 | 17 |
Object subclass:#ClassOrganizer |
593 | 18 |
instanceVariableNames:'globalComment categoryArray categoryStops elementArray class |
19 |
categories' |
|
249 | 20 |
classVariableNames:'' |
21 |
poolDictionaries:'' |
|
22 |
category:'Kernel-Support' |
|
20 | 23 |
! |
24 |
||
27 | 25 |
!ClassOrganizer class methodsFor:'documentation'! |
20 | 26 |
|
27 |
copyright |
|
28 |
" |
|
29 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
4567
b40d0360dbdc
Add missing `ClassOrganizer >> #selectorsFor:`
Jan Vrany <jan.vrany@labware.com>
parents:
4384
diff
changeset
|
30 |
COPYRIGHT (c) 2021 LabWare |
20 | 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 |
||
3012 | 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" |
|
4567
b40d0360dbdc
Add missing `ClassOrganizer >> #selectorsFor:`
Jan Vrany <jan.vrany@labware.com>
parents:
4384
diff
changeset
|
200 |
! |
b40d0360dbdc
Add missing `ClassOrganizer >> #selectorsFor:`
Jan Vrany <jan.vrany@labware.com>
parents:
4384
diff
changeset
|
201 |
|
b40d0360dbdc
Add missing `ClassOrganizer >> #selectorsFor:`
Jan Vrany <jan.vrany@labware.com>
parents:
4384
diff
changeset
|
202 |
selectorsFor: protocol |
b40d0360dbdc
Add missing `ClassOrganizer >> #selectorsFor:`
Jan Vrany <jan.vrany@labware.com>
parents:
4384
diff
changeset
|
203 |
^ self listAtCategoryNamed: protocol |
b40d0360dbdc
Add missing `ClassOrganizer >> #selectorsFor:`
Jan Vrany <jan.vrany@labware.com>
parents:
4384
diff
changeset
|
204 |
|
b40d0360dbdc
Add missing `ClassOrganizer >> #selectorsFor:`
Jan Vrany <jan.vrany@labware.com>
parents:
4384
diff
changeset
|
205 |
"Created: / 04-02-2021 / 08:20:26 / Jan Vrany <jan.vrany@labware.com>" |
249 | 206 |
! ! |
27 | 207 |
|
687
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
208 |
!ClassOrganizer methodsFor:'change & update'! |
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 |
update:something with:parameter from:changedObject |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
211 |
changedObject == class ifTrue:[ |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
212 |
something == #methodTrap ifFalse:[ |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
213 |
categoryArray := elementArray := categories := nil |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
214 |
] |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
215 |
]. |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
216 |
|
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
217 |
"Created: / 20.6.1998 / 12:28:37 / cg" |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
218 |
"Modified: / 20.6.1998 / 12:30:14 / cg" |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
219 |
! ! |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
220 |
|
249 | 221 |
!ClassOrganizer methodsFor:'changing'! |
27 | 222 |
|
249 | 223 |
changeFromString:organizationString |
224 |
"take category<->selector associations from aString, and change |
|
225 |
the categories of those methods. |
|
226 |
Only required when filing in ST-80 code, which changes the categorization |
|
227 |
this way." |
|
27 | 228 |
|
249 | 229 |
|a category m| |
27 | 230 |
|
231 |
" |
|
249 | 232 |
(mis(use) parser for the scanning |
233 |
" |
|
234 |
a := Compiler evaluate:'#(' , organizationString , ')'. |
|
235 |
(a isMemberOf:Array) ifFalse:[^ self error:'malformed argument']. |
|
236 |
a do:[:row | |
|
237 |
category := row at:1. |
|
238 |
2 to:row size do:[:idx | |
|
239 |
|selector| |
|
240 |
||
241 |
selector := row at:idx. |
|
242 |
m := class compiledMethodAt:selector. |
|
243 |
m isNil ifTrue:[ |
|
258 | 244 |
Transcript showCR:'no method for ' , selector , ' in ', class name |
249 | 245 |
] ifFalse:[ |
246 |
m category:category. |
|
247 |
] |
|
248 |
] |
|
249 |
]. |
|
250 |
||
251 |
" |
|
252 |
TestClass |
|
253 |
organization |
|
254 |
changeFromString:'( ''category1'' #foo1 #foo2 foo3) |
|
255 |
( ''category2'' #bar1 #bar2)' |
|
27 | 256 |
" |
593 | 257 |
! |
258 |
||
259 |
classify:aSelector under:aCategory |
|
260 |
"change the category of the method stored under aSelector |
|
261 |
to aCategory." |
|
262 |
||
263 |
|m list| |
|
264 |
||
265 |
class isNil ifTrue:[ |
|
266 |
"/ sigh used without a class ... |
|
267 |
categories isNil ifTrue:[ |
|
268 |
categories := Dictionary new. |
|
269 |
]. |
|
270 |
list := categories at:aCategory ifAbsent:nil. |
|
271 |
list isNil ifTrue:[ |
|
272 |
list := OrderedCollection new. |
|
273 |
categories at:aCategory put:list. |
|
274 |
]. |
|
275 |
list add:aSelector. |
|
276 |
^ self. |
|
277 |
]. |
|
278 |
||
279 |
m := class compiledMethodAt:aSelector. |
|
280 |
m notNil ifTrue:[ |
|
281 |
m category:aCategory |
|
282 |
]. |
|
283 |
||
284 |
"Created: 20.6.1997 / 18:01:18 / cg" |
|
285 |
"Modified: 20.6.1997 / 18:09:37 / cg" |
|
27 | 286 |
! ! |
287 |
||
288 |
!ClassOrganizer methodsFor:'printing & storing'! |
|
289 |
||
290 |
printOn:aStream |
|
291 |
|coll| |
|
292 |
||
593 | 293 |
class notNil ifTrue:[ |
294 |
coll := IdentityDictionary new. |
|
295 |
class methodDictionary keysAndValuesDo:[:sel :mthd | |
|
296 |
|cat list| |
|
27 | 297 |
|
593 | 298 |
cat := mthd category. |
299 |
list := coll at:cat ifAbsent:[]. |
|
300 |
list isNil ifTrue:[ |
|
301 |
coll at:cat put:(list := OrderedCollection new). |
|
302 |
]. |
|
303 |
list add:sel |
|
556 | 304 |
]. |
593 | 305 |
] ifFalse:[ |
306 |
coll := categories |
|
27 | 307 |
]. |
1086 | 308 |
coll notNil ifTrue:[ |
309 |
coll keysAndValuesDo:[:category :list | |
|
310 |
aStream nextPut:$(. |
|
311 |
aStream nextPutAll:category asString storeString. |
|
312 |
list do:[:selector | |
|
313 |
aStream space. |
|
314 |
selector storeOn:aStream |
|
315 |
]. |
|
316 |
aStream nextPut:$). |
|
317 |
aStream cr |
|
318 |
] |
|
27 | 319 |
] |
320 |
||
321 |
" |
|
322 |
Number organization printString |
|
323 |
" |
|
593 | 324 |
|
1086 | 325 |
"Modified: / 30.10.2001 / 17:58:50 / cg" |
27 | 326 |
! ! |
327 |
||
328 |
!ClassOrganizer methodsFor:'private access'! |
|
20 | 329 |
|
330 |
class:aClass |
|
331 |
"set the class" |
|
332 |
||
687
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
333 |
class := aClass. |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
334 |
aClass addDependent:self. |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
335 |
|
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
336 |
" |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
337 |
ClassOrganizer organization |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
338 |
" |
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
339 |
|
47729447d24a
remember categories & watch for class changes.
Claus Gittinger <cg@exept.de>
parents:
658
diff
changeset
|
340 |
"Modified: / 20.6.1998 / 12:29:16 / cg" |
20 | 341 |
! ! |
342 |
||
249 | 343 |
!ClassOrganizer class methodsFor:'documentation'! |
20 | 344 |
|
249 | 345 |
version |
3121
19723298dd2c
Bugfix: reading of Java class extensions methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3042
diff
changeset
|
346 |
^ '$Header: ClassOrganizer.st 1909 2012-03-31 00:14:49Z vranyj1 $' |
19723298dd2c
Bugfix: reading of Java class extensions methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3042
diff
changeset
|
347 |
! |
19723298dd2c
Bugfix: reading of Java class extensions methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3042
diff
changeset
|
348 |
|
19723298dd2c
Bugfix: reading of Java class extensions methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3042
diff
changeset
|
349 |
version_HG |
19723298dd2c
Bugfix: reading of Java class extensions methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3042
diff
changeset
|
350 |
|
19723298dd2c
Bugfix: reading of Java class extensions methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3042
diff
changeset
|
351 |
^ '$Changeset: <not expanded> $' |
3012 | 352 |
! |
353 |
||
354 |
version_SVN |
|
4567
b40d0360dbdc
Add missing `ClassOrganizer >> #selectorsFor:`
Jan Vrany <jan.vrany@labware.com>
parents:
4384
diff
changeset
|
355 |
^ '§Id: ClassOrganizer.st 1909 2012-03-31 00:14:49Z vranyj1 §' |
3012 | 356 |
! ! |
3121
19723298dd2c
Bugfix: reading of Java class extensions methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3042
diff
changeset
|
357 |