class: oldClass instanceVariableNames: instVarString unsafe: unsafe
"This is the basic initialization message to change the definition of
an existing Metaclass"
| instVars newClass needNew copyOfOldClass |
environ := oldClass environment.
instVars := Scanner new scanFieldNames: instVarString.
unsafe ifFalse:[
"Run validation checks so we know that we have a good chance for recompilation"
(self validateInstvars: instVars from: oldClass forSuper: oldClass superclass) ifFalse:[^nil].
(self validateSubclassFormat: oldClass typeOfClass from: oldClass forSuper: oldClass superclass extra: instVars size) ifFalse:[^nil]].
"See if we need a new subclass or not"
needNew := self needsSubclassOf: oldClass superclass type: oldClass typeOfClass instanceVariables: instVars from: oldClass.
needNew ifNil:[^nil]. "some error"
needNew ifFalse:[^oldClass]. "no new class needed"
"Create the new class"
copyOfOldClass := oldClass copy.
newClass := self
newSubclassOf: oldClass superclass
type: oldClass typeOfClass
instanceVariables: instVars
from: oldClass.
newClass := self recompile: false from: oldClass to: newClass mutate: false.
self doneCompiling: newClass.
SystemChangeNotifier uniqueInstance classDefinitionChangedFrom: copyOfOldClass to: newClass.
^newClass
and change newclass
newSubclassOf: newSuper type: type instanceVariables: instVars from: oldClass
"Create a new subclass of the given superclass with the given specification."
| newFormat newClass |
"Compute the format of the new class"
newFormat :=
self computeFormat: type
instSize: instVars size
forSuper: newSuper
ccIndex: (oldClass ifNil:[0] ifNotNil:[oldClass indexIfCompact]).
newFormat == nil ifTrue:[^nil].
(oldClass == nil or:[oldClass isMeta not])
ifTrue:[newClass := self privateNewSubclassOf: newSuper from: oldClass]
ifFalse:[newClass := oldClass clone].
newClass
superclass: newSuper
methodDictionary: MethodDictionary new
format: newFormat;
setInstVarNames: instVars.
oldClass ifNotNil:[
newClass organization: oldClass organization.
"Recompile the new class"
oldClass hasMethods
ifTrue:[newClass compileAllFrom: oldClass].
oldClass hasTraitComposition ifTrue: [
newClass setTraitComposition: oldClass traitComposition copyTraitExpression ].
oldClass class hasTraitComposition ifTrue: [
newClass class setTraitComposition: oldClass class traitComposition copyTraitExpression ].
self recordClass: oldClass replacedBy: newClass.
].
(oldClass == nil or:[oldClass isObsolete not])
ifTrue:[newSuper addSubclass: newClass]
ifFalse:[newSuper addObsoleteSubclass: newClass].
^newClass
Now I was wondering why you did not change
newClass := self recompile: false from: oldClass to: newClass mutate: false. too
Stef