author | Claus Gittinger <cg@exept.de> |
Wed, 04 Oct 2006 17:27:53 +0200 | |
changeset 10036 | 51489deaf8c5 |
parent 8728 | d70396dc4e96 |
child 10037 | b0e6048fc6fe |
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. |
51489deaf8c5
care for non-comment in copyright method (JUN stuff)
Claus Gittinger <cg@exept.de>
parents:
8728
diff
changeset
|
81 |
copyrightText isEmptyOrNil ifTrue:[ |
8227 | 82 |
" |
83 |
no source available - trigger an error |
|
84 |
" |
|
85 |
ClassDescription fileOutErrorSignal |
|
86 |
raiseRequestWith:nonMeta |
|
87 |
errorString:('no source for class ' , nonMeta name , ' available. Cannot fileOut'). |
|
88 |
^ self |
|
89 |
]. |
|
90 |
" |
|
91 |
strip off the selector-line |
|
92 |
" |
|
93 |
copyrightText := copyrightText asCollectionOfLines asStringCollection. |
|
10036
51489deaf8c5
care for non-comment in copyright method (JUN stuff)
Claus Gittinger <cg@exept.de>
parents:
8728
diff
changeset
|
94 |
[copyrightText notEmpty and:[copyrightText first isEmptyOrNil]] whileTrue:[ copyrightText removeFirst ]. |
51489deaf8c5
care for non-comment in copyright method (JUN stuff)
Claus Gittinger <cg@exept.de>
parents:
8728
diff
changeset
|
95 |
[copyrightText notEmpty and:[copyrightText last isEmptyOrNil]] whileTrue:[ copyrightText removeLast ]. |
51489deaf8c5
care for non-comment in copyright method (JUN stuff)
Claus Gittinger <cg@exept.de>
parents:
8728
diff
changeset
|
96 |
copyrightText notEmptyOrNil ifTrue:[ |
51489deaf8c5
care for non-comment in copyright method (JUN stuff)
Claus Gittinger <cg@exept.de>
parents:
8728
diff
changeset
|
97 |
copyrightText addFirst:'"'. |
51489deaf8c5
care for non-comment in copyright method (JUN stuff)
Claus Gittinger <cg@exept.de>
parents:
8728
diff
changeset
|
98 |
copyrightText addLast:'"'. |
51489deaf8c5
care for non-comment in copyright method (JUN stuff)
Claus Gittinger <cg@exept.de>
parents:
8728
diff
changeset
|
99 |
copyrightText := copyrightText asString. |
51489deaf8c5
care for non-comment in copyright method (JUN stuff)
Claus Gittinger <cg@exept.de>
parents:
8728
diff
changeset
|
100 |
outStream nextPutAllAsChunk:copyrightText. |
51489deaf8c5
care for non-comment in copyright method (JUN stuff)
Claus Gittinger <cg@exept.de>
parents:
8728
diff
changeset
|
101 |
]. |
8227 | 102 |
]. |
103 |
||
104 |
stampIt ifTrue:[ |
|
105 |
"/ |
|
106 |
"/ first, a timestamp |
|
107 |
"/ |
|
108 |
outStream nextPutAll:(Smalltalk timeStamp). |
|
109 |
outStream nextPutChunkSeparator. |
|
110 |
outStream cr; cr. |
|
111 |
]. |
|
112 |
||
113 |
withDefinition ifTrue:[ |
|
114 |
"/ |
|
115 |
"/ then the definition(s) |
|
116 |
"/ |
|
117 |
self fileOutAllDefinitionsOf:nonMeta on:outStream. |
|
118 |
"/ |
|
119 |
"/ a comment - if any |
|
120 |
"/ |
|
121 |
(comment := nonMeta comment) notNil ifTrue:[ |
|
122 |
nonMeta fileOutCommentOn:outStream. |
|
123 |
outStream cr. |
|
124 |
]. |
|
125 |
"/ |
|
126 |
"/ primitive definitions - if any |
|
127 |
"/ |
|
128 |
nonMeta fileOutPrimitiveSpecsOn:outStream. |
|
129 |
]. |
|
130 |
||
131 |
"/ |
|
132 |
"/ methods from all categories in metaclass (i.e. class methods) |
|
133 |
"/ EXCEPT: the version method is placed at the very end, to |
|
134 |
"/ avoid sourcePosition-shifts when checked out later. |
|
135 |
"/ (RCS expands this string, so its size is not constant) |
|
136 |
"/ |
|
137 |
collectionOfCategories := meta categories asSortedCollection. |
|
138 |
collectionOfCategories notNil ifTrue:[ |
|
139 |
"/ |
|
140 |
"/ documentation first (if any), but not the version method |
|
141 |
"/ |
|
142 |
(collectionOfCategories includes:'documentation') ifTrue:[ |
|
143 |
versionMethod := meta compiledMethodAt:(nonMeta nameOfVersionMethod). |
|
144 |
versionMethod notNil ifTrue:[ |
|
145 |
skippedMethods := Array with:versionMethod |
|
146 |
]. |
|
147 |
self fileOutCategory:'documentation' of:meta except:skippedMethods only:nil methodFilter:methodFilter on:outStream. |
|
148 |
outStream cr. |
|
149 |
]. |
|
150 |
||
151 |
"/ |
|
152 |
"/ initialization next (if any) |
|
153 |
"/ |
|
154 |
(collectionOfCategories includes:'initialization') ifTrue:[ |
|
155 |
self fileOutCategory:'initialization' of:meta methodFilter:methodFilter on:outStream. |
|
156 |
outStream cr. |
|
157 |
]. |
|
158 |
||
159 |
"/ |
|
160 |
"/ instance creation next (if any) |
|
161 |
"/ |
|
162 |
(collectionOfCategories includes:'instance creation') ifTrue:[ |
|
163 |
self fileOutCategory:'instance creation' of:meta methodFilter:methodFilter on:outStream. |
|
164 |
outStream cr. |
|
165 |
]. |
|
166 |
collectionOfCategories do:[:aCategory | |
|
167 |
((aCategory ~= 'documentation') |
|
168 |
and:[(aCategory ~= 'initialization') |
|
169 |
and:[aCategory ~= 'instance creation']]) ifTrue:[ |
|
170 |
self fileOutCategory:aCategory of:meta methodFilter:methodFilter on:outStream. |
|
171 |
outStream cr |
|
172 |
] |
|
173 |
] |
|
174 |
]. |
|
175 |
||
176 |
"/ |
|
177 |
"/ methods from all categories |
|
178 |
"/ |
|
179 |
collectionOfCategories := nonMeta categories asSortedCollection. |
|
180 |
collectionOfCategories notNil ifTrue:[ |
|
181 |
collectionOfCategories do:[:aCategory | |
|
182 |
self fileOutCategory:aCategory of:nonMeta methodFilter:methodFilter on:outStream. |
|
183 |
outStream cr |
|
184 |
] |
|
185 |
]. |
|
186 |
||
187 |
"/ |
|
188 |
"/ any private classes' methods |
|
189 |
"/ |
|
190 |
nonMeta privateClassesSorted do:[:aClass | |
|
191 |
self fileOutAllMethodsOf:aClass on:outStream methodFilter:methodFilter |
|
192 |
]. |
|
193 |
||
194 |
||
195 |
"/ |
|
196 |
"/ finally, the previously skipped version method |
|
197 |
"/ |
|
198 |
versionMethod notNil ifTrue:[ |
|
199 |
self fileOutCategory:'documentation' of:meta except:nil only:skippedMethods methodFilter:methodFilter on:outStream. |
|
200 |
]. |
|
201 |
||
202 |
initIt ifTrue:[ |
|
203 |
"/ |
|
204 |
"/ optionally an initialize message |
|
205 |
"/ |
|
206 |
classesImplementingInitialize := OrderedCollection new. |
|
207 |
||
208 |
(meta includesSelector:#initialize) ifTrue:[ |
|
209 |
classesImplementingInitialize add:nonMeta |
|
210 |
]. |
|
211 |
nonMeta privateClassesSorted do:[:aPrivateClass | |
|
212 |
(aPrivateClass theMetaclass includesSelector:#initialize) ifTrue:[ |
|
213 |
classesImplementingInitialize add:aPrivateClass |
|
214 |
] |
|
215 |
]. |
|
216 |
classesImplementingInitialize size ~~ 0 ifTrue:[ |
|
217 |
classesImplementingInitialize topologicalSort:[:a :b | b isSubclassOf:a]. |
|
218 |
outStream cr. |
|
219 |
classesImplementingInitialize do:[:eachClass | |
|
220 |
eachClass printClassNameOn:outStream. outStream nextPutAll:' initialize'. |
|
221 |
outStream nextPutChunkSeparator. |
|
222 |
outStream cr. |
|
223 |
]. |
|
224 |
]. |
|
225 |
] |
|
226 |
||
10036
51489deaf8c5
care for non-comment in copyright method (JUN stuff)
Claus Gittinger <cg@exept.de>
parents:
8728
diff
changeset
|
227 |
"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
|
228 |
"Modified: / 01-04-1997 / 16:01:05 / stefan" |
51489deaf8c5
care for non-comment in copyright method (JUN stuff)
Claus Gittinger <cg@exept.de>
parents:
8728
diff
changeset
|
229 |
"Modified: / 04-10-2006 / 17:22:44 / cg" |
8227 | 230 |
! |
231 |
||
232 |
fileOutAllDefinitionsOf:aNonMetaClass on:aStream |
|
233 |
"append expressions on aStream, which defines myself and all of my private classes." |
|
234 |
||
235 |
aNonMetaClass fileOutDefinitionOn:aStream. |
|
236 |
aStream nextPutChunkSeparator. |
|
237 |
aStream cr; cr. |
|
238 |
||
239 |
"/ |
|
240 |
"/ optional classInstanceVariables |
|
241 |
"/ |
|
242 |
aNonMetaClass class instanceVariableString isBlank ifFalse:[ |
|
243 |
aNonMetaClass fileOutClassInstVarDefinitionOn:aStream. |
|
244 |
aStream nextPutChunkSeparator. |
|
245 |
aStream cr; cr |
|
246 |
]. |
|
247 |
||
248 |
"/ here, the full nameSpace prefixes are output, |
|
249 |
"/ to avoid confusing stc |
|
250 |
"/ (which otherwise could not find the correct superclass) |
|
251 |
"/ |
|
252 |
Class fileOutNameSpaceQuerySignal answer:false do:[ |
|
253 |
Class forceNoNameSpaceQuerySignal answer:true do:[ |
|
254 |
aNonMetaClass privateClassesSorted do:[:aClass | |
|
255 |
self fileOutAllDefinitionsOf:aClass on:aStream |
|
256 |
] |
|
257 |
] |
|
258 |
]. |
|
259 |
||
260 |
"Created: 15.10.1996 / 11:15:19 / cg" |
|
261 |
"Modified: 22.3.1997 / 16:11:56 / cg" |
|
262 |
! |
|
263 |
||
264 |
fileOutAllMethodsOf:aClass on:aStream methodFilter:methodFilter |
|
265 |
|collectionOfCategories| |
|
266 |
||
267 |
collectionOfCategories := aClass class categories asSortedCollection. |
|
268 |
collectionOfCategories notNil ifTrue:[ |
|
269 |
collectionOfCategories do:[:aCategory | |
|
270 |
self fileOutCategory:aCategory of:aClass class methodFilter:methodFilter on:aStream. |
|
271 |
aStream cr |
|
272 |
] |
|
273 |
]. |
|
274 |
collectionOfCategories := aClass categories asSortedCollection. |
|
275 |
collectionOfCategories notNil ifTrue:[ |
|
276 |
collectionOfCategories do:[:aCategory | |
|
277 |
self fileOutCategory:aCategory of:aClass methodFilter:methodFilter on:aStream. |
|
278 |
aStream cr |
|
279 |
] |
|
280 |
]. |
|
281 |
||
282 |
aClass privateClassesSorted do:[:aClass | |
|
283 |
self fileOutAllMethodsOf:aClass on:aStream methodFilter:methodFilter |
|
284 |
]. |
|
285 |
||
286 |
"Created: 15.10.1996 / 11:13:00 / cg" |
|
287 |
"Modified: 22.3.1997 / 16:12:17 / cg" |
|
288 |
! |
|
289 |
||
290 |
fileOutCategory:aCategory of:aClass except:skippedMethods only:savedMethods methodFilter:methodFilter on:aStream |
|
291 |
"file out all methods belonging to aCategory, aString onto aStream. |
|
292 |
If skippedMethods is nonNil, those are not saved. |
|
293 |
If savedMethods is nonNil, only those are saved. |
|
294 |
If both are nil, all are saved. See version-method handling in |
|
295 |
fileOut for what this is needed." |
|
296 |
||
297 |
|dict source sortedSelectors first privacy interestingMethods cat| |
|
298 |
||
299 |
dict := aClass methodDictionary. |
|
300 |
dict notNil ifTrue:[ |
|
301 |
interestingMethods := OrderedCollection new. |
|
302 |
dict do:[:aMethod | |
|
303 |
|wanted| |
|
304 |
||
305 |
(methodFilter isNil |
|
306 |
or:[methodFilter value:aMethod]) ifTrue:[ |
|
307 |
(aCategory = aMethod category) ifTrue:[ |
|
308 |
skippedMethods notNil ifTrue:[ |
|
309 |
wanted := (skippedMethods includesIdentical:aMethod) not |
|
310 |
] ifFalse:[ |
|
311 |
savedMethods notNil ifTrue:[ |
|
312 |
wanted := (savedMethods includesIdentical:aMethod). |
|
313 |
] ifFalse:[ |
|
314 |
wanted := true |
|
315 |
] |
|
316 |
]. |
|
317 |
wanted ifTrue:[interestingMethods add:aMethod]. |
|
318 |
] |
|
319 |
] |
|
320 |
]. |
|
321 |
interestingMethods notEmpty ifTrue:[ |
|
322 |
first := true. |
|
323 |
privacy := nil. |
|
324 |
||
325 |
"/ |
|
326 |
"/ sort by selector |
|
327 |
"/ |
|
328 |
sortedSelectors := interestingMethods collect:[:m | aClass selectorAtMethod:m]. |
|
329 |
sortedSelectors sortWith:interestingMethods. |
|
330 |
||
331 |
interestingMethods do:[:aMethod | |
|
332 |
first ifFalse:[ |
|
333 |
privacy ~~ aMethod privacy ifTrue:[ |
|
334 |
first := true. |
|
335 |
aStream space. |
|
336 |
aStream nextPutChunkSeparator. |
|
337 |
]. |
|
338 |
aStream cr; cr |
|
339 |
]. |
|
340 |
||
341 |
privacy := aMethod privacy. |
|
342 |
||
343 |
first ifTrue:[ |
|
344 |
aStream nextPutChunkSeparator. |
|
345 |
aClass printClassNameOn:aStream. |
|
346 |
privacy ~~ #public ifTrue:[ |
|
347 |
aStream space; nextPutAll:privacy; nextPutAll:'MethodsFor:'. |
|
348 |
] ifFalse:[ |
|
349 |
aStream nextPutAll:' methodsFor:'. |
|
350 |
]. |
|
351 |
cat := aCategory. |
|
352 |
cat isNil ifTrue:[ cat := '' ]. |
|
353 |
aStream nextPutAll:aCategory asString storeString. |
|
354 |
aStream nextPutChunkSeparator; cr; cr. |
|
355 |
first := false. |
|
356 |
]. |
|
357 |
source := aMethod source. |
|
358 |
source isNil ifTrue:[ |
|
359 |
Class fileOutErrorSignal |
|
360 |
raiseRequestWith:aClass |
|
361 |
errorString:' - no source for method: ', (aMethod displayString) |
|
362 |
] ifFalse:[ |
|
363 |
aStream nextChunkPut:source. |
|
364 |
]. |
|
365 |
]. |
|
366 |
aStream space. |
|
367 |
aStream nextPutChunkSeparator. |
|
368 |
aStream cr |
|
369 |
] |
|
370 |
] |
|
371 |
||
372 |
"Modified: 28.8.1995 / 14:30:41 / claus" |
|
373 |
"Modified: 12.6.1996 / 11:37:33 / stefan" |
|
374 |
"Modified: 15.11.1996 / 11:32:21 / cg" |
|
375 |
"Created: 1.4.1997 / 16:04:33 / stefan" |
|
376 |
! |
|
377 |
||
378 |
fileOutCategory:aCategory of:aClass methodFilter:methodFilter on:aStream |
|
379 |
"file out all methods belonging to aCategory, aString onto aStream" |
|
380 |
||
381 |
self fileOutCategory:aCategory of:aClass except:nil only:nil methodFilter:methodFilter on:aStream |
|
382 |
||
383 |
"Created: 1.4.1997 / 16:04:44 / stefan" |
|
384 |
! ! |
|
385 |
||
386 |
!SmalltalkChunkFileSourceWriter class methodsFor:'documentation'! |
|
387 |
||
388 |
version |
|
10036
51489deaf8c5
care for non-comment in copyright method (JUN stuff)
Claus Gittinger <cg@exept.de>
parents:
8728
diff
changeset
|
389 |
^ '$Header: /cvs/stx/stx/libbasic/SmalltalkChunkFileSourceWriter.st,v 1.3 2006-10-04 15:27:53 cg Exp $' |
8227 | 390 |
! ! |