ClassDefinitionChange.st
author Claus Gittinger <cg@exept.de>
Mon, 21 Nov 2005 18:32:20 +0100
changeset 1434 bc28c94f2e04
parent 1427 ada0805a62aa
child 1473 a8fe22600414
permissions -rw-r--r--
*** empty log message ***

"
 COPYRIGHT (c) 1993 by Claus Gittinger
	      All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"

"{ Package: 'stx:libbasic3' }"

ClassChange subclass:#ClassDefinitionChange
	instanceVariableNames:'objectType nameSpaceName superClassName classType indexedType
		otherParameters instanceVariableNames classVariableNames
		classInstanceVariableNames poolDictionaries category'
	classVariableNames:''
	poolDictionaries:''
	category:'System-Changes'
!

!ClassDefinitionChange class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1993 by Claus Gittinger
	      All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
!

documentation
"
    instances represent class definition-changes. 
    They are typically held in a ChangeSet.

    [author:]
        Claus Gittinger
"
! !

!ClassDefinitionChange methodsFor:'accessing'!

basicSuperClassName 
    ^ superClassName
!

category
    ^ category
!

category:something
    category := something.
!

classInstanceVariableNames
    ^ classInstanceVariableNames
!

classInstanceVariableNames:something
    classInstanceVariableNames := something.
!

classVariableNames
    ^ classVariableNames
!

classVariableNames:something
    classVariableNames := something.
!

instanceVariableNames
    ^ instanceVariableNames
!

instanceVariableNames:something
    instanceVariableNames := something.
!

nameSpaceName
    objectType == #variable ifTrue:[
        ^ nil
    ].
    ^ self cutNameSpaceOf:(nameSpaceName ? super nameSpaceName)
!

nameSpaceName: aNameSpaceName classType: aClassType otherParameters:otherParametersArg
    |indexedType private imports|

    nameSpaceName := aNameSpaceName.
    classType := aClassType.
    otherParameters := Dictionary new addAll:otherParametersArg; yourself.

    superClassName := otherParameters at:#superclass: ifAbsent:nil.
    superClassName notNil ifTrue:[
        superClassName := superClassName pathString.
    ].
    indexedType := otherParameters at:#indexedType: ifAbsent:nil.
    private := otherParameters at:#private: ifAbsent:nil.
    instanceVariableNames := otherParameters at:#instanceVariableNames: ifAbsent:nil.
    classInstanceVariableNames := otherParameters at:#classInstanceVariableNames: ifAbsent:nil.
    imports := otherParameters at:#imports: ifAbsent:nil.
    category := otherParameters at:#category: ifAbsent:nil.
!

objectType
    "return the value of the instance variable 'objectType' (automatically generated)"

    ^ objectType
!

objectType:something
    "set the value of the instance variable 'objectType' (automatically generated)"

    objectType := something.
!

package:aPackageID
    package := aPackageID
!

poolDictionaries
    ^ poolDictionaries
!

poolDictionaries:something
    poolDictionaries := something.
!

source
    "return the source of the change"

    |src nsName|

    source isNil ifTrue:[
        src := self definitionString
    ] ifFalse:[
        src := super source
    ].

    (nsName := self nameSpaceName) notNil ifTrue:[
        ^ '"{ NameSpace: ' , nsName , ' }"' , 
          Character cr, Character cr , 
          src
    ].
    ^ src
!

superClassName 
    ^ self cutNameSpaceOf:superClassName
!

superClassName:something
    superClassName := something.
! !

!ClassDefinitionChange methodsFor:'comparing'!

isForSameAs:changeB
    "return true, if the given change represents a change for the same
     thingy as the receiver (i.e. same method, same definition etc.)."

    changeB isClassDefinitionChange ifFalse:[^ false].   

    className ~= changeB className ifTrue:[^ false].
    ^ true





!

sameAs:changeB
    "return true, if the given change represents the same change as the receiver."

    (self isForSameAs:changeB) ifFalse:[^ false].
    ^ self sameSourceAs:changeB



! !

!ClassDefinitionChange methodsFor:'printing & storing'!

definitionString
    ^ String streamContents:[:stream |
        objectType == #variable ifTrue:[
            stream 
                nextPutAll:((nameSpaceName asCollectionOfSubstringsSeparatedBy:$.) asStringWith:'::');
                nextPutAll:' addClassVarName:';
                nextPutAll:className asString storeString
        ] ifFalse:[
            stream 
                nextPutAll:self superClassName;
                nextPutAll:' subclass:';
                nextPutAll:self className asSymbol storeString
                ;
                cr;
                spaces:4;
                nextPutAll:'instanceVariableNames: ';
                nextPutAll:(instanceVariableNames ? '') storeString;
                cr;
                spaces:4;
                nextPutAll:'classVariableNames: ';
                nextPutAll:(classVariableNames ? '') storeString;
                cr;
                spaces:4;
                nextPutAll:'poolDictionaries: ';
                nextPutAll:(poolDictionaries ? '') storeString;
                cr;
                spaces:4;
                nextPutAll:'category: ';
                nextPutAll:(category ? '') storeString
            ]
        ]
!

printOn:aStream
    aStream nextPutAll:className
!

printWithoutClassNameOn:aStream
    aStream nextPutAll:('definition of ' , className)


! !

!ClassDefinitionChange methodsFor:'queries'!

definitionSelector
    |parseTree|

    parseTree := Parser parseExpression:self source.
    parseTree isMessage ifTrue:[
        ^ parseTree selector
    ].
    self error:'should not happen'.
!

isClassDefinitionChange
    ^ true
! !

!ClassDefinitionChange methodsFor:'special'!

installAsAutoloadedClassIfPublicWithFilename:aFilenameString
    "install the class defined by this change as autoloaded.
     Skip private classes.
     Enter class file name as abbreviation"

    |parseTree sel cat clsName catIdx|

    parseTree := Parser parseExpression:self source.
    parseTree isMessage ifFalse:[
        self error:'bad change source'.
    ].

    sel := parseTree selector.
    (sel endsWith:':privateIn:') ifTrue:[^ self].

    catIdx := sel keywords indexOf:'category:'.  
    catIdx ~~ 0 ifTrue:[
        cat := (parseTree args at:catIdx) evaluate.
    ].

    clsName := self className asSymbol.

    ((Smalltalk includesKey:clsName) not 
     or:[(Smalltalk at:clsName) isBehavior not
     or:[(Smalltalk at:clsName) isLoaded not]]) ifTrue:[
        |pkg|

        pkg := package ? Project current package.   
        Smalltalk 
           installAutoloadedClassNamed:clsName 
           category:cat 
           package:pkg 
           revision:nil.
        aFilenameString notNil ifTrue:[
            Smalltalk setFilename:aFilenameString forClass:clsName package:pkg.
        ]
    ]
! !

!ClassDefinitionChange class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libbasic3/ClassDefinitionChange.st,v 1.35 2005-11-21 17:32:20 cg Exp $'
! !