author | Claus Gittinger <cg@exept.de> |
Tue, 27 Jan 2015 21:34:51 +0100 | |
changeset 3716 | 16aa34f422bf |
parent 3712 | 88d2378e79e1 |
child 3726 | 6737e09bc2e0 |
permissions | -rw-r--r-- |
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 |
||
3716
16aa34f422bf
class: VSEPackageFileSourceWriter
Claus Gittinger <cg@exept.de>
parents:
3712
diff
changeset
|
16 |
VSEFileSourceWriter subclass:#VSEPackageFileSourceWriter |
3707 | 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 |
|
3716
16aa34f422bf
class: VSEPackageFileSourceWriter
Claus Gittinger <cg@exept.de>
parents:
3712
diff
changeset
|
78 |
|classesToFileout methodsToFileOut writer| |
3712 | 79 |
|
80 |
aStream lineEndCRLF. |
|
81 |
||
82 |
classesToFileout := Smalltalk allClassesInPackage:packageID. |
|
3716
16aa34f422bf
class: VSEPackageFileSourceWriter
Claus Gittinger <cg@exept.de>
parents:
3712
diff
changeset
|
83 |
classesToFileout := classesToFileout reject:[:cls | cls isSubclassOf: ProjectDefinition ]. |
3712 | 84 |
classesToFileout topologicalSort:[:a :b | b isSubclassOf:a]. |
85 |
||
3716
16aa34f422bf
class: VSEPackageFileSourceWriter
Claus Gittinger <cg@exept.de>
parents:
3712
diff
changeset
|
86 |
methodsToFileOut := self extensionMethodsFor:packageID. |
16aa34f422bf
class: VSEPackageFileSourceWriter
Claus Gittinger <cg@exept.de>
parents:
3712
diff
changeset
|
87 |
|
16aa34f422bf
class: VSEPackageFileSourceWriter
Claus Gittinger <cg@exept.de>
parents:
3712
diff
changeset
|
88 |
classesToFileout do:[:eachClass | |
16aa34f422bf
class: VSEPackageFileSourceWriter
Claus Gittinger <cg@exept.de>
parents:
3712
diff
changeset
|
89 |
self ensureNoUnicodeInClass:eachClass |
16aa34f422bf
class: VSEPackageFileSourceWriter
Claus Gittinger <cg@exept.de>
parents:
3712
diff
changeset
|
90 |
]. |
16aa34f422bf
class: VSEPackageFileSourceWriter
Claus Gittinger <cg@exept.de>
parents:
3712
diff
changeset
|
91 |
methodsToFileOut do:[:eachClass | |
16aa34f422bf
class: VSEPackageFileSourceWriter
Claus Gittinger <cg@exept.de>
parents:
3712
diff
changeset
|
92 |
self ensureNoUnicodeInMethod:eachClass |
16aa34f422bf
class: VSEPackageFileSourceWriter
Claus Gittinger <cg@exept.de>
parents:
3712
diff
changeset
|
93 |
]. |
16aa34f422bf
class: VSEPackageFileSourceWriter
Claus Gittinger <cg@exept.de>
parents:
3712
diff
changeset
|
94 |
|
3712 | 95 |
writer := VSEPackageFileSourceWriter new. |
96 |
writer packageName:packageID. |
|
97 |
writer writeHeaderOn:aStream. |
|
98 |
||
99 |
AbstractSourceFileWriter methodSourceRewriteQuery handle:[:rewriteQuery | |
|
100 |
|method source| |
|
101 |
||
102 |
method := rewriteQuery method. |
|
103 |
source := rewriteQuery source. |
|
3716
16aa34f422bf
class: VSEPackageFileSourceWriter
Claus Gittinger <cg@exept.de>
parents:
3712
diff
changeset
|
104 |
source := self vseSourceRewriter rewriteMethod:method. |
3712 | 105 |
rewriteQuery proceedWith:source. |
106 |
] do:[ |
|
107 |
classesToFileout do:[:eachClass | |
|
108 |
writer fileOut:eachClass on:aStream |
|
109 |
]. |
|
110 |
||
111 |
"/ fileout extensions |
|
3716
16aa34f422bf
class: VSEPackageFileSourceWriter
Claus Gittinger <cg@exept.de>
parents:
3712
diff
changeset
|
112 |
methodsToFileOut do:[:eachMethod | |
16aa34f422bf
class: VSEPackageFileSourceWriter
Claus Gittinger <cg@exept.de>
parents:
3712
diff
changeset
|
113 |
writer fileOutMethod:eachMethod on:aStream. |
16aa34f422bf
class: VSEPackageFileSourceWriter
Claus Gittinger <cg@exept.de>
parents:
3712
diff
changeset
|
114 |
aStream cr. |
3712 | 115 |
]. |
116 |
]. |
|
117 |
! ! |
|
118 |
||
3707 | 119 |
!VSEPackageFileSourceWriter methodsFor:'accessing'! |
120 |
||
121 |
packageName:something |
|
122 |
packageName := something. |
|
123 |
! ! |
|
124 |
||
125 |
!VSEPackageFileSourceWriter methodsFor:'source writing'! |
|
126 |
||
127 |
fileOut:aClass on:aStream withTimeStamp:stampIt withInitialize:initIt withDefinition:withDefinition methodFilter:methodFilter encoder:encoderOrNil |
|
128 |
aStream nextPutAll:'Class '. |
|
129 |
aStream nextPutAll:aClass nameWithoutPrefix. |
|
130 |
aStream space. |
|
131 |
aStream nextPutAll:aClass superclass nameWithoutPrefix. |
|
132 |
aStream nextPutLine:'!!'. |
|
133 |
||
134 |
aClass isVariable ifTrue:[ |
|
135 |
] ifFalse:[ |
|
136 |
aStream nextPutLine:'NonIndexable!!'. |
|
137 |
]. |
|
138 |
aClass instanceVariableNames do:[:v | |
|
139 |
aStream nextPutLine:'InstanceVariable ',v,'!!'. |
|
140 |
]. |
|
141 |
||
142 |
aClass class methodDictionary keysAndValuesDo:[:sel :mthd | |
|
143 |
aStream nextPutLine:'Method class ',sel,'!!'. |
|
144 |
self putString:mthd source on:aStream. |
|
145 |
aStream nextPutLine:'!!'. |
|
146 |
self putEntry:'Property' value:'Categories' on:aStream. |
|
147 |
self putEntry:nil value:mthd category on:aStream. |
|
148 |
]. |
|
149 |
||
150 |
aClass methodDictionary keysAndValuesDo:[:sel :mthd | |
|
151 |
aStream nextPutLine:'Method instance ',sel,'!!'. |
|
152 |
self putString:mthd source on:aStream. |
|
153 |
aStream nextPutLine:'!!'. |
|
154 |
self putEntry:'Property' value:'Categories' on:aStream. |
|
155 |
self putEntry:nil value:mthd category on:aStream. |
|
156 |
]. |
|
157 |
||
158 |
self putEntry:'EndClass' value:nil on:aStream. |
|
159 |
! |
|
160 |
||
161 |
fileOutCategory:aCategory of:aClass except:skippedMethods only:savedMethods methodFilter:methodFilter on:aStream |
|
162 |
"file out all methods belonging to aCategory, aString onto aStream. |
|
163 |
If skippedMethods is nonNil, those are not saved. |
|
164 |
If savedMethods is nonNil, only those are saved. |
|
165 |
If both are nil, all are saved. See version-method handling in |
|
166 |
fileOut for what this is needed." |
|
167 |
||
168 |
|sortedSelectors first prevPrivacy privacy interestingMethods| |
|
169 |
||
170 |
interestingMethods := OrderedCollection new. |
|
171 |
aClass methodsDo:[:aMethod | |
|
172 |
|wanted| |
|
173 |
||
174 |
(methodsAlreadySaved includes:aMethod) ifFalse:[ |
|
175 |
(aCategory = aMethod category) ifTrue:[ |
|
176 |
(methodFilter isNil or:[methodFilter value:aMethod]) ifTrue:[ |
|
177 |
skippedMethods notNil ifTrue:[ |
|
178 |
wanted := (skippedMethods includesIdentical:aMethod) not |
|
179 |
] ifFalse:[ |
|
180 |
wanted := savedMethods isNil or:[ savedMethods includesIdentical:aMethod ]. |
|
181 |
]. |
|
182 |
wanted ifTrue:[ |
|
183 |
aMethod selector isSymbol ifTrue:[ |
|
184 |
interestingMethods add:aMethod |
|
185 |
] ifFalse:[ |
|
186 |
Transcript showCR:'skipping non-symbol method ', aMethod selector printString. |
|
187 |
]. |
|
188 |
]. |
|
189 |
] |
|
190 |
] |
|
191 |
] |
|
192 |
]. |
|
193 |
interestingMethods notEmpty ifTrue:[ |
|
194 |
first := true. |
|
195 |
prevPrivacy := nil. |
|
196 |
||
197 |
"/ |
|
198 |
"/ sort by selector |
|
199 |
"/ |
|
200 |
sortedSelectors := interestingMethods collect:[:m | aClass selectorAtMethod:m]. |
|
201 |
sortedSelectors sortWith:interestingMethods. |
|
202 |
||
203 |
interestingMethods do:[:eachMethod | |
|
204 |
privacy := eachMethod privacy. |
|
205 |
||
206 |
first ifFalse:[ |
|
207 |
privacy ~~ prevPrivacy ifTrue:[ |
|
208 |
first := true. |
|
209 |
aStream space. |
|
210 |
aStream nextPutChunkSeparator. |
|
211 |
]. |
|
212 |
aStream cr; cr |
|
213 |
]. |
|
214 |
||
215 |
first ifTrue:[ |
|
216 |
aStream nextPutChunkSeparator. |
|
217 |
aClass printClassNameOn:aStream. |
|
218 |
privacy ~~ #public ifTrue:[ |
|
219 |
aStream nextPutAll:' privateMethods'. |
|
220 |
] ifFalse:[ |
|
221 |
aStream nextPutAll:' publicMethods'. |
|
222 |
]. |
|
223 |
aStream nextPutChunkSeparator; cr; cr. |
|
224 |
first := false. |
|
225 |
]. |
|
226 |
self fileOutMethod:eachMethod on:aStream. |
|
227 |
methodsAlreadySaved add:eachMethod. |
|
228 |
||
229 |
prevPrivacy := privacy. |
|
230 |
]. |
|
231 |
aStream space. |
|
232 |
aStream nextPutChunkSeparator. |
|
233 |
aStream cr |
|
234 |
]. |
|
235 |
aStream cr |
|
236 |
! |
|
237 |
||
238 |
fileOutDefinitionOf:aClass on:aStream |
|
239 |
"append an expression on aStream, which defines myself." |
|
240 |
||
241 |
|s owner ns superclass nm| |
|
242 |
||
243 |
owner := aClass owningClass. |
|
244 |
ns := aClass topNameSpace. |
|
245 |
||
246 |
"take care of nil-superclass" |
|
247 |
superclass := aClass superclass. |
|
248 |
superclass isNil ifTrue:[ |
|
249 |
s := 'nil' |
|
250 |
] ifFalse:[ |
|
251 |
s := superclass nameWithNameSpacePrefix. |
|
252 |
]. |
|
253 |
||
254 |
aStream nextPutAll:s. "/ superclass |
|
255 |
aStream space. |
|
256 |
aClass basicFileOutInstvarTypeKeywordOn:aStream. |
|
257 |
||
258 |
nm := aClass nameWithoutPrefix. |
|
259 |
aStream nextPut:$#. |
|
260 |
aStream nextPutAll:nm. |
|
261 |
||
262 |
aStream crtab. |
|
263 |
aStream nextPutAll:'instanceVariableNames:'''. |
|
264 |
aClass printInstVarNamesOn:aStream indent:16. |
|
265 |
aStream nextPutAll:''''. |
|
266 |
||
267 |
aStream crtab. |
|
268 |
aStream nextPutAll:'classVariableNames:'''. |
|
269 |
aClass printClassVarNamesOn:aStream indent:16. |
|
270 |
aStream nextPutAll:''''. |
|
271 |
||
272 |
aStream crtab. |
|
273 |
aStream nextPutAll:'poolDictionaries:'''. |
|
274 |
aClass printSharedPoolNamesOn:aStream indent:16. |
|
275 |
aStream nextPutAll:''''. |
|
276 |
||
277 |
aStream cr. |
|
278 |
! |
|
279 |
||
280 |
putEntry:key value:value on:aStream |
|
281 |
key notNil ifTrue:[ |
|
282 |
aStream nextPutAll:key. |
|
283 |
]. |
|
284 |
value notNil ifTrue:[ |
|
285 |
aStream space. |
|
286 |
self putString:value on:aStream |
|
287 |
]. |
|
288 |
aStream nextPutLine:'!!'. |
|
289 |
! |
|
290 |
||
291 |
putString:aString on:aStream |
|
292 |
aStream nextPutAll:'<S'. |
|
293 |
aStream nextPutAll:aString size asString. |
|
294 |
aStream nextPutAll:'>'. |
|
295 |
aStream nextPutAll:aString. |
|
296 |
! |
|
297 |
||
298 |
writeHeaderOn:aStream |
|
299 |
self putEntry:'Header' value:nil on:aStream. |
|
300 |
self putEntry:'Type' value:'Package' on:aStream. |
|
301 |
self putEntry:'Format' value:'ExtendedFileOut' on:aStream. |
|
302 |
self putEntry:'Version' value:'1.0' on:aStream. |
|
303 |
self putEntry:'EndHeader' value:nil on:aStream. |
|
304 |
||
305 |
self putEntry:'Package' value:(packageName ? 'unnamed') on:aStream. |
|
306 |
self putEntry:'Property' value:'Release' on:aStream. |
|
307 |
self putEntry:nil value:'1' on:aStream. |
|
308 |
self putEntry:'Property' value:'RevisionNumber' on:aStream. |
|
309 |
self putEntry:nil value:'1' on:aStream. |
|
310 |
self putEntry:'Property' value:'Author' on:aStream. |
|
311 |
self putEntry:nil value:'nobody' on:aStream. |
|
312 |
! ! |
|
313 |
||
314 |
!VSEPackageFileSourceWriter class methodsFor:'documentation'! |
|
315 |
||
316 |
version |
|
3716
16aa34f422bf
class: VSEPackageFileSourceWriter
Claus Gittinger <cg@exept.de>
parents:
3712
diff
changeset
|
317 |
^ '$Header: /cvs/stx/stx/libbasic3/VSEPackageFileSourceWriter.st,v 1.3 2015-01-27 20:34:51 cg Exp $' |
3707 | 318 |
! |
319 |
||
320 |
version_CVS |
|
3716
16aa34f422bf
class: VSEPackageFileSourceWriter
Claus Gittinger <cg@exept.de>
parents:
3712
diff
changeset
|
321 |
^ '$Header: /cvs/stx/stx/libbasic3/VSEPackageFileSourceWriter.st,v 1.3 2015-01-27 20:34:51 cg Exp $' |
3707 | 322 |
! ! |
323 |