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