3707
|
1 |
"
|
|
2 |
COPYRIGHT (c) 2015 by eXept Software AG
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
"{ Package: 'stx:libbasic3' }"
|
|
13 |
|
|
14 |
"{ NameSpace: Smalltalk }"
|
|
15 |
|
|
16 |
SmalltalkChunkFileSourceWriter subclass:#VSEPackageFileSourceWriter
|
|
17 |
instanceVariableNames:'packageName'
|
|
18 |
classVariableNames:''
|
|
19 |
poolDictionaries:''
|
|
20 |
category:'Kernel-Classes-Support'
|
|
21 |
!
|
|
22 |
|
|
23 |
!VSEPackageFileSourceWriter class methodsFor:'documentation'!
|
|
24 |
|
|
25 |
copyright
|
|
26 |
"
|
|
27 |
COPYRIGHT (c) 2015 by eXept Software AG
|
|
28 |
All Rights Reserved
|
|
29 |
|
|
30 |
This software is furnished under a license and may be used
|
|
31 |
only in accordance with the terms of that license and with the
|
|
32 |
inclusion of the above copyright notice. This software may not
|
|
33 |
be provided or otherwise made available to, or used by, any
|
|
34 |
other person. No title to or ownership of the software is
|
|
35 |
hereby transferred.
|
|
36 |
"
|
|
37 |
!
|
|
38 |
|
|
39 |
documentation
|
|
40 |
"
|
|
41 |
fileout in a format which can be read by visualAge.
|
|
42 |
For transporting software.
|
|
43 |
"
|
|
44 |
!
|
|
45 |
|
|
46 |
examples
|
|
47 |
"
|
|
48 |
[exBegin]
|
|
49 |
|s|
|
|
50 |
|
|
51 |
s := 'test.st' asFilename writeStream.
|
|
52 |
[
|
|
53 |
VSEPackageFileSourceWriter new
|
|
54 |
fileOut:OrderedCollection on:s
|
|
55 |
] ensure:[
|
|
56 |
s close
|
|
57 |
]
|
|
58 |
[exEnd]
|
|
59 |
|
|
60 |
[exBegin]
|
|
61 |
|s|
|
|
62 |
|
|
63 |
s := '' writeStream.
|
|
64 |
[
|
|
65 |
VSEPackageFileSourceWriter new
|
|
66 |
fileOut:OrderedCollection on:s
|
|
67 |
] ensure:[
|
|
68 |
s close
|
|
69 |
].
|
|
70 |
s contents
|
|
71 |
[exEnd]
|
|
72 |
"
|
|
73 |
! !
|
|
74 |
|
3712
|
75 |
!VSEPackageFileSourceWriter class methodsFor:'utilities'!
|
|
76 |
|
|
77 |
fileOutPackage:packageID on:aStream
|
|
78 |
|classesToFileout writer|
|
|
79 |
|
|
80 |
aStream lineEndCRLF.
|
|
81 |
|
|
82 |
classesToFileout := Smalltalk allClassesInPackage:packageID.
|
|
83 |
classesToFileout topologicalSort:[:a :b | b isSubclassOf:a].
|
|
84 |
|
|
85 |
writer := VSEPackageFileSourceWriter new.
|
|
86 |
writer packageName:packageID.
|
|
87 |
writer writeHeaderOn:aStream.
|
|
88 |
|
|
89 |
AbstractSourceFileWriter methodSourceRewriteQuery handle:[:rewriteQuery |
|
|
90 |
|method source|
|
|
91 |
|
|
92 |
method := rewriteQuery method.
|
|
93 |
source := rewriteQuery source.
|
|
94 |
source := VSEChunkFileSourceWriter vseSourceRewriter rewriteMethod:method.
|
|
95 |
rewriteQuery proceedWith:source.
|
|
96 |
] do:[
|
|
97 |
classesToFileout do:[:eachClass |
|
|
98 |
writer fileOut:eachClass on:aStream
|
|
99 |
].
|
|
100 |
|
|
101 |
"/ fileout extensions
|
|
102 |
Smalltalk allClassesDo:[:eachClass |
|
|
103 |
(classesToFileout includes:eachClass) ifFalse:[
|
|
104 |
eachClass instAndClassSelectorsAndMethodsDo:[:sel :mthd |
|
|
105 |
|mPckg|
|
|
106 |
|
|
107 |
mPckg := mthd package.
|
|
108 |
(mPckg = packageID and:[mPckg ~= eachClass package]) ifTrue:[
|
|
109 |
writer fileOutMethod:mthd on:aStream.
|
|
110 |
aStream cr.
|
|
111 |
]
|
|
112 |
]
|
|
113 |
].
|
|
114 |
].
|
|
115 |
].
|
|
116 |
! !
|
|
117 |
|
3707
|
118 |
!VSEPackageFileSourceWriter methodsFor:'accessing'!
|
|
119 |
|
|
120 |
packageName:something
|
|
121 |
packageName := something.
|
|
122 |
! !
|
|
123 |
|
|
124 |
!VSEPackageFileSourceWriter methodsFor:'source writing'!
|
|
125 |
|
|
126 |
fileOut:aClass on:aStream withTimeStamp:stampIt withInitialize:initIt withDefinition:withDefinition methodFilter:methodFilter encoder:encoderOrNil
|
|
127 |
aStream nextPutAll:'Class '.
|
|
128 |
aStream nextPutAll:aClass nameWithoutPrefix.
|
|
129 |
aStream space.
|
|
130 |
aStream nextPutAll:aClass superclass nameWithoutPrefix.
|
|
131 |
aStream nextPutLine:'!!'.
|
|
132 |
|
|
133 |
aClass isVariable ifTrue:[
|
|
134 |
] ifFalse:[
|
|
135 |
aStream nextPutLine:'NonIndexable!!'.
|
|
136 |
].
|
|
137 |
aClass instanceVariableNames do:[:v |
|
|
138 |
aStream nextPutLine:'InstanceVariable ',v,'!!'.
|
|
139 |
].
|
|
140 |
|
|
141 |
aClass class methodDictionary keysAndValuesDo:[:sel :mthd |
|
|
142 |
aStream nextPutLine:'Method class ',sel,'!!'.
|
|
143 |
self putString:mthd source on:aStream.
|
|
144 |
aStream nextPutLine:'!!'.
|
|
145 |
self putEntry:'Property' value:'Categories' on:aStream.
|
|
146 |
self putEntry:nil value:mthd category on:aStream.
|
|
147 |
].
|
|
148 |
|
|
149 |
aClass methodDictionary keysAndValuesDo:[:sel :mthd |
|
|
150 |
aStream nextPutLine:'Method instance ',sel,'!!'.
|
|
151 |
self putString:mthd source on:aStream.
|
|
152 |
aStream nextPutLine:'!!'.
|
|
153 |
self putEntry:'Property' value:'Categories' on:aStream.
|
|
154 |
self putEntry:nil value:mthd category on:aStream.
|
|
155 |
].
|
|
156 |
|
|
157 |
self putEntry:'EndClass' value:nil on:aStream.
|
|
158 |
!
|
|
159 |
|
|
160 |
fileOutCategory:aCategory of:aClass except:skippedMethods only:savedMethods methodFilter:methodFilter on:aStream
|
|
161 |
"file out all methods belonging to aCategory, aString onto aStream.
|
|
162 |
If skippedMethods is nonNil, those are not saved.
|
|
163 |
If savedMethods is nonNil, only those are saved.
|
|
164 |
If both are nil, all are saved. See version-method handling in
|
|
165 |
fileOut for what this is needed."
|
|
166 |
|
|
167 |
|sortedSelectors first prevPrivacy privacy interestingMethods|
|
|
168 |
|
|
169 |
interestingMethods := OrderedCollection new.
|
|
170 |
aClass methodsDo:[:aMethod |
|
|
171 |
|wanted|
|
|
172 |
|
|
173 |
(methodsAlreadySaved includes:aMethod) ifFalse:[
|
|
174 |
(aCategory = aMethod category) ifTrue:[
|
|
175 |
(methodFilter isNil or:[methodFilter value:aMethod]) ifTrue:[
|
|
176 |
skippedMethods notNil ifTrue:[
|
|
177 |
wanted := (skippedMethods includesIdentical:aMethod) not
|
|
178 |
] ifFalse:[
|
|
179 |
wanted := savedMethods isNil or:[ savedMethods includesIdentical:aMethod ].
|
|
180 |
].
|
|
181 |
wanted ifTrue:[
|
|
182 |
aMethod selector isSymbol ifTrue:[
|
|
183 |
interestingMethods add:aMethod
|
|
184 |
] ifFalse:[
|
|
185 |
Transcript showCR:'skipping non-symbol method ', aMethod selector printString.
|
|
186 |
].
|
|
187 |
].
|
|
188 |
]
|
|
189 |
]
|
|
190 |
]
|
|
191 |
].
|
|
192 |
interestingMethods notEmpty ifTrue:[
|
|
193 |
first := true.
|
|
194 |
prevPrivacy := nil.
|
|
195 |
|
|
196 |
"/
|
|
197 |
"/ sort by selector
|
|
198 |
"/
|
|
199 |
sortedSelectors := interestingMethods collect:[:m | aClass selectorAtMethod:m].
|
|
200 |
sortedSelectors sortWith:interestingMethods.
|
|
201 |
|
|
202 |
interestingMethods do:[:eachMethod |
|
|
203 |
privacy := eachMethod privacy.
|
|
204 |
|
|
205 |
first ifFalse:[
|
|
206 |
privacy ~~ prevPrivacy ifTrue:[
|
|
207 |
first := true.
|
|
208 |
aStream space.
|
|
209 |
aStream nextPutChunkSeparator.
|
|
210 |
].
|
|
211 |
aStream cr; cr
|
|
212 |
].
|
|
213 |
|
|
214 |
first ifTrue:[
|
|
215 |
aStream nextPutChunkSeparator.
|
|
216 |
aClass printClassNameOn:aStream.
|
|
217 |
privacy ~~ #public ifTrue:[
|
|
218 |
aStream nextPutAll:' privateMethods'.
|
|
219 |
] ifFalse:[
|
|
220 |
aStream nextPutAll:' publicMethods'.
|
|
221 |
].
|
|
222 |
aStream nextPutChunkSeparator; cr; cr.
|
|
223 |
first := false.
|
|
224 |
].
|
|
225 |
self fileOutMethod:eachMethod on:aStream.
|
|
226 |
methodsAlreadySaved add:eachMethod.
|
|
227 |
|
|
228 |
prevPrivacy := privacy.
|
|
229 |
].
|
|
230 |
aStream space.
|
|
231 |
aStream nextPutChunkSeparator.
|
|
232 |
aStream cr
|
|
233 |
].
|
|
234 |
aStream cr
|
|
235 |
!
|
|
236 |
|
|
237 |
fileOutDefinitionOf:aClass on:aStream
|
|
238 |
"append an expression on aStream, which defines myself."
|
|
239 |
|
|
240 |
|s owner ns superclass nm|
|
|
241 |
|
|
242 |
owner := aClass owningClass.
|
|
243 |
ns := aClass topNameSpace.
|
|
244 |
|
|
245 |
"take care of nil-superclass"
|
|
246 |
superclass := aClass superclass.
|
|
247 |
superclass isNil ifTrue:[
|
|
248 |
s := 'nil'
|
|
249 |
] ifFalse:[
|
|
250 |
s := superclass nameWithNameSpacePrefix.
|
|
251 |
].
|
|
252 |
|
|
253 |
aStream nextPutAll:s. "/ superclass
|
|
254 |
aStream space.
|
|
255 |
aClass basicFileOutInstvarTypeKeywordOn:aStream.
|
|
256 |
|
|
257 |
nm := aClass nameWithoutPrefix.
|
|
258 |
aStream nextPut:$#.
|
|
259 |
aStream nextPutAll:nm.
|
|
260 |
|
|
261 |
aStream crtab.
|
|
262 |
aStream nextPutAll:'instanceVariableNames:'''.
|
|
263 |
aClass printInstVarNamesOn:aStream indent:16.
|
|
264 |
aStream nextPutAll:''''.
|
|
265 |
|
|
266 |
aStream crtab.
|
|
267 |
aStream nextPutAll:'classVariableNames:'''.
|
|
268 |
aClass printClassVarNamesOn:aStream indent:16.
|
|
269 |
aStream nextPutAll:''''.
|
|
270 |
|
|
271 |
aStream crtab.
|
|
272 |
aStream nextPutAll:'poolDictionaries:'''.
|
|
273 |
aClass printSharedPoolNamesOn:aStream indent:16.
|
|
274 |
aStream nextPutAll:''''.
|
|
275 |
|
|
276 |
aStream cr.
|
|
277 |
!
|
|
278 |
|
|
279 |
putEntry:key value:value on:aStream
|
|
280 |
key notNil ifTrue:[
|
|
281 |
aStream nextPutAll:key.
|
|
282 |
].
|
|
283 |
value notNil ifTrue:[
|
|
284 |
aStream space.
|
|
285 |
self putString:value on:aStream
|
|
286 |
].
|
|
287 |
aStream nextPutLine:'!!'.
|
|
288 |
!
|
|
289 |
|
|
290 |
putString:aString on:aStream
|
|
291 |
aStream nextPutAll:'<S'.
|
|
292 |
aStream nextPutAll:aString size asString.
|
|
293 |
aStream nextPutAll:'>'.
|
|
294 |
aStream nextPutAll:aString.
|
|
295 |
!
|
|
296 |
|
|
297 |
writeHeaderOn:aStream
|
|
298 |
self putEntry:'Header' value:nil on:aStream.
|
|
299 |
self putEntry:'Type' value:'Package' on:aStream.
|
|
300 |
self putEntry:'Format' value:'ExtendedFileOut' on:aStream.
|
|
301 |
self putEntry:'Version' value:'1.0' on:aStream.
|
|
302 |
self putEntry:'EndHeader' value:nil on:aStream.
|
|
303 |
|
|
304 |
self putEntry:'Package' value:(packageName ? 'unnamed') on:aStream.
|
|
305 |
self putEntry:'Property' value:'Release' on:aStream.
|
|
306 |
self putEntry:nil value:'1' on:aStream.
|
|
307 |
self putEntry:'Property' value:'RevisionNumber' on:aStream.
|
|
308 |
self putEntry:nil value:'1' on:aStream.
|
|
309 |
self putEntry:'Property' value:'Author' on:aStream.
|
|
310 |
self putEntry:nil value:'nobody' on:aStream.
|
|
311 |
! !
|
|
312 |
|
|
313 |
!VSEPackageFileSourceWriter class methodsFor:'documentation'!
|
|
314 |
|
|
315 |
version
|
3712
|
316 |
^ '$Header: /cvs/stx/stx/libbasic3/VSEPackageFileSourceWriter.st,v 1.2 2015-01-27 15:16:58 cg Exp $'
|
3707
|
317 |
!
|
|
318 |
|
|
319 |
version_CVS
|
3712
|
320 |
^ '$Header: /cvs/stx/stx/libbasic3/VSEPackageFileSourceWriter.st,v 1.2 2015-01-27 15:16:58 cg Exp $'
|
3707
|
321 |
! !
|
|
322 |
|