author | Claus Gittinger <cg@exept.de> |
Wed, 24 Oct 2012 18:36:16 +0200 | |
changeset 14426 | 6ac120dc7add |
parent 14409 | 6f53326ef2da |
child 14596 | 45bb7ac30ab0 |
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 |
||
11963 | 14 |
AbstractSourceFileWriter subclass:#SmalltalkChunkFileSourceWriter |
11853
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
15 |
instanceVariableNames:'classBeingSaved methodsAlreadySaved' |
8227 | 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 |
" |
|
14409 | 35 |
! |
36 |
||
37 |
documentation |
|
38 |
" |
|
39 |
I know how to write smalltalk chunk file format |
|
40 |
" |
|
8728 | 41 |
! ! |
8227 | 42 |
|
14326 | 43 |
!SmalltalkChunkFileSourceWriter class methodsFor:'utilities - source code'! |
44 |
||
45 |
methodTemplate |
|
46 |
"return a method definition template string" |
|
47 |
||
48 |
|s| |
|
49 |
||
50 |
s := TextStream on:''. |
|
51 |
s nextPutAll: |
|
52 |
'message selector and argument names |
|
53 |
"comment stating purpose of this message" |
|
54 |
||
55 |
|temporaries| |
|
56 |
||
57 |
statement. |
|
58 |
statement. |
|
59 |
||
60 |
" |
|
61 |
optional: comment giving example use |
|
62 |
" |
|
63 |
'. |
|
64 |
s cr. |
|
65 |
s emphasis:(UserPreferences current commentEmphasisAndColor). |
|
66 |
s nextPutAll: |
|
67 |
'" |
|
68 |
change the above template into real code; |
|
69 |
remove this comment. |
|
70 |
Then `accept'' either via the menu |
|
71 |
or via the keyboard (usually CMD-A). |
|
72 |
||
73 |
You do not need this template; you can also |
|
74 |
select any existing methods code, change it, |
|
75 |
and finally `accept''. The method will then be |
|
76 |
installed under the selector as defined in the |
|
77 |
actual text - no matter which method is selected |
|
78 |
in the browser. |
|
79 |
||
80 |
Or clear this text, type in the method from scratch |
|
81 |
and install it with `accept''. |
|
82 |
" |
|
83 |
'. |
|
84 |
^ s contents |
|
85 |
! |
|
86 |
||
87 |
versionMethodTemplateForCVS |
|
88 |
"careful to avoid expansion by cvs here!!" |
|
89 |
||
90 |
^ ('version\ ^ ''$' , 'Header$''') withCRs |
|
91 |
||
92 |
"Created: / 21-08-2012 / 11:52:27 / cg" |
|
93 |
! ! |
|
94 |
||
8227 | 95 |
!SmalltalkChunkFileSourceWriter methodsFor:'source writing'! |
96 |
||
97 |
fileOut:aClass on:outStreamArg withTimeStamp:stampIt withInitialize:initIt withDefinition:withDefinition methodFilter:methodFilter encoder:encoderOrNil |
|
98 |
"file out my definition and all methods onto aStream. |
|
99 |
If stampIt is true, a timeStamp comment is prepended. |
|
100 |
If initIt is true, and the class implements a class-initialize method, |
|
101 |
append a corresponding doIt expression for initialization. |
|
102 |
The order by which the fileOut is done is used to put the version string at the end. |
|
103 |
Thus, if the version string is expanded (by CVS), the characterPositions of methods should not move" |
|
104 |
||
12043 | 105 |
|collectionOfCategories comment versionMethods |
8227 | 106 |
nonMeta meta classesImplementingInitialize outStream| |
107 |
||
11853
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
108 |
classBeingSaved := nonMeta := aClass theNonMetaclass. |
8227 | 109 |
meta := nonMeta class. |
11853
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
110 |
methodsAlreadySaved := Set new. |
8227 | 111 |
|
112 |
nonMeta isLoaded ifFalse:[ |
|
113 |
^ ClassDescription fileOutErrorSignal |
|
114 |
raiseRequestWith:nonMeta |
|
115 |
errorString:' - will not fileOut unloaded class: ', nonMeta name |
|
116 |
]. |
|
117 |
||
118 |
encoderOrNil isNil ifTrue:[ |
|
119 |
outStream := outStreamArg. |
|
120 |
] ifFalse:[ |
|
121 |
outStream := EncodedStream stream:outStreamArg encoder:encoderOrNil. |
|
122 |
outStream nextPutAll:'"{ Encoding: ' , encoderOrNil nameOfEncoding , ' }"'; cr; cr. |
|
123 |
]. |
|
124 |
||
125 |
" |
|
126 |
if there is a copyright method, add a copyright comment |
|
127 |
at the beginning, taking the string from the copyright method. |
|
128 |
We cannot do this unconditionally - that would lead to my copyrights |
|
129 |
being put on your code ;-). |
|
130 |
On the other hand: I want every file created by myself to have the |
|
131 |
copyright string at the beginning be preserved .... even if the |
|
132 |
code was edited in the browser and filedOut. |
|
133 |
" |
|
11853
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
134 |
self generateHeaderWithCopyrightOn:outStream. |
8227 | 135 |
|
136 |
stampIt ifTrue:[ |
|
137 |
"/ |
|
138 |
"/ first, a timestamp |
|
139 |
"/ |
|
140 |
outStream nextPutAll:(Smalltalk timeStamp). |
|
141 |
outStream nextPutChunkSeparator. |
|
142 |
outStream cr; cr. |
|
143 |
]. |
|
144 |
||
145 |
withDefinition ifTrue:[ |
|
146 |
"/ |
|
147 |
"/ then the definition(s) |
|
148 |
"/ |
|
149 |
self fileOutAllDefinitionsOf:nonMeta on:outStream. |
|
150 |
"/ |
|
151 |
"/ a comment - if any |
|
152 |
"/ |
|
153 |
(comment := nonMeta comment) notNil ifTrue:[ |
|
154 |
nonMeta fileOutCommentOn:outStream. |
|
155 |
outStream cr. |
|
156 |
]. |
|
157 |
"/ |
|
11853
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
158 |
"/ ST/X primitive definitions - if any |
8227 | 159 |
"/ |
160 |
nonMeta fileOutPrimitiveSpecsOn:outStream. |
|
161 |
]. |
|
162 |
||
163 |
"/ |
|
164 |
"/ methods from all categories in metaclass (i.e. class methods) |
|
165 |
"/ EXCEPT: the version method is placed at the very end, to |
|
166 |
"/ avoid sourcePosition-shifts when checked out later. |
|
167 |
"/ (RCS expands this string, so its size is not constant) |
|
168 |
"/ |
|
169 |
collectionOfCategories := meta categories asSortedCollection. |
|
12045
ccb1c727370b
changed: #fileOut:on:withTimeStamp:withInitialize:withDefinition:methodFilter:encoder:
fm
parents:
12043
diff
changeset
|
170 |
versionMethods := meta methodDictionary values select:[:mthd | mthd isVersionMethod]. |
ccb1c727370b
changed: #fileOut:on:withTimeStamp:withInitialize:withDefinition:methodFilter:encoder:
fm
parents:
12043
diff
changeset
|
171 |
|
8227 | 172 |
collectionOfCategories notNil ifTrue:[ |
173 |
"/ |
|
174 |
"/ documentation first (if any), but not the version method |
|
175 |
"/ |
|
176 |
(collectionOfCategories includes:'documentation') ifTrue:[ |
|
12043 | 177 |
|
13754
0ce8b7b9e6ee
changed: #fileOut:on:withTimeStamp:withInitialize:withDefinition:methodFilter:encoder:
Claus Gittinger <cg@exept.de>
parents:
13462
diff
changeset
|
178 |
"/ versionMethods do:[:versionMethod | |
0ce8b7b9e6ee
changed: #fileOut:on:withTimeStamp:withInitialize:withDefinition:methodFilter:encoder:
Claus Gittinger <cg@exept.de>
parents:
13462
diff
changeset
|
179 |
"/ |source| |
0ce8b7b9e6ee
changed: #fileOut:on:withTimeStamp:withInitialize:withDefinition:methodFilter:encoder:
Claus Gittinger <cg@exept.de>
parents:
13462
diff
changeset
|
180 |
"/ |
0ce8b7b9e6ee
changed: #fileOut:on:withTimeStamp:withInitialize:withDefinition:methodFilter:encoder:
Claus Gittinger <cg@exept.de>
parents:
13462
diff
changeset
|
181 |
"/ source := versionMethod source. |
0ce8b7b9e6ee
changed: #fileOut:on:withTimeStamp:withInitialize:withDefinition:methodFilter:encoder:
Claus Gittinger <cg@exept.de>
parents:
13462
diff
changeset
|
182 |
"/ (source isEmptyOrNil or:[(source startsWith:nonMeta nameOfOldVersionMethod) not]) ifTrue:[ |
0ce8b7b9e6ee
changed: #fileOut:on:withTimeStamp:withInitialize:withDefinition:methodFilter:encoder:
Claus Gittinger <cg@exept.de>
parents:
13462
diff
changeset
|
183 |
"/ "something bad happend to the classes code" |
0ce8b7b9e6ee
changed: #fileOut:on:withTimeStamp:withInitialize:withDefinition:methodFilter:encoder:
Claus Gittinger <cg@exept.de>
parents:
13462
diff
changeset
|
184 |
"/ |
0ce8b7b9e6ee
changed: #fileOut:on:withTimeStamp:withInitialize:withDefinition:methodFilter:encoder:
Claus Gittinger <cg@exept.de>
parents:
13462
diff
changeset
|
185 |
"/ Class fileOutErrorSignal |
0ce8b7b9e6ee
changed: #fileOut:on:withTimeStamp:withInitialize:withDefinition:methodFilter:encoder:
Claus Gittinger <cg@exept.de>
parents:
13462
diff
changeset
|
186 |
"/ raiseRequestWith:aClass |
0ce8b7b9e6ee
changed: #fileOut:on:withTimeStamp:withInitialize:withDefinition:methodFilter:encoder:
Claus Gittinger <cg@exept.de>
parents:
13462
diff
changeset
|
187 |
"/ errorString:' - bad source for version method (uncompiled class file?): ', (versionMethod displayString) |
0ce8b7b9e6ee
changed: #fileOut:on:withTimeStamp:withInitialize:withDefinition:methodFilter:encoder:
Claus Gittinger <cg@exept.de>
parents:
13462
diff
changeset
|
188 |
"/ ]. |
0ce8b7b9e6ee
changed: #fileOut:on:withTimeStamp:withInitialize:withDefinition:methodFilter:encoder:
Claus Gittinger <cg@exept.de>
parents:
13462
diff
changeset
|
189 |
"/ ]. |
12043 | 190 |
|
191 |
self fileOutCategory:'documentation' of:meta except:versionMethods only:nil methodFilter:methodFilter on:outStream. |
|
8227 | 192 |
outStream cr. |
193 |
]. |
|
194 |
||
195 |
"/ |
|
196 |
"/ initialization next (if any) |
|
197 |
"/ |
|
198 |
(collectionOfCategories includes:'initialization') ifTrue:[ |
|
199 |
self fileOutCategory:'initialization' of:meta methodFilter:methodFilter on:outStream. |
|
200 |
outStream cr. |
|
201 |
]. |
|
202 |
||
203 |
"/ |
|
204 |
"/ instance creation next (if any) |
|
205 |
"/ |
|
206 |
(collectionOfCategories includes:'instance creation') ifTrue:[ |
|
207 |
self fileOutCategory:'instance creation' of:meta methodFilter:methodFilter on:outStream. |
|
208 |
outStream cr. |
|
209 |
]. |
|
210 |
collectionOfCategories do:[:aCategory | |
|
211 |
((aCategory ~= 'documentation') |
|
212 |
and:[(aCategory ~= 'initialization') |
|
213 |
and:[aCategory ~= 'instance creation']]) ifTrue:[ |
|
214 |
self fileOutCategory:aCategory of:meta methodFilter:methodFilter on:outStream. |
|
215 |
outStream cr |
|
216 |
] |
|
217 |
] |
|
218 |
]. |
|
219 |
||
11853
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
220 |
"/ if there are any primitive definitions (vw-like ffi-primitives), |
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
221 |
"/ file them out first in the order: defines, types. |
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
222 |
"/ Otherwise, we might have trouble when filing in later, because the types are needed |
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
223 |
"/ for the primitive calls. |
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
224 |
nonMeta methodDictionary keysAndValuesDo:[:sel :m | |
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
225 |
m isVisualWorksTypedef ifTrue:[ |
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
226 |
self fileOutCategory:m category of:nonMeta except:nil only:(Array with:m) methodFilter:methodFilter on:outStream. |
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
227 |
]. |
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
228 |
]. |
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
229 |
|
8227 | 230 |
"/ |
231 |
"/ methods from all categories |
|
232 |
"/ |
|
233 |
collectionOfCategories := nonMeta categories asSortedCollection. |
|
234 |
collectionOfCategories notNil ifTrue:[ |
|
235 |
collectionOfCategories do:[:aCategory | |
|
236 |
self fileOutCategory:aCategory of:nonMeta methodFilter:methodFilter on:outStream. |
|
237 |
outStream cr |
|
238 |
] |
|
239 |
]. |
|
240 |
||
241 |
"/ |
|
242 |
"/ any private classes' methods |
|
243 |
"/ |
|
244 |
nonMeta privateClassesSorted do:[:aClass | |
|
245 |
self fileOutAllMethodsOf:aClass on:outStream methodFilter:methodFilter |
|
246 |
]. |
|
247 |
||
248 |
||
249 |
"/ |
|
250 |
"/ finally, the previously skipped version method |
|
251 |
"/ |
|
12043 | 252 |
versionMethods notEmpty ifTrue: [ |
253 |
self fileOutCategory:'documentation' of:meta except:nil only:versionMethods methodFilter:methodFilter on:outStream. |
|
8227 | 254 |
]. |
255 |
||
256 |
initIt ifTrue:[ |
|
257 |
"/ |
|
258 |
"/ optionally an initialize message |
|
259 |
"/ |
|
260 |
classesImplementingInitialize := OrderedCollection new. |
|
261 |
||
262 |
(meta includesSelector:#initialize) ifTrue:[ |
|
263 |
classesImplementingInitialize add:nonMeta |
|
264 |
]. |
|
265 |
nonMeta privateClassesSorted do:[:aPrivateClass | |
|
266 |
(aPrivateClass theMetaclass includesSelector:#initialize) ifTrue:[ |
|
267 |
classesImplementingInitialize add:aPrivateClass |
|
268 |
] |
|
269 |
]. |
|
270 |
classesImplementingInitialize size ~~ 0 ifTrue:[ |
|
271 |
classesImplementingInitialize topologicalSort:[:a :b | b isSubclassOf:a]. |
|
272 |
outStream cr. |
|
273 |
classesImplementingInitialize do:[:eachClass | |
|
274 |
eachClass printClassNameOn:outStream. outStream nextPutAll:' initialize'. |
|
275 |
outStream nextPutChunkSeparator. |
|
276 |
outStream cr. |
|
277 |
]. |
|
278 |
]. |
|
279 |
] |
|
280 |
||
10036
51489deaf8c5
care for non-comment in copyright method (JUN stuff)
Claus Gittinger <cg@exept.de>
parents:
8728
diff
changeset
|
281 |
"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
|
282 |
"Modified: / 01-04-1997 / 16:01:05 / stefan" |
13754
0ce8b7b9e6ee
changed: #fileOut:on:withTimeStamp:withInitialize:withDefinition:methodFilter:encoder:
Claus Gittinger <cg@exept.de>
parents:
13462
diff
changeset
|
283 |
"Modified: / 29-09-2011 / 14:53:49 / cg" |
8227 | 284 |
! |
285 |
||
286 |
fileOutAllDefinitionsOf:aNonMetaClass on:aStream |
|
287 |
"append expressions on aStream, which defines myself and all of my private classes." |
|
288 |
||
289 |
aNonMetaClass fileOutDefinitionOn:aStream. |
|
290 |
aStream nextPutChunkSeparator. |
|
291 |
aStream cr; cr. |
|
292 |
||
293 |
"/ |
|
294 |
"/ optional classInstanceVariables |
|
295 |
"/ |
|
296 |
aNonMetaClass class instanceVariableString isBlank ifFalse:[ |
|
297 |
aNonMetaClass fileOutClassInstVarDefinitionOn:aStream. |
|
298 |
aStream nextPutChunkSeparator. |
|
299 |
aStream cr; cr |
|
300 |
]. |
|
301 |
||
302 |
"/ here, the full nameSpace prefixes are output, |
|
303 |
"/ to avoid confusing stc |
|
304 |
"/ (which otherwise could not find the correct superclass) |
|
305 |
"/ |
|
306 |
Class fileOutNameSpaceQuerySignal answer:false do:[ |
|
307 |
Class forceNoNameSpaceQuerySignal answer:true do:[ |
|
308 |
aNonMetaClass privateClassesSorted do:[:aClass | |
|
309 |
self fileOutAllDefinitionsOf:aClass on:aStream |
|
310 |
] |
|
311 |
] |
|
312 |
]. |
|
313 |
||
314 |
"Created: 15.10.1996 / 11:15:19 / cg" |
|
315 |
"Modified: 22.3.1997 / 16:11:56 / cg" |
|
316 |
! |
|
317 |
||
318 |
fileOutAllMethodsOf:aClass on:aStream methodFilter:methodFilter |
|
319 |
|collectionOfCategories| |
|
320 |
||
321 |
collectionOfCategories := aClass class categories asSortedCollection. |
|
322 |
collectionOfCategories notNil ifTrue:[ |
|
323 |
collectionOfCategories do:[:aCategory | |
|
324 |
self fileOutCategory:aCategory of:aClass class methodFilter:methodFilter on:aStream. |
|
325 |
aStream cr |
|
326 |
] |
|
327 |
]. |
|
328 |
collectionOfCategories := aClass categories asSortedCollection. |
|
329 |
collectionOfCategories notNil ifTrue:[ |
|
330 |
collectionOfCategories do:[:aCategory | |
|
331 |
self fileOutCategory:aCategory of:aClass methodFilter:methodFilter on:aStream. |
|
332 |
aStream cr |
|
333 |
] |
|
334 |
]. |
|
335 |
||
336 |
aClass privateClassesSorted do:[:aClass | |
|
337 |
self fileOutAllMethodsOf:aClass on:aStream methodFilter:methodFilter |
|
338 |
]. |
|
339 |
||
340 |
"Created: 15.10.1996 / 11:13:00 / cg" |
|
341 |
"Modified: 22.3.1997 / 16:12:17 / cg" |
|
342 |
! |
|
343 |
||
344 |
fileOutCategory:aCategory of:aClass except:skippedMethods only:savedMethods methodFilter:methodFilter on:aStream |
|
345 |
"file out all methods belonging to aCategory, aString onto aStream. |
|
346 |
If skippedMethods is nonNil, those are not saved. |
|
347 |
If savedMethods is nonNil, only those are saved. |
|
348 |
If both are nil, all are saved. See version-method handling in |
|
349 |
fileOut for what this is needed." |
|
350 |
||
11853
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
351 |
|sortedSelectors first prevPrivacy privacy interestingMethods cat| |
11701 | 352 |
|
353 |
interestingMethods := OrderedCollection new. |
|
354 |
aClass methodsDo:[:aMethod | |
|
355 |
|wanted| |
|
8227 | 356 |
|
11853
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
357 |
(methodsAlreadySaved includes:aMethod) ifFalse:[ |
11701 | 358 |
(aCategory = aMethod category) ifTrue:[ |
11853
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
359 |
(methodFilter isNil or:[methodFilter value:aMethod]) ifTrue:[ |
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
360 |
skippedMethods notNil ifTrue:[ |
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
361 |
wanted := (skippedMethods includesIdentical:aMethod) not |
8227 | 362 |
] ifFalse:[ |
11853
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
363 |
wanted := savedMethods isNil or:[ savedMethods includesIdentical:aMethod ]. |
11703
54e2c3acf7a7
skip non-symbol-selector methods when filing out
Claus Gittinger <cg@exept.de>
parents:
11701
diff
changeset
|
364 |
]. |
11853
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
365 |
wanted ifTrue:[ |
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
366 |
aMethod selector isSymbol ifTrue:[ |
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
367 |
interestingMethods add:aMethod |
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
368 |
] ifFalse:[ |
14378
3f49f1548631
changed: #fileOutCategory:of:except:only:methodFilter:on:
Stefan Vogel <sv@exept.de>
parents:
14326
diff
changeset
|
369 |
Transcript showCR:'skipping non-symbol method ', aMethod selector printString. |
11853
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
370 |
]. |
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
371 |
]. |
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
372 |
] |
8227 | 373 |
] |
11701 | 374 |
] |
375 |
]. |
|
376 |
interestingMethods notEmpty ifTrue:[ |
|
377 |
first := true. |
|
11853
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
378 |
prevPrivacy := nil. |
8227 | 379 |
|
11701 | 380 |
"/ |
381 |
"/ sort by selector |
|
382 |
"/ |
|
383 |
sortedSelectors := interestingMethods collect:[:m | aClass selectorAtMethod:m]. |
|
384 |
sortedSelectors sortWith:interestingMethods. |
|
8227 | 385 |
|
11853
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
386 |
interestingMethods do:[:eachMethod | |
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
387 |
privacy := eachMethod privacy. |
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
388 |
|
11701 | 389 |
first ifFalse:[ |
11853
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
390 |
privacy ~~ prevPrivacy ifTrue:[ |
11701 | 391 |
first := true. |
392 |
aStream space. |
|
8227 | 393 |
aStream nextPutChunkSeparator. |
11701 | 394 |
]. |
395 |
aStream cr; cr |
|
396 |
]. |
|
397 |
||
398 |
first ifTrue:[ |
|
399 |
aStream nextPutChunkSeparator. |
|
400 |
aClass printClassNameOn:aStream. |
|
401 |
privacy ~~ #public ifTrue:[ |
|
402 |
aStream space; nextPutAll:privacy; nextPutAll:'MethodsFor:'. |
|
403 |
] ifFalse:[ |
|
404 |
aStream nextPutAll:' methodsFor:'. |
|
8227 | 405 |
]. |
11701 | 406 |
cat := aCategory. |
407 |
cat isNil ifTrue:[ cat := '' ]. |
|
408 |
aStream nextPutAll:aCategory asString storeString. |
|
409 |
aStream nextPutChunkSeparator; cr; cr. |
|
410 |
first := false. |
|
8227 | 411 |
]. |
11853
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
412 |
self fileOutMethod:eachMethod on:aStream. |
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
413 |
methodsAlreadySaved add:eachMethod. |
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
414 |
|
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
415 |
prevPrivacy := privacy. |
11701 | 416 |
]. |
417 |
aStream space. |
|
418 |
aStream nextPutChunkSeparator. |
|
419 |
aStream cr |
|
8227 | 420 |
] |
421 |
||
422 |
"Modified: 28.8.1995 / 14:30:41 / claus" |
|
423 |
"Modified: 12.6.1996 / 11:37:33 / stefan" |
|
424 |
"Modified: 15.11.1996 / 11:32:21 / cg" |
|
425 |
"Created: 1.4.1997 / 16:04:33 / stefan" |
|
426 |
! |
|
427 |
||
428 |
fileOutCategory:aCategory of:aClass methodFilter:methodFilter on:aStream |
|
429 |
"file out all methods belonging to aCategory, aString onto aStream" |
|
430 |
||
431 |
self fileOutCategory:aCategory of:aClass except:nil only:nil methodFilter:methodFilter on:aStream |
|
432 |
||
433 |
"Created: 1.4.1997 / 16:04:44 / stefan" |
|
11853
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
434 |
! |
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
435 |
|
12108 | 436 |
fileOutCommentEndOn:aStream |
437 |
"Writes a comment end mark on aStream." |
|
438 |
||
439 |
"/ intentionally left blank - make each line an EOL-comment instead |
|
440 |
! |
|
441 |
||
442 |
fileOutCommentLine:aString on:aStream |
|
443 |
"Writes a single line of comment on a comment to a stream." |
|
444 |
||
445 |
aStream |
|
446 |
nextPutAll:'"/ '; |
|
447 |
nextPutAll: aString |
|
448 |
! |
|
449 |
||
450 |
fileOutCommentStartOn:aStream |
|
451 |
"Writes a comment start mark on aStream." |
|
452 |
||
453 |
"/ intentionally left blank - make each line an EOL-comment instead |
|
454 |
! |
|
455 |
||
11853
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
456 |
fileOutMethod:aMethod on:aStream |
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
457 |
"file a single method onto aStream." |
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
458 |
|
12043 | 459 |
|source possiblyRewrittenSource rewriteQuery| |
11853
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
460 |
|
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
461 |
source := aMethod source. |
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
462 |
source isNil ifTrue:[ |
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
463 |
Class fileOutErrorSignal |
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
464 |
raiseRequestWith:aMethod mclass |
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
465 |
errorString:' - no source for method: ', (aMethod displayString) |
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
466 |
] ifFalse:[ |
12043 | 467 |
"/ hook to allow for just-in-time rewriting of a method's sourceCode while filing out |
468 |
"/ used when saving version_XXX methods in a non-XXX sourceCodeManager |
|
469 |
"/ (i.e. to rewrite all non-CVS version methods while saving into a CVS repository) |
|
470 |
"/ this is required because we cannot save an SVN version method (dollar-ID-...-dollar) into a |
|
471 |
"/ CVS repository without loosing the original string with the next checkout, because it also gets |
|
472 |
"/ expanded by CVS. The same is true vice-versa for CVS-Ids, which get clobbered by SVN. |
|
473 |
rewriteQuery := AbstractSourceFileWriter methodSourceRewriteQuery new. |
|
474 |
rewriteQuery method:aMethod source:source. |
|
475 |
possiblyRewrittenSource := (rewriteQuery query) ? source. |
|
476 |
aStream nextChunkPut:possiblyRewrittenSource. |
|
477 |
"/possiblyRewrittenSource ~= source ifTrue: [ |
|
478 |
"/ Transcript showCR: possiblyRewrittenSource. |
|
479 |
"/]. |
|
11853
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
480 |
]. |
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
481 |
! |
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
482 |
|
13420 | 483 |
fileOutMethods: methods on: stream |
484 |
||
485 |
methods do: |
|
486 |
[:method| |cat source privacy| |
|
487 |
||
488 |
stream nextPutChunkSeparator. |
|
489 |
method mclass name printOn:stream. |
|
490 |
"/ self printClassNameOn:aStream. |
|
491 |
||
492 |
(privacy := method privacy) ~~ #public ifTrue:[ |
|
493 |
stream space; nextPutAll:privacy; nextPutAll:'MethodsFor:'. |
|
494 |
] ifFalse:[ |
|
495 |
stream nextPutAll:' methodsFor:'. |
|
496 |
]. |
|
497 |
||
498 |
cat := method category ? ''. |
|
499 |
stream nextPutAll:cat asString storeString. |
|
500 |
stream nextPutChunkSeparator; cr; cr. |
|
501 |
||
502 |
self fileOutMethod: method on: stream. |
|
503 |
||
504 |
stream space. |
|
505 |
stream nextPutChunkSeparator. |
|
506 |
stream cr] |
|
507 |
||
508 |
"Created: / 30-12-2009 / 18:43:57 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
509 |
! |
|
510 |
||
511 |
fileOutPackageDefinition:pkg on:aStream |
|
512 |
(pkg notNil and:[ pkg ~= PackageId noProjectID ]) ifTrue:[ |
|
513 |
aStream nextPutAll:'"{ Package: '''. |
|
514 |
aStream nextPutAll:pkg asString. |
|
515 |
aStream |
|
516 |
nextPutAll:''' }"'; cr; cr; |
|
517 |
nextPut:$!!; cr; cr |
|
518 |
] |
|
519 |
! |
|
520 |
||
11853
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
521 |
generateHeaderWithCopyrightOn:outStream |
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
522 |
|copyrightMethod copyrightText| |
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
523 |
|
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
524 |
"if there is a copyright method, add a copyright comment |
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
525 |
at the beginning, taking the string from the copyright method. |
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
526 |
We cannot do this unconditionally - that would lead to my copyrights |
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
527 |
being put on your code ;-). |
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
528 |
On the other hand: I want every file created by myself to have the |
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
529 |
copyright string at the beginning be preserved .... even if the |
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
530 |
code was edited in the browser and filedOut." |
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
531 |
|
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
532 |
(copyrightMethod := classBeingSaved theMetaclass compiledMethodAt:#copyright) notNil ifTrue:[ |
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
533 |
" |
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
534 |
get the copyright method's comment-text, strip off empty and blank lines |
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
535 |
and insert at beginning. |
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
536 |
" |
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
537 |
copyrightText := copyrightMethod comment. |
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
538 |
copyrightText notEmptyOrNil ifTrue:[ |
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
539 |
copyrightText := copyrightText asCollectionOfLines asStringCollection. |
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
540 |
copyrightText := copyrightText withoutLeadingBlankLines. |
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
541 |
copyrightText := copyrightText withoutTrailingBlankLines. |
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
542 |
copyrightText notEmpty ifTrue:[ |
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
543 |
copyrightText addFirst:'"'. |
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
544 |
copyrightText addLast:'"'. |
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
545 |
copyrightText := copyrightText asString. |
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
546 |
outStream nextPutAllAsChunk:copyrightText. |
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
547 |
]. |
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
548 |
]. |
7c3265d8931e
save typedef methods before others to ensure that types
Claus Gittinger <cg@exept.de>
parents:
11703
diff
changeset
|
549 |
]. |
8227 | 550 |
! ! |
551 |
||
552 |
!SmalltalkChunkFileSourceWriter class methodsFor:'documentation'! |
|
553 |
||
13420 | 554 |
version_CVS |
14409 | 555 |
^ '$Header: /cvs/stx/stx/libbasic/SmalltalkChunkFileSourceWriter.st,v 1.18 2012-10-20 19:25:49 cg Exp $' |
12043 | 556 |
! |
557 |
||
13420 | 558 |
version_SVN |
13462
2d4683974fc7
changed: #fileOut:on:withTimeStamp:withInitialize:withDefinition:methodFilter:encoder:
Claus Gittinger <cg@exept.de>
parents:
13420
diff
changeset
|
559 |
^ '§ Id: SmalltalkChunkFileSourceWriter.st 10643 2011-06-08 21:53:07Z vranyj1 §' |
8227 | 560 |
! ! |