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