Skip to content

Commit

Permalink
Rip out TreeToString:transitiveEnclosingBugchecker flag.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 538740160
  • Loading branch information
graememorgan authored and Error Prone Team committed Jun 8, 2023
1 parent 0604d38 commit 3602ab0
Showing 1 changed file with 8 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
package com.google.errorprone.bugpatterns;

import static com.google.common.collect.Iterables.getOnlyElement;
import static com.google.common.collect.Streams.stream;
import static com.google.errorprone.BugPattern.SeverityLevel.ERROR;
import static com.google.errorprone.matchers.Matchers.instanceMethod;
import static com.google.errorprone.util.ASTHelpers.getReceiver;
import static com.google.errorprone.util.ASTHelpers.isSubtype;

import com.google.errorprone.BugPattern;
import com.google.errorprone.ErrorProneFlags;
import com.google.errorprone.VisitorState;
import com.google.errorprone.fixes.Fix;
import com.google.errorprone.fixes.SuggestedFix;
Expand Down Expand Up @@ -66,35 +66,21 @@ public class TreeToString extends AbstractToString {
.named("Literal")
.withParameters("java.lang.Object");

private final boolean transitiveEnclosingBugchecker;

@Inject
TreeToString(ErrorProneFlags errorProneFlags) {
this.transitiveEnclosingBugchecker =
errorProneFlags.getBoolean("TreeToString:transitiveEnclosingBugchecker").orElse(true);
TreeToString() {}

@Override
protected TypePredicate typePredicate() {
return this::treeToStringInBugChecker;
}

private boolean treeToStringInBugChecker(Type type, VisitorState state) {
return enclosingBugChecker(state) && IS_TREE.apply(type, state);
}

private boolean enclosingBugChecker(VisitorState state) {
for (Tree tree : state.getPath()) {
if (tree instanceof ClassTree) {
if (IS_BUGCHECKER.matches((ClassTree) tree, state)) {
return true;
}
if (!transitiveEnclosingBugchecker) {
break;
}
}
}
return false;
}

@Override
protected TypePredicate typePredicate() {
return this::treeToStringInBugChecker;
return stream(state.getPath())
.anyMatch(t -> t instanceof ClassTree && IS_BUGCHECKER.matches((ClassTree) t, state));
}

@Override
Expand Down

0 comments on commit 3602ab0

Please sign in to comment.