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