-
-
Notifications
You must be signed in to change notification settings - Fork 353
/
RGElementDefinition.class.st
382 lines (292 loc) · 11.8 KB
/
RGElementDefinition.class.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
"
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
"
Class {
#name : #RGElementDefinition,
#superclass : #RGDefinition,
#instVars : [
'parent'
],
#category : #'Ring-Definitions-Core-Base'
}
{ #category : #'parsing stamp' }
RGElementDefinition class >> basicParseAuthorAliasFrom: aString [
"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."
| tokens dateStartIndex unknown |
"The following timestamp strings are supported:
<authorname><date><time>.
<authorname><date>
<date><time>
<date><time><authorname>
<date><authorname>
<historical>
All fields can be separated by spaces or line ends but a separator between author alias/name and date can be missing as well"
"unknown:= 'unknown'."
unknown := nil.
aString isEmptyOrNil
ifTrue: [ ^ unknown ].
dateStartIndex := (aString indexOf: $/) - 1. "If there is no / character in the timestamp, no author alias/name exists"
dateStartIndex = -1
ifTrue: [ ^ unknown ].
^ [
"Go the start of the date string (there can be 1 or 2 digits and a space separator can be missing at the front!!)"
(dateStartIndex >= 2 and: [ (aString at: dateStartIndex - 1) isDigit ])
ifTrue: [ dateStartIndex := dateStartIndex - 1 ]. "Extract only those tokens that do not possible represent date or time - meaning that authorname may be at the end"
tokens := (aString copyFrom: dateStartIndex to: aString size) substrings
reject: [ :token | (token occurrencesOf: $/) = 2 or: [ (token occurrencesOf: $:) = 1 ] ]. "only one token should be left if author name/alias exists"
^ tokens isEmpty
ifTrue: [
"if dateStartIndex is not 1 then the authorname may be at the beginning"
dateStartIndex > 1
ifTrue: [ (aString copyFrom: 1 to: dateStartIndex - 1) trimBoth ]
ifFalse: [ unknown ] ]
ifFalse: [ tokens first ] ]
on: Exception
do: [ :e | unknown ]
]
{ #category : #'class initialization' }
RGElementDefinition class >> class: aRGBehaviorDefinition [
"The argument is a ring object and serves as the parent of a method, variable or class comment"
^self new
parent: aRGBehaviorDefinition;
yourself
]
{ #category : #'elements-annotations' }
RGElementDefinition class >> classNameKey [
^#className
]
{ #category : #'elements-annotations' }
RGElementDefinition class >> isMetaSideKey [
^#isMetaSide
]
{ #category : #'parsing stamp' }
RGElementDefinition class >> parseAuthorAliasFrom: aString [
"Allows other applications to treat a different empty alias by overriding this method"
^self basicParseAuthorAliasFrom: aString
]
{ #category : #'parsing stamp' }
RGElementDefinition class >> parseTimestampFrom: aString [
^self parseTimestampFrom: aString default: nil
]
{ #category : #'parsing stamp' }
RGElementDefinition class >> parseTimestampFrom: aString default: anObject [
"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."
| tokens dateStartIndex unknown |
"The following timestamp strings are supported:
<authorname><date><time>.
<authorname><date>
<date><time>
<date><time><authorname>
<date><authorname>
<historical>
All fields can be separated by spaces or line ends but a separator between authorname and date can be missing as well"
unknown := anObject.
aString isEmptyOrNil
ifTrue: [ ^ unknown ].
dateStartIndex := (aString indexOf: $/) - 1. "If there is no / character in the timestamp, we cannot parse a date and return the epoch"
dateStartIndex = -1
ifTrue: [ ^ unknown ].
^ [
"Go the start of the date string (there can be 1 or 2 digits and a space separator can be missing at the front!!)"
(dateStartIndex >= 2 and: [ (aString at: dateStartIndex - 1) isDigit ])
ifTrue: [ dateStartIndex := dateStartIndex - 1 ]. "Extract only those tokens that possibly represent date or time"
tokens := (aString copyFrom: dateStartIndex to: aString size) substrings
select: [ :token | (token occurrencesOf: $/) = 2 or: [ (token occurrencesOf: $:) = 1 ] ]. "2 tokens is a datetime"
tokens size = 2
ifTrue: [ (tokens joinUsing: Character space) asDateAndTime ]
ifFalse: [ tokens first asDate asDateAndTime ] ]
on: Exception
do: [ :e | unknown ]
]
{ #category : #'class initialization' }
RGElementDefinition class >> realClass: aClass [
"The argument is a Smalltalk class and the parent of a method, variable, class comment.
However it is not set as parent but only its name and scope (instance/class)"
^self new
parent: aClass asRingDefinition;
yourself
]
{ #category : #'elements-annotations' }
RGElementDefinition class >> sourcePointerKey [
^#sourcePointer
]
{ #category : #'elements-annotations' }
RGElementDefinition class >> statusKey [
^#statusKey
]
{ #category : #comparing }
RGElementDefinition >> = aRGElementDefinition [
"This method look for equality of the properties of the receiver"
"Verifies the class and the parentName of the receiver"
^self class = aRGElementDefinition class
and:[ self parentName == aRGElementDefinition parentName
and:[ self isMetaSide = aRGElementDefinition isMetaSide ] ]
]
{ #category : #'backward compatibility' }
RGElementDefinition >> actualClass [
"returns the Smalltalk class of the receiver"
^ self realClass
]
{ #category : #'class element specific api' }
RGElementDefinition >> className [
^ self parentName
]
{ #category : #'class element specific api' }
RGElementDefinition >> className: aName [
^ self parentName: aName
]
{ #category : #accessing }
RGElementDefinition >> fullName: aString [
^ self annotationNamed: self class fullNameKey put: aString asSymbol
]
{ #category : #comparing }
RGElementDefinition >> hash [
"Hash is re-implemented because #= is re-implemented"
^self class hash bitXor: (self parentName hash bitXor: self isMetaSide hash)
]
{ #category : #'generic parent api' }
RGElementDefinition >> instanceSideParentName [
"Rejects the prefix ' class' or ' classTrait' of the parentName"
| index |
index := self parentName
indexOfSubCollection: ' class'
startingAt: 1
ifAbsent: [ ^self parentName ].
^(self parentName
copyFrom: 1
to: index - 1) asSymbol
]
{ #category : #testing }
RGElementDefinition >> isDefined [
"isDefined when the receiver has its realClass defined in the system"
^self realClass notNil
]
{ #category : #accessing }
RGElementDefinition >> isMetaSide [
"Even thought several class elements do not define this property (ie. class variables, pool variables) they understand it"
"This is a derived property from the class definining the receiver and thus its value is kept as an annotation"
"Default value is false"
^self annotationNamed: self class isMetaSideKey ifAbsentPut: [ false ]
]
{ #category : #accessing }
RGElementDefinition >> isMetaSide: aBoolean [
self annotationNamed: self class isMetaSideKey put: aBoolean
]
{ #category : #testing }
RGElementDefinition >> isSameRevisionAs: aRGElementDefinition [
"This method look for equality of the properties of the receiver"
"Verifies the class and the parentName of the receiver"
^self class = aRGElementDefinition class
and:[ self parentName == aRGElementDefinition parentName ]
]
{ #category : #accessing }
RGElementDefinition >> package [
^ self parent ifNotNil: [ :p | p package ]
]
{ #category : #'generic parent api' }
RGElementDefinition >> parent [
"The parent of a class definition element: method, comment and variable is the class definition. This method retrieves the class that defines such element"
^ parent
]
{ #category : #'generic parent api' }
RGElementDefinition >> parent: aRGBehaviorDefinition [
"Set the class associated to the receiver"
parent := aRGBehaviorDefinition.
self setParentInfo: aRGBehaviorDefinition.
]
{ #category : #'generic parent api' }
RGElementDefinition >> parentName [
"Retrieves the name of the class defining the receiver. Its value is kept as an annotation"
^ self annotationNamed: self class classNameKey
]
{ #category : #'generic parent api' }
RGElementDefinition >> parentName: aString [
self annotationNamed: self class classNameKey put: aString asSymbol
]
{ #category : #'class element specific api' }
RGElementDefinition >> realClass [
"Retrieves the Class/Trait/.. object in the System corresponding to the class of the this element."
^ self realParent
]
{ #category : #'generic parent api' }
RGElementDefinition >> realParent [
"Retrieves the Class/Trait/.. object in the System corresponding to the class of the this element."
^self parent notNil
ifTrue: [ self parent realClass ]
ifFalse: [ self rootEnvironment classNamed: self parentName ]
]
{ #category : #'class element specific api' }
RGElementDefinition >> ringClass [
"Return the ring definition of the class containing the receiver."
^ self parent
]
{ #category : #private }
RGElementDefinition >> setParentInfo: anObject [
"anObject is aRGBehaviorDefinition or aClass/aTrait"
self parentName: anObject name.
self isMetaSide: anObject isMeta
]
{ #category : #deprecated }
RGElementDefinition >> theNonMetaClassName [
^self instanceSideParentName
]
{ #category : #deprecated }
RGElementDefinition >> theNonMetaParentName [
"Rejects the prefix ' class' or ' classTrait' of the parentName"
| index |
index := self parentName
indexOfSubCollection: ' class'
startingAt: 1
ifAbsent: [ ^self parentName ].
^(self parentName
copyFrom: 1
to: index - 1) asSymbol
]