Skip to content

Commit

Permalink
Handle multiple matches in inferClassRenameBasedOnFilePaths()
Browse files Browse the repository at this point in the history
  • Loading branch information
tsantalis committed Jan 15, 2025
1 parent 66f2733 commit 8a204f4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
3 changes: 0 additions & 3 deletions src/main/java/gr/uom/java/xmi/UMLAbstractClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -820,9 +820,6 @@ else if(operation.isConstructor() && commonTokens >= Math.max(tokens1.length, to
if(commonOperations.size() > Math.floor(totalOperations/2.0) || commonOperations.containsAll(this.operations)) {
return new MatchResult(commonOperations.size(), commonAttributes.size(), identicalOperations.size(), totalOperations, totalAttributes, true);
}
else if(commonAttributes.size() == totalAttributes && totalAttributes > 0 && commonOperations.size() > 0) {
return new MatchResult(commonOperations.size(), commonAttributes.size(), identicalOperations.size(), totalOperations, totalAttributes, true);
}
else {
return new MatchResult(commonOperations.size(), commonAttributes.size(), identicalOperations.size(), totalOperations, totalAttributes, false);
}
Expand Down
17 changes: 10 additions & 7 deletions src/main/java/gr/uom/java/xmi/diff/UMLModelDiff.java
Original file line number Diff line number Diff line change
Expand Up @@ -1268,25 +1268,28 @@ public void inferClassRenameBasedOnFilePaths(UMLClassMatcher matcher) throws Ref
for(Iterator<UMLClass> removedClassIterator = removedClasses.iterator(); removedClassIterator.hasNext();) {
UMLClass removedClass = removedClassIterator.next();
String removedClassFilePath = removedClass.getSourceFile();
TreeSet<UMLClassRenameDiff> diffSet = new TreeSet<UMLClassRenameDiff>(new ClassRenameComparator());
for(Iterator<UMLClass> addedClassIterator = addedClasses.iterator(); addedClassIterator.hasNext();) {
UMLClass addedClass = addedClassIterator.next();
String addedClassFilePath = addedClass.getSourceFile();
for(UMLClassRenameDiff classRenameDiff : classRenameDiffList) {
if(classRenameDiff.getOriginalClass().isTopLevel() && classRenameDiff.getNextClass().isTopLevel() &&
classRenameDiff.getOriginalClass().getSourceFile().equals(removedClassFilePath) &&
if(classRenameDiff.getOriginalClass().getSourceFile().equals(removedClassFilePath) &&
classRenameDiff.getNextClass().getSourceFile().equals(addedClassFilePath)) {
MatchResult matchResult = matcher.match(removedClass, addedClass);
if(matchResult.getMatchedOperations() > 0 || matchResult.getMatchedAttributes() > 0) {
UMLClassRenameDiff newClassRenameDiff = new UMLClassRenameDiff(removedClass, addedClass, this, matchResult);
newClassRenameDiff.process();
diffsToBeAdded.add(newClassRenameDiff);
addedClassesToBeRemoved.add(addedClass);
removedClassesToBeRemoved.add(removedClass);
break;
diffSet.add(newClassRenameDiff);
}
}
}
}
if(diffSet.size() > 0) {
UMLClassRenameDiff first = diffSet.first();
diffsToBeAdded.add(first);
first.process();
addedClassesToBeRemoved.add(first.getNextClass());
removedClassesToBeRemoved.add(first.getOriginalClass());
}
}
classRenameDiffList.addAll(diffsToBeAdded);
removedClasses.removeAll(removedClassesToBeRemoved);
Expand Down

0 comments on commit 8a204f4

Please sign in to comment.