0
|
1 |
"{ Package: 'stx:goodies/ring' }"
|
|
2 |
|
|
3 |
"{ NameSpace: Smalltalk }"
|
|
4 |
|
|
5 |
RGDefinition subclass:#RGElementDefinition
|
|
6 |
instanceVariableNames:'parent'
|
|
7 |
classVariableNames:''
|
|
8 |
poolDictionaries:''
|
|
9 |
category:'Ring-Core-Kernel'
|
|
10 |
!
|
|
11 |
|
|
12 |
RGElementDefinition comment:'RGElementDefinition is the abstract class for representing elements of a class-alike definition (i.e., methods, variables, comment).
parent holds the RGClassDefinition or RGMetaclassDefinition defining this element.
Now a RingEntityDefinition offers two APIs: one that is generic and works for all the source code entities and this is the one we just
presented: parent, parentName and realParent. Having such interface is important to build generic tools that could manipulate
any entities in a polymorphic way (yes no isKindOf: everywhere).
In addition, a ring method definition offers a specific interface that should only be used when you know that you are solely manipulate
specific entity such as class element: method definition, class comment, and variables.
Here is the equivalence table
realParent realClass
parent ringClass
parentName className
For example for a methodDefinition we will have the following:
GENERIC API
------------------
* To access the ring class definition name, use parentName
aRGMethodDefinition parentName
Example:
(Point>>#dist:) asRingDefinition parentName
-> #Point
* If you have a complete model where classes and methods are ring definition, to access the ring class definition , use parent
aRGMethodDefinition parent
Example:
aRGMethodDefinition(Point>>#dist:) parent
-> aRGClassDefinition(Point)
* If you want to access the smalltalk class that contains the compiledMethod that is represented by a ringMethodDefinition, use realParent
aRGMethodDefinition realParent
Example:
(Point>>#dist:) asRingDefinition realParent
-> Point
CLASS Element specific API
------------------------------------------
* The message class returns the class of the object :). Yes as you see we could not use class and className because class is already used to refer to the class of the object.
Example:
(Point>>#dist:) asRingDefinition class
-> RingMethodDefinition
* The message className returns the name of the ring class defining the reingMethodDefinition.
Example:
(Point>>#dist:) asRingDefinition className
-> #Point
* If you have a complete model where classes and methods are ring definition, to access the ring class definition , use parent
aRGMethodDefinition ringClass
Example:
aRGMethodDefinition(Point>>#dist:) ringClass
-> aRGClassDefinition(Point)
* If you want to access the smalltalk class that contains the compiledMethod that is represented by a ringMethodDefinition, use realClass
aRGMethodDefinition realClass
Example:
(Point>>#dist:) asRingDefinition realClass
-> Point
'
|
|
13 |
!
|
|
14 |
|
|
15 |
!RGElementDefinition class methodsFor:'class initialization'!
|
|
16 |
|
|
17 |
class: aRGBehaviorDefinition
|
|
18 |
"The argument is a ring object and serves as the parent of a method, variable or class comment"
|
|
19 |
|
|
20 |
^self new
|
|
21 |
parent: aRGBehaviorDefinition;
|
|
22 |
yourself
|
|
23 |
!
|
|
24 |
|
|
25 |
realClass: aClass
|
|
26 |
"The argument is a Smalltalk class and the parent of a method, variable, class comment.
|
|
27 |
However it is not set as parent but only its name and scope (instance/class)"
|
|
28 |
|
|
29 |
^self new
|
|
30 |
parent: aClass asRingDefinition;
|
|
31 |
yourself
|
|
32 |
! !
|
|
33 |
|
|
34 |
!RGElementDefinition class methodsFor:'elements-annotations'!
|
|
35 |
|
|
36 |
classNameKey
|
|
37 |
|
|
38 |
^#className
|
|
39 |
!
|
|
40 |
|
|
41 |
isMetaSideKey
|
|
42 |
|
|
43 |
^#isMetaSide
|
|
44 |
!
|
|
45 |
|
|
46 |
sourcePointerKey
|
|
47 |
|
|
48 |
^#sourcePointer
|
|
49 |
!
|
|
50 |
|
|
51 |
statusKey
|
|
52 |
|
|
53 |
^#statusKey
|
|
54 |
! !
|
|
55 |
|
|
56 |
!RGElementDefinition class methodsFor:'parsing stamp'!
|
|
57 |
|
|
58 |
basicParseAuthorAliasFrom: aString
|
|
59 |
"Parse an alias/name of the author from a string that is extracted from a source file. If there is no alias/name we return emtpy string."
|
|
60 |
|
|
61 |
| tokens dateStartIndex unknown |
|
|
62 |
"The following timestamp strings are supported (source: squeak sources archeological survey):
|
|
63 |
<authorname><date><time>.
|
|
64 |
<authorname><date>
|
|
65 |
<date><time>
|
|
66 |
<date><time><authorname>
|
|
67 |
<date><authorname>
|
|
68 |
<historical>
|
|
69 |
All fields can be separated by spaces or line ends but a separator between author alias/name and date can be missing as well"
|
|
70 |
"unknown:= 'unknown'."
|
|
71 |
unknown := nil.
|
|
72 |
aString isEmptyOrNil
|
|
73 |
ifTrue: [ ^ unknown ].
|
|
74 |
dateStartIndex := (aString indexOf: $/) - 1. "If there is no / character in the timestamp, no author alias/name exists"
|
|
75 |
dateStartIndex = -1
|
|
76 |
ifTrue: [ ^ unknown ].
|
|
77 |
^ [
|
|
78 |
"Go the start of the date string (there can be 1 or 2 digits and a space separator can be missing at the front!!!!)"
|
|
79 |
(dateStartIndex >= 2 and: [ (aString at: dateStartIndex - 1) isDigit ])
|
|
80 |
ifTrue: [ dateStartIndex := dateStartIndex - 1 ]. "Extract only those tokens that do not possible represent date or time - meaning that authorname may be at the end"
|
|
81 |
tokens := (aString copyFrom: dateStartIndex to: aString size) substrings
|
|
82 |
reject: [ :token | (token occurrencesOf: $/) = 2 or: [ (token occurrencesOf: $:) = 1 ] ]. "only one token should be left if author name/alias exists"
|
|
83 |
^ tokens isEmpty
|
|
84 |
ifTrue: [
|
|
85 |
"if dateStartIndex is not 1 then the authorname may be at the beginning"
|
|
86 |
dateStartIndex > 1
|
|
87 |
ifTrue: [ (aString copyFrom: 1 to: dateStartIndex - 1) trimBoth ]
|
|
88 |
ifFalse: [ unknown ] ]
|
|
89 |
ifFalse: [ tokens first ] ]
|
|
90 |
on: Exception
|
|
91 |
do: [ :e | unknown ]
|
|
92 |
!
|
|
93 |
|
|
94 |
parseAuthorAliasFrom: aString
|
|
95 |
"Allows other applications to treat a different empty alias by overriding this method"
|
|
96 |
|
|
97 |
^self basicParseAuthorAliasFrom: aString
|
|
98 |
!
|
|
99 |
|
|
100 |
parseTimestampFrom: aString
|
|
101 |
|
|
102 |
^self parseTimestampFrom: aString default: nil
|
|
103 |
!
|
|
104 |
|
|
105 |
parseTimestampFrom: aString default: anObject
|
|
106 |
"Parse a date-time from a timestamp-string that is extracted from a source file. If there is no timestamp, or we cannot make sense of it, we return the default value."
|
|
107 |
|
|
108 |
| tokens dateStartIndex unknown |
|
|
109 |
"The following timestamp strings are supported (source: squeak sources archeological survey):
|
|
110 |
<authorname><date><time>.
|
|
111 |
<authorname><date>
|
|
112 |
<date><time>
|
|
113 |
<date><time><authorname>
|
|
114 |
<date><authorname>
|
|
115 |
<historical>
|
|
116 |
All fields can be separated by spaces or line ends but a separator between authorname and date can be missing as well"
|
|
117 |
unknown := anObject.
|
|
118 |
aString isEmptyOrNil
|
|
119 |
ifTrue: [ ^ unknown ].
|
|
120 |
dateStartIndex := (aString indexOf: $/) - 1. "If there is no / character in the timestamp, we cannot parse a date and return the epoch"
|
|
121 |
dateStartIndex = -1
|
|
122 |
ifTrue: [ ^ unknown ].
|
|
123 |
^ [
|
|
124 |
"Go the start of the date string (there can be 1 or 2 digits and a space separator can be missing at the front!!!!)"
|
|
125 |
(dateStartIndex >= 2 and: [ (aString at: dateStartIndex - 1) isDigit ])
|
|
126 |
ifTrue: [ dateStartIndex := dateStartIndex - 1 ]. "Extract only those tokens that possibly represent date or time"
|
|
127 |
tokens := (aString copyFrom: dateStartIndex to: aString size) substrings
|
|
128 |
select: [ :token | (token occurrencesOf: $/) = 2 or: [ (token occurrencesOf: $:) = 1 ] ]. "2 tokens is a datetime"
|
|
129 |
tokens size = 2
|
|
130 |
ifTrue: [ (tokens joinUsing: Character space) asDateAndTime ]
|
|
131 |
ifFalse: [ tokens first asDate asDateAndTime ] ]
|
|
132 |
on: Exception
|
|
133 |
do: [ :e | unknown ]
|
|
134 |
! !
|
|
135 |
|
|
136 |
!RGElementDefinition methodsFor:'accessing'!
|
|
137 |
|
|
138 |
fullName: aString
|
|
139 |
|
|
140 |
^ self annotationNamed: self class fullNameKey put: aString asSymbol
|
|
141 |
!
|
|
142 |
|
|
143 |
isMetaSide
|
|
144 |
"Even thought several class elements do not define this property (ie. class variables, pool variables) they understand it"
|
|
145 |
"This is a derived property from the class definining the receiver and thus its value is kept as an annotation"
|
|
146 |
"Default value is false"
|
|
147 |
|
|
148 |
^self annotationNamed: self class isMetaSideKey ifAbsentPut: [ false ]
|
|
149 |
!
|
|
150 |
|
|
151 |
isMetaSide: aBoolean
|
|
152 |
|
|
153 |
self annotationNamed: self class isMetaSideKey put: aBoolean
|
|
154 |
!
|
|
155 |
|
|
156 |
package
|
|
157 |
^self parent package
|
|
158 |
! !
|
|
159 |
|
|
160 |
!RGElementDefinition methodsFor:'backward compatibility'!
|
|
161 |
|
|
162 |
actualClass
|
|
163 |
"returns the Smalltalk class of the receiver"
|
|
164 |
|
|
165 |
^ self realClass
|
|
166 |
! !
|
|
167 |
|
|
168 |
!RGElementDefinition methodsFor:'class element specific api'!
|
|
169 |
|
|
170 |
className
|
|
171 |
|
|
172 |
^ self parentName
|
|
173 |
!
|
|
174 |
|
|
175 |
className: aName
|
|
176 |
|
|
177 |
^ self parentName: aName
|
|
178 |
!
|
|
179 |
|
|
180 |
realClass
|
|
181 |
"Retrieves the Class/Trait/.. object in the System corresponding to the class of the this element."
|
|
182 |
|
|
183 |
^ self realParent
|
|
184 |
!
|
|
185 |
|
|
186 |
ringClass
|
|
187 |
"Return the ring definition of the class containing the receiver."
|
|
188 |
|
|
189 |
^ self parent
|
|
190 |
!
|
|
191 |
|
|
192 |
theNonMetaClassName
|
|
193 |
|
|
194 |
^self theNonMetaParentName
|
|
195 |
! !
|
|
196 |
|
|
197 |
!RGElementDefinition methodsFor:'comparing'!
|
|
198 |
|
|
199 |
= aRGElementDefinition
|
|
200 |
"This method look for equality of the properties of the receiver"
|
|
201 |
"Verifies the class and the parentName of the receiver"
|
|
202 |
|
|
203 |
^self class = aRGElementDefinition class
|
|
204 |
and:[ self parentName == aRGElementDefinition parentName
|
|
205 |
and:[ self isMetaSide = aRGElementDefinition isMetaSide ] ]
|
|
206 |
!
|
|
207 |
|
|
208 |
hash
|
|
209 |
"Hash is re-implemented because #= is re-implemented"
|
|
210 |
|
|
211 |
^self class hash bitXor: (self parentName hash bitXor: self isMetaSide hash)
|
|
212 |
! !
|
|
213 |
|
|
214 |
!RGElementDefinition methodsFor:'generic parent api'!
|
|
215 |
|
|
216 |
parent
|
|
217 |
"The parent of a class definition element: method, comment and variable is the class definition. This method retrieves the class that defines such element"
|
|
218 |
|
|
219 |
^ parent
|
|
220 |
!
|
|
221 |
|
|
222 |
parent: aRGBehaviorDefinition
|
|
223 |
"Set the class associated to the receiver"
|
|
224 |
|
|
225 |
parent := aRGBehaviorDefinition.
|
|
226 |
self setParentInfo: aRGBehaviorDefinition.
|
|
227 |
!
|
|
228 |
|
|
229 |
parentName
|
|
230 |
"Retrieves the name of the class defining the receiver. Its value is kept as an annotation"
|
|
231 |
|
|
232 |
^ self annotationNamed: self class classNameKey
|
|
233 |
!
|
|
234 |
|
|
235 |
parentName: aString
|
|
236 |
|
|
237 |
self annotationNamed: self class classNameKey put: aString asSymbol
|
|
238 |
!
|
|
239 |
|
|
240 |
realParent
|
|
241 |
"Retrieves the Class/Trait/.. object in the System corresponding to the class of the this element."
|
|
242 |
|
|
243 |
^self parent notNil
|
|
244 |
ifTrue: [ self parent realClass ]
|
|
245 |
ifFalse: [ self rootEnvironment classNamed: self parentName ]
|
|
246 |
!
|
|
247 |
|
|
248 |
theNonMetaParentName
|
|
249 |
"Rejects the prefix ' class' or ' classTrait' of the parentName"
|
|
250 |
| index |
|
|
251 |
|
|
252 |
index := self parentName
|
|
253 |
indexOfSubCollection: ' class'
|
|
254 |
startingAt: 1
|
|
255 |
ifAbsent: [ ^self parentName ].
|
|
256 |
|
|
257 |
^(self parentName
|
|
258 |
copyFrom: 1
|
|
259 |
to: index - 1) asSymbol
|
|
260 |
! !
|
|
261 |
|
|
262 |
!RGElementDefinition methodsFor:'private'!
|
|
263 |
|
|
264 |
setParentInfo: anObject
|
|
265 |
"anObject is aRGBehaviorDefinition or aClass/aTrait"
|
|
266 |
|
|
267 |
self parentName: anObject name.
|
|
268 |
self isMetaSide: anObject isMeta
|
|
269 |
! !
|
|
270 |
|
|
271 |
!RGElementDefinition methodsFor:'testing'!
|
|
272 |
|
|
273 |
isDefined
|
|
274 |
"isDefined when the receiver has its realClass defined in the system"
|
|
275 |
|
|
276 |
^self realClass notNil
|
|
277 |
!
|
|
278 |
|
|
279 |
isSameRevisionAs: aRGElementDefinition
|
|
280 |
"This method look for equality of the properties of the receiver"
|
|
281 |
"Verifies the class and the parentName of the receiver"
|
|
282 |
|
|
283 |
^self class = aRGElementDefinition class
|
|
284 |
and:[ self parentName == aRGElementDefinition parentName ]
|
|
285 |
! !
|
|
286 |
|