author | Claus Gittinger <cg@exept.de> |
Thu, 15 Aug 2002 13:09:05 +0200 | |
changeset 3800 | a5c75c369855 |
parent 3719 | d7f6eb94a693 |
child 3804 | d2bc07d678f3 |
permissions | -rw-r--r-- |
3712 | 1 |
"{ Package: 'stx:libtool' }" |
2 |
||
3 |
Object subclass:#CodeGeneratorTool |
|
4 |
instanceVariableNames:'' |
|
5 |
classVariableNames:'' |
|
6 |
poolDictionaries:'' |
|
7 |
category:'Interface-Browsers' |
|
8 |
! |
|
9 |
||
3719 | 10 |
!CodeGeneratorTool class methodsFor:'documentation'! |
11 |
||
12 |
documentation |
|
13 |
" |
|
14 |
extracted code generation stuff from old and newBrowser. |
|
15 |
There is probably more to gome... |
|
16 |
||
17 |
[author:] |
|
18 |
Claus Gittiner |
|
19 |
" |
|
20 |
! ! |
|
3712 | 21 |
|
22 |
!CodeGeneratorTool class methodsFor:'code generation'! |
|
23 |
||
24 |
createAccessMethodsFor:aCollectionOfVarNames in:aClass withChange:withChange asValueHolder:asValueHolder readersOnly:readersOnly writersOnly:writersOnly |
|
25 |
"workhorse for creating access methods for instvars." |
|
26 |
||
27 |
|classesClassVars| |
|
28 |
||
29 |
classesClassVars := aClass theNonMetaclass allClassVarNames. |
|
30 |
||
31 |
aCollectionOfVarNames do:[:name | |
|
32 |
|source varType methodName| |
|
33 |
||
34 |
varType := (classesClassVars includes:name) |
|
35 |
ifTrue:['static'] |
|
36 |
ifFalse:[ |
|
37 |
(aClass isMeta ifTrue:['classInstVar'] ifFalse:['instance'])]. |
|
38 |
||
39 |
methodName := name. |
|
40 |
name first isUppercase ifTrue:[ |
|
41 |
methodName := methodName asLowercaseFirst. |
|
42 |
]. |
|
43 |
||
44 |
writersOnly ifFalse:[ |
|
45 |
"check, if method is not already present" |
|
46 |
(aClass includesSelector:(methodName asSymbol)) ifFalse:[ |
|
47 |
asValueHolder ifTrue:[ |
|
48 |
source := methodName |
|
49 |
, '\ "return/create the ''%2'' value holder (automatically generated)"\\' |
|
50 |
, ' %2 isNil ifTrue:[\' |
|
51 |
, ' %2 := ValueHolder new.\'. |
|
52 |
withChange ifTrue:[ |
|
53 |
source := source |
|
54 |
, ' %2 addDependent:self.\'. |
|
55 |
]. |
|
56 |
source := source |
|
57 |
, ' ].\' |
|
58 |
, ' ^ %2'. |
|
59 |
] ifFalse:[ |
|
60 |
source := methodName |
|
61 |
, '\ "return the value of the %1 variable ''%2'' (automatically generated)"\\' |
|
62 |
, ' ^ %2'. |
|
63 |
]. |
|
64 |
source := (source bindWith:varType with:name) withCRs. |
|
65 |
self compile:source forClass:aClass inCategory:(asValueHolder ifTrue:['aspects'] ifFalse:['accessing']). |
|
66 |
] ifTrue:[ |
|
67 |
Transcript showCR:'method ''', methodName , ''' already present' |
|
68 |
]. |
|
69 |
]. |
|
70 |
||
71 |
readersOnly ifFalse:[ |
|
72 |
(aClass includesSelector:((methodName , ':') asSymbol)) ifFalse:[ |
|
73 |
asValueHolder ifTrue:[ |
|
74 |
source := methodName |
|
75 |
, ':something\ "set the ''%2'' value holder'. |
|
76 |
withChange ifTrue:[ |
|
77 |
source := source |
|
78 |
, ' (automatically generated)"\\' |
|
79 |
, ' |oldValue newValue|\\' |
|
80 |
, ' %2 notNil ifTrue:[\' |
|
81 |
, ' oldValue := %2 value.\' |
|
82 |
, ' %2 removeDependent:self.\' |
|
83 |
, ' ].\' |
|
84 |
, ' %2 := something.\' |
|
85 |
, ' %2 notNil ifTrue:[\' |
|
86 |
, ' %2 addDependent:self.\' |
|
87 |
, ' ].\' |
|
88 |
, ' newValue := %2 value.\' |
|
89 |
, ' oldValue ~~ newValue ifTrue:[\' |
|
90 |
, ' self update:#value with:newValue from:%2.\' |
|
91 |
, ' ].\' |
|
92 |
] ifFalse:[ |
|
93 |
source := source |
|
94 |
, ' (automatically generated)"\\' |
|
95 |
, ' %2 := something.'. |
|
96 |
]. |
|
97 |
] ifFalse:[ |
|
98 |
source := methodName |
|
99 |
, ':something\ "set the value of the %1 variable ''%2'''. |
|
100 |
withChange ifTrue:[ |
|
101 |
source := source |
|
102 |
, ' and send a change notification (automatically generated)"\\' |
|
103 |
, ' (%2 ~~ something) ifTrue:[\' |
|
104 |
, ' %2 := something.\' |
|
105 |
, ' self changed:#%2.\' |
|
106 |
, ' ].\'. |
|
107 |
] ifFalse:[ |
|
108 |
source := source |
|
109 |
, ' (automatically generated)"\\' |
|
110 |
, ' %2 := something.'. |
|
111 |
]. |
|
112 |
]. |
|
113 |
source := (source bindWith:varType with:name) withCRs. |
|
114 |
self |
|
115 |
compile:source |
|
116 |
forClass:aClass |
|
117 |
inCategory:(asValueHolder ifTrue:['aspects'] ifFalse:['accessing']). |
|
118 |
] ifTrue:[ |
|
119 |
Transcript showCR:'method ''', methodName , ':'' already present' |
|
120 |
]. |
|
121 |
]. |
|
122 |
] |
|
123 |
! |
|
124 |
||
125 |
createApplicationCodeFor:aClass |
|
126 |
"create an empty application framework" |
|
127 |
||
128 |
|nonMetaClass metaClass className txt isDialog| |
|
129 |
||
130 |
nonMetaClass := aClass theNonMetaclass. |
|
131 |
metaClass := aClass theMetaclass. |
|
132 |
className := nonMetaClass name. |
|
133 |
||
134 |
isDialog := (nonMetaClass isSubclassOf:SimpleDialog). |
|
135 |
||
136 |
"/ add a windowSpec method for an empty applicationWindow, |
|
137 |
"/ with a menuPanel. |
|
138 |
||
139 |
(metaClass includesSelector:#windowSpec) ifFalse:[ |
|
140 |
isDialog ifTrue:[ |
|
141 |
txt := self initialWindowSpecMethodSourceForDialogs. |
|
142 |
] ifFalse:[ |
|
143 |
txt := self initialWindowSpecMethodSourceForApplications. |
|
144 |
]. |
|
145 |
self |
|
146 |
compile:(txt bindWith:className) |
|
147 |
forClass:metaClass |
|
148 |
inCategory:'interface specs'. |
|
149 |
]. |
|
150 |
||
151 |
isDialog ifFalse:[ |
|
152 |
"/ add a topMenu method |
|
153 |
||
154 |
(metaClass includesSelector:#mainMenu) ifFalse:[ |
|
155 |
txt := self initialMenuSpecMethodSourceForApplications. |
|
156 |
self |
|
157 |
compile:(txt bindWith:className) |
|
158 |
forClass:metaClass |
|
159 |
inCategory:'menu specs'. |
|
160 |
]. |
|
161 |
]. |
|
162 |
||
163 |
(metaClass includesSelector:#postBuildWith:) ifFalse:[ |
|
164 |
txt := |
|
165 |
'postBuildWith:aBuilder |
|
166 |
"This is a hook method generated by the Browser. |
|
167 |
It will be invoked during the initialization of your app/dialog, |
|
168 |
after all of the visual components have been built, |
|
169 |
but BEFORE the top window is made visible. |
|
170 |
Add any app-specific actions here (reading files, setting up values etc.) |
|
171 |
See also #postOpenWith:, which is invoked after opening." |
|
172 |
||
173 |
"/ add any code here ... |
|
174 |
||
175 |
^ super postBuildWith:aBuilder |
|
176 |
'. |
|
177 |
self |
|
178 |
compile:txt |
|
179 |
forClass:nonMetaClass |
|
180 |
inCategory:'initialization & release'. |
|
181 |
]. |
|
182 |
||
183 |
(metaClass includesSelector:#postOpenWith:) ifFalse:[ |
|
184 |
txt := |
|
185 |
'postOpenWith:aBuilder |
|
186 |
"This is a hook method generated by the Browser. |
|
187 |
It will be invoked right after the applications window has been opened. |
|
188 |
Add any app-specific actions here (starting background processes etc.). |
|
189 |
See also #postBuildWith:, which is invoked before opening." |
|
190 |
||
191 |
"/ add any code here ... |
|
192 |
||
193 |
^ super postOpenWith:aBuilder |
|
194 |
'. |
|
195 |
self |
|
196 |
compile:txt |
|
197 |
forClass:nonMetaClass |
|
198 |
inCategory:'initialization & release'. |
|
199 |
]. |
|
200 |
||
201 |
isDialog ifFalse:[ |
|
202 |
(metaClass includesSelector:#closeRequest) ifFalse:[ |
|
203 |
txt := |
|
204 |
'closeRequest |
|
205 |
"This is a hook method generated by the Browser. |
|
206 |
It will be invoked when your app/dialog-window is about to be |
|
207 |
closed (this method has a chance to suppress the close). |
|
208 |
See also #closeDownViews, which is invoked when the close is really done." |
|
209 |
||
210 |
"/ change the code below as required ... |
|
211 |
"/ Closing can be suppressed, by simply returning. |
|
212 |
"/ The ''super closeRequest'' at the end will initiate the real closeDown |
|
213 |
||
214 |
("self hasUnsavedChanges" true) ifTrue:[ |
|
215 |
(self confirm:(resources string:''Close without saving ?'')) ifFalse:[ |
|
216 |
^ self |
|
217 |
] |
|
218 |
]. |
|
219 |
||
220 |
^ super closeRequest |
|
221 |
'. |
|
222 |
self |
|
223 |
compile:txt |
|
224 |
forClass:nonMetaClass |
|
225 |
inCategory:'initialization & release'. |
|
226 |
]. |
|
227 |
]. |
|
228 |
||
229 |
isDialog ifFalse:[ |
|
230 |
(metaClass includesSelector:#closeDownViews) ifFalse:[ |
|
231 |
txt := |
|
232 |
'closeDownViews |
|
233 |
"This is a hook method generated by the Browser. |
|
234 |
It will be invoked when your app/dialog-window is really closed. |
|
235 |
See also #closeDownViews, which is invoked before and may suppress the close |
|
236 |
or ask the user for confirmation." |
|
237 |
||
238 |
"/ change the code below as required ... |
|
239 |
"/ This should cleanup any leftover resources |
|
240 |
"/ (for example, temporary files) |
|
241 |
"/ super closeRequest will initiate the closeDown |
|
242 |
||
243 |
"/ add your code here |
|
244 |
||
245 |
"/ do not remove the one below ... |
|
246 |
^ super closeDownViews |
|
247 |
'. |
|
248 |
self |
|
249 |
compile:txt |
|
250 |
forClass:nonMetaClass |
|
251 |
inCategory:'initialization & release'. |
|
252 |
]. |
|
253 |
]. |
|
254 |
||
255 |
isDialog ifTrue:[ |
|
256 |
(metaClass includesSelector:#accept) ifFalse:[ |
|
257 |
txt := |
|
258 |
'closeAccept |
|
259 |
"This is a hook method generated by the Browser. |
|
260 |
It will be invoked when your dialog-window is closed with OK." |
|
261 |
||
262 |
"/ add any actions as required here ... |
|
263 |
Transcript showCR:''dialog accepted''. |
|
264 |
||
265 |
"/ do not remove the one below ... |
|
266 |
^ super closeAccept |
|
267 |
'. |
|
268 |
self |
|
269 |
compile:txt |
|
270 |
forClass:nonMetaClass |
|
271 |
inCategory:'user actions'. |
|
272 |
]. |
|
273 |
]. |
|
274 |
||
275 |
isDialog ifFalse:[ |
|
276 |
(metaClass includesSelector:#menuNew) ifFalse:[ |
|
277 |
txt := |
|
278 |
'menuNew |
|
279 |
"This method was generated by the Browser. |
|
280 |
It will be invoked when the menu-item ''new'' is selected." |
|
281 |
||
282 |
"/ change below and add any actions as required here ... |
|
283 |
self warn:''no action for ''''new'''' available.''. |
|
284 |
'. |
|
285 |
self |
|
286 |
compile:txt |
|
287 |
forClass:nonMetaClass |
|
288 |
inCategory:'menu actions'. |
|
289 |
]. |
|
290 |
]. |
|
291 |
isDialog ifFalse:[ |
|
292 |
(metaClass includesSelector:#menuOpen) ifFalse:[ |
|
293 |
txt := |
|
294 |
'menuOpen |
|
295 |
"This method was generated by the Browser. |
|
296 |
It will be invoked when the menu-item ''open'' is selected." |
|
297 |
||
298 |
"/ change below and add any actions as required here ... |
|
299 |
self warn:''no action for ''''open'''' available.''. |
|
300 |
'. |
|
301 |
self |
|
302 |
compile:txt |
|
303 |
forClass:nonMetaClass |
|
304 |
inCategory:'menu actions'. |
|
305 |
]. |
|
306 |
]. |
|
307 |
isDialog ifFalse:[ |
|
308 |
(metaClass includesSelector:#menuSave) ifFalse:[ |
|
309 |
txt := |
|
310 |
'menuSave |
|
311 |
"This method was generated by the Browser. |
|
312 |
It will be invoked when the menu-item ''save'' is selected." |
|
313 |
||
314 |
"/ change below and add any actions as required here ... |
|
315 |
self warn:''no action for ''''save'''' available.''. |
|
316 |
'. |
|
317 |
self |
|
318 |
compile:txt |
|
319 |
forClass:nonMetaClass |
|
320 |
inCategory:'menu actions'. |
|
321 |
]. |
|
322 |
]. |
|
323 |
isDialog ifFalse:[ |
|
324 |
(metaClass includesSelector:#menuSaveAs) ifFalse:[ |
|
325 |
txt := |
|
326 |
'menuSaveAs |
|
327 |
"This method was generated by the Browser. |
|
328 |
It will be invoked when the menu-item ''saveAs'' is selected." |
|
329 |
||
330 |
"/ change below and add any actions as required here ... |
|
331 |
self warn:''no action for ''''saveAs'''' available.''. |
|
332 |
'. |
|
333 |
self |
|
334 |
compile:txt |
|
335 |
forClass:nonMetaClass |
|
336 |
inCategory:'menu actions'. |
|
337 |
]. |
|
338 |
]. |
|
339 |
||
340 |
isDialog ifFalse:[ |
|
341 |
(metaClass includesSelector:#openDocumentation) ifFalse:[ |
|
342 |
txt := |
|
343 |
'openDocumentation |
|
344 |
"This method was generated by the Browser. |
|
345 |
It will be invoked when the menu-item ''help-documentation'' is selected." |
|
346 |
||
347 |
"/ change below as required ... |
|
348 |
||
349 |
"/ to open an HTML viewer on some document (under ''doc/online/<language>/'' ): |
|
350 |
HTMLDocumentView openFullOnDocumentationFile:''TOP.html''. |
|
351 |
||
352 |
"/ add application-specific help files under the ''doc/online/<language>/help/appName'' |
|
353 |
"/ directory, and open a viewer with: |
|
354 |
"/ HTMLDocumentView openFullOnDocumentationFile:''help/<MyApplication>/TOP.html''. |
|
355 |
'. |
|
356 |
self |
|
357 |
compile:txt |
|
358 |
forClass:nonMetaClass |
|
359 |
inCategory:'menu actions'. |
|
360 |
]. |
|
361 |
]. |
|
362 |
||
363 |
isDialog ifFalse:[ |
|
364 |
(metaClass includesSelector:#openAboutThisApplication) ifFalse:[ |
|
365 |
txt := |
|
366 |
'openAboutThisApplication |
|
367 |
"This method was generated by the Browser. |
|
368 |
It will be invoked when the menu-item ''help-about'' is selected." |
|
369 |
||
370 |
"/ could open a customized aboutBox here ... |
|
371 |
super openAboutThisApplication |
|
372 |
'. |
|
373 |
self |
|
374 |
compile:txt |
|
375 |
forClass:nonMetaClass |
|
376 |
inCategory:'menu actions'. |
|
377 |
]. |
|
378 |
]. |
|
379 |
||
380 |
"Modified: / 1.2.1998 / 16:10:03 / cg" |
|
381 |
! |
|
382 |
||
383 |
createDocumentationMethodsFor:aClass |
|
384 |
"create empty documentation methods" |
|
385 |
||
386 |
|cls| |
|
387 |
||
388 |
cls := aClass theMetaclass. |
|
389 |
||
390 |
self createVersionMethodFor:cls. |
|
391 |
self createCopyrightMethodFor:aClass. |
|
392 |
self createDocumentationMethodFor:aClass. |
|
393 |
self createInitialHistoryMethodFor:aClass. |
|
394 |
! |
|
395 |
||
396 |
createStandardInitializationMethodsIn:aClass |
|
397 |
"create a #new and #initialize methods |
|
398 |
(I'm tired of typing)" |
|
399 |
||
400 |
|code initializer m| |
|
401 |
||
402 |
(aClass includesSelector:#'initialize') ifFalse:[ |
|
403 |
code := |
|
404 |
'initialize |
|
405 |
"Invoked when a new instance is created." |
|
406 |
||
407 |
super initialize. |
|
408 |
||
409 |
"/ please change as required (and remove this comment) |
|
410 |
'. |
|
411 |
||
412 |
m := aClass responseTo:#initialize. |
|
413 |
m notNil ifTrue:[ |
|
414 |
m messagesSent size == 0 ifTrue:[ |
|
415 |
"/ inherits an empty initialize. |
|
416 |
||
417 |
code := |
|
418 |
'initialize |
|
419 |
"Invoked when a new instance is created." |
|
420 |
||
421 |
"/ please change as required (and remove this comment) |
|
422 |
||
423 |
"/ super initialize. -- commented since inherited method does nothing |
|
424 |
'. |
|
425 |
||
426 |
]. |
|
427 |
]. |
|
428 |
||
429 |
aClass instVarNames do:[:eachInstVar | |
|
430 |
initializer := 'nil'. "/ need more intelligence here (try to guess class from messages sent to it) ... |
|
431 |
code := code , (' ' , eachInstVar , ' := ' , initializer , Character cr). |
|
432 |
]. |
|
433 |
||
434 |
self |
|
435 |
compile:code |
|
436 |
forClass:aClass |
|
437 |
inCategory:'initialization'. |
|
438 |
]. |
|
439 |
||
440 |
(aClass class includesSelector:#'new') ifFalse:[ |
|
441 |
m := aClass class responseTo:#new. |
|
442 |
m notNil ifTrue:[ |
|
443 |
(m sends:#initialize) ifTrue:[ |
|
444 |
(self confirm:'The inherited #new method already seems to invoke #initialize. Redefine ?') |
|
445 |
ifFalse:[ |
|
446 |
^ self |
|
447 |
] |
|
448 |
]. |
|
449 |
]. |
|
450 |
code := |
|
451 |
'new |
|
452 |
^ self basicNew initialize. |
|
453 |
'. |
|
454 |
self |
|
455 |
compile:code |
|
456 |
forClass:aClass class |
|
457 |
inCategory:'instance creation'. |
|
458 |
]. |
|
459 |
||
460 |
||
461 |
"Created: / 11.10.2001 / 22:18:55 / cg" |
|
462 |
! |
|
463 |
||
464 |
createTestCaseSampleCodeFor:aClass |
|
465 |
"create an empty testCase" |
|
466 |
||
467 |
|nonMetaClass metaClass| |
|
468 |
||
469 |
nonMetaClass := aClass theNonMetaclass. |
|
470 |
metaClass := aClass theMetaclass. |
|
471 |
"/ className := nonMetaClass name. |
|
472 |
||
473 |
( nonMetaClass includesSelector:#test1 ) ifFalse:[ |
|
474 |
self |
|
475 |
compile: |
|
476 |
'test1 |
|
477 |
"Just a demonstration testCase. |
|
478 |
Double click on the TestCase class or open a TestRunner to see me checking... |
|
479 |
- please add more methods like this..." |
|
480 |
||
481 |
|o| |
|
482 |
||
483 |
o := Array new:2. |
|
484 |
self assert: ( o size == 2 ). |
|
485 |
self should: [ o at:0 ] raise:Error. |
|
486 |
self shouldnt: [ o at:1 ] raise:Error. |
|
487 |
||
488 |
" |
|
489 |
self run:#test1 |
|
490 |
" |
|
491 |
' |
|
492 |
forClass:nonMetaClass |
|
493 |
inCategory:'tests'. |
|
494 |
]. |
|
495 |
||
496 |
( nonMetaClass includesSelector:#setUp ) ifFalse:[ |
|
497 |
self |
|
498 |
compile: |
|
499 |
'setUp |
|
500 |
"common setup - invoked before testing" |
|
501 |
||
502 |
super setUp |
|
503 |
' |
|
504 |
forClass:nonMetaClass |
|
505 |
inCategory:'initialize / release'. |
|
506 |
]. |
|
507 |
||
508 |
( nonMetaClass includesSelector:#tearDown ) ifFalse:[ |
|
509 |
self |
|
510 |
compile: |
|
511 |
'tearDown |
|
512 |
"common cleanup - invoked after testing" |
|
513 |
||
514 |
super tearDown |
|
515 |
' |
|
516 |
forClass:nonMetaClass |
|
517 |
inCategory:'initialize / release'. |
|
518 |
] |
|
519 |
! |
|
520 |
||
521 |
createVisitorMethodsIn:visitedClass andVisitorClass:visitorClass |
|
522 |
"create acceptVisitor: in visitedClass and acceptXXX in visitorClass. |
|
523 |
(I'm tired of typing)" |
|
524 |
||
525 |
|sel| |
|
526 |
||
527 |
visitedClass isMeta ifTrue:[self halt]. |
|
528 |
visitorClass isMeta ifTrue:[self halt]. |
|
529 |
||
530 |
sel := ('visit' , visitedClass nameWithoutPrefix , ':'). |
|
531 |
self createAcceptVisitorMethod:sel in:visitedClass. |
|
532 |
||
533 |
(visitorClass includesSelector:sel) ifFalse:[ |
|
534 |
self |
|
535 |
compile: |
|
536 |
(('%1anObject |
|
537 |
"dispatched back from the visited %2-object (visitor pattern)" |
|
538 |
||
539 |
"fall back to general object-case - please change as required" |
|
540 |
||
541 |
^ self visitObject:anObject |
|
542 |
') bindWith:sel with:visitedClass nameWithoutPrefix asLowercaseFirst) |
|
543 |
forClass:visitorClass |
|
544 |
inCategory:'visiting'. |
|
545 |
]. |
|
546 |
||
547 |
(visitorClass includesSelector:#'visitObject:') ifFalse:[ |
|
548 |
self |
|
549 |
compile: |
|
550 |
('visitObject:anObject |
|
551 |
"dispatched back from the visited objects (visitor pattern)" |
|
552 |
||
553 |
"general fallBack - please change as required" |
|
554 |
||
555 |
self halt:''not yet implemented'' |
|
556 |
') |
|
557 |
forClass:visitorClass |
|
558 |
inCategory:'visiting'. |
|
559 |
]. |
|
560 |
||
561 |
(visitorClass includesSelector:#'visit:') ifFalse:[ |
|
562 |
self |
|
563 |
compile: |
|
564 |
('visit:anObject |
|
565 |
"visit anObject (visitor pattern). |
|
566 |
The object should call back one of my visitXXXX methods." |
|
567 |
||
568 |
^ anObject acceptVisitor:self |
|
569 |
') |
|
570 |
forClass:visitorClass |
|
571 |
inCategory:'visiting'. |
|
572 |
] |
|
573 |
! |
|
574 |
||
575 |
initialMenuSpecMethodSourceForApplications |
|
576 |
^ |
|
577 |
'mainMenu |
|
578 |
"This resource specification was automatically generated by the CodeGeneratorTool." |
|
579 |
||
580 |
"Do not manually edit this!! If it is corrupted, |
|
581 |
the MenuEditor may not be able to read the specification." |
|
582 |
||
583 |
" |
|
584 |
MenuEditor new openOnClass:%1 andSelector:#mainMenu |
|
585 |
" |
|
586 |
||
587 |
<resource: #menu> |
|
588 |
||
589 |
^ #(#Menu |
|
590 |
#( |
|
591 |
#(#MenuItem |
|
592 |
#label: ''File'' |
|
593 |
#translateLabel: true |
|
594 |
#submenu: |
|
595 |
#(#Menu |
|
596 |
#( |
|
597 |
#(#MenuItem |
|
598 |
#label: ''New'' |
|
599 |
#translateLabel: true |
|
600 |
#value: #menuNew |
|
601 |
) |
|
602 |
#(#MenuItem |
|
603 |
#label: ''-'' |
|
604 |
) |
|
605 |
#(#MenuItem |
|
606 |
#label: ''Open...'' |
|
607 |
#translateLabel: true |
|
608 |
#value: #menuOpen |
|
609 |
) |
|
610 |
#(#MenuItem |
|
611 |
#label: ''-'' |
|
612 |
) |
|
613 |
#(#MenuItem |
|
614 |
#label: ''Save'' |
|
615 |
#translateLabel: true |
|
616 |
#value: #menuSave |
|
617 |
) |
|
618 |
#(#MenuItem |
|
619 |
#label: ''Save As...'' |
|
620 |
#translateLabel: true |
|
621 |
#value: #menuSaveAs |
|
622 |
) |
|
623 |
#(#MenuItem |
|
624 |
#label: ''-'' |
|
625 |
) |
|
626 |
#(#MenuItem |
|
627 |
#label: ''Exit'' |
|
628 |
#translateLabel: true |
|
629 |
#value: #closeRequest |
|
630 |
) |
|
631 |
) nil |
|
632 |
nil |
|
633 |
) |
|
634 |
) |
|
635 |
#(#MenuItem |
|
636 |
#label: ''Help'' |
|
637 |
#translateLabel: true |
|
638 |
#startGroup: #right |
|
639 |
#submenu: |
|
640 |
#(#Menu |
|
641 |
#( |
|
642 |
#(#MenuItem |
|
643 |
#label: ''Documentation'' |
|
644 |
#translateLabel: true |
|
645 |
#value: #openDocumentation |
|
646 |
) |
|
647 |
#(#MenuItem |
|
648 |
#label: ''-'' |
|
649 |
) |
|
650 |
#(#MenuItem |
|
651 |
#label: ''About this Application'' |
|
652 |
#translateLabel: true |
|
653 |
#value: #openAboutThisApplication |
|
654 |
) |
|
655 |
) nil |
|
656 |
nil |
|
657 |
) |
|
658 |
) |
|
659 |
) nil |
|
660 |
nil |
|
661 |
) |
|
662 |
'. |
|
663 |
! |
|
664 |
||
665 |
initialWindowSpecMethodSourceForApplications |
|
666 |
^ |
|
667 |
'windowSpec |
|
668 |
"This resource specification was automatically generated by the CodeGeneratorTool." |
|
669 |
||
670 |
"Do not manually edit this!! If it is corrupted, |
|
671 |
the UIPainter may not be able to read the specification." |
|
672 |
||
673 |
" |
|
674 |
UIPainter new openOnClass:%1 andSelector:#windowSpec |
|
675 |
" |
|
676 |
||
677 |
<resource: #canvas> |
|
678 |
||
679 |
^ #(#FullSpec |
|
680 |
#window: |
|
681 |
#(#WindowSpec |
|
682 |
#name: ''%1'' |
|
683 |
#layout: #(#LayoutFrame 204 0 162 0 503 0 461 0) |
|
684 |
#label: ''%1'' |
|
685 |
#min: #(#Point 10 10) |
|
686 |
#max: #(#Point 1024 768) |
|
687 |
#bounds: #(#Rectangle 204 162 504 462) |
|
688 |
#menu: #mainMenu |
|
689 |
#usePreferredExtent: false |
|
690 |
) |
|
691 |
#component: |
|
692 |
#(#SpecCollection |
|
693 |
#collection: #() |
|
694 |
) |
|
695 |
) |
|
696 |
'. |
|
697 |
! |
|
698 |
||
699 |
initialWindowSpecMethodSourceForDialogs |
|
700 |
^ |
|
701 |
'windowSpec |
|
702 |
"This resource specification was automatically generated by the CodeGeneratorTool." |
|
703 |
||
704 |
"Do not manually edit this!! If it is corrupted, |
|
705 |
the UIPainter may not be able to read the specification." |
|
706 |
||
707 |
" |
|
708 |
UIPainter new openOnClass:%1 andSelector:#windowSpec |
|
709 |
" |
|
710 |
||
711 |
<resource: #canvas> |
|
712 |
||
713 |
^ |
|
714 |
||
715 |
#(#FullSpec |
|
716 |
#window: |
|
717 |
#(#WindowSpec |
|
718 |
#name: ''%1'' |
|
719 |
#layout: #(#LayoutFrame 221 0 118 0 520 0 417 0) |
|
720 |
#level: 0 |
|
721 |
#label: ''%1'' |
|
722 |
#min: #(#Point 10 10) |
|
723 |
#max: #(#Point 1024 768) |
|
724 |
#bounds: #(#Rectangle 221 118 521 418) |
|
725 |
#usePreferredExtent: false |
|
726 |
) |
|
727 |
#component: |
|
728 |
#(#SpecCollection |
|
729 |
#collection: |
|
730 |
#( |
|
731 |
#(#HorizontalPanelViewSpec |
|
732 |
#name: ''buttonPanel'' |
|
733 |
#layout: #(#LayoutFrame 0 0.0 -45 1 0 1.0 0 1.0) |
|
734 |
#component: |
|
735 |
#(#SpecCollection |
|
736 |
#collection: |
|
737 |
#( |
|
738 |
#(#ActionButtonSpec |
|
739 |
#name: ''cancelButton'' |
|
740 |
#label: ''Cancel'' |
|
741 |
#tabable: true |
|
742 |
#translateLabel: true |
|
743 |
#model: #cancel |
|
744 |
#extent: #(#Point 125 22) |
|
745 |
) |
|
746 |
#(#ActionButtonSpec |
|
747 |
#name: ''okButton'' |
|
748 |
#label: ''OK'' |
|
749 |
#tabable: true |
|
750 |
#translateLabel: true |
|
751 |
#isDefault: true |
|
752 |
#model: #accept |
|
753 |
#extent: #(#Point 125 22) |
|
754 |
) |
|
755 |
) |
|
756 |
) |
|
757 |
#reverseOrderIfOKAtLeft: true |
|
758 |
#horizontalLayout: #spreadSpaceMax |
|
759 |
#verticalLayout: #center |
|
760 |
#horizontalSpace: 3 |
|
761 |
#verticalSpace: 3 |
|
762 |
) |
|
763 |
) |
|
764 |
) |
|
765 |
) |
|
766 |
'. |
|
767 |
! ! |
|
768 |
||
769 |
!CodeGeneratorTool class methodsFor:'code generation - individual methods'! |
|
770 |
||
771 |
createAcceptVisitorMethod:selector in:aClass |
|
772 |
"create an acceptVisitor: method |
|
773 |
(I'm tired of typing)" |
|
774 |
||
775 |
aClass isMeta ifTrue:[self halt]. |
|
776 |
||
777 |
(aClass includesSelector:#'acceptVisitor:') ifFalse:[ |
|
778 |
self |
|
779 |
compile: |
|
780 |
(('acceptVisitor:aVisitor |
|
781 |
"Double dispatch back to the visitor, passing my type encoded in |
|
782 |
the selector (visitor pattern)" |
|
783 |
||
784 |
"stub code automatically generated - please change if required" |
|
785 |
||
786 |
^ aVisitor %1self |
|
787 |
') bindWith:selector) |
|
788 |
forClass:aClass |
|
789 |
inCategory:'visiting'. |
|
790 |
] |
|
791 |
! |
|
792 |
||
793 |
createAcceptVisitorMethodIn:aClass |
|
794 |
"create an acceptVisitor: method |
|
795 |
(I'm tired of typing)" |
|
796 |
||
797 |
self |
|
798 |
createAcceptVisitorMethod:('visit' , aClass nameWithoutPrefix , ':') asSymbol |
|
799 |
in:aClass |
|
800 |
! |
|
801 |
||
802 |
createCopyrightMethodFor:aClass |
|
803 |
"add copyright method containing your/your companies |
|
804 |
copyright template but only if not already present. |
|
805 |
this is only added, if specified in the |
|
806 |
COPYRIGHT_TEMPLATE_FILE resources." |
|
807 |
||
808 |
|fn txt| |
|
809 |
||
810 |
(aClass includesSelector:#copyright) ifFalse:[ |
|
811 |
fn := SystemBrowser classResources at:#'COPYRIGHT_TEMPLATE_FILE' default:nil. |
|
812 |
fn notNil ifTrue:[ |
|
813 |
fn := fn asFilename. |
|
814 |
fn exists ifTrue:[ |
|
815 |
txt := fn contents asString |
|
816 |
] |
|
817 |
]. |
|
818 |
||
819 |
txt notNil ifTrue:[ |
|
820 |
txt := txt bindWith:(Date today year). |
|
821 |
self compile: |
|
822 |
'copyright |
|
823 |
" |
|
824 |
' , txt , ' |
|
825 |
" |
|
826 |
' forClass:aClass |
|
827 |
inCategory:'documentation'. |
|
828 |
] |
|
829 |
]. |
|
830 |
! |
|
831 |
||
832 |
createDocumentationMethodFor:aClass |
|
833 |
"add documentation method containing doc template |
|
834 |
but only if not already present." |
|
835 |
||
836 |
|userName loginName hostName emailAddress| |
|
837 |
||
838 |
(aClass includesSelector:#documentation) ifFalse:[ |
|
839 |
userName := OperatingSystem getFullUserName. |
|
840 |
loginName := OperatingSystem getLoginName. |
|
841 |
hostName := OperatingSystem getHostName. |
|
842 |
emailAddress := loginName , '@' , hostName. |
|
843 |
||
844 |
self compile: |
|
845 |
'documentation |
|
846 |
" |
|
847 |
documentation to be added. |
|
848 |
||
849 |
[author:] |
|
850 |
' , userName |
|
851 |
, ' (' , emailAddress , ')' , ' |
|
852 |
||
853 |
[instance variables:] |
|
854 |
||
855 |
[class variables:] |
|
856 |
||
857 |
[see also:] |
|
858 |
||
859 |
" |
|
860 |
' forClass:aClass |
|
861 |
inCategory:'documentation'. |
|
862 |
]. |
|
863 |
! |
|
864 |
||
865 |
createExamplesMethodFor:aClass |
|
866 |
"add examples method containing examples template |
|
867 |
but only if not already present." |
|
868 |
||
869 |
|fragment| |
|
870 |
||
871 |
(aClass includesSelector:#examples) ifFalse:[ |
|
872 |
(aClass theNonMetaclass isSubclassOf:ApplicationModel) ifTrue:[ |
|
873 |
fragment := ' Starting the application: |
|
874 |
[exBegin] |
|
875 |
' , aClass theNonMetaclass name , ' open |
|
876 |
||
877 |
[exEnd] |
|
878 |
' |
|
879 |
] ifFalse:[ |
|
880 |
fragment := '' |
|
881 |
]. |
|
882 |
||
883 |
self |
|
884 |
compile: |
|
885 |
'examples |
|
886 |
" |
|
887 |
' , fragment , ' |
|
888 |
more examples to be added: |
|
889 |
[exBegin] |
|
890 |
... add code fragment for |
|
891 |
... executable example here ... |
|
892 |
[exEnd] |
|
893 |
" |
|
894 |
' |
|
895 |
forClass:aClass |
|
896 |
inCategory:'documentation'. |
|
897 |
]. |
|
898 |
! |
|
899 |
||
900 |
createInitialHistoryMethodFor:aClass |
|
901 |
"add history method containing created-entry |
|
902 |
but only if not already present." |
|
903 |
||
904 |
(aClass includesSelector:#history) ifFalse:[ |
|
905 |
HistoryManager notNil ifTrue:[ |
|
906 |
HistoryManager createInitialHistoryMethodIn:aClass |
|
907 |
]. |
|
908 |
]. |
|
909 |
! |
|
910 |
||
911 |
createMultiSetterMethodFor:aCollectionOfVarNames in:aClass |
|
912 |
"create a multi-setter method for instvars." |
|
913 |
||
914 |
|source| |
|
915 |
||
916 |
source := ''. |
|
917 |
aCollectionOfVarNames do:[:eachVar | |
|
918 |
source := source , (eachVar , ':' , eachVar , 'Arg '). |
|
919 |
]. |
|
920 |
source := source , Character cr. |
|
921 |
source := source , (' "set instance variables (automatically generated)"' , Character cr , Character cr). |
|
922 |
aCollectionOfVarNames do:[:eachVar | |
|
923 |
source := source , (' ' , eachVar , ' := ' , eachVar , 'Arg.' , Character cr). |
|
924 |
]. |
|
925 |
self compile:source forClass:aClass inCategory:'accessing'. |
|
926 |
! |
|
927 |
||
3800
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
928 |
createSubclassResponsibilityMethodFor:aSelector category:cat in:aClass |
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
929 |
"add a subclassResponsibility method; |
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
930 |
but only if not already present." |
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
931 |
|
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
932 |
(aClass includesSelector:aSelector) ifFalse:[ |
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
933 |
|
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
934 |
self compile: |
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
935 |
(Method methodDefinitionTemplateForSelector:aSelector) , |
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
936 |
' |
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
937 |
"raise an error: must be redefined in concrete subclass(es)" |
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
938 |
|
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
939 |
^ self subclassResponsibility |
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
940 |
' |
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
941 |
forClass:aClass |
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
942 |
inCategory:cat. |
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
943 |
]. |
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
944 |
! |
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
945 |
|
3712 | 946 |
createUpdateMethodIn:aClass |
947 |
"create an update:with:from:-method |
|
948 |
(I'm tired of typing)" |
|
949 |
||
950 |
(aClass includesSelector:#'update:with:from:') ifFalse:[ |
|
951 |
self |
|
952 |
compile: |
|
953 |
'update:something with:aParameter from:changedObject |
|
954 |
"Invoked when an object that I depend upon sends a change notification." |
|
955 |
||
956 |
"stub code automatically generated - please change as required" |
|
957 |
||
958 |
"/ changedObject == someOfMyValueHolders ifTrue:[ |
|
959 |
"/ self doSomethingApropriate |
|
960 |
"/ ^ self |
|
961 |
"/ ]. |
|
962 |
super update:something with:aParameter from:changedObject |
|
963 |
' |
|
964 |
forClass:aClass |
|
965 |
inCategory:'change & update'. |
|
966 |
] |
|
967 |
! |
|
968 |
||
969 |
createVersionMethodFor:aClass |
|
970 |
"add version method containing RCS template |
|
971 |
but only if not already present and its not a private class." |
|
972 |
||
973 |
aClass isPrivate ifFalse:[ |
|
974 |
(aClass includesSelector:#version) ifFalse:[ |
|
975 |
self compile: |
|
976 |
'version |
|
977 |
^ ''$' , 'Header$'' |
|
978 |
' |
|
979 |
forClass:aClass |
|
980 |
inCategory:'documentation'. |
|
981 |
] |
|
982 |
]. |
|
983 |
! ! |
|
984 |
||
985 |
!CodeGeneratorTool class methodsFor:'compilation'! |
|
986 |
||
987 |
canUseRefactoringSupport |
|
988 |
^ RefactoryChangeManager notNil and:[RefactoryChangeManager isLoaded] |
|
989 |
! |
|
990 |
||
991 |
compile:theCode forClass:aClass inCategory:cat |
|
992 |
|change| |
|
993 |
||
994 |
self canUseRefactoringSupport ifFalse:[ |
|
3716 | 995 |
aClass compile:theCode classified:cat. |
3712 | 996 |
^ self. |
997 |
]. |
|
998 |
||
3716 | 999 |
change := InteractiveAddMethodChange compile:(theCode asString) in:aClass classified:cat. |
3712 | 1000 |
RefactoryChangeManager instance performChange:change. |
1001 |
! ! |
|
1002 |
||
1003 |
!CodeGeneratorTool class methodsFor:'documentation'! |
|
1004 |
||
1005 |
version |
|
3800
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
1006 |
^ '$Header: /cvs/stx/stx/libtool/CodeGeneratorTool.st,v 1.4 2002-08-15 11:09:05 cg Exp $' |
3712 | 1007 |
! ! |