From ef5e9d4c56880e6bd6936aef0de8f1c4001445e8 Mon Sep 17 00:00:00 2001 From: tsantalis Date: Sun, 15 Dec 2024 16:49:51 -0500 Subject: [PATCH] Further pushing optimize(TreeSet diffSet) https://github.com/checkstyle/checkstyle/commit/7ddc532f01361e832f6ebd32c399f20918f5a388 --- .../gr/uom/java/xmi/diff/UMLModelDiff.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/main/java/gr/uom/java/xmi/diff/UMLModelDiff.java b/src/main/java/gr/uom/java/xmi/diff/UMLModelDiff.java index 90357b58e6..2a8f3deff2 100644 --- a/src/main/java/gr/uom/java/xmi/diff/UMLModelDiff.java +++ b/src/main/java/gr/uom/java/xmi/diff/UMLModelDiff.java @@ -1129,6 +1129,7 @@ private TreeSet optimize(TreeSet diffSet TreeSet identicalStatementDiffSet = new TreeSet(new ClassRenameComparator()); TreeSet identicalSignatureDiffSet = new TreeSet(new ClassRenameComparator()); TreeSet identicalPackageDeclarationDocDiffSet = new TreeSet(new ClassRenameComparator()); + TreeMap> matchingStatementMap = new TreeMap>(); for(UMLClassRenameDiff diff : diffSet) { if(diff.getOriginalClass().getPackageDeclarationJavadoc() != null && diff.getNextClass().getPackageDeclarationJavadoc() != null) { if(diff.getOriginalClass().getPackageDeclarationJavadoc().getFullText().equals(diff.getNextClass().getPackageDeclarationJavadoc().getFullText())) { @@ -1146,6 +1147,7 @@ private TreeSet optimize(TreeSet diffSet int identicalSignatures = 0; int identicalStatementSignatures = 0; int totalStatements = 0; + int matchingStatements = 0; if(operations1.size() == operations2.size()) { for(int i=0; i optimize(TreeSet diffSet } } } + else if(op1.getBody() != null && op2.getBody() != null) { + List rep1 = op1.getBody().stringRepresentation(); + List 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 set = new TreeSet(new ClassRenameComparator()); + set.add(diff); + matchingStatementMap.put(matchingStatements, set); + } } if(identicalBodies == operations1.size()) { identicalBodyDiffSet.add(diff); @@ -1198,6 +1215,10 @@ else if(identicalBodyDiffSet.size() < diffSet.size() && identicalStatementDiffSe if(identicalPackageDeclarationDocDiffSet.size() == 1) { return identicalPackageDeclarationDocDiffSet; } + Map.Entry> entry = matchingStatementMap.lastEntry(); + if(entry != null && entry.getValue().size() == 1) { + return entry.getValue(); + } } return diffSet; }