author | Claus Gittinger <cg@exept.de> |
Wed, 07 May 2003 16:52:53 +0200 | |
changeset 4867 | 269d62a1ed27 |
parent 4590 | 2447e35a81d4 |
child 4908 | 1e145ba4eab7 |
permissions | -rw-r--r-- |
3712 | 1 |
"{ Package: 'stx:libtool' }" |
2 |
||
3 |
Object subclass:#CodeGeneratorTool |
|
4 |
instanceVariableNames:'' |
|
5 |
classVariableNames:'' |
|
6 |
poolDictionaries:'' |
|
7 |
category:'Interface-Browsers' |
|
8 |
! |
|
9 |
||
3719 | 10 |
!CodeGeneratorTool class methodsFor:'documentation'! |
11 |
||
12 |
documentation |
|
13 |
" |
|
14 |
extracted code generation stuff from old and newBrowser. |
|
15 |
There is probably more to gome... |
|
16 |
||
17 |
[author:] |
|
18 |
Claus Gittiner |
|
19 |
" |
|
20 |
! ! |
|
3712 | 21 |
|
22 |
!CodeGeneratorTool class methodsFor:'code generation'! |
|
23 |
||
24 |
createAccessMethodsFor:aCollectionOfVarNames in:aClass withChange:withChange asValueHolder:asValueHolder readersOnly:readersOnly writersOnly:writersOnly |
|
4444
6b077945517c
generate instvar accessors with lazy-init
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
25 |
^ self |
6b077945517c
generate instvar accessors with lazy-init
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
26 |
createAccessMethodsFor:aCollectionOfVarNames |
6b077945517c
generate instvar accessors with lazy-init
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
27 |
in:aClass |
6b077945517c
generate instvar accessors with lazy-init
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
28 |
withChange:withChange |
6b077945517c
generate instvar accessors with lazy-init
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
29 |
asValueHolder:asValueHolder |
6b077945517c
generate instvar accessors with lazy-init
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
30 |
readersOnly:readersOnly |
6b077945517c
generate instvar accessors with lazy-init
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
31 |
writersOnly:writersOnly |
6b077945517c
generate instvar accessors with lazy-init
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
32 |
lazyInitialization:false |
6b077945517c
generate instvar accessors with lazy-init
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
33 |
! |
6b077945517c
generate instvar accessors with lazy-init
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
34 |
|
6b077945517c
generate instvar accessors with lazy-init
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
35 |
createAccessMethodsFor:aCollectionOfVarNames in:aClass withChange:withChange asValueHolder:asValueHolder readersOnly:readersOnly writersOnly:writersOnly lazyInitialization:lazyInitialization |
3712 | 36 |
"workhorse for creating access methods for instvars." |
37 |
||
38 |
|classesClassVars| |
|
39 |
||
40 |
classesClassVars := aClass theNonMetaclass allClassVarNames. |
|
41 |
||
42 |
aCollectionOfVarNames do:[:name | |
|
4444
6b077945517c
generate instvar accessors with lazy-init
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
43 |
|source varType methodName defaultMethodName| |
3712 | 44 |
|
45 |
varType := (classesClassVars includes:name) |
|
46 |
ifTrue:['static'] |
|
47 |
ifFalse:[ |
|
48 |
(aClass isMeta ifTrue:['classInstVar'] ifFalse:['instance'])]. |
|
49 |
||
50 |
methodName := name. |
|
51 |
name first isUppercase ifTrue:[ |
|
52 |
methodName := methodName asLowercaseFirst. |
|
53 |
]. |
|
54 |
||
4444
6b077945517c
generate instvar accessors with lazy-init
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
55 |
"/ the GETTER |
3712 | 56 |
writersOnly ifFalse:[ |
4444
6b077945517c
generate instvar accessors with lazy-init
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
57 |
lazyInitialization ifTrue:[ |
6b077945517c
generate instvar accessors with lazy-init
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
58 |
defaultMethodName := 'default' , name asUppercaseFirst. |
6b077945517c
generate instvar accessors with lazy-init
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
59 |
]. |
6b077945517c
generate instvar accessors with lazy-init
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
60 |
|
3712 | 61 |
"check, if method is not already present" |
62 |
(aClass includesSelector:(methodName asSymbol)) ifFalse:[ |
|
63 |
asValueHolder ifTrue:[ |
|
64 |
source := methodName |
|
65 |
, '\ "return/create the ''%2'' value holder (automatically generated)"\\' |
|
4444
6b077945517c
generate instvar accessors with lazy-init
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
66 |
, ' %2 isNil ifTrue:[\'. |
6b077945517c
generate instvar accessors with lazy-init
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
67 |
lazyInitialization ifTrue:[ |
6b077945517c
generate instvar accessors with lazy-init
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
68 |
source := source |
6b077945517c
generate instvar accessors with lazy-init
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
69 |
, ' %2 := self class %3 asValue.\'. |
6b077945517c
generate instvar accessors with lazy-init
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
70 |
] ifFalse:[ |
6b077945517c
generate instvar accessors with lazy-init
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
71 |
source := source |
6b077945517c
generate instvar accessors with lazy-init
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
72 |
, ' %2 := ValueHolder new.\'. |
6b077945517c
generate instvar accessors with lazy-init
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
73 |
]. |
6b077945517c
generate instvar accessors with lazy-init
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
74 |
|
3712 | 75 |
withChange ifTrue:[ |
76 |
source := source |
|
77 |
, ' %2 addDependent:self.\'. |
|
78 |
]. |
|
79 |
source := source |
|
80 |
, ' ].\' |
|
81 |
, ' ^ %2'. |
|
82 |
] ifFalse:[ |
|
83 |
source := methodName |
|
4444
6b077945517c
generate instvar accessors with lazy-init
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
84 |
, '\ "return the value of the %1 variable ''%2'' (automatically generated)"\\'. |
6b077945517c
generate instvar accessors with lazy-init
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
85 |
lazyInitialization ifTrue:[ |
6b077945517c
generate instvar accessors with lazy-init
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
86 |
source := source |
6b077945517c
generate instvar accessors with lazy-init
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
87 |
, ' %2 isNil ifTrue:[\' |
6b077945517c
generate instvar accessors with lazy-init
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
88 |
, ' %2 := self class %3.\' |
6b077945517c
generate instvar accessors with lazy-init
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
89 |
, ' ].\' |
6b077945517c
generate instvar accessors with lazy-init
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
90 |
, ' ^ %2'. |
6b077945517c
generate instvar accessors with lazy-init
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
91 |
] ifFalse:[ |
6b077945517c
generate instvar accessors with lazy-init
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
92 |
source := source |
6b077945517c
generate instvar accessors with lazy-init
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
93 |
, ' ^ %2'. |
6b077945517c
generate instvar accessors with lazy-init
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
94 |
]. |
3712 | 95 |
]. |
4444
6b077945517c
generate instvar accessors with lazy-init
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
96 |
source := (source bindWith:varType with:name with:defaultMethodName) withCRs. |
3712 | 97 |
self compile:source forClass:aClass inCategory:(asValueHolder ifTrue:['aspects'] ifFalse:['accessing']). |
98 |
] ifTrue:[ |
|
99 |
Transcript showCR:'method ''', methodName , ''' already present' |
|
100 |
]. |
|
4444
6b077945517c
generate instvar accessors with lazy-init
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
101 |
|
6b077945517c
generate instvar accessors with lazy-init
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
102 |
"/ default for lazy on class side |
6b077945517c
generate instvar accessors with lazy-init
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
103 |
lazyInitialization ifTrue:[ |
6b077945517c
generate instvar accessors with lazy-init
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
104 |
(aClass class includesSelector:(defaultMethodName asSymbol)) ifFalse:[ |
6b077945517c
generate instvar accessors with lazy-init
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
105 |
source := defaultMethodName |
6b077945517c
generate instvar accessors with lazy-init
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
106 |
, '\ "default value for the ''%2'' instance variable (automatically generated)"\\' |
6b077945517c
generate instvar accessors with lazy-init
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
107 |
, ' self halt:''unfinished code''.\' |
6b077945517c
generate instvar accessors with lazy-init
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
108 |
, ' ^ nil.'. |
6b077945517c
generate instvar accessors with lazy-init
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
109 |
source := (source bindWith:varType with:name) withCRs. |
6b077945517c
generate instvar accessors with lazy-init
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
110 |
self compile:source forClass:aClass class inCategory:'defaults'. |
6b077945517c
generate instvar accessors with lazy-init
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
111 |
]. |
6b077945517c
generate instvar accessors with lazy-init
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
112 |
]. |
3712 | 113 |
]. |
114 |
||
4444
6b077945517c
generate instvar accessors with lazy-init
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
115 |
"/ the SETTER |
3712 | 116 |
readersOnly ifFalse:[ |
117 |
(aClass includesSelector:((methodName , ':') asSymbol)) ifFalse:[ |
|
118 |
asValueHolder ifTrue:[ |
|
119 |
source := methodName |
|
120 |
, ':something\ "set the ''%2'' value holder'. |
|
121 |
withChange ifTrue:[ |
|
122 |
source := source |
|
123 |
, ' (automatically generated)"\\' |
|
124 |
, ' |oldValue newValue|\\' |
|
125 |
, ' %2 notNil ifTrue:[\' |
|
126 |
, ' oldValue := %2 value.\' |
|
127 |
, ' %2 removeDependent:self.\' |
|
128 |
, ' ].\' |
|
129 |
, ' %2 := something.\' |
|
130 |
, ' %2 notNil ifTrue:[\' |
|
131 |
, ' %2 addDependent:self.\' |
|
132 |
, ' ].\' |
|
133 |
, ' newValue := %2 value.\' |
|
134 |
, ' oldValue ~~ newValue ifTrue:[\' |
|
135 |
, ' self update:#value with:newValue from:%2.\' |
|
136 |
, ' ].\' |
|
137 |
] ifFalse:[ |
|
138 |
source := source |
|
139 |
, ' (automatically generated)"\\' |
|
140 |
, ' %2 := something.'. |
|
141 |
]. |
|
142 |
] ifFalse:[ |
|
143 |
source := methodName |
|
144 |
, ':something\ "set the value of the %1 variable ''%2'''. |
|
145 |
withChange ifTrue:[ |
|
146 |
source := source |
|
147 |
, ' and send a change notification (automatically generated)"\\' |
|
148 |
, ' (%2 ~~ something) ifTrue:[\' |
|
149 |
, ' %2 := something.\' |
|
150 |
, ' self changed:#%2.\' |
|
151 |
, ' ].\'. |
|
152 |
] ifFalse:[ |
|
153 |
source := source |
|
154 |
, ' (automatically generated)"\\' |
|
155 |
, ' %2 := something.'. |
|
156 |
]. |
|
157 |
]. |
|
158 |
source := (source bindWith:varType with:name) withCRs. |
|
159 |
self |
|
160 |
compile:source |
|
161 |
forClass:aClass |
|
162 |
inCategory:(asValueHolder ifTrue:['aspects'] ifFalse:['accessing']). |
|
163 |
] ifTrue:[ |
|
164 |
Transcript showCR:'method ''', methodName , ':'' already present' |
|
165 |
]. |
|
166 |
]. |
|
167 |
] |
|
168 |
! |
|
169 |
||
170 |
createApplicationCodeFor:aClass |
|
171 |
"create an empty application framework" |
|
172 |
||
173 |
|nonMetaClass metaClass className txt isDialog| |
|
174 |
||
175 |
nonMetaClass := aClass theNonMetaclass. |
|
176 |
metaClass := aClass theMetaclass. |
|
177 |
className := nonMetaClass name. |
|
178 |
||
179 |
isDialog := (nonMetaClass isSubclassOf:SimpleDialog). |
|
180 |
||
181 |
"/ add a windowSpec method for an empty applicationWindow, |
|
182 |
"/ with a menuPanel. |
|
183 |
||
184 |
(metaClass includesSelector:#windowSpec) ifFalse:[ |
|
185 |
isDialog ifTrue:[ |
|
186 |
txt := self initialWindowSpecMethodSourceForDialogs. |
|
187 |
] ifFalse:[ |
|
188 |
txt := self initialWindowSpecMethodSourceForApplications. |
|
189 |
]. |
|
190 |
self |
|
191 |
compile:(txt bindWith:className) |
|
192 |
forClass:metaClass |
|
193 |
inCategory:'interface specs'. |
|
194 |
]. |
|
195 |
||
196 |
isDialog ifFalse:[ |
|
197 |
"/ add a topMenu method |
|
198 |
||
199 |
(metaClass includesSelector:#mainMenu) ifFalse:[ |
|
200 |
txt := self initialMenuSpecMethodSourceForApplications. |
|
201 |
self |
|
202 |
compile:(txt bindWith:className) |
|
203 |
forClass:metaClass |
|
204 |
inCategory:'menu specs'. |
|
205 |
]. |
|
206 |
]. |
|
207 |
||
208 |
(metaClass includesSelector:#postBuildWith:) ifFalse:[ |
|
209 |
txt := |
|
210 |
'postBuildWith:aBuilder |
|
211 |
"This is a hook method generated by the Browser. |
|
212 |
It will be invoked during the initialization of your app/dialog, |
|
213 |
after all of the visual components have been built, |
|
214 |
but BEFORE the top window is made visible. |
|
215 |
Add any app-specific actions here (reading files, setting up values etc.) |
|
216 |
See also #postOpenWith:, which is invoked after opening." |
|
217 |
||
218 |
"/ add any code here ... |
|
219 |
||
220 |
^ super postBuildWith:aBuilder |
|
221 |
'. |
|
222 |
self |
|
223 |
compile:txt |
|
224 |
forClass:nonMetaClass |
|
225 |
inCategory:'initialization & release'. |
|
226 |
]. |
|
227 |
||
228 |
(metaClass includesSelector:#postOpenWith:) ifFalse:[ |
|
229 |
txt := |
|
230 |
'postOpenWith:aBuilder |
|
231 |
"This is a hook method generated by the Browser. |
|
232 |
It will be invoked right after the applications window has been opened. |
|
233 |
Add any app-specific actions here (starting background processes etc.). |
|
234 |
See also #postBuildWith:, which is invoked before opening." |
|
235 |
||
236 |
"/ add any code here ... |
|
237 |
||
238 |
^ super postOpenWith:aBuilder |
|
239 |
'. |
|
240 |
self |
|
241 |
compile:txt |
|
242 |
forClass:nonMetaClass |
|
243 |
inCategory:'initialization & release'. |
|
244 |
]. |
|
245 |
||
246 |
isDialog ifFalse:[ |
|
247 |
(metaClass includesSelector:#closeRequest) ifFalse:[ |
|
248 |
txt := |
|
249 |
'closeRequest |
|
250 |
"This is a hook method generated by the Browser. |
|
251 |
It will be invoked when your app/dialog-window is about to be |
|
252 |
closed (this method has a chance to suppress the close). |
|
253 |
See also #closeDownViews, which is invoked when the close is really done." |
|
254 |
||
255 |
"/ change the code below as required ... |
|
256 |
"/ Closing can be suppressed, by simply returning. |
|
257 |
"/ The ''super closeRequest'' at the end will initiate the real closeDown |
|
258 |
||
259 |
("self hasUnsavedChanges" true) ifTrue:[ |
|
260 |
(self confirm:(resources string:''Close without saving ?'')) ifFalse:[ |
|
261 |
^ self |
|
262 |
] |
|
263 |
]. |
|
264 |
||
265 |
^ super closeRequest |
|
266 |
'. |
|
267 |
self |
|
268 |
compile:txt |
|
269 |
forClass:nonMetaClass |
|
270 |
inCategory:'initialization & release'. |
|
271 |
]. |
|
272 |
]. |
|
273 |
||
274 |
isDialog ifFalse:[ |
|
275 |
(metaClass includesSelector:#closeDownViews) ifFalse:[ |
|
276 |
txt := |
|
277 |
'closeDownViews |
|
278 |
"This is a hook method generated by the Browser. |
|
279 |
It will be invoked when your app/dialog-window is really closed. |
|
280 |
See also #closeDownViews, which is invoked before and may suppress the close |
|
281 |
or ask the user for confirmation." |
|
282 |
||
283 |
"/ change the code below as required ... |
|
284 |
"/ This should cleanup any leftover resources |
|
285 |
"/ (for example, temporary files) |
|
286 |
"/ super closeRequest will initiate the closeDown |
|
287 |
||
288 |
"/ add your code here |
|
289 |
||
290 |
"/ do not remove the one below ... |
|
291 |
^ super closeDownViews |
|
292 |
'. |
|
293 |
self |
|
294 |
compile:txt |
|
295 |
forClass:nonMetaClass |
|
296 |
inCategory:'initialization & release'. |
|
297 |
]. |
|
298 |
]. |
|
299 |
||
300 |
isDialog ifTrue:[ |
|
301 |
(metaClass includesSelector:#accept) ifFalse:[ |
|
302 |
txt := |
|
303 |
'closeAccept |
|
304 |
"This is a hook method generated by the Browser. |
|
305 |
It will be invoked when your dialog-window is closed with OK." |
|
306 |
||
307 |
"/ add any actions as required here ... |
|
308 |
Transcript showCR:''dialog accepted''. |
|
309 |
||
310 |
"/ do not remove the one below ... |
|
311 |
^ super closeAccept |
|
312 |
'. |
|
313 |
self |
|
314 |
compile:txt |
|
315 |
forClass:nonMetaClass |
|
316 |
inCategory:'user actions'. |
|
317 |
]. |
|
318 |
]. |
|
319 |
||
320 |
isDialog ifFalse:[ |
|
321 |
(metaClass includesSelector:#menuNew) ifFalse:[ |
|
322 |
txt := |
|
323 |
'menuNew |
|
324 |
"This method was generated by the Browser. |
|
325 |
It will be invoked when the menu-item ''new'' is selected." |
|
326 |
||
327 |
"/ change below and add any actions as required here ... |
|
328 |
self warn:''no action for ''''new'''' available.''. |
|
329 |
'. |
|
330 |
self |
|
331 |
compile:txt |
|
332 |
forClass:nonMetaClass |
|
333 |
inCategory:'menu actions'. |
|
334 |
]. |
|
335 |
]. |
|
336 |
isDialog ifFalse:[ |
|
337 |
(metaClass includesSelector:#menuOpen) ifFalse:[ |
|
338 |
txt := |
|
339 |
'menuOpen |
|
340 |
"This method was generated by the Browser. |
|
341 |
It will be invoked when the menu-item ''open'' is selected." |
|
342 |
||
343 |
"/ change below and add any actions as required here ... |
|
344 |
self warn:''no action for ''''open'''' available.''. |
|
345 |
'. |
|
346 |
self |
|
347 |
compile:txt |
|
348 |
forClass:nonMetaClass |
|
349 |
inCategory:'menu actions'. |
|
350 |
]. |
|
351 |
]. |
|
352 |
isDialog ifFalse:[ |
|
353 |
(metaClass includesSelector:#menuSave) ifFalse:[ |
|
354 |
txt := |
|
355 |
'menuSave |
|
356 |
"This method was generated by the Browser. |
|
357 |
It will be invoked when the menu-item ''save'' is selected." |
|
358 |
||
359 |
"/ change below and add any actions as required here ... |
|
360 |
self warn:''no action for ''''save'''' available.''. |
|
361 |
'. |
|
362 |
self |
|
363 |
compile:txt |
|
364 |
forClass:nonMetaClass |
|
365 |
inCategory:'menu actions'. |
|
366 |
]. |
|
367 |
]. |
|
368 |
isDialog ifFalse:[ |
|
369 |
(metaClass includesSelector:#menuSaveAs) ifFalse:[ |
|
370 |
txt := |
|
371 |
'menuSaveAs |
|
372 |
"This method was generated by the Browser. |
|
373 |
It will be invoked when the menu-item ''saveAs'' is selected." |
|
374 |
||
375 |
"/ change below and add any actions as required here ... |
|
376 |
self warn:''no action for ''''saveAs'''' available.''. |
|
377 |
'. |
|
378 |
self |
|
379 |
compile:txt |
|
380 |
forClass:nonMetaClass |
|
381 |
inCategory:'menu actions'. |
|
382 |
]. |
|
383 |
]. |
|
384 |
||
385 |
isDialog ifFalse:[ |
|
386 |
(metaClass includesSelector:#openDocumentation) ifFalse:[ |
|
387 |
txt := |
|
388 |
'openDocumentation |
|
389 |
"This method was generated by the Browser. |
|
390 |
It will be invoked when the menu-item ''help-documentation'' is selected." |
|
391 |
||
392 |
"/ change below as required ... |
|
393 |
||
394 |
"/ to open an HTML viewer on some document (under ''doc/online/<language>/'' ): |
|
395 |
HTMLDocumentView openFullOnDocumentationFile:''TOP.html''. |
|
396 |
||
397 |
"/ add application-specific help files under the ''doc/online/<language>/help/appName'' |
|
398 |
"/ directory, and open a viewer with: |
|
399 |
"/ HTMLDocumentView openFullOnDocumentationFile:''help/<MyApplication>/TOP.html''. |
|
400 |
'. |
|
401 |
self |
|
402 |
compile:txt |
|
403 |
forClass:nonMetaClass |
|
404 |
inCategory:'menu actions'. |
|
405 |
]. |
|
406 |
]. |
|
407 |
||
408 |
isDialog ifFalse:[ |
|
409 |
(metaClass includesSelector:#openAboutThisApplication) ifFalse:[ |
|
410 |
txt := |
|
411 |
'openAboutThisApplication |
|
412 |
"This method was generated by the Browser. |
|
413 |
It will be invoked when the menu-item ''help-about'' is selected." |
|
414 |
||
415 |
"/ could open a customized aboutBox here ... |
|
416 |
super openAboutThisApplication |
|
417 |
'. |
|
418 |
self |
|
419 |
compile:txt |
|
420 |
forClass:nonMetaClass |
|
421 |
inCategory:'menu actions'. |
|
422 |
]. |
|
423 |
]. |
|
424 |
||
425 |
"Modified: / 1.2.1998 / 16:10:03 / cg" |
|
426 |
! |
|
427 |
||
3804 | 428 |
createClassResponsibleProtocolFor:aClass |
429 |
"create stubs for the required protocol" |
|
430 |
||
4108
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
431 |
self privCreateClassResponsibleProtocolFor:aClass theNonMetaclass. |
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
432 |
self privCreateClassResponsibleProtocolFor:aClass theMetaclass. |
3804 | 433 |
! |
434 |
||
4351 | 435 |
createClassTypeTestMethodsIn:aClass |
436 |
"create a #isXXX test methods |
|
437 |
(I'm tired of typing)" |
|
438 |
||
439 |
|subClasses code| |
|
440 |
||
441 |
subClasses := aClass subclasses. |
|
442 |
subClasses do:[:eachSubClass | |
|
443 |
|nm selector| |
|
444 |
||
445 |
nm := eachSubClass nameWithoutPrefix. |
|
446 |
selector := 'is' , nm. |
|
447 |
(aClass includesSelector:selector) ifFalse:[ |
|
448 |
code := (selector , '\ ^ false') withCRs. |
|
449 |
self |
|
450 |
compile:code |
|
451 |
forClass:aClass |
|
452 |
inCategory:'testing'. |
|
453 |
]. |
|
454 |
(eachSubClass includesSelector:selector) ifFalse:[ |
|
455 |
code := (selector , '\ ^ true') withCRs. |
|
456 |
self |
|
457 |
compile:code |
|
458 |
forClass:eachSubClass |
|
459 |
inCategory:'testing'. |
|
460 |
]. |
|
461 |
]. |
|
462 |
! |
|
463 |
||
3712 | 464 |
createDocumentationMethodsFor:aClass |
465 |
"create empty documentation methods" |
|
466 |
||
467 |
|cls| |
|
468 |
||
469 |
cls := aClass theMetaclass. |
|
470 |
||
471 |
self createVersionMethodFor:cls. |
|
472 |
self createCopyrightMethodFor:aClass. |
|
473 |
self createDocumentationMethodFor:aClass. |
|
474 |
self createInitialHistoryMethodFor:aClass. |
|
475 |
! |
|
476 |
||
477 |
createStandardInitializationMethodsIn:aClass |
|
478 |
"create a #new and #initialize methods |
|
479 |
(I'm tired of typing)" |
|
480 |
||
481 |
|code initializer m| |
|
482 |
||
483 |
(aClass includesSelector:#'initialize') ifFalse:[ |
|
484 |
code := |
|
485 |
'initialize |
|
486 |
"Invoked when a new instance is created." |
|
487 |
||
488 |
super initialize. |
|
489 |
||
490 |
"/ please change as required (and remove this comment) |
|
491 |
'. |
|
492 |
||
493 |
m := aClass responseTo:#initialize. |
|
494 |
m notNil ifTrue:[ |
|
495 |
m messagesSent size == 0 ifTrue:[ |
|
496 |
"/ inherits an empty initialize. |
|
497 |
||
498 |
code := |
|
499 |
'initialize |
|
500 |
"Invoked when a new instance is created." |
|
501 |
||
502 |
"/ please change as required (and remove this comment) |
|
503 |
||
504 |
"/ super initialize. -- commented since inherited method does nothing |
|
505 |
'. |
|
506 |
||
507 |
]. |
|
508 |
]. |
|
509 |
||
510 |
aClass instVarNames do:[:eachInstVar | |
|
511 |
initializer := 'nil'. "/ need more intelligence here (try to guess class from messages sent to it) ... |
|
512 |
code := code , (' ' , eachInstVar , ' := ' , initializer , Character cr). |
|
513 |
]. |
|
514 |
||
515 |
self |
|
516 |
compile:code |
|
517 |
forClass:aClass |
|
518 |
inCategory:'initialization'. |
|
519 |
]. |
|
520 |
||
521 |
(aClass class includesSelector:#'new') ifFalse:[ |
|
522 |
m := aClass class responseTo:#new. |
|
523 |
m notNil ifTrue:[ |
|
524 |
(m sends:#initialize) ifTrue:[ |
|
525 |
(self confirm:'The inherited #new method already seems to invoke #initialize. Redefine ?') |
|
526 |
ifFalse:[ |
|
527 |
^ self |
|
528 |
] |
|
529 |
]. |
|
530 |
]. |
|
531 |
code := |
|
532 |
'new |
|
533 |
^ self basicNew initialize. |
|
534 |
'. |
|
535 |
self |
|
536 |
compile:code |
|
537 |
forClass:aClass class |
|
538 |
inCategory:'instance creation'. |
|
539 |
]. |
|
540 |
||
541 |
||
542 |
"Created: / 11.10.2001 / 22:18:55 / cg" |
|
543 |
! |
|
544 |
||
545 |
createTestCaseSampleCodeFor:aClass |
|
4590 | 546 |
"create an (almost) empty testCase class" |
3712 | 547 |
|
548 |
|nonMetaClass metaClass| |
|
549 |
||
550 |
nonMetaClass := aClass theNonMetaclass. |
|
551 |
metaClass := aClass theMetaclass. |
|
552 |
"/ className := nonMetaClass name. |
|
553 |
||
554 |
( nonMetaClass includesSelector:#test1 ) ifFalse:[ |
|
555 |
self |
|
556 |
compile: |
|
557 |
'test1 |
|
4590 | 558 |
"This is a demonstration testCase - it is meant to be removed eventually. |
559 |
This testCase will PASS. |
|
3712 | 560 |
Double click on the TestCase class or open a TestRunner to see me checking... |
561 |
- please add more methods like this..." |
|
562 |
||
563 |
|o| |
|
564 |
||
565 |
o := Array new:2. |
|
566 |
self assert: ( o size == 2 ). |
|
567 |
self should: [ o at:0 ] raise:Error. |
|
568 |
self shouldnt: [ o at:1 ] raise:Error. |
|
569 |
||
570 |
" |
|
571 |
self run:#test1 |
|
4590 | 572 |
self new test1 |
573 |
" |
|
574 |
' |
|
575 |
forClass:nonMetaClass |
|
576 |
inCategory:'tests'. |
|
577 |
]. |
|
578 |
||
579 |
( nonMetaClass includesSelector:#test2 ) ifFalse:[ |
|
580 |
self |
|
581 |
compile: |
|
582 |
'test2 |
|
583 |
"This is a demonstration testCase - it is meant to be removed eventually.. |
|
584 |
This testCase WILL FAIL. |
|
585 |
Double click on the TestCase class or open a TestRunner to see me checking... |
|
586 |
- please add more methods like this..." |
|
587 |
||
588 |
|o| |
|
589 |
||
590 |
o := Array new:2. |
|
591 |
self assert: ( o size == 3 ). |
|
592 |
||
593 |
" |
|
594 |
self run:#test2 |
|
595 |
self new test2 |
|
596 |
" |
|
597 |
' |
|
598 |
forClass:nonMetaClass |
|
599 |
inCategory:'tests'. |
|
600 |
]. |
|
601 |
||
602 |
( nonMetaClass includesSelector:#test3 ) ifFalse:[ |
|
603 |
self |
|
604 |
compile: |
|
605 |
'test3 |
|
606 |
"This is a demonstration testCase - it is meant to be removed eventually.. |
|
607 |
This testCase WILL generate an ERROR. |
|
608 |
Double click on the TestCase class or open a TestRunner to see me checking... |
|
609 |
- please add more methods like this..." |
|
610 |
||
611 |
|o| |
|
612 |
||
613 |
o := Array new:2. |
|
614 |
self assert: ( o foo ). |
|
615 |
||
616 |
" |
|
617 |
self run:#test3 |
|
618 |
self new test3 |
|
3712 | 619 |
" |
620 |
' |
|
621 |
forClass:nonMetaClass |
|
622 |
inCategory:'tests'. |
|
623 |
]. |
|
624 |
||
625 |
( nonMetaClass includesSelector:#setUp ) ifFalse:[ |
|
626 |
self |
|
627 |
compile: |
|
628 |
'setUp |
|
4590 | 629 |
"common setup - invoked before testing." |
3712 | 630 |
|
631 |
super setUp |
|
632 |
' |
|
633 |
forClass:nonMetaClass |
|
634 |
inCategory:'initialize / release'. |
|
635 |
]. |
|
636 |
||
637 |
( nonMetaClass includesSelector:#tearDown ) ifFalse:[ |
|
638 |
self |
|
639 |
compile: |
|
640 |
'tearDown |
|
4590 | 641 |
"common cleanup - invoked after testing." |
3712 | 642 |
|
643 |
super tearDown |
|
644 |
' |
|
645 |
forClass:nonMetaClass |
|
646 |
inCategory:'initialize / release'. |
|
647 |
] |
|
648 |
! |
|
649 |
||
650 |
createVisitorMethodsIn:visitedClass andVisitorClass:visitorClass |
|
651 |
"create acceptVisitor: in visitedClass and acceptXXX in visitorClass. |
|
652 |
(I'm tired of typing)" |
|
653 |
||
654 |
|sel| |
|
655 |
||
656 |
visitedClass isMeta ifTrue:[self halt]. |
|
657 |
visitorClass isMeta ifTrue:[self halt]. |
|
658 |
||
659 |
sel := ('visit' , visitedClass nameWithoutPrefix , ':'). |
|
660 |
self createAcceptVisitorMethod:sel in:visitedClass. |
|
661 |
||
662 |
(visitorClass includesSelector:sel) ifFalse:[ |
|
663 |
self |
|
664 |
compile: |
|
665 |
(('%1anObject |
|
666 |
"dispatched back from the visited %2-object (visitor pattern)" |
|
667 |
||
668 |
"fall back to general object-case - please change as required" |
|
669 |
||
670 |
^ self visitObject:anObject |
|
671 |
') bindWith:sel with:visitedClass nameWithoutPrefix asLowercaseFirst) |
|
672 |
forClass:visitorClass |
|
673 |
inCategory:'visiting'. |
|
674 |
]. |
|
675 |
||
676 |
(visitorClass includesSelector:#'visitObject:') ifFalse:[ |
|
677 |
self |
|
678 |
compile: |
|
679 |
('visitObject:anObject |
|
680 |
"dispatched back from the visited objects (visitor pattern)" |
|
681 |
||
682 |
"general fallBack - please change as required" |
|
683 |
||
684 |
self halt:''not yet implemented'' |
|
685 |
') |
|
686 |
forClass:visitorClass |
|
687 |
inCategory:'visiting'. |
|
688 |
]. |
|
689 |
||
690 |
(visitorClass includesSelector:#'visit:') ifFalse:[ |
|
691 |
self |
|
692 |
compile: |
|
693 |
('visit:anObject |
|
694 |
"visit anObject (visitor pattern). |
|
695 |
The object should call back one of my visitXXXX methods." |
|
696 |
||
697 |
^ anObject acceptVisitor:self |
|
698 |
') |
|
699 |
forClass:visitorClass |
|
700 |
inCategory:'visiting'. |
|
701 |
] |
|
702 |
! |
|
703 |
||
704 |
initialMenuSpecMethodSourceForApplications |
|
705 |
^ |
|
706 |
'mainMenu |
|
707 |
"This resource specification was automatically generated by the CodeGeneratorTool." |
|
708 |
||
709 |
"Do not manually edit this!! If it is corrupted, |
|
710 |
the MenuEditor may not be able to read the specification." |
|
711 |
||
712 |
" |
|
713 |
MenuEditor new openOnClass:%1 andSelector:#mainMenu |
|
714 |
" |
|
715 |
||
716 |
<resource: #menu> |
|
717 |
||
718 |
^ #(#Menu |
|
719 |
#( |
|
720 |
#(#MenuItem |
|
721 |
#label: ''File'' |
|
722 |
#translateLabel: true |
|
723 |
#submenu: |
|
724 |
#(#Menu |
|
725 |
#( |
|
726 |
#(#MenuItem |
|
727 |
#label: ''New'' |
|
728 |
#translateLabel: true |
|
729 |
#value: #menuNew |
|
730 |
) |
|
731 |
#(#MenuItem |
|
732 |
#label: ''-'' |
|
733 |
) |
|
734 |
#(#MenuItem |
|
735 |
#label: ''Open...'' |
|
736 |
#translateLabel: true |
|
737 |
#value: #menuOpen |
|
738 |
) |
|
739 |
#(#MenuItem |
|
740 |
#label: ''-'' |
|
741 |
) |
|
742 |
#(#MenuItem |
|
743 |
#label: ''Save'' |
|
744 |
#translateLabel: true |
|
745 |
#value: #menuSave |
|
746 |
) |
|
747 |
#(#MenuItem |
|
748 |
#label: ''Save As...'' |
|
749 |
#translateLabel: true |
|
750 |
#value: #menuSaveAs |
|
751 |
) |
|
752 |
#(#MenuItem |
|
753 |
#label: ''-'' |
|
754 |
) |
|
755 |
#(#MenuItem |
|
756 |
#label: ''Exit'' |
|
757 |
#translateLabel: true |
|
758 |
#value: #closeRequest |
|
759 |
) |
|
760 |
) nil |
|
761 |
nil |
|
762 |
) |
|
763 |
) |
|
764 |
#(#MenuItem |
|
765 |
#label: ''Help'' |
|
766 |
#translateLabel: true |
|
767 |
#startGroup: #right |
|
768 |
#submenu: |
|
769 |
#(#Menu |
|
770 |
#( |
|
771 |
#(#MenuItem |
|
772 |
#label: ''Documentation'' |
|
773 |
#translateLabel: true |
|
774 |
#value: #openDocumentation |
|
775 |
) |
|
776 |
#(#MenuItem |
|
777 |
#label: ''-'' |
|
778 |
) |
|
779 |
#(#MenuItem |
|
780 |
#label: ''About this Application'' |
|
781 |
#translateLabel: true |
|
782 |
#value: #openAboutThisApplication |
|
783 |
) |
|
784 |
) nil |
|
785 |
nil |
|
786 |
) |
|
787 |
) |
|
788 |
) nil |
|
789 |
nil |
|
790 |
) |
|
791 |
'. |
|
792 |
! |
|
793 |
||
794 |
initialWindowSpecMethodSourceForApplications |
|
795 |
^ |
|
796 |
'windowSpec |
|
797 |
"This resource specification was automatically generated by the CodeGeneratorTool." |
|
798 |
||
799 |
"Do not manually edit this!! If it is corrupted, |
|
800 |
the UIPainter may not be able to read the specification." |
|
801 |
||
802 |
" |
|
803 |
UIPainter new openOnClass:%1 andSelector:#windowSpec |
|
804 |
" |
|
805 |
||
806 |
<resource: #canvas> |
|
807 |
||
808 |
^ #(#FullSpec |
|
809 |
#window: |
|
810 |
#(#WindowSpec |
|
811 |
#name: ''%1'' |
|
812 |
#layout: #(#LayoutFrame 204 0 162 0 503 0 461 0) |
|
813 |
#label: ''%1'' |
|
814 |
#min: #(#Point 10 10) |
|
815 |
#max: #(#Point 1024 768) |
|
816 |
#bounds: #(#Rectangle 204 162 504 462) |
|
817 |
#menu: #mainMenu |
|
818 |
#usePreferredExtent: false |
|
819 |
) |
|
820 |
#component: |
|
821 |
#(#SpecCollection |
|
822 |
#collection: #() |
|
823 |
) |
|
824 |
) |
|
825 |
'. |
|
826 |
! |
|
827 |
||
828 |
initialWindowSpecMethodSourceForDialogs |
|
829 |
^ |
|
830 |
'windowSpec |
|
831 |
"This resource specification was automatically generated by the CodeGeneratorTool." |
|
832 |
||
833 |
"Do not manually edit this!! If it is corrupted, |
|
834 |
the UIPainter may not be able to read the specification." |
|
835 |
||
836 |
" |
|
837 |
UIPainter new openOnClass:%1 andSelector:#windowSpec |
|
838 |
" |
|
839 |
||
840 |
<resource: #canvas> |
|
841 |
||
842 |
^ |
|
843 |
||
844 |
#(#FullSpec |
|
845 |
#window: |
|
846 |
#(#WindowSpec |
|
847 |
#name: ''%1'' |
|
848 |
#layout: #(#LayoutFrame 221 0 118 0 520 0 417 0) |
|
849 |
#level: 0 |
|
850 |
#label: ''%1'' |
|
851 |
#min: #(#Point 10 10) |
|
852 |
#max: #(#Point 1024 768) |
|
853 |
#bounds: #(#Rectangle 221 118 521 418) |
|
854 |
#usePreferredExtent: false |
|
855 |
) |
|
856 |
#component: |
|
857 |
#(#SpecCollection |
|
858 |
#collection: |
|
859 |
#( |
|
860 |
#(#HorizontalPanelViewSpec |
|
861 |
#name: ''buttonPanel'' |
|
862 |
#layout: #(#LayoutFrame 0 0.0 -45 1 0 1.0 0 1.0) |
|
863 |
#component: |
|
864 |
#(#SpecCollection |
|
865 |
#collection: |
|
866 |
#( |
|
867 |
#(#ActionButtonSpec |
|
868 |
#name: ''cancelButton'' |
|
869 |
#label: ''Cancel'' |
|
870 |
#tabable: true |
|
871 |
#translateLabel: true |
|
872 |
#model: #cancel |
|
873 |
#extent: #(#Point 125 22) |
|
874 |
) |
|
875 |
#(#ActionButtonSpec |
|
876 |
#name: ''okButton'' |
|
877 |
#label: ''OK'' |
|
878 |
#tabable: true |
|
879 |
#translateLabel: true |
|
880 |
#isDefault: true |
|
881 |
#model: #accept |
|
882 |
#extent: #(#Point 125 22) |
|
883 |
) |
|
884 |
) |
|
885 |
) |
|
886 |
#reverseOrderIfOKAtLeft: true |
|
887 |
#horizontalLayout: #spreadSpaceMax |
|
888 |
#verticalLayout: #center |
|
889 |
#horizontalSpace: 3 |
|
890 |
#verticalSpace: 3 |
|
891 |
) |
|
892 |
) |
|
893 |
) |
|
894 |
) |
|
895 |
'. |
|
896 |
! ! |
|
897 |
||
898 |
!CodeGeneratorTool class methodsFor:'code generation - individual methods'! |
|
899 |
||
900 |
createAcceptVisitorMethod:selector in:aClass |
|
901 |
"create an acceptVisitor: method |
|
902 |
(I'm tired of typing)" |
|
903 |
||
904 |
aClass isMeta ifTrue:[self halt]. |
|
905 |
||
906 |
(aClass includesSelector:#'acceptVisitor:') ifFalse:[ |
|
907 |
self |
|
908 |
compile: |
|
909 |
(('acceptVisitor:aVisitor |
|
910 |
"Double dispatch back to the visitor, passing my type encoded in |
|
911 |
the selector (visitor pattern)" |
|
912 |
||
913 |
"stub code automatically generated - please change if required" |
|
914 |
||
915 |
^ aVisitor %1self |
|
916 |
') bindWith:selector) |
|
917 |
forClass:aClass |
|
918 |
inCategory:'visiting'. |
|
919 |
] |
|
920 |
! |
|
921 |
||
922 |
createAcceptVisitorMethodIn:aClass |
|
923 |
"create an acceptVisitor: method |
|
924 |
(I'm tired of typing)" |
|
925 |
||
926 |
self |
|
927 |
createAcceptVisitorMethod:('visit' , aClass nameWithoutPrefix , ':') asSymbol |
|
928 |
in:aClass |
|
929 |
! |
|
930 |
||
931 |
createCopyrightMethodFor:aClass |
|
932 |
"add copyright method containing your/your companies |
|
933 |
copyright template but only if not already present. |
|
934 |
this is only added, if specified in the |
|
935 |
COPYRIGHT_TEMPLATE_FILE resources." |
|
936 |
||
937 |
|fn txt| |
|
938 |
||
939 |
(aClass includesSelector:#copyright) ifFalse:[ |
|
940 |
fn := SystemBrowser classResources at:#'COPYRIGHT_TEMPLATE_FILE' default:nil. |
|
941 |
fn notNil ifTrue:[ |
|
942 |
fn := fn asFilename. |
|
943 |
fn exists ifTrue:[ |
|
944 |
txt := fn contents asString |
|
945 |
] |
|
946 |
]. |
|
947 |
||
948 |
txt notNil ifTrue:[ |
|
949 |
txt := txt bindWith:(Date today year). |
|
950 |
self compile: |
|
951 |
'copyright |
|
952 |
" |
|
953 |
' , txt , ' |
|
954 |
" |
|
955 |
' forClass:aClass |
|
956 |
inCategory:'documentation'. |
|
957 |
] |
|
958 |
]. |
|
959 |
! |
|
960 |
||
961 |
createDocumentationMethodFor:aClass |
|
962 |
"add documentation method containing doc template |
|
963 |
but only if not already present." |
|
964 |
||
965 |
|userName loginName hostName emailAddress| |
|
966 |
||
967 |
(aClass includesSelector:#documentation) ifFalse:[ |
|
968 |
userName := OperatingSystem getFullUserName. |
|
969 |
loginName := OperatingSystem getLoginName. |
|
970 |
hostName := OperatingSystem getHostName. |
|
971 |
emailAddress := loginName , '@' , hostName. |
|
972 |
||
973 |
self compile: |
|
974 |
'documentation |
|
975 |
" |
|
976 |
documentation to be added. |
|
977 |
||
978 |
[author:] |
|
979 |
' , userName |
|
980 |
, ' (' , emailAddress , ')' , ' |
|
981 |
||
982 |
[instance variables:] |
|
983 |
||
984 |
[class variables:] |
|
985 |
||
986 |
[see also:] |
|
987 |
||
988 |
" |
|
989 |
' forClass:aClass |
|
990 |
inCategory:'documentation'. |
|
991 |
]. |
|
992 |
! |
|
993 |
||
994 |
createExamplesMethodFor:aClass |
|
995 |
"add examples method containing examples template |
|
996 |
but only if not already present." |
|
997 |
||
998 |
|fragment| |
|
999 |
||
1000 |
(aClass includesSelector:#examples) ifFalse:[ |
|
1001 |
(aClass theNonMetaclass isSubclassOf:ApplicationModel) ifTrue:[ |
|
1002 |
fragment := ' Starting the application: |
|
1003 |
[exBegin] |
|
1004 |
' , aClass theNonMetaclass name , ' open |
|
1005 |
||
1006 |
[exEnd] |
|
1007 |
' |
|
1008 |
] ifFalse:[ |
|
1009 |
fragment := '' |
|
1010 |
]. |
|
1011 |
||
1012 |
self |
|
1013 |
compile: |
|
1014 |
'examples |
|
1015 |
" |
|
1016 |
' , fragment , ' |
|
1017 |
more examples to be added: |
|
1018 |
[exBegin] |
|
1019 |
... add code fragment for |
|
1020 |
... executable example here ... |
|
1021 |
[exEnd] |
|
1022 |
" |
|
1023 |
' |
|
1024 |
forClass:aClass |
|
1025 |
inCategory:'documentation'. |
|
1026 |
]. |
|
1027 |
! |
|
1028 |
||
3822
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
1029 |
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
|
1030 |
|imageStoreStream mthd imageKey category| |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
1031 |
|
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
1032 |
anImage storeOn: (imageStoreStream := WriteStream on: ''). |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
1033 |
|
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
1034 |
"/ 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
|
1035 |
category := 'image specs'. |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
1036 |
(mthd := aClass compiledMethodAt:sel) notNil ifTrue:[ |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
1037 |
category := mthd category. |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
1038 |
]. |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
1039 |
|
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
1040 |
imageKey := (aClass name, ' ', sel) asSymbol. |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
1041 |
Icon constantNamed: imageKey put:nil. |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
1042 |
aClass |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
1043 |
compile: ((sel, |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
1044 |
'\', comment, |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
1045 |
'\\' , |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
1046 |
' "\', |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
1047 |
' self ' , sel , ' inspect\', |
3823 | 1048 |
' ImageEditor openOnClass:self andSelector:#', sel, '\', |
3822
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
1049 |
' Icon flushCachedIcons', |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
1050 |
'\ "', |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
1051 |
'\\', |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
1052 |
' <resource: #image>', |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
1053 |
'\\', |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
1054 |
' ^Icon\') withCRs, |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
1055 |
' constantNamed:#''', imageKey, '''\' withCRs, |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
1056 |
' ifAbsentPut:[', imageStoreStream contents, ']') |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
1057 |
classified: category. |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
1058 |
! |
4e9f2f69875f
code generation for icons moved from ImageEditor
Claus Gittinger <cg@exept.de>
parents:
3804
diff
changeset
|
1059 |
|
3712 | 1060 |
createInitialHistoryMethodFor:aClass |
1061 |
"add history method containing created-entry |
|
1062 |
but only if not already present." |
|
1063 |
||
1064 |
(aClass includesSelector:#history) ifFalse:[ |
|
1065 |
HistoryManager notNil ifTrue:[ |
|
1066 |
HistoryManager createInitialHistoryMethodIn:aClass |
|
1067 |
]. |
|
1068 |
]. |
|
1069 |
! |
|
1070 |
||
4512 | 1071 |
createInstanceCreationMethodWithSetupFor:selector category:category in:aMetaClass |
1072 |
"add an inst-creation method" |
|
1073 |
||
1074 |
|template| |
|
1075 |
||
1076 |
(aMetaClass includesSelector:selector) ifFalse:[ |
|
1077 |
template := Parser methodSpecificationForSelector:selector. |
|
1078 |
self |
|
1079 |
compile: |
|
1080 |
template , ' |
|
1081 |
^ self new ' , template , ' |
|
1082 |
' |
|
1083 |
forClass:aMetaClass |
|
1084 |
inCategory:category. |
|
1085 |
]. |
|
1086 |
! |
|
1087 |
||
3712 | 1088 |
createMultiSetterMethodFor:aCollectionOfVarNames in:aClass |
1089 |
"create a multi-setter method for instvars." |
|
1090 |
||
1091 |
|source| |
|
1092 |
||
1093 |
source := ''. |
|
1094 |
aCollectionOfVarNames do:[:eachVar | |
|
1095 |
source := source , (eachVar , ':' , eachVar , 'Arg '). |
|
1096 |
]. |
|
1097 |
source := source , Character cr. |
|
1098 |
source := source , (' "set instance variables (automatically generated)"' , Character cr , Character cr). |
|
1099 |
aCollectionOfVarNames do:[:eachVar | |
|
1100 |
source := source , (' ' , eachVar , ' := ' , eachVar , 'Arg.' , Character cr). |
|
1101 |
]. |
|
1102 |
self compile:source forClass:aClass inCategory:'accessing'. |
|
1103 |
! |
|
1104 |
||
3800
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
1105 |
createSubclassResponsibilityMethodFor:aSelector category:cat in:aClass |
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
1106 |
"add a subclassResponsibility method; |
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
1107 |
but only if not already present." |
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
1108 |
|
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
1109 |
(aClass includesSelector:aSelector) ifFalse:[ |
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
1110 |
|
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
1111 |
self compile: |
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
1112 |
(Method methodDefinitionTemplateForSelector:aSelector) , |
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
1113 |
' |
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
1114 |
"raise an error: must be redefined in concrete subclass(es)" |
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
1115 |
|
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
1116 |
^ self subclassResponsibility |
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
1117 |
' |
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
1118 |
forClass:aClass |
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
1119 |
inCategory:cat. |
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
1120 |
]. |
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
1121 |
! |
a5c75c369855
added generateSubclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
1122 |
|
3712 | 1123 |
createUpdateMethodIn:aClass |
1124 |
"create an update:with:from:-method |
|
1125 |
(I'm tired of typing)" |
|
1126 |
||
1127 |
(aClass includesSelector:#'update:with:from:') ifFalse:[ |
|
1128 |
self |
|
1129 |
compile: |
|
1130 |
'update:something with:aParameter from:changedObject |
|
1131 |
"Invoked when an object that I depend upon sends a change notification." |
|
1132 |
||
1133 |
"stub code automatically generated - please change as required" |
|
1134 |
||
1135 |
"/ changedObject == someOfMyValueHolders ifTrue:[ |
|
1136 |
"/ self doSomethingApropriate |
|
1137 |
"/ ^ self |
|
1138 |
"/ ]. |
|
1139 |
super update:something with:aParameter from:changedObject |
|
1140 |
' |
|
1141 |
forClass:aClass |
|
1142 |
inCategory:'change & update'. |
|
1143 |
] |
|
1144 |
! |
|
1145 |
||
1146 |
createVersionMethodFor:aClass |
|
1147 |
"add version method containing RCS template |
|
1148 |
but only if not already present and its not a private class." |
|
1149 |
||
1150 |
aClass isPrivate ifFalse:[ |
|
1151 |
(aClass includesSelector:#version) ifFalse:[ |
|
1152 |
self compile: |
|
1153 |
'version |
|
1154 |
^ ''$' , 'Header$'' |
|
1155 |
' |
|
1156 |
forClass:aClass |
|
1157 |
inCategory:'documentation'. |
|
1158 |
] |
|
1159 |
]. |
|
1160 |
! ! |
|
1161 |
||
1162 |
!CodeGeneratorTool class methodsFor:'compilation'! |
|
1163 |
||
1164 |
canUseRefactoringSupport |
|
1165 |
^ RefactoryChangeManager notNil and:[RefactoryChangeManager isLoaded] |
|
1166 |
! |
|
1167 |
||
1168 |
compile:theCode forClass:aClass inCategory:cat |
|
1169 |
|change| |
|
1170 |
||
1171 |
self canUseRefactoringSupport ifFalse:[ |
|
3716 | 1172 |
aClass compile:theCode classified:cat. |
3712 | 1173 |
^ self. |
1174 |
]. |
|
1175 |
||
3716 | 1176 |
change := InteractiveAddMethodChange compile:(theCode asString) in:aClass classified:cat. |
3712 | 1177 |
RefactoryChangeManager instance performChange:change. |
1178 |
! ! |
|
1179 |
||
4108
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
1180 |
!CodeGeneratorTool class methodsFor:'private'! |
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
1181 |
|
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
1182 |
privCreateClassResponsibleProtocolFor:aClass |
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
1183 |
"create stubs for the required protocol aClass may be a a MetaClass |
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
1184 |
or a NonMetaClass" |
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
1185 |
|
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
1186 |
|selectors| |
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
1187 |
|
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
1188 |
selectors := IdentitySet new. |
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
1189 |
aClass allSuperclassesDo:[:cls | |
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
1190 |
cls methodDictionary keysAndValuesDo:[:sel :mthd | |
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
1191 |
(mthd sends:#subclassResponsibility) ifTrue:[ |
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
1192 |
selectors add:sel. |
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
1193 |
] |
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
1194 |
] |
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
1195 |
]. |
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
1196 |
|
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
1197 |
selectors do:[:eachSelector | |
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
1198 |
|cat comment mthd implClass| |
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
1199 |
|
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
1200 |
implClass := aClass whichClassImplements:eachSelector. |
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
1201 |
implClass ~~ aClass ifTrue:[ |
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
1202 |
mthd := implClass compiledMethodAt:eachSelector. |
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
1203 |
(mthd sends:#subclassResponsibility) ifTrue:[ |
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
1204 |
cat := mthd category. |
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
1205 |
comment := mthd methodComment. |
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
1206 |
comment size == 0 ifTrue:[ |
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
1207 |
comment := 'Superclass says that I am responsible to implement this method' |
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
1208 |
]. |
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
1209 |
|
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
1210 |
self |
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
1211 |
compile: |
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
1212 |
(Method methodDefinitionTemplateForSelector:eachSelector), Character cr, ' "', comment, |
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
1213 |
'" |
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
1214 |
|
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
1215 |
self shouldImplement |
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
1216 |
' |
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
1217 |
forClass:aClass |
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
1218 |
inCategory:cat. |
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
1219 |
]. |
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
1220 |
]. |
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
1221 |
]. |
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
1222 |
! ! |
19af32811dfd
Generate minimal protocol classes for metaclass.
Stefan Vogel <sv@exept.de>
parents:
3823
diff
changeset
|
1223 |
|
3712 | 1224 |
!CodeGeneratorTool class methodsFor:'documentation'! |
1225 |
||
1226 |
version |
|
4590 | 1227 |
^ '$Header: /cvs/stx/stx/libtool/CodeGeneratorTool.st,v 1.12 2003-02-21 09:54:32 cg Exp $' |
3712 | 1228 |
! ! |