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