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