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