author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Mon, 31 Aug 2015 14:01:56 +0100 | |
changeset 3 | ed5aae792d24 |
parent 0 | 43cb9f3e345e |
child 5 | 5cc2caa88b23 |
permissions | -rw-r--r-- |
0 | 1 |
"{ Package: 'stx:goodies/ring' }" |
2 |
||
3 |
"{ NameSpace: Smalltalk }" |
|
4 |
||
5 |
RGClassDescriptionDefinition subclass:#RGClassDefinition |
|
6 |
instanceVariableNames:'metaClass comment classVariables category package sharedPools' |
|
7 |
classVariableNames:'' |
|
8 |
poolDictionaries:'' |
|
9 |
category:'Ring-Core-Kernel' |
|
10 |
! |
|
11 |
||
12 |
RGClassDefinition comment:'RGClassDefinition is the concrete representation of a class (no trait)' |
|
13 |
! |
|
14 |
||
15 |
!RGClassDefinition class methodsFor:'instance creation'! |
|
16 |
||
3
ed5aae792d24
More Smalltalk/X API methods. Better RGClassDefinition creation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
17 |
newClass |
ed5aae792d24
More Smalltalk/X API methods. Better RGClassDefinition creation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
18 |
"Creates new class definition (along with it's metaclass)" |
ed5aae792d24
More Smalltalk/X API methods. Better RGClassDefinition creation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
19 |
|
ed5aae792d24
More Smalltalk/X API methods. Better RGClassDefinition creation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
20 |
^ self new withMetaclass |
ed5aae792d24
More Smalltalk/X API methods. Better RGClassDefinition creation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
21 |
|
ed5aae792d24
More Smalltalk/X API methods. Better RGClassDefinition creation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
22 |
"Created: / 29-08-2015 / 12:02:20 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
ed5aae792d24
More Smalltalk/X API methods. Better RGClassDefinition creation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
23 |
"Modified: / 31-08-2015 / 11:54:44 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
ed5aae792d24
More Smalltalk/X API methods. Better RGClassDefinition creation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
24 |
! |
ed5aae792d24
More Smalltalk/X API methods. Better RGClassDefinition creation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
25 |
|
ed5aae792d24
More Smalltalk/X API methods. Better RGClassDefinition creation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
26 |
newSharedPool |
ed5aae792d24
More Smalltalk/X API methods. Better RGClassDefinition creation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
27 |
"A shared pool is a class inheriting from #SharedPool" |
ed5aae792d24
More Smalltalk/X API methods. Better RGClassDefinition creation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
28 |
|
ed5aae792d24
More Smalltalk/X API methods. Better RGClassDefinition creation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
29 |
^ RGClassDefinition newClass |
ed5aae792d24
More Smalltalk/X API methods. Better RGClassDefinition creation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
30 |
superclassName:#SharedPool; |
ed5aae792d24
More Smalltalk/X API methods. Better RGClassDefinition creation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
31 |
isPool:true; |
ed5aae792d24
More Smalltalk/X API methods. Better RGClassDefinition creation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
32 |
yourself |
ed5aae792d24
More Smalltalk/X API methods. Better RGClassDefinition creation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
33 |
|
ed5aae792d24
More Smalltalk/X API methods. Better RGClassDefinition creation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
34 |
"Created: / 29-08-2015 / 11:54:08 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
ed5aae792d24
More Smalltalk/X API methods. Better RGClassDefinition creation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
35 |
! |
ed5aae792d24
More Smalltalk/X API methods. Better RGClassDefinition creation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
36 |
|
ed5aae792d24
More Smalltalk/X API methods. Better RGClassDefinition creation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
37 |
newSharedPoolNamed:aSymbol |
0 | 38 |
"A shared pool is a class inheriting from #SharedPool" |
39 |
||
3
ed5aae792d24
More Smalltalk/X API methods. Better RGClassDefinition creation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
40 |
^ self newSharedPool |
ed5aae792d24
More Smalltalk/X API methods. Better RGClassDefinition creation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
41 |
name: aSymbol; |
ed5aae792d24
More Smalltalk/X API methods. Better RGClassDefinition creation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
42 |
yourself |
ed5aae792d24
More Smalltalk/X API methods. Better RGClassDefinition creation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
43 |
|
ed5aae792d24
More Smalltalk/X API methods. Better RGClassDefinition creation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
44 |
"Modified: / 29-08-2015 / 11:54:27 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
0 | 45 |
! ! |
46 |
||
47 |
!RGClassDefinition methodsFor:'accessing'! |
|
48 |
||
49 |
category |
|
50 |
"retrieves a tag for its package" |
|
51 |
||
52 |
^category |
|
53 |
! |
|
54 |
||
55 |
category: aSymbol |
|
56 |
"stores a tag for its package" |
|
57 |
||
58 |
category := aSymbol |
|
59 |
! |
|
60 |
||
61 |
classVariables |
|
62 |
||
63 |
^classVariables |
|
64 |
! |
|
65 |
||
66 |
classVariables: aCollection |
|
67 |
||
68 |
classVariables:= aCollection |
|
69 |
! |
|
70 |
||
71 |
comment |
|
72 |
"Retrieves the comment definition object" |
|
73 |
||
74 |
^comment |
|
75 |
! |
|
76 |
||
77 |
comment: anObject |
|
78 |
"Sets a RGCommentDefinition object based on the argument" |
|
79 |
||
80 |
comment := anObject isRingObject |
|
81 |
ifFalse: [ |
|
82 |
RGCommentDefinition new |
|
83 |
parent: self; |
|
84 |
content: anObject; |
|
85 |
yourself ] |
|
86 |
ifTrue: [anObject ] |
|
87 |
||
88 |
||
89 |
! |
|
90 |
||
3
ed5aae792d24
More Smalltalk/X API methods. Better RGClassDefinition creation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
91 |
name: aString |
ed5aae792d24
More Smalltalk/X API methods. Better RGClassDefinition creation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
92 |
super name: aString. |
ed5aae792d24
More Smalltalk/X API methods. Better RGClassDefinition creation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
93 |
(metaClass notNil and:[metaClass name isNil]) ifTrue:[ |
ed5aae792d24
More Smalltalk/X API methods. Better RGClassDefinition creation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
94 |
metaClass name: aString, ' class'. |
ed5aae792d24
More Smalltalk/X API methods. Better RGClassDefinition creation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
95 |
]. |
ed5aae792d24
More Smalltalk/X API methods. Better RGClassDefinition creation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
96 |
|
ed5aae792d24
More Smalltalk/X API methods. Better RGClassDefinition creation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
97 |
"Created: / 29-08-2015 / 12:05:22 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
ed5aae792d24
More Smalltalk/X API methods. Better RGClassDefinition creation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
98 |
! |
ed5aae792d24
More Smalltalk/X API methods. Better RGClassDefinition creation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
99 |
|
0 | 100 |
package |
101 |
"Retrieves the package in which this class is contained, if exists" |
|
102 |
||
103 |
^package |
|
104 |
! |
|
105 |
||
106 |
package: aRGPackage |
|
107 |
"Sets the package in which this class is contained" |
|
108 |
||
109 |
package:= aRGPackage |
|
110 |
! |
|
111 |
||
112 |
sharedPools |
|
113 |
"Keeps the pool variable relationship of the receiver" |
|
114 |
||
115 |
^ sharedPools |
|
116 |
! |
|
117 |
||
118 |
sharedPools: aCollection |
|
119 |
sharedPools := aCollection |
|
120 |
! |
|
121 |
||
122 |
stamp |
|
123 |
||
124 |
^self hasComment ifTrue:[ self comment stamp ] ifFalse:[ nil ] |
|
125 |
! |
|
126 |
||
127 |
stamp: aString |
|
128 |
||
129 |
self hasComment |
|
130 |
ifTrue: [ self comment stamp: aString ] |
|
131 |
ifFalse:[ RGCommentDefinition new |
|
132 |
parent: self; |
|
133 |
stamp: aString ] |
|
134 |
! |
|
135 |
||
136 |
theMetaClass |
|
137 |
||
138 |
^metaClass |
|
139 |
! |
|
140 |
||
141 |
theNonMetaClass |
|
142 |
||
143 |
^self |
|
144 |
! ! |
|
145 |
||
146 |
!RGClassDefinition methodsFor:'behavior'! |
|
147 |
||
148 |
withMetaclass |
|
149 |
"Registers explicitly the metaclass of a class" |
|
150 |
||
151 |
metaClass:= RGMetaclassDefinition class: self |
|
152 |
! |
|
153 |
||
154 |
withMetaclass: aRGMetaclassDefinition |
|
155 |
"Registers explicitly the metaclass of a class" |
|
156 |
||
157 |
metaClass:= aRGMetaclassDefinition. |
|
158 |
metaClass baseClass: self. |
|
159 |
! ! |
|
160 |
||
161 |
!RGClassDefinition methodsFor:'class variables'! |
|
162 |
||
163 |
addClassVarNamed: aString |
|
164 |
| var | |
|
165 |
var := (RGClassVariableDefinition named: aString) parent: self. |
|
166 |
self addVariable: var in: classVariables. |
|
167 |
^var |
|
168 |
! |
|
169 |
||
170 |
addClassVariable: aRCClassVariable |
|
171 |
||
172 |
self addVariable: (aRCClassVariable parent: self) |
|
173 |
in: classVariables |
|
174 |
! |
|
175 |
||
176 |
addClassVariables: aCollection |
|
177 |
||
178 |
aCollection do: [:var | self addClassVarNamed: var ] |
|
179 |
! |
|
180 |
||
181 |
allClassVarNames |
|
182 |
||
183 |
^self allClassVariables collect:[ :cvar| cvar name ] |
|
184 |
! |
|
185 |
||
186 |
allClassVariables |
|
187 |
"Answer a collection of the receiver's classVariables, including those defined its superclasses" |
|
188 |
||
189 |
^self hasSuperclass |
|
190 |
ifFalse:[ classVariables ] |
|
191 |
ifTrue:[ self superclass allClassVariables, classVariables ] |
|
192 |
! |
|
193 |
||
194 |
classVarNamed: aString |
|
195 |
||
196 |
^classVariables detect:[ :v| v name = aString asSymbol ] ifNone:[ nil ] |
|
197 |
! |
|
198 |
||
199 |
classVarNames |
|
200 |
"Answer a collection of the names of the class variables defined in the receiver." |
|
201 |
||
202 |
^classVariables collect:[ :cvar| cvar name ] |
|
203 |
! |
|
204 |
||
205 |
removeClassVarNamed: aString |
|
206 |
||
207 |
self removeVariable: (self classVarNamed: aString) from: classVariables |
|
208 |
! |
|
209 |
||
210 |
removeClassVariable: aRGClassVariableDefinition |
|
211 |
||
212 |
self removeVariable: aRGClassVariableDefinition from: classVariables |
|
213 |
! ! |
|
214 |
||
215 |
!RGClassDefinition methodsFor:'initialization'! |
|
216 |
||
217 |
initialize |
|
218 |
||
219 |
super initialize. |
|
220 |
classVariables:= OrderedCollection new. |
|
221 |
sharedPools:= OrderedCollection new. |
|
222 |
! ! |
|
223 |
||
224 |
!RGClassDefinition methodsFor:'managing pool users'! |
|
225 |
||
226 |
addUser: aRGClassDefinition |
|
227 |
"The receiver registers the aRGClassDefinition as an user. An reinforces its status as a shared pool." |
|
228 |
||
229 |
aRGClassDefinition isClass ifFalse:[ ^self ]. |
|
230 |
(aRGClassDefinition theNonMetaClass sharedPoolNamed: self name) isNil |
|
231 |
ifTrue: [ aRGClassDefinition theNonMetaClass addSharedPoolNamed: self name ]. |
|
232 |
self isPool: true. |
|
233 |
self users add: aRGClassDefinition theNonMetaClass |
|
234 |
! |
|
235 |
||
236 |
includesUser: aRGBehaviorDefinition |
|
237 |
||
238 |
^self users includes: aRGBehaviorDefinition |
|
239 |
! |
|
240 |
||
241 |
isPool |
|
242 |
"The receiver is a shared pool if it inherits from SharedPool" |
|
243 |
||
244 |
^self annotationNamed: self class isPoolKey |
|
245 |
ifAbsent: [ self superclassName == #SharedPool ] |
|
246 |
! |
|
247 |
||
248 |
isPool: aBoolean |
|
249 |
||
250 |
^self annotationNamed: self class isPoolKey put: aBoolean |
|
251 |
! |
|
252 |
||
253 |
removeUser: aRGClassDefinition |
|
254 |
"Removes this RGClassDefinition from the users of the receiver" |
|
255 |
||
256 |
aRGClassDefinition isClass ifFalse:[ ^self ]. |
|
257 |
aRGClassDefinition theNonMetaClass removeSharedPoolNamed: self name. |
|
258 |
self users remove: aRGClassDefinition theNonMetaClass ifAbsent:[ ] |
|
259 |
! |
|
260 |
||
261 |
users |
|
262 |
"If the reciever is a SharedPool then retrieves its users" |
|
263 |
||
264 |
^self isPool |
|
265 |
ifTrue: [ self annotationNamed: self class usersKey ifAbsentPut: [ OrderedCollection new ] ] |
|
266 |
ifFalse:[ #() ] |
|
267 |
! ! |
|
268 |
||
269 |
!RGClassDefinition methodsFor:'shared pools'! |
|
270 |
||
271 |
addSharedPool: aRGPoolVariableDefinition |
|
272 |
self |
|
273 |
addVariable: (aRGPoolVariableDefinition parent: self) |
|
274 |
in: sharedPools |
|
275 |
! |
|
276 |
||
277 |
addSharedPoolNamed: poolName |
|
278 |
| pool | |
|
279 |
pool:= (RGPoolVariableDefinition named: poolName) parent: self. |
|
280 |
self addVariable: pool in: sharedPools. |
|
281 |
^pool |
|
282 |
! |
|
283 |
||
284 |
addSharedPools: aCollection |
|
285 |
aCollection do: [ :pool | self addSharedPoolNamed: pool ] |
|
286 |
! |
|
287 |
||
288 |
allSharedPoolNames |
|
289 |
^ self allSharedPools collect: [ :pool | pool name ] |
|
290 |
! |
|
291 |
||
292 |
allSharedPools |
|
293 |
"Answer a collection of the pools the receiver shares, including those defined |
|
294 |
in the superclasses of the receiver." |
|
295 |
||
296 |
^ self hasSuperclass |
|
297 |
ifFalse: [ sharedPools ] |
|
298 |
ifTrue: [ self superclass allSharedPools , sharedPools ] |
|
299 |
! |
|
300 |
||
301 |
removeSharedPool: aRGPoolVariableDefinition |
|
302 |
||
303 |
self removeVariable: aRGPoolVariableDefinition from: sharedPools |
|
304 |
! |
|
305 |
||
306 |
removeSharedPoolNamed: poolName |
|
307 |
||
308 |
self removeVariable: (self sharedPoolNamed: poolName) from: sharedPools |
|
309 |
! |
|
310 |
||
311 |
sharedPoolNamed: poolName |
|
312 |
||
313 |
^sharedPools detect:[ :v| v name = poolName asSymbol ] ifNone:[ nil ] |
|
314 |
! |
|
315 |
||
316 |
sharedPoolNames |
|
317 |
||
318 |
^sharedPools collect:[ :pool| pool name ] |
|
319 |
! ! |
|
320 |
||
321 |
!RGClassDefinition methodsFor:'testing'! |
|
322 |
||
323 |
hasComment |
|
324 |
||
325 |
^comment isEmptyOrNil not |
|
326 |
! |
|
327 |
||
328 |
hasMetaclass |
|
329 |
||
330 |
^metaClass notNil |
|
331 |
! |
|
332 |
||
333 |
hasStamp |
|
334 |
||
335 |
^self stamp isEmptyOrNil not |
|
336 |
! |
|
337 |
||
338 |
isSameRevisionAs: aRGClassDefinition |
|
339 |
"This method look for equality of the properties of the receiver" |
|
340 |
||
341 |
^(super isSameRevisionAs: aRGClassDefinition) |
|
342 |
and:[ self superclassName == aRGClassDefinition superclassName |
|
343 |
and:[ self category = aRGClassDefinition category |
|
344 |
and:[ self classVarNames sorted = aRGClassDefinition classVarNames sorted |
|
345 |
and:[ self sharedPoolNames sorted = aRGClassDefinition sharedPoolNames sorted |
|
346 |
and:[ self traitCompositionSource = aRGClassDefinition traitCompositionSource |
|
347 |
and:[ ((self hasComment and:[ self comment isSameRevisionAs: aRGClassDefinition comment ]) or:[ self hasComment not ]) |
|
348 |
and:[ (self theMetaClass isSameRevisionAs: aRGClassDefinition theMetaClass) ] ] ] ] ] ] ] |
|
349 |
! ! |
|
350 |
||
3
ed5aae792d24
More Smalltalk/X API methods. Better RGClassDefinition creation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
351 |