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