From 3602ab040d4dc0f7348fe6103ccfd20252ec1af9 Mon Sep 17 00:00:00 2001 From: ghm Date: Thu, 8 Jun 2023 03:46:46 -0700 Subject: [PATCH] Rip out `TreeToString:transitiveEnclosingBugchecker` flag. PiperOrigin-RevId: 538740160 --- .../errorprone/bugpatterns/TreeToString.java | 30 +++++-------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/TreeToString.java b/core/src/main/java/com/google/errorprone/bugpatterns/TreeToString.java index 5b19dc735af..786e9d96754 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/TreeToString.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/TreeToString.java @@ -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; @@ -66,12 +66,12 @@ 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) { @@ -79,22 +79,8 @@ private boolean treeToStringInBugChecker(Type type, VisitorState 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