Skip to content

Commit

Permalink
Fix placement of extension methods when grouping by package.
Browse files Browse the repository at this point in the history
  • Loading branch information
chisandrei committed Jan 3, 2023
1 parent 3607388 commit 5ab737d
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,12 @@ BaselineOfGToolkit4Changes >> postLoadEpiceaChanges: spec [
self class environment
at: #TGtEpBehaviorCategoryChangeOldPackageName
ifPresent: [ :aTrait |
aClass addToComposition: aTrait ] ])
aClass addToComposition: aTrait ] ]).
(self class environment
at: #EpMethodModification
ifPresent: [ :aClass |
self class environment
at: #TGtEpMethodModificationClassPackagename
ifPresent: [ :aTrait |
aClass addToComposition: aTrait ] ]).
]
25 changes: 25 additions & 0 deletions src/GToolkit4Epicea/EpMethodModification.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@ EpMethodModification >> = other [
self newSourceCode = other newSourceCode ] ] ] ] ] ]
]

{ #category : #'*GToolkit4Epicea' }
EpMethodModification >> gtIsProtocolChangeForExtensionMethod [
self oldProtocol = self newProtocol ifTrue: [ ^ false ].

^ ((self oldProtocol beginsWith: '*') or: [
self newProtocol beginsWith: '*' ])
]

{ #category : #'*GToolkit4Epicea' }
EpMethodModification >> gtPreviousPackageName [
^ (self oldProtocol beginsWith: '*')
ifTrue: [ self oldProtocol copyWithFirst: '*' ]
ifFalse: [ self classPackageName ]
]

{ #category : #'*GToolkit4Epicea' }
EpMethodModification >> hash [
^ super hash
Expand All @@ -22,6 +37,16 @@ EpMethodModification >> hash [
bitXor: (self oldSourceCode hash bitXor: self newSourceCode hash)))))
]

