author | Claus Gittinger <cg@exept.de> |
Thu, 21 Jul 2011 15:20:38 +0200 | |
changeset 10371 | c35aa5f6abf6 |
parent 9960 | 324ad5515d57 |
child 10591 | 91a0e6defc80 |
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 |
]. |
|
215 |
self compile:code forClass:aClass inCategory:(aCategory ? 'actions'). |
|
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). |
|
253 |
self compile:code forClass:aClass inCategory:(aCategory ? 'actions'). |
|
254 |
^ code |
|
255 |
! ! |
|
256 |
||
9960 | 257 |
!SmalltalkCodeGeneratorTool class methodsFor:'others'! |
258 |
||
259 |
version_CVS |
|
10371
c35aa5f6abf6
changed: #createAccessMethodsFor:in:withChange:asValueHolder:readersOnly:writersOnly:lazyInitialization:
Claus Gittinger <cg@exept.de>
parents:
9960
diff
changeset
|
260 |
^ '$Header: /cvs/stx/stx/libtool/SmalltalkCodeGeneratorTool.st,v 1.7 2011-07-21 13:20:38 cg Exp $' |
9960 | 261 |
! ! |
262 |
||
9706 | 263 |
!SmalltalkCodeGeneratorTool class methodsFor:'private'! |
264 |
||
265 |
methodNameTemplateFor:aSelector |
|
266 |
|numArgs method| |
|
267 |
||
268 |
numArgs := aSelector numArgs. |
|
269 |
numArgs == 1 ifTrue:[ |
|
270 |
method := aSelector, 'anArgument'. |
|
271 |
] ifFalse:[ |
|
272 |
numArgs == 0 ifTrue:[ |
|
273 |
method := aSelector |
|
274 |
] ifFalse:[ |
|
275 |
method := ''. |
|
276 |
aSelector keywords keysAndValuesDo:[:i :key| |
|
277 |
method := method, key, 'arg', i printString, ' '. |
|
278 |
]. |
|
279 |
] |
|
280 |
]. |
|
281 |
^ method |
|
282 |
! ! |
|
283 |
||
284 |
!SmalltalkCodeGeneratorTool methodsFor:'code generation'! |
|
285 |
||
286 |
createClassInitializeMethodIn:aClass |
|
287 |
"create a #initialize method on the class side (I'm tired of typing)" |
|
288 |
||
289 |
|nonMetaClass metaClass className code initializer bindings| |
|
290 |
||
291 |
nonMetaClass := aClass theNonMetaclass. |
|
292 |
metaClass := aClass theMetaclass. |
|
293 |
className := nonMetaClass name. |
|
294 |
||
295 |
self startCollectChanges. |
|
296 |
||
297 |
(metaClass includesSelector:#'initialize') ifFalse:[ |
|
298 |
'initialize |
|
299 |
"Invoked at system start or when the class is dynamically loaded." |
|
300 |
||
301 |
"/ please change as required (and remove this comment) |
|
302 |
'. |
|
303 |
bindings := Dictionary new. |
|
304 |
bindings at:'INIT_CLASSINSTVARS' put:( |
|
305 |
String streamContents:[:s | |
|
306 |
metaClass instVarNames do:[:eachClassInstVar | |
|
307 |
initializer := 'nil'. "/ need more intelligence here (try to guess class from messages sent to it) ... |
|
308 |
s nextPutLine:(' "/ %1 := %2.' bindWith:eachClassInstVar with:initializer). |
|
309 |
] |
|
310 |
]). |
|
311 |
||
312 |
bindings at:'INIT_CLASSVARS' put:( |
|
313 |
String streamContents:[:s | |
|
314 |
nonMetaClass classVarNames do:[:eachClassVar | |
|
315 |
initializer := 'nil'. "/ need more intelligence here (try to guess class from messages sent to it) ... |
|
316 |
s nextPutLine:(' "/ %1 := %2.' bindWith:eachClassVar with:initializer). |
|
317 |
] |
|
318 |
]). |
|
319 |
||
320 |
code := (self codeFor_classInitialize) expandPlaceholdersWith:bindings. |
|
321 |
||
322 |
self |
|
323 |
compile:code |
|
324 |
forClass:metaClass |
|
325 |
inCategory:'initialization'. |
|
326 |
]. |
|
327 |
||
328 |
self executeCollectedChangesNamed:('Add Class Initializer to ' , className). |
|
329 |
! |
|
330 |
||
331 |
createClassTypeTestMethodsIn:aClass forClasses:subClasses |
|
332 |
"create a #isXXX test methods (I'm tired of typing)" |
|
333 |
||
334 |
| code| |
|
335 |
||
336 |
self startCollectChanges. |
|
337 |
||
338 |
subClasses do:[:eachSubClass | |
|
339 |
|nm selector| |
|
340 |
||
341 |
nm := eachSubClass nameWithoutPrefix. |
|
342 |
selector := 'is' , nm. |
|
343 |
(aClass includesSelector:selector) ifFalse:[ |
|
344 |
code := (selector , '\ ^ false') withCRs. |
|
345 |
self |
|
346 |
compile:code |
|
347 |
forClass:aClass |
|
348 |
inCategory:'testing'. |
|
349 |
]. |
|
350 |
(eachSubClass includesSelector:selector) ifFalse:[ |
|
351 |
code := (selector , '\ ^ true') withCRs. |
|
352 |
self |
|
353 |
compile:code |
|
354 |
forClass:eachSubClass |
|
355 |
inCategory:'testing'. |
|
356 |
]. |
|
357 |
]. |
|
358 |
||
359 |
self executeCollectedChangesNamed:'Add ClassType Tests' |
|
360 |
! |
|
361 |
||
362 |
createEnumTypeCodeFor:aClass |
|
363 |
|nonMetaClass metaClass className enumValues code initCode runValue maxValue| |
|
364 |
||
365 |
self startCollectChanges. |
|
366 |
||
367 |
nonMetaClass := aClass theNonMetaclass. |
|
368 |
metaClass := aClass theMetaclass. |
|
369 |
className := nonMetaClass name. |
|
370 |
||
371 |
enumValues := nonMetaClass classVarNames. |
|
372 |
enumValues do:[:eachVariableName | |
|
373 |
self |
|
374 |
createAccessMethodsFor:(Array with:eachVariableName) |
|
375 |
in:metaClass |
|
376 |
withChange:false |
|
377 |
asValueHolder:false |
|
378 |
readersOnly:true |
|
379 |
writersOnly:false |
|
380 |
]. |
|
381 |
||
382 |
maxValue := enumValues |
|
383 |
inject:0 |
|
384 |
into:[:maxSoFar :eachVariableName | |
|
385 |
|oldVal val| |
|
386 |
oldVal := nonMetaClass classVarAt:eachVariableName. |
|
387 |
oldVal notNil ifTrue:[ val := oldVal numericValue ]. |
|
388 |
(val ? maxSoFar) max:maxSoFar |
|
389 |
]. |
|
390 |
||
391 |
initCode := WriteStream on: String new. |
|
392 |
initCode nextPutLine:'initialize'. |
|
393 |
runValue := maxValue + 1. |
|
394 |
enumValues keysAndValuesDo:[:idx :eachVariableName | |
|
395 |
|oldValue thisValue| |
|
396 |
||
397 |
oldValue := nonMetaClass classVarAt:eachVariableName. |
|
398 |
oldValue notNil ifTrue:[ |
|
399 |
thisValue := oldValue numericValue. |
|
400 |
] ifFalse:[ |
|
401 |
thisValue := runValue. |
|
402 |
runValue := runValue + 1. |
|
403 |
]. |
|
404 |
initCode |
|
405 |
nextPutAll:' '; |
|
406 |
nextPutAll:eachVariableName; |
|
407 |
nextPutAll:' := self basicNew'. |
|
408 |
(aClass canUnderstand:#'setNumericValue:') ifTrue:[ |
|
409 |
initCode nextPutAll:' setNumericValue: ',thisValue printString. |
|
410 |
]. |
|
411 |
(aClass canUnderstand:#'setCssClassString:') ifTrue:[ |
|
412 |
initCode nextPutAll:('; setCssClassString: ''' , nonMetaClass nameWithoutPrefix asLowercaseFirst , eachVariableName , ''''). |
|
413 |
]. |
|
414 |
(aClass canUnderstand:#'setName:') ifTrue:[ |
|
415 |
initCode nextPutAll:('; setName: ''' , eachVariableName asLowercaseFirst , ''''). |
|
416 |
]. |
|
417 |
initCode nextPutLine:'.'. |
|
418 |
]. |
|
419 |
initCode cr. |
|
420 |
initCode nextPutLine:' "'. |
|
421 |
initCode nextPutLine:' ',className, ' initialize'. |
|
422 |
initCode nextPutLine:' "'. |
|
423 |
||
424 |
self |
|
425 |
compile:(initCode contents) |
|
426 |
forClass:metaClass |
|
427 |
inCategory:'class initialization'. |
|
428 |
||
429 |
||
430 |
code := 'allStateNames\ ^ #( ' , |
|
431 |
((enumValues collect:[:each | '#''',each asLowercaseFirst,'''']) asStringWith:' ') , ')', |
|
432 |
'\\ "\' , |
|
433 |
' ',className, ' allStateNames\' , |
|
434 |
' "\'. |
|
435 |
self |
|
436 |
compile:code withCRs |
|
437 |
forClass:metaClass |
|
438 |
inCategory:'queries'. |
|
439 |
||
440 |
self executeCollectedChangesNamed:('Generate EnumType Code for ' , className). |
|
441 |
||
442 |
aClass initialize. |
|
443 |
||
444 |
"Modified: / 1.2.1998 / 16:10:03 / cg" |
|
445 |
! |
|
446 |
||
447 |
createExamplesMethodForViewClass:aClass |
|
448 |
"create an examples method" |
|
449 |
||
450 |
|nonMetaClass metaClass className code| |
|
451 |
||
452 |
nonMetaClass := aClass theNonMetaclass. |
|
453 |
metaClass := aClass theMetaclass. |
|
454 |
className := nonMetaClass name. |
|
455 |
||
456 |
self startCollectChanges. |
|
457 |
||
458 |
(metaClass includesSelector:#examples) ifFalse:[ |
|
459 |
code := |
|
460 |
'examples |
|
461 |
" |
|
462 |
Notice that everything between [exBegin] and [exEnd] is extracted by the html-doc generator |
|
463 |
to create nicely formatted and clickable executable examples in the generated html-doc. |
|
464 |
(see the browsers class-documentation menu items for more) |
|
465 |
||
466 |
trying the widget as standAlone view: |
|
467 |
[exBegin] |
|
468 |
%1 new open |
|
469 |
[exEnd] |
|
470 |
||
471 |
embedded in another view: |
|
472 |
[exBegin] |
|
473 |
|top v| |
|
474 |
||
475 |
top := StandardSystemView new. |
|
476 |
top extent:300@300. |
|
477 |
v := %1 new. |
|
478 |
v origin:10@10 corner:150@150. |
|
479 |
top add:v. |
|
480 |
top open |
|
481 |
[exEnd] |
|
482 |
" |
|
483 |
' bindWith:className. |
|
484 |
||
485 |
self |
|
486 |
compile:code |
|
487 |
forClass:metaClass |
|
488 |
inCategory:'documentation'. |
|
489 |
]. |
|
490 |
||
491 |
self executeCollectedChangesNamed:('Add Example to ' , className). |
|
492 |
! |
|
493 |
||
494 |
createInitializationMethodIn:aClass |
|
495 |
"create a #initialize methods (I'm tired of typing)" |
|
496 |
||
497 |
|nonMetaClass metaClass className code initializer m| |
|
498 |
||
499 |
nonMetaClass := aClass theNonMetaclass. |
|
500 |
metaClass := aClass theMetaclass. |
|
501 |
className := nonMetaClass name. |
|
502 |
||
503 |
self startCollectChanges. |
|
504 |
||
505 |
(nonMetaClass includesSelector:#'initialize') ifFalse:[ |
|
506 |
code := |
|
507 |
'initialize |
|
508 |
"Invoked when a new instance is created." |
|
509 |
||
510 |
"/ please change as required (and remove this comment) |
|
511 |
'. |
|
512 |
||
513 |
nonMetaClass instVarNames do:[:eachInstVar | |
|
514 |
initializer := 'nil'. "/ need more intelligence here (try to guess class from messages sent to it) ... |
|
515 |
code := code , (' "/ ' , eachInstVar , ' := ' , initializer , '.' , Character cr). |
|
516 |
]. |
|
517 |
||
518 |
m := nonMetaClass responseTo:#initialize. |
|
519 |
(m notNil and:[m messagesSent size == 0]) ifTrue:[ |
|
520 |
"/ inherits an empty initialize. |
|
521 |
||
522 |
code := code , ' |
|
523 |
"/ super initialize. -- commented since inherited method does nothing |
|
524 |
'. |
|
525 |
] ifFalse:[ |
|
526 |
code := code , ' |
|
527 |
super initialize. |
|
528 |
'. |
|
529 |
]. |
|
530 |
||
531 |
self |
|
532 |
compile:code |
|
533 |
forClass:nonMetaClass |
|
534 |
inCategory:'initialization'. |
|
535 |
]. |
|
536 |
||
537 |
self executeCollectedChangesNamed:('Add Initialized Instance Creation to ' , className). |
|
538 |
! |
|
539 |
||
540 |
createInitializedInstanceCreationMethodsIn:aClass |
|
541 |
"create a #new and #initialize methods (I'm tired of typing)" |
|
542 |
||
543 |
|nonMetaClass metaClass className code m| |
|
544 |
||
545 |
nonMetaClass := aClass theNonMetaclass. |
|
546 |
metaClass := aClass theMetaclass. |
|
547 |
className := nonMetaClass name. |
|
548 |
||
549 |
self startCollectChanges. |
|
550 |
||
551 |
self createInitializationMethodIn:aClass. |
|
552 |
||
553 |
(metaClass includesSelector:#'new') ifFalse:[ |
|
554 |
m := metaClass responseTo:#new. |
|
555 |
(m isNil |
|
556 |
or:[ (m sends:#initialize) not |
|
557 |
or:[ |
|
558 |
(Dialog |
|
9720
1ea182385871
changed: #createInitializedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
9706
diff
changeset
|
559 |
confirmWithCancel:('The inherited #new method already seems to invoke #initialize.\Redefine ?' withCRs) |
1ea182385871
changed: #createInitializedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
9706
diff
changeset
|
560 |
default:false |
1ea182385871
changed: #createInitializedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
9706
diff
changeset
|
561 |
onCancel:[^ self] ) |
1ea182385871
changed: #createInitializedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
9706
diff
changeset
|
562 |
]]) ifTrue:[ |
9706 | 563 |
code := |
564 |
'new |
|
565 |
"return an initialized instance" |
|
566 |
||
567 |
^ self basicNew initialize. |
|
568 |
'. |
|
569 |
self |
|
570 |
compile:code |
|
571 |
forClass:metaClass |
|
572 |
inCategory:'instance creation'. |
|
573 |
]. |
|
574 |
]. |
|
575 |
||
576 |
self executeCollectedChangesNamed:('Add Initialized Instance Creation to ' , className). |
|
577 |
||
9720
1ea182385871
changed: #createInitializedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
9706
diff
changeset
|
578 |
"Created: / 11-10-2001 / 22:18:55 / cg" |
1ea182385871
changed: #createInitializedInstanceCreationMethodsIn:
Claus Gittinger <cg@exept.de>
parents:
9706
diff
changeset
|
579 |
"Modified: / 30-01-2011 / 00:58:04 / cg" |
9706 | 580 |
! |
581 |
||
582 |
createParametrizedInstanceCreationMethodsNamed:selector in:aClass |
|
583 |
"create a #selector instance creation method (I'm tired of typing)" |
|
584 |
||
585 |
|nonMetaClass metaClass className code initializer m dfn| |
|
586 |
||
587 |
dfn := Method methodDefinitionTemplateForSelector:selector. |
|
588 |
||
589 |
nonMetaClass := aClass theNonMetaclass. |
|
590 |
metaClass := aClass theMetaclass. |
|
591 |
className := nonMetaClass name. |
|
592 |
||
593 |
self startCollectChanges. |
|
594 |
||
595 |
(nonMetaClass includesSelector:selector asSymbol) ifFalse:[ |
|
596 |
code := |
|
597 |
'initialize',dfn asUppercaseFirst,' |
|
598 |
"Invoked when a new instance is created for arg." |
|
599 |
||
600 |
"/ please change as required (and remove these comments) |
|
601 |
"/ do something with arg here (instVar-foo := arg) |
|
602 |
'. |
|
603 |
nonMetaClass instVarNames do:[:eachInstVar | |
|
604 |
initializer := 'nil'. "/ need more intelligence here (try to guess class from messages sent to it) ... |
|
605 |
code := code , (' "/ ' , eachInstVar , ' := ' , initializer , '.' , Character cr). |
|
606 |
]. |
|
607 |
||
608 |
m := nonMetaClass responseTo:#initialize. |
|
609 |
(m notNil and:[ m messagesSent size == 0 ]) ifTrue:[ |
|
610 |
"/ inherits an empty initialize. |
|
611 |
||
612 |
code := code , ' |
|
613 |
"/ super initialize. -- commented since inherited method does nothing |
|
614 |
'. |
|
615 |
] ifFalse:[ |
|
616 |
code := code , ' |
|
617 |
super initialize. |
|
618 |
'. |
|
619 |
]. |
|
620 |
||
621 |
self |
|
622 |
compile:code |
|
623 |
forClass:nonMetaClass |
|
624 |
inCategory:'initialization'. |
|
625 |
]. |
|
626 |
||
627 |
(metaClass includesSelector:selector) ifFalse:[ |
|
628 |
m := metaClass responseTo:selector. |
|
629 |
(m isNil |
|
630 |
or:[ (Dialog confirmWithCancel:'The ',selector,'- method is already inherited. Redefine ?' onCancel:[^ self]) ]) |
|
631 |
ifTrue:[ |
|
632 |
code := |
|
633 |
dfn,' |
|
634 |
"Create & return a new instance for arg." |
|
635 |
||
636 |
^ self basicNew initialize',dfn asUppercaseFirst,' |
|
637 |
'. |
|
638 |
self |
|
639 |
compile:code |
|
640 |
forClass:metaClass |
|
641 |
inCategory:'instance creation'. |
|
642 |
]. |
|
643 |
]. |
|
644 |
||
645 |
self executeCollectedChangesNamed:('Add Parametrized Instance Creation to ' , className). |
|
646 |
! |
|
647 |
||
648 |
createPoolInitializationCodeFor:aClass |
|
649 |
|nonMetaClass metaClass className poolVars code initCode runValue maxValue| |
|
650 |
||
651 |
self startCollectChanges. |
|
652 |
||
653 |
nonMetaClass := aClass theNonMetaclass. |
|
654 |
metaClass := aClass theMetaclass. |
|
655 |
className := nonMetaClass name. |
|
656 |
||
657 |
poolVars := nonMetaClass classVarNames. |
|
658 |
||
659 |
initCode := WriteStream on: String new. |
|
660 |
initCode nextPutLine:'initialize'. |
|
661 |
||
662 |
poolVars do:[:eachVariableName | |
|
663 |
|oldValue thisValue| |
|
664 |
||
665 |
oldValue := nonMetaClass classVarAt:eachVariableName. |
|
666 |
oldValue notNil ifTrue:[ |
|
667 |
thisValue := oldValue. |
|
668 |
] ifFalse:[ |
|
669 |
thisValue := nil. |
|
670 |
]. |
|
671 |
initCode |
|
672 |
nextPutAll:' '; |
|
673 |
nextPutAll:eachVariableName; |
|
674 |
nextPutAll:' := '; |
|
675 |
nextPutAll:thisValue storeString; |
|
676 |
nextPutLine:'.'. |
|
677 |
]. |
|
678 |
initCode cr. |
|
679 |
initCode nextPutLine:' "'. |
|
680 |
initCode nextPutLine:' ',className, ' initialize'. |
|
681 |
initCode nextPutLine:' "'. |
|
682 |
||
683 |
self |
|
684 |
compile:(initCode contents) |
|
685 |
forClass:metaClass |
|
686 |
inCategory:'class initialization'. |
|
687 |
||
688 |
self executeCollectedChangesNamed:('Generate Pool Initialization Code for ' , className). |
|
689 |
||
690 |
aClass initialize. |
|
691 |
||
692 |
"Created: / 25-10-2006 / 09:28:40 / cg" |
|
693 |
! |
|
694 |
||
695 |
createRedefinedInstanceCreationMethodsIn:aClass |
|
696 |
"create a redefined #new methods" |
|
697 |
||
698 |
|nonMetaClass metaClass className code| |
|
699 |
||
700 |
nonMetaClass := aClass theNonMetaclass. |
|
701 |
metaClass := aClass theMetaclass. |
|
702 |
className := nonMetaClass name. |
|
703 |
||
704 |
self startCollectChanges. |
|
705 |
||
706 |
(metaClass includesSelector:#'new') ifFalse:[ |
|
707 |
code := |
|
708 |
'new |
|
709 |
^ super new. |
|
710 |
'. |
|
711 |
self |
|
712 |
compile:code |
|
713 |
forClass:metaClass |
|
714 |
inCategory:'redefined instance creation'. |
|
715 |
]. |
|
716 |
(metaClass includesSelector:#'new:') ifFalse:[ |
|
717 |
code := |
|
718 |
'new:n |
|
719 |
^ super new:n. |
|
720 |
'. |
|
721 |
self |
|
722 |
compile:code |
|
723 |
forClass:metaClass |
|
724 |
inCategory:'redefined instance creation'. |
|
725 |
]. |
|
726 |
||
727 |
self executeCollectedChangesNamed:('Redefined Instance Creation to ' , className). |
|
728 |
! |
|
729 |
||
9756
5a1787bbf85e
added: #classMenuGenerateSingletonPatternInstanceCreationMethods
Claus Gittinger <cg@exept.de>
parents:
9720
diff
changeset
|
730 |
createSingletonPatternInstanceCreationMethodsIn:aClass usingVariable:varName |
5a1787bbf85e
added: #classMenuGenerateSingletonPatternInstanceCreationMethods
Claus Gittinger <cg@exept.de>
parents:
9720
diff
changeset
|
731 |
"create redefined #new methods for singleton pattern. |
5a1787bbf85e
added: #classMenuGenerateSingletonPatternInstanceCreationMethods
Claus Gittinger <cg@exept.de>
parents:
9720
diff
changeset
|
732 |
Uses varName (typically a class-instvar) to keep the singleton instance." |
5a1787bbf85e
added: #classMenuGenerateSingletonPatternInstanceCreationMethods
Claus Gittinger <cg@exept.de>
parents:
9720
diff
changeset
|
733 |
|
5a1787bbf85e
added: #classMenuGenerateSingletonPatternInstanceCreationMethods
Claus Gittinger <cg@exept.de>
parents:
9720
diff
changeset
|
734 |
|nonMetaClass metaClass className code| |
5a1787bbf85e
added: #classMenuGenerateSingletonPatternInstanceCreationMethods
Claus Gittinger <cg@exept.de>
parents:
9720
diff
changeset
|
735 |
|
5a1787bbf85e
added: #classMenuGenerateSingletonPatternInstanceCreationMethods
Claus Gittinger <cg@exept.de>
parents:
9720
diff
changeset
|
736 |
nonMetaClass := aClass theNonMetaclass. |
5a1787bbf85e
added: #classMenuGenerateSingletonPatternInstanceCreationMethods
Claus Gittinger <cg@exept.de>
parents:
9720
diff
changeset
|
737 |
metaClass := aClass theMetaclass. |
5a1787bbf85e
added: #classMenuGenerateSingletonPatternInstanceCreationMethods
Claus Gittinger <cg@exept.de>
parents:
9720
diff
changeset
|
738 |
className := nonMetaClass name. |
5a1787bbf85e
added: #classMenuGenerateSingletonPatternInstanceCreationMethods
Claus Gittinger <cg@exept.de>
parents:
9720
diff
changeset
|
739 |
|
5a1787bbf85e
added: #classMenuGenerateSingletonPatternInstanceCreationMethods
Claus Gittinger <cg@exept.de>
parents:
9720
diff
changeset
|
740 |
self startCollectChanges. |
5a1787bbf85e
added: #classMenuGenerateSingletonPatternInstanceCreationMethods
Claus Gittinger <cg@exept.de>
parents:
9720
diff
changeset
|
741 |
|
5a1787bbf85e
added: #classMenuGenerateSingletonPatternInstanceCreationMethods
Claus Gittinger <cg@exept.de>
parents:
9720
diff
changeset
|
742 |
(metaClass includesSelector:#'theOneAndOnlyInstance') ifFalse:[ |
5a1787bbf85e
added: #classMenuGenerateSingletonPatternInstanceCreationMethods
Claus Gittinger <cg@exept.de>
parents:
9720
diff
changeset
|
743 |
code := |
5a1787bbf85e
added: #classMenuGenerateSingletonPatternInstanceCreationMethods
Claus Gittinger <cg@exept.de>
parents:
9720
diff
changeset
|
744 |
'theOneAndOnlyInstance |
5a1787bbf85e
added: #classMenuGenerateSingletonPatternInstanceCreationMethods
Claus Gittinger <cg@exept.de>
parents:
9720
diff
changeset
|
745 |
"returns a singleton" |
5a1787bbf85e
added: #classMenuGenerateSingletonPatternInstanceCreationMethods
Claus Gittinger <cg@exept.de>
parents:
9720
diff
changeset
|
746 |
|
5a1787bbf85e
added: #classMenuGenerateSingletonPatternInstanceCreationMethods
Claus Gittinger <cg@exept.de>
parents:
9720
diff
changeset
|
747 |
%1 isNil ifTrue:[ |
5a1787bbf85e
added: #classMenuGenerateSingletonPatternInstanceCreationMethods
Claus Gittinger <cg@exept.de>
parents:
9720
diff
changeset
|
748 |
%1 := self basicNew initialize. |
5a1787bbf85e
added: #classMenuGenerateSingletonPatternInstanceCreationMethods
Claus Gittinger <cg@exept.de>
parents:
9720
diff
changeset
|
749 |
]. |
5a1787bbf85e
added: #classMenuGenerateSingletonPatternInstanceCreationMethods
Claus Gittinger <cg@exept.de>
parents:
9720
diff
changeset
|
750 |
^ %1. |
5a1787bbf85e
added: #classMenuGenerateSingletonPatternInstanceCreationMethods
Claus Gittinger <cg@exept.de>
parents:
9720
diff
changeset
|
751 |
'. |
5a1787bbf85e
added: #classMenuGenerateSingletonPatternInstanceCreationMethods
Claus Gittinger <cg@exept.de>
parents:
9720
diff
changeset
|
752 |
self |
5a1787bbf85e
added: #classMenuGenerateSingletonPatternInstanceCreationMethods
Claus Gittinger <cg@exept.de>
parents:
9720
diff
changeset
|
753 |
compile:(code bindWith:varName) |
5a1787bbf85e
added: #classMenuGenerateSingletonPatternInstanceCreationMethods
Claus Gittinger <cg@exept.de>
parents:
9720
diff
changeset
|
754 |
forClass:metaClass |
5a1787bbf85e
added: #classMenuGenerateSingletonPatternInstanceCreationMethods
Claus Gittinger <cg@exept.de>
parents:
9720
diff
changeset
|
755 |
inCategory:'instance creation'. |
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 |
|
5a1787bbf85e
added: #classMenuGenerateSingletonPatternInstanceCreationMethods
Claus Gittinger <cg@exept.de>
parents:
9720
diff
changeset
|
758 |
(metaClass includesSelector:#'new') ifFalse:[ |
5a1787bbf85e
added: #classMenuGenerateSingletonPatternInstanceCreationMethods
Claus Gittinger <cg@exept.de>
parents:
9720
diff
changeset
|
759 |
code := |
5a1787bbf85e
added: #classMenuGenerateSingletonPatternInstanceCreationMethods
Claus Gittinger <cg@exept.de>
parents:
9720
diff
changeset
|
760 |
'new |
5a1787bbf85e
added: #classMenuGenerateSingletonPatternInstanceCreationMethods
Claus Gittinger <cg@exept.de>
parents:
9720
diff
changeset
|
761 |
"returns a singleton" |
5a1787bbf85e
added: #classMenuGenerateSingletonPatternInstanceCreationMethods
Claus Gittinger <cg@exept.de>
parents:
9720
diff
changeset
|
762 |
|
5a1787bbf85e
added: #classMenuGenerateSingletonPatternInstanceCreationMethods
Claus Gittinger <cg@exept.de>
parents:
9720
diff
changeset
|
763 |
^ self theOneAndOnlyInstance. |
5a1787bbf85e
added: #classMenuGenerateSingletonPatternInstanceCreationMethods
Claus Gittinger <cg@exept.de>
parents:
9720
diff
changeset
|
764 |
'. |
5a1787bbf85e
added: #classMenuGenerateSingletonPatternInstanceCreationMethods
Claus Gittinger <cg@exept.de>
parents:
9720
diff
changeset
|
765 |
self |
5a1787bbf85e
added: #classMenuGenerateSingletonPatternInstanceCreationMethods
Claus Gittinger <cg@exept.de>
parents:
9720
diff
changeset
|
766 |
compile:(code bindWith:varName) |
5a1787bbf85e
added: #classMenuGenerateSingletonPatternInstanceCreationMethods
Claus Gittinger <cg@exept.de>
parents:
9720
diff
changeset
|
767 |
forClass:metaClass |
5a1787bbf85e
added: #classMenuGenerateSingletonPatternInstanceCreationMethods
Claus Gittinger <cg@exept.de>
parents:
9720
diff
changeset
|
768 |
inCategory:'instance creation'. |
5a1787bbf85e
added: #classMenuGenerateSingletonPatternInstanceCreationMethods
Claus Gittinger <cg@exept.de>
parents:
9720
diff
changeset
|
769 |
]. |
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 |
(metaClass includesSelector:#'flushSingleton') ifFalse:[ |
5a1787bbf85e
added: #classMenuGenerateSingletonPatternInstanceCreationMethods
Claus Gittinger <cg@exept.de>
parents:
9720
diff
changeset
|
772 |
code := |
5a1787bbf85e
added: #classMenuGenerateSingletonPatternInstanceCreationMethods
Claus Gittinger <cg@exept.de>
parents:
9720
diff
changeset
|
773 |
'flushSingleton |
5a1787bbf85e
added: #classMenuGenerateSingletonPatternInstanceCreationMethods
Claus Gittinger <cg@exept.de>
parents:
9720
diff
changeset
|
774 |
"flushes the cached singleton" |
5a1787bbf85e
added: #classMenuGenerateSingletonPatternInstanceCreationMethods
Claus Gittinger <cg@exept.de>
parents:
9720
diff
changeset
|
775 |
|
5a1787bbf85e
added: #classMenuGenerateSingletonPatternInstanceCreationMethods
Claus Gittinger <cg@exept.de>
parents:
9720
diff
changeset
|
776 |
%1 := nil |
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 |
" |
5a1787bbf85e
added: #classMenuGenerateSingletonPatternInstanceCreationMethods
Claus Gittinger <cg@exept.de>
parents:
9720
diff
changeset
|
779 |
self flushSingleton |
5a1787bbf85e
added: #classMenuGenerateSingletonPatternInstanceCreationMethods
Claus Gittinger <cg@exept.de>
parents:
9720
diff
changeset
|
780 |
" |
5a1787bbf85e
added: #classMenuGenerateSingletonPatternInstanceCreationMethods
Claus Gittinger <cg@exept.de>
parents:
9720
diff
changeset
|
781 |
'. |
5a1787bbf85e
added: #classMenuGenerateSingletonPatternInstanceCreationMethods
Claus Gittinger <cg@exept.de>
parents:
9720
diff
changeset
|
782 |
self |
5a1787bbf85e
added: #classMenuGenerateSingletonPatternInstanceCreationMethods
Claus Gittinger <cg@exept.de>
parents:
9720
diff
changeset
|
783 |
compile:(code bindWith:varName) |
5a1787bbf85e
added: #classMenuGenerateSingletonPatternInstanceCreationMethods
Claus Gittinger <cg@exept.de>
parents:
9720
diff
changeset
|
784 |
forClass:metaClass |
5a1787bbf85e
added: #classMenuGenerateSingletonPatternInstanceCreationMethods
Claus Gittinger <cg@exept.de>
parents:
9720
diff
changeset
|
785 |
inCategory:'instance creation'. |
5a1787bbf85e
added: #classMenuGenerateSingletonPatternInstanceCreationMethods
Claus Gittinger <cg@exept.de>
parents:
9720
diff
changeset
|
786 |
]. |
5a1787bbf85e
added: #classMenuGenerateSingletonPatternInstanceCreationMethods
Claus Gittinger <cg@exept.de>
parents:
9720
diff
changeset
|
787 |
|
5a1787bbf85e
added: #classMenuGenerateSingletonPatternInstanceCreationMethods
Claus Gittinger <cg@exept.de>
parents:
9720
diff
changeset
|
788 |
self executeCollectedChangesNamed:('Singleton Pattern for ' , className). |
5a1787bbf85e
added: #classMenuGenerateSingletonPatternInstanceCreationMethods
Claus Gittinger <cg@exept.de>
parents:
9720
diff
changeset
|
789 |
|
5a1787bbf85e
added: #classMenuGenerateSingletonPatternInstanceCreationMethods
Claus Gittinger <cg@exept.de>
parents:
9720
diff
changeset
|
790 |
"Created: / 10-02-2011 / 16:32:48 / cg" |
5a1787bbf85e
added: #classMenuGenerateSingletonPatternInstanceCreationMethods
Claus Gittinger <cg@exept.de>
parents:
9720
diff
changeset
|
791 |
! |
5a1787bbf85e
added: #classMenuGenerateSingletonPatternInstanceCreationMethods
Claus Gittinger <cg@exept.de>
parents:
9720
diff
changeset
|
792 |
|
9706 | 793 |
createStandardPrintOnMethodIn:aClass |
794 |
"create a #printOn: method (I'm tired of typing)" |
|
795 |
||
796 |
|code nonMetaClass| |
|
797 |
||
798 |
nonMetaClass := aClass theNonMetaclass. |
|
799 |
||
800 |
self startCollectChanges. |
|
801 |
||
802 |
(nonMetaClass includesSelector:#'printOn:') ifFalse:[ |
|
803 |
code := |
|
804 |
'printOn:aStream |
|
805 |
"append a printed representation if the receiver to the argument, aStream" |
|
806 |
||
807 |
super printOn:aStream. |
|
808 |
'. |
|
809 |
nonMetaClass instVarNames do:[:eachInstVarName | |
|
810 |
code := code , ' '. |
|
811 |
code := code , 'aStream nextPutAll:'''. |
|
812 |
code := code , eachInstVarName. |
|
813 |
code := code , ': ''.' , Character cr. |
|
814 |
code := code , ' '. |
|
815 |
code := code , eachInstVarName. |
|
816 |
code := code , ' printOn:aStream.' , Character cr. |
|
817 |
||
818 |
]. |
|
819 |
||
820 |
self |
|
821 |
compile:code |
|
822 |
forClass:nonMetaClass |
|
823 |
inCategory:'printing & storing'. |
|
824 |
]. |
|
825 |
||
826 |
||
827 |
self executeCollectedChangesNamed:('Add #printOn: to ' , nonMetaClass name). |
|
828 |
||
829 |
"Created: / 11.10.2001 / 22:18:55 / cg" |
|
830 |
! |
|
831 |
||
832 |
createStartupCodeFor:aClass forStartOf:anApplicationClassOrNil |
|
833 |
"create startup code (main)" |
|
834 |
||
835 |
|nonMetaClass metaClass className source |
|
836 |
hasAplicationClass anApplicationClassNameOrStartupClassName| |
|
837 |
||
838 |
self startCollectChanges. |
|
839 |
||
840 |
hasAplicationClass := anApplicationClassOrNil notNil. |
|
841 |
nonMetaClass := aClass theNonMetaclass. |
|
842 |
metaClass := aClass theMetaclass. |
|
843 |
className := nonMetaClass name. |
|
844 |
||
845 |
(metaClass includesSelector:#main:) ifFalse:[ |
|
846 |
||
847 |
source := String streamContents:[:stream | |
|
848 |
stream nextPutAll: |
|
849 |
'main:argv |
|
850 |
self verboseInfo:''starting %1''. |
|
851 |
||
852 |
'. |
|
853 |
hasAplicationClass ifTrue: [ |
|
854 |
stream nextPutAll: |
|
855 |
' Smalltalk openDisplay. |
|
856 |
Display notNil ifTrue:[ |
|
857 |
Display exitOnLastClose:true. |
|
858 |
]. |
|
859 |
%1 open. |
|
860 |
'. |
|
861 |
]. |
|
862 |
]. |
|
863 |
||
864 |
anApplicationClassNameOrStartupClassName := hasAplicationClass |
|
865 |
ifTrue: [anApplicationClassOrNil name] |
|
866 |
ifFalse: [className.]. |
|
867 |
self |
|
868 |
compile:(source bindWith:anApplicationClassNameOrStartupClassName) |
|
869 |
forClass:metaClass |
|
870 |
inCategory:'startup'. |
|
871 |
]. |
|
872 |
self executeCollectedChangesNamed:('Add Startup Code to ' , className). |
|
873 |
! |
|
874 |
||
875 |
createTestCaseSampleCodeFor:aClass |
|
876 |
"create an (almost) empty testCase class" |
|
877 |
||
878 |
|nonMetaClass metaClass| |
|
879 |
||
880 |
nonMetaClass := aClass theNonMetaclass. |
|
881 |
metaClass := aClass theMetaclass. |
|
882 |
"/ className := nonMetaClass name. |
|
883 |
||
884 |
( nonMetaClass includesSelector:#test1 ) ifFalse:[ |
|
885 |
self |
|
886 |
compile: |
|
887 |
'test1 |
|
888 |
"This is a demonstration testCase - it is meant to be removed eventually. |
|
889 |
This testCase will PASS. |
|
890 |
Double click on the TestCase class or open a TestRunner to see me checking... |
|
891 |
- please add more methods like this..." |
|
892 |
||
893 |
|o| |
|
894 |
||
895 |
o := Array new:2. |
|
896 |
self assert: ( o size == 2 ). |
|
897 |
self should: [ o at:0 ] raise:Error. |
|
898 |
self shouldnt: [ o at:1 ] raise:Error. |
|
899 |
||
900 |
" |
|
901 |
self run:#test1 |
|
902 |
self new test1 |
|
903 |
" |
|
904 |
' |
|
905 |
forClass:nonMetaClass |
|
906 |
inCategory:'tests'. |
|
907 |
]. |
|
908 |
||
909 |
( nonMetaClass includesSelector:#test2 ) ifFalse:[ |
|
910 |
self |
|
911 |
compile: |
|
912 |
'test2 |
|
913 |
"This is a demonstration testCase - it is meant to be removed eventually.. |
|
914 |
This testCase WILL FAIL. |
|
915 |
Double click on the TestCase class or open a TestRunner to see me checking... |
|
916 |
- please add more methods like this..." |
|
917 |
||
918 |
|o| |
|
919 |
||
920 |
o := Array new:2. |
|
921 |
self assert: ( o size == 3 ). |
|
922 |
||
923 |
" |
|
924 |
self run:#test2 |
|
925 |
self new test2 |
|
926 |
" |
|
927 |
' |
|
928 |
forClass:nonMetaClass |
|
929 |
inCategory:'tests'. |
|
930 |
]. |
|
931 |
||
932 |
( nonMetaClass includesSelector:#test3 ) ifFalse:[ |
|
933 |
self |
|
934 |
compile: |
|
935 |
'test3 |
|
936 |
"This is a demonstration testCase - it is meant to be removed eventually.. |
|
937 |
This testCase WILL generate an ERROR. |
|
938 |
Double click on the TestCase class or open a TestRunner to see me checking... |
|
939 |
- please add more methods like this..." |
|
940 |
||
941 |
|o| |
|
942 |
||
943 |
o := Array new:2. |
|
944 |
self assert: ( o foo ). |
|
945 |
||
946 |
" |
|
947 |
self run:#test3 |
|
948 |
self new test3 |
|
949 |
" |
|
950 |
' |
|
951 |
forClass:nonMetaClass |
|
952 |
inCategory:'tests'. |
|
953 |
]. |
|
954 |
||
955 |
( nonMetaClass includesSelector:#setUp ) ifFalse:[ |
|
956 |
self |
|
957 |
compile: |
|
958 |
'setUp |
|
959 |
"common setup - invoked before testing." |
|
960 |
||
961 |
super setUp |
|
962 |
' |
|
963 |
forClass:nonMetaClass |
|
964 |
inCategory:'initialize / release'. |
|
965 |
]. |
|
966 |
||
967 |
( nonMetaClass includesSelector:#tearDown ) ifFalse:[ |
|
968 |
self |
|
969 |
compile: |
|
970 |
'tearDown |
|
971 |
"common cleanup - invoked after testing." |
|
972 |
||
973 |
super tearDown |
|
974 |
' |
|
975 |
forClass:nonMetaClass |
|
976 |
inCategory:'initialize / release'. |
|
977 |
] |
|
978 |
! |
|
979 |
||
980 |
createVisitorMethodsIn:visitedClass andVisitorClass:visitorClass |
|
981 |
"create acceptVisitor: in visitedClass and acceptXXX in visitorClass. (I'm tired of typing)" |
|
982 |
||
983 |
|sel| |
|
984 |
||
985 |
self assert:( visitedClass isMeta not ). |
|
986 |
self assert:( visitorClass isMeta not ). |
|
987 |
||
988 |
self startCollectChanges. |
|
989 |
||
990 |
sel := ('visit' , visitedClass nameWithoutPrefix , ':'). |
|
991 |
self createAcceptVisitorMethod:sel in:visitedClass. |
|
992 |
||
993 |
(visitorClass includesSelector:sel) ifFalse:[ |
|
994 |
self |
|
995 |
compile: |
|
996 |
(('%1anObject |
|
997 |
"dispatched back from the visited %2-object (visitor pattern)" |
|
998 |
||
999 |
"fall back to general object-case - please change as required" |
|
1000 |
||
1001 |
^ self visitObject:anObject |
|
1002 |
') bindWith:sel with:visitedClass nameWithoutPrefix asLowercaseFirst) |
|
1003 |
forClass:visitorClass |
|
1004 |
inCategory:'visiting'. |
|
1005 |
]. |
|
1006 |
||
1007 |
(visitorClass includesSelector:#'visitObject:') ifFalse:[ |
|
1008 |
self |
|
1009 |
compile: |
|
1010 |
('visitObject:anObject |
|
1011 |
"dispatched back from the visited objects (visitor pattern)" |
|
1012 |
||
1013 |
"general fallBack - please change as required" |
|
1014 |
||
1015 |
self halt:''not yet implemented'' |
|
1016 |
') |
|
1017 |
forClass:visitorClass |
|
1018 |
inCategory:'visiting'. |
|
1019 |
]. |
|
1020 |
||
1021 |
(visitorClass includesSelector:#'visit:') ifFalse:[ |
|
1022 |
self |
|
1023 |
compile: |
|
1024 |
('visit:anObject |
|
1025 |
"visit anObject (visitor pattern). |
|
1026 |
The object should call back one of my visitXXXX methods." |
|
1027 |
||
1028 |
^ anObject acceptVisitor:self |
|
1029 |
') |
|
1030 |
forClass:visitorClass |
|
1031 |
inCategory:'visiting'. |
|
1032 |
]. |
|
1033 |
||
1034 |
self executeCollectedChangesNamed:('Add Visitor Pattern'). |
|
1035 |
! |
|
1036 |
||
1037 |
createWebApplicationCodeFor:aClass |
|
1038 |
"create an empty webApplication framework" |
|
1039 |
||
1040 |
|nonMetaClass metaClass className txt| |
|
1041 |
||
1042 |
self startCollectChanges. |
|
1043 |
||
1044 |
nonMetaClass := aClass theNonMetaclass. |
|
1045 |
metaClass := aClass theMetaclass. |
|
1046 |
className := nonMetaClass name. |
|
1047 |
||
1048 |
(metaClass includesSelector:#pageSpec) ifFalse:[ |
|
1049 |
txt := self class initialPageSpecMethodSourceForWebApplications. |
|
1050 |
self |
|
1051 |
compile:(txt bindWith:className) |
|
1052 |
forClass:metaClass |
|
1053 |
inCategory:'page specs'. |
|
1054 |
]. |
|
1055 |
||
1056 |
self executeCollectedChangesNamed:('Add WebApplication Code for ' , className). |
|
1057 |
||
1058 |
"Modified: / 1.2.1998 / 16:10:03 / cg" |
|
1059 |
! |
|
1060 |
||
1061 |
createWebServiceCodeFor:aClass |
|
1062 |
"create an empty webService framework" |
|
1063 |
||
1064 |
|nonMetaClass metaClass className txt| |
|
1065 |
||
1066 |
self startCollectChanges. |
|
1067 |
||
1068 |
nonMetaClass := aClass theNonMetaclass. |
|
1069 |
metaClass := aClass theMetaclass. |
|
1070 |
className := nonMetaClass name. |
|
1071 |
||
9934
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1072 |
(nonMetaClass includesSelector:#page1:) ifFalse:[ |
9706 | 1073 |
txt := |
9934
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1074 |
'page1:aRequest |
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1075 |
"This is a sample page-generation method. |
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1076 |
This uses the simplest possible way to generate html: generating plain HTML. |
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1077 |
See page2 for a more structured example." |
9706 | 1078 |
|
1079 |
|response| |
|
1080 |
||
1081 |
response := aRequest response. |
|
1082 |
response nextPutLine:''<HTML>''. |
|
1083 |
response nextPutLine:'' <HEAD>''. |
|
1084 |
response nextPutLine:'' <TITLE>Hello</TITLE>''. |
|
1085 |
response nextPutLine:'' </HEAD>''. |
|
1086 |
response nextPutLine:'' <BODY>''. |
|
1087 |
response nextPutLine:'' <H1>Hello World !!</H1>''. |
|
1088 |
response nextPutLine:'' </BODY>''. |
|
1089 |
response nextPutLine:''</HTML>''. |
|
1090 |
'. |
|
1091 |
self |
|
1092 |
compile:txt |
|
1093 |
forClass:nonMetaClass |
|
9934
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1094 |
inCategory:'response generation - pages'. |
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1095 |
]. |
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1096 |
|
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1097 |
(nonMetaClass includesSelector:#page2:) ifFalse:[ |
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1098 |
txt := |
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1099 |
'page2:aRequest |
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1100 |
"This is a sample page-generation method. |
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1101 |
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
|
1102 |
Event better examples to follow..." |
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1103 |
|
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1104 |
|page| |
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1105 |
|
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1106 |
page := HTML::TreeBuilder newDocument. |
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1107 |
page |
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1108 |
head; |
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1109 |
title:''Hello''; |
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1110 |
headEnd; |
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1111 |
body; |
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1112 |
h1:''Hello World''; |
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1113 |
div; |
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1114 |
nlsText:''here is some text and ''; |
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1115 |
a; href:''page3''; |
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1116 |
text:''an anchor''; |
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1117 |
aEnd; |
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1118 |
text:'' and an image: ''; |
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1119 |
img:(httpServer graphicLinkIdFor:(ToolbarIconLibrary smiley_cool) expirationTimeDelta:30 seconds); |
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1120 |
divEnd; |
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1121 |
bodyEnd. |
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1122 |
|
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1123 |
aRequest reply:(page htmlString). |
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1124 |
'. |
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1125 |
self |
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1126 |
compile:txt |
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1127 |
forClass:nonMetaClass |
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1128 |
inCategory:'response generation - pages'. |
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1129 |
]. |
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1130 |
|
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1131 |
(nonMetaClass includesSelector:#page3:) ifFalse:[ |
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1132 |
txt := |
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1133 |
'page3:aRequest |
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1134 |
"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
|
1135 |
|
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1136 |
aRequest response |
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1137 |
contentType:''text/plain''; |
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1138 |
data:''This is some plain text, |
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1139 |
without any html formatting.'' |
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1140 |
'. |
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1141 |
self |
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1142 |
compile:txt |
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1143 |
forClass:nonMetaClass |
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1144 |
inCategory:'response generation - pages'. |
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1145 |
]. |
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1146 |
|
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1147 |
(nonMetaClass includesSelector:#process:) ifFalse:[ |
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1148 |
txt := |
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1149 |
'process:aRequest |
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1150 |
"This is the web services main processing method. |
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1151 |
It will be invoked for every incoming webBrowser-request. |
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1152 |
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
|
1153 |
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
|
1154 |
|
9935
5a0685d2ee90
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9934
diff
changeset
|
1155 |
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
|
1156 |
|
5a0685d2ee90
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9934
diff
changeset
|
1157 |
|whichPage methodName method| |
9934
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1158 |
|
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1159 |
whichPage := aRequest pathRelativeToService. |
9935
5a0685d2ee90
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9934
diff
changeset
|
1160 |
whichPage isEmpty ifTrue:[ whichPage := ''page1'' ]. |
5a0685d2ee90
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9934
diff
changeset
|
1161 |
|
5a0685d2ee90
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9934
diff
changeset
|
1162 |
"/ to prevent intruders from calling any method, check if it one |
5a0685d2ee90
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9934
diff
changeset
|
1163 |
"/ of my own methods, which is marked as a PAGE-method. |
5a0685d2ee90
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9934
diff
changeset
|
1164 |
|
5a0685d2ee90
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9934
diff
changeset
|
1165 |
methodName := (whichPage,'':'') asSymbol. |
5a0685d2ee90
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9934
diff
changeset
|
1166 |
method := self class compiledMethodAt:methodName. |
5a0685d2ee90
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9934
diff
changeset
|
1167 |
"/ is there such a method ? |
5a0685d2ee90
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9934
diff
changeset
|
1168 |
method notNil ifTrue:[ |
5a0685d2ee90
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9934
diff
changeset
|
1169 |
"/ and it is marked as being a WebPage-generator ? |
5a0685d2ee90
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9934
diff
changeset
|
1170 |
(method hasResource:#''PAGE'') ifTrue:[ |
5a0685d2ee90
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9934
diff
changeset
|
1171 |
self perform:methodName with:aRequest. |
5a0685d2ee90
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9934
diff
changeset
|
1172 |
^ self |
5a0685d2ee90
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9934
diff
changeset
|
1173 |
]. |
9934
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1174 |
]. |
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1175 |
aRequest reportNotFound:''No such page in this service''. |
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1176 |
'. |
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1177 |
self |
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1178 |
compile:txt |
e8885f059bea
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9756
diff
changeset
|
1179 |
forClass:nonMetaClass |
9706 | 1180 |
inCategory:'response generation'. |
1181 |
]. |
|
1182 |
||
1183 |
(metaClass includesSelector:#linkName) ifFalse:[ |
|
1184 |
txt := |
|
1185 |
'linkName |
|
1186 |
"return the default linkName path (with slash)." |
|
1187 |
||
1188 |
^ ''/NewService'' |
|
1189 |
'. |
|
1190 |
self |
|
1191 |
compile:txt |
|
1192 |
forClass:metaClass |
|
1193 |
inCategory:'defaults'. |
|
1194 |
]. |
|
1195 |
||
1196 |
(metaClass includesSelector:#settingsApplicationClass) ifFalse:[ |
|
1197 |
txt := |
|
1198 |
'settingsApplicationClass |
|
1199 |
"a SettingsApplication class - or nil (used in the settings dialog if non-nil)." |
|
1200 |
||
1201 |
^ nil |
|
1202 |
'. |
|
1203 |
self |
|
1204 |
compile:txt |
|
1205 |
forClass:metaClass |
|
1206 |
inCategory:'defaults'. |
|
1207 |
]. |
|
1208 |
||
1209 |
||
1210 |
self executeCollectedChangesNamed:('Add WebService Code for ' , className). |
|
1211 |
||
9935
5a0685d2ee90
changed: #createWebServiceCodeFor:
Claus Gittinger <cg@exept.de>
parents:
9934
diff
changeset
|
1212 |
"Modified: / 02-06-2011 / 12:51:15 / cg" |
9706 | 1213 |
! |
1214 |
||
1215 |
createWidgetCodeFor:aClass |
|
1216 |
"create usually required widget code (redraw, model update, event handling)" |
|
1217 |
||
1218 |
|nonMetaClass metaClass className compileTemplateAction| |
|
1219 |
||
1220 |
self startCollectChanges. |
|
1221 |
||
1222 |
nonMetaClass := aClass theNonMetaclass. |
|
1223 |
metaClass := aClass theMetaclass. |
|
1224 |
className := nonMetaClass name. |
|
1225 |
||
1226 |
compileTemplateAction := |
|
1227 |
[:selector :templateSelector :category | |
|
1228 |
(nonMetaClass includesSelector:selector) ifFalse:[ |
|
1229 |
|txt| |
|
1230 |
||
1231 |
txt := self perform:templateSelector. |
|
1232 |
self |
|
1233 |
compile:txt |
|
1234 |
forClass:nonMetaClass |
|
1235 |
inCategory:category. |
|
1236 |
] |
|
1237 |
]. |
|
1238 |
||
1239 |
#( |
|
1240 |
#'initialize' #code_forWidget_initialize 'initialization & release' |
|
1241 |
#'update:with:from:' #code_forWidget_update 'change & update' |
|
1242 |
#'redrawX:y:width:height:' #code_forWidget_redraw 'drawing' |
|
1243 |
#'buttonPress:x:y:' #code_forWidget_buttonPress 'event handling' |
|
1244 |
#'keyPress:x:y:' #code_forWidget_keyPress 'event handling' |
|
1245 |
#'sizeChanged:' #code_forWidget_sizeChanged 'event handling' |
|
1246 |
) inGroupsOf:3 do:compileTemplateAction. |
|
1247 |
||
1248 |
self executeCollectedChangesNamed:('Add Widget Code for ' , className). |
|
1249 |
! ! |
|
1250 |
||
1251 |
!SmalltalkCodeGeneratorTool methodsFor:'code generation-basic'! |
|
1252 |
||
1253 |
createAccessMethodsFor:aCollectionOfVarNames in:aClass withChange:withChange asValueHolder:asValueHolder readersOnly:readersOnly writersOnly:writersOnly lazyInitialization:lazyInitialization |
|
1254 |
"workhorse for creating access methods for instvars." |
|
1255 |
||
1256 |
|classesClassVars generateCommentsForSetters generateCommentsForGetters| |
|
1257 |
||
1258 |
self startCollectChanges. |
|
1259 |
||
1260 |
generateCommentsForSetters := userPreferences generateCommentsForSetters. |
|
1261 |
generateCommentsForGetters := userPreferences generateCommentsForGetters. |
|
1262 |
||
1263 |
classesClassVars := aClass theNonMetaclass allClassVarNames. |
|
1264 |
||
1265 |
aCollectionOfVarNames do:[:name | |
|
1266 |
|source varType methodName defaultMethodName argName| |
|
1267 |
||
1268 |
varType := (classesClassVars includes:name) |
|
1269 |
ifTrue:['static'] |
|
1270 |
ifFalse:[ |
|
1271 |
(aClass isMeta ifTrue:['classInstVar'] ifFalse:['instance'])]. |
|
1272 |
||
1273 |
methodName := name. |
|
1274 |
name isUppercaseFirst ifTrue:[ |
|
10371
c35aa5f6abf6
changed: #createAccessMethodsFor:in:withChange:asValueHolder:readersOnly:writersOnly:lazyInitialization:
Claus Gittinger <cg@exept.de>
parents:
9960
diff
changeset
|
1275 |
(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
|
1276 |
methodName := methodName asLowercaseFirst. |
c35aa5f6abf6
changed: #createAccessMethodsFor:in:withChange:asValueHolder:readersOnly:writersOnly:lazyInitialization:
Claus Gittinger <cg@exept.de>
parents:
9960
diff
changeset
|
1277 |
] |
9706 | 1278 |
]. |
1279 |
argName := 'something'. |
|
1280 |
||
1281 |
"/ the GETTER |
|
1282 |
writersOnly ifFalse:[ |
|
1283 |
lazyInitialization ifTrue:[ |
|
1284 |
defaultMethodName := 'default' , name asUppercaseFirst. |
|
1285 |
]. |
|
1286 |
||
1287 |
"check, if method is not already present" |
|
1288 |
(aClass includesSelector:(methodName asSymbol)) ifFalse:[ |
|
1289 |
asValueHolder ifTrue:[ |
|
1290 |
source := methodName , '\'. |
|
1291 |
generateComments ifTrue:[ |
|
1292 |
source := source , ' "return/create the ''%2'' value holder (automatically generated)"\\'. |
|
1293 |
]. |
|
1294 |
source := source , ' %2 isNil ifTrue:[\'. |
|
1295 |
lazyInitialization ifTrue:[ |
|
1296 |
source := source |
|
1297 |
, ' %2 := self class %3 asValue.\'. |
|
1298 |
] ifFalse:[ |
|
1299 |
source := source |
|
1300 |
, ' %2 := ValueHolder new.\'. |
|
1301 |
]. |
|
1302 |
||
1303 |
withChange ifTrue:[ |
|
1304 |
source := source |
|
1305 |
, ' %2 addDependent:self.\'. |
|
1306 |
]. |
|
1307 |
source := source |
|
1308 |
, ' ].\' |
|
1309 |
, ' ^ %2'. |
|
1310 |
] ifFalse:[ |
|
1311 |
source := methodName , '\'. |
|
1312 |
lazyInitialization ifTrue:[ |
|
1313 |
generateCommentsForGetters ifTrue:[ |
|
1314 |
source := source , ' "return the %1 instance variable ''%2'' with lazy instance creation (automatically generated)"\\'. |
|
1315 |
]. |
|
1316 |
source := source |
|
1317 |
, ' %2 isNil ifTrue:[\' |
|
1318 |
, ' %2 := self class %3.\' |
|
1319 |
, ' ].\' |
|
1320 |
, ' ^ %2'. |
|
1321 |
] ifFalse:[ |
|
1322 |
generateCommentsForGetters ifTrue:[ |
|
1323 |
source := source , ' "return the %1 instance variable ''%2'' (automatically generated)"\\'. |
|
1324 |
]. |
|
1325 |
source := source |
|
1326 |
, ' ^ %2'. |
|
1327 |
]. |
|
1328 |
]. |
|
1329 |
source := (source bindWith:varType with:name with:defaultMethodName) withCRs. |
|
1330 |
self compile:source forClass:aClass inCategory:(asValueHolder ifTrue:['aspects'] ifFalse:['accessing']). |
|
1331 |
] ifTrue:[ |
|
1332 |
Transcript showCR:'method ''', methodName , ''' already present' |
|
1333 |
]. |
|
1334 |
||
1335 |
"/ default for lazy on class side |
|
1336 |
lazyInitialization ifTrue:[ |
|
1337 |
(aClass theMetaclass includesSelector:(defaultMethodName asSymbol)) ifFalse:[ |
|
1338 |
source := defaultMethodName , '\'. |
|
1339 |
generateComments ifTrue:[ |
|
1340 |
source := source , ' "default value for the ''%2'' instance variable (automatically generated)"\\'. |
|
1341 |
]. |
|
1342 |
source := source |
|
1343 |
, ' self shouldImplement.\' |
|
1344 |
, ' ^ nil.'. |
|
1345 |
source := (source bindWith:varType with:name) withCRs. |
|
1346 |
self compile:source forClass:aClass theMetaclass inCategory:'defaults'. |
|
1347 |
]. |
|
1348 |
]. |
|
1349 |
]. |
|
1350 |
||
1351 |
"/ the SETTER |
|
1352 |
readersOnly ifFalse:[ |
|
1353 |
(aClass includesSelector:((methodName , ':') asSymbol)) ifFalse:[ |
|
1354 |
((methodName size > 2) and:[ (methodName startsWith:'is') and:[ (methodName at:3) isUppercase ]]) |
|
1355 |
ifTrue:[ |
|
1356 |
argName := 'aBoolean' |
|
1357 |
]. |
|
1358 |
asValueHolder ifTrue:[ |
|
1359 |
source := methodName , ':%3\'. "/ argName |
|
1360 |
generateComments ifTrue:[ |
|
1361 |
source := source , ' "set the ''%2'' value holder' , ' (automatically generated)"\\'. |
|
1362 |
]. |
|
1363 |
withChange ifTrue:[ |
|
1364 |
source := source |
|
1365 |
, ' |oldValue newValue|\\' |
|
1366 |
, ' %2 notNil ifTrue:[\' |
|
1367 |
, ' oldValue := %2 value.\' |
|
1368 |
, ' %2 removeDependent:self.\' |
|
1369 |
, ' ].\' |
|
1370 |
, ' %2 := %3.\' "/ argName |
|
1371 |
, ' %2 notNil ifTrue:[\' |
|
1372 |
, ' %2 addDependent:self.\' |
|
1373 |
, ' ].\' |
|
1374 |
, ' newValue := %2 value.\' |
|
1375 |
, ' oldValue ~~ newValue ifTrue:[\' |
|
1376 |
, ' self update:#value with:newValue from:%2.\' |
|
1377 |
, ' ].\' |
|
1378 |
] ifFalse:[ |
|
1379 |
source := source |
|
1380 |
, ' %2 := %3.'. "/ argName |
|
1381 |
]. |
|
1382 |
] ifFalse:[ |
|
1383 |
source := methodName , ':%3\'. "/ argName |
|
1384 |
withChange ifTrue:[ |
|
1385 |
generateComments ifTrue:[ |
|
1386 |
source := source , ' "set the value of the %1 variable ''%2'''. |
|
1387 |
source := source , ' and send a change notification (automatically generated)"\\'. |
|
1388 |
]. |
|
1389 |
source := source |
|
1390 |
, ' (%2 ~~ %3) ifTrue:[\' |
|
1391 |
, ' %2 := %3.\' "/ argName |
|
1392 |
, ' self changed:#%2.\' |
|
1393 |
, ' ].\'. |
|
1394 |
] ifFalse:[ |
|
1395 |
generateCommentsForSetters ifTrue:[ |
|
1396 |
source := source , ' "set the value of the %1 variable ''%2'''. |
|
1397 |
source := source , ' (automatically generated)"\\'. |
|
1398 |
]. |
|
1399 |
source := source |
|
1400 |
, ' %2 := %3.'. "/ argName |
|
1401 |
]. |
|
1402 |
]. |
|
1403 |
source := (source bindWith:varType with:name with:argName) withCRs. |
|
1404 |
self |
|
1405 |
compile:source |
|
1406 |
forClass:aClass |
|
1407 |
inCategory:(asValueHolder ifTrue:['aspects'] ifFalse:['accessing']). |
|
1408 |
] ifTrue:[ |
|
1409 |
Transcript showCR:'method ''', methodName , ':'' already present' |
|
1410 |
]. |
|
1411 |
]. |
|
1412 |
]. |
|
1413 |
||
1414 |
self executeCollectedChangesNamed:('Add Accessors'). |
|
10371
c35aa5f6abf6
changed: #createAccessMethodsFor:in:withChange:asValueHolder:readersOnly:writersOnly:lazyInitialization:
Claus Gittinger <cg@exept.de>
parents:
9960
diff
changeset
|
1415 |
|
c35aa5f6abf6
changed: #createAccessMethodsFor:in:withChange:asValueHolder:readersOnly:writersOnly:lazyInitialization:
Claus Gittinger <cg@exept.de>
parents:
9960
diff
changeset
|
1416 |
"Modified: / 21-07-2011 / 15:19:25 / cg" |
9706 | 1417 |
! |
1418 |
||
1419 |
createCollectionAccessMethodsFor:aCollectionOfVarNames in:aClass withChange:withChange |
|
1420 |
|classesClassVars| |
|
1421 |
||
1422 |
self startCollectChanges. |
|
1423 |
||
1424 |
classesClassVars := aClass theNonMetaclass allClassVarNames. |
|
1425 |
||
1426 |
aCollectionOfVarNames do:[:name | |
|
1427 |
|source varType methodNameBase methodName defaultMethodName| |
|
1428 |
||
1429 |
varType := (classesClassVars includes:name) |
|
1430 |
ifTrue:['static'] |
|
1431 |
ifFalse:[ |
|
1432 |
(aClass isMeta ifTrue:['classInstVar'] ifFalse:['instance'])]. |
|
1433 |
||
1434 |
methodNameBase := name asUppercaseFirst. |
|
1435 |
(methodNameBase endsWith:'s') ifTrue:[ |
|
1436 |
methodNameBase := methodNameBase copyWithoutLast:1. |
|
1437 |
]. |
|
1438 |
methodName := 'add' , methodNameBase, ':'. |
|
1439 |
||
1440 |
"check, if method is not already present" |
|
1441 |
(aClass includesSelector:(methodName asSymbol)) ifFalse:[ |
|
1442 |
source := methodName , 'a%1\'. |
|
1443 |
generateComments ifTrue:[ |
|
1444 |
source := source , ' "add a ',methodNameBase,'"\\'. |
|
1445 |
]. |
|
1446 |
source := source , ' %2 isNil ifTrue:[\'. |
|
1447 |
source := source |
|
1448 |
, ' %2 := OrderedCollection new.\'. |
|
1449 |
source := source |
|
1450 |
, ' ].\' |
|
1451 |
, ' %2 add: a%1'. |
|
1452 |
source := (source bindWith:methodNameBase with:name) withCRs. |
|
1453 |
self compile:source forClass:aClass inCategory:'accessing'. |
|
1454 |
] ifTrue:[ |
|
1455 |
Transcript showCR:'method ''', methodName , ''' already present' |
|
1456 |
]. |
|
1457 |
||
1458 |
methodName := 'remove' , methodNameBase, ':'. |
|
1459 |
||
1460 |
"check, if method is not already present" |
|
1461 |
(aClass includesSelector:(methodName asSymbol)) ifFalse:[ |
|
1462 |
source := methodName , 'a%1\'. |
|
1463 |
generateComments ifTrue:[ |
|
1464 |
source := source , ' "remove a ',methodNameBase,'"\\'. |
|
1465 |
]. |
|
1466 |
source := source |
|
1467 |
, ' %2 remove: a%1'. |
|
1468 |
source := (source bindWith:methodNameBase with:name) withCRs. |
|
1469 |
self compile:source forClass:aClass inCategory:'accessing'. |
|
1470 |
] ifTrue:[ |
|
1471 |
Transcript showCR:'method ''', methodName , ''' already present' |
|
1472 |
]. |
|
1473 |
]. |
|
1474 |
||
1475 |
self |
|
1476 |
createAccessMethodsFor:aCollectionOfVarNames |
|
1477 |
in:aClass |
|
1478 |
withChange:withChange |
|
1479 |
asValueHolder:false |
|
1480 |
readersOnly:true |
|
1481 |
writersOnly:false |
|
1482 |
lazyInitialization:false. |
|
1483 |
||
1484 |
self executeCollectedChangesNamed:('Add Collection Access'). |
|
1485 |
||
1486 |
"Created: / 04-02-2007 / 15:52:31 / cg" |
|
1487 |
! |
|
1488 |
||
1489 |
createValueHoldersFor:aCollectionOfVarNames in:aClass lazyInitialization:lazyInitialization |
|
1490 |
"workhorse for creating access methods for instvars." |
|
1491 |
||
1492 |
|nonMetaClass metaClass classesClassVars generateCommentsForSetters generateCommentsForGetters| |
|
1493 |
||
1494 |
nonMetaClass := aClass theNonMetaclass. |
|
1495 |
metaClass := aClass theMetaclass. |
|
1496 |
||
1497 |
self startCollectChanges. |
|
1498 |
||
1499 |
generateCommentsForSetters := userPreferences generateCommentsForSetters. |
|
1500 |
generateCommentsForGetters := userPreferences generateCommentsForGetters. |
|
1501 |
||
1502 |
classesClassVars := nonMetaClass allClassVarNames. |
|
1503 |
||
1504 |
aCollectionOfVarNames do:[:name | |
|
1505 |
|source varType methodName holderMethodName defaultMethodName| |
|
1506 |
||
1507 |
holderMethodName := name. |
|
1508 |
name isUppercaseFirst ifTrue:[ |
|
1509 |
holderMethodName := holderMethodName asLowercaseFirst. |
|
1510 |
]. |
|
1511 |
(holderMethodName endsWith:'Holder') ifTrue:[ |
|
1512 |
methodName := holderMethodName copyWithoutLast:6. |
|
1513 |
] ifFalse:[ |
|
1514 |
methodName := holderMethodName. |
|
1515 |
holderMethodName := methodName , 'Holder'. |
|
1516 |
]. |
|
1517 |
||
1518 |
methodName notNil ifTrue:[ |
|
1519 |
(metaClass includesSelector:(methodName asSymbol)) ifFalse:[ |
|
1520 |
source := '%1\'. |
|
1521 |
generateComments ifTrue:[ |
|
1522 |
source := source , ' "return the value in ''%2''"\\'. |
|
1523 |
]. |
|
1524 |
source := source , ' ^ self %2 value'. |
|
1525 |
source := (source bindWith:methodName with:holderMethodName) withCRs. |
|
1526 |
self compile:source forClass:nonMetaClass inCategory:('accessing'). |
|
1527 |
] ifTrue:[ |
|
1528 |
Transcript showCR:'method ''', methodName , ''' already present' |
|
1529 |
]. |
|
1530 |
||
1531 |
(metaClass includesSelector:((methodName , ':') asSymbol)) ifFalse:[ |
|
1532 |
source := '%1: newValue\'. |
|
1533 |
generateComments ifTrue:[ |
|
1534 |
source := source , ' "set the value in ''%2''"\\'. |
|
1535 |
]. |
|
1536 |
source := source , ' self %2 value: newValue'. |
|
1537 |
source := (source bindWith:methodName with:holderMethodName) withCRs. |
|
1538 |
self compile:source forClass:nonMetaClass inCategory:('accessing'). |
|
1539 |
] ifTrue:[ |
|
1540 |
Transcript showCR:'method ''', methodName , ':'' already present' |
|
1541 |
]. |
|
1542 |
]. |
|
1543 |
(metaClass includesSelector:(holderMethodName asSymbol)) ifFalse:[ |
|
1544 |
source := '%1\'. |
|
1545 |
generateComments ifTrue:[ |
|
1546 |
source := source , ' "return/create the valueHolder ''%1''"\\'. |
|
1547 |
]. |
|
1548 |
source := source , ' %1 isNil ifTrue:[\'. |
|
1549 |
source := source , ' %1 := ValueHolder with:nil "defaultValue here".\'. |
|
1550 |
source := source , ' ].\'. |
|
1551 |
source := source , ' ^ %1\'. |
|
1552 |
source := (source bindWith:holderMethodName) withCRs. |
|
1553 |
self compile:source forClass:nonMetaClass inCategory:('accessing'). |
|
1554 |
] ifTrue:[ |
|
1555 |
Transcript showCR:'method ''', methodName , ''' already present' |
|
1556 |
]. |
|
1557 |
]. |
|
1558 |
||
1559 |
self executeCollectedChangesNamed:('Add ValueHolder'). |
|
1560 |
! ! |
|
1561 |
||
1562 |
!SmalltalkCodeGeneratorTool methodsFor:'code generation-individual methods'! |
|
1563 |
||
1564 |
createAcceptVisitorMethod:selector in:aClass |
|
1565 |
"create an acceptVisitor: method |
|
1566 |
(I'm tired of typing)" |
|
1567 |
||
1568 |
self assert:( aClass isMeta not ). |
|
1569 |
||
1570 |
(aClass includesSelector:#'acceptVisitor:') ifFalse:[ |
|
1571 |
self |
|
1572 |
compile: |
|
1573 |
(('acceptVisitor:aVisitor |
|
1574 |
"Double dispatch back to the visitor, passing my type encoded in |
|
1575 |
the selector (visitor pattern)" |
|
1576 |
||
1577 |
"stub code automatically generated - please change if required" |
|
1578 |
||
1579 |
^ aVisitor %1self |
|
1580 |
') bindWith:selector) |
|
1581 |
forClass:aClass |
|
1582 |
inCategory:'visiting'. |
|
1583 |
] |
|
1584 |
! |
|
1585 |
||
1586 |
createAcceptVisitorMethodIn:aClass |
|
1587 |
"create an acceptVisitor: method |
|
1588 |
(I'm tired of typing)" |
|
1589 |
||
1590 |
self |
|
1591 |
createAcceptVisitorMethod:('visit' , aClass nameWithoutPrefix , ':') asSymbol |
|
1592 |
in:aClass |
|
1593 |
! |
|
1594 |
||
1595 |
createCopyrightMethodFor:copyRightText for:aClass |
|
1596 |
"add copyright method containing text, |
|
1597 |
but only if not already present." |
|
1598 |
||
1599 |
|txt| |
|
1600 |
||
1601 |
(aClass includesSelector:#copyright) ifFalse:[ |
|
1602 |
copyRightText notNil ifTrue:[ |
|
1603 |
txt := copyRightText bindWith:(Date today year). |
|
1604 |
self compile: |
|
1605 |
'copyright |
|
1606 |
" |
|
1607 |
' , txt , ' |
|
1608 |
" |
|
1609 |
' forClass:aClass |
|
1610 |
inCategory:'documentation'. |
|
1611 |
] |
|
1612 |
]. |
|
1613 |
! |
|
1614 |
||
1615 |
createDocumentationMethodFor:aClass |
|
1616 |
"add documentation method containing doc template |
|
1617 |
but only if not already present." |
|
1618 |
||
1619 |
|metaClass nonMetaClass userName loginName hostName emailAddress code existingComment| |
|
1620 |
||
1621 |
metaClass := aClass theMetaclass. |
|
1622 |
nonMetaClass := aClass theNonMetaclass. |
|
1623 |
||
1624 |
(metaClass includesSelector:#documentation) ifFalse:[ |
|
1625 |
existingComment := nonMetaClass comment. |
|
1626 |
existingComment isEmptyOrNil ifTrue:[ |
|
1627 |
(nonMetaClass isSubclassOf:HTTPService) ifTrue:[ |
|
1628 |
existingComment := ' [start Server with:] |
|
1629 |
HTTPServer startServerOnPort:8080 |
|
1630 |
||
1631 |
[start with:] |
|
1632 |
(self new) |
|
1633 |
registerServiceOn:(HTTPServer runningServerOnPort:8080)'. |
|
1634 |
]. |
|
1635 |
]. |
|
1636 |
||
1637 |
userName := OperatingSystem getFullUserName. |
|
1638 |
loginName := OperatingSystem getLoginName. |
|
1639 |
hostName := OperatingSystem getHostName. |
|
1640 |
emailAddress := loginName , '@' , hostName. |
|
1641 |
||
9960 | 1642 |
|
1643 |
||
9706 | 1644 |
"/ ugly; should ask the class for that |
1645 |
metaClass isJavaScriptMetaclass ifTrue:[ |
|
1646 |
code := |
|
1647 |
'function documentation() { |
|
1648 |
/* |
|
1649 |
' , (existingComment ? ' documentation to be added.') , ' |
|
1650 |
||
1651 |
[author:] |
|
9960 | 1652 |
' ", userName |
1653 |
, ' (' , emailAddress , ')' " |
|
1654 |
, UserPreferences current historyManagerSignature , ' |
|
9706 | 1655 |
|
1656 |
[instance variables:] |
|
1657 |
||
1658 |
[class variables:] |
|
1659 |
||
1660 |
[see also:] |
|
1661 |
||
1662 |
*/ |
|
1663 |
} |
|
1664 |
' |
|
1665 |
] ifFalse:[ |
|
1666 |
code:= |
|
1667 |
'documentation |
|
1668 |
" |
|
1669 |
' , (existingComment ? ' documentation to be added.') , ' |
|
1670 |
||
1671 |
[author:] |
|
9960 | 1672 |
' ", userName |
1673 |
, ' (' , emailAddress , ')' " |
|
1674 |
, UserPreferences current historyManagerSignature , ' |
|
9706 | 1675 |
|
1676 |
[instance variables:] |
|
1677 |
||
1678 |
[class variables:] |
|
1679 |
||
1680 |
[see also:] |
|
1681 |
||
1682 |
" |
|
1683 |
' |
|
1684 |
]. |
|
1685 |
||
1686 |
self |
|
1687 |
compile:code |
|
1688 |
forClass:metaClass |
|
1689 |
inCategory:'documentation'. |
|
1690 |
]. |
|
1691 |
||
1692 |
"Modified: / 24-11-2006 / 15:54:27 / cg" |
|
9960 | 1693 |
"Modified: / 04-02-2011 / 08:24:31 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
9706 | 1694 |
! |
1695 |
||
1696 |
createExamplesMethodFor:aClass |
|
1697 |
"add examples method containing examples template |
|
1698 |
but only if not already present." |
|
1699 |
||
1700 |
|nonMetaclass fragment| |
|
1701 |
||
1702 |
nonMetaclass := aClass theNonMetaclass. |
|
1703 |
||
1704 |
(nonMetaclass isSubclassOf:View) ifTrue:[ |
|
1705 |
self createExamplesMethodForViewClass:aClass. |
|
1706 |
^ self |
|
1707 |
]. |
|
1708 |
||
1709 |
(nonMetaclass isSubclassOf:ApplicationModel) ifFalse:[ |
|
1710 |
^ self |
|
1711 |
]. |
|
1712 |
||
1713 |
(aClass includesSelector:#examples) ifFalse:[ |
|
1714 |
(nonMetaclass isSubclassOf:ApplicationModel) ifTrue:[ |
|
1715 |
fragment := ' Starting the application: |
|
1716 |
[exBegin] |
|
1717 |
' , nonMetaclass name , ' open |
|
1718 |
||
1719 |
[exEnd] |
|
1720 |
' |
|
1721 |
] ifFalse:[ |
|
1722 |
fragment := '' |
|
1723 |
]. |
|
1724 |
||
1725 |
self |
|
1726 |
compile: |
|
1727 |
'examples |
|
1728 |
" |
|
1729 |
' , fragment , ' |
|
1730 |
more examples to be added: |
|
1731 |
[exBegin] |
|
1732 |
... add code fragment for |
|
1733 |
... executable example here ... |
|
1734 |
[exEnd] |
|
1735 |
" |
|
1736 |
' |
|
1737 |
forClass:aClass |
|
1738 |
inCategory:'documentation'. |
|
1739 |
]. |
|
1740 |
! |
|
1741 |
||
1742 |
createImageSpecMethodFor:anImage comment:comment in:aClass selector:sel |
|
1743 |
|imageStoreStream mthd imageKey category| |
|
1744 |
||
1745 |
anImage storeOn: (imageStoreStream := WriteStream on: ''). |
|
1746 |
||
1747 |
"/ if that method already exists, do not overwrite the category |
|
1748 |
category := 'image specs'. |
|
1749 |
(mthd := aClass compiledMethodAt:sel) notNil ifTrue:[ |
|
1750 |
category := mthd category. |
|
1751 |
]. |
|
1752 |
||
1753 |
imageKey := (aClass name, ' ', sel) asSymbol. |
|
1754 |
Icon constantNamed: imageKey put:nil. |
|
9960 | 1755 |
self |
9706 | 1756 |
compile: ((sel, |
1757 |
'\', comment, |
|
1758 |
'\\' , |
|
1759 |
' "\', |
|
1760 |
' self ' , sel , ' inspect\', |
|
1761 |
' ImageEditor openOnClass:self andSelector:#', sel, '\', |
|
1762 |
' Icon flushCachedIcons', |
|
1763 |
'\ "', |
|
1764 |
'\\', |
|
1765 |
' <resource: #image>', |
|
1766 |
'\\', |
|
1767 |
' ^Icon\') withCRs, |
|
1768 |
' constantNamed:''', imageKey, '''\' withCRs, |
|
1769 |
' ifAbsentPut:[', imageStoreStream contents, ']') |
|
9960 | 1770 |
forClass:aClass |
1771 |
inCategory: category. |
|
1772 |
||
1773 |
"Modified: / 01-07-2011 / 12:31:12 / cg" |
|
9706 | 1774 |
! |
1775 |
||
1776 |
createInitialHistoryMethodFor:aClass |
|
1777 |
"add history method containing created-entry |
|
1778 |
but only if not already present." |
|
1779 |
||
1780 |
|code| |
|
1781 |
||
1782 |
(aClass includesSelector:#history) ifFalse:[ |
|
1783 |
HistoryManager notNil ifTrue:[ |
|
1784 |
code := HistoryManager codeForInitialHistoryMethodIn:aClass. |
|
1785 |
self |
|
1786 |
compile:code |
|
1787 |
forClass:aClass |
|
1788 |
inCategory:'documentation'. |
|
1789 |
]. |
|
1790 |
]. |
|
1791 |
! |
|
1792 |
||
1793 |
createInstanceCreationMethodWithSetupFor:selector category:category in:aMetaClass |
|
1794 |
"add an inst-creation method" |
|
1795 |
||
1796 |
|template instMthd argNames| |
|
1797 |
||
1798 |
(aMetaClass includesSelector:selector) ifFalse:[ |
|
1799 |
instMthd := aMetaClass theNonMetaclass compiledMethodAt:selector. |
|
1800 |
(instMthd notNil |
|
1801 |
and:[ (argNames := instMthd methodArgNames) notEmptyOrNil ]) |
|
1802 |
ifTrue:[ |
|
1803 |
template := Parser methodSpecificationForSelector:selector argNames:argNames. |
|
1804 |
] ifFalse:[ |
|
1805 |
template := Parser methodSpecificationForSelector:selector. |
|
1806 |
]. |
|
1807 |
||
1808 |
self |
|
1809 |
compile: |
|
1810 |
template , ' |
|
1811 |
^ self new ' , template , ' |
|
1812 |
' |
|
1813 |
forClass:aMetaClass |
|
1814 |
inCategory:category. |
|
1815 |
]. |
|
1816 |
! |
|
1817 |
||
1818 |
createMultiSetterMethodFor:aCollectionOfVarNames in:aClass |
|
1819 |
"create a multi-setter method for instvars." |
|
1820 |
||
1821 |
|source| |
|
1822 |
||
1823 |
source := ''. |
|
1824 |
aCollectionOfVarNames do:[:eachVar | |
|
1825 |
source := source , (eachVar , ':' , eachVar , 'Arg '). |
|
1826 |
]. |
|
1827 |
source := source , Character cr. |
|
1828 |
(userPreferences generateCommentsForSetters) ifTrue:[ |
|
1829 |
source := source , (' "set instance variables"' , Character cr , Character cr). |
|
1830 |
]. |
|
1831 |
aCollectionOfVarNames do:[:eachVar | |
|
1832 |
source := source , (' ' , eachVar , ' := ' , eachVar , 'Arg.' , Character cr). |
|
1833 |
]. |
|
1834 |
self compile:source forClass:aClass inCategory:'accessing'. |
|
1835 |
! |
|
1836 |
||
1837 |
createSubclassResponsibilityMethodFor:aSelector category:cat in:aClass |
|
1838 |
"add a subclassResponsibility method; |
|
1839 |
but only if not already present." |
|
1840 |
||
1841 |
(aClass includesSelector:aSelector) ifFalse:[ |
|
1842 |
||
1843 |
self compile: |
|
1844 |
(Method methodDefinitionTemplateForSelector:aSelector) , |
|
1845 |
' |
|
1846 |
"raise an error: must be redefined in concrete subclass(es)" |
|
1847 |
||
1848 |
^ self subclassResponsibility |
|
1849 |
' |
|
1850 |
forClass:aClass |
|
1851 |
inCategory:cat. |
|
1852 |
]. |
|
1853 |
! |
|
1854 |
||
1855 |
createUpdateMethodIn:aClass |
|
1856 |
"create an update:with:from:-method |
|
1857 |
(I'm tired of typing)" |
|
1858 |
||
1859 |
|code| |
|
1860 |
||
1861 |
(aClass includesSelector:#'update:with:from:') ifFalse:[ |
|
1862 |
generateComments ifFalse:[ |
|
1863 |
code := |
|
1864 |
'update:something with:aParameter from:changedObject |
|
1865 |
super update:something with:aParameter from:changedObject |
|
1866 |
' |
|
1867 |
] ifTrue:[ |
|
1868 |
code := |
|
1869 |
'update:something with:aParameter from:changedObject |
|
1870 |
"Invoked when an object that I depend upon sends a change notification." |
|
1871 |
||
1872 |
"stub code automatically generated - please change as required" |
|
1873 |
||
1874 |
"/ changedObject == someOfMyValueHolders ifTrue:[ |
|
1875 |
"/ self doSomethingApropriate. |
|
1876 |
"/ ^ self. |
|
1877 |
"/ ]. |
|
1878 |
super update:something with:aParameter from:changedObject |
|
1879 |
' |
|
1880 |
]. |
|
1881 |
||
1882 |
self |
|
1883 |
compile:code |
|
1884 |
forClass:aClass |
|
1885 |
inCategory:'change & update'. |
|
1886 |
] |
|
1887 |
! |
|
1888 |
||
1889 |
createVersionMethodFor:aClass |
|
1890 |
<resource: #obsolete> |
|
1891 |
"add version method containing RCS template |
|
1892 |
but only if not already present and its not a private class." |
|
1893 |
||
1894 |
|code| |
|
1895 |
||
1896 |
self obsoleteMethodWarning. |
|
1897 |
||
1898 |
aClass isPrivate ifFalse:[ |
|
1899 |
(aClass includesSelector:#version) ifFalse:[ |
|
1900 |
"/ ugly; should ask the class for that |
|
1901 |
aClass isJavaScriptClass ifTrue:[ |
|
1902 |
code:= ('function version() {\ return ("$' , 'Header$");\}') withCRs |
|
1903 |
] ifFalse:[ |
|
1904 |
code:= ('version\ ^ ''$' , 'Header$''') withCRs |
|
1905 |
]. |
|
1906 |
self |
|
1907 |
compile:code |
|
1908 |
forClass:aClass |
|
1909 |
inCategory:'documentation'. |
|
1910 |
] |
|
1911 |
]. |
|
1912 |
! ! |
|
1913 |
||
1914 |
!SmalltalkCodeGeneratorTool methodsFor:'code templates'! |
|
1915 |
||
1916 |
codeFor_classInitialize |
|
1917 |
generateComments ifFalse:[ |
|
1918 |
^ |
|
1919 |
'initialize |
|
1920 |
%(INIT_CLASSINSTVARS) |
|
1921 |
%(INIT_CLASSVARS) |
|
1922 |
'. |
|
1923 |
]. |
|
1924 |
||
1925 |
^ |
|
1926 |
'initialize |
|
1927 |
"Invoked at system start or when the class is dynamically loaded." |
|
1928 |
||
1929 |
"/ please change as required (and remove this comment) |
|
1930 |
%(INIT_CLASSINSTVARS) |
|
1931 |
%(INIT_CLASSVARS) |
|
1932 |
'. |
|
1933 |
! |
|
1934 |
||
1935 |
codeFor_closeAccept |
|
1936 |
generateComments ifFalse:[ |
|
1937 |
^ |
|
1938 |
'closeAccept |
|
1939 |
^ super closeAccept |
|
1940 |
'. |
|
1941 |
]. |
|
1942 |
||
1943 |
^ |
|
1944 |
'closeAccept |
|
1945 |
"This is a hook method generated by the Browser/CodeGeneratorTool. |
|
1946 |
It will be invoked when your dialog-window is closed with OK." |
|
1947 |
||
1948 |
"/ add any actions as required here ... |
|
1949 |
Transcript showCR:''dialog accepted''. |
|
1950 |
||
1951 |
"/ do not remove the one below (otherwise, the dialog will not close itself)... |
|
1952 |
^ super closeAccept |
|
1953 |
'. |
|
1954 |
||
1955 |
"Created: / 27-10-2006 / 10:03:31 / cg" |
|
1956 |
! |
|
1957 |
||
1958 |
codeFor_closeDownViews |
|
1959 |
generateComments ifFalse:[ |
|
1960 |
^ |
|
1961 |
'closeDownViews |
|
1962 |
^ super closeDownViews |
|
1963 |
'. |
|
1964 |
]. |
|
1965 |
||
1966 |
^ |
|
1967 |
'closeDownViews |
|
1968 |
"This is a hook method generated by the Browser/CodeGeneratorTool. |
|
1969 |
It will be invoked when your app/dialog-window is really closed. |
|
1970 |
See also #closeDownViews, which is invoked before and may suppress the close |
|
1971 |
or ask the user for confirmation." |
|
1972 |
||
1973 |
"/ change the code below as required ... |
|
1974 |
"/ This should cleanup any leftover resources |
|
1975 |
"/ (for example, temporary files) |
|
1976 |
"/ super closeRequest will initiate the closeDown |
|
1977 |
||
1978 |
"/ add your code here |
|
1979 |
||
1980 |
"/ do not remove the one below ... |
|
1981 |
^ super closeDownViews |
|
1982 |
'. |
|
1983 |
||
1984 |
"Created: / 27-10-2006 / 10:01:32 / cg" |
|
1985 |
! |
|
1986 |
||
1987 |
codeFor_closeRequest |
|
1988 |
generateComments ifFalse:[ |
|
1989 |
^ |
|
1990 |
'closeRequest |
|
1991 |
self hasUnsavedChanges ifTrue:[ |
|
1992 |
(self confirm:(resources string:''Close without saving ?'')) ifFalse:[ |
|
1993 |
^ self |
|
1994 |
] |
|
1995 |
]. |
|
1996 |
^ super closeRequest |
|
1997 |
'. |
|
1998 |
]. |
|
1999 |
||
2000 |
^ |
|
2001 |
'closeRequest |
|
2002 |
"This is a hook method generated by the Browser/CodeGeneratorTool. |
|
2003 |
It will be invoked when your app/dialog-window is about to be |
|
2004 |
closed (this method has a chance to suppress the close). |
|
2005 |
See also #closeDownViews, which is invoked when the close is really done." |
|
2006 |
||
2007 |
"/ change the code below as required ... |
|
2008 |
"/ Closing can be suppressed, by simply returning. |
|
2009 |
"/ The ''super closeRequest'' at the end will initiate the real closeDown |
|
2010 |
||
2011 |
self hasUnsavedChanges ifTrue:[ |
|
2012 |
(self confirm:(resources string:''Close without saving ?'')) ifFalse:[ |
|
2013 |
^ self |
|
2014 |
] |
|
2015 |
]. |
|
2016 |
||
2017 |
^ super closeRequest |
|
2018 |
'. |
|
2019 |
||
2020 |
"Created: / 27-10-2006 / 10:01:06 / cg" |
|
2021 |
! |
|
2022 |
||
2023 |
codeFor_emptyMenuActionCodeFor:selector menuItem:item |
|
2024 |
generateComments ifFalse:[ |
|
2025 |
^ |
|
2026 |
selector,' |
|
2027 |
self warn:''no action for ''''',item,''''' defined.''. |
|
2028 |
'. |
|
2029 |
]. |
|
2030 |
||
2031 |
^ |
|
2032 |
selector,' |
|
2033 |
"This method was generated by the Browser/CodeGeneratorTool. |
|
2034 |
It will be invoked when the menu-item ''',item,''' is selected." |
|
2035 |
||
2036 |
"/ change below and add any actions as required here ... |
|
2037 |
self warn:''no action for ''''',item,''''' defined.''. |
|
2038 |
'. |
|
2039 |
||
2040 |
"Created: / 27-10-2006 / 10:16:43 / cg" |
|
2041 |
! |
|
2042 |
||
2043 |
codeFor_hasUnsavedChanges |
|
2044 |
generateComments ifFalse:[ |
|
2045 |
^ |
|
2046 |
'hasUnsavedChanges |
|
2047 |
^ false. |
|
2048 |
'. |
|
2049 |
]. |
|
2050 |
||
2051 |
^ |
|
2052 |
'hasUnsavedChanges |
|
2053 |
"Return true, if any unsaved changes are present |
|
2054 |
(i.e. the contents needs to be saved or else will be lost)" |
|
2055 |
||
2056 |
"/ add real code as required (or remove the halt and always return false)... |
|
2057 |
"/ self halt:''check this code''. |
|
2058 |
^ false. |
|
2059 |
'. |
|
2060 |
||
2061 |
"Created: / 27-10-2006 / 10:00:36 / cg" |
|
2062 |
! |
|
2063 |
||
2064 |
codeFor_menuSaveAs |
|
2065 |
^ |
|
2066 |
'menuSaveAs |
|
2067 |
"This method was generated by the Browser/CodeGeneratorTool. |
|
2068 |
It will be invoked when the menu-item ''saveAs'' is selected." |
|
2069 |
||
2070 |
"/ change below as required... (see examples in Dialog class for more options) |
|
2071 |
Dialog |
|
2072 |
requestSaveFileName:(resources string:''Save'') |
|
2073 |
default:''foo.txt'' |
|
2074 |
fromDirectory:nil |
|
2075 |
action:[:fileName | self doSaveAs:fileName] |
|
2076 |
appendAction:nil. |
|
2077 |
'. |
|
2078 |
||
2079 |
"Created: / 27-10-2006 / 10:01:57 / cg" |
|
2080 |
! |
|
2081 |
||
2082 |
codeFor_openAboutThisApplication |
|
2083 |
^ |
|
2084 |
'openAboutThisApplication |
|
2085 |
"This method was generated by the Browser/CodeGeneratorTool. |
|
2086 |
It will be invoked when the menu-item ''help-about'' is selected." |
|
2087 |
||
2088 |
"/ could open a customized aboutBox here ... |
|
2089 |
super openAboutThisApplication |
|
2090 |
'. |
|
2091 |
||
2092 |
"Created: / 27-10-2006 / 10:03:13 / cg" |
|
2093 |
! |
|
2094 |
||
2095 |
codeFor_openDocumentation |
|
2096 |
^ |
|
2097 |
'openDocumentation |
|
2098 |
"This method was generated by the Browser/CodeGeneratorTool. |
|
2099 |
It will be invoked when the menu-item ''help-documentation'' is selected." |
|
2100 |
||
2101 |
"/ change below as required ... |
|
2102 |
||
2103 |
"/ to open an HTML viewer on some document (under ''doc/online/<language>/'' ): |
|
2104 |
self openDocumentationFile:''TOP.html''. |
|
2105 |
||
2106 |
"/ add application-specific help files under the ''doc/online/<language>/help/appName'' |
|
2107 |
"/ directory, and open a viewer with: |
|
2108 |
"/ self openDocumentationFile:''help/<MyApplication>/TOP.html''. |
|
2109 |
'. |
|
2110 |
||
2111 |
"Created: / 27-10-2006 / 10:02:55 / cg" |
|
2112 |
! |
|
2113 |
||
2114 |
codeFor_postBuildWith |
|
2115 |
generateComments ifFalse:[ |
|
2116 |
^ |
|
2117 |
'postBuildWith:aBuilder |
|
2118 |
^ super postBuildWith:aBuilder |
|
2119 |
'. |
|
2120 |
]. |
|
2121 |
||
2122 |
^ |
|
2123 |
'postBuildWith:aBuilder |
|
2124 |
"This is a hook method generated by the Browser/CodeGeneratorTool. |
|
2125 |
It will be invoked during the initialization of your app/dialog, |
|
2126 |
after all of the visual components have been built, |
|
2127 |
but BEFORE the top window is made visible. |
|
2128 |
Add any app-specific actions here (reading files, setting up values etc.) |
|
2129 |
See also #postOpenWith:, which is invoked after opening." |
|
2130 |
||
2131 |
"/ add any code here ... |
|
2132 |
||
2133 |
^ super postBuildWith:aBuilder |
|
2134 |
'. |
|
2135 |
||
2136 |
"Created: / 27-10-2006 / 09:59:33 / cg" |
|
2137 |
! |
|
2138 |
||
2139 |
codeFor_postOpenWith |
|
2140 |
generateComments ifFalse:[ |
|
2141 |
^ |
|
2142 |
'postOpenWith:aBuilder |
|
2143 |
^ super postOpenWith:aBuilder |
|
2144 |
'. |
|
2145 |
]. |
|
2146 |
||
2147 |
^ |
|
2148 |
'postOpenWith:aBuilder |
|
2149 |
"This is a hook method generated by the Browser/CodeGeneratorTool. |
|
2150 |
It will be invoked right after the applications window has been opened. |
|
2151 |
Add any app-specific actions here (starting background processes etc.). |
|
2152 |
See also #postBuildWith:, which is invoked before opening." |
|
2153 |
||
2154 |
"/ add any code here ... |
|
2155 |
||
2156 |
^ super postOpenWith:aBuilder |
|
2157 |
'. |
|
2158 |
||
2159 |
"Created: / 27-10-2006 / 09:59:56 / cg" |
|
2160 |
! |
|
2161 |
||
2162 |
code_forWidget_buttonPress |
|
2163 |
generateComments ifFalse:[ |
|
2164 |
^ |
|
2165 |
'buttonPress:button x:x y:y |
|
2166 |
Transcript show:''button: ''; showCR:button. |
|
2167 |
super buttonPress:button x:x y:y |
|
2168 |
' |
|
2169 |
]. |
|
2170 |
||
2171 |
^ |
|
2172 |
'buttonPress:button x:x y:y |
|
2173 |
"called when a mouse-button is pressed. button is the button-nr (1 for left-button). |
|
2174 |
x/y are the mouse position at the time of the click. |
|
2175 |
There are also corresponding buttonRelease and buttonMotion methods which could be |
|
2176 |
redefined...." |
|
2177 |
||
2178 |
Transcript show:''button: ''; showCR:button. |
|
2179 |
"/ super-code handles middleButtonMenu, if it was assigned (with middleButtonmenu:) |
|
2180 |
super buttonPress:button x:x y:y |
|
2181 |
' |
|
2182 |
! |
|
2183 |
||
2184 |
code_forWidget_initialize |
|
2185 |
^ |
|
2186 |
'initialize |
|
2187 |
super initialize "/ to initialize inherited state |
|
2188 |
||
2189 |
"/ add code to initialize private variables, |
|
2190 |
"/ and sub-components as required. |
|
2191 |
' |
|
2192 |
! |
|
2193 |
||
2194 |
code_forWidget_keyPress |
|
2195 |
generateComments ifFalse:[ |
|
2196 |
^ |
|
2197 |
'keyPress:key x:x y:y |
|
2198 |
"/ key == #Copy ifTrue:[ |
|
2199 |
"/ ]. |
|
2200 |
"/ key == #Cut ifTrue:[ |
|
2201 |
"/ ]. |
|
2202 |
Transcript show:''key: ''; showCR:key. |
|
2203 |
super keyPress:key x:x y:y |
|
2204 |
' |
|
2205 |
]. |
|
2206 |
^ |
|
2207 |
'keyPress:key x:x y:y |
|
2208 |
"called when a keyboard-key was pressed. key is either a character (for ordinary keys) |
|
2209 |
or a symbol, such as #Copy, #Cut or #Paste. |
|
2210 |
x/y are the mouse position at the time of the key-press. |
|
2211 |
There is also a corresponding keyRelease method which could be redefined...." |
|
2212 |
||
2213 |
Transcript show:''key: ''; showCR:key. |
|
2214 |
super keyPress:key x:x y:y |
|
2215 |
' |
|
2216 |
! |
|
2217 |
||
2218 |
code_forWidget_redraw |
|
2219 |
|sel comment code| |
|
2220 |
||
2221 |
sel := 'redrawX:x y:y width:w height:h'. |
|
2222 |
generateComments ifFalse:[ |
|
2223 |
comment := ''. |
|
2224 |
] ifTrue:[ |
|
2225 |
comment := ' |
|
2226 |
"called to redraw a part of the widgets area. x/y define the origin, w/h the size of |
|
2227 |
that area. The clipping region has already been set by the caller, so even if the code |
|
2228 |
below draws outside the redraw-area, it will not affect what is on the screen. |
|
2229 |
Therefore, the example below can fill the rectangle in the redraw area, but still draw |
|
2230 |
the cross in the outside regions." |
|
2231 |
||
2232 |
'. |
|
2233 |
]. |
|
2234 |
||
2235 |
code := ' |
|
2236 |
self paint:Color red. |
|
2237 |
self fillRectangleX:x y:y width:w height:h. |
|
2238 |
||
2239 |
self paint:Color yellow. |
|
2240 |
self displayLineFrom:0@0 to:(width@height). |
|
2241 |
self displayLineFrom:width@0 to:(0@height). |
|
2242 |
'. |
|
2243 |
||
2244 |
^ sel,comment,code |
|
2245 |
! |
|
2246 |
||
2247 |
code_forWidget_sizeChanged |
|
2248 |
generateComments ifFalse:[ |
|
2249 |
^ |
|
2250 |
'sizeChanged:how |
|
2251 |
self invalidate. |
|
2252 |
super sizeChanged:how. |
|
2253 |
' |
|
2254 |
]. |
|
2255 |
||
2256 |
^ |
|
2257 |
'sizeChanged:how |
|
2258 |
"Invoked whenever the size of the view changes. |
|
2259 |
Here, we force a full redraw, which might not be needed all the time" |
|
2260 |
||
2261 |
self invalidate. |
|
2262 |
super sizeChanged:how. |
|
2263 |
' |
|
2264 |
! |
|
2265 |
||
2266 |
code_forWidget_update |
|
2267 |
generateComments ifFalse:[ |
|
2268 |
^ |
|
2269 |
'update:something with:aParameter from:changedObject |
|
2270 |
changedObject == model ifTrue:[ |
|
2271 |
self invalidate. |
|
2272 |
^ self |
|
2273 |
]. |
|
2274 |
super update:something with:aParameter from:changedObject |
|
2275 |
' |
|
2276 |
]. |
|
2277 |
||
2278 |
^ |
|
2279 |
'update:something with:aParameter from:changedObject |
|
2280 |
"Invoked when an object that I depend upon sends a change notification." |
|
2281 |
||
2282 |
"stub code automatically generated - please change as required" |
|
2283 |
||
2284 |
changedObject == model ifTrue:[ |
|
2285 |
self invalidate. |
|
2286 |
^ self |
|
2287 |
]. |
|
2288 |
super update:something with:aParameter from:changedObject |
|
2289 |
' |
|
2290 |
! ! |
|
2291 |
||
2292 |
!SmalltalkCodeGeneratorTool methodsFor:'private'! |
|
2293 |
||
2294 |
codeFor_shouldImplementFor:selector inClass:aClass |
|
2295 |
"used in the 'generate required protocol' to generate a shouldImplement-sending |
|
2296 |
method for each subclassClassresponsibility method above aClass." |
|
2297 |
||
2298 |
|mthd comment implClass methodBodyStream searcher errorMessageString| |
|
2299 |
||
2300 |
(aClass notNil |
|
2301 |
and:[ aClass superclass notNil ]) ifTrue:[ |
|
2302 |
implClass := aClass superclass whichClassImplements:selector. |
|
2303 |
]. |
|
2304 |
implClass isNil ifTrue:[ |
|
2305 |
^ ((Method methodDefinitionTemplateForSelector:selector),'\ ^ self shouldImplement\') withCRs |
|
2306 |
]. |
|
2307 |
||
2308 |
mthd := implClass compiledMethodAt:selector. |
|
2309 |
||
2310 |
methodBodyStream := '' writeStream. |
|
2311 |
methodBodyStream |
|
2312 |
nextPutAll:mthd methodDefinitionTemplate; cr; |
|
2313 |
nextPutAll:' "'. |
|
2314 |
||
2315 |
"/ include the comment of the subclassResponsibility-sending method |
|
2316 |
||
2317 |
comment := mthd methodComment. |
|
2318 |
comment isEmptyOrNil ifTrue:[ |
|
2319 |
methodBodyStream |
|
2320 |
nextPutAll:('superclass <1s> says that I am responsible to implement this method' |
|
2321 |
expandMacrosWith:implClass name) |
|
2322 |
] ifFalse:[ |
|
2323 |
comment |
|
2324 |
asStringCollection do:[:eachLine| |
|
2325 |
methodBodyStream nextPutAll:eachLine. |
|
2326 |
] separatedBy:[ |
|
2327 |
methodBodyStream cr; nextPutAll:' '. |
|
2328 |
]. |
|
2329 |
]. |
|
2330 |
methodBodyStream |
|
2331 |
nextPut:$"; cr; cr. |
|
2332 |
||
2333 |
"/ include the argument of the subclassResponsibility:-sending method |
|
2334 |
self canUseRefactoringSupport ifTrue:[ |
|
2335 |
(mthd sends:#subclassResponsibility:) ifTrue:[ |
|
2336 |
searcher := ParseTreeSearcher new. |
|
2337 |
searcher |
|
2338 |
matches: 'self subclassResponsibility: `''.*''' |
|
2339 |
do:[:node :answer | |
|
2340 |
errorMessageString := node arguments first value. |
|
2341 |
true. |
|
2342 |
]. |
|
2343 |
searcher executeTree: (mthd parseTree) initialAnswer: false. |
|
2344 |
]. |
|
2345 |
]. |
|
2346 |
errorMessageString notEmptyOrNil ifTrue:[ |
|
2347 |
methodBodyStream |
|
2348 |
nextPutAll:' ^ self shouldImplement:'; |
|
2349 |
nextPutLine:(errorMessageString storeString) |
|
2350 |
] ifFalse:[ |
|
2351 |
methodBodyStream |
|
2352 |
nextPutLine:' ^ self shouldImplement'. |
|
2353 |
]. |
|
2354 |
||
2355 |
^ methodBodyStream contents |
|
2356 |
! ! |
|
2357 |
||
2358 |
!SmalltalkCodeGeneratorTool class methodsFor:'documentation'! |
|
2359 |
||
9960 | 2360 |
version_SVN |
2361 |
^ '§Id§' |
|
9706 | 2362 |
! ! |