Skip to content

Commit

Permalink
Improve the matching of inner classes in commit
Browse files Browse the repository at this point in the history
  • Loading branch information
tsantalis committed Jan 3, 2025
1 parent 6309cb1 commit 6f6a767
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/main/java/gr/uom/java/xmi/diff/ClassMoveComparator.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gr.uom.java.xmi.diff;

import java.util.Comparator;
import java.util.Set;

public class ClassMoveComparator implements Comparator<UMLClassMoveDiff> {

Expand All @@ -12,6 +13,11 @@ public int compare(UMLClassMoveDiff o1, UMLClassMoveDiff o2) {
return -Integer.compare(matchedMembers1, matchedMembers2);
}
else {
Set<String> set1 = o1.commonPackagesInQualifiedName();
Set<String> set2 = o2.commonPackagesInQualifiedName();
if(set1.size() != set2.size()) {
return -Integer.compare(set1.size(), set2.size());
}
double sourceFolderDistance1 = o1.getMovedClass().normalizedSourceFolderDistance(o1.getOriginalClass());
double sourceFolderDistance2 = o2.getMovedClass().normalizedSourceFolderDistance(o2.getOriginalClass());
if(sourceFolderDistance1 != sourceFolderDistance2) {
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/gr/uom/java/xmi/diff/UMLAbstractClassDiff.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static gr.uom.java.xmi.Constants.JAVA;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
Expand Down Expand Up @@ -188,6 +189,14 @@ public UMLModelDiff getModelDiff() {
return modelDiff;
}

public Set<String> commonPackagesInQualifiedName() {
List<String> packages1 = Arrays.asList(originalClass.getName().split("\\."));
List<String> packages2 = Arrays.asList(nextClass.getName().split("\\."));
Set<String> intersection = new LinkedHashSet<>(packages1);
intersection.retainAll(packages2);
return intersection;
}

protected void processAnnotations() {
this.annotationListDiff = new UMLAnnotationListDiff(originalClass.getAnnotations(), nextClass.getAnnotations());
for(UMLAnnotation annotation : annotationListDiff.getAddedAnnotations()) {
Expand Down

0 comments on commit 6f6a767

Please sign in to comment.