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