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