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