# HG changeset patch # User Claus Gittinger # Date 1031135573 -7200 # Node ID 630b8b5260cc7a5fec8c404133fcf0dd01940505 # Parent 7bbf6fdeda01dd4451a2e86db076c2b8d9a7255d refactored; separated classVarNameKey generation to a single method diff -r 7bbf6fdeda01 -r 630b8b5260cc Class.st --- a/Class.st Fri Aug 23 10:49:28 2002 +0200 +++ b/Class.st Wed Sep 04 12:32:53 2002 +0200 @@ -384,12 +384,30 @@ !Class methodsFor:'accessing'! +addChangeRecordForClass:aClass andNotifyChangeOf:aspect + "writes a change record and notifies dependents." + + |namespace| + + self addChangeRecordForClass:aClass. + + aClass changed:#definition. + + namespace := aClass nameSpace. + namespace changed:#classDefinition with:aClass. + namespace ~~ Smalltalk ifTrue:[ + Smalltalk changed:#classDefinition with:aClass. + ]. + namespace changed:aspect with:aClass. + namespace ~~ Smalltalk ifTrue:[ + Smalltalk changed:aspect with:aClass. + ]. +! + addClassVarName:aString "add a class variable if not already there and initialize it with nil. Also writes a change record and notifies dependents." - |namespace| - (self classVarNames includes:aString) ifFalse:[ self classVariableString:(self classVariableString , ' ' , aString). Class withoutUpdatingChangesDo:[ @@ -398,17 +416,7 @@ (Array with:aString asSymbol) ]. ]. - self addChangeRecordForClass:self. - - self changed:#definition. - (namespace := self nameSpace) changed:#classDefinition with:self. - namespace ~~ Smalltalk ifTrue:[ - Smalltalk changed:#classDefinition with:self. - ]. - (namespace := self nameSpace) changed:#classVariables with:self. - namespace ~~ Smalltalk ifTrue:[ - Smalltalk changed:#classVariables with:self. - ]. + self addChangeRecordForClass:self andNotifyChangeOf:#classVariables. ] "Created: / 29.10.1995 / 19:40:51 / cg" @@ -471,7 +479,7 @@ the Smalltalk dictionary with a funny name, since there are no classPools yet. " - ^ Smalltalk at:(self name , ':' , aSymbol) asSymbol + ^ Smalltalk at:(self globalKeyForClassVar:aSymbol) ! classVarAt:aSymbol ifAbsent:exceptionBlock @@ -485,7 +493,7 @@ the Smalltalk dictionary with a funny name, since there are no classPools yet. " - ^ Smalltalk at:(self name , ':' , aSymbol) asSymbol ifAbsent:exceptionBlock + ^ Smalltalk at:(self globalKeyForClassVar:aSymbol) ifAbsent:exceptionBlock ! classVarAt:aSymbol put:something @@ -499,7 +507,7 @@ the Smalltalk dictionary with a funny name, since there are no classPools yet. " - Smalltalk at:(self name , ':' , aSymbol) asSymbol put:something. + Smalltalk at:(self globalKeyForClassVar:aSymbol) put:something. ! classVarNames @@ -633,6 +641,15 @@ ^ self nameSpace ! +globalKeyForClassVar:aStringOrSymbol + "this helps to encapsulate the (current) implementation of classVariables + from the outside world. Currently, classvars are stored in + the Smalltalk dictionary with a funny name, since there are + no classPools yet. + " + ^ (self name , ':' , aStringOrSymbol) asSymbol +! + name "return the name of the class. This returns a symbol (but notice, that other smalltalks might return a string)." @@ -990,7 +1007,7 @@ "remove a class variable if not already there. Also writes a change record and notifies dependents." - |names newNames namespace| + |names newNames| names := self classVarNames. (names includes:aString) ifTrue:[ @@ -1003,17 +1020,7 @@ (Array with:aString asSymbol) ]. ]. - self addChangeRecordForClass:self. - - self changed:#definition. - (namespace := self nameSpace) changed:#classDefinition with:self. - namespace ~~ Smalltalk ifTrue:[ - Smalltalk changed:#classDefinition with:self. - ]. - (namespace := self nameSpace) changed:#classVariables with:self. - namespace ~~ Smalltalk ifTrue:[ - Smalltalk changed:#classVariables with:self. - ]. + self addChangeRecordForClass:self andNotifyChangeOf:#classVariables. ] "Created: / 29.10.1995 / 19:42:08 / cg" @@ -1982,11 +1989,7 @@ fullName := FileOutNameSpaceQuerySignal query == true. owner := self owningClass. - owner isNil ifTrue:[ - ns := self nameSpace. - ] ifFalse:[ - ns := self topOwningClass nameSpace. - ]. + ns := self topNameSpace. (showPackage and:[owner isNil]) ifTrue:[ aStream nextPutAll:'"{ Package: '''. @@ -4710,5 +4713,5 @@ !Class class methodsFor:'documentation'! version - ^ '$Header: /cvs/stx/stx/libbasic/Class.st,v 1.416 2002-08-16 11:49:35 cg Exp $' + ^ '$Header: /cvs/stx/stx/libbasic/Class.st,v 1.417 2002-09-04 10:32:53 cg Exp $' ! !