From 6e73633884d96691614a5ddc39985814640ee817 Mon Sep 17 00:00:00 2001 From: Ben Christians Date: Thu, 28 May 2020 12:39:24 -0400 Subject: [PATCH] Added another check to determine if changed SATD is still SATD --- .../se/satd/mining/RepositoryDiffMiner.java | 3 +- .../mining/commit/CommitToCommitDiff.java | 35 ++++++++++++++----- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/main/java/edu/rit/se/satd/mining/RepositoryDiffMiner.java b/src/main/java/edu/rit/se/satd/mining/RepositoryDiffMiner.java index 2072924..df0ea87 100644 --- a/src/main/java/edu/rit/se/satd/mining/RepositoryDiffMiner.java +++ b/src/main/java/edu/rit/se/satd/mining/RepositoryDiffMiner.java @@ -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 newerSATD = this.secondRepo.getFilesToSATDOccurrences( diff --git a/src/main/java/edu/rit/se/satd/mining/commit/CommitToCommitDiff.java b/src/main/java/edu/rit/se/satd/mining/commit/CommitToCommitDiff.java index 7ec05a1..bf8a68d 100644 --- a/src/main/java/edu/rit/se/satd/mining/commit/CommitToCommitDiff.java +++ b/src/main/java/edu/rit/se/satd/mining/commit/CommitToCommitDiff.java @@ -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; @@ -32,19 +33,22 @@ public class CommitToCommitDiff { - private Git gitInstance; - private RevCommit newCommit; - private List diffEntries; + private final Git gitInstance; + private final RevCommit newCommit; + private final List 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 getModifiedFilesNew() { @@ -140,12 +144,25 @@ private List 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