8227
|
1 |
"{ Package: 'stx:libbasic' }"
|
|
2 |
|
|
3 |
Object subclass:#SmalltalkChunkFileSourceWriter
|
|
4 |
instanceVariableNames:'classBeingSaved'
|
|
5 |
classVariableNames:''
|
|
6 |
poolDictionaries:''
|
|
7 |
category:'Kernel-Classes'
|
|
8 |
!
|
|
9 |
|
|
10 |
|
|
11 |
!SmalltalkChunkFileSourceWriter methodsFor:'source writing'!
|
|
12 |
|
|
13 |
fileOut:aClass on:outStreamArg withTimeStamp:stampIt withInitialize:initIt withDefinition:withDefinition methodFilter:methodFilter encoder:encoderOrNil
|
|
14 |
"file out my definition and all methods onto aStream.
|
|
15 |
If stampIt is true, a timeStamp comment is prepended.
|
|
16 |
If initIt is true, and the class implements a class-initialize method,
|
|
17 |
append a corresponding doIt expression for initialization.
|
|
18 |
The order by which the fileOut is done is used to put the version string at the end.
|
|
19 |
Thus, if the version string is expanded (by CVS), the characterPositions of methods should not move"
|
|
20 |
|
|
21 |
|collectionOfCategories copyrightMethod copyrightText comment versionMethod skippedMethods
|
|
22 |
nonMeta meta classesImplementingInitialize outStream|
|
|
23 |
|
|
24 |
nonMeta := aClass theNonMetaclass.
|
|
25 |
meta := nonMeta class.
|
|
26 |
|
|
27 |
nonMeta isLoaded ifFalse:[
|
|
28 |
^ ClassDescription fileOutErrorSignal
|
|
29 |
raiseRequestWith:nonMeta
|
|
30 |
errorString:' - will not fileOut unloaded class: ', nonMeta name
|
|
31 |
].
|
|
32 |
|
|
33 |
encoderOrNil isNil ifTrue:[
|
|
34 |
outStream := outStreamArg.
|
|
35 |
] ifFalse:[
|
|
36 |
outStream := EncodedStream stream:outStreamArg encoder:encoderOrNil.
|
|
37 |
outStream nextPutAll:'"{ Encoding: ' , encoderOrNil nameOfEncoding , ' }"'; cr; cr.
|
|
38 |
].
|
|
39 |
|
|
40 |
"
|
|
41 |
if there is a copyright method, add a copyright comment
|
|
42 |
at the beginning, taking the string from the copyright method.
|
|
43 |
We cannot do this unconditionally - that would lead to my copyrights
|
|
44 |
being put on your code ;-).
|
|
45 |
On the other hand: I want every file created by myself to have the
|
|
46 |
copyright string at the beginning be preserved .... even if the
|
|
47 |
code was edited in the browser and filedOut.
|
|
48 |
"
|
|
49 |
(copyrightMethod := meta compiledMethodAt:#copyright) notNil ifTrue:[
|
|
50 |
"
|
|
51 |
get the copyright methods source,
|
|
52 |
and insert at beginning.
|
|
53 |
"
|
|
54 |
copyrightText := copyrightMethod source.
|
|
55 |
copyrightText isNil ifTrue:[
|
|
56 |
"
|
|
57 |
no source available - trigger an error
|
|
58 |
"
|
|
59 |
ClassDescription fileOutErrorSignal
|
|
60 |
raiseRequestWith:nonMeta
|
|
61 |
errorString:('no source for class ' , nonMeta name , ' available. Cannot fileOut').
|
|
62 |
^ self
|
|
63 |
].
|
|
64 |
"
|
|
65 |
strip off the selector-line
|
|
66 |
"
|
|
67 |
copyrightText := copyrightText asCollectionOfLines asStringCollection.
|
|
68 |
copyrightText := copyrightText copyFrom:2 to:(copyrightText size).
|
|
69 |
"/ copyrightText do:[:line | outStream nextPutAll:line. aStream cr.].
|
|
70 |
copyrightText := copyrightText asString.
|
|
71 |
outStream nextPutAllAsChunk:copyrightText.
|
|
72 |
].
|
|
73 |
|
|
74 |
stampIt ifTrue:[
|
|
75 |
"/
|
|
76 |
"/ first, a timestamp
|
|
77 |
"/
|
|
78 |
outStream nextPutAll:(Smalltalk timeStamp).
|
|
79 |
outStream nextPutChunkSeparator.
|
|
80 |
outStream cr; cr.
|
|
81 |
].
|
|
82 |
|
|
83 |
withDefinition ifTrue:[
|
|
84 |
"/
|
|
85 |
"/ then the definition(s)
|
|
86 |
"/
|
|
87 |
self fileOutAllDefinitionsOf:nonMeta on:outStream.
|
|
88 |
"/
|
|
89 |
"/ a comment - if any
|
|
90 |
"/
|
|
91 |
(comment := nonMeta comment) notNil ifTrue:[
|
|
92 |
nonMeta fileOutCommentOn:outStream.
|
|
93 |
outStream cr.
|
|
94 |
].
|
|
95 |
"/
|
|
96 |
"/ primitive definitions - if any
|
|
97 |
"/
|
|
98 |
nonMeta fileOutPrimitiveSpecsOn:outStream.
|
|
99 |
].
|
|
100 |
|
|
101 |
"/
|
|
102 |
"/ methods from all categories in metaclass (i.e. class methods)
|
|
103 |
"/ EXCEPT: the version method is placed at the very end, to
|
|
104 |
"/ avoid sourcePosition-shifts when checked out later.
|
|
105 |
"/ (RCS expands this string, so its size is not constant)
|
|
106 |
"/
|
|
107 |
collectionOfCategories := meta categories asSortedCollection.
|
|
108 |
collectionOfCategories notNil ifTrue:[
|
|
109 |
"/
|
|
110 |
"/ documentation first (if any), but not the version method
|
|
111 |
"/
|
|
112 |
(collectionOfCategories includes:'documentation') ifTrue:[
|
|
113 |
versionMethod := meta compiledMethodAt:(nonMeta nameOfVersionMethod).
|
|
114 |
versionMethod notNil ifTrue:[
|
|
115 |
skippedMethods := Array with:versionMethod
|
|
116 |
].
|
|
117 |
self fileOutCategory:'documentation' of:meta except:skippedMethods only:nil methodFilter:methodFilter on:outStream.
|
|
118 |
outStream cr.
|
|
119 |
].
|
|
120 |
|
|
121 |
"/
|
|
122 |
"/ initialization next (if any)
|
|
123 |
"/
|
|
124 |
(collectionOfCategories includes:'initialization') ifTrue:[
|
|
125 |
self fileOutCategory:'initialization' of:meta methodFilter:methodFilter on:outStream.
|
|
126 |
outStream cr.
|
|
127 |
].
|
|
128 |
|
|
129 |
"/
|
|
130 |
"/ instance creation next (if any)
|
|
131 |
"/
|
|
132 |
(collectionOfCategories includes:'instance creation') ifTrue:[
|
|
133 |
self fileOutCategory:'instance creation' of:meta methodFilter:methodFilter on:outStream.
|
|
134 |
outStream cr.
|
|
135 |
].
|
|
136 |
collectionOfCategories do:[:aCategory |
|
|
137 |
((aCategory ~= 'documentation')
|
|
138 |
and:[(aCategory ~= 'initialization')
|
|
139 |
and:[aCategory ~= 'instance creation']]) ifTrue:[
|
|
140 |
self fileOutCategory:aCategory of:meta methodFilter:methodFilter on:outStream.
|
|
141 |
outStream cr
|
|
142 |
]
|
|
143 |
]
|
|
144 |
].
|
|
145 |
|
|
146 |
"/
|
|
147 |
"/ methods from all categories
|
|
148 |
"/
|
|
149 |
collectionOfCategories := nonMeta categories asSortedCollection.
|
|
150 |
collectionOfCategories notNil ifTrue:[
|
|
151 |
collectionOfCategories do:[:aCategory |
|
|
152 |
self fileOutCategory:aCategory of:nonMeta methodFilter:methodFilter on:outStream.
|
|
153 |
outStream cr
|
|
154 |
]
|
|
155 |
].
|
|
156 |
|
|
157 |
"/
|
|
158 |
"/ any private classes' methods
|
|
159 |
"/
|
|
160 |
nonMeta privateClassesSorted do:[:aClass |
|
|
161 |
self fileOutAllMethodsOf:aClass on:outStream methodFilter:methodFilter
|
|
162 |
].
|
|
163 |
|
|
164 |
|
|
165 |
"/
|
|
166 |
"/ finally, the previously skipped version method
|
|
167 |
"/
|
|
168 |
versionMethod notNil ifTrue:[
|
|
169 |
self fileOutCategory:'documentation' of:meta except:nil only:skippedMethods methodFilter:methodFilter on:outStream.
|
|
170 |
].
|
|
171 |
|
|
172 |
initIt ifTrue:[
|
|
173 |
"/
|
|
174 |
"/ optionally an initialize message
|
|
175 |
"/
|
|
176 |
classesImplementingInitialize := OrderedCollection new.
|
|
177 |
|
|
178 |
(meta includesSelector:#initialize) ifTrue:[
|
|
179 |
classesImplementingInitialize add:nonMeta
|
|
180 |
].
|
|
181 |
nonMeta privateClassesSorted do:[:aPrivateClass |
|
|
182 |
(aPrivateClass theMetaclass includesSelector:#initialize) ifTrue:[
|
|
183 |
classesImplementingInitialize add:aPrivateClass
|
|
184 |
]
|
|
185 |
].
|
|
186 |
classesImplementingInitialize size ~~ 0 ifTrue:[
|
|
187 |
classesImplementingInitialize topologicalSort:[:a :b | b isSubclassOf:a].
|
|
188 |
outStream cr.
|
|
189 |
classesImplementingInitialize do:[:eachClass |
|
|
190 |
eachClass printClassNameOn:outStream. outStream nextPutAll:' initialize'.
|
|
191 |
outStream nextPutChunkSeparator.
|
|
192 |
outStream cr.
|
|
193 |
].
|
|
194 |
].
|
|
195 |
]
|
|
196 |
|
|
197 |
"Created: / 15.11.1995 / 12:53:06 / cg"
|
|
198 |
"Modified: / 1.4.1997 / 16:01:05 / stefan"
|
|
199 |
"Modified: / 13.3.1998 / 12:23:59 / cg"
|
|
200 |
!
|
|
201 |
|
|
202 |
fileOutAllDefinitionsOf:aNonMetaClass on:aStream
|
|
203 |
"append expressions on aStream, which defines myself and all of my private classes."
|
|
204 |
|
|
205 |
aNonMetaClass fileOutDefinitionOn:aStream.
|
|
206 |
aStream nextPutChunkSeparator.
|
|
207 |
aStream cr; cr.
|
|
208 |
|
|
209 |
"/
|
|
210 |
"/ optional classInstanceVariables
|
|
211 |
"/
|
|
212 |
aNonMetaClass class instanceVariableString isBlank ifFalse:[
|
|
213 |
aNonMetaClass fileOutClassInstVarDefinitionOn:aStream.
|
|
214 |
aStream nextPutChunkSeparator.
|
|
215 |
aStream cr; cr
|
|
216 |
].
|
|
217 |
|
|
218 |
"/ here, the full nameSpace prefixes are output,
|
|
219 |
"/ to avoid confusing stc
|
|
220 |
"/ (which otherwise could not find the correct superclass)
|
|
221 |
"/
|
|
222 |
Class fileOutNameSpaceQuerySignal answer:false do:[
|
|
223 |
Class forceNoNameSpaceQuerySignal answer:true do:[
|
|
224 |
aNonMetaClass privateClassesSorted do:[:aClass |
|
|
225 |
self fileOutAllDefinitionsOf:aClass on:aStream
|
|
226 |
]
|
|
227 |
]
|
|
228 |
].
|
|
229 |
|
|
230 |
"Created: 15.10.1996 / 11:15:19 / cg"
|
|
231 |
"Modified: 22.3.1997 / 16:11:56 / cg"
|
|
232 |
!
|
|
233 |
|
|
234 |
fileOutAllMethodsOf:aClass on:aStream methodFilter:methodFilter
|
|
235 |
|collectionOfCategories|
|
|
236 |
|
|
237 |
collectionOfCategories := aClass class categories asSortedCollection.
|
|
238 |
collectionOfCategories notNil ifTrue:[
|
|
239 |
collectionOfCategories do:[:aCategory |
|
|
240 |
self fileOutCategory:aCategory of:aClass class methodFilter:methodFilter on:aStream.
|
|
241 |
aStream cr
|
|
242 |
]
|
|
243 |
].
|
|
244 |
collectionOfCategories := aClass categories asSortedCollection.
|
|
245 |
collectionOfCategories notNil ifTrue:[
|
|
246 |
collectionOfCategories do:[:aCategory |
|
|
247 |
self fileOutCategory:aCategory of:aClass methodFilter:methodFilter on:aStream.
|
|
248 |
aStream cr
|
|
249 |
]
|
|
250 |
].
|
|
251 |
|
|
252 |
aClass privateClassesSorted do:[:aClass |
|
|
253 |
self fileOutAllMethodsOf:aClass on:aStream methodFilter:methodFilter
|
|
254 |
].
|
|
255 |
|
|
256 |
"Created: 15.10.1996 / 11:13:00 / cg"
|
|
257 |
"Modified: 22.3.1997 / 16:12:17 / cg"
|
|
258 |
!
|
|
259 |
|
|
260 |
fileOutCategory:aCategory of:aClass except:skippedMethods only:savedMethods methodFilter:methodFilter on:aStream
|
|
261 |
"file out all methods belonging to aCategory, aString onto aStream.
|
|
262 |
If skippedMethods is nonNil, those are not saved.
|
|
263 |
If savedMethods is nonNil, only those are saved.
|
|
264 |
If both are nil, all are saved. See version-method handling in
|
|
265 |
fileOut for what this is needed."
|
|
266 |
|
|
267 |
|dict source sortedSelectors first privacy interestingMethods cat|
|
|
268 |
|
|
269 |
dict := aClass methodDictionary.
|
|
270 |
dict notNil ifTrue:[
|
|
271 |
interestingMethods := OrderedCollection new.
|
|
272 |
dict do:[:aMethod |
|
|
273 |
|wanted|
|
|
274 |
|
|
275 |
(methodFilter isNil
|
|
276 |
or:[methodFilter value:aMethod]) ifTrue:[
|
|
277 |
(aCategory = aMethod category) ifTrue:[
|
|
278 |
skippedMethods notNil ifTrue:[
|
|
279 |
wanted := (skippedMethods includesIdentical:aMethod) not
|
|
280 |
] ifFalse:[
|
|
281 |
savedMethods notNil ifTrue:[
|
|
282 |
wanted := (savedMethods includesIdentical:aMethod).
|
|
283 |
] ifFalse:[
|
|
284 |
wanted := true
|
|
285 |
]
|
|
286 |
].
|
|
287 |
wanted ifTrue:[interestingMethods add:aMethod].
|
|
288 |
]
|
|
289 |
]
|
|
290 |
].
|
|
291 |
interestingMethods notEmpty ifTrue:[
|
|
292 |
first := true.
|
|
293 |
privacy := nil.
|
|
294 |
|
|
295 |
"/
|
|
296 |
"/ sort by selector
|
|
297 |
"/
|
|
298 |
sortedSelectors := interestingMethods collect:[:m | aClass selectorAtMethod:m].
|
|
299 |
sortedSelectors sortWith:interestingMethods.
|
|
300 |
|
|
301 |
interestingMethods do:[:aMethod |
|
|
302 |
first ifFalse:[
|
|
303 |
privacy ~~ aMethod privacy ifTrue:[
|
|
304 |
first := true.
|
|
305 |
aStream space.
|
|
306 |
aStream nextPutChunkSeparator.
|
|
307 |
].
|
|
308 |
aStream cr; cr
|
|
309 |
].
|
|
310 |
|
|
311 |
privacy := aMethod privacy.
|
|
312 |
|
|
313 |
first ifTrue:[
|
|
314 |
aStream nextPutChunkSeparator.
|
|
315 |
aClass printClassNameOn:aStream.
|
|
316 |
privacy ~~ #public ifTrue:[
|
|
317 |
aStream space; nextPutAll:privacy; nextPutAll:'MethodsFor:'.
|
|
318 |
] ifFalse:[
|
|
319 |
aStream nextPutAll:' methodsFor:'.
|
|
320 |
].
|
|
321 |
cat := aCategory.
|
|
322 |
cat isNil ifTrue:[ cat := '' ].
|
|
323 |
aStream nextPutAll:aCategory asString storeString.
|
|
324 |
aStream nextPutChunkSeparator; cr; cr.
|
|
325 |
first := false.
|
|
326 |
].
|
|
327 |
source := aMethod source.
|
|
328 |
source isNil ifTrue:[
|
|
329 |
Class fileOutErrorSignal
|
|
330 |
raiseRequestWith:aClass
|
|
331 |
errorString:' - no source for method: ', (aMethod displayString)
|
|
332 |
] ifFalse:[
|
|
333 |
aStream nextChunkPut:source.
|
|
334 |
].
|
|
335 |
].
|
|
336 |
aStream space.
|
|
337 |
aStream nextPutChunkSeparator.
|
|
338 |
aStream cr
|
|
339 |
]
|
|
340 |
]
|
|
341 |
|
|
342 |
"Modified: 28.8.1995 / 14:30:41 / claus"
|
|
343 |
"Modified: 12.6.1996 / 11:37:33 / stefan"
|
|
344 |
"Modified: 15.11.1996 / 11:32:21 / cg"
|
|
345 |
"Created: 1.4.1997 / 16:04:33 / stefan"
|
|
346 |
!
|
|
347 |
|
|
348 |
fileOutCategory:aCategory of:aClass methodFilter:methodFilter on:aStream
|
|
349 |
"file out all methods belonging to aCategory, aString onto aStream"
|
|
350 |
|
|
351 |
self fileOutCategory:aCategory of:aClass except:nil only:nil methodFilter:methodFilter on:aStream
|
|
352 |
|
|
353 |
"Created: 1.4.1997 / 16:04:44 / stefan"
|
|
354 |
! !
|
|
355 |
|
|
356 |
!SmalltalkChunkFileSourceWriter class methodsFor:'documentation'!
|
|
357 |
|
|
358 |
version
|
|
359 |
^ '$Header: /cvs/stx/stx/libbasic/SmalltalkChunkFileSourceWriter.st,v 1.1 2004-03-19 08:16:43 ca Exp $'
|
|
360 |
! !
|