Skip to content

Commit

Permalink
Minor fix to FallThrough to skip generated/mutated AST nodes
Browse files Browse the repository at this point in the history
(e.g. Lombok)

Fixes #1573

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=311375182
  • Loading branch information
lazaroclapp authored and kluever committed May 14, 2020
1 parent 5b46391 commit 20473c3
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.sun.source.tree.BlockTree;
import com.sun.source.tree.SwitchTree;
import com.sun.tools.javac.tree.JCTree;
import com.sun.tools.javac.util.Position;
import java.util.regex.Pattern;

/** A {@link BugChecker}; see the associated {@link BugPattern} annotation for details. */
Expand Down Expand Up @@ -61,12 +62,12 @@ public Description matchSwitch(SwitchTree tree, VisitorState state) {
// reported an error if that statement wasn't reachable, and the answer is
// independent of any preceding statements.
boolean completes = Reachability.canCompleteNormally(getLast(caseTree.stats));
int endPos = caseEndPosition(state, caseTree);
if (endPos == Position.NOPOS) {
break;
}
String comments =
state
.getSourceCode()
.subSequence(caseEndPosition(state, caseTree), next.getStartPosition())
.toString()
.trim();
state.getSourceCode().subSequence(endPos, next.getStartPosition()).toString().trim();
if (completes && !FALL_THROUGH_PATTERN.matcher(comments).find()) {
state.reportMatch(
buildDescription(next)
Expand Down

0 comments on commit 20473c3

Please sign in to comment.