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