author | Claus Gittinger <cg@exept.de> |
Sun, 01 Mar 2015 02:06:15 +0100 | |
changeset 976 | eba7baca1ed0 |
parent 960 | f7640c71d77a |
child 1035 | fb88d1d65df6 |
child 1098 | 620da38786b6 |
permissions | -rw-r--r-- |
41 | 1 |
"{ Package: 'stx:goodies/monticello' }" |
2 |
||
3 |
MCSnapshotReader subclass:#MCStReader |
|
4 |
instanceVariableNames:'' |
|
5 |
classVariableNames:'' |
|
6 |
poolDictionaries:'' |
|
684 | 7 |
category:'SCM-Monticello-Chunk Format' |
41 | 8 |
! |
9 |
||
796 | 10 |
!MCStReader class methodsFor:'documentation'! |
11 |
||
12 |
documentation |
|
13 |
" |
|
14 |
I read Category/Classes/Methodes/.... definitions from Monticello source.st file format. |
|
15 |
||
16 |
See also MCStWriter. |
|
17 |
||
18 |
Example: |
|
19 |
||
20 |
|source| |
|
21 |
source := String streamContents: [:aStream| |writer| |
|
22 |
writer := MCStWriter on: aStream. |
|
23 |
writer writeDefinitions: {True asClassDefinition. False asClassDefinition}. |
|
24 |
]. |
|
25 |
||
26 |
(MCStReader on: source readStream) definitions explore. |
|
27 |
" |
|
28 |
! ! |
|
41 | 29 |
|
30 |
!MCStReader class methodsFor:'as yet unclassified'! |
|
31 |
||
32 |
extension |
|
33 |
^ 'st' |
|
34 |
! ! |
|
35 |
||
36 |
!MCStReader methodsFor:'as yet unclassified'! |
|
37 |
||
38 |
addDefinitionsFromDoit: aString |
|
209 | 39 |
| parser | |
40 |
(parser := MCDoItParser forDoit: aString) ifNotNil: |
|
41 |
[ |
|
41 | 42 |
parser addDefinitionsTo: definitions] |
43 |
! |
|
44 |
||
45 |
categoryFromDoIt: aString |
|
46 |
| tokens | |
|
209 | 47 |
tokens := Scanner new scanTokens: aString. |
41 | 48 |
tokens size = 3 ifFalse: [self error: 'Unrecognized category definition']. |
49 |
^ tokens at: 3 |
|
50 |
! |
|
51 |
||
52 |
classDefinitionFrom: aPseudoClass |
|
209 | 53 |
| tokens traitCompositionString lastIndex classTraitCompositionString | |
54 |
tokens := Scanner new scanTokens: aPseudoClass definition. |
|
55 |
traitCompositionString := ((ReadStream on: aPseudoClass definition) |
|
56 |
match: 'uses:'; |
|
57 |
upToAll: 'instanceVariableNames:') withBlanksTrimmed. |
|
58 |
classTraitCompositionString := ((ReadStream on: aPseudoClass metaClass definition asString) |
|
59 |
match: 'uses:'; |
|
60 |
upToAll: 'instanceVariableNames:') withBlanksTrimmed. |
|
61 |
traitCompositionString isEmpty ifTrue: [traitCompositionString := '{}']. |
|
62 |
classTraitCompositionString isEmpty ifTrue: [classTraitCompositionString := '{}']. |
|
63 |
lastIndex := tokens size. |
|
41 | 64 |
^ MCClassDefinition |
65 |
name: (tokens at: 3) |
|
66 |
superclassName: (tokens at: 1) |
|
209 | 67 |
traitComposition: traitCompositionString |
68 |
classTraitComposition: classTraitCompositionString |
|
69 |
category: (tokens at: lastIndex) |
|
70 |
instVarNames: ((tokens at: lastIndex - 6) findTokens: ' ') |
|
71 |
classVarNames: ((tokens at: lastIndex - 4) findTokens: ' ') |
|
72 |
poolDictionaryNames: ((tokens at: lastIndex - 2) findTokens: ' ') |
|
41 | 73 |
classInstVarNames: (self classInstVarNamesFor: aPseudoClass) |
74 |
type: (self typeOfSubclass: (tokens at: 2)) |
|
75 |
comment: (self commentFor: aPseudoClass) |
|
76 |
commentStamp: (self commentStampFor: aPseudoClass) |
|
77 |
! |
|
78 |
||
79 |
classInstVarNamesFor: aPseudoClass |
|
80 |
| tokens | |
|
209 | 81 |
|
82 |
self flag: #traits. |
|
41 | 83 |
aPseudoClass metaClass hasDefinition ifFalse: [^ #()]. |
209 | 84 |
tokens := Scanner new scanTokens: aPseudoClass metaClass definition. |
85 |
"tokens size = 4 ifFalse: [self error: 'Unrecognized metaclass definition']." |
|
41 | 86 |
^ tokens last findTokens: ' ' |
87 |
! |
|
88 |
||
89 |
commentFor: aPseudoClass |
|
90 |
| comment | |
|
209 | 91 |
comment := aPseudoClass organization classComment. |
41 | 92 |
^ comment asString = '' |
93 |
ifTrue: [comment] |
|
94 |
ifFalse: [comment string] |
|
95 |
! |
|
96 |
||
97 |
commentStampFor: aPseudoClass |
|
98 |
| comment | |
|
209 | 99 |
comment := aPseudoClass organization classComment. |
41 | 100 |
^ [comment stamp] on: MessageNotUnderstood do: [nil] |
101 |
! |
|
102 |
||
103 |
methodDefinitionsFor: aPseudoClass |
|
880 | 104 |
^ aPseudoClass selectors collect: |
105 |
[:ea | |
|
106 |
MCMethodDefinition |
|
107 |
className: aPseudoClass name |
|
108 |
classIsMeta: aPseudoClass isMeta |
|
109 |
selector: ea |
|
110 |
category: (aPseudoClass organization categoryOfElement: ea) |
|
111 |
timeStamp: (aPseudoClass stampAt: ea) |
|
112 |
source: (aPseudoClass sourceCodeAt: ea) string] |
|
41 | 113 |
! |
114 |
||
115 |
systemOrganizationFromRecords: changeRecords |
|
116 |
| categories | |
|
209 | 117 |
categories := changeRecords |
41 | 118 |
select: [:ea | 'SystemOrganization*' match: ea string] |
119 |
thenCollect: [:ea | (self categoryFromDoIt: ea string)]. |
|
120 |
^ categories isEmpty ifFalse: [MCOrganizationDefinition categories: categories asArray] |
|
121 |
! |
|
122 |
||
123 |
typeOfSubclass: aSymbol |
|
124 |
#( |
|
125 |
(subclass: normal) |
|
126 |
(variableSubclass: variable) |
|
127 |
(variableByteSubclass: bytes) |
|
128 |
(variableWordSubclass: words) |
|
129 |
(weakSubclass: weak) |
|
130 |
) do: [:ea | ea first = aSymbol ifTrue: [^ ea second]]. |
|
131 |
self error: 'Unrecognized class definition' |
|
132 |
! ! |
|
133 |
||
134 |
!MCStReader methodsFor:'evaluating'! |
|
135 |
||
136 |
loadDefinitions |
|
519 | 137 |
|changeList| |
138 |
||
139 |
definitions := OrderedCollection new. |
|
140 |
||
141 |
Smalltalk isSmalltalkX ifTrue:[ |
|
142 |
changeList := ChangeSet fromStream:self readStream. |
|
143 |
changeList do:[:eachChange | |
|
144 |
|dfn| |
|
145 |
||
146 |
self addDefinitionFromChange:eachChange. |
|
147 |
]. |
|
148 |
] ifFalse:[ |
|
149 |
| filePackage | |
|
150 |
filePackage := |
|
151 |
FilePackage new |
|
152 |
fullName: 'ReadStream'; |
|
153 |
fileInFrom: self readStream. |
|
154 |
filePackage classes do: |
|
155 |
[:pseudoClass | |
|
156 |
pseudoClass hasDefinition |
|
157 |
ifTrue: [definitions add: |
|
158 |
(self classDefinitionFrom: pseudoClass)]. |
|
159 |
definitions addAll: (self methodDefinitionsFor: pseudoClass). |
|
160 |
definitions addAll: (self methodDefinitionsFor: pseudoClass metaClass)]. |
|
161 |
filePackage doIts do: |
|
162 |
[:ea | |
|
163 |
self addDefinitionsFromDoit: ea string]. |
|
164 |
] |
|
165 |
||
166 |
"Modified: / 25-11-2011 / 17:23:48 / cg" |
|
41 | 167 |
! |
168 |
||
169 |
readStream |
|
170 |
^ ('!!!! |
|
171 |
||
172 |
', stream contents) readStream |
|
173 |
! ! |
|
174 |
||
519 | 175 |
!MCStReader methodsFor:'stx change conversion'! |
176 |
||
177 |
addDefinitionFromChange:aChange |
|
178 |
aChange acceptChangeVisitor:self. |
|
179 |
||
180 |
"Created: / 25-11-2011 / 17:24:08 / cg" |
|
181 |
! |
|
182 |
||
960 | 183 |
visitClassCommentChange:aChange |
184 |
definitions add:(MCClassComment new |
|
185 |
className: aChange className |
|
186 |
comment: aChange comment |
|
187 |
source: aChange source string |
|
188 |
) |
|
189 |
! |
|
190 |
||
519 | 191 |
visitClassDefinitionChange:aChange |
192 |
| tokens traitCompositionString lastIndex classTraitCompositionString | |
|
193 |
||
194 |
tokens := Scanner new scanTokens: aChange source. |
|
195 |
||
196 |
"/ traitCompositionString := ((ReadStream on: aChange source) |
|
197 |
"/ match: 'uses:'; |
|
198 |
"/ upToAll: 'instanceVariableNames:') withBlanksTrimmed. |
|
199 |
"/ classTraitCompositionString := ((ReadStream on: aPseudoClass metaClass definition asString) |
|
200 |
"/ match: 'uses:'; |
|
201 |
"/ upToAll: 'instanceVariableNames:') withBlanksTrimmed. |
|
202 |
traitCompositionString isEmptyOrNil ifTrue: [traitCompositionString := '{}']. |
|
203 |
classTraitCompositionString isEmptyOrNil ifTrue: [classTraitCompositionString := '{}']. |
|
204 |
lastIndex := tokens size. |
|
205 |
definitions add:( MCClassDefinition |
|
206 |
name: aChange className "/ (tokens at: 3) |
|
207 |
superclassName: aChange superClassName "/ (tokens at: 1) |
|
208 |
traitComposition: traitCompositionString |
|
209 |
classTraitComposition: classTraitCompositionString |
|
210 |
category: aChange category "/ (tokens at: lastIndex) |
|
211 |
instVarNames: aChange instanceVariableNames asCollectionOfWords "/ ((tokens at: lastIndex - 6) findTokens: ' ') |
|
212 |
classVarNames: aChange classVariableNames asCollectionOfWords "/ ((tokens at: lastIndex - 4) findTokens: ' ') |
|
213 |
poolDictionaryNames: aChange poolDictionaries asCollectionOfWords "/ ((tokens at: lastIndex - 2) findTokens: ' ') |
|
214 |
classInstVarNames: (aChange classInstanceVariableNames ? '') asCollectionOfWords "/ (self classInstVarNamesFor: aPseudoClass) |
|
215 |
type: (self typeOfSubclass: (tokens at: 2)) |
|
216 |
comment: nil "/ (self commentFor: aPseudoClass) |
|
217 |
commentStamp: nil "/ (self commentStampFor: aPseudoClass) |
|
218 |
) |
|
219 |
||
220 |
"Created: / 25-11-2011 / 17:20:41 / cg" |
|
221 |
! |
|
222 |
||
520
3eed472bc1ad
category of: #visitClassInstVarDefinitionChange:
Claus Gittinger <cg@exept.de>
parents:
519
diff
changeset
|
223 |
visitClassInstVarDefinitionChange:aChange |
3eed472bc1ad
category of: #visitClassInstVarDefinitionChange:
Claus Gittinger <cg@exept.de>
parents:
519
diff
changeset
|
224 |
"there must be already a definition change for that class" |
3eed472bc1ad
category of: #visitClassInstVarDefinitionChange:
Claus Gittinger <cg@exept.de>
parents:
519
diff
changeset
|
225 |
|
3eed472bc1ad
category of: #visitClassInstVarDefinitionChange:
Claus Gittinger <cg@exept.de>
parents:
519
diff
changeset
|
226 |
|nonMetaName defn| |
3eed472bc1ad
category of: #visitClassInstVarDefinitionChange:
Claus Gittinger <cg@exept.de>
parents:
519
diff
changeset
|
227 |
|
3eed472bc1ad
category of: #visitClassInstVarDefinitionChange:
Claus Gittinger <cg@exept.de>
parents:
519
diff
changeset
|
228 |
self assert:(aChange className endsWith:' class'). |
3eed472bc1ad
category of: #visitClassInstVarDefinitionChange:
Claus Gittinger <cg@exept.de>
parents:
519
diff
changeset
|
229 |
nonMetaName := aChange className copyWithoutLast:' class' size. |
3eed472bc1ad
category of: #visitClassInstVarDefinitionChange:
Claus Gittinger <cg@exept.de>
parents:
519
diff
changeset
|
230 |
|
3eed472bc1ad
category of: #visitClassInstVarDefinitionChange:
Claus Gittinger <cg@exept.de>
parents:
519
diff
changeset
|
231 |
defn := definitions detectLast:[:def | def isClassDefinition and:[def className = nonMetaName]]. |
3eed472bc1ad
category of: #visitClassInstVarDefinitionChange:
Claus Gittinger <cg@exept.de>
parents:
519
diff
changeset
|
232 |
defn classInstVarNames: (aChange classInstVarNames). |
3eed472bc1ad
category of: #visitClassInstVarDefinitionChange:
Claus Gittinger <cg@exept.de>
parents:
519
diff
changeset
|
233 |
|
3eed472bc1ad
category of: #visitClassInstVarDefinitionChange:
Claus Gittinger <cg@exept.de>
parents:
519
diff
changeset
|
234 |
"Created: / 25-11-2011 / 17:32:12 / cg" |
3eed472bc1ad
category of: #visitClassInstVarDefinitionChange:
Claus Gittinger <cg@exept.de>
parents:
519
diff
changeset
|
235 |
! |
3eed472bc1ad
category of: #visitClassInstVarDefinitionChange:
Claus Gittinger <cg@exept.de>
parents:
519
diff
changeset
|
236 |
|
519 | 237 |
visitDoItChange:aChange |
238 |
self addDefinitionsFromDoit: aChange source |
|
239 |
||
240 |
"Created: / 25-11-2011 / 17:15:21 / cg" |
|
241 |
! |
|
242 |
||
243 |
visitMethodChange:aChange |
|
244 |
definitions add:(MCMethodDefinition |
|
245 |
className: aChange className |
|
246 |
classIsMeta: aChange isForMeta |
|
247 |
selector: aChange changeSelector |
|
248 |
category: aChange category "/ (aPseudoClass organization categoryOfElement: ea) |
|
249 |
timeStamp: nil "aChange timeStamp" "/ (aPseudoClass stampAt: ea) |
|
880 | 250 |
source: aChange source string"/ (aPseudoClass sourceCodeAt: ea) |
519 | 251 |
) |
252 |
||
253 |
"Created: / 25-11-2011 / 17:15:36 / cg" |
|
254 |
! ! |
|
255 |
||
41 | 256 |
!MCStReader class methodsFor:'documentation'! |
257 |
||
258 |
version |
|
960 | 259 |
^ '$Header: /cvs/stx/stx/goodies/monticello/MCStReader.st,v 1.9 2014-12-23 19:48:43 cg Exp $' |
209 | 260 |
! |
261 |
||
262 |
version_CVS |
|
960 | 263 |
^ '$Header: /cvs/stx/stx/goodies/monticello/MCStReader.st,v 1.9 2014-12-23 19:48:43 cg Exp $' |
209 | 264 |
! |
265 |
||
266 |
version_SVN |
|
960 | 267 |
^ '$Id: MCStReader.st,v 1.9 2014-12-23 19:48:43 cg Exp $' |
41 | 268 |
! ! |
796 | 269 |