Skip to content

Commit

Permalink
Perfect diff for commit
Browse files Browse the repository at this point in the history
  • Loading branch information
tsantalis committed Sep 20, 2024
1 parent 7f33e01 commit cf0af1b
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8395,6 +8395,51 @@ protected LeafMapping createLeafMapping(AbstractCodeFragment leaf1, AbstractCode
}
}
mapping.setMatchingArgumentsWithOperationInvocation(matchingArguments);
if(leaf1.getCreations().size() > 0 && leaf2.getCreations().size() > 0) {
ObjectCreation creation1 = (ObjectCreation) leaf1.getCreations().get(0);
ObjectCreation creation2 = (ObjectCreation) leaf2.getCreations().get(0);
if(creation1.isArray() && creation2.isArray() && creation1.getAnonymousClassDeclaration() != null && creation2.getAnonymousClassDeclaration() != null) {
List<ObjectCreation> nestedCreations1 = new ArrayList<ObjectCreation>();
for(int i=1; i<leaf1.getCreations().size(); i++) {
if(creation1.getLocationInfo().subsumes(leaf1.getCreations().get(i).getLocationInfo())) {
nestedCreations1.add((ObjectCreation) leaf1.getCreations().get(i));
}
}
List<ObjectCreation> nestedCreations2 = new ArrayList<ObjectCreation>();
for(int i=1; i<leaf2.getCreations().size(); i++) {
if(creation2.getLocationInfo().subsumes(leaf2.getCreations().get(i).getLocationInfo())) {
nestedCreations2.add((ObjectCreation) leaf2.getCreations().get(i));
}
}
if(nestedCreations1.size() <= nestedCreations2.size()) {
for(ObjectCreation nestedCreation1 : nestedCreations1) {
int[] editDistance = new int[nestedCreations2.size()];
int[] argumentIntersections = new int[nestedCreations2.size()];
int index = 0;
for(ObjectCreation nestedCreation2 : nestedCreations2) {
int argumentIntersection = nestedCreation1.argumentIntersection(nestedCreation2).size();
argumentIntersections[index] = argumentIntersection;
int d = StringDistance.editDistance(nestedCreation1.actualString(), nestedCreation2.actualString());
editDistance[index] = d;
index++;
}
int minIndex = 0;
int minValue = editDistance[0];
int maxArgumentIntersection = argumentIntersections[0];
for(int i=0; i<editDistance.length; i++) {
if(editDistance[i] < minValue && argumentIntersections[i] > maxArgumentIntersection) {
minValue = editDistance[i];
maxArgumentIntersection = argumentIntersections[i];
minIndex = i;
}
}
LeafMapping newMapping = new LeafMapping(nestedCreation1.asLeafExpression(), nestedCreations2.get(minIndex).asLeafExpression(), container1, container2);
mapping.addSubExpressionMapping(newMapping);
nestedCreations2.remove(minIndex);
}
}
}
}
return mapping;
}

Expand Down
3 changes: 0 additions & 3 deletions src/test/resources/astDiff/commits/cases-problematic.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
}, {
"repo" : "https://github.com/spring-projects/spring-hateoas.git",
"commit" : "8bdc57ba8975d851fe91edc908761aacea624766"
}, {
"repo" : "https://github.com/openhab/openhab1-addons.git",
"commit" : "f25fa3ae35e4a60a2b7f79a88f14d46ce6cebf55"
}, {
"repo" : "https://github.com/checkstyle/checkstyle.git",
"commit" : "5a9b7249e3d092a78ac8e7d48aeeb62bf1c44e20"
Expand Down
3 changes: 3 additions & 0 deletions src/test/resources/astDiff/commits/cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -400,4 +400,7 @@
}, {
"repo" : "https://github.com/apache/pig.git",
"commit" : "92dce401344a28ff966ad4cf3dd969a676852315"
}, {
"repo" : "https://github.com/openhab/openhab1-addons.git",
"commit" : "f25fa3ae35e4a60a2b7f79a88f14d46ce6cebf55"
} ]

0 comments on commit cf0af1b

Please sign in to comment.