author | Claus Gittinger <cg@exept.de> |
Tue, 09 Dec 2008 15:03:59 +0100 | |
changeset 8488 | bb2810d17bd9 |
parent 8344 | efda36a55d02 |
child 8572 | beebdd1ee40e |
permissions | -rw-r--r-- |
5141 | 1 |
" |
2 |
COPYRIGHT (c) 2002 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 |
" |
|
3712 | 12 |
"{ Package: 'stx:libtool' }" |
13 |
||
14 |
Object subclass:#CodeGeneratorTool |
|
5758 | 15 |
instanceVariableNames:'compositeChangeCollector compositeChangeNesting' |
8258 | 16 |
classVariableNames:'GenerateCommentsForGetters GenerateCommentsForSetters |
17 |
CopyrightTemplate' |
|
3712 | 18 |
poolDictionaries:'' |
19 |
category:'Interface-Browsers' |
|
20 |
! |
|
21 |
||
3719 | 22 |
!CodeGeneratorTool class methodsFor:'documentation'! |
23 |
||
5141 | 24 |
copyright |
25 |
" |
|
26 |
COPYRIGHT (c) 2002 by eXept Software AG |
|
27 |
All Rights Reserved |
|
28 |
||
29 |
This software is furnished under a license and may be used |
|
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
37 |
||
3719 | 38 |
documentation |
39 |
" |
|
5013
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
40 |
This utility class contains various code generation facilites; |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
41 |
these were extracted from the old and newBrowser. |
6791
6559c9ebb561
Keep method argument names when generating required methods
Stefan Vogel <sv@exept.de>
parents:
6718
diff
changeset
|
42 |
There is probably more to come... |
3719 | 43 |
|
44 |
[author:] |
|
45 |
Claus Gittiner |
|
46 |
" |
|
47 |
! ! |
|
3712 | 48 |
|
49 |
!CodeGeneratorTool class methodsFor:'code generation'! |
|
50 |
||
51 |
createAccessMethodsFor:aCollectionOfVarNames in:aClass withChange:withChange asValueHolder:asValueHolder readersOnly:readersOnly writersOnly:writersOnly |
|
5013
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
52 |
"create accessors in aClass" |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
53 |
|
5758 | 54 |
^ self new |
6313 | 55 |
createAccessMethodsFor:aCollectionOfVarNames |
56 |
in:aClass |
|
57 |
withChange:withChange |
|
58 |
asValueHolder:asValueHolder |
|
59 |
readersOnly:readersOnly |
|
60 |
writersOnly:writersOnly |
|
4444
6b077945517c
generate instvar accessors with lazy-init
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
61 |
! |
6b077945517c
generate instvar accessors with lazy-init
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
62 |
|
3712 | 63 |
createApplicationCodeFor:aClass |
64 |
"create an empty application framework" |
|
65 |
||
5758 | 66 |
^ self new createApplicationCodeFor:aClass |
3712 | 67 |
! |
68 |
||
3804 | 69 |
createClassResponsibleProtocolFor:aClass |
70 |
"create stubs for the required protocol" |
|
71 |
||
5758 | 72 |
^ self new createClassResponsibleProtocolFor:aClass |
3804 | 73 |
! |
74 |
||
5124 | 75 |
createClassTypeTestMethodsIn:aClass forClasses:subClasses |
5013
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
76 |
"create a #isXXX test methods (I'm tired of typing)" |
4351 | 77 |
|
5758 | 78 |
^ self new createClassTypeTestMethodsIn:aClass forClasses:subClasses |
4351 | 79 |
! |
80 |
||
3712 | 81 |
createDocumentationMethodsFor:aClass |
82 |
"create empty documentation methods" |
|
83 |
||
5758 | 84 |
^ self new createDocumentationMethodsFor:aClass |
3712 | 85 |
! |
86 |
||
6313 | 87 |
createEnumTypeCodeFor:aClass |
88 |
^ self new createEnumTypeCodeFor:aClass |
|
89 |
! |
|
90 |
||
6718 | 91 |
createInitializedInstanceCreationMethodsIn:aClass |
5013
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
92 |
"create a #new and #initialize methods (I'm tired of typing)" |
3712 | 93 |
|
6718 | 94 |
^ self new createInitializedInstanceCreationMethodsIn:aClass |
95 |
! |
|
96 |
||
97 |
createParametrizedInstanceCreationMethodsNamed:selector in:aClass |
|
98 |
"create a #selector instance creation method (I'm tired of typing)" |
|
99 |
||
100 |
^ self new createParametrizedInstanceCreationMethodsNamed:selector in:aClass |
|
3712 | 101 |
! |
102 |
||
8344
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
103 |
createRedefinedInstanceCreationMethodsIn:aClass |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
104 |
"create a redefined #new method" |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
105 |
|
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
106 |
^ self new createRedefinedInstanceCreationMethodsIn:aClass |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
107 |
! |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
108 |
|
3712 | 109 |
createTestCaseSampleCodeFor:aClass |
4590 | 110 |
"create an (almost) empty testCase class" |
3712 | 111 |
|
5758 | 112 |
^ self new createTestCaseSampleCodeFor:aClass |
3712 | 113 |
! |
114 |
||
115 |
createVisitorMethodsIn:visitedClass andVisitorClass:visitorClass |
|
5013
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
116 |
"create acceptVisitor: in visitedClass and acceptXXX in visitorClass. (I'm tired of typing)" |
3712 | 117 |
|
5758 | 118 |
^ self new createVisitorMethodsIn:visitedClass andVisitorClass:visitorClass |
3712 | 119 |
! |
120 |
||
6050 | 121 |
createWebApplicationCodeFor:aClass |
122 |
"create an empty webApplication framework" |
|
123 |
||
124 |
^ self new createWebApplicationCodeFor:aClass |
|
125 |
! |
|
126 |
||
7973 | 127 |
createWebServiceCodeFor:aClass |
128 |
"create an empty webService framework" |
|
129 |
||
130 |
^ self new createWebServiceCodeFor:aClass |
|
131 |
! |
|
132 |
||
3712 | 133 |
initialMenuSpecMethodSourceForApplications |
5013
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
134 |
"return a menuSpec with typical stuff in it" |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
135 |
|
3712 | 136 |
^ |
137 |
'mainMenu |
|
138 |
"This resource specification was automatically generated by the CodeGeneratorTool." |
|
139 |
||
140 |
"Do not manually edit this!! If it is corrupted, |
|
141 |
the MenuEditor may not be able to read the specification." |
|
142 |
||
143 |
" |
|
144 |
MenuEditor new openOnClass:%1 andSelector:#mainMenu |
|
145 |
" |
|
146 |
||
147 |
<resource: #menu> |
|
148 |
||
149 |
^ #(#Menu |
|
150 |
#( |
|
151 |
#(#MenuItem |
|
152 |
#label: ''File'' |
|
153 |
#translateLabel: true |
|
154 |
#submenu: |
|
155 |
#(#Menu |
|
156 |
#( |
|
157 |
#(#MenuItem |
|
158 |
#label: ''New'' |
|
159 |
#translateLabel: true |
|
160 |
#value: #menuNew |
|
161 |
) |
|
162 |
#(#MenuItem |
|
163 |
#label: ''-'' |
|
164 |
) |
|
165 |
#(#MenuItem |
|
166 |
#label: ''Open...'' |
|
167 |
#translateLabel: true |
|
168 |
#value: #menuOpen |
|
169 |
) |
|
170 |
#(#MenuItem |
|
171 |
#label: ''-'' |
|
172 |
) |
|
173 |
#(#MenuItem |
|
174 |
#label: ''Save'' |
|
175 |
#translateLabel: true |
|
176 |
#value: #menuSave |
|
177 |
) |
|
178 |
#(#MenuItem |
|
179 |
#label: ''Save As...'' |
|
180 |
#translateLabel: true |
|
181 |
#value: #menuSaveAs |
|
182 |
) |
|
183 |
#(#MenuItem |
|
184 |
#label: ''-'' |
|
185 |
) |
|
186 |
#(#MenuItem |
|
187 |
#label: ''Exit'' |
|
188 |
#translateLabel: true |
|
189 |
#value: #closeRequest |
|
190 |
) |
|
191 |
) nil |
|
192 |
nil |
|
193 |
) |
|
194 |
) |
|
195 |
#(#MenuItem |
|
196 |
#label: ''Help'' |
|
197 |
#translateLabel: true |
|
198 |
#startGroup: #right |
|
199 |
#submenu: |
|
200 |
#(#Menu |
|
201 |
#( |
|
202 |
#(#MenuItem |
|
203 |
#label: ''Documentation'' |
|
204 |
#translateLabel: true |
|
205 |
#value: #openDocumentation |
|
206 |
) |
|
207 |
#(#MenuItem |
|
208 |
#label: ''-'' |
|
209 |
) |
|
210 |
#(#MenuItem |
|
6643 | 211 |
#label: ''About this Application...'' |
3712 | 212 |
#translateLabel: true |
213 |
#value: #openAboutThisApplication |
|
214 |
) |
|
215 |
) nil |
|
216 |
nil |
|
217 |
) |
|
218 |
) |
|
219 |
) nil |
|
220 |
nil |
|
221 |
) |
|
222 |
'. |
|
223 |
! |
|
224 |
||
7973 | 225 |
initialPageMenuSpec |
226 |
"return a menuSpec with typical stuff in it" |
|
227 |
||
228 |
"This resource specification was automatically generated by the CodeGeneratorTool." |
|
229 |
||
230 |
"Do not manually edit this!! If it is corrupted, |
|
231 |
the MenuEditor may not be able to read the specification." |
|
232 |
||
233 |
" |
|
234 |
MenuEditor new openOnClass:%1 andSelector:#mainMenu |
|
235 |
" |
|
236 |
||
237 |
<resource: #menu> |
|
238 |
||
239 |
^ #(#Menu |
|
240 |
#( |
|
241 |
#(#MenuItem |
|
242 |
#label: 'AAA' |
|
243 |
#translateLabel: true |
|
244 |
#submenu: |
|
245 |
#(#Menu |
|
246 |
#( |
|
247 |
#(#MenuItem |
|
248 |
#label: 'New' |
|
249 |
#translateLabel: true |
|
250 |
#value: #menuNew |
|
251 |
) |
|
252 |
#(#MenuItem |
|
253 |
#label: '-' |
|
254 |
) |
|
255 |
#(#MenuItem |
|
256 |
#label: 'Open...' |
|
257 |
#translateLabel: true |
|
258 |
#value: #menuOpen |
|
259 |
) |
|
260 |
#(#MenuItem |
|
261 |
#label: '-' |
|
262 |
) |
|
263 |
#(#MenuItem |
|
264 |
#label: 'Save' |
|
265 |
#translateLabel: true |
|
266 |
#value: #menuSave |
|
267 |
) |
|
268 |
#(#MenuItem |
|
269 |
#label: 'Save As...' |
|
270 |
#translateLabel: true |
|
271 |
#value: #menuSaveAs |
|
272 |
) |
|
273 |
#(#MenuItem |
|
274 |
#label: '-' |
|
275 |
) |
|
276 |
#(#MenuItem |
|
277 |
#label: 'Exit' |
|
278 |
#translateLabel: true |
|
279 |
#value: #closeRequest |
|
280 |
) |
|
281 |
) nil |
|
282 |
nil |
|
283 |
) |
|
284 |
) |
|
285 |
#(#MenuItem |
|
286 |
#label: 'Help' |
|
287 |
#translateLabel: true |
|
288 |
#startGroup: #right |
|
289 |
#submenu: |
|
290 |
#(#Menu |
|
291 |
#( |
|
292 |
#(#MenuItem |
|
293 |
#label: 'Documentation' |
|
294 |
#translateLabel: true |
|
295 |
#value: #openDocumentation |
|
296 |
) |
|
297 |
#(#MenuItem |
|
298 |
#label: '-' |
|
299 |
) |
|
300 |
#(#MenuItem |
|
301 |
#label: 'About this Application...' |
|
302 |
#translateLabel: true |
|
303 |
#value: #openAboutThisApplication |
|
304 |
) |
|
305 |
) nil |
|
306 |
nil |
|
307 |
) |
|
308 |
) |
|
309 |
) nil |
|
310 |
nil |
|
311 |
) |
|
312 |
! |
|
313 |
||
314 |
initialPageMenuSpecMethodSourceForWebApplications |
|
315 |
"return a menuSpec with typical stuff in it" |
|
316 |
||
317 |
^ |
|
318 |
'mainMenu |
|
319 |
"This resource specification was automatically generated by the CodeGeneratorTool." |
|
320 |
||
321 |
"Do not manually edit this!! If it is corrupted, |
|
322 |
the MenuEditor may not be able to read the specification." |
|
323 |
||
324 |
" |
|
325 |
MenuEditor new openOnClass:%1 andSelector:#mainMenu |
|
326 |
" |
|
327 |
||
328 |
<resource: #menu> |
|
329 |
||
330 |
^ ',(self initialPageMenuSpec decodeAsLiteralArray literalArrayEncoding storeString),' |
|
331 |
'. |
|
332 |
||
333 |
" |
|
334 |
self initialPageMenuSpecMethodSourceForWebApplications |
|
335 |
" |
|
336 |
! |
|
337 |
||
338 |
initialPageSpecMethodSourceForWebApplications |
|
339 |
"return an empty pageSpec" |
|
340 |
||
341 |
^ |
|
342 |
'pageSpec |
|
343 |
"This resource specification was automatically generated by the CodeGeneratorTool." |
|
344 |
||
345 |
"Do not manually edit this!! If it is corrupted, |
|
346 |
the UIPainter may not be able to read the specification." |
|
347 |
||
348 |
" |
|
349 |
UIPainter new openOnClass:%1 andSelector:#windowSpec |
|
350 |
" |
|
351 |
||
352 |
<resource: #canvas> |
|
353 |
||
354 |
^ #(#FullSpec |
|
355 |
#window: |
|
356 |
#(#WindowSpec |
|
357 |
#name: ''%1'' |
|
358 |
#layout: #(#LayoutFrame 204 0 162 0 503 0 461 0) |
|
359 |
#label: ''%1'' |
|
360 |
#min: #(#Point 10 10) |
|
361 |
#max: #(#Point 1024 768) |
|
362 |
#bounds: #(#Rectangle 204 162 504 462) |
|
363 |
#menu: #pageMenu |
|
364 |
#usePreferredExtent: false |
|
365 |
) |
|
366 |
#component: |
|
367 |
#(#SpecCollection |
|
368 |
#collection: #() |
|
369 |
) |
|
370 |
) |
|
371 |
'. |
|
372 |
! |
|
373 |
||
3712 | 374 |
initialWindowSpecMethodSourceForApplications |
5013
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
375 |
"return an empty windowSpec with an initial menubar in it" |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
376 |
|
3712 | 377 |
^ |
378 |
'windowSpec |
|
379 |
"This resource specification was automatically generated by the CodeGeneratorTool." |
|
380 |
||
381 |
"Do not manually edit this!! If it is corrupted, |
|
382 |
the UIPainter may not be able to read the specification." |
|
383 |
||
384 |
" |
|
385 |
UIPainter new openOnClass:%1 andSelector:#windowSpec |
|
386 |
" |
|
387 |
||
388 |
<resource: #canvas> |
|
389 |
||
390 |
^ #(#FullSpec |
|
391 |
#window: |
|
392 |
#(#WindowSpec |
|
393 |
#name: ''%1'' |
|
394 |
#layout: #(#LayoutFrame 204 0 162 0 503 0 461 0) |
|
395 |
#label: ''%1'' |
|
396 |
#min: #(#Point 10 10) |
|
397 |
#max: #(#Point 1024 768) |
|
398 |
#bounds: #(#Rectangle 204 162 504 462) |
|
399 |
#menu: #mainMenu |
|
400 |
#usePreferredExtent: false |
|
401 |
) |
|
402 |
#component: |
|
403 |
#(#SpecCollection |
|
404 |
#collection: #() |
|
405 |
) |
|
406 |
) |
|
407 |
'. |
|
408 |
! |
|
409 |
||
410 |
initialWindowSpecMethodSourceForDialogs |
|
5013
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
411 |
"return an empty windowSpec for dialogs" |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
412 |
|
3712 | 413 |
^ |
414 |
'windowSpec |
|
415 |
"This resource specification was automatically generated by the CodeGeneratorTool." |
|
416 |
||
417 |
"Do not manually edit this!! If it is corrupted, |
|
418 |
the UIPainter may not be able to read the specification." |
|
419 |
||
420 |
" |
|
421 |
UIPainter new openOnClass:%1 andSelector:#windowSpec |
|
422 |
" |
|
423 |
||
424 |
<resource: #canvas> |
|
425 |
||
426 |
^ |
|
427 |
||
428 |
#(#FullSpec |
|
429 |
#window: |
|
430 |
#(#WindowSpec |
|
431 |
#name: ''%1'' |
|
432 |
#layout: #(#LayoutFrame 221 0 118 0 520 0 417 0) |
|
433 |
#level: 0 |
|
434 |
#label: ''%1'' |
|
435 |
#min: #(#Point 10 10) |
|
436 |
#max: #(#Point 1024 768) |
|
437 |
#bounds: #(#Rectangle 221 118 521 418) |
|
438 |
#usePreferredExtent: false |
|
439 |
) |
|
440 |
#component: |
|
441 |
#(#SpecCollection |
|
442 |
#collection: |
|
443 |
#( |
|
444 |
#(#HorizontalPanelViewSpec |
|
445 |
#name: ''buttonPanel'' |
|
446 |
#layout: #(#LayoutFrame 0 0.0 -45 1 0 1.0 0 1.0) |
|
447 |
#component: |
|
448 |
#(#SpecCollection |
|
449 |
#collection: |
|
450 |
#( |
|
451 |
#(#ActionButtonSpec |
|
452 |
#name: ''cancelButton'' |
|
453 |
#label: ''Cancel'' |
|
454 |
#tabable: true |
|
455 |
#translateLabel: true |
|
456 |
#model: #cancel |
|
457 |
#extent: #(#Point 125 22) |
|
458 |
) |
|
459 |
#(#ActionButtonSpec |
|
460 |
#name: ''okButton'' |
|
461 |
#label: ''OK'' |
|
462 |
#tabable: true |
|
463 |
#translateLabel: true |
|
464 |
#isDefault: true |
|
465 |
#model: #accept |
|
466 |
#extent: #(#Point 125 22) |
|
467 |
) |
|
468 |
) |
|
469 |
) |
|
470 |
#reverseOrderIfOKAtLeft: true |
|
471 |
#horizontalLayout: #spreadSpaceMax |
|
472 |
#verticalLayout: #center |
|
473 |
#horizontalSpace: 3 |
|
474 |
#verticalSpace: 3 |
|
475 |
) |
|
476 |
) |
|
477 |
) |
|
478 |
) |
|
479 |
'. |
|
480 |
! ! |
|
481 |
||
5013
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
482 |
!CodeGeneratorTool class methodsFor:'code generation-basic'! |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
483 |
|
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
484 |
createAccessMethodsFor:aCollectionOfVarNames in:aClass withChange:withChange asValueHolder:asValueHolder readersOnly:readersOnly writersOnly:writersOnly lazyInitialization:lazyInitialization |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
485 |
"workhorse for creating access methods for instvars." |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
486 |
|
5758 | 487 |
^ self new |
488 |
createAccessMethodsFor:aCollectionOfVarNames in:aClass withChange:withChange asValueHolder:asValueHolder readersOnly:readersOnly writersOnly:writersOnly lazyInitialization:lazyInitialization |
|
489 |
! ! |
|
490 |
||
491 |
!CodeGeneratorTool class methodsFor:'code generation-individual methods'! |
|
492 |
||
493 |
createAcceptVisitorMethod:selector in:aClass |
|
494 |
"create an acceptVisitor: method |
|
495 |
(I'm tired of typing)" |
|
496 |
||
497 |
^ self new createAcceptVisitorMethod:selector in:aClass |
|
498 |
! |
|
499 |
||
500 |
createAcceptVisitorMethodIn:aClass |
|
501 |
"create an acceptVisitor: method |
|
502 |
(I'm tired of typing)" |
|
503 |
||
504 |
^ self new createAcceptVisitorMethodIn:aClass |
|
505 |
! |
|
506 |
||
507 |
createCopyrightMethodFor:aClass |
|
508 |
"add copyright method containing your/your companies |
|
509 |
copyright template but only if not already present. |
|
510 |
this is only added, if specified in the |
|
511 |
COPYRIGHT_TEMPLATE_FILE resources." |
|
512 |
||
513 |
^ self new createCopyrightMethodFor:aClass |
|
514 |
! |
|
515 |
||
516 |
createDocumentationMethodFor:aClass |
|
517 |
"add documentation method containing doc template |
|
518 |
but only if not already present." |
|
519 |
||
520 |
^ self new createDocumentationMethodFor:aClass |
|
521 |
! |
|
522 |
||
523 |
createExamplesMethodFor:aClass |
|
524 |
"add examples method containing examples template |
|
525 |
but only if not already present." |
|
526 |
||
527 |
^ self new createExamplesMethodFor:aClass |
|
528 |
! |
|
529 |
||
530 |
createImageSpecMethodFor:anImage comment:comment in:aClass selector:sel |
|
531 |
^ self new createImageSpecMethodFor:anImage comment:comment in:aClass selector:sel |
|
532 |
! |
|
533 |
||
534 |
createInitialHistoryMethodFor:aClass |
|
535 |
"add history method containing created-entry |
|
536 |
but only if not already present." |
|
537 |
||
538 |
^ self new createInitialHistoryMethodFor:aClass |
|
539 |
! |
|
540 |
||
541 |
createInstanceCreationMethodWithSetupFor:selector category:category in:aMetaClass |
|
542 |
"add an inst-creation method" |
|
543 |
||
544 |
^ self new createInstanceCreationMethodWithSetupFor:selector category:category in:aMetaClass |
|
545 |
! |
|
546 |
||
547 |
createMultiSetterMethodFor:aCollectionOfVarNames in:aClass |
|
548 |
"create a multi-setter method for instvars." |
|
549 |
||
550 |
^ self new createMultiSetterMethodFor:aCollectionOfVarNames in:aClass |
|
551 |
! |
|
552 |
||
553 |
createSubclassResponsibilityMethodFor:aSelector category:cat in:aClass |
|
554 |
"add a subclassResponsibility method; |
|
555 |
but only if not already present." |
|
556 |
||
557 |
^ self new createSubclassResponsibilityMethodFor:aSelector category:cat in:aClass |
|
558 |
! |
|
559 |
||
560 |
createUpdateMethodIn:aClass |
|
561 |
"create an update:with:from:-method |
|
562 |
(I'm tired of typing)" |
|
563 |
||
564 |
^ self new createUpdateMethodIn:aClass |
|
565 |
! |
|
566 |
||
567 |
createVersionMethodFor:aClass |
|
568 |
"add version method containing RCS template |
|
569 |
but only if not already present and its not a private class." |
|
570 |
||
571 |
^ self new createVersionMethodFor:aClass |
|
572 |
! ! |
|
573 |
||
7973 | 574 |
!CodeGeneratorTool class methodsFor:'code generation-menus'! |
575 |
||
576 |
createActionMethodFor:aSelector in:aClass category:aCategory redefine:redefine |
|
577 |
|alreadyInSuperclass method code| |
|
578 |
||
579 |
(aClass includesSelector:aSelector) ifTrue:[ |
|
580 |
^ nil |
|
581 |
]. |
|
582 |
||
583 |
alreadyInSuperclass := aClass superclass canUnderstand:aSelector. |
|
584 |
(alreadyInSuperclass and:[redefine not]) ifTrue:[ |
|
585 |
^ nil |
|
586 |
]. |
|
587 |
||
588 |
method := self methodNameTemplateFor:aSelector. |
|
589 |
||
590 |
code := '%1 |
|
591 |
"automatically generated by UIEditor ..." |
|
592 |
||
593 |
"*** the code below performs no action" |
|
594 |
"*** (except for some feedback on the Transcript)" |
|
595 |
"*** Please change as required and accept in the browser." |
|
596 |
"*** (and replace this comment by something more useful ;-)" |
|
597 |
||
598 |
"action to be added ..." |
|
599 |
||
600 |
Transcript showCR:self class name, '': action for #%2 ...''. |
|
601 |
' bindWith:method with:aSelector. |
|
602 |
||
603 |
alreadyInSuperclass ifTrue:[ |
|
604 |
code := code, (('\ super %1\' bindWith:method) withCRs). |
|
605 |
]. |
|
606 |
self compile:code forClass:aClass inCategory:(aCategory ? 'actions'). |
|
607 |
^ code |
|
608 |
! |
|
609 |
||
610 |
createAspectMethodFor:aSelector in:aClass category:aCategory redefine:redefine |
|
611 |
|alreadyInSuperclass method code text| |
|
612 |
||
613 |
(aClass includesSelector:aSelector) ifTrue:[ |
|
614 |
^ nil |
|
615 |
]. |
|
616 |
||
617 |
alreadyInSuperclass := aClass superclass canUnderstand:aSelector. |
|
618 |
(alreadyInSuperclass and:[redefine not]) ifTrue:[ |
|
619 |
^ nil |
|
620 |
]. |
|
621 |
||
622 |
method := self methodNameTemplateFor:aSelector. |
|
623 |
||
624 |
code := '%1 |
|
625 |
"automatically generated by UIEditor ..." |
|
626 |
||
627 |
"*** the code below creates a default model when invoked" |
|
628 |
"*** (which may not be the one you wanted)" |
|
629 |
"*** Please change as required and accept in the browser." |
|
630 |
"*** (and replace this comment by something more useful ;-)" |
|
631 |
||
632 |
"aspect to be added ..." |
|
633 |
||
634 |
Transcript showCR:self class name, '': aspect for #%2 ...''. |
|
635 |
||
636 |
' bindWith:method with:aSelector. |
|
637 |
||
638 |
alreadyInSuperclass ifTrue:[ |
|
639 |
text := ' ^ super %1\' bindWith:method. |
|
640 |
] ifFalse:[ |
|
641 |
text := ' ^ builder valueAspectFor:#''%1'' initialValue:true\' bindWith:aSelector. |
|
642 |
]. |
|
643 |
code := code, (text withCRs). |
|
644 |
self compile:code forClass:aClass inCategory:(aCategory ? 'actions'). |
|
645 |
^ code |
|
646 |
! ! |
|
647 |
||
5758 | 648 |
!CodeGeneratorTool class methodsFor:'compilation'! |
649 |
||
650 |
compile:theCode forClass:aClass inCategory:cat |
|
651 |
"install some code for a class. |
|
652 |
If refactory browser stuff is avaliable the refactory tools are used to support undo" |
|
653 |
||
654 |
^ self new compile:theCode forClass:aClass inCategory:cat |
|
655 |
! ! |
|
656 |
||
8258 | 657 |
!CodeGeneratorTool class methodsFor:'defaults'! |
658 |
||
659 |
copyrightTemplate |
|
660 |
"return the contents of COPYRIGHT_TEMPLATE_FILE resources |
|
661 |
or a standard template" |
|
662 |
||
663 |
|fn| |
|
664 |
||
665 |
CopyrightTemplate notNil ifTrue:[^ CopyrightTemplate]. |
|
666 |
||
667 |
fn := SystemBrowser classResources at:#'COPYRIGHT_TEMPLATE_FILE' default:nil. |
|
668 |
fn notNil ifTrue:[ |
|
669 |
fn := fn asFilename. |
|
670 |
fn exists ifTrue:[ |
|
8488 | 671 |
^ fn contentsAsString. |
8258 | 672 |
]. |
673 |
]. |
|
674 |
^ ' COPYRIGHT (c) %1 by >>yourCompany<< |
|
675 |
All Rights Reserved |
|
676 |
||
677 |
This software is furnished under a license and may be used |
|
678 |
only in accordance with the terms of that license and with the |
|
679 |
inclusion of the above copyright notice. This software may not |
|
680 |
be provided or otherwise made available to, or used by, any |
|
681 |
other person. No title to or ownership of the software is |
|
682 |
hereby transferred. |
|
683 |
'. |
|
684 |
! |
|
685 |
||
686 |
copyrightTemplate:aString |
|
8488 | 687 |
"set the COPYRIGHT_TEMPLATE_FILE" |
688 |
||
8258 | 689 |
CopyrightTemplate := aString. |
690 |
! ! |
|
691 |
||
5758 | 692 |
!CodeGeneratorTool class methodsFor:'private'! |
693 |
||
694 |
canUseRefactoringSupport |
|
695 |
"check if refactory browser stuff is avaliable" |
|
696 |
||
697 |
^ RefactoryChangeManager notNil |
|
698 |
and:[RefactoryChangeManager isLoaded |
|
699 |
and:[UserPreferences current useRefactoringSupport]] |
|
7973 | 700 |
! |
701 |
||
702 |
methodNameTemplateFor:aSelector |
|
703 |
|numArgs method| |
|
704 |
||
705 |
numArgs := aSelector numArgs. |
|
706 |
numArgs == 1 ifTrue:[ |
|
707 |
method := aSelector, 'anArgument'. |
|
708 |
] ifFalse:[ |
|
709 |
numArgs == 0 ifTrue:[ |
|
710 |
method := aSelector |
|
711 |
] ifFalse:[ |
|
712 |
method := ''. |
|
713 |
aSelector keywords keysAndValuesDo:[:i :key| |
|
714 |
method := method, key, 'arg', i printString, ' '. |
|
715 |
]. |
|
716 |
] |
|
717 |
]. |
|
718 |
^ method |
|
5758 | 719 |
! ! |
720 |
||
5759 | 721 |
!CodeGeneratorTool methodsFor:'buld changes'! |
722 |
||
5763 | 723 |
addChange:aChange |
724 |
compositeChangeCollector addChange:aChange |
|
725 |
! |
|
726 |
||
5759 | 727 |
executeCollectedChangesNamed:name |
728 |
compositeChangeCollector notNil ifTrue:[ |
|
729 |
compositeChangeNesting := compositeChangeNesting - 1. |
|
730 |
compositeChangeNesting == 0 ifTrue:[ |
|
731 |
compositeChangeCollector name:name. |
|
732 |
compositeChangeCollector changesSize == 0 ifTrue:[ |
|
733 |
self information:'Nothing generated.'. |
|
734 |
] ifFalse:[ |
|
7037 | 735 |
RefactoryChangeManager performChange:compositeChangeCollector. |
5759 | 736 |
]. |
737 |
compositeChangeCollector := nil. |
|
738 |
] |
|
739 |
] |
|
740 |
! |
|
741 |
||
742 |
startCollectChanges |
|
743 |
(self canUseRefactoringSupport) ifTrue:[ |
|
744 |
compositeChangeCollector isNil ifTrue:[ |
|
745 |
compositeChangeCollector := CompositeRefactoryChange new. |
|
746 |
compositeChangeNesting := 0. |
|
747 |
]. |
|
748 |
compositeChangeNesting := compositeChangeNesting + 1. |
|
749 |
] |
|
750 |
! ! |
|
751 |
||
5758 | 752 |
!CodeGeneratorTool methodsFor:'code generation'! |
753 |
||
754 |
createAccessMethodsFor:aCollectionOfVarNames in:aClass withChange:withChange asValueHolder:asValueHolder readersOnly:readersOnly writersOnly:writersOnly |
|
755 |
"create accessors in aClass" |
|
756 |
||
757 |
self |
|
758 |
createAccessMethodsFor:aCollectionOfVarNames |
|
759 |
in:aClass |
|
760 |
withChange:withChange |
|
761 |
asValueHolder:asValueHolder |
|
762 |
readersOnly:readersOnly |
|
763 |
writersOnly:writersOnly |
|
764 |
lazyInitialization:false |
|
765 |
! |
|
766 |
||
767 |
createApplicationCodeFor:aClass |
|
768 |
"create an empty application framework" |
|
769 |
||
7480
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
770 |
|nonMetaClass metaClass className txt isDialog |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
771 |
categoryForMenuActionsMethods compileMenuAction compileTemplateAction| |
5758 | 772 |
|
773 |
self startCollectChanges. |
|
774 |
||
775 |
categoryForMenuActionsMethods := UserPreferences current categoryForMenuActionsMethods. |
|
776 |
||
777 |
nonMetaClass := aClass theNonMetaclass. |
|
778 |
metaClass := aClass theMetaclass. |
|
779 |
className := nonMetaClass name. |
|
780 |
||
781 |
isDialog := (nonMetaClass isSubclassOf:SimpleDialog). |
|
782 |
||
783 |
"/ add a windowSpec method for an empty applicationWindow, |
|
784 |
"/ with a menuPanel. |
|
785 |
||
786 |
(metaClass includesSelector:#windowSpec) ifFalse:[ |
|
787 |
isDialog ifTrue:[ |
|
788 |
txt := self class initialWindowSpecMethodSourceForDialogs. |
|
789 |
] ifFalse:[ |
|
790 |
txt := self class initialWindowSpecMethodSourceForApplications. |
|
791 |
]. |
|
792 |
self |
|
793 |
compile:(txt bindWith:className) |
|
794 |
forClass:metaClass |
|
795 |
inCategory:'interface specs'. |
|
796 |
]. |
|
797 |
||
7480
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
798 |
compileTemplateAction := |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
799 |
[:selector :category | |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
800 |
(nonMetaClass includesSelector:selector) ifFalse:[ |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
801 |
|codeTemplateSelector| |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
802 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
803 |
codeTemplateSelector := ('codeFor_',(selector upTo:$:)) asSymbol. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
804 |
txt := self perform:codeTemplateSelector. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
805 |
self |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
806 |
compile:txt |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
807 |
forClass:nonMetaClass |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
808 |
inCategory:(category = '*' ifTrue:categoryForMenuActionsMethods ifFalse:category). |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
809 |
] |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
810 |
]. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
811 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
812 |
#( |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
813 |
#'postBuildWith:' 'initialization & release' |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
814 |
#'postOpenWith:' 'initialization & release' |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
815 |
) pairWiseDo:compileTemplateAction. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
816 |
|
5758 | 817 |
isDialog ifFalse:[ |
818 |
"/ add a topMenu method |
|
819 |
||
820 |
(metaClass includesSelector:#mainMenu) ifFalse:[ |
|
821 |
txt := self class initialMenuSpecMethodSourceForApplications. |
|
822 |
self |
|
823 |
compile:(txt bindWith:className) |
|
824 |
forClass:metaClass |
|
825 |
inCategory:'menu specs'. |
|
826 |
]. |
|
827 |
||
7480
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
828 |
#( |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
829 |
#'hasUnsavedChanges' 'private queries' |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
830 |
#'closeRequest' 'initialization & release' |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
831 |
#'closeDownViews' 'initialization & release' |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
832 |
#'menuSaveAs' '*' |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
833 |
#'menuNew' '*' |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
834 |
#'menuOpen' '*' |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
835 |
#'menuSave' '*' |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
836 |
#'doSaveAs' '*' |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
837 |
#'openDocumentation' '*' |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
838 |
#'openAboutThisApplication' '*' |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
839 |
) pairWiseDo:compileTemplateAction. |
5758 | 840 |
]. |
841 |
||
842 |
isDialog ifTrue:[ |
|
7480
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
843 |
#( |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
844 |
#'closeAccept' 'user actions' |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
845 |
) pairWiseDo:compileTemplateAction. |
5758 | 846 |
]. |
847 |
||
6050 | 848 |
self executeCollectedChangesNamed:('Add Application Code for ' , className). |
5758 | 849 |
|
7480
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
850 |
"Modified: / 27-10-2006 / 10:21:58 / cg" |
5758 | 851 |
! |
852 |
||
853 |
createClassResponsibleProtocolFor:aClass |
|
854 |
"create stubs for the required protocol" |
|
855 |
||
6050 | 856 |
|nonMetaClass metaClass className| |
857 |
||
858 |
nonMetaClass := aClass theNonMetaclass. |
|
859 |
metaClass := aClass theMetaclass. |
|
860 |
className := nonMetaClass name. |
|
861 |
||
5758 | 862 |
self startCollectChanges. |
863 |
||
6050 | 864 |
self privCreateClassResponsibleProtocolFor:nonMetaClass. |
865 |
self privCreateClassResponsibleProtocolFor:metaClass. |
|
5758 | 866 |
|
6050 | 867 |
self executeCollectedChangesNamed:('Add Required Protocol to ' , className). |
5758 | 868 |
! |
869 |
||
870 |
createClassTypeTestMethodsIn:aClass forClasses:subClasses |
|
871 |
"create a #isXXX test methods (I'm tired of typing)" |
|
872 |
||
873 |
| code| |
|
874 |
||
875 |
self startCollectChanges. |
|
876 |
||
877 |
subClasses do:[:eachSubClass | |
|
878 |
|nm selector| |
|
879 |
||
880 |
nm := eachSubClass nameWithoutPrefix. |
|
881 |
selector := 'is' , nm. |
|
882 |
(aClass includesSelector:selector) ifFalse:[ |
|
883 |
code := (selector , '\ ^ false') withCRs. |
|
884 |
self |
|
885 |
compile:code |
|
886 |
forClass:aClass |
|
887 |
inCategory:'testing'. |
|
888 |
]. |
|
889 |
(eachSubClass includesSelector:selector) ifFalse:[ |
|
890 |
code := (selector , '\ ^ true') withCRs. |
|
891 |
self |
|
892 |
compile:code |
|
893 |
forClass:eachSubClass |
|
894 |
inCategory:'testing'. |
|
895 |
]. |
|
896 |
]. |
|
897 |
||
5759 | 898 |
self executeCollectedChangesNamed:'Add ClassType Tests' |
5758 | 899 |
! |
900 |
||
901 |
createDocumentationMethodsFor:aClass |
|
902 |
"create empty documentation methods" |
|
903 |
||
6050 | 904 |
|nonMetaClass metaClass className| |
5758 | 905 |
|
6050 | 906 |
nonMetaClass := aClass theNonMetaclass. |
907 |
metaClass := aClass theMetaclass. |
|
908 |
className := nonMetaClass name. |
|
5758 | 909 |
|
910 |
self startCollectChanges. |
|
911 |
||
6050 | 912 |
self createVersionMethodFor:metaClass. |
913 |
self createCopyrightMethodFor:metaClass. |
|
914 |
self createDocumentationMethodFor:metaClass. |
|
915 |
self createInitialHistoryMethodFor:metaClass. |
|
5758 | 916 |
|
6050 | 917 |
self executeCollectedChangesNamed:('Add Documentation to ' , className). |
5758 | 918 |
! |
919 |
||
6313 | 920 |
createEnumTypeCodeFor:aClass |
921 |
|nonMetaClass metaClass className enumValues code initCode runValue maxValue| |
|
922 |
||
923 |
self startCollectChanges. |
|
924 |
||
925 |
nonMetaClass := aClass theNonMetaclass. |
|
926 |
metaClass := aClass theMetaclass. |
|
927 |
className := nonMetaClass name. |
|
928 |
||
929 |
enumValues := nonMetaClass classVarNames. |
|
930 |
enumValues do:[:eachVariableName | |
|
931 |
self |
|
932 |
createAccessMethodsFor:(Array with:eachVariableName) |
|
933 |
in:metaClass |
|
934 |
withChange:false |
|
935 |
asValueHolder:false |
|
936 |
readersOnly:true |
|
937 |
writersOnly:false |
|
938 |
]. |
|
939 |
||
940 |
maxValue := enumValues inject:0 into:[:maxSoFar :eachVariableName | |oldVal val| |
|
941 |
oldVal := nonMetaClass classVarAt:eachVariableName. |
|
942 |
oldVal notNil ifTrue:[ val := oldVal numericValue ]. |
|
943 |
(val ? maxSoFar) max:maxSoFar]. |
|
944 |
||
945 |
initCode := WriteStream on: String new. |
|
946 |
initCode nextPutLine:'initialize'. |
|
947 |
runValue := maxValue + 1. |
|
948 |
enumValues keysAndValuesDo:[:idx :eachVariableName | |
|
949 |
|oldValue thisValue| |
|
950 |
||
951 |
oldValue := nonMetaClass classVarAt:eachVariableName. |
|
952 |
oldValue notNil ifTrue:[ |
|
953 |
thisValue := oldValue numericValue. |
|
954 |
] ifFalse:[ |
|
955 |
thisValue := runValue. |
|
956 |
runValue := runValue + 1. |
|
957 |
]. |
|
958 |
initCode |
|
959 |
nextPutAll:' '; |
|
960 |
nextPutAll:eachVariableName; |
|
961 |
nextPutAll:' := self basicNew'. |
|
962 |
(aClass canUnderstand:#'setNumericValue:') ifTrue:[ |
|
963 |
initCode nextPutAll:' setNumericValue: ',thisValue printString. |
|
964 |
]. |
|
965 |
(aClass canUnderstand:#'setCssClassString:') ifTrue:[ |
|
966 |
initCode nextPutAll:('; setCssClassString: ''' , nonMetaClass nameWithoutPrefix asLowercaseFirst , eachVariableName , ''''). |
|
967 |
]. |
|
968 |
(aClass canUnderstand:#'setName:') ifTrue:[ |
|
969 |
initCode nextPutAll:('; setName: ''' , eachVariableName asLowercaseFirst , ''''). |
|
970 |
]. |
|
971 |
initCode nextPutLine:'.'. |
|
972 |
]. |
|
973 |
initCode cr. |
|
974 |
initCode nextPutLine:' "'. |
|
975 |
initCode nextPutLine:' ',className, ' initialize'. |
|
976 |
initCode nextPutLine:' "'. |
|
977 |
||
978 |
self |
|
979 |
compile:(initCode contents) |
|
980 |
forClass:metaClass |
|
981 |
inCategory:'class initialization'. |
|
982 |
||
983 |
||
984 |
code := 'allStateNames\ ^ #( ' , |
|
6341 | 985 |
((enumValues collect:[:each | '#''',each asLowercaseFirst,'''']) asStringWith:' ') , ')', |
6313 | 986 |
'\\ "\' , |
987 |
' ',className, ' allStateNames\' , |
|
988 |
' "\'. |
|
989 |
self |
|
990 |
compile:code withCRs |
|
991 |
forClass:metaClass |
|
992 |
inCategory:'queries'. |
|
993 |
||
994 |
self executeCollectedChangesNamed:('Generate EnumType Code for ' , className). |
|
995 |
||
996 |
aClass initialize. |
|
997 |
||
998 |
"Modified: / 1.2.1998 / 16:10:03 / cg" |
|
999 |
! |
|
1000 |
||
6718 | 1001 |
createInitializedInstanceCreationMethodsIn:aClass |
5758 | 1002 |
"create a #new and #initialize methods (I'm tired of typing)" |
1003 |
||
6050 | 1004 |
|nonMetaClass metaClass className code initializer m| |
1005 |
||
1006 |
nonMetaClass := aClass theNonMetaclass. |
|
1007 |
metaClass := aClass theMetaclass. |
|
1008 |
className := nonMetaClass name. |
|
5758 | 1009 |
|
1010 |
self startCollectChanges. |
|
1011 |
||
6050 | 1012 |
(nonMetaClass includesSelector:#'initialize') ifFalse:[ |
5758 | 1013 |
code := |
1014 |
'initialize |
|
1015 |
"Invoked when a new instance is created." |
|
1016 |
||
1017 |
"/ please change as required (and remove this comment) |
|
1018 |
'. |
|
1019 |
||
6718 | 1020 |
nonMetaClass instVarNames do:[:eachInstVar | |
1021 |
initializer := 'nil'. "/ need more intelligence here (try to guess class from messages sent to it) ... |
|
1022 |
code := code , (' "/ ' , eachInstVar , ' := ' , initializer , '.' , Character cr). |
|
1023 |
]. |
|
5758 | 1024 |
|
6718 | 1025 |
m := nonMetaClass responseTo:#initialize. |
1026 |
(m notNil and:[m messagesSent size == 0]) ifTrue:[ |
|
1027 |
"/ inherits an empty initialize. |
|
5758 | 1028 |
|
6718 | 1029 |
code := code , ' |
5758 | 1030 |
"/ super initialize. -- commented since inherited method does nothing |
1031 |
'. |
|
6718 | 1032 |
] ifFalse:[ |
1033 |
code := code , ' |
|
1034 |
super initialize. |
|
1035 |
'. |
|
5758 | 1036 |
]. |
1037 |
||
1038 |
self |
|
1039 |
compile:code |
|
6050 | 1040 |
forClass:nonMetaClass |
5758 | 1041 |
inCategory:'initialization'. |
1042 |
]. |
|
1043 |
||
6050 | 1044 |
(metaClass includesSelector:#'new') ifFalse:[ |
1045 |
m := metaClass responseTo:#new. |
|
6718 | 1046 |
(m isNil |
1047 |
or:[ (m sends:#initialize) not |
|
1048 |
or:[ |answer| |
|
1049 |
(Dialog |
|
1050 |
confirmWithCancel:'The inherited #new method already seems to invoke #initialize. Redefine ?' |
|
1051 |
onCancel:[^ self]) ]]) ifTrue:[ |
|
1052 |
code := |
|
5758 | 1053 |
'new |
1054 |
^ self basicNew initialize. |
|
1055 |
'. |
|
6718 | 1056 |
self |
1057 |
compile:code |
|
1058 |
forClass:metaClass |
|
1059 |
inCategory:'instance creation'. |
|
1060 |
]. |
|
1061 |
]. |
|
1062 |
||
1063 |
self executeCollectedChangesNamed:('Add Initialized Instance Creation to ' , className). |
|
1064 |
||
1065 |
"Created: / 11.10.2001 / 22:18:55 / cg" |
|
1066 |
! |
|
1067 |
||
1068 |
createParametrizedInstanceCreationMethodsNamed:selector in:aClass |
|
1069 |
"create a #selector instance creation method (I'm tired of typing)" |
|
1070 |
||
1071 |
|nonMetaClass metaClass className code initializer m dfn| |
|
1072 |
||
1073 |
dfn := Method methodDefinitionTemplateForSelector:selector. |
|
1074 |
||
1075 |
nonMetaClass := aClass theNonMetaclass. |
|
1076 |
metaClass := aClass theMetaclass. |
|
1077 |
className := nonMetaClass name. |
|
1078 |
||
1079 |
self startCollectChanges. |
|
1080 |
||
1081 |
(nonMetaClass includesSelector:selector asSymbol) ifFalse:[ |
|
1082 |
code := |
|
1083 |
'initialize',dfn asUppercaseFirst,' |
|
1084 |
"Invoked when a new instance is created for arg." |
|
1085 |
||
1086 |
"/ please change as required (and remove these comments) |
|
1087 |
"/ do something with arg here (instVar-foo := arg) |
|
1088 |
'. |
|
1089 |
nonMetaClass instVarNames do:[:eachInstVar | |
|
1090 |
initializer := 'nil'. "/ need more intelligence here (try to guess class from messages sent to it) ... |
|
1091 |
code := code , (' "/ ' , eachInstVar , ' := ' , initializer , '.' , Character cr). |
|
1092 |
]. |
|
1093 |
||
1094 |
m := nonMetaClass responseTo:#initialize. |
|
1095 |
(m notNil and:[ m messagesSent size == 0 ]) ifTrue:[ |
|
1096 |
"/ inherits an empty initialize. |
|
1097 |
||
1098 |
code := code , ' |
|
1099 |
"/ super initialize. -- commented since inherited method does nothing |
|
1100 |
'. |
|
1101 |
] ifFalse:[ |
|
1102 |
code := code , ' |
|
1103 |
super initialize. |
|
1104 |
'. |
|
1105 |
]. |
|
1106 |
||
5758 | 1107 |
self |
1108 |
compile:code |
|
6718 | 1109 |
forClass:nonMetaClass |
1110 |
inCategory:'initialization'. |
|
5758 | 1111 |
]. |
1112 |
||
6718 | 1113 |
(metaClass includesSelector:selector) ifFalse:[ |
1114 |
m := metaClass responseTo:selector. |
|
1115 |
(m isNil |
|
1116 |
or:[ (Dialog confirmWithCancel:'The ',selector,'- method is already inherited. Redefine ?' onCancel:[^ self]) ]) |
|
1117 |
ifTrue:[ |
|
1118 |
code := |
|
1119 |
dfn,' |
|
1120 |
"Create & return a new instance for arg." |
|
5758 | 1121 |
|
6718 | 1122 |
^ self basicNew initialize',dfn asUppercaseFirst,' |
1123 |
'. |
|
1124 |
self |
|
1125 |
compile:code |
|
1126 |
forClass:metaClass |
|
1127 |
inCategory:'instance creation'. |
|
1128 |
]. |
|
1129 |
]. |
|
1130 |
||
1131 |
self executeCollectedChangesNamed:('Add Parametrized Instance Creation to ' , className). |
|
5758 | 1132 |
! |
1133 |
||
7470 | 1134 |
createPoolInitializationCodeFor:aClass |
1135 |
|nonMetaClass metaClass className poolVars code initCode runValue maxValue| |
|
1136 |
||
1137 |
self startCollectChanges. |
|
1138 |
||
1139 |
nonMetaClass := aClass theNonMetaclass. |
|
1140 |
metaClass := aClass theMetaclass. |
|
1141 |
className := nonMetaClass name. |
|
1142 |
||
1143 |
poolVars := nonMetaClass classVarNames. |
|
1144 |
||
1145 |
initCode := WriteStream on: String new. |
|
1146 |
initCode nextPutLine:'initialize'. |
|
1147 |
||
1148 |
poolVars do:[:eachVariableName | |
|
1149 |
|oldValue thisValue| |
|
1150 |
||
1151 |
oldValue := nonMetaClass classVarAt:eachVariableName. |
|
1152 |
oldValue notNil ifTrue:[ |
|
1153 |
thisValue := oldValue. |
|
1154 |
] ifFalse:[ |
|
1155 |
thisValue := nil. |
|
1156 |
]. |
|
1157 |
initCode |
|
1158 |
nextPutAll:' '; |
|
1159 |
nextPutAll:eachVariableName; |
|
1160 |
nextPutAll:' := '; |
|
1161 |
nextPutAll:thisValue storeString; |
|
1162 |
nextPutLine:'.'. |
|
1163 |
]. |
|
1164 |
initCode cr. |
|
1165 |
initCode nextPutLine:' "'. |
|
1166 |
initCode nextPutLine:' ',className, ' initialize'. |
|
1167 |
initCode nextPutLine:' "'. |
|
1168 |
||
1169 |
self |
|
1170 |
compile:(initCode contents) |
|
1171 |
forClass:metaClass |
|
1172 |
inCategory:'class initialization'. |
|
1173 |
||
1174 |
self executeCollectedChangesNamed:('Generate Pool Initialization Code for ' , className). |
|
1175 |
||
1176 |
aClass initialize. |
|
1177 |
||
1178 |
"Created: / 25-10-2006 / 09:28:40 / cg" |
|
1179 |
! |
|
1180 |
||
8344
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1181 |
createRedefinedInstanceCreationMethodsIn:aClass |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1182 |
"create a redefined #new methods" |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1183 |
|
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1184 |
|nonMetaClass metaClass className code| |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1185 |
|
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1186 |
nonMetaClass := aClass theNonMetaclass. |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1187 |
metaClass := aClass theMetaclass. |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1188 |
className := nonMetaClass name. |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1189 |
|
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1190 |
self startCollectChanges. |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1191 |
|
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1192 |
(metaClass includesSelector:#'new') ifFalse:[ |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1193 |
code := |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1194 |
'new |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1195 |
^ super new. |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1196 |
'. |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1197 |
self |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1198 |
compile:code |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1199 |
forClass:metaClass |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1200 |
inCategory:'redefined instance creation'. |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1201 |
]. |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1202 |
(metaClass includesSelector:#'new:') ifFalse:[ |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1203 |
code := |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1204 |
'new:n |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1205 |
^ super new:n. |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1206 |
'. |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1207 |
self |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1208 |
compile:code |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1209 |
forClass:metaClass |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1210 |
inCategory:'redefined instance creation'. |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1211 |
]. |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1212 |
|
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1213 |
self executeCollectedChangesNamed:('Redefined Instance Creation to ' , className). |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1214 |
! |
efda36a55d02
changed #createRedefinedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
8258
diff
changeset
|
1215 |
|
5953 | 1216 |
createStandardPrintOnMethodIn:aClass |
1217 |
"create a #printOn: method (I'm tired of typing)" |
|
1218 |
||
6050 | 1219 |
|code nonMetaClass| |
1220 |
||
1221 |
nonMetaClass := aClass theNonMetaclass. |
|
5953 | 1222 |
|
1223 |
self startCollectChanges. |
|
1224 |
||
6050 | 1225 |
(nonMetaClass includesSelector:#'printOn:') ifFalse:[ |
5953 | 1226 |
code := |
1227 |
'printOn:aStream |
|
1228 |
"append a printed representation if the receiver to the argument, aStream" |
|
1229 |
||
1230 |
super printOn:aStream. |
|
1231 |
'. |
|
6050 | 1232 |
nonMetaClass instVarNames do:[:eachInstVarName | |
5953 | 1233 |
code := code , ' '. |
1234 |
code := code , 'aStream nextPutAll:'''. |
|
1235 |
code := code , eachInstVarName. |
|
1236 |
code := code , ': ''.' , Character cr. |
|
1237 |
code := code , ' '. |
|
1238 |
code := code , eachInstVarName. |
|
1239 |
code := code , ' printOn:aStream.' , Character cr. |
|
1240 |
||
1241 |
]. |
|
1242 |
||
1243 |
self |
|
1244 |
compile:code |
|
6050 | 1245 |
forClass:nonMetaClass |
5953 | 1246 |
inCategory:'printing & storing'. |
1247 |
]. |
|
1248 |
||
1249 |
||
6050 | 1250 |
self executeCollectedChangesNamed:('Add #printOn: to ' , nonMetaClass name). |
5953 | 1251 |
|
1252 |
"Created: / 11.10.2001 / 22:18:55 / cg" |
|
1253 |
! |
|
1254 |
||
5758 | 1255 |
createTestCaseSampleCodeFor:aClass |
1256 |
"create an (almost) empty testCase class" |
|
1257 |
||
1258 |
|nonMetaClass metaClass| |
|
1259 |
||
1260 |
nonMetaClass := aClass theNonMetaclass. |
|
1261 |
metaClass := aClass theMetaclass. |
|
1262 |
"/ className := nonMetaClass name. |
|
1263 |
||
1264 |
( nonMetaClass includesSelector:#test1 ) ifFalse:[ |
|
1265 |
self |
|
1266 |
compile: |
|
1267 |
'test1 |
|
1268 |
"This is a demonstration testCase - it is meant to be removed eventually. |
|
1269 |
This testCase will PASS. |
|
1270 |
Double click on the TestCase class or open a TestRunner to see me checking... |
|
1271 |
- please add more methods like this..." |
|
1272 |
||
1273 |
|o| |
|
1274 |
||
1275 |
o := Array new:2. |
|
1276 |
self assert: ( o size == 2 ). |
|
1277 |
self should: [ o at:0 ] raise:Error. |
|
1278 |
self shouldnt: [ o at:1 ] raise:Error. |
|
1279 |
||
1280 |
" |
|
1281 |
self run:#test1 |
|
1282 |
self new test1 |
|
1283 |
" |
|
1284 |
' |
|
1285 |
forClass:nonMetaClass |
|
1286 |
inCategory:'tests'. |
|
1287 |
]. |
|
1288 |
||
1289 |
( nonMetaClass includesSelector:#test2 ) ifFalse:[ |
|
1290 |
self |
|
1291 |
compile: |
|
1292 |
'test2 |
|
1293 |
"This is a demonstration testCase - it is meant to be removed eventually.. |
|
1294 |
This testCase WILL FAIL. |
|
1295 |
Double click on the TestCase class or open a TestRunner to see me checking... |
|
1296 |
- please add more methods like this..." |
|
1297 |
||
1298 |
|o| |
|
1299 |
||
1300 |
o := Array new:2. |
|
1301 |
self assert: ( o size == 3 ). |
|
1302 |
||
1303 |
" |
|
1304 |
self run:#test2 |
|
1305 |
self new test2 |
|
1306 |
" |
|
1307 |
' |
|
1308 |
forClass:nonMetaClass |
|
1309 |
inCategory:'tests'. |
|
1310 |
]. |
|
1311 |
||
1312 |
( nonMetaClass includesSelector:#test3 ) ifFalse:[ |
|
1313 |
self |
|
1314 |
compile: |
|
1315 |
'test3 |
|
1316 |
"This is a demonstration testCase - it is meant to be removed eventually.. |
|
1317 |
This testCase WILL generate an ERROR. |
|
1318 |
Double click on the TestCase class or open a TestRunner to see me checking... |
|
1319 |
- please add more methods like this..." |
|
1320 |
||
1321 |
|o| |
|
1322 |
||
1323 |
o := Array new:2. |
|
1324 |
self assert: ( o foo ). |
|
1325 |
||
1326 |
" |
|
1327 |
self run:#test3 |
|
1328 |
self new test3 |
|
1329 |
" |
|
1330 |
' |
|
1331 |
forClass:nonMetaClass |
|
1332 |
inCategory:'tests'. |
|
1333 |
]. |
|
1334 |
||
1335 |
( nonMetaClass includesSelector:#setUp ) ifFalse:[ |
|
1336 |
self |
|
1337 |
compile: |
|
1338 |
'setUp |
|
1339 |
"common setup - invoked before testing." |
|
1340 |
||
1341 |
super setUp |
|
1342 |
' |
|
1343 |
forClass:nonMetaClass |
|
1344 |
inCategory:'initialize / release'. |
|
1345 |
]. |
|
1346 |
||
1347 |
( nonMetaClass includesSelector:#tearDown ) ifFalse:[ |
|
1348 |
self |
|
1349 |
compile: |
|
1350 |
'tearDown |
|
1351 |
"common cleanup - invoked after testing." |
|
1352 |
||
1353 |
super tearDown |
|
1354 |
' |
|
1355 |
forClass:nonMetaClass |
|
1356 |
inCategory:'initialize / release'. |
|
1357 |
] |
|
1358 |
! |
|
1359 |
||
1360 |
createVisitorMethodsIn:visitedClass andVisitorClass:visitorClass |
|
1361 |
"create acceptVisitor: in visitedClass and acceptXXX in visitorClass. (I'm tired of typing)" |
|
1362 |
||
1363 |
|sel| |
|
1364 |
||
6921 | 1365 |
self assert:( visitedClass isMeta not ). |
1366 |
self assert:( visitorClass isMeta not ). |
|
5758 | 1367 |
|
1368 |
self startCollectChanges. |
|
1369 |
||
1370 |
sel := ('visit' , visitedClass nameWithoutPrefix , ':'). |
|
1371 |
self createAcceptVisitorMethod:sel in:visitedClass. |
|
1372 |
||
1373 |
(visitorClass includesSelector:sel) ifFalse:[ |
|
1374 |
self |
|
1375 |
compile: |
|
1376 |
(('%1anObject |
|
1377 |
"dispatched back from the visited %2-object (visitor pattern)" |
|
1378 |
||
1379 |
"fall back to general object-case - please change as required" |
|
1380 |
||
1381 |
^ self visitObject:anObject |
|
1382 |
') bindWith:sel with:visitedClass nameWithoutPrefix asLowercaseFirst) |
|
1383 |
forClass:visitorClass |
|
1384 |
inCategory:'visiting'. |
|
1385 |
]. |
|
1386 |
||
1387 |
(visitorClass includesSelector:#'visitObject:') ifFalse:[ |
|
1388 |
self |
|
1389 |
compile: |
|
1390 |
('visitObject:anObject |
|
1391 |
"dispatched back from the visited objects (visitor pattern)" |
|
1392 |
||
1393 |
"general fallBack - please change as required" |
|
1394 |
||
1395 |
self halt:''not yet implemented'' |
|
1396 |
') |
|
1397 |
forClass:visitorClass |
|
1398 |
inCategory:'visiting'. |
|
1399 |
]. |
|
1400 |
||
1401 |
(visitorClass includesSelector:#'visit:') ifFalse:[ |
|
1402 |
self |
|
1403 |
compile: |
|
1404 |
('visit:anObject |
|
1405 |
"visit anObject (visitor pattern). |
|
1406 |
The object should call back one of my visitXXXX methods." |
|
1407 |
||
1408 |
^ anObject acceptVisitor:self |
|
1409 |
') |
|
1410 |
forClass:visitorClass |
|
1411 |
inCategory:'visiting'. |
|
1412 |
]. |
|
1413 |
||
1414 |
self executeCollectedChangesNamed:('Add Visitor Pattern'). |
|
6050 | 1415 |
! |
1416 |
||
1417 |
createWebApplicationCodeFor:aClass |
|
1418 |
"create an empty webApplication framework" |
|
1419 |
||
1420 |
|nonMetaClass metaClass className txt| |
|
1421 |
||
1422 |
self startCollectChanges. |
|
1423 |
||
1424 |
nonMetaClass := aClass theNonMetaclass. |
|
1425 |
metaClass := aClass theMetaclass. |
|
1426 |
className := nonMetaClass name. |
|
1427 |
||
7973 | 1428 |
(metaClass includesSelector:#pageSpec) ifFalse:[ |
1429 |
txt := self class initialPageSpecMethodSourceForWebApplications. |
|
1430 |
self |
|
1431 |
compile:(txt bindWith:className) |
|
1432 |
forClass:metaClass |
|
1433 |
inCategory:'page specs'. |
|
1434 |
]. |
|
1435 |
||
1436 |
self executeCollectedChangesNamed:('Add WebApplication Code for ' , className). |
|
1437 |
||
1438 |
"Modified: / 1.2.1998 / 16:10:03 / cg" |
|
1439 |
! |
|
1440 |
||
1441 |
createWebServiceCodeFor:aClass |
|
1442 |
"create an empty webService framework" |
|
1443 |
||
1444 |
|nonMetaClass metaClass className txt| |
|
1445 |
||
1446 |
self startCollectChanges. |
|
1447 |
||
1448 |
nonMetaClass := aClass theNonMetaclass. |
|
1449 |
metaClass := aClass theMetaclass. |
|
1450 |
className := nonMetaClass name. |
|
1451 |
||
6050 | 1452 |
(nonMetaClass includesSelector:#process:) ifFalse:[ |
1453 |
txt := |
|
1454 |
'process:aRequest |
|
7973 | 1455 |
"This is the web services main processing method. |
6050 | 1456 |
It will be invoked for every incoming webBrowser-request. |
1457 |
The argument, aRequest contains the parameters (url, fields, parameters etc.)." |
|
1458 |
||
1459 |
|response| |
|
1460 |
||
1461 |
response := aRequest response. |
|
1462 |
response nextPutLine:''<HTML>''. |
|
1463 |
response nextPutLine:'' <HEAD>''. |
|
1464 |
response nextPutLine:'' <TITLE>Hello</TITLE>''. |
|
1465 |
response nextPutLine:'' </HEAD>''. |
|
1466 |
response nextPutLine:'' <BODY>''. |
|
1467 |
response nextPutLine:'' <H1>Hello World !!</H1>''. |
|
1468 |
response nextPutLine:'' </BODY>''. |
|
1469 |
response nextPutLine:''</HTML>''. |
|
1470 |
'. |
|
1471 |
self |
|
1472 |
compile:txt |
|
1473 |
forClass:nonMetaClass |
|
1474 |
inCategory:'response generation'. |
|
1475 |
]. |
|
1476 |
||
1477 |
(metaClass includesSelector:#linkName) ifFalse:[ |
|
1478 |
txt := |
|
1479 |
'linkName |
|
1480 |
"return the default linkName path (with slash)." |
|
1481 |
||
1482 |
^ ''/NewService'' |
|
1483 |
'. |
|
1484 |
self |
|
1485 |
compile:txt |
|
1486 |
forClass:metaClass |
|
1487 |
inCategory:'defaults'. |
|
1488 |
]. |
|
1489 |
||
1490 |
(metaClass includesSelector:#settingsApplicationClass) ifFalse:[ |
|
1491 |
txt := |
|
1492 |
'settingsApplicationClass |
|
1493 |
"a SettingsApplication class - or nil (used in the settings dialog if non-nil)." |
|
1494 |
||
1495 |
^ nil |
|
1496 |
'. |
|
1497 |
self |
|
1498 |
compile:txt |
|
1499 |
forClass:metaClass |
|
1500 |
inCategory:'defaults'. |
|
1501 |
]. |
|
1502 |
||
1503 |
||
7973 | 1504 |
self executeCollectedChangesNamed:('Add WebService Code for ' , className). |
6050 | 1505 |
|
1506 |
"Modified: / 1.2.1998 / 16:10:03 / cg" |
|
5758 | 1507 |
! ! |
1508 |
||
1509 |
!CodeGeneratorTool methodsFor:'code generation-basic'! |
|
1510 |
||
1511 |
createAccessMethodsFor:aCollectionOfVarNames in:aClass withChange:withChange asValueHolder:asValueHolder readersOnly:readersOnly writersOnly:writersOnly lazyInitialization:lazyInitialization |
|
1512 |
"workhorse for creating access methods for instvars." |
|
1513 |
||
1514 |
|classesClassVars generateComments generateCommentsForSetters generateCommentsForGetters| |
|
1515 |
||
1516 |
self startCollectChanges. |
|
1517 |
||
1518 |
generateComments := UserPreferences current generateComments. |
|
1519 |
generateCommentsForSetters := UserPreferences current generateCommentsForSetters. |
|
1520 |
generateCommentsForGetters := UserPreferences current generateCommentsForGetters. |
|
5013
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1521 |
|
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1522 |
classesClassVars := aClass theNonMetaclass allClassVarNames. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1523 |
|
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1524 |
aCollectionOfVarNames do:[:name | |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1525 |
|source varType methodName defaultMethodName| |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1526 |
|
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1527 |
varType := (classesClassVars includes:name) |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1528 |
ifTrue:['static'] |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1529 |
ifFalse:[ |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1530 |
(aClass isMeta ifTrue:['classInstVar'] ifFalse:['instance'])]. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1531 |
|
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1532 |
methodName := name. |
6643 | 1533 |
name isUppercaseFirst ifTrue:[ |
5013
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1534 |
methodName := methodName asLowercaseFirst. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1535 |
]. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1536 |
|
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1537 |
"/ the GETTER |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1538 |
writersOnly ifFalse:[ |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1539 |
lazyInitialization ifTrue:[ |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1540 |
defaultMethodName := 'default' , name asUppercaseFirst. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1541 |
]. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1542 |
|
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1543 |
"check, if method is not already present" |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1544 |
(aClass includesSelector:(methodName asSymbol)) ifFalse:[ |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1545 |
asValueHolder ifTrue:[ |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1546 |
source := methodName , '\'. |
5758 | 1547 |
generateComments ifTrue:[ |
5013
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1548 |
source := source , ' "return/create the ''%2'' value holder (automatically generated)"\\'. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1549 |
]. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1550 |
source := source , ' %2 isNil ifTrue:[\'. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1551 |
lazyInitialization ifTrue:[ |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1552 |
source := source |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1553 |
, ' %2 := self class %3 asValue.\'. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1554 |
] ifFalse:[ |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1555 |
source := source |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1556 |
, ' %2 := ValueHolder new.\'. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1557 |
]. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1558 |
|
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1559 |
withChange ifTrue:[ |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1560 |
source := source |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1561 |
, ' %2 addDependent:self.\'. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1562 |
]. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1563 |
source := source |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1564 |
, ' ].\' |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1565 |
, ' ^ %2'. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1566 |
] ifFalse:[ |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1567 |
source := methodName , '\'. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1568 |
lazyInitialization ifTrue:[ |
5758 | 1569 |
generateCommentsForGetters ifTrue:[ |
5013
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1570 |
source := source , ' "return the %1 instance variable ''%2'' with lazy instance creation (automatically generated)"\\'. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1571 |
]. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1572 |
source := source |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1573 |
, ' %2 isNil ifTrue:[\' |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1574 |
, ' %2 := self class %3.\' |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1575 |
, ' ].\' |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1576 |
, ' ^ %2'. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1577 |
] ifFalse:[ |
5758 | 1578 |
generateCommentsForGetters ifTrue:[ |
5013
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1579 |
source := source , ' "return the %1 instance variable ''%2'' (automatically generated)"\\'. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1580 |
]. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1581 |
source := source |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1582 |
, ' ^ %2'. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1583 |
]. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1584 |
]. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1585 |
source := (source bindWith:varType with:name with:defaultMethodName) withCRs. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1586 |
self compile:source forClass:aClass inCategory:(asValueHolder ifTrue:['aspects'] ifFalse:['accessing']). |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1587 |
] ifTrue:[ |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1588 |
Transcript showCR:'method ''', methodName , ''' already present' |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1589 |
]. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1590 |
|
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1591 |
"/ default for lazy on class side |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1592 |
lazyInitialization ifTrue:[ |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1593 |
(aClass class includesSelector:(defaultMethodName asSymbol)) ifFalse:[ |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1594 |
source := defaultMethodName , '\'. |
5758 | 1595 |
generateComments ifTrue:[ |
5013
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1596 |
source := source , ' "default value for the ''%2'' instance variable (automatically generated)"\\'. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1597 |
]. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1598 |
source := source |
6839
c25218305e50
Send #shouldImplement instead of #halt:.
Stefan Vogel <sv@exept.de>
parents:
6791
diff
changeset
|
1599 |
, ' self shouldImplement.\' |
5013
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1600 |
, ' ^ nil.'. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1601 |
source := (source bindWith:varType with:name) withCRs. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1602 |
self compile:source forClass:aClass class inCategory:'defaults'. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1603 |
]. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1604 |
]. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1605 |
]. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1606 |
|
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1607 |
"/ the SETTER |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1608 |
readersOnly ifFalse:[ |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1609 |
(aClass includesSelector:((methodName , ':') asSymbol)) ifFalse:[ |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1610 |
asValueHolder ifTrue:[ |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1611 |
source := methodName , ':something\'. |
5758 | 1612 |
generateComments ifTrue:[ |
5013
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1613 |
source := source , ' "set the ''%2'' value holder' , ' (automatically generated)"\\'. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1614 |
]. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1615 |
withChange ifTrue:[ |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1616 |
source := source |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1617 |
, ' |oldValue newValue|\\' |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1618 |
, ' %2 notNil ifTrue:[\' |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1619 |
, ' oldValue := %2 value.\' |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1620 |
, ' %2 removeDependent:self.\' |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1621 |
, ' ].\' |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1622 |
, ' %2 := something.\' |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1623 |
, ' %2 notNil ifTrue:[\' |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1624 |
, ' %2 addDependent:self.\' |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1625 |
, ' ].\' |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1626 |
, ' newValue := %2 value.\' |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1627 |
, ' oldValue ~~ newValue ifTrue:[\' |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1628 |
, ' self update:#value with:newValue from:%2.\' |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1629 |
, ' ].\' |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1630 |
] ifFalse:[ |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1631 |
source := source |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1632 |
, ' %2 := something.'. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1633 |
]. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1634 |
] ifFalse:[ |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1635 |
source := methodName , ':something\'. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1636 |
withChange ifTrue:[ |
5758 | 1637 |
generateComments ifTrue:[ |
5013
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1638 |
source := source , ' "set the value of the %1 variable ''%2'''. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1639 |
source := source , ' and send a change notification (automatically generated)"\\'. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1640 |
]. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1641 |
source := source |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1642 |
, ' (%2 ~~ something) ifTrue:[\' |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1643 |
, ' %2 := something.\' |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1644 |
, ' self changed:#%2.\' |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1645 |
, ' ].\'. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1646 |
] ifFalse:[ |
5758 | 1647 |
generateCommentsForSetters ifTrue:[ |
5013
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1648 |
source := source , ' "set the value of the %1 variable ''%2'''. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1649 |
source := source , ' (automatically generated)"\\'. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1650 |
]. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1651 |
source := source |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1652 |
, ' %2 := something.'. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1653 |
]. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1654 |
]. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1655 |
source := (source bindWith:varType with:name) withCRs. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1656 |
self |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1657 |
compile:source |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1658 |
forClass:aClass |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1659 |
inCategory:(asValueHolder ifTrue:['aspects'] ifFalse:['accessing']). |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1660 |
] ifTrue:[ |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1661 |
Transcript showCR:'method ''', methodName , ':'' already present' |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1662 |
]. |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1663 |
]. |
5758 | 1664 |
]. |
1665 |
||
1666 |
self executeCollectedChangesNamed:('Add Accessors'). |
|
5763 | 1667 |
! |
1668 |
||
7615 | 1669 |
createCollectionAccessMethodsFor:aCollectionOfVarNames in:aClass withChange:withChange |
1670 |
||
1671 |
|classesClassVars generateComments generateCommentsForSetters generateCommentsForGetters| |
|
1672 |
||
1673 |
self startCollectChanges. |
|
1674 |
||
1675 |
generateComments := UserPreferences current generateComments. |
|
1676 |
||
1677 |
classesClassVars := aClass theNonMetaclass allClassVarNames. |
|
1678 |
||
1679 |
aCollectionOfVarNames do:[:name | |
|
1680 |
|source varType methodNameBase methodName defaultMethodName| |
|
1681 |
||
1682 |
varType := (classesClassVars includes:name) |
|
1683 |
ifTrue:['static'] |
|
1684 |
ifFalse:[ |
|
1685 |
(aClass isMeta ifTrue:['classInstVar'] ifFalse:['instance'])]. |
|
1686 |
||
1687 |
methodNameBase := name asUppercaseFirst. |
|
1688 |
(methodNameBase endsWith:'s') ifTrue:[ |
|
1689 |
methodNameBase := methodNameBase copyWithoutLast:1. |
|
1690 |
]. |
|
1691 |
methodName := 'add' , methodNameBase, ':'. |
|
1692 |
||
1693 |
"check, if method is not already present" |
|
1694 |
(aClass includesSelector:(methodName asSymbol)) ifFalse:[ |
|
1695 |
source := methodName , 'a%1\'. |
|
1696 |
generateComments ifTrue:[ |
|
1697 |
source := source , ' "add a ',methodNameBase,'"\\'. |
|
1698 |
]. |
|
1699 |
source := source , ' %2 isNil ifTrue:[\'. |
|
1700 |
source := source |
|
1701 |
, ' %2 := OrderedCollection new.\'. |
|
1702 |
source := source |
|
1703 |
, ' ].\' |
|
1704 |
, ' %2 add: a%1'. |
|
1705 |
source := (source bindWith:methodNameBase with:name) withCRs. |
|
1706 |
self compile:source forClass:aClass inCategory:'accessing'. |
|
1707 |
] ifTrue:[ |
|
1708 |
Transcript showCR:'method ''', methodName , ''' already present' |
|
1709 |
]. |
|
1710 |
||
1711 |
methodName := 'remove' , methodNameBase, ':'. |
|
1712 |
||
1713 |
"check, if method is not already present" |
|
1714 |
(aClass includesSelector:(methodName asSymbol)) ifFalse:[ |
|
1715 |
source := methodName , 'a%1\'. |
|
1716 |
generateComments ifTrue:[ |
|
1717 |
source := source , ' "remove a ',methodNameBase,'"\\'. |
|
1718 |
]. |
|
1719 |
source := source |
|
1720 |
, ' %2 remove: a%1'. |
|
1721 |
source := (source bindWith:methodNameBase with:name) withCRs. |
|
1722 |
self compile:source forClass:aClass inCategory:'accessing'. |
|
1723 |
] ifTrue:[ |
|
1724 |
Transcript showCR:'method ''', methodName , ''' already present' |
|
1725 |
]. |
|
1726 |
]. |
|
1727 |
||
1728 |
self |
|
1729 |
createAccessMethodsFor:aCollectionOfVarNames |
|
1730 |
in:aClass |
|
1731 |
withChange:withChange |
|
1732 |
asValueHolder:false |
|
1733 |
readersOnly:true |
|
1734 |
writersOnly:false |
|
1735 |
lazyInitialization:false. |
|
1736 |
||
1737 |
self executeCollectedChangesNamed:('Add Collection Access'). |
|
1738 |
||
1739 |
"Created: / 04-02-2007 / 15:52:31 / cg" |
|
1740 |
! |
|
1741 |
||
5763 | 1742 |
createValueHoldersFor:aCollectionOfVarNames in:aClass lazyInitialization:lazyInitialization |
1743 |
"workhorse for creating access methods for instvars." |
|
1744 |
||
6050 | 1745 |
|nonMetaClass metaClass classesClassVars generateComments generateCommentsForSetters generateCommentsForGetters| |
1746 |
||
1747 |
nonMetaClass := aClass theNonMetaclass. |
|
1748 |
metaClass := aClass theMetaclass. |
|
5763 | 1749 |
|
1750 |
self startCollectChanges. |
|
1751 |
||
1752 |
generateComments := UserPreferences current generateComments. |
|
1753 |
generateCommentsForSetters := UserPreferences current generateCommentsForSetters. |
|
1754 |
generateCommentsForGetters := UserPreferences current generateCommentsForGetters. |
|
1755 |
||
6050 | 1756 |
classesClassVars := nonMetaClass allClassVarNames. |
5763 | 1757 |
|
1758 |
aCollectionOfVarNames do:[:name | |
|
1759 |
|source varType methodName holderMethodName defaultMethodName| |
|
1760 |
||
1761 |
holderMethodName := name. |
|
6643 | 1762 |
name isUppercaseFirst ifTrue:[ |
5763 | 1763 |
holderMethodName := holderMethodName asLowercaseFirst. |
1764 |
]. |
|
1765 |
(holderMethodName endsWith:'Holder') ifTrue:[ |
|
1766 |
methodName := holderMethodName copyWithoutLast:6. |
|
1767 |
] ifFalse:[ |
|
1768 |
methodName := holderMethodName. |
|
1769 |
holderMethodName := methodName , 'Holder'. |
|
1770 |
]. |
|
1771 |
||
1772 |
methodName notNil ifTrue:[ |
|
6050 | 1773 |
(metaClass includesSelector:(methodName asSymbol)) ifFalse:[ |
5763 | 1774 |
source := '%1\'. |
1775 |
generateComments ifTrue:[ |
|
1776 |
source := source , ' "return the value in ''%2''"\\'. |
|
1777 |
]. |
|
1778 |
source := source , ' ^ self %2 value'. |
|
1779 |
source := (source bindWith:methodName with:holderMethodName) withCRs. |
|
6050 | 1780 |
self compile:source forClass:nonMetaClass inCategory:('accessing'). |
5763 | 1781 |
] ifTrue:[ |
1782 |
Transcript showCR:'method ''', methodName , ''' already present' |
|
1783 |
]. |
|
1784 |
||
6050 | 1785 |
(metaClass includesSelector:((methodName , ':') asSymbol)) ifFalse:[ |
5763 | 1786 |
source := '%1: newValue\'. |
1787 |
generateComments ifTrue:[ |
|
1788 |
source := source , ' "set the value in ''%2''"\\'. |
|
1789 |
]. |
|
1790 |
source := source , ' self %2 value: newValue'. |
|
1791 |
source := (source bindWith:methodName with:holderMethodName) withCRs. |
|
6050 | 1792 |
self compile:source forClass:nonMetaClass inCategory:('accessing'). |
5763 | 1793 |
] ifTrue:[ |
1794 |
Transcript showCR:'method ''', methodName , ':'' already present' |
|
1795 |
]. |
|
1796 |
]. |
|
6050 | 1797 |
(metaClass includesSelector:(holderMethodName asSymbol)) ifFalse:[ |
5763 | 1798 |
source := '%1\'. |
1799 |
generateComments ifTrue:[ |
|
1800 |
source := source , ' "return/create the valueHolder ''%1''"\\'. |
|
1801 |
]. |
|
1802 |
source := source , ' %1 isNil ifTrue:[\'. |
|
1803 |
source := source , ' %1 := ValueHolder with:nil "defaultValue here".\'. |
|
1804 |
source := source , ' ].\'. |
|
1805 |
source := source , ' ^ %1\'. |
|
1806 |
source := (source bindWith:holderMethodName) withCRs. |
|
6050 | 1807 |
self compile:source forClass:nonMetaClass inCategory:('accessing'). |
5763 | 1808 |
] ifTrue:[ |
1809 |
Transcript showCR:'method ''', methodName , ''' already present' |
|
1810 |
]. |
|
1811 |
]. |
|
1812 |
||
1813 |
self executeCollectedChangesNamed:('Add ValueHolder'). |
|
5013
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1814 |
! ! |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
1815 |
|
5758 | 1816 |
!CodeGeneratorTool methodsFor:'code generation-individual methods'! |
3712 | 1817 |
|
1818 |
createAcceptVisitorMethod:selector in:aClass |
|
1819 |
"create an acceptVisitor: method |
|
1820 |
(I'm tired of typing)" |
|
1821 |
||
6921 | 1822 |
self assert:( aClass isMeta not ). |
3712 | 1823 |
|
1824 |
(aClass includesSelector:#'acceptVisitor:') ifFalse:[ |
|
1825 |
self |
|
1826 |
compile: |
|
1827 |
(('acceptVisitor:aVisitor |
|
1828 |
"Double dispatch back to the visitor, passing my type encoded in |
|
1829 |
the selector (visitor pattern)" |
|
1830 |
||
1831 |
"stub code automatically generated - please change if required" |
|
1832 |
||
1833 |
^ aVisitor %1self |
|
1834 |
') bindWith:selector) |
|
1835 |
forClass:aClass |
|
1836 |
inCategory:'visiting'. |
|
1837 |
] |
|
1838 |
! |
|
1839 |
||
1840 |
createAcceptVisitorMethodIn:aClass |
|
1841 |
"create an acceptVisitor: method |
|
1842 |
(I'm tired of typing)" |
|
1843 |
||
1844 |
self |
|
1845 |
createAcceptVisitorMethod:('visit' , aClass nameWithoutPrefix , ':') asSymbol |
|
1846 |
in:aClass |
|
1847 |
! |
|
1848 |
||
1849 |
createCopyrightMethodFor:aClass |
|
1850 |
"add copyright method containing your/your companies |
|
1851 |
copyright template but only if not already present. |
|
1852 |
this is only added, if specified in the |
|
1853 |
COPYRIGHT_TEMPLATE_FILE resources." |
|
1854 |
||
8258 | 1855 |
|fn copyRightText| |
3712 | 1856 |
|
1857 |
(aClass includesSelector:#copyright) ifFalse:[ |
|
1858 |
fn := SystemBrowser classResources at:#'COPYRIGHT_TEMPLATE_FILE' default:nil. |
|
1859 |
fn notNil ifTrue:[ |
|
1860 |
fn := fn asFilename. |
|
1861 |
fn exists ifTrue:[ |
|
8488 | 1862 |
copyRightText := fn contentsAsString. |
8258 | 1863 |
self createCopyrightMethodFor:copyRightText for:aClass |
3712 | 1864 |
] |
1865 |
]. |
|
8258 | 1866 |
]. |
1867 |
! |
|
1868 |
||
1869 |
createCopyrightMethodFor:copyRightText for:aClass |
|
1870 |
"add copyright method containing text, |
|
1871 |
but only if not already present." |
|
1872 |
||
1873 |
|txt| |
|
1874 |
||
1875 |
(aClass includesSelector:#copyright) ifFalse:[ |
|
1876 |
copyRightText notNil ifTrue:[ |
|
1877 |
txt := copyRightText bindWith:(Date today year). |
|
3712 | 1878 |
self compile: |
1879 |
'copyright |
|
1880 |
" |
|
1881 |
' , txt , ' |
|
1882 |
" |
|
1883 |
' forClass:aClass |
|
1884 |
inCategory:'documentation'. |
|
1885 |
] |
|
1886 |
]. |
|
1887 |
! |
|
1888 |
||
1889 |
createDocumentationMethodFor:aClass |
|
1890 |
"add documentation method containing doc template |
|
1891 |
but only if not already present." |
|
1892 |
||
6050 | 1893 |
|metaClass nonMetaClass userName loginName hostName emailAddress code existingComment| |
1894 |
||
1895 |
metaClass := aClass theMetaclass. |
|
1896 |
nonMetaClass := aClass theNonMetaclass. |
|
3712 | 1897 |
|
6050 | 1898 |
(metaClass includesSelector:#documentation) ifFalse:[ |
1899 |
existingComment := nonMetaClass comment. |
|
1900 |
existingComment isEmptyOrNil ifTrue:[ |
|
1901 |
(nonMetaClass isSubclassOf:HTTPService) ifTrue:[ |
|
6159 | 1902 |
existingComment := ' [start Server with:] |
7545
df2fc5dbee78
changed #createDocumentationMethodFor:
Claus Gittinger <cg@exept.de>
parents:
7480
diff
changeset
|
1903 |
HTTPServer startServerOnPort:8080 |
6159 | 1904 |
|
1905 |
[start with:] |
|
6050 | 1906 |
(self new) |
7545
df2fc5dbee78
changed #createDocumentationMethodFor:
Claus Gittinger <cg@exept.de>
parents:
7480
diff
changeset
|
1907 |
registerServiceOn:(HTTPServer runningServerOnPort:8080)'. |
6050 | 1908 |
]. |
1909 |
]. |
|
1910 |
||
3712 | 1911 |
userName := OperatingSystem getFullUserName. |
1912 |
loginName := OperatingSystem getLoginName. |
|
1913 |
hostName := OperatingSystem getHostName. |
|
1914 |
emailAddress := loginName , '@' , hostName. |
|
1915 |
||
5756 | 1916 |
"/ ugly; should ask the class for that |
6350 | 1917 |
metaClass isJavaScriptMetaclass ifTrue:[ |
5756 | 1918 |
code := |
1919 |
'function documentation() { |
|
1920 |
/* |
|
6050 | 1921 |
' , (existingComment ? ' documentation to be added.') , ' |
5756 | 1922 |
|
1923 |
[author:] |
|
1924 |
' , userName |
|
1925 |
, ' (' , emailAddress , ')' , ' |
|
1926 |
||
1927 |
[instance variables:] |
|
1928 |
||
1929 |
[class variables:] |
|
1930 |
||
1931 |
[see also:] |
|
1932 |
||
1933 |
*/ |
|
1934 |
} |
|
1935 |
' |
|
1936 |
] ifFalse:[ |
|
1937 |
code:= |
|
3712 | 1938 |
'documentation |
1939 |
" |
|
6050 | 1940 |
' , (existingComment ? ' documentation to be added.') , ' |
3712 | 1941 |
|
1942 |
[author:] |
|
1943 |
' , userName |
|
1944 |
, ' (' , emailAddress , ')' , ' |
|
1945 |
||
1946 |
[instance variables:] |
|
1947 |
||
1948 |
[class variables:] |
|
1949 |
||
1950 |
[see also:] |
|
1951 |
||
1952 |
" |
|
5756 | 1953 |
' |
1954 |
]. |
|
1955 |
||
1956 |
self |
|
1957 |
compile:code |
|
6050 | 1958 |
forClass:metaClass |
5756 | 1959 |
inCategory:'documentation'. |
3712 | 1960 |
]. |
7545
df2fc5dbee78
changed #createDocumentationMethodFor:
Claus Gittinger <cg@exept.de>
parents:
7480
diff
changeset
|
1961 |
|
df2fc5dbee78
changed #createDocumentationMethodFor:
Claus Gittinger <cg@exept.de>
parents:
7480
diff
changeset
|
1962 |
"Modified: / 24-11-2006 / 15:54:27 / cg" |
3712 | 1963 |
! |
1964 |
||
1965 |
createExamplesMethodFor:aClass |
|
1966 |
"add examples method containing examples template |
|
1967 |
but only if not already present." |
|
1968 |
||
6050 | 1969 |
|nonMetaclass fragment| |
1970 |
||
1971 |
nonMetaclass := aClass theNonMetaclass. |
|
1972 |
(nonMetaclass isSubclassOf:ApplicationModel) ifFalse:[ |
|
1973 |
^ self |
|
1974 |
]. |
|
3712 | 1975 |
|
1976 |
(aClass includesSelector:#examples) ifFalse:[ |
|
6050 | 1977 |
(nonMetaclass isSubclassOf:ApplicationModel) ifTrue:[ |
3712 | 1978 |
fragment := ' Starting the application: |
1979 |
[exBegin] |
|
6050 | 1980 |
' , nonMetaclass name , ' open |
3712 | 1981 |
|
1982 |
[exEnd] |
|
1983 |
' |
|
1984 |
] ifFalse:[ |
|
1985 |
fragment := '' |
|
1986 |
]. |
|
1987 |
||
1988 |
self |
|
1989 |
compile: |
|
1990 |
'examples |
|
1991 |
" |
|
1992 |
' , fragment , ' |
|
1993 |
more examples to be added: |
|
1994 |
[exBegin] |
|
1995 |
... add code fragment for |
|
1996 |
... executable example here ... |
|
1997 |
[exEnd] |
|
1998 |
" |
|
1999 |
' |
|
2000 |
forClass:aClass |
|
2001 |
inCategory:'documentation'. |
|
2002 |
]. |
|
2003 |
! |
|
2004 |
||
3822
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
2005 |
createImageSpecMethodFor:anImage comment:comment in:aClass selector:sel |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
2006 |
|imageStoreStream mthd imageKey category| |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
2007 |
|
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
2008 |
anImage storeOn: (imageStoreStream := WriteStream on: ''). |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
2009 |
|
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
2010 |
"/ if that method already exists, do not overwrite the category |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
2011 |
category := 'image specs'. |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
2012 |
(mthd := aClass compiledMethodAt:sel) notNil ifTrue:[ |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
2013 |
category := mthd category. |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
2014 |
]. |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
2015 |
|
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
2016 |
imageKey := (aClass name, ' ', sel) asSymbol. |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
2017 |
Icon constantNamed: imageKey put:nil. |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
2018 |
aClass |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
2019 |
compile: ((sel, |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
2020 |
'\', comment, |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
2021 |
'\\' , |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
2022 |
' "\', |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
2023 |
' self ' , sel , ' inspect\', |
3823 | 2024 |
' ImageEditor openOnClass:self andSelector:#', sel, '\', |
3822
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
2025 |
' Icon flushCachedIcons', |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
2026 |
'\ "', |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
2027 |
'\\', |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
2028 |
' <resource: #image>', |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
2029 |
'\\', |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
2030 |
' ^Icon\') withCRs, |
7967
2560906ca552
use string-key in constantNamed:-icon caching
Claus Gittinger <cg@exept.de>
parents:
7615
diff
changeset
|
2031 |
' constantNamed:''', imageKey, '''\' withCRs, |
3822
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
2032 |
' ifAbsentPut:[', imageStoreStream contents, ']') |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
2033 |
classified: category. |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
2034 |
! |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
2035 |
|
3712 | 2036 |
createInitialHistoryMethodFor:aClass |
2037 |
"add history method containing created-entry |
|
2038 |
but only if not already present." |
|
2039 |
||
5758 | 2040 |
|code| |
2041 |
||
3712 | 2042 |
(aClass includesSelector:#history) ifFalse:[ |
2043 |
HistoryManager notNil ifTrue:[ |
|
5758 | 2044 |
code := HistoryManager codeForInitialHistoryMethodIn:aClass. |
2045 |
self |
|
2046 |
compile:code |
|
2047 |
forClass:aClass |
|
2048 |
inCategory:'documentation'. |
|
3712 | 2049 |
]. |
2050 |
]. |
|
2051 |
! |
|
2052 |
||
4512 | 2053 |
createInstanceCreationMethodWithSetupFor:selector category:category in:aMetaClass |
2054 |
"add an inst-creation method" |
|
2055 |
||
2056 |
|template| |
|
2057 |
||
2058 |
(aMetaClass includesSelector:selector) ifFalse:[ |
|
2059 |
template := Parser methodSpecificationForSelector:selector. |
|
2060 |
self |
|
2061 |
compile: |
|
2062 |
template , ' |
|
2063 |
^ self new ' , template , ' |
|
2064 |
' |
|
2065 |
forClass:aMetaClass |
|
2066 |
inCategory:category. |
|
2067 |
]. |
|
2068 |
! |
|
2069 |
||
3712 | 2070 |
createMultiSetterMethodFor:aCollectionOfVarNames in:aClass |
2071 |
"create a multi-setter method for instvars." |
|
2072 |
||
2073 |
|source| |
|
2074 |
||
2075 |
source := ''. |
|
2076 |
aCollectionOfVarNames do:[:eachVar | |
|
2077 |
source := source , (eachVar , ':' , eachVar , 'Arg '). |
|
2078 |
]. |
|
2079 |
source := source , Character cr. |
|
6992 | 2080 |
(UserPreferences current generateCommentsForSetters) ifTrue:[ |
6993 | 2081 |
source := source , (' "set instance variables"' , Character cr , Character cr). |
6992 | 2082 |
]. |
3712 | 2083 |
aCollectionOfVarNames do:[:eachVar | |
2084 |
source := source , (' ' , eachVar , ' := ' , eachVar , 'Arg.' , Character cr). |
|
2085 |
]. |
|
2086 |
self compile:source forClass:aClass inCategory:'accessing'. |
|
2087 |
! |
|
2088 |
||
3800
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
2089 |
createSubclassResponsibilityMethodFor:aSelector category:cat in:aClass |
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
2090 |
"add a subclassResponsibility method; |
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
2091 |
but only if not already present." |
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
2092 |
|
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
2093 |
(aClass includesSelector:aSelector) ifFalse:[ |
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
2094 |
|
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
2095 |
self compile: |
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
2096 |
(Method methodDefinitionTemplateForSelector:aSelector) , |
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
2097 |
' |
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
2098 |
"raise an error: must be redefined in concrete subclass(es)" |
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
2099 |
|
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
2100 |
^ self subclassResponsibility |
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
2101 |
' |
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
2102 |
forClass:aClass |
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
2103 |
inCategory:cat. |
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
2104 |
]. |
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
2105 |
! |
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
2106 |
|
3712 | 2107 |
createUpdateMethodIn:aClass |
2108 |
"create an update:with:from:-method |
|
2109 |
(I'm tired of typing)" |
|
2110 |
||
2111 |
(aClass includesSelector:#'update:with:from:') ifFalse:[ |
|
2112 |
self |
|
2113 |
compile: |
|
2114 |
'update:something with:aParameter from:changedObject |
|
2115 |
"Invoked when an object that I depend upon sends a change notification." |
|
2116 |
||
2117 |
"stub code automatically generated - please change as required" |
|
2118 |
||
2119 |
"/ changedObject == someOfMyValueHolders ifTrue:[ |
|
4926 | 2120 |
"/ self doSomethingApropriate. |
2121 |
"/ ^ self. |
|
3712 | 2122 |
"/ ]. |
2123 |
super update:something with:aParameter from:changedObject |
|
2124 |
' |
|
2125 |
forClass:aClass |
|
2126 |
inCategory:'change & update'. |
|
2127 |
] |
|
2128 |
! |
|
2129 |
||
2130 |
createVersionMethodFor:aClass |
|
2131 |
"add version method containing RCS template |
|
2132 |
but only if not already present and its not a private class." |
|
2133 |
||
5756 | 2134 |
|code| |
2135 |
||
3712 | 2136 |
aClass isPrivate ifFalse:[ |
2137 |
(aClass includesSelector:#version) ifFalse:[ |
|
5756 | 2138 |
"/ ugly; should ask the class for that |
2139 |
aClass isJavaScriptClass ifTrue:[ |
|
2140 |
code:= ('function version() {\ return ("$' , 'Header$");\}') withCRs |
|
2141 |
] ifFalse:[ |
|
2142 |
code:= ('version\ ^ ''$' , 'Header$''') withCRs |
|
2143 |
]. |
|
2144 |
self |
|
2145 |
compile:code |
|
2146 |
forClass:aClass |
|
2147 |
inCategory:'documentation'. |
|
3712 | 2148 |
] |
2149 |
]. |
|
2150 |
! ! |
|
2151 |
||
7480
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2152 |
!CodeGeneratorTool methodsFor:'code templates'! |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2153 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2154 |
codeFor_closeAccept |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2155 |
^ |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2156 |
'closeAccept |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2157 |
"This is a hook method generated by the Browser. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2158 |
It will be invoked when your dialog-window is closed with OK." |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2159 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2160 |
"/ add any actions as required here ... |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2161 |
Transcript showCR:''dialog accepted''. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2162 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2163 |
"/ do not remove the one below (otherwise, the dialog will not close itself)... |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2164 |
^ super closeAccept |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2165 |
'. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2166 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2167 |
"Created: / 27-10-2006 / 10:03:31 / cg" |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2168 |
! |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2169 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2170 |
codeFor_closeDownViews |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2171 |
^ |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2172 |
'closeDownViews |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2173 |
"This is a hook method generated by the Browser. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2174 |
It will be invoked when your app/dialog-window is really closed. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2175 |
See also #closeDownViews, which is invoked before and may suppress the close |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2176 |
or ask the user for confirmation." |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2177 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2178 |
"/ change the code below as required ... |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2179 |
"/ This should cleanup any leftover resources |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2180 |
"/ (for example, temporary files) |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2181 |
"/ super closeRequest will initiate the closeDown |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2182 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2183 |
"/ add your code here |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2184 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2185 |
"/ do not remove the one below ... |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2186 |
^ super closeDownViews |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2187 |
'. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2188 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2189 |
"Created: / 27-10-2006 / 10:01:32 / cg" |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2190 |
! |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2191 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2192 |
codeFor_closeRequest |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2193 |
^ |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2194 |
'closeRequest |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2195 |
"This is a hook method generated by the Browser. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2196 |
It will be invoked when your app/dialog-window is about to be |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2197 |
closed (this method has a chance to suppress the close). |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2198 |
See also #closeDownViews, which is invoked when the close is really done." |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2199 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2200 |
"/ change the code below as required ... |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2201 |
"/ Closing can be suppressed, by simply returning. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2202 |
"/ The ''super closeRequest'' at the end will initiate the real closeDown |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2203 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2204 |
self hasUnsavedChanges ifTrue:[ |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2205 |
(self confirm:(resources string:''Close without saving ?'')) ifFalse:[ |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2206 |
^ self |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2207 |
] |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2208 |
]. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2209 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2210 |
^ super closeRequest |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2211 |
'. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2212 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2213 |
"Created: / 27-10-2006 / 10:01:06 / cg" |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2214 |
! |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2215 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2216 |
codeFor_doSaveAs |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2217 |
^ self codeFor_emptyMenuActionCodeFor:#doSaveAs menuItem:'save/saveAs' |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2218 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2219 |
"Created: / 27-10-2006 / 10:22:06 / cg" |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2220 |
! |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2221 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2222 |
codeFor_emptyMenuActionCodeFor:selector menuItem:item |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2223 |
^ |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2224 |
selector,' |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2225 |
"This method was generated by the Browser. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2226 |
It will be invoked when the menu-item ''',item,''' is selected." |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2227 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2228 |
"/ change below and add any actions as required here ... |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2229 |
self warn:''no action for ''''',item,''''' defined.''. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2230 |
'. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2231 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2232 |
"Created: / 27-10-2006 / 10:16:43 / cg" |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2233 |
! |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2234 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2235 |
codeFor_hasUnsavedChanges |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2236 |
^ |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2237 |
'hasUnsavedChanges |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2238 |
"Return true, if any unsaved changes are present |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2239 |
(i.e. the contents needs to be saved or else will be lost)" |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2240 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2241 |
"/ add real code as required (or remove the halt and always return false)... |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2242 |
self halt:''check this code''. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2243 |
^ false. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2244 |
'. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2245 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2246 |
"Created: / 27-10-2006 / 10:00:36 / cg" |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2247 |
! |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2248 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2249 |
codeFor_menuNew |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2250 |
^ self codeFor_emptyMenuActionCodeFor:#menuNew menuItem:'new' |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2251 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2252 |
"Created: / 27-10-2006 / 10:17:08 / cg" |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2253 |
! |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2254 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2255 |
codeFor_menuOpen |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2256 |
^ self codeFor_emptyMenuActionCodeFor:#menuOpen menuItem:'open' |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2257 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2258 |
"Created: / 27-10-2006 / 10:17:18 / cg" |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2259 |
! |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2260 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2261 |
codeFor_menuSave |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2262 |
^ self codeFor_emptyMenuActionCodeFor:#menuSave menuItem:'save' |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2263 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2264 |
"Created: / 27-10-2006 / 10:17:25 / cg" |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2265 |
! |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2266 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2267 |
codeFor_menuSaveAs |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2268 |
^ |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2269 |
'menuSaveAs |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2270 |
"This method was generated by the Browser. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2271 |
It will be invoked when the menu-item ''saveAs'' is selected." |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2272 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2273 |
"/ change below as required... (see examples in Dialog class for more options) |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2274 |
Dialog |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2275 |
requestSaveFileName:(resources string:''Save'') |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2276 |
default:''foo.txt'' |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2277 |
fromDirectory:nil |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2278 |
action:[:fileName | self doSaveAs:fileName] |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2279 |
appendAction:nil. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2280 |
'. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2281 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2282 |
"Created: / 27-10-2006 / 10:01:57 / cg" |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2283 |
! |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2284 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2285 |
codeFor_openAboutThisApplication |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2286 |
^ |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2287 |
'openAboutThisApplication |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2288 |
"This method was generated by the Browser. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2289 |
It will be invoked when the menu-item ''help-about'' is selected." |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2290 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2291 |
"/ could open a customized aboutBox here ... |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2292 |
super openAboutThisApplication |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2293 |
'. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2294 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2295 |
"Created: / 27-10-2006 / 10:03:13 / cg" |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2296 |
! |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2297 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2298 |
codeFor_openDocumentation |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2299 |
^ |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2300 |
'openDocumentation |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2301 |
"This method was generated by the Browser. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2302 |
It will be invoked when the menu-item ''help-documentation'' is selected." |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2303 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2304 |
"/ change below as required ... |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2305 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2306 |
"/ to open an HTML viewer on some document (under ''doc/online/<language>/'' ): |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2307 |
HTMLDocumentView openFullOnDocumentationFile:''TOP.html''. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2308 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2309 |
"/ add application-specific help files under the ''doc/online/<language>/help/appName'' |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2310 |
"/ directory, and open a viewer with: |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2311 |
"/ HTMLDocumentView openFullOnDocumentationFile:''help/<MyApplication>/TOP.html''. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2312 |
'. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2313 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2314 |
"Created: / 27-10-2006 / 10:02:55 / cg" |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2315 |
! |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2316 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2317 |
codeFor_postBuildWith |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2318 |
^ |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2319 |
'postBuildWith:aBuilder |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2320 |
"This is a hook method generated by the Browser. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2321 |
It will be invoked during the initialization of your app/dialog, |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2322 |
after all of the visual components have been built, |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2323 |
but BEFORE the top window is made visible. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2324 |
Add any app-specific actions here (reading files, setting up values etc.) |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2325 |
See also #postOpenWith:, which is invoked after opening." |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2326 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2327 |
"/ add any code here ... |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2328 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2329 |
^ super postBuildWith:aBuilder |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2330 |
'. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2331 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2332 |
"Created: / 27-10-2006 / 09:59:33 / cg" |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2333 |
! |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2334 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2335 |
codeFor_postOpenWith |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2336 |
^ |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2337 |
'postOpenWith:aBuilder |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2338 |
"This is a hook method generated by the Browser. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2339 |
It will be invoked right after the applications window has been opened. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2340 |
Add any app-specific actions here (starting background processes etc.). |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2341 |
See also #postBuildWith:, which is invoked before opening." |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2342 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2343 |
"/ add any code here ... |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2344 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2345 |
^ super postOpenWith:aBuilder |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2346 |
'. |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2347 |
|
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2348 |
"Created: / 27-10-2006 / 09:59:56 / cg" |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2349 |
! ! |
33930379ab27
code cleanup; more application code generation
Claus Gittinger <cg@exept.de>
parents:
7470
diff
changeset
|
2350 |
|
6938 | 2351 |
!CodeGeneratorTool methodsFor:'compilation'! |
2352 |
||
2353 |
compile:theCode forClass:aClass inCategory:cat |
|
2354 |
"install some code for a class. |
|
2355 |
If refactory browser stuff is avaliable the refactory tools are used to support undo" |
|
2356 |
||
7037 | 2357 |
self |
2358 |
compile:theCode forClass:aClass inCategory:cat |
|
2359 |
skipIfSame:true |
|
2360 |
! |
|
6938 | 2361 |
|
7037 | 2362 |
compile:theCode forClass:aClass inCategory:cat skipIfSame:skipIfSame |
2363 |
"install some code for a class. |
|
2364 |
If refactory browser stuff is avaliable the refactory tools are used to support undo" |
|
2365 |
||
2366 |
|change compiler selector oldMthd isSame| |
|
6938 | 2367 |
|
7037 | 2368 |
isSame := false. |
2369 |
skipIfSame ifTrue:[ |
|
2370 |
compiler := aClass compilerClass new. |
|
2371 |
compiler parseMethod:theCode in:aClass ignoreErrors:true ignoreWarnings:true. |
|
2372 |
||
2373 |
selector := compiler selector. |
|
2374 |
selector notNil ifTrue:[ |
|
2375 |
oldMthd := aClass compiledMethodAt:selector. |
|
2376 |
isSame := (oldMthd notNil and:[oldMthd source = theCode]). |
|
2377 |
isSame ifTrue:[ ^ self ]. |
|
6938 | 2378 |
]. |
2379 |
]. |
|
2380 |
||
2381 |
self canUseRefactoringSupport ifFalse:[ |
|
2382 |
"/ compile immediately |
|
2383 |
aClass compile:theCode classified:cat. |
|
2384 |
^ self. |
|
2385 |
]. |
|
2386 |
||
2387 |
change := InteractiveAddMethodChange compile:(theCode asString) in:aClass classified:cat. |
|
2388 |
||
2389 |
"/ if collecting, add to changes (to be executed as one change at the end, |
|
2390 |
"/ in order to have only one change in the undo-list (instead of many) |
|
2391 |
compositeChangeCollector notNil ifTrue:[ |
|
2392 |
compositeChangeCollector addChange:change |
|
2393 |
] ifFalse:[ |
|
7037 | 2394 |
RefactoryChangeManager performChange:change. |
6938 | 2395 |
] |
2396 |
||
2397 |
"Modified: / 21-08-2006 / 18:39:06 / cg" |
|
2398 |
! ! |
|
3712 | 2399 |
|
5758 | 2400 |
!CodeGeneratorTool methodsFor:'private'! |
4108
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
2401 |
|
5013
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
2402 |
canUseRefactoringSupport |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
2403 |
"check if refactory browser stuff is avaliable" |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
2404 |
|
5758 | 2405 |
^ self class canUseRefactoringSupport |
5013
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
2406 |
! |
0f2c39fc6e8c
comments; allow for comments to be suppressed
Claus Gittinger <cg@exept.de>
parents:
4926
diff
changeset
|
2407 |
|
4108
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
2408 |
privCreateClassResponsibleProtocolFor:aClass |
6791
6559c9ebb561
Keep method argument names when generating required methods
Stefan Vogel <sv@exept.de>
parents:
6718
diff
changeset
|
2409 |
"create stubs for the required protocol. |
6559c9ebb561
Keep method argument names when generating required methods
Stefan Vogel <sv@exept.de>
parents:
6718
diff
changeset
|
2410 |
aClass may be a a MetaClass or a non-MetaClass" |
4108
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
2411 |
|
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
2412 |
|selectors| |
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
2413 |
|
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
2414 |
selectors := IdentitySet new. |
6791
6559c9ebb561
Keep method argument names when generating required methods
Stefan Vogel <sv@exept.de>
parents:
6718
diff
changeset
|
2415 |
aClass allSuperclassesDo:[:eachSuperClass | |
6559c9ebb561
Keep method argument names when generating required methods
Stefan Vogel <sv@exept.de>
parents:
6718
diff
changeset
|
2416 |
eachSuperClass methodDictionary keysAndValuesDo:[:eachSelector :eachMethod | |
6559c9ebb561
Keep method argument names when generating required methods
Stefan Vogel <sv@exept.de>
parents:
6718
diff
changeset
|
2417 |
(eachMethod sends:#subclassResponsibility) ifTrue:[ |
6559c9ebb561
Keep method argument names when generating required methods
Stefan Vogel <sv@exept.de>
parents:
6718
diff
changeset
|
2418 |
selectors add:eachSelector. |
4108
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
2419 |
] |
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
2420 |
] |
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
2421 |
]. |
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
2422 |
|
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
2423 |
selectors do:[:eachSelector | |
6791
6559c9ebb561
Keep method argument names when generating required methods
Stefan Vogel <sv@exept.de>
parents:
6718
diff
changeset
|
2424 |
|mthd comment implClass methodBodyStream| |
4108
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
2425 |
|
6791
6559c9ebb561
Keep method argument names when generating required methods
Stefan Vogel <sv@exept.de>
parents:
6718
diff
changeset
|
2426 |
implClass := aClass whichClassIncludesSelector:eachSelector. |
4108
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
2427 |
implClass ~~ aClass ifTrue:[ |
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
2428 |
mthd := implClass compiledMethodAt:eachSelector. |
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
2429 |
(mthd sends:#subclassResponsibility) ifTrue:[ |
6791
6559c9ebb561
Keep method argument names when generating required methods
Stefan Vogel <sv@exept.de>
parents:
6718
diff
changeset
|
2430 |
methodBodyStream := '' writeStream. |
6559c9ebb561
Keep method argument names when generating required methods
Stefan Vogel <sv@exept.de>
parents:
6718
diff
changeset
|
2431 |
methodBodyStream |
6559c9ebb561
Keep method argument names when generating required methods
Stefan Vogel <sv@exept.de>
parents:
6718
diff
changeset
|
2432 |
nextPutAll:mthd methodDefinitionTemplate; cr; |
6559c9ebb561
Keep method argument names when generating required methods
Stefan Vogel <sv@exept.de>
parents:
6718
diff
changeset
|
2433 |
nextPutAll:' "'. |
6559c9ebb561
Keep method argument names when generating required methods
Stefan Vogel <sv@exept.de>
parents:
6718
diff
changeset
|
2434 |
|
4108
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
2435 |
comment := mthd methodComment. |
6791
6559c9ebb561
Keep method argument names when generating required methods
Stefan Vogel <sv@exept.de>
parents:
6718
diff
changeset
|
2436 |
comment isEmptyOrNil ifTrue:[ |
6559c9ebb561
Keep method argument names when generating required methods
Stefan Vogel <sv@exept.de>
parents:
6718
diff
changeset
|
2437 |
methodBodyStream |
6559c9ebb561
Keep method argument names when generating required methods
Stefan Vogel <sv@exept.de>
parents:
6718
diff
changeset
|
2438 |
nextPutAll:('Superclass <1s> says that I am responsible to implement this method' |
6559c9ebb561
Keep method argument names when generating required methods
Stefan Vogel <sv@exept.de>
parents:
6718
diff
changeset
|
2439 |
expandMacrosWith:implClass name) |
6559c9ebb561
Keep method argument names when generating required methods
Stefan Vogel <sv@exept.de>
parents:
6718
diff
changeset
|
2440 |
] ifFalse:[ |
6559c9ebb561
Keep method argument names when generating required methods
Stefan Vogel <sv@exept.de>
parents:
6718
diff
changeset
|
2441 |
comment asStringCollection do:[:eachLine| |
6559c9ebb561
Keep method argument names when generating required methods
Stefan Vogel <sv@exept.de>
parents:
6718
diff
changeset
|
2442 |
methodBodyStream nextPutAll:eachLine. |
6559c9ebb561
Keep method argument names when generating required methods
Stefan Vogel <sv@exept.de>
parents:
6718
diff
changeset
|
2443 |
] separatedBy:[ |
6559c9ebb561
Keep method argument names when generating required methods
Stefan Vogel <sv@exept.de>
parents:
6718
diff
changeset
|
2444 |
methodBodyStream cr; nextPutAll:' '. |
6559c9ebb561
Keep method argument names when generating required methods
Stefan Vogel <sv@exept.de>
parents:
6718
diff
changeset
|
2445 |
]. |
4108
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
2446 |
]. |
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
2447 |
|
6791
6559c9ebb561
Keep method argument names when generating required methods
Stefan Vogel <sv@exept.de>
parents:
6718
diff
changeset
|
2448 |
methodBodyStream |
6559c9ebb561
Keep method argument names when generating required methods
Stefan Vogel <sv@exept.de>
parents:
6718
diff
changeset
|
2449 |
nextPut:$"; cr; cr; |
6559c9ebb561
Keep method argument names when generating required methods
Stefan Vogel <sv@exept.de>
parents:
6718
diff
changeset
|
2450 |
nextPutAll:' self shouldImplement'; cr. |
6559c9ebb561
Keep method argument names when generating required methods
Stefan Vogel <sv@exept.de>
parents:
6718
diff
changeset
|
2451 |
|
4108
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
2452 |
self |
6791
6559c9ebb561
Keep method argument names when generating required methods
Stefan Vogel <sv@exept.de>
parents:
6718
diff
changeset
|
2453 |
compile:methodBodyStream contents |
4108
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
2454 |
forClass:aClass |
6791
6559c9ebb561
Keep method argument names when generating required methods
Stefan Vogel <sv@exept.de>
parents:
6718
diff
changeset
|
2455 |
inCategory:mthd category. |
4108
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
2456 |
]. |
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
2457 |
]. |
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
2458 |
]. |
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
2459 |
! ! |
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
2460 |
|
3712 | 2461 |
!CodeGeneratorTool class methodsFor:'documentation'! |
2462 |
||
2463 |
version |
|
8488 | 2464 |
^ '$Header: /cvs/stx/stx/libtool/CodeGeneratorTool.st,v 1.58 2008-12-09 14:03:59 cg Exp $' |
3712 | 2465 |
! ! |