0
|
1 |
"{ Package: 'stx:goodies/ring' }"
|
|
2 |
|
|
3 |
"{ NameSpace: Smalltalk }"
|
|
4 |
|
|
5 |
RGBehaviorDefinition subclass:#RGClassDescriptionDefinition
|
|
6 |
instanceVariableNames:'instanceVariables organization'
|
|
7 |
classVariableNames:''
|
|
8 |
poolDictionaries:''
|
|
9 |
category:'Ring-Core-Kernel'
|
|
10 |
!
|
|
11 |
|
|
12 |
RGClassDescriptionDefinition comment:'RGClassDescriptionDefinition is the common parent for classes and metaclasses defining instance variables'
|
|
13 |
!
|
|
14 |
|
|
15 |
!RGClassDescriptionDefinition methodsFor:'accessing'!
|
|
16 |
|
|
17 |
instanceVariables
|
|
18 |
|
|
19 |
^instanceVariables
|
|
20 |
!
|
|
21 |
|
|
22 |
instanceVariables: aCollection
|
|
23 |
|
|
24 |
instanceVariables:= aCollection
|
|
25 |
!
|
|
26 |
|
|
27 |
organization: aClassOrg
|
|
28 |
"Install an instance of ClassOrganizer that represents the organization of the messages of the receiver."
|
|
29 |
|
|
30 |
aClassOrg ifNotNil: [aClassOrg setSubject: self].
|
|
31 |
organization := aClassOrg
|
|
32 |
! !
|
|
33 |
|
|
34 |
!RGClassDescriptionDefinition methodsFor:'comparing'!
|
|
35 |
|
|
36 |
= aRGClassDefinition
|
|
37 |
|
|
38 |
^self class = aRGClassDefinition class
|
|
39 |
and: [ self name = aRGClassDefinition name
|
|
40 |
and: [ self environment = aRGClassDefinition environment ] ]
|
|
41 |
!
|
|
42 |
|
|
43 |
hash
|
|
44 |
|
|
45 |
^self name hash bitXor: self class hash
|
|
46 |
! !
|
|
47 |
|
|
48 |
!RGClassDescriptionDefinition methodsFor:'initialization'!
|
|
49 |
|
|
50 |
initialize
|
|
51 |
|
|
52 |
super initialize.
|
|
53 |
instanceVariables:= OrderedCollection new.
|
|
54 |
! !
|
|
55 |
|
|
56 |
!RGClassDescriptionDefinition methodsFor:'instance variables'!
|
|
57 |
|
|
58 |
addInstVarNamed: aString
|
|
59 |
| var |
|
|
60 |
var := ((self isMeta
|
|
61 |
ifTrue: [ RGClassInstanceVariableDefinition ]
|
|
62 |
ifFalse:[ RGInstanceVariableDefinition ])
|
|
63 |
named: aString) parent: self.
|
|
64 |
self addVariable: var in: instanceVariables.
|
|
65 |
^var
|
|
66 |
!
|
|
67 |
|
|
68 |
addInstanceVariable: aRGVariableDefinition
|
|
69 |
"aRGVariableDefinition is a instance variable or class instance variable"
|
|
70 |
|
|
71 |
self addVariable: (aRGVariableDefinition parent: self)
|
|
72 |
in: instanceVariables
|
|
73 |
!
|
|
74 |
|
|
75 |
addInstanceVariables: aCollection
|
|
76 |
|
|
77 |
aCollection do: [:var | self addInstVarNamed: var ]
|
|
78 |
!
|
|
79 |
|
|
80 |
allInstVarNames
|
|
81 |
|
|
82 |
^self allInstanceVariables collect:[ :ivar| ivar name ]
|
|
83 |
!
|
|
84 |
|
|
85 |
allInstanceVariables
|
|
86 |
"Answer a collection of the receiver's instanceVariables, including those defined in its superclass"
|
|
87 |
|
|
88 |
^self hasSuperclass
|
|
89 |
ifFalse:[ instanceVariables ]
|
|
90 |
ifTrue:[ self superclass allInstanceVariables, instanceVariables ]
|
|
91 |
!
|
|
92 |
|
|
93 |
instVarNames
|
|
94 |
"Answer a collection of the names of the instance variables defined in the receiver."
|
|
95 |
|
|
96 |
^instanceVariables collect:[ :ivar| ivar name ]
|
|
97 |
!
|
|
98 |
|
|
99 |
instanceVariableNamed: aString
|
|
100 |
^ instanceVariables
|
|
101 |
detect: [ :v | v name = aString asSymbol ]
|
|
102 |
ifNone: [ nil ]
|
|
103 |
!
|
|
104 |
|
5
|
105 |
instanceVariableNames: aStringOrCollection
|
|
106 |
| instanceVariableNames |
|
|
107 |
|
|
108 |
aStringOrCollection isString ifTrue:[
|
|
109 |
instanceVariableNames := ((aStringOrCollection tokensBasedOn: Character space) reject:[:e | e isEmpty])
|
|
110 |
] ifFalse:[
|
|
111 |
instanceVariableNames := aStringOrCollection.
|
|
112 |
].
|
|
113 |
instanceVariables := OrderedCollection new.
|
|
114 |
self addInstanceVariables: instanceVariableNames
|
|
115 |
|
|
116 |
"Created: / 31-08-2015 / 15:30:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
117 |
!
|
|
118 |
|
0
|
119 |
removeInstVarNamed: aString
|
|
120 |
|
|
121 |
self removeVariable: (self instanceVariableNamed: aString) from: instanceVariables
|
|
122 |
!
|
|
123 |
|
|
124 |
removeInstanceVariable: aRGVariableDefinition
|
|
125 |
"aRGVariableDefinition is a instance variable or class instance variable"
|
|
126 |
|
|
127 |
self removeVariable: aRGVariableDefinition from: instanceVariables
|
|
128 |
! !
|
|
129 |
|
|
130 |
!RGClassDescriptionDefinition methodsFor:'organization'!
|
|
131 |
|
|
132 |
organization
|
|
133 |
"Answer the instance of ClassOrganizer that represents the organization
|
|
134 |
of the messages of the receiver."
|
|
135 |
|
|
136 |
organization ifNil: [
|
|
137 |
self organization: (ClassOrganization forClass: self) ].
|
|
138 |
"Making sure that subject is set correctly. It should not be necessary."
|
|
139 |
organization ifNotNil: [ organization setSubject: self ].
|
|
140 |
^ organization
|
|
141 |
! !
|
|
142 |
|
|
143 |
!RGClassDescriptionDefinition methodsFor:'printing'!
|
|
144 |
|
|
145 |
storeOn: aStream
|
|
146 |
aStream
|
|
147 |
nextPutAll: '(';
|
|
148 |
nextPutAll: self class name;
|
|
149 |
nextPutAll: ' named: '.
|
|
150 |
name storeOn: aStream.
|
|
151 |
aStream nextPut: $)
|
|
152 |
! !
|
|
153 |
|
|
154 |
!RGClassDescriptionDefinition methodsFor:'private'!
|
|
155 |
|
|
156 |
addVariable: aRGVariableDefinition in: aCollection
|
|
157 |
"Adds a RGVariableDefinition in the collection received"
|
|
158 |
|
|
159 |
aCollection add: aRGVariableDefinition
|
|
160 |
!
|
|
161 |
|
|
162 |
removeVariable: aRGVariableDefinition from: aCollection
|
|
163 |
"Removes a variable from a particular collection.
|
|
164 |
This behavior is the same for any kind of variable"
|
|
165 |
aCollection remove: aRGVariableDefinition ifAbsent:[]
|
|
166 |
! !
|
|
167 |
|
|
168 |
!RGClassDescriptionDefinition methodsFor:'testing'!
|
|
169 |
|
|
170 |
isClass
|
|
171 |
|
|
172 |
^true
|
|
173 |
!
|
|
174 |
|
|
175 |
isSameRevisionAs: aRGClassDescriptionDefinition
|
|
176 |
"This method look for equality of the properties of the receiver"
|
|
177 |
"Instances variables are compared at the level of names but without any sorting"
|
|
178 |
|
|
179 |
^(super isSameRevisionAs: aRGClassDescriptionDefinition)
|
|
180 |
and:[ self instVarNames sort = aRGClassDescriptionDefinition instVarNames sort ]
|
|
181 |
! !
|
|
182 |
|