{ #category : #'*GToolkit4Epicea' }
EpMethodModification >> initializeWithOldMethod: anOldMethod newMethod: aNewMethod [

self initialize.
oldMethod := anOldMethod asEpiceaRingDefinition.
newMethod := aNewMethod asEpiceaRingDefinition.

self updateClassPackageName.
]

{ #category : #'*GToolkit4Epicea' }
EpMethodModification >> isEpMethodModification [

Expand Down
25 changes: 23 additions & 2 deletions src/GToolkit4Epicea/GtEpHistoryGroupingExamples.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ GtEpHistoryGroupingExamples >> ensureSetup [
{ #category : #accessing }
GtEpHistoryGroupingExamples >> mainPackageNameForTesting [

^ #'CategoryForTestToBeDeleted'
^ #'CategoryForTestToBeDeleted-Default'
]

{ #category : #accessing }
Expand Down Expand Up @@ -135,13 +135,34 @@ GtEpHistoryGroupingExamples >> testMethodEventsWithNoImpactInNewClass [
{ #category : #examples }
GtEpHistoryGroupingExamples >> testTransformMethodToExtensionMethodEventsGrouping [
<gtExample>
| entries packageHistories |

| entries packageHistories mainPackageHistory secondPackageHistory methodHistoryInMainPackage methodHistoryInSecondPackage |
entries := self transformMethodToExtensionMethodEvents.
packageHistories := entries packageHistories.

self assert: packageHistories hasNoEffect not.
self assert: packageHistories size equals: 2.

mainPackageHistory := packageHistories
historyForPackageNamed: self mainPackageNameForTesting.
self assert: mainPackageHistory hasNoEffect not.

secondPackageHistory := packageHistories
historyForPackageNamed: self secondaryPackageNameForTesting.
self assert: mainPackageHistory hasNoEffect not.

methodHistoryInMainPackage := mainPackageHistory classHistories first methodHistories first.
self assert: methodHistoryInMainPackage hasNoEffect.
self assert: methodHistoryInMainPackage changes size equals: 2.
self assert: methodHistoryInMainPackage isInitialChangeAddition.
self assert: methodHistoryInMainPackage isLatestChangeRemoval.

methodHistoryInSecondPackage := secondPackageHistory classHistories first methodHistories first.
self assert: methodHistoryInSecondPackage hasNoEffect not.
self assert: methodHistoryInSecondPackage changes size equals: 1.
self assert: methodHistoryInSecondPackage isInitialChangeAddition.
self assert: methodHistoryInSecondPackage isLatestChangeRemoval not.

^ entries
]

Expand Down
5 changes: 5 additions & 0 deletions src/GToolkit4Epicea/GtEpiceaClassHistory.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ GtEpiceaClassHistory class >> forClass: aTargetClass withBehaviourChanges: aColl
sorted: [ :anEntry | anEntry gtTime] descending ))
]

{ #category : #accessing }
GtEpiceaClassHistory class >> methodHistoryType [
^ GtEpiceaMethodHistory
]

{ #category : #adding }
GtEpiceaClassHistory >> addMethodHistory: aMethodHistory [
self methodHistories add: aMethodHistory
Expand Down
9 changes: 8 additions & 1 deletion src/GToolkit4Epicea/GtEpiceaClassInPackageHistory.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ Class {
#category : #'GToolkit4Epicea-History'
}

{ #category : #accessing }
GtEpiceaClassInPackageHistory class >> methodHistoryType [
^ GtEpiceaMethodInPackageHistory
]

{ #category : #accessing }
GtEpiceaClassInPackageHistory >> isInitialBehaviourChangeAddition [
| epEvent |
Expand Down Expand Up @@ -36,5 +41,7 @@ GtEpiceaClassInPackageHistory >> targetPackageName [
{ #category : #accessing }
GtEpiceaClassInPackageHistory >> targetPackageName: aPackageName [

targetPackageName := aPackageName
targetPackageName := aPackageName.
methodHistories do: [ :aMethodHistory |
aMethodHistory targetPackageName: aPackageName ]
]
5 changes: 4 additions & 1 deletion src/GToolkit4Epicea/GtEpiceaClassesHistoryBuilder.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ GtEpiceaClassesHistoryBuilder >> buildHistory [

{ #category : #actions }
GtEpiceaClassesHistoryBuilder >> buildMethodHistories [
^ self entriesGroup methodHistories
^ (GtEpiceaMethodsHistoryBuilder
forEntriesGroup: self entriesGroup)
methodHistoryTypeName: self classHistoryType methodHistoryType name;
buildHistory
]

{ #category : #accessing }
Expand Down
35 changes: 35 additions & 0 deletions src/GToolkit4Epicea/GtEpiceaMethodInPackageHistory.class.st
Original file line number Diff line number Diff line change
@@ -1,5 +1,40 @@
Class {
#name : #GtEpiceaMethodInPackageHistory,
#superclass : #GtEpiceaMethodHistory,
#instVars : [
'targetPackageName'
],
#category : #'GToolkit4Epicea-History'
}

{ #category : #accessing }
GtEpiceaMethodInPackageHistory >> isInitialChangeAddition [
| epEvent |

epEvent := self initialChange content.
^ super isInitialChangeAddition or: [
(epEvent class = EpMethodModification and: [
epEvent gtIsProtocolChangeForExtensionMethod and: [
epEvent gtAffectedPackageName = self targetPackageName ] ]) ]
]

{ #category : #accessing }
GtEpiceaMethodInPackageHistory >> isLatestChangeRemoval [
| epEvent |

epEvent := self latestChange content.
^ super isLatestChangeRemoval or: [
(epEvent class = EpMethodModification and: [
epEvent gtIsProtocolChangeForExtensionMethod and: [
epEvent gtPreviousPackageName = self targetPackageName ] ]) ]
]

{ #category : #accessing }
GtEpiceaMethodInPackageHistory >> targetPackageName [
^ targetPackageName
]

{ #category : #accessing }
GtEpiceaMethodInPackageHistory >> targetPackageName: aPackageName [
targetPackageName := aPackageName
]
19 changes: 15 additions & 4 deletions src/GToolkit4Epicea/GtEpiceaPackagesHistoryBuilder.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,20 @@ GtEpiceaPackagesHistoryBuilder >> addExtraEventForCategoryChangeFor: anOmbuEntry

{ #category : #'accessing - grouping' }
GtEpiceaPackagesHistoryBuilder >> addExtraEventForExtensionMethodFor: anOmbuEntry toGroups: groupedByPackageName [
anOmbuEntry class = EpMethodModification ifFalse: [ ^ self ].
| event previousPackageName|
event := anOmbuEntry content.
event class = EpMethodModification ifFalse: [ ^ self ].

"TODO"
"We add an extra event in case the protocol of an extension method is involved"
event gtIsProtocolChangeForExtensionMethod ifFalse: [ ^ self ].

previousPackageName := event gtPreviousPackageName.
previousPackageName ifNil: [ ^ self ].

self
addCodeEntityChange: anOmbuEntry
toPackageNamed: previousPackageName
inGroups: groupedByPackageName
]

{ #category : #actions }
Expand Down Expand Up @@ -90,10 +101,10 @@ GtEpiceaPackagesHistoryBuilder >> groupedByPackageName [
toGroups: groupedByPackageName.
self
addExtraEventForCategoryChangeFor: anOmbuEntry
toGroups: groupedByPackageName."
toGroups: groupedByPackageName.
self
addExtraEventForExtensionMethodFor: anOmbuEntry
toGroups: groupedByPackageName" ].
toGroups: groupedByPackageName ].

^ groupedByPackageName
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Trait {
#name : #TGtEpMethodModificationClassPackagename,
#instVars : [
'classPackageName'
],
#category : #'GToolkit4Epicea-Model'
}

{ #category : #accessing }
TGtEpMethodModificationClassPackagename >> classPackageName [
^ classPackageName
]

{ #category : #accessing }
TGtEpMethodModificationClassPackagename >> updateClassPackageName [
self newMethod realParent
ifNotNil: [ :aParent |
classPackageName := aParent package name ]
]

0 comments on commit 5ab737d

Please sign in to comment.