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