Metaclass.st
changeset 3 24d81bf47225
parent 2 6526dde5f3ac
child 5 67342904af11
equal deleted inserted replaced
2:6526dde5f3ac 3:24d81bf47225
    24 
    24 
    25 every class-class is a subclass of Metaclass
    25 every class-class is a subclass of Metaclass
    26 - this adds support for creating new subclasses or changing the definition
    26 - this adds support for creating new subclasses or changing the definition
    27 of an already existing class.
    27 of an already existing class.
    28 
    28 
    29 %W% %E%
    29 $Header: /cvs/stx/stx/libbasic/Metaclass.st,v 1.3 1993-10-13 00:16:31 claus Exp $
    30 '!
    30 '!
    31 
    31 
    32 !Metaclass methodsFor:'creating classes'!
    32 !Metaclass methodsFor:'creating classes'!
    33 
    33 
    34 name:newName inEnvironment:aSystemDictionary
    34 name:newName inEnvironment:aSystemDictionary
   156         newClass comment:newComment
   156         newClass comment:newComment
   157     ].
   157     ].
   158 
   158 
   159     superClassChange := oldClass superclass ~~ newClass superclass.
   159     superClassChange := oldClass superclass ~~ newClass superclass.
   160 
   160 
       
   161     "dont allow built-in classes to be modified"
       
   162     (oldClass notNil and:[oldClass isBuiltInClass and:[superClassChange]]) ifTrue:[
       
   163         self error:'the inheritance of this class is fixed - you cannot change it'.
       
   164         ^ oldClass
       
   165     ].
       
   166 
   161     (superClassChange 
   167     (superClassChange 
   162      and:[
   168      and:[
   163         (oldClass superclass isNil or:[oldClass superclass name = newClass superclass name])
   169         (oldClass superclass isNil or:[oldClass superclass name = newClass superclass name])
   164         and:[
   170         and:[
   165             (oldClass classVariableString = newClass classVariableString) 
   171             (oldClass classVariableString = newClass classVariableString) 
   251         ] ifTrue:[
   257         ] ifTrue:[
   252             oldNames := oldClass instanceVariableString asCollectionOfWords.
   258             oldNames := oldClass instanceVariableString asCollectionOfWords.
   253             newNames := newClass instanceVariableString asCollectionOfWords.
   259             newNames := newClass instanceVariableString asCollectionOfWords.
   254 
   260 
   255             instVarChange := (oldNames ~= newNames).
   261             instVarChange := (oldNames ~= newNames).
       
   262 
       
   263             "dont allow built-in classes to be modified"
       
   264             (oldClass notNil and:[oldClass isBuiltInClass and:[instVarChange]]) ifTrue:[
       
   265                 self error:'the layout of this class is fixed - you cannot change it'.
       
   266                 ^ oldClass
       
   267             ].
       
   268 
   256             instVarChange ifTrue:[
   269             instVarChange ifTrue:[
   257 
   270 
   258                 ((oldNames size == 0) 
   271                 ((oldNames size == 0) 
   259                 or:[newNames startsWith:oldNames]) ifTrue:[
   272                 or:[newNames startsWith:oldNames]) ifTrue:[
   260                     "new variable(s) has/have been added - old methods still work"
   273                     "new variable(s) has/have been added - old methods still work"