author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Wed, 02 Sep 2015 09:18:30 +0100 | |
changeset 4 | 90637b709fa9 |
parent 2 | e439b82dda7d |
permissions | -rw-r--r-- |
0 | 1 |
"{ Package: 'stx:goodies/ring' }"! |
2 |
||
3 |
!Behavior methodsFor:'*Ring-Core-Kernel'! |
|
4 |
||
5 |
methodNamed: aSelector |
|
6 |
||
7 |
^ self methodDict at: aSelector |
|
8 |
||
9 |
"Created: / 28-08-2015 / 09:37:34 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10 |
! ! |
|
11 |
||
12 |
!Behavior methodsFor:'*Ring-Core-Kernel'! |
|
13 |
||
14 |
protocols |
|
15 |
||
16 |
^ self organization categories copy |
|
17 |
||
18 |
"Created: / 28-08-2015 / 09:37:23 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
19 |
! ! |
|
20 |
||
21 |
!Class methodsFor:'*Ring-Core-Kernel'! |
|
22 |
||
23 |
asFullRingDefinition |
|
24 |
"A behavior is converted to a ring class including its variables, methods, direct superclass, direct subclasses and the package in which is loaded. |
|
25 |
Active methods are generated and each knows its package as well. |
|
26 |
Note that for its direct superclass and subclasses no full definitions are requested. If you need to traverse hierarchies use #asRingDefinitionWithMethods:withSuperclasses:withSubclasses:withPackages:" |
|
27 |
||
28 |
| rgClass rgSuper rgSub rgMethod packageKeys | |
|
29 |
rgClass:= self asRingDefinition. |
|
30 |
rgClass package: (RGContainer packageOfClass: rgClass). |
|
31 |
||
32 |
self superclass notNil |
|
33 |
ifTrue: [ |
|
34 |
rgSuper := self superclass asRingDefinition. |
|
35 |
rgClass superclass: rgSuper ] |
|
36 |
ifFalse: [ |
|
37 |
self isTrait ifTrue: [ |
|
38 |
rgSuper := Trait asRingDefinition. |
|
39 |
rgClass superclass: rgSuper. ] |
|
40 |
]. |
|
41 |
||
42 |
self subclasses do:[ :each | |
|
43 |
rgSub := each asRingDefinition. |
|
44 |
rgSub superclass: rgClass ]. |
|
45 |
||
46 |
packageKeys := RGContainer packageKeys. |
|
47 |
self methodsDo:[ :mth| |
|
48 |
rgMethod := mth asActiveRingDefinition. |
|
49 |
rgClass addMethod: rgMethod. |
|
50 |
rgMethod package: (RGContainer packageOfMethod: rgMethod using: packageKeys) ]. |
|
51 |
self theMetaClass methodsDo:[ :mth| |
|
52 |
rgMethod := mth asActiveRingDefinition. |
|
53 |
rgClass theMetaClass addMethod: rgMethod. |
|
54 |
rgMethod package: (RGContainer packageOfMethod: rgMethod using: packageKeys) ]. |
|
55 |
||
56 |
^ rgClass |
|
57 |
||
58 |
"Created: / 28-08-2015 / 09:36:18 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
59 |
! ! |
|
60 |
||
61 |
!Class methodsFor:'*Ring-Core-Kernel'! |
|
62 |
||
63 |
asRingDefinition |
|
64 |
"A behavior is converted to a ring class. Only the receiver and its variables (instance, class, pools) are converted. |
|
65 |
Methods, superclasses, subclasses are not generated" |
|
66 |
||
67 |
| ring | |
|
68 |
ring := (RGClassDefinition named: self name) |
|
69 |
category: self category; |
|
70 |
superclassName: self superclass name; |
|
71 |
traitCompositionSource: self traitCompositionString; |
|
72 |
addInstanceVariables: self instVarNames; |
|
73 |
addClassVariables: self classVarNames; |
|
74 |
addSharedPools: self sharedPoolNames; |
|
75 |
comment: self organization classComment; |
|
76 |
stamp: self organization commentStamp; |
|
77 |
definitionSource: self definition; |
|
2
e439b82dda7d
Fixed some tests. Not all pass, though,
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1
diff
changeset
|
78 |
package: (RGPackage named: self package); |
0 | 79 |
withMetaclass. |
80 |
ring theMetaClass |
|
81 |
traitCompositionSource: self theMetaClass traitCompositionString; |
|
82 |
definitionSource: self theMetaClass definition; |
|
83 |
addInstanceVariables: self theMetaClass instVarNames. |
|
84 |
^ ring |
|
2
e439b82dda7d
Fixed some tests. Not all pass, though,
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1
diff
changeset
|
85 |
|
e439b82dda7d
Fixed some tests. Not all pass, though,
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1
diff
changeset
|
86 |
"Modified: / 28-08-2015 / 18:27:13 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
0 | 87 |
! ! |
88 |
||
89 |
!Class methodsFor:'*Ring-Core-Kernel'! |
|
90 |
||
91 |
asRingDefinitionWithMethods: methodsBoolean withSuperclasses: supersBoolean withSubclasses: subsBoolean withPackageKeys: packageKeys in: aRGSlice |
|
92 |
| rgClass rgMethod rgSuper rgSub subs | |
|
93 |
rgClass := self asRingDefinition. |
|
94 |
aRGSlice loadClass: rgClass using: packageKeys. |
|
95 |
methodsBoolean |
|
96 |
ifTrue: [ |
|
97 |
self |
|
98 |
methodsDo: [ :mth | |
|
99 |
rgMethod := mth asActiveRingDefinition. |
|
100 |
aRGSlice loadMethod: rgMethod inClass: rgClass using: packageKeys ]. |
|
101 |
self theMetaClass |
|
102 |
methodsDo: [ :mth | |
|
103 |
rgMethod := mth asActiveRingDefinition. |
|
104 |
aRGSlice loadMethod: rgMethod inClass: rgClass theMetaClass using: packageKeys ] ]. |
|
105 |
supersBoolean |
|
106 |
ifTrue: [ |
|
107 |
self superclass |
|
108 |
ifNotNil: [ |
|
109 |
rgSuper := aRGSlice classNamed: self superclass name. |
|
110 |
rgSuper |
|
111 |
ifNil: [ |
|
112 |
rgSuper := self superclass |
|
113 |
asRingDefinitionWithMethods: methodsBoolean |
|
114 |
withSuperclasses: supersBoolean |
|
115 |
withSubclasses: subsBoolean |
|
116 |
withPackageKeys: packageKeys |
|
117 |
in: aRGSlice ]. |
|
118 |
rgClass superclass: rgSuper ] ]. |
|
119 |
subsBoolean |
|
120 |
ifTrue: [ |
|
121 |
subs := self subclasses reject: [ :sub | sub isMeta ]. |
|
122 |
rgClass name = #Trait |
|
123 |
ifTrue: [ subs := aRGSlice environment allTraits ]. |
|
124 |
subs |
|
125 |
do: [ :each | |
|
126 |
rgSub := aRGSlice classNamed: each name. |
|
127 |
rgSub |
|
128 |
ifNil: [ |
|
129 |
rgSub := each |
|
130 |
asRingDefinitionWithMethods: methodsBoolean |
|
131 |
withSuperclasses: supersBoolean |
|
132 |
withSubclasses: subsBoolean |
|
133 |
withPackageKeys: packageKeys |
|
134 |
in: aRGSlice ]. |
|
135 |
rgSub superclass: rgClass ] ]. |
|
136 |
^ rgClass |
|
137 |
! ! |
|
138 |
||
139 |
!Class methodsFor:'*Ring-Core-Kernel'! |
|
140 |
||
141 |
asRingDefinitionWithMethods: methodsBoolean withSuperclasses: supersBoolean withSubclasses: subsBoolean withPackages: packsBoolean |
|
142 |
"Retrieves a ring class/trait based on the receiver. |
|
143 |
The data loaded in the class/trait (active methods, superclasses, subclasses and packages) is requested by the users. |
|
144 |
As it may need to traverse hierarchies for retrieving super and subclasses a ring slice is created as the container for every class, method and package. |
|
145 |
To retrieve the slice: aRGClass environment " |
|
146 |
| rgClass rgSlice rgPackageKeys | |
|
147 |
||
148 |
rgSlice := RGSlice named: #fromImage. |
|
149 |
packsBoolean ifTrue: [ |
|
150 |
rgPackageKeys := rgSlice loadPackagesFromImage ]. |
|
151 |
rgClass := self asRingDefinitionWithMethods: methodsBoolean withSuperclasses: supersBoolean withSubclasses: subsBoolean withPackageKeys: rgPackageKeys in: rgSlice. |
|
152 |
rgSlice cleanEmptyPackages. |
|
153 |
rgSlice loadTraitUsers. |
|
154 |
||
155 |
^ rgClass |
|
156 |
||
157 |
"Created: / 28-08-2015 / 09:36:00 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
158 |
! ! |
|
159 |
||
160 |
!Method methodsFor:'*Ring-Core-Kernel'! |
|
161 |
||
162 |
asActiveRingDefinition |
|
163 |
"Retrieves an active RGMethodDefinition object based on the data of the receiver. |
|
164 |
Source, protocol and stamp are retrieved from the compiled method" |
|
165 |
||
166 |
^ RGMethodDefinition new |
|
167 |
name: self selector; |
|
168 |
parentName: self methodClass name; |
|
169 |
isMetaSide: self methodClass isMeta; |
|
170 |
asActive. |
|
171 |
! ! |
|
172 |
||
173 |
!Method methodsFor:'*Ring-Core-Kernel'! |
|
174 |
||
175 |
asFullRingDefinition |
|
176 |
||
177 |
"Retrieves an active RGMethodDefinition which knows its parent <class>. |
|
178 |
Note that the full conversion does not happen at the level of the class. If you need that request asFullRingDefinition to the class" |
|
179 |
| rgClass rgMethod | |
|
180 |
rgClass := self realClass asRingDefinition. |
|
181 |
rgMethod := self asActiveRingDefinition. |
|
182 |
rgClass addMethod: rgMethod. |
|
183 |
rgMethod package: (RGContainer packageOfMethod: rgMethod). |
|
184 |
^ rgMethod |
|
185 |
! ! |
|
186 |
||
187 |
!Method methodsFor:'*Ring-Core-Kernel'! |
|
188 |
||
189 |
asHistoricalRingDefinition |
|
190 |
||
191 |
"Retrieves a historical RGMethodDefinition object based on the data of the receiver. |
|
192 |
Source, protocol and stamp are retrieved from the source file method" |
|
193 |
| ring | |
|
194 |
ring := (RGMethodDefinition named: self selector) |
|
195 |
parentName: self methodClass name; |
|
196 |
isMetaSide: self methodClass isMeta. |
|
197 |
||
2
e439b82dda7d
Fixed some tests. Not all pass, though,
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1
diff
changeset
|
198 |
self sourceCode isNil |
0 | 199 |
ifTrue: [ "this should not happen but sometimes the system looks corrupted" |
200 |
ring protocol: self category; |
|
201 |
sourceCode: self sourceCode; |
|
202 |
stamp: self timeStamp ] |
|
203 |
ifFalse: [ |
|
2
e439b82dda7d
Fixed some tests. Not all pass, though,
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1
diff
changeset
|
204 |
ring sourceCode: self sourceCode ]. |
e439b82dda7d
Fixed some tests. Not all pass, though,
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1
diff
changeset
|
205 |
ring asHistorical. |
0 | 206 |
^ ring |
2
e439b82dda7d
Fixed some tests. Not all pass, though,
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1
diff
changeset
|
207 |
|
e439b82dda7d
Fixed some tests. Not all pass, though,
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1
diff
changeset
|
208 |
"Modified: / 29-08-2015 / 08:01:18 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
0 | 209 |
! ! |
210 |
||
211 |
!Method methodsFor:'*Ring-Core-Kernel'! |
|
212 |
||
213 |
asPassiveRingDefinition |
|
214 |
"Retrieves a passive RGMethodDefinition object based on the data of the receiver. |
|
215 |
Source, protocol and stamp are retrieved from value assigned in creation" |
|
216 |
||
217 |
^RGMethodDefinition new |
|
218 |
name: self selector; |
|
219 |
parentName: self methodClass name; |
|
220 |
isMetaSide: self methodClass isMeta; |
|
221 |
protocol: self category; |
|
222 |
sourceCode: self sourceCode; |
|
223 |
stamp: self timeStamp; |
|
224 |
asPassive. |
|
225 |
! ! |
|
226 |
||
227 |
!Method methodsFor:'*Ring-Core-Kernel'! |
|
228 |
||
229 |
asRingDefinition |
|
230 |
"Retrieves an active RGMethodDefinition object based on the receiver. |
|
231 |
Note that its class is not converted." |
|
232 |
||
233 |
^ self asActiveRingDefinition |
|
234 |
! ! |
|
235 |
||
236 |
!Method methodsFor:'*Ring-Core-Kernel'! |
|
237 |
||
238 |
methodReference |
|
239 |
||
240 |
| class selector | |
|
241 |
class := self methodClass ifNil: [^nil]. |
|
242 |
selector := self selector ifNil: [^nil]. |
|
243 |
^RGMethodDefinition realClass: class selector: selector. |
|
244 |
||
245 |
! ! |
|
246 |
||
247 |
!Method methodsFor:'*Ring-Core-Kernel'! |
|
248 |
||
249 |
realClass |
|
250 |
"answer the class that I am installed in" |
|
251 |
||
252 |
^ self methodClass |
|
253 |
! ! |
|
254 |
||
255 |
!Object methodsFor:'*Ring-Core-Kernel'! |
|
256 |
||
257 |
isRingObject |
|
258 |
||
259 |
^false |
|
260 |
! ! |
|
261 |
||
262 |
!stx_goodies_ring class methodsFor:'documentation'! |
|
263 |
||
264 |
extensionsVersion_HG |
|
265 |
||
266 |
^ '$Changeset: <not expanded> $' |
|
267 |
! ! |