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