Skip to content

Commit

Permalink
Further improvement in matching classes taking into account file size
Browse files Browse the repository at this point in the history
  • Loading branch information
tsantalis committed Jan 3, 2025
1 parent 6f6a767 commit 537b999
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/main/java/gr/uom/java/xmi/LocationInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class LocationInfo {
private int startColumn;
private int endLine;
private int endColumn;
private int compilationUnitLength;
private CodeElementType codeElementType;

public LocationInfo(CompilationUnit cu, String sourceFolder, String filePath, ASTNode node, CodeElementType codeElementType) {
Expand Down Expand Up @@ -48,6 +49,12 @@ public LocationInfo(CompilationUnit cu, String sourceFolder, String filePath, AS
if(this.endColumn > 0) {
this.endColumn += 1;
}

int cuEndOffset = cu.getStartPosition() + cu.getLength();
this.compilationUnitLength = cu.getLineNumber(cuEndOffset);
if(this.compilationUnitLength == -1) {
this.compilationUnitLength = cu.getLineNumber(cuEndOffset-1);
}
}

public String getSourceFolder() {
Expand Down Expand Up @@ -86,6 +93,10 @@ public int getEndColumn() {
return endColumn;
}

public int getCompilationUnitLength() {
return compilationUnitLength;
}

public CodeElementType getCodeElementType() {
return codeElementType;
}
Expand Down
22 changes: 20 additions & 2 deletions src/main/java/gr/uom/java/xmi/diff/ClassMoveComparator.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,26 @@ public int compare(UMLClassMoveDiff o1, UMLClassMoveDiff o2) {
else {
Set<String> set1 = o1.commonPackagesInQualifiedName();
Set<String> set2 = o2.commonPackagesInQualifiedName();
if(set1.size() != set2.size()) {
return -Integer.compare(set1.size(), set2.size());
boolean sameNumberOfLines1 = o1.getOriginalClass().getLocationInfo().getCompilationUnitLength() == o1.getNextClass().getLocationInfo().getCompilationUnitLength();
boolean sameNumberOfLines2 = o2.getOriginalClass().getLocationInfo().getCompilationUnitLength() == o2.getNextClass().getLocationInfo().getCompilationUnitLength();
int lineNumberDifference1 = Math.abs(o1.getOriginalClass().getLocationInfo().getCompilationUnitLength() - o1.getNextClass().getLocationInfo().getCompilationUnitLength());
int lineNumberDifference2 = Math.abs(o2.getOriginalClass().getLocationInfo().getCompilationUnitLength() - o2.getNextClass().getLocationInfo().getCompilationUnitLength());
boolean isEmpty1 = o1.getOriginalClass().isEmpty() && o1.getNextClass().isEmpty();
boolean isEmpty2 = o2.getOriginalClass().isEmpty() && o2.getNextClass().isEmpty();
if(set1.size() != set2.size() && !isEmpty1 && !isEmpty2) {
if(lineNumberDifference1 == lineNumberDifference2)
return -Integer.compare(set1.size(), set2.size());
else {
if(sameNumberOfLines1 && !sameNumberOfLines2) {
return -1;
}
else if(!sameNumberOfLines1 && sameNumberOfLines2) {
return 1;
}
else {
return Integer.compare(lineNumberDifference1, lineNumberDifference2);
}
}
}
double sourceFolderDistance1 = o1.getMovedClass().normalizedSourceFolderDistance(o1.getOriginalClass());
double sourceFolderDistance2 = o2.getMovedClass().normalizedSourceFolderDistance(o2.getOriginalClass());
Expand Down

0 comments on commit 537b999

Please sign in to comment.