ChangeSetDiff.st
author vrany
Tue, 29 Nov 2011 14:12:30 +0100
changeset 2630 deae273e56c3
parent 2629 4786ed332f59
child 2878 6b43d308b5f7
child 3011 1997ff6e7e55
permissions -rw-r--r--
changed: #versionA:versionB:versionBase: - fomatting && do not include version methods

"
 Copyright (c) 2007-2010 Jan Vrany, SWING Research Group,
                           Czech Technical University in Prague
 Copyright (c) 2009-2010 eXept Software AG

 Permission is hereby granted, free of charge, to any person
 obtaining a copy of this software and associated documentation
 files (the 'Software'), to deal in the Software without
 restriction, including without limitation the rights to use,
 copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the
 Software is furnished to do so, subject to the following
 conditions:

 The above copyright notice and this permission notice shall be
 included in all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
"
"{ Package: 'stx:libbasic3' }"

Object subclass:#ChangeSetDiff
	instanceVariableNames:'diffset'
	classVariableNames:''
	poolDictionaries:''
	category:'System-Changes-Diff'
!

!ChangeSetDiff class methodsFor:'documentation'!

copyright
"
 Copyright (c) 2007-2010 Jan Vrany, SWING Research Group,
                           Czech Technical University in Prague
 Copyright (c) 2009-2010 eXept Software AG

 Permission is hereby granted, free of charge, to any person
 obtaining a copy of this software and associated documentation
 files (the 'Software'), to deal in the Software without
 restriction, including without limitation the rights to use,
 copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the
 Software is furnished to do so, subject to the following
 conditions:

 The above copyright notice and this permission notice shall be
 included in all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.

"
! !

!ChangeSetDiff class methodsFor:'instance creation'!

new
    ^ self basicNew initialize.
! !

!ChangeSetDiff class methodsFor:'utilities'!

versionA:changesetA versionB:changesetB 
    ^ (self new)
        versionA:changesetA versionB:changesetB;
        diffset

    "Created: / 02-11-2009 / 16:12:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

versionA:changesetA versionB:changesetB versionBase: versionBase 
    ^ (self new)
        versionA:changesetA versionB:changesetB versionBase: versionBase;
        diffset

    "Created: / 03-11-2009 / 07:58:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!ChangeSetDiff methodsFor:'accessing'!

diffset
    ^ diffset
! !

!ChangeSetDiff methodsFor:'diffing'!

versionA:changesetA versionB:changesetB 

    self versionA:changesetA versionB:changesetB versionBase: nil

    "Created: / 31-10-2009 / 19:12:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 02-11-2009 / 18:38:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

versionA:a versionB:b versionBase:base 
    |ds diffsByClass include|

    diffsByClass := Dictionary new.
    ds := a diffSetsAgainst:b.
    include := [:chg | 
            (AbstractSourceCodeManager isVersionMethodSelector:chg selector) not
        ].
    ds onlyInReceiver do:[:chg | 
        (include value:chg) ifTrue:[
            (diffsByClass at:(chg nonMetaClassName isNil ifTrue:[
                        chg class name
                    ])
                ifAbsentPut:[ChangeSetDiffSet new name:chg nonMetaClassName]) 
                    add:(ChangeSetDiffEntry versionA:chg)
        ]
    ].
    ds changed do:[:chgPair | 
        (include value:chgPair first) ifTrue:[
            (diffsByClass at:chgPair first nonMetaClassName
                ifAbsentPut:[ChangeSetDiffSet new name:chgPair first nonMetaClassName]) 
                    add:(ChangeSetDiffEntry versionA:chgPair first versionB:chgPair second)
        ]
    ].
    ds onlyInArg do:[:chg | 
        (include value:chg) ifTrue:[
            (diffsByClass at:chg nonMetaClassName
                ifAbsentPut:[ChangeSetDiffSet new name:chg nonMetaClassName]) 
                    add:(ChangeSetDiffEntry versionB:chg)
        ]
    ].
    base notNil ifTrue:[
        "Try to assign base version to each diff item"
        "Sorry, we are using O^2 algorithm here, I'm too lazy now :-)"
        diffsByClass do:[:diffs | 
            diffs do:[:diff | 
                |versionBase|

                versionBase := base 
                            detect:[:each | each isForSameAs:diff versionA]
                            ifNone:[nil].
                versionBase isNil ifTrue:[
                    diff versionA isClassRemoveChangeOrMethodRemoveChange not ifTrue:[
                        versionBase := diff versionA asAntiChange
                    ] ifFalse:[
                        versionBase := diff versionA copy
                    ]
                ].
                diff versionBase:versionBase.
                diff automerge
            ]
        ]
    ].
    diffsByClass size = 1 ifTrue:[
        diffset addAll:diffsByClass anyOne diffs
    ] ifFalse:[
        diffset addAll:diffsByClass values
    ].
    diffset versionALabel:a name.
    diffset versionBLabel:b name.
    base notNil ifTrue:[
        diffset versionBaseLabel:base name.
    ].

    "Created: / 02-11-2009 / 16:17:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 29-06-2011 / 08:22:49 / Jan Vrany <enter your email here>"
    "Modified (format): / 29-11-2011 / 14:11:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!ChangeSetDiff methodsFor:'initialization'!

initialize
    "Invoked when a new instance is created."

    "/ please change as required (and remove this comment)
    diffset := ChangeSetDiffSet new.

    "/ super initialize.   -- commented since inherited method does nothing

    "Modified: / 06-07-2011 / 13:00:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!ChangeSetDiff class methodsFor:'documentation'!

version_CVS
    ^ '$Header: /cvs/stx/stx/libbasic3/ChangeSetDiff.st,v 1.3 2011-11-29 13:12:30 vrany Exp $'
! !