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