Skip to content

Commit

Permalink
Further pushing optimize(TreeSet<UMLClassRenameDiff> diffSet)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsantalis committed Dec 15, 2024
1 parent 92aea74 commit ef5e9d4
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/main/java/gr/uom/java/xmi/diff/UMLModelDiff.java
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,7 @@ private TreeSet<UMLClassRenameDiff> optimize(TreeSet<UMLClassRenameDiff> diffSet
TreeSet<UMLClassRenameDiff> identicalStatementDiffSet = new TreeSet<UMLClassRenameDiff>(new ClassRenameComparator());
TreeSet<UMLClassRenameDiff> identicalSignatureDiffSet = new TreeSet<UMLClassRenameDiff>(new ClassRenameComparator());
TreeSet<UMLClassRenameDiff> identicalPackageDeclarationDocDiffSet = new TreeSet<UMLClassRenameDiff>(new ClassRenameComparator());
TreeMap<Integer, TreeSet<UMLClassRenameDiff>> matchingStatementMap = new TreeMap<Integer, TreeSet<UMLClassRenameDiff>>();
for(UMLClassRenameDiff diff : diffSet) {
if(diff.getOriginalClass().getPackageDeclarationJavadoc() != null && diff.getNextClass().getPackageDeclarationJavadoc() != null) {
if(diff.getOriginalClass().getPackageDeclarationJavadoc().getFullText().equals(diff.getNextClass().getPackageDeclarationJavadoc().getFullText())) {
Expand All @@ -1146,6 +1147,7 @@ private TreeSet<UMLClassRenameDiff> optimize(TreeSet<UMLClassRenameDiff> diffSet
int identicalSignatures = 0;
int identicalStatementSignatures = 0;
int totalStatements = 0;
int matchingStatements = 0;
if(operations1.size() == operations2.size()) {
for(int i=0; i<operations1.size(); i++) {
UMLOperation op1 = operations1.get(i);
Expand All @@ -1169,12 +1171,27 @@ private TreeSet<UMLClassRenameDiff> optimize(TreeSet<UMLClassRenameDiff> diffSet
}
}
}
else if(op1.getBody() != null && op2.getBody() != null) {
List<String> rep1 = op1.getBody().stringRepresentation();
List<String> rep2 = op2.getBody().stringRepresentation();
if(rep1.containsAll(rep2) || rep2.containsAll(rep1)) {
matchingStatements += Math.min(rep1.size(), rep2.size());
}
}
String actualSignature1 = op1.getActualSignature();
String actualSignature2 = op2.getActualSignature();
if(actualSignature1 != null && actualSignature2 != null && actualSignature1.equals(actualSignature2)) {
identicalSignatures++;
}
}
if(matchingStatementMap.containsKey(matchingStatements)) {
matchingStatementMap.get(matchingStatements).add(diff);
}
else {
TreeSet<UMLClassRenameDiff> set = new TreeSet<UMLClassRenameDiff>(new ClassRenameComparator());
set.add(diff);
matchingStatementMap.put(matchingStatements, set);
}
}
if(identicalBodies == operations1.size()) {
identicalBodyDiffSet.add(diff);
Expand All @@ -1198,6 +1215,10 @@ else if(identicalBodyDiffSet.size() < diffSet.size() && identicalStatementDiffSe
if(identicalPackageDeclarationDocDiffSet.size() == 1) {
return identicalPackageDeclarationDocDiffSet;
}
Map.Entry<Integer, TreeSet<UMLClassRenameDiff>> entry = matchingStatementMap.lastEntry();
if(entry != null && entry.getValue().size() == 1) {
return entry.getValue();
}
}
return diffSet;
}
Expand Down

0 comments on commit ef5e9d4

Please sign in to comment.