Skip to content

Commit

Permalink
Fixed an issue with multiple added entries -- medium sized edge case
Browse files Browse the repository at this point in the history
  • Loading branch information
bbchristians committed May 14, 2020
1 parent 4dab79d commit d60f41d
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 28 deletions.
7 changes: 2 additions & 5 deletions src/main/java/edu/rit/se/satd/SATDMiner.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,7 @@ private SATDDifference mapSATDInstanceLikeness(SATDDifference diff) {
if( !this.satdInstanceMappings.containsKey(satdInstance.getNewInstance()) ) {
this.satdInstanceMappings.put(satdInstance.getNewInstance(), this.getNewSATDId());
} else {
if( isErrorOutputEnabled() ) {
System.err.println("\nGot extra SATD_ADDED instance for " +
satdInstance.getOldInstance().toString());
}
this.status.addErrorEncountered();
System.err.println("here!");
}
satdInstance.setId(this.satdInstanceMappings.get(satdInstance.getNewInstance()));
break;
Expand Down Expand Up @@ -238,6 +234,7 @@ private SATDDifference mapSATDInstanceLikeness(SATDDifference diff) {
} else {
// Otherwise it exists, so we can propagate it forward
satdInstance.setId(this.satdInstanceMappings.get(satdInstance.getOldInstance()));
this.satdInstanceMappings.remove(satdInstance.getOldInstance());
}
break;
}
Expand Down
40 changes: 26 additions & 14 deletions src/main/java/edu/rit/se/satd/comment/GroupedComment.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package edu.rit.se.satd.comment;

import com.github.javaparser.Position;
import com.github.javaparser.Range;
import com.github.javaparser.ast.Node;
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
Expand Down Expand Up @@ -33,11 +32,15 @@ public class GroupedComment implements Comparable {
@Getter
final private String containingClass;
@Getter
final private int containingClassDeclarationLine;
final private int containingClassDeclarationLineStart;
@Getter
final private int containingClassDeclarationLineEnd;
@Getter
final private String containingMethod;
@Getter
final private int containingMethodDeclarationLine;
final private int containingMethodDeclarationLineStart;
@Getter
final private int containingMethodDeclarationLineEnd;

public static final String TYPE_COMMENTED_SOURCE = "CommentedSource";
public static final String TYPE_BLOCK = "Block";
Expand Down Expand Up @@ -72,33 +75,40 @@ public GroupedComment(Comment oldComment) {
.filter(dec -> JavaParseUtil.isRangeBetweenBounds(dec.getRange().get(), this.startLine, this.endLine))
.findFirst();
if( classRoot.isPresent() ) {
// Class Data
this.containingClass = classRoot
.map(ClassOrInterfaceDeclaration::getFullyQualifiedName)
.map(opt -> opt.orElse(UNKNOWN))
.get();
this.containingClassDeclarationLine = classRoot
final Range classRange = classRoot
.map(ClassOrInterfaceDeclaration::getName)
.map(Node::getRange)
.get()
.orElse(new Range(new Position(-1, -1), new Position(-1, -1)))
.begin.line;
.orElse(NULL_RANGE);
this.containingClassDeclarationLineStart = classRange.begin.line;
this.containingClassDeclarationLineEnd = classRange.end.line;

// Method Data
final Optional<MethodDeclaration> thisMethod = classRoot.get().findAll(MethodDeclaration.class).stream()
.filter(dec -> dec.getRange().isPresent())
.filter(dec -> JavaParseUtil.isRangeBetweenBounds(dec.getRange().get(), this.startLine, this.endLine))
.findFirst();
this.containingMethod = thisMethod
.map(MethodDeclaration::getNameAsString)
.map(asd -> asd.getDeclarationAsString(false, false, false))
.orElse(UNKNOWN);
this.containingMethodDeclarationLine = thisMethod
final Range methodRange = thisMethod
.map(Node::getRange)
.orElse(Optional.of(NULL_RANGE))
.orElse(NULL_RANGE)
.begin.line;
.orElse(NULL_RANGE);
this.containingMethodDeclarationLineStart = methodRange.begin.line;
this.containingMethodDeclarationLineEnd = methodRange.end.line;
} else {
this.containingMethod = UNKNOWN;
this.containingMethodDeclarationLine = -1;
this.containingMethodDeclarationLineStart = -1;
this.containingMethodDeclarationLineEnd = -1;
this.containingClass = UNKNOWN;
this.containingClassDeclarationLine = -1;
this.containingClassDeclarationLineStart = -1;
this.containingClassDeclarationLineEnd = -1;
}
}

Expand All @@ -117,9 +127,11 @@ public GroupedComment joinWith(GroupedComment other) {
String.join("\n", other.comment, this.comment),
this.commentType,
this.containingClass,
this.containingClassDeclarationLine,
this.containingClassDeclarationLineStart,
this.containingClassDeclarationLineEnd,
this.containingMethod,
this.containingMethodDeclarationLine);
this.containingMethodDeclarationLineStart,
this.containingMethodDeclarationLineEnd);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class NullGroupedComment extends GroupedComment {

public NullGroupedComment() {
super(NULL_FIELD_INT, NULL_FIELD_INT, NULL_FIELD, NULL_FIELD,
NULL_FIELD, NULL_FIELD_INT, NULL_FIELD, NULL_FIELD_INT);
NULL_FIELD, NULL_FIELD_INT, NULL_FIELD_INT,
NULL_FIELD, NULL_FIELD_INT, NULL_FIELD_INT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -263,21 +263,21 @@ private boolean editImpactedComment(Edit edit, GroupedComment comment, int bound
private boolean editImpactedContainingMethod(Edit edit, GroupedComment comment, boolean isOld) {
return isOld ?
GitUtil.editOccursInOldFileBetween(edit,
comment.getContainingMethodDeclarationLine(),
comment.getContainingMethodDeclarationLine())
comment.getContainingMethodDeclarationLineStart(),
comment.getContainingMethodDeclarationLineEnd())
: GitUtil.editOccursInNewFileBetween(edit,
comment.getContainingMethodDeclarationLine(),
comment.getContainingMethodDeclarationLine());
comment.getContainingMethodDeclarationLineStart(),
comment.getContainingMethodDeclarationLineEnd());
}

private boolean editImpactedContainingClass(Edit edit, GroupedComment comment, boolean isOld) {
return isOld ?
GitUtil.editOccursInOldFileBetween(edit,
comment.getContainingClassDeclarationLine(),
comment.getContainingClassDeclarationLine())
comment.getContainingClassDeclarationLineStart(),
comment.getContainingClassDeclarationLineEnd())
: GitUtil.editOccursInNewFileBetween(edit,
comment.getContainingClassDeclarationLine(),
comment.getContainingClassDeclarationLine());
comment.getContainingClassDeclarationLineStart(),
comment.getContainingClassDeclarationLineEnd());
}

private boolean editsTouchedClassOrMethodSignatureOldComment(List<Edit> edits, GroupedComment oldComment) {
Expand Down

0 comments on commit d60f41d

Please sign in to comment.