MethodChange.st
author Claus Gittinger <cg@exept.de>
Mon, 19 Jul 2004 13:58:02 +0200
changeset 1394 392398eeac68
parent 1325 b874a070362e
child 1468 e2a5a81a5961
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:#MethodChange
	instanceVariableNames:'selector methodCategory privacy previousVersion'
	classVariableNames:''
	poolDictionaries:''
	category:'System-Changes'
!

MethodChange subclass:#NamedMethodChange
	instanceVariableNames:'changeName'
	classVariableNames:''
	poolDictionaries:''
	privateIn:MethodChange
!

!MethodChange 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 method-changes (as done in the browser). 
    They are typically held in a ChangeSet.

    [author:]
        Claus Gittinger
"
! !

!MethodChange class methodsFor:'instance creation'!

class:cls selector:sel source:src category:cat
    ^ self basicNew class:cls selector:sel source:src category:cat
!

className:clsName selector:sel source:src category:cat
    ^ self basicNew className:clsName selector:sel source:src category:cat
! !

!MethodChange methodsFor:'accessing'!

category
    ^ methodCategory 
!

category: aCategory
    methodCategory := aCategory

    "Created: / 7.2.1998 / 19:47:53 / cg"
!

changeMethod
    |cls|

    cls := self changeClass.
    cls isNil ifTrue:[^ nil].
    ^ cls compiledMethodAt:selector 

    "Created: / 7.2.1998 / 19:47:53 / cg"
!

changeSelector
    ^ selector

    "Created: / 6.2.1998 / 13:29:25 / cg"
!

class:cls selector:sel source:src category:cat
    self className:(cls name) selector:sel source:src category:cat
!

className:clsName selector:sel source:src category:cat
    self className:clsName selector:sel source:src category:cat privacy:nil
!

className:clsName selector:sel source:src category:cat privacy:priv
    src isString ifFalse:[self halt].

    className := clsName.
    selector := sel.
    source := src.
    methodCategory := cat.
    privacy := priv.

    "Created: / 16.2.1998 / 12:29:49 / cg"
    "Modified: / 16.2.1998 / 14:28:12 / cg"
!

methodCategory

    ^ methodCategory

    "Created: / 7.2.1998 / 19:47:53 / cg"
!

previousPackage
    | isNewMethod |
    isNewMethod := self previousVersion isNil.
    isNewMethod ifFalse:[
        ^ self previousVersion package.
    ].

    ^ nil
!

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

    ^ previousVersion
!

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

    previousVersion := something.
!

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

    previousVersion isNil ifTrue:[^ nil].
    ^ previousVersion source
!

selector
    ^ selector

    "Created: / 6.2.1998 / 13:29:25 / cg"
!

selector:aSymbol
    selector := aSymbol

    "Created: / 6.2.1998 / 13:29:25 / cg"
! !

!MethodChange methodsFor:'applying'!

apply
    "apply the change"

    |className class|

    className := self className.

    class := Smalltalk classNamed:className.
    class isNil ifTrue:[
        class := Parser evaluate:className
    ].
    class isNil ifTrue:[
        self error:('Cannot apply change for missing class: ' , className).
    ].
    class compile:source classified:methodCategory logged:true.
! !

!MethodChange 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.)."

    "/ I am a methodChange - B must be as well.
    changeB isMethodChange ifFalse:[^ false].   

    selector ~= changeB selector ifTrue:[^ 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




! !

!MethodChange methodsFor:'converting'!

asNamedMethodChange
    ^ NamedMethodChange fromMethodChange:self
! !

!MethodChange methodsFor:'printing & storing'!

printOn:aStream
    "append a user printed representation of the receiver to aStream.
     The format is suitable for a human - not meant to be read back."

    aStream 
        nextPutAll:self className; 
        space; 
        nextPutAll:selector; 
        nextPutAll:' {'; 
        nextPutAll:methodCategory; 
        nextPutAll:'}' 
!

printWithoutClassNameOn:aStream
    (className endsWith:' class') ifTrue:[
        aStream nextPutAll:'class '
    ].
    aStream nextPutAll:selector 
!

printWithoutOwningClassOn:aStream
    self halt.
    (className endsWith:' class') ifTrue:[
        aStream nextPutAll:'class '
    ].
    aStream nextPutAll:selector 
! !

!MethodChange methodsFor:'queries'!

isMethodChange
    ^ true

    "Created: / 7.2.1998 / 19:26:59 / cg"
! !

!MethodChange::NamedMethodChange class methodsFor:'instance creation'!

fromMethodChange:aMethodChange
    ^ self new cloneInstanceVariablesFrom:aMethodChange
! !

!MethodChange::NamedMethodChange methodsFor:'accessing'!

changeName:something
    changeName := something.
! !

!MethodChange::NamedMethodChange methodsFor:'printing & storing'!

printOn:aStream
    changeName notNil ifTrue:[
        changeName printOn:aStream.
        ^ self.
    ].
    super printOn:aStream
! !

!MethodChange class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libbasic3/MethodChange.st,v 1.37 2004-07-19 11:57:54 cg Exp $'
! !