author | Stefan Vogel <sv@exept.de> |
Wed, 22 Feb 2006 10:59:23 +0100 | |
changeset 9187 | 9e9eb3e21448 |
parent 9114 | 51f597570dda |
child 9238 | bc93f81da495 |
permissions | -rw-r--r-- |
7592 | 1 |
" |
2 |
COPYRIGHT (c) 2001 by eXept Software AG |
|
3 |
All Rights Reserved |
|
4 |
||
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
5905 | 13 |
"{ Package: 'stx:libbasic' }" |
14 |
||
15 |
Object subclass:#ClassBuilder |
|
7617 | 16 |
instanceVariableNames:'metaclass className environment superClass instanceVariableNames |
17 |
variable words pointers classVariableNames poolDictionaries |
|
18 |
category comment changed classInstanceVariableNames oldMetaClass |
|
9114 | 19 |
oldClass oldPoolDictionaries oldSuperClass oldClassVars |
20 |
oldInstVars realNewName buildPrivateClass buildingPrivateClass |
|
21 |
nameKey newSuperClass superClassChange newClassVars newInstVars |
|
22 |
classVarChange instVarChange recompileGlobalAccessTo |
|
23 |
oldClassToBecomeNew' |
|
6057 | 24 |
classVariableNames:'' |
25 |
poolDictionaries:'' |
|
26 |
category:'Kernel-Support' |
|
5905 | 27 |
! |
28 |
||
7592 | 29 |
!ClassBuilder class methodsFor:'documentation'! |
30 |
||
31 |
copyright |
|
32 |
" |
|
33 |
COPYRIGHT (c) 2001 by eXept Software AG |
|
34 |
All Rights Reserved |
|
35 |
||
36 |
This software is furnished under a license and may be used |
|
37 |
only in accordance with the terms of that license and with the |
|
38 |
inclusion of the above copyright notice. This software may not |
|
39 |
be provided or otherwise made available to, or used by, any |
|
40 |
other person. No title to or ownership of the software is |
|
41 |
hereby transferred. |
|
42 |
" |
|
43 |
! ! |
|
5905 | 44 |
|
45 |
!ClassBuilder class methodsFor:'checks'! |
|
46 |
||
5907 | 47 |
checkForAliasesOf:oldClass with:newClass |
48 |
"oldClass changed its identity (now use newClass). |
|
49 |
check if there are any global aliases, which should also be changed" |
|
50 |
||
51 |
Smalltalk keysAndValuesDo:[:nm :o | |
|
52 |
o == oldClass ifTrue:[ |
|
53 |
nm ~~ oldClass name ifTrue:[ |
|
54 |
(self confirm:('The global/classVar `' , nm , ''' is an alias for ' , oldClass name , '.\\Change it to the new class ?') withCRs) |
|
55 |
ifTrue:[ |
|
56 |
Smalltalk at:nm put:newClass |
|
57 |
] |
|
58 |
] |
|
59 |
] |
|
60 |
]. |
|
61 |
! |
|
62 |
||
5905 | 63 |
differentInstanceVariableOffsetsIn:class1 and:class2 |
64 |
"return a set of instance variable names which have different |
|
65 |
positions in class1 and class2. |
|
66 |
Also, variables which are only present in one class are returned. |
|
67 |
This is used to find methods which need recompilation after a |
|
68 |
change in the instance variable layout." |
|
69 |
||
70 |
|offsets1 offsets2 changeSet| |
|
71 |
||
72 |
changeSet := Set new. |
|
73 |
||
74 |
" |
|
75 |
collect the instvar-indices in the old and new class |
|
76 |
" |
|
77 |
offsets1 := class1 instanceVariableOffsets. |
|
78 |
offsets2 := class2 instanceVariableOffsets. |
|
79 |
||
80 |
" |
|
81 |
compute the changeset as a set of instance variables, |
|
82 |
which have a different position |
|
83 |
" |
|
84 |
offsets1 keysAndValuesDo:[:varName :varIndex | |
|
85 |
(offsets2 includesKey:varName) ifFalse:[ |
|
86 |
changeSet add:varName |
|
87 |
] ifTrue:[ |
|
88 |
(varIndex ~~ (offsets2 at:varName)) ifTrue:[ |
|
89 |
changeSet add:varName |
|
90 |
] |
|
91 |
] |
|
92 |
]. |
|
93 |
offsets2 keysAndValuesDo:[:varName :varIndex | |
|
94 |
(offsets1 includesKey:varName) ifFalse:[ |
|
95 |
changeSet add:varName |
|
96 |
] ifTrue:[ |
|
97 |
(varIndex ~~ (offsets1 at:varName)) ifTrue:[ |
|
98 |
changeSet add:varName |
|
99 |
] |
|
100 |
] |
|
101 |
]. |
|
102 |
^ changeSet |
|
103 |
||
104 |
" |
|
105 |
View class |
|
106 |
differentInstanceVariableOffsetsIn:View |
|
107 |
and:StandardSystemView |
|
108 |
View class |
|
109 |
differentInstanceVariableOffsetsIn:Object |
|
110 |
and:Point |
|
111 |
" |
|
112 |
! ! |
|
113 |
||
114 |
!ClassBuilder class methodsFor:'recompiling'! |
|
115 |
||
6024 | 116 |
copyInvalidatedMethodsFrom:oldClass for:newClass |
117 |
"copy all methods from oldClass to newClass and change their code |
|
118 |
to a trap method reporting an error. |
|
119 |
This is done when a class has changed its layout or inheritance, |
|
120 |
before recompilation is attempted. |
|
121 |
This allows us to keep the source while trapping uncompilable (due to |
|
122 |
now undefined instvars) methods. Later compilation of these methods will show |
|
123 |
an error on the transcript and lead to the debugger once called." |
|
124 |
||
125 |
|trap trapCode trapByteCode oldMethod newMethod |
|
126 |
oldDict newDict| |
|
127 |
||
128 |
oldDict := oldClass methodDictionary. |
|
129 |
newDict := MethodDictionary new:oldDict size. |
|
130 |
||
131 |
oldDict keysAndValuesDo:[ :sel :mthd | |
|
132 |
trap := mthd trapMethodForNumArgs:(mthd numArgs). |
|
133 |
trapCode := trap code. |
|
134 |
trapByteCode := trap byteCode. |
|
135 |
||
136 |
mthd isWrapped ifTrue:[ |
|
137 |
oldMethod := mthd originalMethod |
|
138 |
] ifFalse:[ |
|
139 |
oldMethod := mthd. |
|
140 |
]. |
|
141 |
||
142 |
newMethod := oldMethod copy. |
|
143 |
newMethod makeInvalid. |
|
144 |
newDict at:sel put:newMethod |
|
145 |
]. |
|
146 |
||
147 |
newClass methodDictionary:newDict. |
|
148 |
||
149 |
"Modified: 12.6.1996 / 10:44:27 / stefan" |
|
150 |
"Modified: 4.11.1996 / 22:55:57 / cg" |
|
151 |
! |
|
152 |
||
5905 | 153 |
copyInvalidatedMethodsFrom:oldClass for:newClass accessingAny:setOfNames |
154 |
"copy all methods from oldClass to newClass. Those methods accessing |
|
155 |
a variable in setOfNames will be copied as invalid method, leading to |
|
156 |
a trap when its executed. This is used when a class has changed its |
|
157 |
layout for all methods which are affected by the change." |
|
158 |
||
159 |
self copyInvalidatedMethodsFrom:oldClass |
|
160 |
for:newClass |
|
161 |
accessingAny:setOfNames |
|
162 |
orSuper:false |
|
163 |
! |
|
164 |
||
165 |
copyInvalidatedMethodsFrom:oldClass for:newClass accessingAny:setOfNames orSuper:superBoolean |
|
166 |
"copy all methods from oldClass to newClass. |
|
167 |
Those methods accessing a variable in setOfNames will be copied as invalid method, |
|
168 |
leading to a trap when its executed. If superBoolean is true, this is also done |
|
169 |
for methods accessing super. This is used when a class has changed its |
|
170 |
layout for all methods which are affected by the change." |
|
171 |
||
172 |
|p source mustInvalidate |
|
173 |
oldMethod newMethod methodDict newMethodDict nNames| |
|
174 |
||
175 |
methodDict := oldClass methodDictionary. |
|
176 |
newMethodDict := methodDict copy. |
|
177 |
nNames := setOfNames size. |
|
178 |
||
179 |
methodDict keysAndValuesDo:[:selector :method | |
|
180 |
method isWrapped ifTrue:[ |
|
181 |
oldMethod := method originalMethod |
|
182 |
] ifFalse:[ |
|
183 |
oldMethod := method |
|
184 |
]. |
|
185 |
||
186 |
"before parsing (which may take some time), |
|
187 |
do a string search if its only one variable, |
|
188 |
we are looking for. |
|
189 |
Could look for more than one variable by string compare, but then |
|
190 |
parsing it right away may be faster ..." |
|
191 |
||
192 |
source := oldMethod source. |
|
193 |
((nNames == 1) and:[superBoolean not]) ifTrue:[ |
|
194 |
mustInvalidate := (source findString:(setOfNames first)) ~~ 0. |
|
195 |
] ifFalse:[ |
|
196 |
((nNames == 0) and:[superBoolean]) ifTrue:[ |
|
197 |
mustInvalidate := (source findString:'super') ~~ 0. |
|
198 |
] ifFalse:[ |
|
199 |
mustInvalidate := true |
|
200 |
]. |
|
201 |
]. |
|
202 |
||
203 |
mustInvalidate ifTrue:[ |
|
204 |
"we have to parse it ..." |
|
205 |
p := Parser parseMethod:source in:newClass. |
|
206 |
(p isNil |
|
207 |
or:[(p usedVars includesAny:setOfNames) |
|
208 |
or:[superBoolean and:[p usesSuper]]]) ifFalse:[ |
|
209 |
mustInvalidate := false |
|
210 |
] |
|
211 |
]. |
|
212 |
||
213 |
mustInvalidate ifTrue:[ |
|
214 |
newMethod := oldMethod copy. |
|
215 |
"/ Smalltalk silentLoading ifFalse:[ |
|
216 |
"/ Transcript showCR:'invalidating ' , selector , '...'. |
|
217 |
"/ ]. |
|
218 |
newMethod makeInvalid. |
|
219 |
] ifFalse:[ |
|
220 |
newMethod := oldMethod. |
|
221 |
newMethod mclass:nil. |
|
222 |
]. |
|
223 |
newMethodDict at:selector put:newMethod |
|
224 |
]. |
|
225 |
newClass methodDictionary:newMethodDict. |
|
226 |
||
227 |
"Modified: 7.6.1996 / 08:33:52 / stefan" |
|
228 |
"Modified: 19.6.1997 / 18:27:09 / cg" |
|
229 |
! |
|
230 |
||
231 |
copyMethodsFrom:oldClass for:newClass |
|
232 |
"copy all methods from oldClass to newClass. |
|
233 |
This is used for class-methods when a class has changed, but its metaclass is |
|
234 |
unaffected (i.e. classVars/inheritance have not changed) so there is no need |
|
235 |
to recompile the class methods." |
|
236 |
||
237 |
newClass methodDictionary:(oldClass methodDictionary copy). |
|
8467 | 238 |
newClass methodDictionary do:[:mthd | mthd mclass:nil.]. |
5905 | 239 |
|
8467 | 240 |
"Modified: / 05-08-2004 / 19:52:28 / stefan" |
5905 | 241 |
! |
242 |
||
243 |
recompileGlobalAccessorsTo:aGlobalKey in:aNamespace except:someClass |
|
244 |
"when a new class enters a namespace, all accessors to the same-named |
|
245 |
class in that namespace must be recompiled" |
|
246 |
||
247 |
aNamespace allPrivateClassesDo:[:aClass | |
|
248 |
aClass ~~ someClass ifTrue:[ |
|
249 |
aClass isLoaded ifTrue:[ |
|
250 |
||
251 |
"/ Smalltalk silentLoading ifFalse:[ |
|
252 |
"/ Transcript showCR:'recompiling methods in ''' , aClass name , ''' accessing ''' , aGlobalKey , ''''. |
|
253 |
"/ Transcript endEntry. |
|
254 |
"/ ]. |
|
255 |
||
256 |
aClass recompileMethodsAccessingGlobal:aGlobalKey. |
|
257 |
aClass class recompileMethodsAccessingGlobal:aGlobalKey. |
|
258 |
"/ actually - must eventually recompile USERS of this namespace too |
|
259 |
] |
|
260 |
] |
|
6408
32ed2e990c09
fixed recompilation of accessors when a private class shadows a global
Claus Gittinger <cg@exept.de>
parents:
6385
diff
changeset
|
261 |
]. |
6414 | 262 |
aNamespace isNameSpace ifFalse:[ |
6408
32ed2e990c09
fixed recompilation of accessors when a private class shadows a global
Claus Gittinger <cg@exept.de>
parents:
6385
diff
changeset
|
263 |
aNamespace recompileMethodsAccessingGlobal:aGlobalKey. |
32ed2e990c09
fixed recompilation of accessors when a private class shadows a global
Claus Gittinger <cg@exept.de>
parents:
6385
diff
changeset
|
264 |
aNamespace class recompileMethodsAccessingGlobal:aGlobalKey. |
32ed2e990c09
fixed recompilation of accessors when a private class shadows a global
Claus Gittinger <cg@exept.de>
parents:
6385
diff
changeset
|
265 |
]. |
5905 | 266 |
|
267 |
"Modified: 31.1.1997 / 11:22:57 / cg" |
|
268 |
! |
|
269 |
||
270 |
recompileMachineCodeMethodsIn:aClass |
|
271 |
"recompile all machine-code methods in aClass." |
|
272 |
||
273 |
aClass recompileMethodsWithMachineCode. |
|
274 |
aClass class recompileMethodsWithMachineCode. |
|
275 |
! ! |
|
276 |
||
277 |
!ClassBuilder methodsFor:'accessing'! |
|
278 |
||
8724 | 279 |
classClass |
280 |
^ Class |
|
281 |
! |
|
282 |
||
7617 | 283 |
metaclass:metaclassOrASubclassOfIt |
284 |
metaclass := metaclassOrASubclassOfIt. |
|
285 |
! |
|
286 |
||
6825 | 287 |
name:newName inEnvironment:aSystemDictionaryOrClass subclassOf:aClass instanceVariableNames:stringOfInstVarNames variable:variableBoolean words:wordsBoolean pointers:pointersBoolean classVariableNames:stringOfClassVarNames poolDictionaries:stringOfPoolNames category:categoryString comment:commentString changed:changedBoolean classInstanceVariableNames:stringOfClassInstVarNamesOrNil |
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
288 |
className := newName asSymbol. |
5905 | 289 |
environment := aSystemDictionaryOrClass. |
290 |
superClass := aClass. |
|
291 |
instanceVariableNames := stringOfInstVarNames. |
|
292 |
variable := variableBoolean. |
|
293 |
words := wordsBoolean. |
|
294 |
pointers := pointersBoolean. |
|
295 |
classVariableNames := stringOfClassVarNames. |
|
296 |
poolDictionaries := stringOfPoolNames. |
|
297 |
category := categoryString. |
|
298 |
comment := commentString. |
|
299 |
changed := changedBoolean. |
|
300 |
classInstanceVariableNames := stringOfClassInstVarNamesOrNil |
|
5907 | 301 |
! |
302 |
||
303 |
oldMetaclass:aMetaclass instanceVariableNames:stringOfInstVarNames |
|
7516
42c5b199db20
change notifications for classInstVar change
Claus Gittinger <cg@exept.de>
parents:
7487
diff
changeset
|
304 |
|instrVarNames| |
42c5b199db20
change notifications for classInstVar change
Claus Gittinger <cg@exept.de>
parents:
7487
diff
changeset
|
305 |
|
5907 | 306 |
oldMetaClass := aMetaclass. |
7516
42c5b199db20
change notifications for classInstVar change
Claus Gittinger <cg@exept.de>
parents:
7487
diff
changeset
|
307 |
instrVarNames := oldMetaClass superclass allInstanceVariableNames asBag. |
42c5b199db20
change notifications for classInstVar change
Claus Gittinger <cg@exept.de>
parents:
7487
diff
changeset
|
308 |
instrVarNames addAll:(stringOfInstVarNames asStringCollection). |
42c5b199db20
change notifications for classInstVar change
Claus Gittinger <cg@exept.de>
parents:
7487
diff
changeset
|
309 |
(instrVarNames contents includesValue:2) ifTrue:[ |
42c5b199db20
change notifications for classInstVar change
Claus Gittinger <cg@exept.de>
parents:
7487
diff
changeset
|
310 |
self error:'duplicate variable name'. |
42c5b199db20
change notifications for classInstVar change
Claus Gittinger <cg@exept.de>
parents:
7487
diff
changeset
|
311 |
]. |
42c5b199db20
change notifications for classInstVar change
Claus Gittinger <cg@exept.de>
parents:
7487
diff
changeset
|
312 |
|
5907 | 313 |
instanceVariableNames := stringOfInstVarNames. |
5905 | 314 |
! ! |
315 |
||
316 |
!ClassBuilder methodsFor:'building'! |
|
317 |
||
318 |
buildClass |
|
319 |
||
320 |
"this is the main workhorse for installing new classes - special care |
|
321 |
has to be taken, when changing an existing classes definition. In this |
|
322 |
case, some or all of the methods and subclasses methods have to be |
|
323 |
recompiled. |
|
324 |
Also, the old class(es) are still kept (but not accessable as a global), |
|
325 |
to allow existing instances some life. |
|
326 |
This might change in the future. |
|
327 |
" |
|
328 |
||
8743
3992e2ac5c7f
care for the case when defining a class with a name-space name but
Claus Gittinger <cg@exept.de>
parents:
8724
diff
changeset
|
329 |
|newClass newMetaclass newComment| |
5905 | 330 |
|
331 |
"NOTICE: |
|
332 |
this method is too complex and should be splitted into managable pieces ... |
|
333 |
I dont like it anymore :-) |
|
334 |
(well, at least, its a good test for the compilers ability |
|
335 |
to handle big, complex methods ;-) |
|
336 |
take it as an example of bad coding style ... |
|
337 |
||
338 |
ST-80 uses a ClassBuilder object to collect the work and perform all updates; |
|
339 |
this method may be changed to do something similar in the future ... |
|
340 |
" |
|
341 |
||
342 |
self checkClassName. |
|
343 |
self checkValidSubclassing. |
|
344 |
||
7230
82934cb163d4
autoload is understood by all classes (dummy if already loaded)
Claus Gittinger <cg@exept.de>
parents:
7201
diff
changeset
|
345 |
environment notNil ifTrue:[ |
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
346 |
environment autoload "/ owner must be loaded |
5905 | 347 |
]. |
348 |
||
8764
1fe531dc199b
allow nil instance/class VariableNames
Claus Gittinger <cg@exept.de>
parents:
8743
diff
changeset
|
349 |
instanceVariableNames notNil ifTrue:[ |
1fe531dc199b
allow nil instance/class VariableNames
Claus Gittinger <cg@exept.de>
parents:
8743
diff
changeset
|
350 |
instanceVariableNames isString ifFalse:[ |
1fe531dc199b
allow nil instance/class VariableNames
Claus Gittinger <cg@exept.de>
parents:
8743
diff
changeset
|
351 |
instanceVariableNames := instanceVariableNames asStringWith:Character space |
1fe531dc199b
allow nil instance/class VariableNames
Claus Gittinger <cg@exept.de>
parents:
8743
diff
changeset
|
352 |
]. |
1fe531dc199b
allow nil instance/class VariableNames
Claus Gittinger <cg@exept.de>
parents:
8743
diff
changeset
|
353 |
] ifFalse:[ |
1fe531dc199b
allow nil instance/class VariableNames
Claus Gittinger <cg@exept.de>
parents:
8743
diff
changeset
|
354 |
instanceVariableNames := '' |
1fe531dc199b
allow nil instance/class VariableNames
Claus Gittinger <cg@exept.de>
parents:
8743
diff
changeset
|
355 |
]. |
1fe531dc199b
allow nil instance/class VariableNames
Claus Gittinger <cg@exept.de>
parents:
8743
diff
changeset
|
356 |
classVariableNames notNil ifTrue:[ |
1fe531dc199b
allow nil instance/class VariableNames
Claus Gittinger <cg@exept.de>
parents:
8743
diff
changeset
|
357 |
classVariableNames isString ifFalse:[ |
1fe531dc199b
allow nil instance/class VariableNames
Claus Gittinger <cg@exept.de>
parents:
8743
diff
changeset
|
358 |
classVariableNames := classVariableNames asStringWith:Character space |
1fe531dc199b
allow nil instance/class VariableNames
Claus Gittinger <cg@exept.de>
parents:
8743
diff
changeset
|
359 |
]. |
1fe531dc199b
allow nil instance/class VariableNames
Claus Gittinger <cg@exept.de>
parents:
8743
diff
changeset
|
360 |
] ifFalse:[ |
1fe531dc199b
allow nil instance/class VariableNames
Claus Gittinger <cg@exept.de>
parents:
8743
diff
changeset
|
361 |
classVariableNames := '' |
1fe531dc199b
allow nil instance/class VariableNames
Claus Gittinger <cg@exept.de>
parents:
8743
diff
changeset
|
362 |
]. |
1fe531dc199b
allow nil instance/class VariableNames
Claus Gittinger <cg@exept.de>
parents:
8743
diff
changeset
|
363 |
|
5905 | 364 |
(instanceVariableNames size > 0 |
365 |
or:[classVariableNames size > 0]) ifTrue:[ |
|
366 |
(self |
|
367 |
checkValidVarNamesFor:className |
|
368 |
subClassOf:superClass |
|
369 |
instVarNames:instanceVariableNames |
|
370 |
classVarNames:classVariableNames) |
|
371 |
ifFalse:[ |
|
372 |
^ nil |
|
373 |
]. |
|
374 |
]. |
|
375 |
||
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
376 |
(self determineNewName) ifFalse:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
377 |
^ nil. |
5905 | 378 |
]. |
379 |
||
380 |
(superClass notNil and:[realNewName = superClass name]) ifTrue:[ |
|
381 |
self error:'trying to create circular class definition'. |
|
382 |
^ nil |
|
383 |
]. |
|
384 |
||
385 |
"look, if it already exists as a class" |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
386 |
environment notNil ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
387 |
buildingPrivateClass ifFalse:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
388 |
oldClass := environment at:className ifAbsent:[nil]. |
5905 | 389 |
] ifTrue:[ |
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
390 |
oldClass := environment privateClassesAt:className. |
5905 | 391 |
] |
392 |
]. |
|
393 |
||
7528 | 394 |
(oldClass notNil and:[oldClass isNameSpace and:[oldClass ~~ Smalltalk]]) ifTrue:[ |
6713
6f197bcc0958
catch class exists as nameSpace
Claus Gittinger <cg@exept.de>
parents:
6514
diff
changeset
|
395 |
self error:'class exists as namespace'. |
6f197bcc0958
catch class exists as nameSpace
Claus Gittinger <cg@exept.de>
parents:
6514
diff
changeset
|
396 |
^ nil |
6f197bcc0958
catch class exists as nameSpace
Claus Gittinger <cg@exept.de>
parents:
6514
diff
changeset
|
397 |
]. |
6f197bcc0958
catch class exists as nameSpace
Claus Gittinger <cg@exept.de>
parents:
6514
diff
changeset
|
398 |
|
5905 | 399 |
(oldClass isBehavior and:[oldClass isLoaded not]) ifTrue:[ |
400 |
oldClassToBecomeNew := oldClass |
|
401 |
]. |
|
402 |
||
403 |
(oldClass isBehavior and:[oldClass isLoaded]) ifFalse:[ |
|
404 |
oldClass := nil. |
|
405 |
||
9098 | 406 |
(buildingPrivateClass and:[ParserFlags warnings and:[ParserFlags warnSTXSpecials]]) ifTrue:[ |
407 |
(self confirm:('Support for private classes is an ST/X extension.\\continue ?') withCRs) |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
408 |
ifFalse:[^ nil]. |
5905 | 409 |
]. |
410 |
] ifTrue:[ |
|
411 |
oldClass name ~= realNewName ifTrue:[ |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
412 |
(self confirm:(className , ' is an alias for ' , oldClass name , '\\continue ?') withCRs) |
5905 | 413 |
ifFalse:[^ nil]. |
414 |
oldClass := nil |
|
415 |
] ifFalse:[ |
|
6034
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
416 |
(self checkForCircularDefinitionFrom:oldClass) ifTrue:[ |
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
417 |
self error:'trying to create circular class definition'. |
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
418 |
^ nil |
5905 | 419 |
]. |
420 |
||
421 |
" |
|
422 |
warn, if it exists with different category and different instvars, |
|
423 |
and the existing is not an autoload class. |
|
424 |
Usually, this indicates that someone wants to create a new class with |
|
425 |
a name, which already exists (it happened a few times to myself, while |
|
426 |
I wanted to create a new class called ReturnNode ...). |
|
427 |
This will be much less of a problem, once multiple name spaces are |
|
428 |
implemented and classes can be put into separate packages. |
|
429 |
" |
|
430 |
oldClass isLoaded ifTrue:[ |
|
431 |
oldClass category ~= category ifTrue:[ |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
432 |
oldClass instanceVariableString asCollectionOfWords ~= instanceVariableNames asCollectionOfWords ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
433 |
(self confirm:'a class named ' , oldClass name , ' already exists -\\create (i.e. change) anyway ?' withCRs) |
5905 | 434 |
ifFalse:[ |
435 |
^ nil |
|
436 |
] |
|
437 |
] |
|
438 |
] |
|
439 |
]. |
|
440 |
||
441 |
"/ |
|
442 |
"/ hints - warn, if creating a variableSubclass of a Set |
|
443 |
"/ (common error - containers in ST/X do not use variable-slots) |
|
444 |
"/ |
|
445 |
((variable == true) and:[pointers]) ifTrue:[ |
|
446 |
(oldClass isKindOf:Set class) ifTrue:[ |
|
8743
3992e2ac5c7f
care for the case when defining a class with a name-space name but
Claus Gittinger <cg@exept.de>
parents:
8724
diff
changeset
|
447 |
(self confirm:('ST/X Set & Dictionary are not variable-classes.\Create %1 anyway ?' bindWith:className) withCRs) |
5905 | 448 |
ifFalse:[ |
449 |
^ nil |
|
450 |
] |
|
451 |
] |
|
452 |
] |
|
453 |
] |
|
454 |
]. |
|
455 |
||
456 |
"/ Check for some 'considered bad-style' things, like lower case names. |
|
457 |
"/ But only do these checks for new classes - |
|
458 |
"/ - thus, once confirmed, the warnings will not come again and again. |
|
459 |
||
460 |
"/ NOTICE: |
|
461 |
"/ I dont like the confirmers there - we need a notifying: argument, to give |
|
462 |
"/ the outer codeview a chance to highlight the error. |
|
463 |
"/ (but thats how its defined in the book - maybe I will change anyway). |
|
464 |
"/ - or use upQueries in future versions. |
|
465 |
||
466 |
oldClass isNil ifTrue:[ |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
467 |
(instanceVariableNames size > 0 or:[classVariableNames size > 0]) ifTrue:[ |
5905 | 468 |
(self |
469 |
checkConventionsFor:className |
|
470 |
subClassOf:superClass |
|
471 |
instVarNames:instanceVariableNames |
|
472 |
classVarNames:classVariableNames) |
|
473 |
ifFalse:[ |
|
474 |
^ nil |
|
475 |
] |
|
476 |
]. |
|
7132 | 477 |
]. |
5905 | 478 |
|
7132 | 479 |
(self |
480 |
checkInstvarRedefsWith:instanceVariableNames |
|
481 |
subclassOf:superClass |
|
482 |
old:oldClass |
|
483 |
name:className) ifFalse:[^ nil]. |
|
5905 | 484 |
|
8610 | 485 |
self checkValidPools. |
486 |
||
6514 | 487 |
newMetaclass := self instantiateMetaclass. |
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
488 |
newClass := self instantiateNewClassFrom:newMetaclass. |
5905 | 489 |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
490 |
(environment notNil and:[environment ~~ Smalltalk]) ifTrue:[ |
5905 | 491 |
newClass setName:realNewName. |
492 |
"/ |
|
493 |
"/ if that key exists in smalltalk, |
|
494 |
"/ must recompile everything in that nameSpace, |
|
495 |
"/ which refers to the unprefixed global. |
|
496 |
"/ |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
497 |
recompileGlobalAccessTo := className. |
5905 | 498 |
] ifFalse:[ |
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
499 |
newClass setName:className. |
5905 | 500 |
recompileGlobalAccessTo := nil. |
501 |
]. |
|
502 |
||
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
503 |
newComment := comment. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
504 |
newComment isNil ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
505 |
oldClass notNil ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
506 |
newComment := oldClass comment |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
507 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
508 |
]. |
5905 | 509 |
newClass setComment:newComment category:category. |
8610 | 510 |
poolDictionaries notEmptyOrNil ifTrue:[ |
511 |
newClass sharedPools:poolDictionaries |
|
512 |
]. |
|
5905 | 513 |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
514 |
"/ for new classes, we are almost done here |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
515 |
"/ (also for autoloaded classes) |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
516 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
517 |
(oldClass isNil or:[oldClass isLoaded not]) ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
518 |
self handleNewlyCreatedClass:newClass. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
519 |
^ newClass |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
520 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
521 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
522 |
"/ here comes the hard part - we are actually changing the |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
523 |
"/ definition of an existing class .... |
8610 | 524 |
"/ Try hard to get away WITHOUT recompiling, since it is both slow |
525 |
"/ and it makes all compiled code into interpreted (which is reJITed then)... |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
526 |
oldInstVars := oldClass instanceVariableString asCollectionOfWords. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
527 |
newInstVars := newClass instanceVariableString asCollectionOfWords. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
528 |
oldClassVars := oldClass classVariableString asCollectionOfWords. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
529 |
newClassVars := newClass classVariableString asCollectionOfWords. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
530 |
|
8610 | 531 |
"/ We are on the bright side of life, if the instance layout and inheritance do not change. |
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
532 |
"/ In this case, we can go ahead and patch the class object. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
533 |
"/ (only comment and/or classVars have changed) |
8235
4cb26959673c
oops - did not care for changed superclass
Claus Gittinger <cg@exept.de>
parents:
8234
diff
changeset
|
534 |
oldSuperClass := oldClass superclass. |
4cb26959673c
oops - did not care for changed superclass
Claus Gittinger <cg@exept.de>
parents:
8234
diff
changeset
|
535 |
newSuperClass := newClass superclass. |
4cb26959673c
oops - did not care for changed superclass
Claus Gittinger <cg@exept.de>
parents:
8234
diff
changeset
|
536 |
superClassChange := (oldSuperClass ~~ newSuperClass). |
4cb26959673c
oops - did not care for changed superclass
Claus Gittinger <cg@exept.de>
parents:
8234
diff
changeset
|
537 |
|
9114 | 538 |
oldPoolDictionaries := oldClass sharedPools. |
539 |
||
8235
4cb26959673c
oops - did not care for changed superclass
Claus Gittinger <cg@exept.de>
parents:
8234
diff
changeset
|
540 |
superClassChange ifFalse:[ |
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
541 |
(oldClass instSize == newClass instSize) ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
542 |
(oldClass flags == newClass flags) ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
543 |
(oldClass name = newClass name) ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
544 |
(oldInstVars = newInstVars) ifTrue:[ |
9114 | 545 |
(oldPoolDictionaries = newClass sharedPools) ifTrue:[ |
546 |
self handleEasyNewClass:newClass. |
|
547 |
^ oldClass |
|
548 |
] |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
549 |
] |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
550 |
] |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
551 |
] |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
552 |
] |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
553 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
554 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
555 |
self handleHardNewClass:newClass. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
556 |
^ newClass |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
557 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
558 |
"Created: / 26.5.1996 / 11:55:26 / cg" |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
559 |
"Modified: / 18.3.1999 / 18:23:31 / stefan" |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
560 |
"Modified: / 13.2.2000 / 22:59:57 / cg" |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
561 |
! ! |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
562 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
563 |
!ClassBuilder methodsFor:'building-helpers'! |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
564 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
565 |
changeReferencesFrom:oldClass to:newClass |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
566 |
| refs| |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
567 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
568 |
refs := OrderedCollection new. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
569 |
ObjectMemory allObjectsDo:[:obj | |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
570 |
(obj referencesObject:oldClass) ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
571 |
obj isContext ifFalse:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
572 |
refs add:obj |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
573 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
574 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
575 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
576 |
refs isEmpty ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
577 |
^ self |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
578 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
579 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
580 |
"/ answer := OptionBox |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
581 |
"/ request:('Update References (from old class to new class) ?') withCRs |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
582 |
"/ label:'Confirm' |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
583 |
"/ buttonLabels:#('no' 'browse references' 'update') |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
584 |
"/ values:#(false #browse true) |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
585 |
"/ default:#true |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
586 |
"/ onCancel:false. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
587 |
"/ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
588 |
"/ answer == #browse ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
589 |
"/ refs inspect. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
590 |
"/ answer := self confirm:('Update References (from old class to new class) ?') withCRs. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
591 |
"/ ]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
592 |
"/ answer == false ifTrue:[^ self]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
593 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
594 |
refs do:[:obj | |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
595 |
|skip| |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
596 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
597 |
skip := false. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
598 |
obj isBehavior ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
599 |
skip := true. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
600 |
obj isObsolete ifFalse:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
601 |
obj isMeta ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
602 |
"/ the owner-slot ? |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
603 |
obj owningClass == oldClass ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
604 |
"/ self halt. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
605 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
606 |
obj theNonMetaclass == oldClass ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
607 |
"/ self halt. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
608 |
] |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
609 |
] |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
610 |
] |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
611 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
612 |
skip ifFalse:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
613 |
obj replaceReferencesTo:oldClass with:newClass. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
614 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
615 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
616 |
! |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
617 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
618 |
copyClassInstanceVariablesFrom:oldClass to:newClass |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
619 |
|oldCIVNames newCIVNames| |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
620 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
621 |
"/ copy over classInstanceVariables |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
622 |
"/ but not those inherited from class |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
623 |
|
5905 | 624 |
oldClass notNil ifTrue:[ |
625 |
oldCIVNames := oldClass class allInstVarNames asSet. |
|
626 |
newCIVNames := newClass class allInstVarNames asSet. |
|
627 |
Class class allInstVarNames do:[:n | |
|
628 |
oldCIVNames remove:n ifAbsent:nil. |
|
629 |
newCIVNames remove:n ifAbsent:nil. |
|
630 |
]. |
|
631 |
||
632 |
newCIVNames size > 0 ifTrue:[ |
|
633 |
newCIVNames do:[:n | |
|
634 |
(oldCIVNames includes:n) ifTrue:[ |
|
635 |
newClass instVarNamed:n put:(oldClass instVarNamed:n) |
|
636 |
] |
|
637 |
] |
|
638 |
]. |
|
639 |
]. |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
640 |
! |
5905 | 641 |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
642 |
determineNewName |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
643 |
|doCreate namespace classSymbol idx nsName| |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
644 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
645 |
classSymbol := className asSymbol. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
646 |
namespace := environment. |
5905 | 647 |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
648 |
(namespace notNil |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
649 |
and:[namespace isNameSpace not]) ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
650 |
buildingPrivateClass := true. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
651 |
realNewName := (namespace name , '::' , classSymbol) asSymbol. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
652 |
] ifFalse:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
653 |
buildingPrivateClass := false. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
654 |
realNewName := classSymbol. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
655 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
656 |
"/ does the name imply a nameSpace ? |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
657 |
((idx := realNewName indexOf:$:)) ~~ 0 ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
658 |
"/ check for this namespace to exist |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
659 |
nsName := realNewName copyTo:(idx - 1). |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
660 |
nsName := nsName asSymbol. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
661 |
(realNewName indexOf:$: startingAt:(idx+2)) ~~ 0 ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
662 |
(Smalltalk at:nsName) isNameSpace ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
663 |
self warn:('Nested namespaces are not (yet) implemented.') withCRs. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
664 |
] ifFalse:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
665 |
self warn:('Trying to define a private class with a non-private definition selector.') withCRs. |
5905 | 666 |
]. |
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
667 |
^ false |
5905 | 668 |
]. |
669 |
||
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
670 |
namespace := Smalltalk at:nsName ifAbsent:nil. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
671 |
namespace isNameSpace ifFalse:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
672 |
namespace isNil ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
673 |
doCreate := Class createNameSpaceQuerySignal query. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
674 |
doCreate ifFalse:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
675 |
doCreate := Dialog |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
676 |
confirmWithCancel:('Nonexistent Namespace: `' , nsName , '''.\\Create ?') withCRs. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
677 |
doCreate isNil ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
678 |
"/ cancelled |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
679 |
AbortSignal raise. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
680 |
^ false. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
681 |
] |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
682 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
683 |
doCreate ifFalse:[^ false]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
684 |
namespace := NameSpace name:nsName. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
685 |
] ifFalse:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
686 |
(namespace isBehavior |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
687 |
and:[namespace isMeta not]) |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
688 |
ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
689 |
buildingPrivateClass := true. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
690 |
realNewName := classSymbol asSymbol. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
691 |
] ifFalse:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
692 |
self warn:('A global named ' , nsName , ' exists, but is no namespace.') withCRs. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
693 |
^ false |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
694 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
695 |
] |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
696 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
697 |
namespace isNameSpace ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
698 |
nameKey := (classSymbol copyFrom:(nsName size + 3)) asSymbol. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
699 |
] |
5905 | 700 |
] ifFalse:[ |
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
701 |
(namespace notNil and:[namespace ~~ Smalltalk]) ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
702 |
realNewName := (namespace name , '::' , classSymbol) asSymbol. |
5905 | 703 |
] |
704 |
] |
|
705 |
]. |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
706 |
^ true |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
707 |
! |
5905 | 708 |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
709 |
environmentChanged:how with:argument |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
710 |
environment changed:how with:argument. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
711 |
environment ~~ Smalltalk ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
712 |
Smalltalk changed:how with:argument. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
713 |
] |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
714 |
! |
5905 | 715 |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
716 |
environmentChangedOrganization |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
717 |
environment changed:#organization. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
718 |
environment ~~ Smalltalk ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
719 |
Smalltalk changed:#organization. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
720 |
] |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
721 |
! |
5905 | 722 |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
723 |
fixMethodsIn:newClass |
8235
4cb26959673c
oops - did not care for changed superclass
Claus Gittinger <cg@exept.de>
parents:
8234
diff
changeset
|
724 |
|changeSet1 changeSet2 newMetaclass addedNames| |
5905 | 725 |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
726 |
newMetaclass := newClass class. |
5905 | 727 |
|
728 |
"/ care for class methods ... |
|
729 |
||
730 |
changeSet1 := Set new. |
|
731 |
||
732 |
classVarChange := false. |
|
733 |
||
734 |
superClassChange ifTrue:[ |
|
735 |
(oldSuperClass notNil |
|
736 |
and:[newSuperClass notNil |
|
737 |
and:[oldSuperClass allClassVarNames = newSuperClass allClassVarNames |
|
738 |
and:[oldSuperClass name = newSuperClass name |
|
739 |
and:[oldClassVars = newClassVars]]]]) |
|
740 |
ifTrue:[ |
|
741 |
||
742 |
"/ Transcript showCR:'keep class methods (same classvars)'. |
|
743 |
"/ Transcript endEntry. |
|
744 |
||
745 |
"/ class methods still work |
|
746 |
||
747 |
self class copyMethodsFrom:(oldClass class) for:newMetaclass. |
|
748 |
||
749 |
"/ Smalltalk silentLoading ifFalse:[ |
|
750 |
"/ Transcript showCR:'recompiling class methods accessing super ...'. |
|
751 |
"/ Transcript endEntry. |
|
752 |
"/ ]. |
|
753 |
||
754 |
"/ however, those accessing super must be recompiled |
|
755 |
||
756 |
self class |
|
757 |
copyInvalidatedMethodsFrom:(oldClass class) |
|
758 |
for:newMetaclass |
|
759 |
accessingAny:#() |
|
760 |
orSuper:true. |
|
761 |
] ifFalse:[ |
|
762 |
"/ superclass changed: |
|
763 |
"/ must recompile all class methods accessing ANY classvar |
|
764 |
"/ (actually, we could be less strict and handle the case where |
|
765 |
"/ both the old and the new superclass have a common ancestor, |
|
766 |
"/ and both have no new classvariables in between. |
|
767 |
"/ This would speedup the case when a class is inserted into |
|
768 |
"/ the inheritance chain.) |
|
769 |
||
770 |
oldClass allClassVarNames do:[:nm | changeSet1 add:nm]. |
|
771 |
newClass allClassVarNames do:[:nm | changeSet1 add:nm]. |
|
772 |
||
773 |
"/ Smalltalk silentLoading ifFalse:[ |
|
774 |
"/ Transcript showCR:'recompiling class methods accessing any classvar or super ...'. |
|
775 |
"/ Transcript endEntry. |
|
776 |
"/ ]. |
|
777 |
||
778 |
self class |
|
779 |
copyInvalidatedMethodsFrom:(oldClass class) |
|
780 |
for:newMetaclass |
|
781 |
accessingAny:changeSet1 |
|
782 |
orSuper:true. |
|
783 |
]. |
|
784 |
newMetaclass recompileInvalidatedMethods. |
|
785 |
] ifFalse:[ |
|
786 |
"/ same superclass, find out which classvars have changed |
|
787 |
||
788 |
classVarChange := oldClassVars ~= newClassVars. |
|
789 |
classVarChange ifTrue:[ |
|
790 |
oldClassVars do:[:nm | |
|
791 |
(newClassVars includes:nm) ifFalse:[ |
|
792 |
changeSet1 add:nm |
|
793 |
] |
|
794 |
]. |
|
795 |
newClassVars do:[:nm | |
|
796 |
(oldClassVars includes:nm) ifFalse:[ |
|
797 |
changeSet1 add:nm |
|
798 |
] |
|
799 |
]. |
|
800 |
||
801 |
"/ must recompile some class-methods |
|
802 |
||
803 |
"/ Smalltalk silentLoading ifFalse:[ |
|
804 |
"/ Transcript showCR:'recompiling class methods accessing ' , changeSet1 printString. |
|
805 |
"/ Transcript endEntry. |
|
806 |
"/ ]. |
|
807 |
||
808 |
self class |
|
809 |
copyInvalidatedMethodsFrom:(oldClass class) |
|
810 |
for:newMetaclass |
|
811 |
accessingAny:changeSet1. |
|
812 |
newMetaclass recompileInvalidatedMethods. |
|
813 |
] ifFalse:[ |
|
814 |
||
815 |
"/ class methods still work |
|
816 |
||
817 |
self class copyMethodsFrom:(oldClass class) for:newMetaclass |
|
818 |
]. |
|
819 |
]. |
|
820 |
||
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
821 |
|
5905 | 822 |
"/ care for instance methods ... |
823 |
||
824 |
superClassChange ifTrue:[ |
|
825 |
"/ superclass changed, |
|
826 |
"/ must recompile all methods accessing any class or instvar. |
|
827 |
"/ If number of instvars (i.e. the instances instSize) is the same, |
|
828 |
"/ we can limit the set of recompiled instance methods to those methods, |
|
829 |
"/ which refer to an instvar with a different inst-index |
|
830 |
||
831 |
"/ the changeset consists of instance variables, |
|
832 |
"/ with a different position |
|
833 |
||
834 |
changeSet2 := self class differentInstanceVariableOffsetsIn:oldClass and:newClass. |
|
835 |
||
836 |
"/ merge in the changed class variables |
|
837 |
||
838 |
changeSet1 do:[:nm | changeSet2 add:nm]. |
|
839 |
||
840 |
"/ Smalltalk silentLoading ifFalse:[ |
|
841 |
"/ Transcript showCR:'recompiling instance methods accessing ' , changeSet2 printString , ' [superclass change]...'. |
|
842 |
"/ Transcript endEntry. |
|
843 |
"/ ]. |
|
844 |
||
845 |
self class |
|
846 |
copyInvalidatedMethodsFrom:oldClass |
|
847 |
for:newClass |
|
848 |
accessingAny:changeSet2 |
|
849 |
orSuper:true. |
|
850 |
newClass recompileInvalidatedMethods. |
|
851 |
||
852 |
] ifFalse:[ |
|
853 |
||
854 |
"/ same inheritance ... |
|
855 |
||
856 |
instVarChange := oldInstVars ~= newInstVars. |
|
857 |
instVarChange ifFalse:[ |
|
858 |
||
859 |
"/ same instance variables ... |
|
860 |
||
861 |
classVarChange ifTrue:[ |
|
862 |
"recompile all inst methods accessing changed classvars" |
|
863 |
||
864 |
"/ Smalltalk silentLoading ifFalse:[ |
|
865 |
"/ Transcript showCR:'recompiling instance methods accessing classvars ' , changeSet1 printString , ' ...'. |
|
866 |
"/ Transcript endEntry. |
|
867 |
"/ ]. |
|
868 |
self class |
|
869 |
copyInvalidatedMethodsFrom:oldClass |
|
870 |
for:newClass |
|
871 |
accessingAny:changeSet1. |
|
872 |
newClass recompileInvalidatedMethods. |
|
873 |
] ifFalse:[ |
|
874 |
"/ instance methods still work |
|
875 |
||
876 |
self class copyMethodsFrom:oldClass for:newClass |
|
877 |
] |
|
878 |
] ifTrue:[ |
|
879 |
||
880 |
"/ dont allow built-in classes to be modified |
|
881 |
||
882 |
(oldClass notNil and:[oldClass isBuiltInClass and:[instVarChange]]) ifTrue:[ |
|
883 |
self error:'the layout of this class is fixed - you cannot change it'. |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
884 |
AbortSignal raise |
5905 | 885 |
]. |
886 |
||
887 |
((oldInstVars size == 0) |
|
888 |
or:[newInstVars startsWith:oldInstVars]) ifTrue:[ |
|
889 |
||
890 |
"/ only new inst variable(s) has/have been added - |
|
891 |
"/ old methods still work (the existing inst-indices are still valid) |
|
892 |
||
893 |
"/ Transcript showCR:'copying methods ...'. |
|
894 |
"/ Transcript endEntry. |
|
895 |
||
896 |
self class copyMethodsFrom:oldClass for:newClass. |
|
897 |
||
898 |
"/ but: we have to recompile all methods accessing new instars |
|
899 |
"/ (it might have been a classVar/global before ...) |
|
900 |
||
901 |
addedNames := newInstVars select:[:nm | (oldInstVars includes:nm) not]. |
|
902 |
"merge in class variables" |
|
903 |
changeSet1 do:[:nm | addedNames add:nm]. |
|
904 |
||
905 |
"/ Smalltalk silentLoading ifFalse:[ |
|
906 |
"/ Transcript showCR:'recompiling instance methods accessing ' , addedNames printString , '... [added instvars]'. |
|
907 |
"/ Transcript endEntry. |
|
908 |
"/ ]. |
|
909 |
||
910 |
newClass recompileMethodsAccessingAny:addedNames. |
|
911 |
] ifFalse:[ |
|
912 |
||
913 |
"/ the changeset consists of instance variables, |
|
914 |
"/ with a different position |
|
915 |
||
916 |
changeSet2 := self class differentInstanceVariableOffsetsIn:oldClass and:newClass. |
|
917 |
||
918 |
"merge in the class variables" |
|
919 |
changeSet1 do:[:nm | changeSet2 add:nm]. |
|
920 |
||
921 |
"/ Smalltalk silentLoading ifFalse:[ |
|
922 |
"/ Transcript showCR:'recompiling instance methods accessing ' , changeSet2 printString , ' ... [changed instvars]'. |
|
923 |
"/ Transcript endEntry. |
|
924 |
"/ ]. |
|
925 |
||
926 |
self class |
|
927 |
copyInvalidatedMethodsFrom:oldClass |
|
928 |
for:newClass |
|
929 |
accessingAny:changeSet2. |
|
930 |
newClass recompileInvalidatedMethods. |
|
931 |
]. |
|
932 |
]. |
|
933 |
]. |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
934 |
! |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
935 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
936 |
handleEasyNewClass:newClass |
8610 | 937 |
"instance layout remains the same. |
938 |
We only have to recompile methods which access changed class variables |
|
939 |
and changed pool variables." |
|
940 |
||
941 |
|newComment anyChange setOfChangedVariables oldPoolVars newPoolVars| |
|
942 |
||
943 |
oldPoolVars := oldClass sharedPools collectAll:[:pool | pool keys]. |
|
944 |
newPoolVars := newClass sharedPools collectAll:[:pool | pool keys]. |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
945 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
946 |
newComment := newClass comment. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
947 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
948 |
(newComment ~= oldClass comment) ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
949 |
oldClass setComment:newComment. "writes a change-chunk" |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
950 |
oldClass changed:#comment with:oldClass comment. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
951 |
changed ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
952 |
oldClass addChangeRecordForClassComment:oldClass. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
953 |
] |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
954 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
955 |
|
8610 | 956 |
((oldClassVars = newClassVars) |
957 |
and:[oldPoolVars = newPoolVars]) ifTrue:[ |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
958 |
"/ really no change (just comment and/or category) |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
959 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
960 |
anyChange := false. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
961 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
962 |
oldClass setInstanceVariableString:(newClass instanceVariableString). |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
963 |
oldClass setClassVariableString:(newClass classVariableString). |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
964 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
965 |
oldClass category ~= category ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
966 |
oldClass setCategory:category. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
967 |
changed ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
968 |
newClass addChangeRecordForClass:newClass. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
969 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
970 |
environment notNil ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
971 |
buildingPrivateClass ifFalse:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
972 |
self environmentChangedOrganization. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
973 |
] |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
974 |
] |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
975 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
976 |
"notify change of class" |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
977 |
"/ oldClass changed. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
978 |
^ oldClass |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
979 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
980 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
981 |
"/ when we arrive here, class variables have changed |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
982 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
983 |
oldClass category ~= category ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
984 |
"notify change of organization" |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
985 |
oldClass setCategory:category. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
986 |
environment notNil ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
987 |
buildingPrivateClass ifFalse:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
988 |
self environmentChangedOrganization. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
989 |
] |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
990 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
991 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
992 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
993 |
"/ set class variable string; |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
994 |
"/ this also updates the set of class variables |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
995 |
"/ by creating new / deleting obsolete ones. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
996 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
997 |
oldClass classVariableString:classVariableNames. |
8610 | 998 |
oldClass sharedPools:newClass sharedPools. |
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
999 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1000 |
" |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1001 |
get the set of changed class variables |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1002 |
" |
8610 | 1003 |
setOfChangedVariables := Set new. |
1004 |
||
1005 |
" |
|
1006 |
add the set of changed class variables (those which are not in both) |
|
1007 |
" |
|
1008 |
setOfChangedVariables addAll:(oldClassVars xor:newClassVars). |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1009 |
|
8610 | 1010 |
" |
1011 |
add the set of changed pool variables (those which are not in both) |
|
1012 |
" |
|
1013 |
setOfChangedVariables addAll:(oldPoolVars xor:newPoolVars). |
|
1014 |
||
1015 |
" |
|
1016 |
add the set of pool vars which are now classVars and vice versa |
|
1017 |
" |
|
1018 |
setOfChangedVariables addAll:(oldPoolVars intersect:newClassVars). |
|
1019 |
setOfChangedVariables addAll:(oldClassVars intersect:newPoolVars). |
|
1020 |
||
1021 |
setOfChangedVariables notEmpty ifTrue:[ |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1022 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1023 |
"/ recompile all methods accessing set of changed classvars |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1024 |
"/ here and also in all subclasses ... |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1025 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1026 |
"/ dont update change file for the recompilation |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1027 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1028 |
Class withoutUpdatingChangesDo:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1029 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1030 |
"/ Smalltalk silentLoading ifFalse:[ |
8610 | 1031 |
"/ Transcript showCR:'recompiling class & inst methods accessing ' , setOfChangedVariables printString. |
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1032 |
"/ Transcript endEntry. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1033 |
"/ ]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1034 |
oldClass withAllSubclasses do:[:aClass | |
8610 | 1035 |
aClass class recompileMethodsAccessingAnyClassvarOrGlobal:setOfChangedVariables. |
1036 |
aClass recompileMethodsAccessingAnyClassvarOrGlobal:setOfChangedVariables. |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1037 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1038 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1039 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1040 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1041 |
Class flushSubclassInfo. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1042 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1043 |
"notify change of class" |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1044 |
changed ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1045 |
oldClass addChangeRecordForClass:oldClass. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1046 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1047 |
oldClass changed:#definition. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1048 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1049 |
self environmentChanged:#classDefinition with:newClass. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1050 |
! |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1051 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1052 |
handleHardNewClass:newClass |
8235
4cb26959673c
oops - did not care for changed superclass
Claus Gittinger <cg@exept.de>
parents:
8234
diff
changeset
|
1053 |
|oldCategory| |
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1054 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1055 |
"/ dont allow built-in classes to be modified this way |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1056 |
(oldClass notNil and:[oldClass isBuiltInClass and:[superClassChange]]) ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1057 |
self error:'the inheritance of this class is fixed - you cannot change it'. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1058 |
^ oldClass |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1059 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1060 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1061 |
"/ since we will change the inheritance of some class(es) |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1062 |
Class flushSubclassInfo. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1063 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1064 |
"/ catch special case, where superclass changed its layout and thus |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1065 |
"/ forced redefinition of this class; |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1066 |
"/ only log if this is not the case. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1067 |
changed ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1068 |
(superClassChange |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1069 |
and:[(oldSuperClass isNil or:[newSuperClass notNil and:[oldSuperClass name = newSuperClass name]]) |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1070 |
and:[(oldClassVars = newClassVars) |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1071 |
and:[(oldInstVars = newInstVars) |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1072 |
and:[oldClass comment = newClass comment]]]]) ifFalse:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1073 |
newClass addChangeRecordForClass:newClass. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1074 |
] |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1075 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1076 |
self fixMethodsIn:newClass. |
5905 | 1077 |
|
1078 |
"/ finally, if the oldClass came from a dynamically loaded |
|
1079 |
"/ classLibrary, we must recompile the methods in the newClass. |
|
1080 |
"/ otherwise, the methods code will vanish when the old (obsolete) |
|
1081 |
"/ class eventually vanishes ... |
|
1082 |
self class recompileMachineCodeMethodsIn:newClass. |
|
1083 |
||
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1084 |
"/ (oldPkg notNil and:[oldPkg ~= pkg]) ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1085 |
"/ "/ we have to change all methods package info |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1086 |
"/ "/ to belong to the old package. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1087 |
"/ newClass instAndClassSelectorsAndMethodsDo:[:sel :mthd | |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1088 |
"/ mthd setPackage:oldPkg |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1089 |
"/ ]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1090 |
"/ ]. |
5905 | 1091 |
|
1092 |
"/ WOW, everything done for this class |
|
1093 |
"/ what about subclasses ? |
|
1094 |
||
1095 |
"/ update superclass of immediate subclasses - |
|
1096 |
"/ this forces recompilation (recursively) if needed |
|
1097 |
"/ (dont update change file for the subclass changes) |
|
1098 |
||
8838
81ee56a49ac3
Rename #xxxRedefinitionSignal to #xxxRedefinitionNotification.
Stefan Vogel <sv@exept.de>
parents:
8764
diff
changeset
|
1099 |
Class classRedefinitionNotification answer:#keep do:[ |
5905 | 1100 |
Class withoutUpdatingChangesDo:[ |
1101 |
oldClass subclasses copy do:[:aClass | |
|
1102 |
aClass superclass:newClass |
|
1103 |
] |
|
1104 |
] |
|
1105 |
]. |
|
1106 |
||
1107 |
"/ change any private subclasses' owners |
|
1108 |
||
1109 |
oldClass privateClassesDo:[:aClass | |
|
1110 |
aClass isLoaded ifTrue:[ |
|
1111 |
aClass class setOwningClass:newClass |
|
1112 |
] |
|
1113 |
]. |
|
1114 |
||
1115 |
"/ change category in oldClass - so we see immediately what it is ... |
|
1116 |
||
1117 |
oldCategory := oldClass category. |
|
7580
0a49277831d9
class category: sends a change notification;
Claus Gittinger <cg@exept.de>
parents:
7528
diff
changeset
|
1118 |
oldClass setCategory:#'* obsolete *'. |
5905 | 1119 |
oldClass wasAutoloaded ifTrue:[ Autoload removeClass:oldClass ]. |
1120 |
Smalltalk flushCachedClass:oldClass. |
|
1121 |
||
1122 |
"/ and make the new class globally known |
|
1123 |
||
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1124 |
environment notNil ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1125 |
buildingPrivateClass ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1126 |
environment privateClassesAt:className put:newClass. |
5905 | 1127 |
] ifFalse:[ |
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1128 |
environment at:className put:newClass. |
5905 | 1129 |
|
1130 |
oldCategory ~= category ifTrue:[ |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1131 |
self environmentChangedOrganization. |
5905 | 1132 |
] |
1133 |
]. |
|
1134 |
]. |
|
1135 |
||
1136 |
"/ Not becoming the old class creates some update problems; |
|
1137 |
"/ the browsers must check carefully - a simple identity compare is |
|
1138 |
"/ not enough ... |
|
1139 |
"/ QUESTION: is this a good idea ? |
|
1140 |
newClass dependents:(oldClass dependents). |
|
1141 |
newClass changed:#definition. |
|
1142 |
||
1143 |
"just to make certain ... - tell dependents of oldClass, that something changed |
|
1144 |
(systemBrowsers will react on this, and update their views)" |
|
1145 |
oldClass changed:#definition with:newClass. |
|
1146 |
||
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1147 |
self environmentChanged:#classDefinition with:newClass. |
5905 | 1148 |
|
1149 |
ObjectMemory flushCaches. |
|
1150 |
||
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1151 |
buildingPrivateClass ifFalse:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1152 |
oldClass ~~ newClass ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1153 |
environment == Smalltalk ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1154 |
ClassBuilder checkForAliasesOf:oldClass with:newClass. |
5905 | 1155 |
] |
1156 |
] |
|
1157 |
]. |
|
6034
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
1158 |
(instVarChange or:[classVarChange]) ifTrue:[ |
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
1159 |
self changeReferencesFrom:oldClass to:newClass. |
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
1160 |
]. |
7434
aa0faab58aaf
SubclassInfo moved from Behavior to Class
Stefan Vogel <sv@exept.de>
parents:
7370
diff
changeset
|
1161 |
Class flushSubclassInfo. |
5905 | 1162 |
^ newClass |
1163 |
||
1164 |
"Created: / 26.5.1996 / 11:55:26 / cg" |
|
1165 |
"Modified: / 18.3.1999 / 18:23:31 / stefan" |
|
1166 |
"Modified: / 13.2.2000 / 22:59:57 / cg" |
|
5907 | 1167 |
! |
1168 |
||
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1169 |
handleNewlyCreatedClass:newClass |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1170 |
"/ comment notNil ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1171 |
"/ newClass comment:comment |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1172 |
"/ ]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1173 |
environment notNil ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1174 |
buildingPrivateClass ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1175 |
environment privateClassesAt:className put:newClass. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1176 |
] ifFalse:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1177 |
environment at:className put:newClass. |
8351 | 1178 |
]. |
1179 |
(oldClass isNil and:[changed and:[superClass ~~ Autoload]]) ifTrue:[ |
|
1180 |
newClass addChangeRecordForClass:newClass. |
|
1181 |
]. |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1182 |
]. |
6035 | 1183 |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1184 |
oldClass notNil ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1185 |
"/ since we changed the classes inheritance (from Autoloaded) |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1186 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1187 |
"/ actually, could optimize to: |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1188 |
"/ Class updateSuperclassInfoFor:oldClass superclass. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1189 |
"/ Class updateSuperclassInfoFor:newClass superclass. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1190 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1191 |
Class flushSubclassInfo. |
6037 | 1192 |
]. |
1193 |
||
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1194 |
oldClassToBecomeNew notNil ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1195 |
"/ old was an autoloaded class - make it the new one |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1196 |
"/ and flush ... |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1197 |
oldClassToBecomeNew class becomeSameAs:newClass class. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1198 |
oldClassToBecomeNew becomeSameAs:newClass. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1199 |
ObjectMemory flushCaches. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1200 |
]. |
6035 | 1201 |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1202 |
environment notNil ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1203 |
buildingPrivateClass ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1204 |
environment changed. |
8351 | 1205 |
]. |
1206 |
self environmentChanged:#newClass with:newClass. |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1207 |
]. |
6034
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
1208 |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1209 |
"/ be very careful, when adding classes |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1210 |
"/ to a namespace or adding a privateClass. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1211 |
"/ When adding, all methods within that namespace/owning class |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1212 |
"/ which access the unprefixed-global, |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1213 |
"/ must be recompiled (so they access the new class) |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1214 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1215 |
recompileGlobalAccessTo notNil ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1216 |
self class |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1217 |
recompileGlobalAccessorsTo:recompileGlobalAccessTo |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1218 |
in:environment except:newClass. |
6034
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
1219 |
]. |
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1220 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1221 |
(buildingPrivateClass |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1222 |
and:[newClass owningClass nameSpace notNil]) ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1223 |
"/ namespace is a class; |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1224 |
"/ if this owner is itself in a namespace, |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1225 |
"/ must recompile all from owners namespace |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1226 |
"/ accessing the new class (without namespace prefix) |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1227 |
self class |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1228 |
recompileGlobalAccessorsTo:(newClass nameWithoutNameSpacePrefix asSymbol) |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1229 |
in:(newClass owningClass nameSpace) except:newClass. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1230 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1231 |
^ newClass |
6034
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
1232 |
! |
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
1233 |
|
6514 | 1234 |
instantiateMetaclass |
1235 |
"create the metaclass proper" |
|
1236 |
||
1237 |
|newMetaclass classesSuperclass| |
|
1238 |
||
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1239 |
classInstanceVariableNames isNil ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1240 |
oldClass isNil ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1241 |
classInstanceVariableNames := '' |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1242 |
] ifFalse:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1243 |
classInstanceVariableNames := oldClass class instanceVariableString |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1244 |
] |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1245 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1246 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1247 |
buildingPrivateClass ifTrue:[ |
7617 | 1248 |
newMetaclass := metaclass asPrivate new |
6514 | 1249 |
] ifFalse:[ |
7617 | 1250 |
newMetaclass := metaclass new. |
6514 | 1251 |
]. |
1252 |
superClass isNil ifTrue:[ |
|
8724 | 1253 |
classesSuperclass := self classClass. |
6514 | 1254 |
] ifFalse:[ |
1255 |
classesSuperclass := superClass class. |
|
1256 |
]. |
|
1257 |
newMetaclass setSuperclass:classesSuperclass instSize:(classesSuperclass instSize + classInstanceVariableNames countWords). |
|
1258 |
newMetaclass setInstanceVariableString:classInstanceVariableNames. |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1259 |
buildingPrivateClass ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1260 |
newMetaclass setOwningClass:environment. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1261 |
]. |
6514 | 1262 |
^ newMetaclass |
1263 |
! |
|
1264 |
||
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1265 |
instantiateNewClassFrom:newMetaclass |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1266 |
"create the class proper" |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1267 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1268 |
|newClass nInstVars newInstSize| |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1269 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1270 |
"let the new meta create the class" |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1271 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1272 |
instanceVariableNames size > 0 ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1273 |
nInstVars := instanceVariableNames countWords. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1274 |
] ifFalse:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1275 |
nInstVars := 0. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1276 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1277 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1278 |
newClass := newMetaclass new. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1279 |
superClass isNil ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1280 |
newInstSize := nInstVars. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1281 |
] ifFalse:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1282 |
newInstSize := superClass instSize + nInstVars. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1283 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1284 |
newClass setSuperclass:superClass instSize:newInstSize. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1285 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1286 |
self copyClassInstanceVariablesFrom:oldClass to:newClass. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1287 |
self setPackageInNewClass:newClass fromOld:oldClass. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1288 |
self setupNewClass:newClass fromOld:oldClass. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1289 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1290 |
^ newClass |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1291 |
! |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1292 |
|
5907 | 1293 |
rebuildForChangedInstanceVariables |
1294 |
"changing / adding class-inst vars - |
|
1295 |
this actually creates a new metaclass and class, leaving the original |
|
1296 |
classes around as obsolete classes. This may also be true for all subclasses, |
|
1297 |
if class instance variables are added/removed. |
|
1298 |
Existing instances continue to be defined by their original classes. |
|
1299 |
||
1300 |
Time will show, if this is an acceptable behavior or if we should migrate |
|
1301 |
instances to become insts. of the new classes." |
|
1302 |
||
1303 |
|newClass newMetaclass nClassInstVars oldClass |
|
1304 |
allSubclasses oldVars |
|
1305 |
oldNames newNames addedNames |
|
1306 |
oldOffsets newOffsets offset changeSet delta |
|
8235
4cb26959673c
oops - did not care for changed superclass
Claus Gittinger <cg@exept.de>
parents:
8234
diff
changeset
|
1307 |
oldToNew newSubMeta newSub oldSubMeta |
5907 | 1308 |
commonClassInstVars t superclass| |
1309 |
||
1310 |
" |
|
1311 |
cleanup needed here: extract common things with name:inEnvironment:... |
|
1312 |
and restructure things ... currently way too complex. |
|
1313 |
" |
|
1314 |
||
1315 |
oldVars := oldMetaClass instanceVariableString. |
|
1316 |
instanceVariableNames = oldVars ifTrue:[ |
|
1317 |
" |
|
1318 |
Transcript showCR:'no change (', oldVars , ') -> (', instanceVariableNames , ')'. |
|
1319 |
" |
|
1320 |
^ self |
|
1321 |
]. |
|
1322 |
||
1323 |
oldNames := oldVars asCollectionOfWords. |
|
1324 |
newNames := instanceVariableNames asCollectionOfWords. |
|
1325 |
||
1326 |
oldNames = newNames ifTrue:[ |
|
1327 |
" |
|
1328 |
Transcript showCR:'no real change'. |
|
1329 |
" |
|
1330 |
"no real change (just formatting)" |
|
1331 |
oldMetaClass setInstanceVariableString:instanceVariableNames. |
|
1332 |
^ self |
|
1333 |
]. |
|
1334 |
||
1335 |
"/ " |
|
1336 |
"/ let user confirm, if any name is no good (and was good before) |
|
1337 |
"/ " |
|
1338 |
"/ (oldNames inject:true |
|
1339 |
"/ into:[:okSoFar :word | |
|
1340 |
"/ okSoFar and:[word first isUppercase] |
|
1341 |
"/ ]) |
|
1342 |
"/ ifTrue:[ |
|
1343 |
"/ "was ok before" |
|
1344 |
"/ (newNames inject:true |
|
1345 |
"/ into:[:okSoFar :word | |
|
1346 |
"/ okSoFar and:[word first isUppercase] |
|
1347 |
"/ ]) |
|
1348 |
"/ ifFalse:[ |
|
1349 |
"/ (self confirm:'class instance variable names should start with an uppercase letter |
|
1350 |
"/(by convention only) |
|
1351 |
"/ |
|
1352 |
"/install anyway ?' withCRs) |
|
1353 |
"/ ifFalse:[ |
|
1354 |
"/ ^ nil |
|
1355 |
"/ ] |
|
1356 |
"/ ] |
|
1357 |
"/ ]. |
|
1358 |
||
1359 |
nClassInstVars := newNames size. |
|
1360 |
||
1361 |
" |
|
1362 |
Transcript showCR:'create new class/metaclass'. |
|
1363 |
" |
|
1364 |
||
1365 |
" |
|
1366 |
create the new metaclass |
|
1367 |
" |
|
1368 |
oldMetaClass isPrivate ifTrue:[ |
|
6514 | 1369 |
newMetaclass := oldMetaClass class "PrivateMetaclass" new. |
5907 | 1370 |
newMetaclass setOwningClass:(oldMetaClass owningClass). |
1371 |
] ifFalse:[ |
|
6514 | 1372 |
newMetaclass := oldMetaClass class "Metaclass" new. |
5907 | 1373 |
]. |
1374 |
superclass := oldMetaClass superclass. |
|
1375 |
newMetaclass setSuperclass:superclass. |
|
1376 |
newMetaclass instSize:(superclass instSize + nClassInstVars). |
|
1377 |
(nClassInstVars ~~ 0) ifTrue:[ |
|
1378 |
newMetaclass setInstanceVariableString:instanceVariableNames |
|
1379 |
]. |
|
1380 |
"/ newMetaclass flags:(Behavior flagBehavior "flagNotIndexed"). |
|
1381 |
"/ newMetaclass setName:name. |
|
1382 |
"/ newMetaclass classVariableString:classvars. |
|
1383 |
"/ newMetaclass setComment:(self comment). |
|
1384 |
||
1385 |
"find the class which is my sole instance" |
|
1386 |
||
1387 |
oldClass := oldMetaClass theNonMetaclass. |
|
1388 |
||
1389 |
" |
|
1390 |
create the new class |
|
1391 |
" |
|
1392 |
newClass := newMetaclass new. |
|
1393 |
newClass setSuperclass:(oldClass superclass) instSize:(oldClass instSize). |
|
1394 |
newClass flags:(oldClass flags). |
|
1395 |
newClass setName:(oldClass name). |
|
1396 |
newClass setInstanceVariableString:(oldClass instanceVariableString). |
|
1397 |
newClass classVariableString:(oldClass classVariableString). |
|
1398 |
newClass setComment:(oldClass comment). |
|
7580
0a49277831d9
class category: sends a change notification;
Claus Gittinger <cg@exept.de>
parents:
7528
diff
changeset
|
1399 |
newClass setCategory:(oldClass category). |
7487 | 1400 |
(t := oldClass classAttributes) notNil ifTrue:[ |
1401 |
newClass classAttributes:t. |
|
5907 | 1402 |
]. |
1403 |
newClass setClassFilename:(oldClass classFilename). |
|
1404 |
||
1405 |
"/ set the new classes package |
|
1406 |
"/ from the old package |
|
1407 |
||
1408 |
newClass package:(oldClass package). |
|
1409 |
||
1410 |
"/ and keep the binary revision |
|
1411 |
newClass setBinaryRevision:(oldClass binaryRevision). |
|
1412 |
||
1413 |
changeSet := Set new. |
|
1414 |
((oldNames size == 0) |
|
1415 |
or:[newNames startsWith:oldNames]) ifTrue:[ |
|
1416 |
"new variable(s) has/have been added - old methods still work" |
|
1417 |
||
1418 |
"/ Transcript showCR:'copying methods ...'. |
|
1419 |
"/ Transcript endEntry. |
|
1420 |
||
1421 |
ClassBuilder copyMethodsFrom:oldMetaClass for:newMetaclass. |
|
1422 |
ClassBuilder copyMethodsFrom:oldClass for:newClass. |
|
1423 |
||
1424 |
" |
|
1425 |
but have to recompile methods accessing stuff now defined |
|
1426 |
(it might have been a global/undeclared before ...) |
|
1427 |
" |
|
1428 |
||
1429 |
addedNames := newNames select:[:nm | (oldNames includes:nm) not]. |
|
1430 |
||
1431 |
"/ Smalltalk silentLoading ifFalse:[ |
|
1432 |
"/ Transcript showCR:'recompiling class methods of ' , newMetaclass name , |
|
1433 |
"/ ' accessing any of ' , addedNames printString. |
|
1434 |
"/ ]. |
|
1435 |
||
1436 |
"recompile class-methods" |
|
1437 |
newMetaclass recompileMethodsAccessingAny:addedNames. |
|
1438 |
] ifFalse:[ |
|
1439 |
" |
|
1440 |
create the changeSet; thats the set of class instvar names |
|
1441 |
which have changed their position or are new |
|
1442 |
" |
|
1443 |
offset := 0. oldOffsets := Dictionary new. |
|
1444 |
oldNames do:[:nm | offset := offset + 1. oldOffsets at:nm put:offset]. |
|
1445 |
offset := 0. newOffsets := Dictionary new. |
|
1446 |
newNames do:[:nm | offset := offset + 1. newOffsets at:nm put:offset]. |
|
1447 |
||
1448 |
oldOffsets associationsDo:[:a | |
|
1449 |
|k| |
|
1450 |
||
1451 |
k := a key. |
|
1452 |
(newOffsets includesKey:k) ifFalse:[ |
|
1453 |
changeSet add:k |
|
1454 |
] ifTrue:[ |
|
1455 |
(a value ~~ (newOffsets at:k)) ifTrue:[ |
|
1456 |
changeSet add:k |
|
1457 |
] |
|
1458 |
] |
|
1459 |
]. |
|
1460 |
newOffsets associationsDo:[:a | |
|
1461 |
|k| |
|
1462 |
||
1463 |
k := a key. |
|
1464 |
(oldOffsets includesKey:k) ifFalse:[ |
|
1465 |
changeSet add:k |
|
1466 |
] ifTrue:[ |
|
1467 |
(a value ~~ (oldOffsets at:k)) ifTrue:[ |
|
1468 |
changeSet add:k |
|
1469 |
] |
|
1470 |
] |
|
1471 |
]. |
|
1472 |
||
1473 |
"/ Smalltalk silentLoading ifFalse:[ |
|
1474 |
"/ Transcript showCR:'recompiling class methods of ' , newMetaclass name , |
|
1475 |
"/ ' accessing any of ' , changeSet printString. |
|
1476 |
"/ ]. |
|
1477 |
||
1478 |
" |
|
1479 |
recompile class-methods accessing any c-instvar with a changed position |
|
1480 |
" |
|
1481 |
ClassBuilder copyInvalidatedMethodsFrom:oldMetaClass for:newMetaclass accessingAny:changeSet. |
|
1482 |
newMetaclass recompileInvalidatedMethods. |
|
1483 |
||
1484 |
ClassBuilder copyMethodsFrom:oldClass for:newClass. |
|
1485 |
]. |
|
1486 |
||
1487 |
delta := newNames size - oldNames size. |
|
1488 |
||
1489 |
"/ preserve existing classInstVar values (but not those from Class) |
|
1490 |
newMetaclass allInstVarNames do:[:nm | |
|
1491 |
|v| |
|
1492 |
||
1493 |
(Class class allInstVarNames includes:nm) ifFalse:[ |
|
1494 |
v := oldClass instVarNamed:nm ifAbsent:nil. |
|
1495 |
v notNil ifTrue:[ |
|
1496 |
newClass instVarNamed:nm put:v. |
|
1497 |
]. |
|
1498 |
]. |
|
1499 |
]. |
|
1500 |
||
1501 |
" |
|
1502 |
get list of all subclasses - do before superclass is changed |
|
1503 |
" |
|
1504 |
allSubclasses := oldClass allSubclasses asOrderedCollection. |
|
1505 |
"/ cg: wrong: allSubclasses := allSubclasses asSortedCollection:[:a :b | b isSubclassOf:a]. |
|
1506 |
allSubclasses := allSubclasses topologicalSort:[:a :b | b isSubclassOf:a]. |
|
1507 |
||
1508 |
oldToNew := IdentityDictionary new. |
|
1509 |
||
1510 |
" |
|
1511 |
create a new class tree, based on the new version |
|
1512 |
" |
|
6957
562b88083688
more cache flushing when instvars change
Claus Gittinger <cg@exept.de>
parents:
6825
diff
changeset
|
1513 |
Smalltalk flushCachedClasses. |
562b88083688
more cache flushing when instvars change
Claus Gittinger <cg@exept.de>
parents:
6825
diff
changeset
|
1514 |
Class flushSubclassInfo. |
5907 | 1515 |
allSubclasses do:[:aSubclass | |
8235
4cb26959673c
oops - did not care for changed superclass
Claus Gittinger <cg@exept.de>
parents:
8234
diff
changeset
|
1516 |
|oldSuper| |
4cb26959673c
oops - did not care for changed superclass
Claus Gittinger <cg@exept.de>
parents:
8234
diff
changeset
|
1517 |
|
5907 | 1518 |
oldSuper := aSubclass superclass. |
1519 |
oldSubMeta := aSubclass class. |
|
1520 |
||
1521 |
newSubMeta := Metaclass new. |
|
1522 |
oldSuper == oldClass ifTrue:[ |
|
1523 |
newSubMeta setSuperclass:newMetaclass. |
|
1524 |
] ifFalse:[ |
|
1525 |
newSubMeta setSuperclass:(oldToNew at:oldSuper) class. |
|
1526 |
]. |
|
1527 |
newSubMeta instSize:(oldSubMeta instSize + delta). |
|
1528 |
newSubMeta flags:(oldSubMeta flags). |
|
1529 |
"/ newSubMeta setName:(oldSubMeta name). |
|
1530 |
newSubMeta setInstanceVariableString:(oldSubMeta instanceVariableString). |
|
1531 |
"/ newSubMeta setComment:(oldSubMeta comment). |
|
1532 |
||
1533 |
newSub := newSubMeta new. |
|
1534 |
oldSuper == oldClass ifTrue:[ |
|
1535 |
newSub setSuperclass:newClass. |
|
1536 |
] ifFalse:[ |
|
1537 |
newSub setSuperclass:(oldToNew at:oldSuper). |
|
1538 |
]. |
|
1539 |
||
1540 |
"/ newSub setMethodDictionary:(aSubclass methodDictionary copy). |
|
1541 |
"/ newSub class setMethodDictionary:(aSubclass class methodDictionary copy). |
|
1542 |
newSub setName:(aSubclass name). |
|
7516
42c5b199db20
change notifications for classInstVar change
Claus Gittinger <cg@exept.de>
parents:
7487
diff
changeset
|
1543 |
newSub setClassVariableString:(aSubclass classVariableString). |
5907 | 1544 |
newSub setInstanceVariableString:(aSubclass instanceVariableString). |
7487 | 1545 |
(t := aSubclass classAttributes) notNil ifTrue:[ |
1546 |
newSub classAttributes:t. |
|
7370
1ed996a6e7bf
primitiveSpec changed to attributes.
Claus Gittinger <cg@exept.de>
parents:
7230
diff
changeset
|
1547 |
]. |
5907 | 1548 |
newSub package:(aSubclass package). |
1549 |
newSub setClassFilename:(oldClass classFilename). |
|
1550 |
newSub setComment:(aSubclass comment). |
|
7580
0a49277831d9
class category: sends a change notification;
Claus Gittinger <cg@exept.de>
parents:
7528
diff
changeset
|
1551 |
newSub setCategory:(aSubclass category). |
5907 | 1552 |
newSub instSize:(aSubclass instSize). |
1553 |
newSub setBinaryRevision:(aSubclass binaryRevision). |
|
1554 |
||
1555 |
oldToNew at:aSubclass put:newSub. |
|
1556 |
||
7580
0a49277831d9
class category: sends a change notification;
Claus Gittinger <cg@exept.de>
parents:
7528
diff
changeset
|
1557 |
aSubclass setCategory:#'* obsolete *'. |
5907 | 1558 |
|
1559 |
"/ preserve existing classInstVar values (but not those from Class) |
|
1560 |
||
1561 |
newSubMeta allInstVarNames do:[:nm | |
|
1562 |
|v| |
|
1563 |
||
1564 |
(Class class allInstVarNames includes:nm) ifFalse:[ |
|
1565 |
v := aSubclass instVarNamed:nm ifAbsent:nil. |
|
1566 |
v notNil ifTrue:[ |
|
1567 |
newSub instVarNamed:nm put:v. |
|
1568 |
]. |
|
1569 |
]. |
|
1570 |
]. |
|
1571 |
||
1572 |
]. |
|
1573 |
||
1574 |
"recompile what needs to be" |
|
1575 |
||
1576 |
delta == 0 ifTrue:[ |
|
1577 |
"only have to recompile class methods accessing |
|
1578 |
class instvars from changeset |
|
1579 |
" |
|
1580 |
||
1581 |
allSubclasses do:[:oldSubclass | |
|
1582 |
|newSubclass| |
|
1583 |
||
1584 |
newSubclass := oldToNew at:oldSubclass. |
|
1585 |
||
1586 |
"/ Smalltalk silentLoading ifFalse:[ |
|
1587 |
"/ Transcript showCR:'recompiling class methods of ' , newSubclass class name , |
|
1588 |
"/ ' accessing any of ' , changeSet printString. |
|
1589 |
"/ ]. |
|
1590 |
||
1591 |
ClassBuilder |
|
1592 |
copyInvalidatedMethodsFrom:oldSubclass class for:newSubclass class |
|
1593 |
accessingAny:changeSet orSuper:true. |
|
1594 |
||
1595 |
ClassBuilder |
|
1596 |
copyInvalidatedMethodsFrom:oldSubclass for:newSubclass |
|
1597 |
accessingAny:#() orSuper:true. |
|
1598 |
||
1599 |
newSubclass class recompileInvalidatedMethods. |
|
1600 |
newSubclass recompileInvalidatedMethods. |
|
1601 |
] |
|
1602 |
] ifFalse:[ |
|
1603 |
" |
|
1604 |
have to recompile all class methods accessing class instvars |
|
1605 |
" |
|
1606 |
commonClassInstVars := oldClass class allInstVarNames. |
|
1607 |
changeSet do:[:v | |
|
1608 |
commonClassInstVars remove:v ifAbsent:[] |
|
1609 |
]. |
|
1610 |
||
1611 |
allSubclasses do:[:oldSubclass | |
|
1612 |
|newSubclass classInstVars| |
|
1613 |
||
1614 |
newSubclass := oldToNew at:oldSubclass. |
|
1615 |
||
1616 |
classInstVars := newSubclass class allInstVarNames asSet. |
|
1617 |
classInstVars removeAll:commonClassInstVars. |
|
1618 |
classInstVars addAll:changeSet. |
|
1619 |
||
1620 |
"/ Smalltalk silentLoading ifFalse:[ |
|
1621 |
"/ Transcript showCR:'recompiling class methods of ' , newSubclass class name , |
|
1622 |
"/ ' accessing any of ' , classInstVars printString. |
|
1623 |
"/ ]. |
|
1624 |
||
1625 |
ClassBuilder |
|
1626 |
copyInvalidatedMethodsFrom:oldSubclass class for:newSubclass class |
|
1627 |
accessingAny:classInstVars orSuper:true. |
|
1628 |
||
1629 |
ClassBuilder |
|
1630 |
copyInvalidatedMethodsFrom:oldSubclass for:newSubclass |
|
1631 |
accessingAny:#() orSuper:true. |
|
1632 |
||
1633 |
newSubclass class recompileInvalidatedMethods. |
|
1634 |
newSubclass recompileInvalidatedMethods. |
|
1635 |
] |
|
1636 |
]. |
|
1637 |
||
1638 |
newClass addChangeRecordForClassInstvars:newClass. |
|
1639 |
||
1640 |
"install all new classes" |
|
1641 |
||
1642 |
(Smalltalk at:(oldClass name asSymbol) ifAbsent:nil) == oldClass ifTrue:[ |
|
1643 |
Smalltalk at:(oldClass name asSymbol) put:newClass. |
|
1644 |
ClassBuilder checkForAliasesOf:oldClass with:newClass. |
|
1645 |
||
1646 |
" |
|
1647 |
change any private subclasses' owners |
|
1648 |
" |
|
1649 |
oldClass privateClassesDo:[:aClass | |
|
1650 |
aClass class setOwningClass:newClass |
|
1651 |
]. |
|
1652 |
||
1653 |
]. |
|
1654 |
ObjectMemory flushCachesFor:oldClass. |
|
1655 |
||
1656 |
allSubclasses do:[:oldSubClass | |
|
1657 |
|newSubClass| |
|
1658 |
||
1659 |
newSubClass := oldToNew at:oldSubClass. |
|
1660 |
||
1661 |
"/ Transcript showCR:'install ' , newSubClass name , '(' , newSubClass category , ')' , |
|
1662 |
"/ ' as ' , newSubClass name. |
|
1663 |
||
1664 |
(Smalltalk at:(oldSubClass name asSymbol) ifAbsent:nil) == oldSubClass ifTrue:[ |
|
1665 |
Smalltalk at:oldSubClass name asSymbol put:newSubClass. |
|
1666 |
ClassBuilder checkForAliasesOf:oldSubClass with:newSubClass. |
|
1667 |
]. |
|
1668 |
ObjectMemory flushCachesFor:oldSubClass. |
|
1669 |
||
1670 |
oldSubClass privateClassesDo:[:aClass | |
|
1671 |
aClass class setOwningClass:newSubClass |
|
1672 |
]. |
|
1673 |
]. |
|
1674 |
||
1675 |
"tell dependents ..." |
|
1676 |
||
1677 |
oldClass changed:#definition. |
|
7516
42c5b199db20
change notifications for classInstVar change
Claus Gittinger <cg@exept.de>
parents:
7487
diff
changeset
|
1678 |
"/ oldClass nameSpace changed:#classDefinition with:oldClass. |
42c5b199db20
change notifications for classInstVar change
Claus Gittinger <cg@exept.de>
parents:
7487
diff
changeset
|
1679 |
"/ oldClass nameSpace ~~ Smalltalk ifTrue:[ |
42c5b199db20
change notifications for classInstVar change
Claus Gittinger <cg@exept.de>
parents:
7487
diff
changeset
|
1680 |
"/ Smalltalk changed:#classDefinition with:oldClass. |
42c5b199db20
change notifications for classInstVar change
Claus Gittinger <cg@exept.de>
parents:
7487
diff
changeset
|
1681 |
"/ ]. |
42c5b199db20
change notifications for classInstVar change
Claus Gittinger <cg@exept.de>
parents:
7487
diff
changeset
|
1682 |
|
5907 | 1683 |
oldMetaClass changed:#definition. |
1684 |
oldMetaClass nameSpace changed:#classDefinition with:oldMetaClass. |
|
1685 |
oldMetaClass nameSpace ~~ Smalltalk ifTrue:[ |
|
1686 |
Smalltalk changed:#classDefinition with:oldMetaClass. |
|
1687 |
]. |
|
1688 |
||
7580
0a49277831d9
class category: sends a change notification;
Claus Gittinger <cg@exept.de>
parents:
7528
diff
changeset
|
1689 |
oldClass setCategory:#'* obsolete *'. |
5907 | 1690 |
^ newMetaclass |
1691 |
||
1692 |
"Created: / 29.10.1995 / 19:57:08 / cg" |
|
1693 |
"Modified: / 1.4.1997 / 15:44:09 / stefan" |
|
1694 |
"Modified: / 31.7.1998 / 18:02:00 / cg" |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1695 |
! |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1696 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1697 |
setPackageInNewClass:newClass fromOld:oldClass |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1698 |
|pkg oldPkg answer| |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1699 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1700 |
"/ set the new classes package |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1701 |
"/ but be careful here ... |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1702 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1703 |
oldClass isNil ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1704 |
"/ new classes get the current package ... |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1705 |
pkg := Class packageQuerySignal query. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1706 |
] ifFalse:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1707 |
newClass setClassFilename:(oldClass classFilename). |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1708 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1709 |
oldPkg := oldClass package. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1710 |
oldClass isLoaded ifFalse:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1711 |
"/ autoloaded classes get the package of the autoload stub ... |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1712 |
pkg := oldPkg |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1713 |
] ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1714 |
"/ not autoloading, check for packageRedef ... |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1715 |
buildingPrivateClass ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1716 |
pkg := environment package. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1717 |
] ifFalse:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1718 |
pkg := Class packageQuerySignal query. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1719 |
oldPkg ~= pkg ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1720 |
newClass package:pkg. |
8838
81ee56a49ac3
Rename #xxxRedefinitionSignal to #xxxRedefinitionNotification.
Stefan Vogel <sv@exept.de>
parents:
8764
diff
changeset
|
1721 |
answer := Class classRedefinitionNotification |
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1722 |
raiseRequestWith:(oldClass -> newClass) |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1723 |
errorString:('redefinition of class: ' , oldClass name). |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1724 |
answer == #keep ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1725 |
pkg := oldPkg. "/ keep old package |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1726 |
] ifFalse:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1727 |
answer ~~ #continue ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1728 |
^ nil "/ cancel |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1729 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1730 |
"/ take new package |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1731 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1732 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1733 |
newClass setBinaryRevision:(oldClass binaryRevision). |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1734 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1735 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1736 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1737 |
pkg notNil ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1738 |
"/ Transcript showCR:('set package of class: ' , newClass name , ' to ' , pkg printString). |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1739 |
newClass package:pkg. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1740 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1741 |
! |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1742 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1743 |
setupNewClass:newClass fromOld:oldClass |
9114 | 1744 |
|newFlags superFlags nInstVars| |
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1745 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1746 |
(instanceVariableNames size > 0) ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1747 |
nInstVars := instanceVariableNames countWords. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1748 |
] ifFalse:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1749 |
nInstVars := 0. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1750 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1751 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1752 |
"/ Allowing non-booleans as variableBoolean |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1753 |
"/ is a hack for backward (ST-80) compatibility: |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1754 |
"/ ST-80 code will pass true or false as variableBoolean, |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1755 |
"/ while ST/X also calls it with symbols such as #float, #double etc. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1756 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1757 |
(variable == true) ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1758 |
pointers ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1759 |
newFlags := Behavior flagPointers |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1760 |
] ifFalse:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1761 |
words ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1762 |
newFlags := Behavior flagWords |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1763 |
] ifFalse:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1764 |
newFlags := Behavior flagBytes |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1765 |
] |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1766 |
] |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1767 |
] ifFalse:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1768 |
"/ false or symbol. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1769 |
newFlags := Behavior flagForSymbolic:variable. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1770 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1771 |
superClass isNil ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1772 |
superFlags := 0 |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1773 |
] ifFalse:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1774 |
superFlags := superClass flags bitAnd:(Behavior maskIndexType bitInvert). "preserve other bits" |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1775 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1776 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1777 |
oldClass notNil ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1778 |
oldClass isBuiltInClass ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1779 |
" |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1780 |
special care when redefining Method, Block and other built-in classes, |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1781 |
which might have other flag bits ... |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1782 |
" |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1783 |
newFlags := newFlags bitOr:(oldClass flags bitAnd:(Behavior maskIndexType bitInvert)) |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1784 |
] |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1785 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1786 |
newClass flags:(newFlags bitOr:superFlags). "preserve inherited special bits" |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1787 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1788 |
(nInstVars ~~ 0) ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1789 |
newClass setInstanceVariableString:instanceVariableNames |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1790 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1791 |
oldClass notNil ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1792 |
"/ setting first will make new class clear obsolete classvars |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1793 |
newClass setClassVariableString:(oldClass classVariableString). |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1794 |
newClass setClassFilename:(oldClass classFilename). |
9114 | 1795 |
newClass setPrimitiveDefinitions:(oldClass primitiveDefinitionsString). |
1796 |
newClass setPrimitiveFunctions:(oldClass primitiveFunctionsString). |
|
1797 |
newClass setPrimitiveVariables:(oldClass primitiveVariablesString). |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1798 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1799 |
newClass setClassVariableString:classVariableNames. |
5905 | 1800 |
! ! |
1801 |
||
1802 |
!ClassBuilder methodsFor:'checks'! |
|
1803 |
||
1804 |
checkClassName |
|
8743
3992e2ac5c7f
care for the case when defining a class with a name-space name but
Claus Gittinger <cg@exept.de>
parents:
8724
diff
changeset
|
1805 |
|fullNameString idx environmentName| |
3992e2ac5c7f
care for the case when defining a class with a name-space name but
Claus Gittinger <cg@exept.de>
parents:
8724
diff
changeset
|
1806 |
|
3992e2ac5c7f
care for the case when defining a class with a name-space name but
Claus Gittinger <cg@exept.de>
parents:
8724
diff
changeset
|
1807 |
"/ check if the given name implies a (sub-) namespace |
3992e2ac5c7f
care for the case when defining a class with a name-space name but
Claus Gittinger <cg@exept.de>
parents:
8724
diff
changeset
|
1808 |
"/ happens (currently) when installing autoloaded classes |
3992e2ac5c7f
care for the case when defining a class with a name-space name but
Claus Gittinger <cg@exept.de>
parents:
8724
diff
changeset
|
1809 |
(className includes:$:) ifTrue:[ |
3992e2ac5c7f
care for the case when defining a class with a name-space name but
Claus Gittinger <cg@exept.de>
parents:
8724
diff
changeset
|
1810 |
environment notNil ifTrue:[ |
3992e2ac5c7f
care for the case when defining a class with a name-space name but
Claus Gittinger <cg@exept.de>
parents:
8724
diff
changeset
|
1811 |
fullNameString := environment name , '::' , className |
3992e2ac5c7f
care for the case when defining a class with a name-space name but
Claus Gittinger <cg@exept.de>
parents:
8724
diff
changeset
|
1812 |
] ifFalse:[ |
3992e2ac5c7f
care for the case when defining a class with a name-space name but
Claus Gittinger <cg@exept.de>
parents:
8724
diff
changeset
|
1813 |
fullNameString := className |
3992e2ac5c7f
care for the case when defining a class with a name-space name but
Claus Gittinger <cg@exept.de>
parents:
8724
diff
changeset
|
1814 |
]. |
3992e2ac5c7f
care for the case when defining a class with a name-space name but
Claus Gittinger <cg@exept.de>
parents:
8724
diff
changeset
|
1815 |
idx := fullNameString lastIndexOf:$:. |
3992e2ac5c7f
care for the case when defining a class with a name-space name but
Claus Gittinger <cg@exept.de>
parents:
8724
diff
changeset
|
1816 |
className := (fullNameString copyFrom:idx+1) asSymbol. |
3992e2ac5c7f
care for the case when defining a class with a name-space name but
Claus Gittinger <cg@exept.de>
parents:
8724
diff
changeset
|
1817 |
environmentName := fullNameString copyTo:idx-2. |
3992e2ac5c7f
care for the case when defining a class with a name-space name but
Claus Gittinger <cg@exept.de>
parents:
8724
diff
changeset
|
1818 |
environment := Smalltalk at:environmentName asSymbol. |
3992e2ac5c7f
care for the case when defining a class with a name-space name but
Claus Gittinger <cg@exept.de>
parents:
8724
diff
changeset
|
1819 |
environment isNil ifTrue:[ |
3992e2ac5c7f
care for the case when defining a class with a name-space name but
Claus Gittinger <cg@exept.de>
parents:
8724
diff
changeset
|
1820 |
environment := NameSpace fullName:environmentName |
3992e2ac5c7f
care for the case when defining a class with a name-space name but
Claus Gittinger <cg@exept.de>
parents:
8724
diff
changeset
|
1821 |
]. |
3992e2ac5c7f
care for the case when defining a class with a name-space name but
Claus Gittinger <cg@exept.de>
parents:
8724
diff
changeset
|
1822 |
]. |
3992e2ac5c7f
care for the case when defining a class with a name-space name but
Claus Gittinger <cg@exept.de>
parents:
8724
diff
changeset
|
1823 |
|
8421 | 1824 |
environment isNil ifTrue:[ |
1825 |
"/ no constraints |
|
1826 |
^ self |
|
1827 |
]. |
|
1828 |
||
5905 | 1829 |
(className isSymbol not |
1830 |
or:[className size == 0]) ifTrue:[ |
|
1831 |
self error:'invalid class name (must be a nonEmpty symbol)'. |
|
1832 |
]. |
|
1833 |
className first isLetter ifFalse:[ |
|
1834 |
self error:'invalid class name (must start with a letter)'. |
|
1835 |
]. |
|
1836 |
! |
|
1837 |
||
1838 |
checkConventionsFor:className subClassOf:aClass instVarNames:instVarNameString classVarNames:classVarNameString |
|
1839 |
"Check for some 'considered bad-style' things, like lower case names. |
|
1840 |
NOTICE: |
|
1841 |
I dont like the confirmers below - we need a notifying: argument, to give |
|
1842 |
the outer codeview a chance to highlight the error. |
|
1843 |
(but thats how its defined in the book - maybe I will change it anyway). |
|
1844 |
" |
|
1845 |
||
1846 |
|names idx what doChecks answ| |
|
1847 |
||
1848 |
doChecks := Metaclass confirmationQuerySignal query. |
|
1849 |
doChecks == false ifTrue:[^ true]. |
|
1850 |
||
1851 |
"let user confirm, if the classname is no good" |
|
1852 |
className first isUppercase ifFalse:[ |
|
1853 |
aClass == NameSpace ifTrue:[ |
|
1854 |
what := 'namespace' |
|
1855 |
] ifFalse:[ |
|
1856 |
what := 'class' |
|
1857 |
]. |
|
1858 |
||
1859 |
answ := Class classConventionViolationConfirmationQuerySignal query. |
|
1860 |
answ notNil ifTrue:[^ answ]. |
|
1861 |
||
1862 |
(self confirm:(what , ' name ''' , className , |
|
1863 |
''' should start with an uppercase letter |
|
1864 |
(by convention only) |
|
1865 |
||
1866 |
install anyway ?') withCRs) |
|
1867 |
ifFalse:[ |
|
1868 |
^ false |
|
1869 |
] |
|
1870 |
]. |
|
1871 |
||
1872 |
names := instVarNameString asCollectionOfWords. |
|
1873 |
||
1874 |
"let user confirm, if any instvarname is no good" |
|
1875 |
(idx := names findFirst:[:word | word first isUppercase]) ~~ 0 ifTrue:[ |
|
1876 |
answ := Class classConventionViolationConfirmationQuerySignal query. |
|
1877 |
answ notNil ifTrue:[^ answ]. |
|
1878 |
||
1879 |
(self confirm:className , ': instance variable named ''' , (names at:idx) allBold , ''' |
|
1880 |
should start with a lowercase letter (by convention only). |
|
1881 |
||
1882 |
Install anyway ?' withCRs) |
|
1883 |
ifFalse:[ |
|
1884 |
^ false |
|
1885 |
] |
|
1886 |
]. |
|
1887 |
||
1888 |
names := classVarNameString asCollectionOfWords. |
|
1889 |
||
1890 |
"let user confirm, if any classvarname is no good" |
|
1891 |
(idx := names findFirst:[:word | word first isLowercase]) ~~ 0 ifTrue:[ |
|
1892 |
answ := Class classConventionViolationConfirmationQuerySignal query. |
|
1893 |
answ notNil ifTrue:[^ answ]. |
|
1894 |
||
1895 |
(self confirm:className , ': class variable named ''' , (names at:idx) allBold , ''' |
|
1896 |
should start with an uppercase letter (by convention only). |
|
1897 |
||
1898 |
Install anyway ?' withCRs) |
|
1899 |
ifFalse:[ |
|
1900 |
^ false |
|
1901 |
]. |
|
1902 |
]. |
|
1903 |
||
1904 |
^ true |
|
1905 |
||
1906 |
"Created: / 15.10.1996 / 11:56:38 / cg" |
|
1907 |
"Modified: / 3.2.1999 / 11:24:52 / cg" |
|
1908 |
"Modified: / 18.3.1999 / 18:22:47 / stefan" |
|
1909 |
! |
|
1910 |
||
6034
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
1911 |
checkForCircularDefinitionFrom:oldClass |
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
1912 |
oldClass allSuperclasses do:[:cls | |
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
1913 |
cls name = realNewName ifTrue:[ |
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
1914 |
^ true |
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
1915 |
] |
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
1916 |
]. |
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
1917 |
|
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
1918 |
superClass notNil ifTrue:[ |
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
1919 |
superClass allSuperclasses do:[:cls | |
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
1920 |
cls name = realNewName ifTrue:[ |
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
1921 |
^ true |
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
1922 |
] |
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
1923 |
]. |
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
1924 |
]. |
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
1925 |
^ false |
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
1926 |
! |
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
1927 |
|
5905 | 1928 |
checkInstvarRedefsWith:stringOfInstVarNames subclassOf:aClass old:oldClass name:newName |
1929 |
|superInstVars msg| |
|
1930 |
||
1931 |
aClass notNil ifTrue:[ |
|
1932 |
" |
|
1933 |
check for instVar redef of superClass instVars |
|
1934 |
" |
|
1935 |
superInstVars := aClass allInstVarNames. |
|
1936 |
stringOfInstVarNames asCollectionOfWords do:[:nm | |
|
1937 |
(superInstVars includes:nm) ifTrue:[ |
|
1938 |
(oldClass notNil |
|
1939 |
and:[stringOfInstVarNames = oldClass instanceVariableString]) |
|
1940 |
ifTrue:[ |
|
1941 |
Transcript showCR:('instVar conflict in `' , newName , ''' for `' , nm , ''' due to superclass change.'). |
|
7132 | 1942 |
msg := 'InstVar conflict in `' , newName allBold , ''' for `' , nm allBold, ''' due to superclass change.\You now have two different instVar slots with the same name.\\Don''t forget to fix this later.'. |
5905 | 1943 |
self warn:msg withCRs. |
1944 |
] ifFalse:[ |
|
1945 |
Transcript showCR:('instVar `' , nm , ''' is already defined in a superclass of `' , newName , '''.'). |
|
7132 | 1946 |
msg := 'instVar `' , nm allBold, ''' is already defined in a superclass.\Change the definition of `' , newName allBold, ''' anyway ?\\Don''t forget to fix this later.'. |
5905 | 1947 |
^ self confirm:msg withCRs |
1948 |
]. |
|
1949 |
] |
|
1950 |
]. |
|
1951 |
]. |
|
1952 |
||
1953 |
oldClass notNil ifTrue:[ |
|
1954 |
" |
|
1955 |
check for instVar redefs in subclass instVars |
|
1956 |
" |
|
1957 |
oldClass allSubclassesDo:[:sub | |
|
1958 |
|vars| |
|
1959 |
||
1960 |
vars := sub instVarNames. |
|
1961 |
stringOfInstVarNames asCollectionOfWords do:[:nm | |
|
1962 |
(vars includes:nm) ifTrue:[ |
|
7132 | 1963 |
^ self confirm:('subclass `' |
1964 |
, sub name allBold |
|
1965 |
, ''' already defines an instVar named `' |
|
1966 |
, nm allBold |
|
5905 | 1967 |
, '''.\\Change the definition of `' |
7132 | 1968 |
, newName allBold |
1969 |
, ''' anyway ?\Notice: you must fix this later.' |
|
5905 | 1970 |
) withCRs |
1971 |
] |
|
1972 |
] |
|
1973 |
] |
|
1974 |
]. |
|
1975 |
^ true |
|
1976 |
||
1977 |
"Created: 29.1.1997 / 17:42:11 / cg" |
|
1978 |
! |
|
1979 |
||
8539 | 1980 |
checkValidPools |
1981 |
"check for invalid subclassing of UndefinedObject and SmallInteger" |
|
1982 |
||
1983 |
poolDictionaries notNil ifTrue:[ |
|
1984 |
poolDictionaries asCollectionOfWords do:[:eachPoolName | |
|
1985 |
|pool| |
|
1986 |
||
9187
9e9eb3e21448
send #isNameSpace instead of obsolete #isNamespace
Stefan Vogel <sv@exept.de>
parents:
9114
diff
changeset
|
1987 |
environment isNameSpace ifTrue:[ |
9114 | 1988 |
pool := environment classNamed:eachPoolName. |
1989 |
] ifFalse:[ |
|
1990 |
pool := environment nameSpace classNamed:eachPoolName. |
|
1991 |
]. |
|
8636 | 1992 |
pool isNil ifTrue:[ |
1993 |
pool := Smalltalk classNamed:eachPoolName. |
|
1994 |
]. |
|
8639 | 1995 |
(pool notNil and:[pool isBehavior]) ifTrue:[ |
1996 |
pool autoload. |
|
1997 |
pool isSharedPool ifFalse:[ |
|
1998 |
self error:('Not a valid pool: ' , eachPoolName) mayProceed:true. |
|
1999 |
] |
|
8539 | 2000 |
] |
2001 |
] |
|
2002 |
]. |
|
2003 |
! |
|
2004 |
||
5905 | 2005 |
checkValidSubclassing |
2006 |
"check for invalid subclassing of UndefinedObject and SmallInteger" |
|
2007 |
superClass notNil ifTrue:[ |
|
2008 |
superClass canBeSubclassed ifFalse:[ |
|
2009 |
self error:('it is not possible to subclass ' , superClass name). |
|
2010 |
] |
|
2011 |
]. |
|
2012 |
! |
|
2013 |
||
2014 |
checkValidVarNamesFor:className subClassOf:aClass instVarNames:instVarNameString classVarNames:classVarNameString |
|
2015 |
"Check for some 'considered bad-style' things, like lower case names. |
|
2016 |
NOTICE: |
|
2017 |
I dont like the confirmers below - we need a notifying: argument, to give |
|
2018 |
the outer codeview a chance to highlight the error. |
|
2019 |
(but thats how its defined in the book - maybe I will change it anyway). |
|
2020 |
" |
|
2021 |
||
2022 |
|names| |
|
2023 |
||
2024 |
names := instVarNameString asCollectionOfWords. |
|
2025 |
||
2026 |
"check for instvar redefs within local instvars" |
|
2027 |
names keysAndValuesDo:[:index :aName | |
|
2028 |
(names indexOf:aName startingAt:index+1) ~~ 0 ifTrue:[ |
|
2029 |
self warn:'instance variable ''' , aName , '''\occurs multiple times in instVarString.\\Class not installed.' withCRs. |
|
2030 |
^ false. |
|
2031 |
] |
|
2032 |
]. |
|
2033 |
||
2034 |
names := classVarNameString asCollectionOfWords. |
|
2035 |
||
2036 |
"check for classvar redefs within local instvars" |
|
2037 |
names keysAndValuesDo:[:index :aName | |
|
2038 |
(names indexOf:aName startingAt:index+1) ~~ 0 ifTrue:[ |
|
2039 |
self warn:'class variable ''' , aName , '''\occurs multiple times in classVarString.\\Class not installed.' withCRs. |
|
2040 |
^ false. |
|
2041 |
] |
|
2042 |
]. |
|
2043 |
^ true |
|
2044 |
||
2045 |
"Created: 8.1.1997 / 21:09:14 / cg" |
|
2046 |
"Modified: 9.1.1997 / 02:10:02 / cg" |
|
2047 |
! ! |
|
2048 |
||
2049 |
!ClassBuilder class methodsFor:'documentation'! |
|
2050 |
||
2051 |
version |
|
9187
9e9eb3e21448
send #isNameSpace instead of obsolete #isNamespace
Stefan Vogel <sv@exept.de>
parents:
9114
diff
changeset
|
2052 |
^ '$Header: /cvs/stx/stx/libbasic/ClassBuilder.st,v 1.48 2006-02-22 09:59:23 stefan Exp $' |
5905 | 2053 |
! ! |