Skip to content

Commit

Permalink
Added another check to determine if changed SATD is still SATD
Browse files Browse the repository at this point in the history
  • Loading branch information
bbchristians committed May 28, 2020
1 parent c352fd9 commit 6e73633
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public SATDDifference mineDiff() {
this.secondRepo.getCommit());

// Load the diffs between versions
final CommitToCommitDiff cToCDiff = new CommitToCommitDiff(this.firstRepo, this.secondRepo);
final CommitToCommitDiff cToCDiff = new CommitToCommitDiff(
this.firstRepo, this.secondRepo, this.satdDetector);

// Get the SATD occurrences for each repo
final Map<String, RepositoryComments> newerSATD = this.secondRepo.getFilesToSATDOccurrences(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import edu.rit.se.satd.comment.GroupedComment;
import edu.rit.se.satd.comment.NullGroupedComment;
import edu.rit.se.satd.comment.RepositoryComments;
import edu.rit.se.satd.detector.SATDDetector;
import edu.rit.se.satd.model.SATDInstance;
import edu.rit.se.satd.model.SATDInstanceInFile;
import edu.rit.se.util.JavaParseUtil;
Expand Down Expand Up @@ -32,19 +33,22 @@

public class CommitToCommitDiff {

private Git gitInstance;
private RevCommit newCommit;
private List<DiffEntry> diffEntries;
private final Git gitInstance;
private final RevCommit newCommit;
private final List<DiffEntry> diffEntries;
private final SATDDetector detector;

public static DiffAlgorithm diffAlgo = DiffAlgorithm.getAlgorithm(DiffAlgorithm.SupportedAlgorithm.MYERS);

public CommitToCommitDiff(RepositoryCommitReference oldRepo, RepositoryCommitReference newRepo) {
public CommitToCommitDiff(RepositoryCommitReference oldRepo,
RepositoryCommitReference newRepo, SATDDetector detector) {
this.gitInstance = newRepo.getGitInstance();
this.newCommit = newRepo.getCommit();
this.diffEntries = GitUtil.getDiffEntries(this.gitInstance, oldRepo.getCommit(), this.newCommit)
.stream()
.filter(diffEntry -> diffEntry.getOldPath().endsWith(".java") || diffEntry.getNewPath().endsWith(".java"))
.collect(Collectors.toList());
this.detector = detector;
}

public List<String> getModifiedFilesNew() {
Expand Down Expand Up @@ -140,12 +144,25 @@ private List<SATDInstance> getSATDFromDiffOldFile(DiffEntry diffEntry, GroupedCo
updatedComments.stream()
.map(nc -> {
// If the comment that was added is similar enough to the old comment
// we can infer that the comment was changed
if( SimilarityUtil.commentsAreSimilar(oldComment, nc) ) {
// We know the comment was changed
return new SATDInstance(
new SATDInstanceInFile(diffEntry.getOldPath(), oldComment),
new SATDInstanceInFile(diffEntry.getNewPath(), nc),
SATDInstance.SATDResolution.SATD_CHANGED);
// If the new comment is still SATD, then the instance is changed
if( this.detector.isSATD(nc.getComment()) ) {
return new SATDInstance(
new SATDInstanceInFile(diffEntry.getOldPath(), oldComment),
new SATDInstanceInFile(diffEntry.getNewPath(), nc),
SATDInstance.SATDResolution.SATD_CHANGED);
}
// Otherwise the part of the comment that was making the comment SATD
// was removed, and so it can be determined that the SATD instance
// was removed
else {
return new SATDInstance(
new SATDInstanceInFile(diffEntry.getOldPath(), oldComment),
new SATDInstanceInFile(diffEntry.getNewPath(), nc),
SATDInstance.SATDResolution.SATD_REMOVED);
}

} else {
// We know the comment was removed, and the one that was added
// was a different comment
Expand Down

0 comments on commit 6e73633

Please sign in to comment.