Skip to content

Commit

Permalink
Fix bug I found
Browse files Browse the repository at this point in the history
  • Loading branch information
jecisc committed Jun 10, 2024
1 parent 920fa18 commit 17a9eaa
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 21 deletions.
16 changes: 8 additions & 8 deletions src/Famix-Diff-Core-Tests/FamixDiffTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,14 @@ FamixDiffTest >> testAddedEntities [
self createTestDiffForAdditionsAndRemovalsEdgeCases.
addition := result additions.

self assert: (result select: [ :change | change baseEntity isKindOf: FamixStPackage ]) size equals: 1.
self assert: (result detect: [ :change | change baseEntity isKindOf: FamixStPackage ]) name equals: self packageName3.
self assert: (result select: [ :change | change baseEntity isKindOf: FamixStClass ]) size equals: 1.
self assert: (result detect: [ :change | change baseEntity isKindOf: FamixStClass ]) name equals: #C3.
self assert: (result select: [ :change | change baseEntity isKindOf: FamixStMethod ]) size equals: 1.
self assert: (result detect: [ :change | change baseEntity isKindOf: FamixStMethod ]) name equals: #m5.
self assert: (result select: [ :change | change baseEntity isKindOf: FamixStLocalVariable ]) size equals: 1.
self assert: (result detect: [ :change | change baseEntity isKindOf: FamixStLocalVariable ]) name equals: #temp3
self assert: (addition select: [ :change | change baseEntity isKindOf: FamixStPackage ]) size equals: 1.
self assert: (addition detect: [ :change | change baseEntity isKindOf: FamixStPackage ]) entity name equals: self packageName3.
self assert: (addition select: [ :change | change baseEntity isKindOf: FamixStClass ]) size equals: 1.
self assert: (addition detect: [ :change | change baseEntity isKindOf: FamixStClass ]) entity name equals: #C3.
self assert: (addition select: [ :change | change baseEntity isKindOf: FamixStMethod ]) size equals: 1.
self assert: (addition detect: [ :change | change baseEntity isKindOf: FamixStMethod ]) entity name equals: #m5.
self assert: (addition select: [ :change | change baseEntity isKindOf: FamixStLocalVariable ]) size equals: 1.
self assert: (addition detect: [ :change | change baseEntity isKindOf: FamixStLocalVariable ]) entity name equals: #temp3
]

{ #category : #tests }
Expand Down
63 changes: 50 additions & 13 deletions src/Famix-Diff-Core/FamixDiffResolver.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -135,24 +135,17 @@ FamixDiffResolver >> diffAssociations [
FamixDiffResolver >> diffEntities [

[ :job |
| baseTodo targetTodo |
job max: self baseModel entities size.
"loops on this block"
[
| entitiesToMatchSize |
entitiesToMatchSize := (self entitiesToMatchIn: self baseModel) size.
job
currentValue: (job max - entitiesToMatchSize);
label: 'Diff computation in progress. ' , entitiesToMatchSize asString , ' left out of ' , self baseModel entities size asString.
self updateProgressBarOf: job.
self findNextIdentitiesRenamingsOrMovedEntities.

baseTodo := (self topEntitiesToMatchIn: self baseModel) asOrderedCollection.
targetTodo := (self topEntitiesToMatchIn: self targetModel) asOrderedCollection.
self updateProgressBarOf: job.

"as soon as one return true, go to next loop iteration"
(self identityMatchesFrom: baseTodo to: targetTodo) or: [
(self renameMatchesFrom: baseTodo to: targetTodo) or: [
(self moveMatchesFrom: baseTodo to: targetTodo) or: [ (self removedEntitiesFrom: baseTodo) or: [ self addedEntitiesFrom: targetTodo ] ] ] ] ] whileTrue ]
asJob run
self lookForMovedEntitiesInUnmatchedEntities or: [
self updateProgressBarOf: job.
self lookForAddedAndRemovedEntities ] ] whileTrue ] asJob run
]

{ #category : #'run-entities' }
Expand All @@ -163,6 +156,19 @@ FamixDiffResolver >> entitiesToMatchIn: aModel [
^ aModel entities select: [ :e | self shouldMatch: e ]
]

{ #category : #'run-entities' }
FamixDiffResolver >> findNextIdentitiesRenamingsOrMovedEntities [

[
| baseTodo targetTodo |
baseTodo := self topEntitiesToMatchIn: self baseModel.
targetTodo := self topEntitiesToMatchIn: self targetModel.

"as soon as one return true, go to next loop iteration"
(self identityMatchesFrom: baseTodo to: targetTodo) or: [
(self renameMatchesFrom: baseTodo to: targetTodo) or: [ self moveMatchesFrom: baseTodo to: targetTodo ] ] ] whileTrue
]

{ #category : #testing }
FamixDiffResolver >> hasParentMatched: entity [
"Return true only if the parents of the entity are already matched.
Expand Down Expand Up @@ -213,6 +219,24 @@ FamixDiffResolver >> is: baseEntity sameAs: targetEntity [
^ false
]

{ #category : #'run-entities' }
FamixDiffResolver >> lookForAddedAndRemovedEntities [

[
| baseTodo targetTodo |
baseTodo := self topEntitiesToMatchIn: self baseModel.
targetTodo := self topEntitiesToMatchIn: self targetModel.
(self addedEntitiesFrom: targetTodo) or: [ self removedEntitiesFrom: baseTodo ] ] whileTrue.

^ false
]

{ #category : #'run-entities' }
FamixDiffResolver >> lookForMovedEntitiesInUnmatchedEntities [

^ self moveMatchesFrom: (self entitiesToMatchIn: self baseModel) to: (self entitiesToMatchIn: self targetModel)
]

{ #category : #testing }
FamixDiffResolver >> matched: entity [
^ self changesDico includesKey: entity
Expand Down Expand Up @@ -246,6 +270,7 @@ FamixDiffResolver >> moveMatchesFrom: baseEntities to: targetEntities [
to: targetEntities
ifMatch: [ :baseEntity :targetEntity |
| match |
targetEntities remove: targetEntity.
match := FamixMoveChange base: baseEntity target: targetEntity.
self changesDico
at: baseEntity put: match;
Expand Down Expand Up @@ -292,6 +317,7 @@ FamixDiffResolver >> renameMatchesFrom: baseEntities to: targetEntities [
to: targetEntities
ifMatch: [ :baseEntity :targetEntity |
| match |
targetEntities remove: targetEntity.
match := FamixRenameChange base: baseEntity target: targetEntity.
self changesDico
at: baseEntity put: match;
Expand Down Expand Up @@ -342,3 +368,14 @@ FamixDiffResolver >> topEntitiesToMatchIn: aModel [

^ (self entitiesToMatchIn: aModel) select: [ :entity | self hasParentMatched: entity ]
]

{ #category : #'run-entities' }
FamixDiffResolver >> updateProgressBarOf: job [

| entitiesToMatchSize |
entitiesToMatchSize := (self entitiesToMatchIn: self baseModel) size.

job
label: 'Diff computation in progress. ' , entitiesToMatchSize asString , ' left out of ' , job max asString;
currentValue: job max - entitiesToMatchSize
]

0 comments on commit 17a9eaa

Please sign in to comment.