Skip to content

Commit

Permalink
Disable scope in comment diff when there is control flow restructuring
Browse files Browse the repository at this point in the history
  • Loading branch information
tsantalis committed Oct 10, 2024
1 parent 5f243cd commit 1d823ca
Show file tree
Hide file tree
Showing 10 changed files with 6,647 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2654,11 +2654,26 @@ else if(streamAPIStatements1.size() > 0 && streamAPIStatements2.size() == 0) {
AbstractCodeMapping parentMapping = findParentMappingContainingOperationInvocation();
Set<UMLComment> deletedComments = new LinkedHashSet<UMLComment>();
if(parentMapping != null) {
for(UMLComment deletedComment : parentMapper.commentListDiff.getDeletedComments()) {
if(parentMapping.getFragment1().getLocationInfo().subsumes(deletedComment.getLocationInfo())) {
deletedComments.add(deletedComment);
boolean containsReturn = false;
if(parentMapping.getFragment1() instanceof CompositeStatementObject) {
CompositeStatementObject comp = (CompositeStatementObject)parentMapping.getFragment1();
for(AbstractCodeFragment fragment : comp.getLeaves()) {
if(fragment.getString().equals(JAVA.RETURN_STATEMENT)) {
containsReturn = true;
break;
}
}
}
if(!containsReturn) {
for(UMLComment deletedComment : parentMapper.commentListDiff.getDeletedComments()) {
if(parentMapping.getFragment1().getLocationInfo().subsumes(deletedComment.getLocationInfo())) {
deletedComments.add(deletedComment);
}
}
}
else {
deletedComments.addAll(parentMapper.commentListDiff.getDeletedComments());
}
}
else {
deletedComments.addAll(parentMapper.commentListDiff.getDeletedComments());
Expand Down Expand Up @@ -3054,11 +3069,26 @@ else if(streamAPIStatements1.size() > 0 && streamAPIStatements2.size() == 0) {
AbstractCodeMapping parentMapping = findParentMappingContainingOperationInvocation();
Set<UMLComment> addedComments = new LinkedHashSet<UMLComment>();
if(parentMapping != null) {
for(UMLComment addedComment : parentMapper.commentListDiff.getAddedComments()) {
if(parentMapping.getFragment2().getLocationInfo().subsumes(addedComment.getLocationInfo())) {
addedComments.add(addedComment);
boolean containsReturn = false;
if(parentMapping.getFragment2() instanceof CompositeStatementObject) {
CompositeStatementObject comp = (CompositeStatementObject)parentMapping.getFragment2();
for(AbstractCodeFragment fragment : comp.getLeaves()) {
if(fragment.getString().equals(JAVA.RETURN_STATEMENT)) {
containsReturn = true;
break;
}
}
}
if(!containsReturn) {
for(UMLComment addedComment : parentMapper.commentListDiff.getAddedComments()) {
if(parentMapping.getFragment2().getLocationInfo().subsumes(addedComment.getLocationInfo())) {
addedComments.add(addedComment);
}
}
}
else {
addedComments.addAll(parentMapper.commentListDiff.getAddedComments());
}
}
else {
addedComments.addAll(parentMapper.commentListDiff.getAddedComments());
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/org/refactoringminer/test/TestJavadocDiff.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ public void testMethodCommentMappings(String url, String commitId, String classN
@CsvSource({
"https://github.com/jOOQ/jOOQ.git, 58a4e74d28073e7c6f15d1f225ac1c2fd9aa4357, org.jooq.tools.Convert.ConvertAll, jOOQ-58a4e74d28073e7c6f15d1f225ac1c2fd9aa4357-comments.txt",
"https://github.com/thymeleaf/thymeleaf.git, 378ba37750a9cb1b19a6db434dfa59308f721ea6, org.thymeleaf.templateparser.reader.BlockAwareReader, thymeleaf-378ba37750a9cb1b19a6db434dfa59308f721ea6-comments.txt",
"https://github.com/eclipse-vertx/vert.x.git, 32a8c9086040fd6d6fa11a214570ee4f75a4301f, io.vertx.core.http.impl.HttpServerImpl.ServerHandler, vertx-32a8c9086040fd6d6fa11a214570ee4f75a4301f-comments.txt"
"https://github.com/eclipse-vertx/vert.x.git, 32a8c9086040fd6d6fa11a214570ee4f75a4301f, io.vertx.core.http.impl.HttpServerImpl.ServerHandler, vertx-32a8c9086040fd6d6fa11a214570ee4f75a4301f-comments.txt",
"https://github.com/eclipse-jgit/jgit.git, 5d8a9f6f3f43ac43c6b1c48cdfad55e545171ea3, org.eclipse.jgit.internal.storage.pack.PackWriter, jgit-5d8a9f6f3f43ac43c6b1c48cdfad55e545171ea3-comments.txt"
})
public void testMethodCommentMultiMappings(String url, String commitId, String className, String testResultFileName) throws Exception {
final List<String> actual = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
private searchForDeltas(monitor ProgressMonitor, list ObjectToPack[], cnt int) : void -> private parallelDeltaSearch(monitor ProgressMonitor, list ObjectToPack[], cnt int, threads int) : void
line range:1353-1353==line range:1375-1375
line range:1354-1354==line range:1376-1376
line range:1371-1371==line range:1393-1393
line range:1372-1372==line range:1394-1394
line range:1373-1373==line range:1395-1395
line range:1388-1388==line range:1410-1410
line range:1389-1389==line range:1411-1411
line range:1390-1390==line range:1412-1412
line range:1396-1396==line range:1418-1418
line range:1397-1397==line range:1419-1419
line range:1398-1398==line range:1420-1420
line range:1350-1350==line range:1372-1372
private searchForDeltas(monitor ProgressMonitor, list ObjectToPack[], cnt int) : void -> private searchForDeltas(monitor ProgressMonitor, list ObjectToPack[], cnt int) : void
Loading

0 comments on commit 1d823ca

Please sign in to comment.