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