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