0
|
1 |
"{ Package: 'stx:goodies/ring' }"
|
|
2 |
|
|
3 |
"{ NameSpace: Smalltalk }"
|
|
4 |
|
|
5 |
RGContainer subclass:#RGPackage
|
|
6 |
instanceVariableNames:'package'
|
|
7 |
classVariableNames:''
|
|
8 |
poolDictionaries:''
|
|
9 |
category:'Ring-Core-Containers'
|
|
10 |
!
|
|
11 |
|
|
12 |
RGPackage comment:'RGPackage is the representation for packages.
A package manages classes, methods and children packages as elements.
A package can also know in which package is defined
'
|
|
13 |
!
|
|
14 |
|
|
15 |
!RGPackage methodsFor:'accessing'!
|
|
16 |
|
|
17 |
categories
|
|
18 |
"Retrieves class categories of the receiver"
|
|
19 |
|
|
20 |
^self elements at: #categories
|
|
21 |
!
|
|
22 |
|
|
23 |
categories: aCollection
|
|
24 |
"Set the class categories collection"
|
|
25 |
|
|
26 |
self elements at: #categories put: (aCollection asOrderedCollection)
|
|
27 |
!
|
|
28 |
|
|
29 |
classNames
|
|
30 |
|
|
31 |
^ self classes isDictionary
|
|
32 |
ifTrue: [ self classes keys ]
|
|
33 |
ifFalse:[ self classes collect:[ :class| class name ] ]
|
|
34 |
!
|
|
35 |
|
|
36 |
classes
|
|
37 |
"Retrieves a collection (by default a dictionary) of classes defined in the receiver and classes holding extension methods"
|
|
38 |
|
|
39 |
^self definedClasses, self extendedClasses
|
|
40 |
!
|
|
41 |
|
|
42 |
definedClassNames
|
|
43 |
|
|
44 |
^ super classNames
|
|
45 |
!
|
|
46 |
|
|
47 |
definedTraits
|
|
48 |
"Retrieves the traits defined in the receiver"
|
|
49 |
|
|
50 |
^self traits
|
|
51 |
!
|
|
52 |
|
|
53 |
extendedClassNames
|
|
54 |
|
|
55 |
^ self extendedClasses isDictionary
|
|
56 |
ifTrue: [ self extendedClasses keys ]
|
|
57 |
ifFalse:[ self extendedClasses collect:[ :each| each name ]]
|
|
58 |
!
|
|
59 |
|
|
60 |
extendedClasses
|
|
61 |
"Retrieves the classes holding the extension methods and returns a dictionary as well"
|
|
62 |
| classesOfExt |
|
|
63 |
classesOfExt := Dictionary new.
|
|
64 |
|
|
65 |
self extensionMethods
|
|
66 |
do:[ :mth| (classesOfExt includesKey: mth parentName)
|
|
67 |
ifFalse:[ classesOfExt at: mth parentName put: mth parent ] ].
|
|
68 |
|
|
69 |
^classesOfExt
|
|
70 |
!
|
|
71 |
|
|
72 |
extendedSelectors
|
|
73 |
"Retrieves the names of the methods"
|
|
74 |
|
|
75 |
^ self extensionMethods keys
|
|
76 |
!
|
|
77 |
|
|
78 |
extensionMethods
|
|
79 |
"Retrieves extension methods"
|
|
80 |
|
|
81 |
^self elements at: #extensionMethods
|
|
82 |
!
|
|
83 |
|
|
84 |
extensionMethods: aCollection
|
|
85 |
"Set the extension methods collection"
|
|
86 |
|
|
87 |
self elements at: #extensionMethods put: aCollection
|
|
88 |
!
|
|
89 |
|
|
90 |
methods
|
|
91 |
"Retrieves all the methods defined in the receiver.
|
|
92 |
#methods holds the methods of defined classes"
|
|
93 |
|
|
94 |
^super methods, self extensionMethods
|
|
95 |
!
|
|
96 |
|
|
97 |
package
|
|
98 |
"Retrieves the package in which self is contained"
|
|
99 |
|
|
100 |
^package
|
|
101 |
!
|
|
102 |
|
|
103 |
package: aRGPackage
|
|
104 |
"Sets the outer package of the receiver if exists"
|
|
105 |
|
|
106 |
package:= aRGPackage
|
|
107 |
!
|
|
108 |
|
|
109 |
parent
|
|
110 |
"Retrieves the environment linked to this package"
|
|
111 |
|
|
112 |
^self environment
|
|
113 |
! !
|
|
114 |
|
|
115 |
!RGPackage methodsFor:'adding/removing'!
|
|
116 |
|
|
117 |
addElement: aRGDefinition in: aCollection
|
|
118 |
|
|
119 |
aRGDefinition package: self.
|
|
120 |
super addElement: aRGDefinition in: aCollection.
|
|
121 |
!
|
|
122 |
|
|
123 |
addMethod: aRGMethodDefinition
|
|
124 |
"aRGMethodDefinition needs to satisfy the status isMethod"
|
|
125 |
|
|
126 |
aRGMethodDefinition isMethod ifFalse:[ ^self ].
|
|
127 |
aRGMethodDefinition package: self. "Needed to evaluate #isExtension if it was not set in advance"
|
|
128 |
self
|
|
129 |
addElement: aRGMethodDefinition
|
|
130 |
in: (aRGMethodDefinition isExtension
|
|
131 |
ifTrue: [ self extensionMethods ]
|
|
132 |
ifFalse:[ super methods ])
|
|
133 |
!
|
|
134 |
|
|
135 |
removeMethod: aRGMethodDefinition
|
|
136 |
|
|
137 |
self
|
|
138 |
removeElement: aRGMethodDefinition
|
|
139 |
from: (aRGMethodDefinition isExtension
|
|
140 |
ifTrue: [ self extensionMethods ]
|
|
141 |
ifFalse:[ super methods ])
|
|
142 |
!
|
|
143 |
|
|
144 |
withoutCategories
|
|
145 |
|
|
146 |
self removeElementsCategorized: #categories
|
|
147 |
! !
|
|
148 |
|
|
149 |
!RGPackage methodsFor:'initialization'!
|
|
150 |
|
|
151 |
initialize
|
|
152 |
|
|
153 |
super initialize.
|
5
|
154 |
self withoutPackages. "By default the receiver has no child packages"
|
|
155 |
self extensionMethods: Dictionary new.
|
0
|
156 |
self categories: OrderedCollection new.
|
5
|
157 |
|
|
158 |
"Modified: / 02-09-2015 / 12:02:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
0
|
159 |
! !
|
|
160 |
|
|
161 |
!RGPackage methodsFor:'lookup'!
|
|
162 |
|
|
163 |
lookupClassNamed: className
|
|
164 |
"Look for the class named className in the receiver's defined classes or in any of its package children"
|
|
165 |
| class |
|
|
166 |
|
|
167 |
class:= self classNamed: className.
|
|
168 |
class ifNotNil:[ ^class ].
|
|
169 |
|
|
170 |
self packages
|
|
171 |
do:[ :each| class:= each lookupClassNamed: className.
|
|
172 |
class ifNotNil:[ ^class ] ].
|
|
173 |
^nil
|
|
174 |
! !
|
|
175 |
|
|
176 |
!RGPackage methodsFor:'managing container'!
|
|
177 |
|
|
178 |
addInContainer: anRGContainer
|
|
179 |
|
|
180 |
anRGContainer addPackage: self
|
|
181 |
! !
|
|
182 |
|
|
183 |
!RGPackage methodsFor:'metrics'!
|
|
184 |
|
|
185 |
numberOfLinesOfCode
|
|
186 |
|
|
187 |
^ self
|
|
188 |
annotationNamed: #numberOfLinesOfCode
|
|
189 |
ifAbsentPut: [
|
|
190 |
| number |
|
|
191 |
number := self classes inject: 0 into: [ :sum :each | sum + each numberOfLinesOfCode + each theMetaClass numberOfLinesOfCode ].
|
|
192 |
number := self methods inject: number into: [ :sum :each | sum + each numberOfLinesOfCode ].
|
|
193 |
number ]
|
|
194 |
! !
|
|
195 |
|
|
196 |
!RGPackage methodsFor:'printing'!
|
|
197 |
|
|
198 |
printOn: aStream
|
|
199 |
aStream
|
|
200 |
nextPutAll: self class name;
|
|
201 |
nextPutAll: '(';
|
|
202 |
nextPutAll: self name;
|
|
203 |
nextPutAll: ')'
|
|
204 |
! !
|
|
205 |
|
|
206 |
!RGPackage methodsFor:'testing'!
|
|
207 |
|
|
208 |
definesClass: aRGBehaviorDefinition
|
|
209 |
"Returns true if the receiver includes aRGBehaviorDefinition in the defined classes"
|
|
210 |
|
|
211 |
^ self includesClass: aRGBehaviorDefinition
|
|
212 |
!
|
|
213 |
|
|
214 |
definesOrExtendsClass: aRGBehaviorDefinition
|
|
215 |
"Returns true whether the class, aRGBehaviorDefinition, is one locally defined classes of the receiver or
|
|
216 |
if the receiver extends such class (that is defined in another package)"
|
|
217 |
|
|
218 |
^ (self definesClass: aRGBehaviorDefinition) or:[ self extendsClass: aRGBehaviorDefinition ]
|
|
219 |
!
|
|
220 |
|
|
221 |
extendsClass: aRGBehaviorDefinition
|
|
222 |
"Returns true if the receiver extends aRGBehaviorDefinition (that is defined in another package)"
|
|
223 |
|
|
224 |
^ self extendedClasses includes: aRGBehaviorDefinition
|
|
225 |
!
|
|
226 |
|
|
227 |
isPackage
|
|
228 |
|
|
229 |
^true
|
|
230 |
! !
|
|
231 |
|