author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Fri, 28 Aug 2015 14:04:03 +0100 | |
changeset 1 | 24b88532f6ef |
parent 0 | 43cb9f3e345e |
child 6 | 3e34be6a5d07 |
permissions | -rw-r--r-- |
0 | 1 |
"{ Package: 'stx:goodies/ring' }" |
2 |
||
3 |
"{ NameSpace: Smalltalk }" |
|
4 |
||
5 |
RGElementDefinition subclass:#RGCommentDefinition |
|
6 |
instanceVariableNames:'content stamp' |
|
7 |
classVariableNames:'' |
|
8 |
poolDictionaries:'' |
|
9 |
category:'Ring-Core-Kernel' |
|
10 |
! |
|
11 |
||
12 |
RGCommentDefinition comment:'RGCommentDefinition is a first-class representation of class''s comments' |
|
13 |
! |
|
14 |
||
15 |
!RGCommentDefinition class methodsFor:'instance creation'! |
|
16 |
||
17 |
realClass: aClass |
|
18 |
"Creates a ring comment definition from a Smalltalk class" |
|
19 |
^(super realClass: aClass) |
|
20 |
asActive; |
|
21 |
yourself |
|
22 |
! ! |
|
23 |
||
24 |
!RGCommentDefinition methodsFor:'accessing'! |
|
25 |
||
26 |
content |
|
27 |
||
28 |
self isActive |
|
29 |
ifTrue: [ ^ self realClass organization classComment ]. |
|
30 |
self isHistorical |
|
1
24b88532f6ef
Fixes to make it stc-compilable
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
31 |
ifTrue: [ ^ self contentAtPointer ifNil:[ | rc | (rc := self realClass) ifNil:[ content ] ifNotNil:[ rc organization classComment ] ] ]. |
0 | 32 |
^ content |
33 |
! |
|
34 |
||
35 |
content: anObject |
|
36 |
||
37 |
content:= anObject |
|
38 |
! |
|
39 |
||
40 |
fullName |
|
41 |
"Keeps a unique description for the receiver. As annotation to avoid converting each time is invoked" |
|
42 |
||
43 |
^self annotationNamed: self class fullNameKey |
|
44 |
ifAbsentPut:[ (self parentName, ' ', self name) asSymbol ] |
|
45 |
! |
|
46 |
||
47 |
name |
|
48 |
||
49 |
^name ifNil:[ name := #Comment ] |
|
50 |
! |
|
51 |
||
52 |
stamp |
|
53 |
"Retrieves the user-alias + timestamp associated to the receiver (if exists)" |
|
54 |
||
55 |
self isActive |
|
56 |
ifTrue: [ ^ self realClass organization commentStamp ]. |
|
57 |
self isHistorical |
|
1
24b88532f6ef
Fixes to make it stc-compilable
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
58 |
ifTrue: [ ^ self stampAtPointer ifNil:[ | rc | (rc := self realClass) ifNil:[ stamp ] ifNotNil:[ rc organization commentStamp ] ] ]. |
0 | 59 |
^ stamp |
60 |
! |
|
61 |
||
62 |
stamp: anObject |
|
63 |
||
64 |
stamp:= anObject |
|
65 |
! ! |
|
66 |
||
67 |
!RGCommentDefinition methodsFor:'backward compatibility'! |
|
68 |
||
69 |
sourceCode |
|
70 |
||
71 |
^ self content |
|
72 |
! ! |
|
73 |
||
74 |
!RGCommentDefinition methodsFor:'comparing'! |
|
75 |
||
76 |
<= aRGCommentDefinition |
|
77 |
"Sort comment definition according to: 1) name of the class" |
|
78 |
||
79 |
^(self parentName <= aRGCommentDefinition parentName) |
|
80 |
! ! |
|
81 |
||
82 |
!RGCommentDefinition methodsFor:'printing'! |
|
83 |
||
84 |
printOn: aStream |
|
85 |
||
86 |
self parentName ifNotNil: [ |
|
87 |
aStream nextPutAll: self parentName; |
|
88 |
nextPutAll: ' ' ]. |
|
89 |
aStream nextPutAll: self name |
|
90 |
! ! |
|
91 |
||
92 |
!RGCommentDefinition methodsFor:'source pointers'! |
|
93 |
||
94 |
commentDataPointers |
|
95 |
"Retrieves the combination key to look for information of the receiver in the source file" |
|
96 |
^'commentStamp:' -> #commentStamp: |
|
97 |
! |
|
98 |
||
99 |
contentAtPointer |
|
100 |
"A RGCommentDefinition may be created to point the sourceFile in which case it retrieves the class comment" |
|
101 |
||
102 |
^ self sourcePointer notNil |
|
103 |
ifTrue: [ SourceFiles sourceCodeAt: self sourcePointer ] |
|
104 |
ifFalse:[ '' ] |
|
105 |
! |
|
106 |
||
107 |
sourcePointer |
|
108 |
"Retrieves the sourcePointer for this definition if exists" |
|
109 |
||
110 |
^self annotationNamed: self class sourcePointerKey |
|
111 |
! |
|
112 |
||
113 |
sourcePointer: aNumber |
|
114 |
||
115 |
self annotationNamed: self class sourcePointerKey put: aNumber |
|
116 |
! |
|
117 |
||
118 |
stampAtPointer |
|
119 |
"A RGMethodDefinition may be created to point the sourceFile in which case it retrieves the stamp" |
|
120 |
||
121 |
^ self sourcePointer notNil |
|
122 |
ifTrue: [ SourceFiles timeStampAt: self sourcePointer for: self commentDataPointers ] |
|
123 |
ifFalse:[ nil ] |
|
124 |
! ! |
|
125 |
||
126 |
!RGCommentDefinition methodsFor:'stamp values'! |
|
127 |
||
128 |
author |
|
129 |
||
130 |
^self annotationNamed: self class authorKey |
|
131 |
ifAbsentPut:[ self class parseAuthorAliasFrom: stamp ] |
|
132 |
! |
|
133 |
||
134 |
author: aString |
|
135 |
||
136 |
self annotationNamed: self class authorKey |
|
137 |
put: aString |
|
138 |
! |
|
139 |
||
140 |
timeStamp |
|
141 |
||
142 |
^ self annotationNamed: self class timeStampKey |
|
143 |
ifAbsentPut: [ self class |
|
144 |
parseTimestampFrom: self stamp |
|
145 |
default: (DateAndTime epoch) ] |
|
146 |
! |
|
147 |
||
148 |
timeStamp: aTimestamp |
|
149 |
||
150 |
self annotationNamed: self class timeStampKey |
|
151 |
put: aTimestamp |
|
152 |
! ! |
|
153 |
||
154 |
!RGCommentDefinition methodsFor:'testing'! |
|
155 |
||
156 |
hasAuthor |
|
157 |
||
158 |
^self hasStamp and:[ self author isEmptyOrNil not ] |
|
159 |
! |
|
160 |
||
161 |
hasStamp |
|
162 |
||
163 |
^stamp isEmptyOrNil not |
|
164 |
||
165 |
||
166 |
! |
|
167 |
||
168 |
isComment |
|
169 |
||
170 |
^true |
|
171 |
! |
|
172 |
||
173 |
isEmptyOrNil |
|
174 |
||
175 |
^content isEmptyOrNil |
|
176 |
! |
|
177 |
||
178 |
isFromTrait |
|
179 |
^false |
|
180 |
! |
|
181 |
||
182 |
isSameRevisionAs: aRGCommentDefinition |
|
183 |
"This method look for equality of the properties of the receiver" |
|
184 |
"A comment validates only its contents and not its stamp" |
|
185 |
||
186 |
^(super isSameRevisionAs: aRGCommentDefinition) |
|
187 |
and:[ self content = aRGCommentDefinition content ] |
|
188 |
! ! |
|
189 |
||
190 |
!RGCommentDefinition methodsFor:'to remove as soon as possible'! |
|
191 |
||
192 |
category |
|
193 |
^self realClass category |
|
194 |
! |
|
195 |
||
196 |
isValid |
|
197 |
"for compatibility with method definition" |
|
198 |
||
199 |
^ true |
|
200 |
! |
|
201 |
||
202 |
methodClass |
|
203 |
self flag: 'if comments are mixed with methods use #realClass instead'. |
|
204 |
^self realClass |
|
205 |
! |
|
206 |
||
207 |
selector |
|
208 |
self flag: 'if comments are mixed with methods use #name instead'. |
|
209 |
^self name |
|
210 |
! ! |
|
211 |
||
212 |
!RGCommentDefinition methodsFor:'type of comments'! |
|
213 |
||
214 |
asActive |
|
215 |
||
216 |
"Sets the receiver as active object, which will allow itself to retrieve its data from the class organization" |
|
217 |
self annotationNamed: self class statusKey put: #active. |
|
218 |
! |
|
219 |
||
220 |
asHistorical |
|
221 |
||
222 |
"Sets the receiver as historical object, which will allow itself to retrieve its data using the sourcePointer" |
|
223 |
| realClass | |
|
224 |
self annotationNamed: self class statusKey put: #historical. |
|
225 |
self sourcePointer ifNil:[ |
|
226 |
realClass := self realClass. |
|
227 |
realClass notNil ifTrue: [ |
|
1
24b88532f6ef
Fixes to make it stc-compilable
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
228 |
| str | |
24b88532f6ef
Fixes to make it stc-compilable
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
229 |
(str := realClass organization commentRemoteString) |
24b88532f6ef
Fixes to make it stc-compilable
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
230 |
ifNotNil: [ self sourcePointer: str sourcePointer ] ] ] |
0 | 231 |
! |
232 |
||
233 |
asPassive |
|
234 |
||
235 |
"Sets the receiver as passive object, which will allow itself to retrieve its data that was assigned in its creation" |
|
236 |
self annotationNamed: self class statusKey put: #passive |
|
237 |
! |
|
238 |
||
239 |
fromActiveToHistorical |
|
240 |
"If the receiver was generated as an active comment, it can be converted to a historical one by reading the data of the real class (if exists)" |
|
241 |
||
242 |
self isActive ifTrue: [ |
|
243 |
self asHistorical ] |
|
244 |
! |
|
245 |
||
246 |
fromActiveToPassive |
|
247 |
"If the receiver was generated as an active comment, it can be converted to a passive one by reading the data of the real class organization" |
|
248 |
||
249 |
| realClass | |
|
250 |
self isActive |
|
251 |
ifFalse: [ ^ self ]. |
|
252 |
realClass := self realClass. |
|
253 |
realClass notNil |
|
254 |
ifTrue: [ |
|
255 |
self content: realClass organization classComment. |
|
256 |
self stamp: realClass organization commentStamp ]. |
|
257 |
self asPassive |
|
258 |
! |
|
259 |
||
260 |
isActive |
|
1
24b88532f6ef
Fixes to make it stc-compilable
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
261 |
"A ring comment isActive when it needs to access the class organization for retrieving its data" |
0 | 262 |
|
1
24b88532f6ef
Fixes to make it stc-compilable
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
263 |
| status | |
24b88532f6ef
Fixes to make it stc-compilable
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
264 |
|
24b88532f6ef
Fixes to make it stc-compilable
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
265 |
^(status := self annotationNamed: self class statusKey) |
0 | 266 |
ifNil:[ false ] |
1
24b88532f6ef
Fixes to make it stc-compilable
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
267 |
ifNotNil:[ status == #active ] |
0 | 268 |
! |
269 |
||
270 |
isHistorical |
|
1
24b88532f6ef
Fixes to make it stc-compilable
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
271 |
"A ring comment can be used to point an old version of the receiver, in this case it will use the sourcePointer to retrieve its information" |
0 | 272 |
|
1
24b88532f6ef
Fixes to make it stc-compilable
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
273 |
| status | |
24b88532f6ef
Fixes to make it stc-compilable
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
274 |
|
0 | 275 |
^(self annotationNamed: self class statusKey) |
276 |
ifNil:[ false ] |
|
1
24b88532f6ef
Fixes to make it stc-compilable
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
277 |
ifNotNil:[ status == #historical ] |
0 | 278 |
! |
279 |
||
280 |
isPassive |
|
1
24b88532f6ef
Fixes to make it stc-compilable
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
281 |
"A ring comment isPassive by default. In this case it will retrieve the data that was assigned in its creation" |
0 | 282 |
|
1
24b88532f6ef
Fixes to make it stc-compilable
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
283 |
| status | |
24b88532f6ef
Fixes to make it stc-compilable
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
284 |
|
24b88532f6ef
Fixes to make it stc-compilable
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
285 |
^(status := self annotationNamed: self class statusKey) |
0 | 286 |
ifNil:[ true ] |
1
24b88532f6ef
Fixes to make it stc-compilable
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
0
diff
changeset
|
287 |
ifNotNil:[ status == #passive ] |
0 | 288 |
! ! |
289 |