From bb2563e40178442cda38eaee7b9e3b6e1a9b6c97 Mon Sep 17 00:00:00 2001 From: ghm Date: Thu, 5 Jan 2023 11:41:36 -0800 Subject: [PATCH] Automatic code cleanup. PiperOrigin-RevId: 499956864 --- .../java/com/google/errorprone/bugpatterns/AlreadyChecked.java | 2 ++ .../java/com/google/errorprone/bugpatterns/AlwaysThrows.java | 2 ++ .../google/errorprone/bugpatterns/BoxedPrimitiveEquality.java | 2 ++ .../com/google/errorprone/bugpatterns/CheckReturnValue.java | 2 ++ .../java/com/google/errorprone/bugpatterns/DefaultCharset.java | 2 ++ .../com/google/errorprone/bugpatterns/DoNotCallChecker.java | 2 ++ .../google/errorprone/bugpatterns/EqualsIncompatibleType.java | 2 ++ .../com/google/errorprone/bugpatterns/FieldCanBeStatic.java | 2 ++ .../com/google/errorprone/bugpatterns/IgnoredPureGetter.java | 2 ++ .../google/errorprone/bugpatterns/ImpossibleNullComparison.java | 2 ++ .../com/google/errorprone/bugpatterns/MethodCanBeStatic.java | 2 ++ .../java/com/google/errorprone/bugpatterns/MissingOverride.java | 2 ++ .../com/google/errorprone/bugpatterns/OptionalNotPresent.java | 2 ++ .../java/com/google/errorprone/bugpatterns/ParameterName.java | 2 ++ .../com/google/errorprone/bugpatterns/ReturnValueIgnored.java | 2 ++ .../com/google/errorprone/bugpatterns/TooManyParameters.java | 2 ++ .../java/com/google/errorprone/bugpatterns/TreeToString.java | 2 ++ .../com/google/errorprone/bugpatterns/UngroupedOverloads.java | 2 ++ .../bugpatterns/UnsynchronizedOverridesSynchronized.java | 2 ++ .../java/com/google/errorprone/bugpatterns/UnusedVariable.java | 2 ++ .../main/java/com/google/errorprone/bugpatterns/WrongOneof.java | 2 ++ .../errorprone/bugpatterns/apidiff/AndroidJdkLibsChecker.java | 2 ++ .../google/errorprone/bugpatterns/apidiff/Java8ApiChecker.java | 2 ++ .../collectionincompatibletype/CollectionIncompatibleType.java | 2 ++ .../collectionincompatibletype/IncompatibleArgumentType.java | 2 ++ .../collectionincompatibletype/TruthIncompatibleType.java | 2 ++ .../bugpatterns/flogger/FloggerRequiredModifiers.java | 2 ++ .../com/google/errorprone/bugpatterns/inlineme/Inliner.java | 2 ++ .../com/google/errorprone/bugpatterns/inlineme/Suggester.java | 2 ++ .../com/google/errorprone/bugpatterns/inlineme/Validator.java | 2 ++ .../errorprone/bugpatterns/nullness/EqualsMissingNullable.java | 2 ++ .../errorprone/bugpatterns/nullness/FieldMissingNullable.java | 2 ++ .../bugpatterns/nullness/NullArgumentForNonNullParameter.java | 2 ++ .../bugpatterns/nullness/ParameterMissingNullable.java | 2 ++ .../errorprone/bugpatterns/nullness/ReturnMissingNullable.java | 2 ++ .../errorprone/bugpatterns/nullness/VoidMissingNullable.java | 2 ++ .../bugpatterns/threadsafety/ImmutableAnnotationChecker.java | 2 ++ .../errorprone/bugpatterns/threadsafety/ImmutableChecker.java | 2 ++ .../bugpatterns/threadsafety/ImmutableEnumChecker.java | 2 ++ .../com/google/errorprone/bugpatterns/time/PeriodTimeMath.java | 2 ++ .../errorprone/bugpatterns/time/PreferJavaTimeOverload.java | 2 ++ .../google/errorprone/ErrorProneCompilerIntegrationTest.java | 2 ++ 42 files changed, 84 insertions(+) diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/AlreadyChecked.java b/core/src/main/java/com/google/errorprone/bugpatterns/AlreadyChecked.java index 8c8955082c8..aeb048ec86d 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/AlreadyChecked.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/AlreadyChecked.java @@ -50,6 +50,7 @@ import java.util.Deque; import java.util.HashSet; import java.util.Set; +import javax.inject.Inject; import org.checkerframework.checker.nullness.qual.Nullable; /** Bugpattern to find conditions which are checked more than once. */ @@ -58,6 +59,7 @@ public final class AlreadyChecked extends BugChecker implements CompilationUnitT private final ConstantExpressions constantExpressions; + @Inject public AlreadyChecked(ErrorProneFlags flags) { this.constantExpressions = ConstantExpressions.fromFlags(flags); } diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/AlwaysThrows.java b/core/src/main/java/com/google/errorprone/bugpatterns/AlwaysThrows.java index 28665ea5b38..3396372f1f8 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/AlwaysThrows.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/AlwaysThrows.java @@ -48,6 +48,7 @@ import java.lang.reflect.InvocationTargetException; import java.util.UUID; import java.util.function.Consumer; +import javax.inject.Inject; import org.checkerframework.checker.nullness.qual.Nullable; /** A {@link BugChecker}; see the associated {@link BugPattern} annotation for details. */ @@ -136,6 +137,7 @@ void validate(MethodInvocationTree tree, String argument) { private final ConstantExpressions constantExpressions; + @Inject public AlwaysThrows(ErrorProneFlags flags) { this.constantExpressions = ConstantExpressions.fromFlags(flags); } diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/BoxedPrimitiveEquality.java b/core/src/main/java/com/google/errorprone/bugpatterns/BoxedPrimitiveEquality.java index 63926c97022..406a8a97668 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/BoxedPrimitiveEquality.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/BoxedPrimitiveEquality.java @@ -31,6 +31,7 @@ import com.sun.tools.javac.code.Symbol; import com.sun.tools.javac.code.Symbol.VarSymbol; import com.sun.tools.javac.code.Type; +import javax.inject.Inject; /** A {@link BugChecker}; see the associated {@link BugPattern} annotation for details. */ @BugPattern( @@ -43,6 +44,7 @@ public final class BoxedPrimitiveEquality extends AbstractReferenceEquality { private final boolean handleNumber; + @Inject public BoxedPrimitiveEquality(ErrorProneFlags flags) { this.handleNumber = flags.getBoolean("BoxedPrimitiveEquality:HandleNumber").orElse(true); } diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/CheckReturnValue.java b/core/src/main/java/com/google/errorprone/bugpatterns/CheckReturnValue.java index 171da43a7e7..c8e6e766de8 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/CheckReturnValue.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/CheckReturnValue.java @@ -84,6 +84,7 @@ import com.sun.tools.javac.processing.JavacProcessingEnvironment; import java.util.Optional; import java.util.stream.Stream; +import javax.inject.Inject; import javax.lang.model.element.ElementKind; import org.checkerframework.checker.nullness.qual.Nullable; @@ -139,6 +140,7 @@ public MethodKind getMethodKind(MethodSymbol method) { private final MessageTrailerStyle messageTrailerStyle; private final ResultUsePolicyEvaluator evaluator; + @Inject public CheckReturnValue(ErrorProneFlags flags) { super(flags); this.messageTrailerStyle = diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/DefaultCharset.java b/core/src/main/java/com/google/errorprone/bugpatterns/DefaultCharset.java index 81bd58af1d1..964bebeae0a 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/DefaultCharset.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/DefaultCharset.java @@ -70,6 +70,7 @@ import java.util.Iterator; import java.util.List; import java.util.Scanner; +import javax.inject.Inject; /** A {@link BugChecker}; see the associated {@link BugPattern} annotation for details. */ @BugPattern( @@ -200,6 +201,7 @@ String replacement() { private final boolean byteArrayOutputStreamToString; + @Inject public DefaultCharset(ErrorProneFlags flags) { this.byteArrayOutputStreamToString = flags.getBoolean("DefaultCharset:ByteArrayOutputStreamToString").orElse(true); diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/DoNotCallChecker.java b/core/src/main/java/com/google/errorprone/bugpatterns/DoNotCallChecker.java index cbacb2e14dc..eeaa586aee0 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/DoNotCallChecker.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/DoNotCallChecker.java @@ -68,6 +68,7 @@ import java.util.Map; import java.util.Optional; import java.util.stream.Stream; +import javax.inject.Inject; import javax.lang.model.element.Modifier; /** A {@link BugChecker}; see the associated {@link BugPattern} annotation for details. */ @@ -77,6 +78,7 @@ public class DoNotCallChecker extends BugChecker private final boolean checkNewGetClassMethods; private final boolean checkThreadRun; + @Inject public DoNotCallChecker(ErrorProneFlags flags) { checkNewGetClassMethods = flags.getBoolean("DoNotCallChecker:CheckNewGetClassMethods").orElse(true); diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/EqualsIncompatibleType.java b/core/src/main/java/com/google/errorprone/bugpatterns/EqualsIncompatibleType.java index 74f1a837adb..3b797105a8c 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/EqualsIncompatibleType.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/EqualsIncompatibleType.java @@ -44,6 +44,7 @@ import com.sun.source.tree.MethodInvocationTree; import com.sun.source.tree.Tree; import com.sun.tools.javac.code.Type; +import javax.inject.Inject; /** * @author avenet@google.com (Arnaud J. Venet) @@ -66,6 +67,7 @@ public class EqualsIncompatibleType extends BugChecker private final TypeCompatibilityUtils typeCompatibilityUtils; + @Inject public EqualsIncompatibleType(ErrorProneFlags flags) { this.typeCompatibilityUtils = TypeCompatibilityUtils.fromFlags(flags); } diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/FieldCanBeStatic.java b/core/src/main/java/com/google/errorprone/bugpatterns/FieldCanBeStatic.java index a4bfd44e528..29d83643b77 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/FieldCanBeStatic.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/FieldCanBeStatic.java @@ -61,6 +61,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.regex.Pattern; import java.util.stream.Stream; +import javax.inject.Inject; import javax.lang.model.element.NestingKind; /** Finds fields which can be safely made static. */ @@ -81,6 +82,7 @@ public final class FieldCanBeStatic extends BugChecker implements VariableTreeMa private final WellKnownMutability wellKnownMutability; private final ConstantExpressions constantExpressions; + @Inject public FieldCanBeStatic(ErrorProneFlags flags) { this.wellKnownMutability = WellKnownMutability.fromFlags(flags); this.constantExpressions = ConstantExpressions.fromFlags(flags); diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/IgnoredPureGetter.java b/core/src/main/java/com/google/errorprone/bugpatterns/IgnoredPureGetter.java index 16fc6b5c978..1ffc645929a 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/IgnoredPureGetter.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/IgnoredPureGetter.java @@ -40,6 +40,7 @@ import com.sun.tools.javac.code.Symbol.MethodSymbol; import com.sun.tools.javac.code.Type; import java.util.Optional; +import javax.inject.Inject; /** Flags ignored return values from pure getters. */ @BugPattern( @@ -61,6 +62,7 @@ public IgnoredPureGetter() { this(ErrorProneFlags.empty()); } + @Inject public IgnoredPureGetter(ErrorProneFlags flags) { super(flags); } diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/ImpossibleNullComparison.java b/core/src/main/java/com/google/errorprone/bugpatterns/ImpossibleNullComparison.java index cfaa7a79749..17dbf508730 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/ImpossibleNullComparison.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/ImpossibleNullComparison.java @@ -69,6 +69,7 @@ import java.util.Optional; import java.util.Set; import javax.annotation.Nullable; +import javax.inject.Inject; /** Matches comparison of proto fields to {@code null}. */ @BugPattern( @@ -145,6 +146,7 @@ private static boolean isNull(ExpressionTree tree) { private final boolean matchTestAssertions; private final boolean matchOptionalAndMultimap; + @Inject public ImpossibleNullComparison(ErrorProneFlags flags) { this.matchTestAssertions = flags.getBoolean("ProtoFieldNullComparison:MatchTestAssertions").orElse(true); diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/MethodCanBeStatic.java b/core/src/main/java/com/google/errorprone/bugpatterns/MethodCanBeStatic.java index aaca0c1e3f5..f3b31099afa 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/MethodCanBeStatic.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/MethodCanBeStatic.java @@ -54,6 +54,7 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; +import javax.inject.Inject; import javax.lang.model.element.Modifier; /** A {@link BugChecker}; see the associated {@link BugPattern} annotation for details. */ @@ -65,6 +66,7 @@ public class MethodCanBeStatic extends BugChecker implements CompilationUnitTreeMatcher { private final FindingOutputStyle findingOutputStyle; + @Inject public MethodCanBeStatic(ErrorProneFlags flags) { boolean findingPerSite = flags.getBoolean("MethodCanBeStatic:FindingPerSite").orElse(false); this.findingOutputStyle = diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/MissingOverride.java b/core/src/main/java/com/google/errorprone/bugpatterns/MissingOverride.java index f9baf7b1923..7e70dcbe223 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/MissingOverride.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/MissingOverride.java @@ -30,6 +30,7 @@ import com.google.errorprone.matchers.Description; import com.google.errorprone.util.ASTHelpers; import com.sun.source.tree.MethodTree; +import javax.inject.Inject; import javax.lang.model.element.Modifier; /** A {@link BugChecker}; see the associated {@link BugPattern} annotation for details. */ @@ -42,6 +43,7 @@ public class MissingOverride extends BugChecker implements MethodTreeMatcher { /** if true, don't warn on missing {@code @Override} annotations inside interfaces */ private final boolean ignoreInterfaceOverrides; + @Inject public MissingOverride(ErrorProneFlags flags) { this.ignoreInterfaceOverrides = flags.getBoolean("MissingOverride:IgnoreInterfaceOverrides").orElse(false); diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/OptionalNotPresent.java b/core/src/main/java/com/google/errorprone/bugpatterns/OptionalNotPresent.java index 32981eac2e0..d365ff1a6a9 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/OptionalNotPresent.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/OptionalNotPresent.java @@ -42,6 +42,7 @@ import com.sun.source.tree.Tree; import com.sun.tools.javac.code.Symbol.MethodSymbol; import java.util.stream.Stream; +import javax.inject.Inject; /** * @author mariasam@google.com (Maria Sam) @@ -59,6 +60,7 @@ public final class OptionalNotPresent extends BugChecker implements CompilationU private final ConstantExpressions constantExpressions; + @Inject public OptionalNotPresent(ErrorProneFlags flags) { this.constantExpressions = ConstantExpressions.fromFlags(flags); } diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/ParameterName.java b/core/src/main/java/com/google/errorprone/bugpatterns/ParameterName.java index 80e12e376b3..e92eb15d626 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/ParameterName.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/ParameterName.java @@ -56,6 +56,7 @@ import java.util.Optional; import java.util.function.Consumer; import java.util.regex.Matcher; +import javax.inject.Inject; /** A {@link BugChecker}; see the associated {@link BugPattern} annotation for details. */ @BugPattern( @@ -68,6 +69,7 @@ public class ParameterName extends BugChecker private final ImmutableList exemptPackages; + @Inject public ParameterName(ErrorProneFlags errorProneFlags) { this.exemptPackages = errorProneFlags diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/ReturnValueIgnored.java b/core/src/main/java/com/google/errorprone/bugpatterns/ReturnValueIgnored.java index 7d7e6da92e4..7374913312e 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/ReturnValueIgnored.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/ReturnValueIgnored.java @@ -47,6 +47,7 @@ import com.sun.tools.javac.code.Symbol.MethodSymbol; import com.sun.tools.javac.code.Type; import java.util.regex.Pattern; +import javax.inject.Inject; import javax.lang.model.element.Modifier; import javax.lang.model.element.Name; @@ -419,6 +420,7 @@ public ReturnValueIgnored() { this.matcher = anyOf(ALL_MATCHERS); } + @Inject public ReturnValueIgnored(ErrorProneFlags flags) { super(flags); this.matcher = createMatcher(flags); diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/TooManyParameters.java b/core/src/main/java/com/google/errorprone/bugpatterns/TooManyParameters.java index 94682c8626b..97c6e965842 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/TooManyParameters.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/TooManyParameters.java @@ -30,6 +30,7 @@ import com.google.errorprone.bugpatterns.BugChecker.MethodTreeMatcher; import com.google.errorprone.matchers.Description; import com.sun.source.tree.MethodTree; +import javax.inject.Inject; /** A {@link BugChecker}; see the associated {@link BugPattern} annotation for details. */ @BugPattern( @@ -60,6 +61,7 @@ public class TooManyParameters extends BugChecker implements MethodTreeMatcher { private final int limit; + @Inject public TooManyParameters(ErrorProneFlags flags) { this.limit = flags.getInteger(TOO_MANY_PARAMETERS_FLAG_NAME).orElse(DEFAULT_LIMIT); checkArgument(limit > 0, "%s (%s) must be > 0", TOO_MANY_PARAMETERS_FLAG_NAME, limit); 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 8f956587045..8bbc203ec68 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/TreeToString.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/TreeToString.java @@ -40,6 +40,7 @@ import com.sun.tools.javac.code.Symbol.VarSymbol; import com.sun.tools.javac.code.Type; import java.util.Optional; +import javax.inject.Inject; /** * Flags {@code com.sun.source.tree.Tree#toString} usage in {@link BugChecker}s. @@ -67,6 +68,7 @@ public class TreeToString extends AbstractToString { private final boolean transitiveEnclosingBugchecker; + @Inject public TreeToString(ErrorProneFlags errorProneFlags) { this.transitiveEnclosingBugchecker = errorProneFlags.getBoolean("TreeToString:transitiveEnclosingBugchecker").orElse(true); diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/UngroupedOverloads.java b/core/src/main/java/com/google/errorprone/bugpatterns/UngroupedOverloads.java index 7ef3334b7a6..eed74362e20 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/UngroupedOverloads.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/UngroupedOverloads.java @@ -42,6 +42,7 @@ import java.util.List; import java.util.Map; import java.util.stream.Stream; +import javax.inject.Inject; import javax.lang.model.element.Name; /** @@ -57,6 +58,7 @@ public class UngroupedOverloads extends BugChecker implements ClassTreeMatcher { private final Boolean batchFindings; + @Inject public UngroupedOverloads(ErrorProneFlags flags) { batchFindings = flags.getBoolean("UngroupedOverloads:BatchFindings").orElse(false); } diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/UnsynchronizedOverridesSynchronized.java b/core/src/main/java/com/google/errorprone/bugpatterns/UnsynchronizedOverridesSynchronized.java index f46a0859636..8113c869da2 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/UnsynchronizedOverridesSynchronized.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/UnsynchronizedOverridesSynchronized.java @@ -45,6 +45,7 @@ import com.sun.tools.javac.code.Flags; import com.sun.tools.javac.code.Symbol.MethodSymbol; import com.sun.tools.javac.code.Type; +import javax.inject.Inject; import javax.lang.model.element.Modifier; /** A {@link BugChecker}; see the associated {@link BugPattern} annotation for details. */ @@ -60,6 +61,7 @@ public UnsynchronizedOverridesSynchronized() { this(ErrorProneFlags.empty()); } + @Inject public UnsynchronizedOverridesSynchronized(ErrorProneFlags flags) { this.constantExpressions = ConstantExpressions.fromFlags(flags); } diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/UnusedVariable.java b/core/src/main/java/com/google/errorprone/bugpatterns/UnusedVariable.java index 8cd6711bca1..93a1285ab62 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/UnusedVariable.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/UnusedVariable.java @@ -109,6 +109,7 @@ import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; import javax.annotation.Nullable; +import javax.inject.Inject; import javax.lang.model.element.ElementKind; import javax.lang.model.element.Modifier; import javax.lang.model.element.Name; @@ -169,6 +170,7 @@ public final class UnusedVariable extends BugChecker implements CompilationUnitT private final boolean reportInjectedFields; + @Inject public UnusedVariable(ErrorProneFlags flags) { ImmutableSet.Builder methodAnnotationsExemptingParameters = ImmutableSet.builder().add("org.robolectric.annotation.Implementation"); diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/WrongOneof.java b/core/src/main/java/com/google/errorprone/bugpatterns/WrongOneof.java index 57047eb3ff3..7421e18da18 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/WrongOneof.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/WrongOneof.java @@ -48,6 +48,7 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import javax.inject.Inject; /** Matches always-default expressions in oneof switches. */ @BugPattern( @@ -59,6 +60,7 @@ public final class WrongOneof extends BugChecker implements SwitchTreeMatcher { private final ConstantExpressions constantExpressions; + @Inject public WrongOneof(ErrorProneFlags flags) { this.constantExpressions = ConstantExpressions.fromFlags(flags); } diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/apidiff/AndroidJdkLibsChecker.java b/core/src/main/java/com/google/errorprone/bugpatterns/apidiff/AndroidJdkLibsChecker.java index 517b0afc1b3..0847570a1a3 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/apidiff/AndroidJdkLibsChecker.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/apidiff/AndroidJdkLibsChecker.java @@ -30,6 +30,7 @@ import com.sun.source.tree.ExpressionTree; import java.io.IOException; import java.io.UncheckedIOException; +import javax.inject.Inject; /** * Checks for uses of classes, fields, or methods that are not compatible with legacy Android @@ -63,6 +64,7 @@ private static ApiDiff loadApiDiff(boolean allowJava8) { private final boolean allowJava8; + @Inject public AndroidJdkLibsChecker(ErrorProneFlags flags) { this(flags.getBoolean("Android:Java8Libs").orElse(false)); } diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/apidiff/Java8ApiChecker.java b/core/src/main/java/com/google/errorprone/bugpatterns/apidiff/Java8ApiChecker.java index cccce8edc58..a5a7215a31a 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/apidiff/Java8ApiChecker.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/apidiff/Java8ApiChecker.java @@ -29,6 +29,7 @@ import java.io.UncheckedIOException; import java.util.Map; import java.util.regex.Pattern; +import javax.inject.Inject; /** Checks for uses of classes, fields, or methods that are not compatible with JDK 8 */ @BugPattern( @@ -70,6 +71,7 @@ private static ApiDiff loadApiDiff(ErrorProneFlags errorProneFlags) { private static final String CHECKSUM = "java/util/zip/Checksum"; + @Inject public Java8ApiChecker(ErrorProneFlags errorProneFlags) { super(loadApiDiff(errorProneFlags)); } diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/collectionincompatibletype/CollectionIncompatibleType.java b/core/src/main/java/com/google/errorprone/bugpatterns/collectionincompatibletype/CollectionIncompatibleType.java index 0150ef08afb..4e8ff21b6a9 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/collectionincompatibletype/CollectionIncompatibleType.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/collectionincompatibletype/CollectionIncompatibleType.java @@ -40,6 +40,7 @@ import java.util.Collection; import java.util.List; import java.util.Map; +import javax.inject.Inject; /** * Checker for calling Object-accepting methods with types that don't match the type arguments of @@ -73,6 +74,7 @@ private enum FixType { private final FixType fixType; private final TypeCompatibilityUtils typeCompatibilityUtils; + @Inject public CollectionIncompatibleType(ErrorProneFlags flags) { this.fixType = flags.getEnum("CollectionIncompatibleType:FixType", FixType.class).orElse(FixType.NONE); diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/collectionincompatibletype/IncompatibleArgumentType.java b/core/src/main/java/com/google/errorprone/bugpatterns/collectionincompatibletype/IncompatibleArgumentType.java index d1e864b5263..a594f0a79a8 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/collectionincompatibletype/IncompatibleArgumentType.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/collectionincompatibletype/IncompatibleArgumentType.java @@ -46,6 +46,7 @@ import java.util.List; import java.util.Map; import javax.annotation.Nullable; +import javax.inject.Inject; import javax.lang.model.element.Parameterizable; import javax.lang.model.element.TypeParameterElement; @@ -59,6 +60,7 @@ public class IncompatibleArgumentType extends BugChecker implements MethodInvoca private final TypeCompatibilityUtils typeCompatibilityUtils; + @Inject public IncompatibleArgumentType(ErrorProneFlags flags) { this.typeCompatibilityUtils = TypeCompatibilityUtils.fromFlags(flags); } diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/collectionincompatibletype/TruthIncompatibleType.java b/core/src/main/java/com/google/errorprone/bugpatterns/collectionincompatibletype/TruthIncompatibleType.java index 0f66b125858..10ad59c63eb 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/collectionincompatibletype/TruthIncompatibleType.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/collectionincompatibletype/TruthIncompatibleType.java @@ -56,6 +56,7 @@ import com.sun.tools.javac.code.Type; import com.sun.tools.javac.code.Type.ArrayType; import java.util.stream.Stream; +import javax.inject.Inject; /** A {@link BugChecker}; see the associated {@link BugPattern} annotation for details. */ @BugPattern(summary = "Argument is not compatible with the subject's type.", severity = WARNING) @@ -145,6 +146,7 @@ public class TruthIncompatibleType extends BugChecker implements MethodInvocatio private final TypeCompatibilityUtils typeCompatibilityUtils; + @Inject public TruthIncompatibleType(ErrorProneFlags flags) { this.typeCompatibilityUtils = TypeCompatibilityUtils.fromFlags(flags); } diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/flogger/FloggerRequiredModifiers.java b/core/src/main/java/com/google/errorprone/bugpatterns/flogger/FloggerRequiredModifiers.java index 41a0c8dff99..6ae836509d1 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/flogger/FloggerRequiredModifiers.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/flogger/FloggerRequiredModifiers.java @@ -72,6 +72,7 @@ import java.util.Map; import java.util.Optional; import java.util.Set; +import javax.inject.Inject; import javax.lang.model.element.Modifier; import javax.lang.model.element.NestingKind; @@ -140,6 +141,7 @@ public final class FloggerRequiredModifiers extends BugChecker * values check only a subset of the Flogger best practices, and are designed to generate a more * fine grained adjustments. */ + @Inject public FloggerRequiredModifiers(ErrorProneFlags flags) { this(flags.getEnum("FloggerRequiredModifiers:Goal", Goal.class).orElse(Goal.DEFAULT_ALL_GOALS)); } diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/inlineme/Inliner.java b/core/src/main/java/com/google/errorprone/bugpatterns/inlineme/Inliner.java index feb5b8ef9e4..002d9a0b752 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/inlineme/Inliner.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/inlineme/Inliner.java @@ -59,6 +59,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Stream; +import javax.inject.Inject; /** * Checker that performs the inlining at call-sites (where the invoked APIs are annotated as @@ -88,6 +89,7 @@ public final class Inliner extends BugChecker private final boolean skipCallsitesWithComments; private final boolean checkFixCompiles; + @Inject public Inliner(ErrorProneFlags flags) { this.apiPrefixes = ImmutableSet.copyOf(flags.getSet(PREFIX_FLAG).orElse(ImmutableSet.of())); diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/inlineme/Suggester.java b/core/src/main/java/com/google/errorprone/bugpatterns/inlineme/Suggester.java index 11f5f7c031f..688b9c001b0 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/inlineme/Suggester.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/inlineme/Suggester.java @@ -33,6 +33,7 @@ import com.google.errorprone.fixes.SuggestedFixes; import com.google.errorprone.matchers.Description; import com.sun.source.tree.MethodTree; +import javax.inject.Inject; import javax.lang.model.element.Modifier; /** Checker that recommends using {@code @InlineMe} on single-statement deprecated APIs. */ @@ -47,6 +48,7 @@ public final class Suggester extends BugChecker implements MethodTreeMatcher { private final String inlineMe; + @Inject public Suggester(ErrorProneFlags errorProneFlags) { inlineMe = errorProneFlags diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/inlineme/Validator.java b/core/src/main/java/com/google/errorprone/bugpatterns/inlineme/Validator.java index ed394f96f23..574e99b6a31 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/inlineme/Validator.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/inlineme/Validator.java @@ -44,6 +44,7 @@ import java.util.Set; import java.util.function.Function; import java.util.function.Predicate; +import javax.inject.Inject; /** Checker that ensures the {@code @InlineMe} annotation is used correctly. */ @BugPattern( @@ -57,6 +58,7 @@ public final class Validator extends BugChecker implements MethodTreeMatcher { private final boolean cleanupInlineMes; + @Inject public Validator(ErrorProneFlags flags) { this.cleanupInlineMes = flags.getBoolean(CLEANUP_INLINE_ME_FLAG).orElse(false); } diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/nullness/EqualsMissingNullable.java b/core/src/main/java/com/google/errorprone/bugpatterns/nullness/EqualsMissingNullable.java index dcb066b9133..a560862425e 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/nullness/EqualsMissingNullable.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/nullness/EqualsMissingNullable.java @@ -36,6 +36,7 @@ import com.sun.source.tree.MethodTree; import com.sun.source.tree.VariableTree; import com.sun.tools.javac.code.Symbol.VarSymbol; +import javax.inject.Inject; /** A {@link BugChecker}; see the associated {@link BugPattern} annotation for details. */ @BugPattern( @@ -44,6 +45,7 @@ public class EqualsMissingNullable extends BugChecker implements MethodTreeMatcher { private final boolean beingConservative; + @Inject public EqualsMissingNullable(ErrorProneFlags flags) { this.beingConservative = nullnessChecksShouldBeConservative(flags); } diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/nullness/FieldMissingNullable.java b/core/src/main/java/com/google/errorprone/bugpatterns/nullness/FieldMissingNullable.java index 2187202b850..d3d164f624e 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/nullness/FieldMissingNullable.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/nullness/FieldMissingNullable.java @@ -44,6 +44,7 @@ import com.sun.source.tree.ExpressionTree; import com.sun.source.tree.VariableTree; import com.sun.tools.javac.code.Symbol; +import javax.inject.Inject; import javax.lang.model.element.Name; /** A {@link BugChecker}; see the associated {@link BugPattern} annotation for details. */ @@ -56,6 +57,7 @@ public class FieldMissingNullable extends BugChecker implements BinaryTreeMatcher, AssignmentTreeMatcher, VariableTreeMatcher { private final boolean beingConservative; + @Inject public FieldMissingNullable(ErrorProneFlags flags) { this.beingConservative = nullnessChecksShouldBeConservative(flags); } diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/nullness/NullArgumentForNonNullParameter.java b/core/src/main/java/com/google/errorprone/bugpatterns/nullness/NullArgumentForNonNullParameter.java index 79c80792c5c..5b59b29e649 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/nullness/NullArgumentForNonNullParameter.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/nullness/NullArgumentForNonNullParameter.java @@ -49,6 +49,7 @@ import com.sun.tools.javac.code.Type; import com.sun.tools.javac.util.Name; import java.util.List; +import javax.inject.Inject; /** A {@link BugChecker}; see the associated {@link BugPattern} annotation for details. */ @BugPattern(summary = "Null is not permitted for this parameter.", severity = ERROR) @@ -71,6 +72,7 @@ public final class NullArgumentForNonNullParameter extends BugChecker private final boolean beingConservative; + @Inject public NullArgumentForNonNullParameter(ErrorProneFlags flags) { this.beingConservative = nullnessChecksShouldBeConservative(flags); } diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/nullness/ParameterMissingNullable.java b/core/src/main/java/com/google/errorprone/bugpatterns/nullness/ParameterMissingNullable.java index 33c5fb95f97..6d4f1a7fb12 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/nullness/ParameterMissingNullable.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/nullness/ParameterMissingNullable.java @@ -57,6 +57,7 @@ import com.sun.tools.javac.code.Symbol; import com.sun.tools.javac.code.Symbol.MethodSymbol; import java.util.List; +import javax.inject.Inject; /** A {@link BugChecker}; see the associated {@link BugPattern} annotation for details. */ @BugPattern( @@ -66,6 +67,7 @@ public final class ParameterMissingNullable extends BugChecker implements BinaryTreeMatcher, MethodInvocationTreeMatcher, NewClassTreeMatcher { private final boolean beingConservative; + @Inject public ParameterMissingNullable(ErrorProneFlags flags) { this.beingConservative = nullnessChecksShouldBeConservative(flags); } diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/nullness/ReturnMissingNullable.java b/core/src/main/java/com/google/errorprone/bugpatterns/nullness/ReturnMissingNullable.java index feff9fa1bd4..e2ff09940d9 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/nullness/ReturnMissingNullable.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/nullness/ReturnMissingNullable.java @@ -71,6 +71,7 @@ import com.sun.tools.javac.code.Type; import java.util.List; import java.util.stream.Stream; +import javax.inject.Inject; import javax.lang.model.element.Name; /** A {@link BugChecker}; see the associated {@link BugPattern} annotation for details. */ @@ -194,6 +195,7 @@ public class ReturnMissingNullable extends BugChecker implements CompilationUnit private final boolean beingConservative; + @Inject public ReturnMissingNullable(ErrorProneFlags flags) { this.beingConservative = nullnessChecksShouldBeConservative(flags); } diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/nullness/VoidMissingNullable.java b/core/src/main/java/com/google/errorprone/bugpatterns/nullness/VoidMissingNullable.java index 132a7f15514..6754c99cf1d 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/nullness/VoidMissingNullable.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/nullness/VoidMissingNullable.java @@ -55,6 +55,7 @@ import com.sun.tools.javac.code.Symbol.MethodSymbol; import com.sun.tools.javac.code.Symbol.VarSymbol; import com.sun.tools.javac.code.Type; +import javax.inject.Inject; /** A {@link BugChecker}; see the associated {@link BugPattern} annotation for details. */ @BugPattern(summary = "The type Void is not annotated @Nullable", severity = SUGGESTION) @@ -62,6 +63,7 @@ public class VoidMissingNullable extends BugChecker implements ParameterizedTypeTreeMatcher, MethodTreeMatcher, VariableTreeMatcher { private final boolean beingConservative; + @Inject public VoidMissingNullable(ErrorProneFlags flags) { this.beingConservative = nullnessChecksShouldBeConservative(flags); } diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/threadsafety/ImmutableAnnotationChecker.java b/core/src/main/java/com/google/errorprone/bugpatterns/threadsafety/ImmutableAnnotationChecker.java index 39d766e173b..826c9a7fed8 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/threadsafety/ImmutableAnnotationChecker.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/threadsafety/ImmutableAnnotationChecker.java @@ -40,6 +40,7 @@ import com.sun.tools.javac.code.Symbol.ClassSymbol; import java.util.Collections; import java.util.Optional; +import javax.inject.Inject; /** A {@link BugChecker}; see the associated {@link BugPattern} annotation for details. */ @BugPattern( @@ -59,6 +60,7 @@ public class ImmutableAnnotationChecker extends BugChecker implements ClassTreeM private final WellKnownMutability wellKnownMutability; + @Inject public ImmutableAnnotationChecker(ErrorProneFlags flags) { this.wellKnownMutability = WellKnownMutability.fromFlags(flags); } diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/threadsafety/ImmutableChecker.java b/core/src/main/java/com/google/errorprone/bugpatterns/threadsafety/ImmutableChecker.java index 613862112a7..eb1e83a9d08 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/threadsafety/ImmutableChecker.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/threadsafety/ImmutableChecker.java @@ -82,6 +82,7 @@ import java.util.Map; import java.util.Optional; import java.util.Set; +import javax.inject.Inject; import javax.lang.model.element.ElementKind; import org.checkerframework.checker.nullness.qual.Nullable; @@ -106,6 +107,7 @@ public class ImmutableChecker extends BugChecker this(ErrorProneFlags.empty(), immutableAnnotations); } + @Inject public ImmutableChecker(ErrorProneFlags flags) { this(flags, ImmutableSet.of(Immutable.class.getName())); } diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/threadsafety/ImmutableEnumChecker.java b/core/src/main/java/com/google/errorprone/bugpatterns/threadsafety/ImmutableEnumChecker.java index 18c66f75fb8..f6a6dbb5b7c 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/threadsafety/ImmutableEnumChecker.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/threadsafety/ImmutableEnumChecker.java @@ -40,6 +40,7 @@ import com.sun.tools.javac.code.Symbol.ClassSymbol; import java.util.Optional; import java.util.stream.Stream; +import javax.inject.Inject; /** A {@link BugChecker}; see the associated {@link BugPattern} annotation for details. */ @BugPattern( @@ -55,6 +56,7 @@ public class ImmutableEnumChecker extends BugChecker implements ClassTreeMatcher private final WellKnownMutability wellKnownMutability; + @Inject public ImmutableEnumChecker(ErrorProneFlags flags) { this.wellKnownMutability = WellKnownMutability.fromFlags(flags); } diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/time/PeriodTimeMath.java b/core/src/main/java/com/google/errorprone/bugpatterns/time/PeriodTimeMath.java index c6129e4e305..ea38bd11979 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/time/PeriodTimeMath.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/time/PeriodTimeMath.java @@ -31,6 +31,7 @@ import com.google.errorprone.matchers.Matcher; import com.sun.source.tree.ExpressionTree; import com.sun.source.tree.MethodInvocationTree; +import javax.inject.Inject; /** Bans calls to {@code Period#plus/minus(TemporalAmount)} where the argument is a Duration. */ @BugPattern( @@ -49,6 +50,7 @@ public final class PeriodTimeMath extends BugChecker implements MethodInvocation private static final Matcher DURATION = isSameType("java.time.Duration"); private static final Matcher PERIOD = isSameType("java.time.Period"); + @Inject public PeriodTimeMath(ErrorProneFlags flags) { boolean requireStrictCompatibility = flags.getBoolean("PeriodTimeMath:RequireStaticPeriodArgument").orElse(false); diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/time/PreferJavaTimeOverload.java b/core/src/main/java/com/google/errorprone/bugpatterns/time/PreferJavaTimeOverload.java index 6ba1e62d586..4efc407551e 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/time/PreferJavaTimeOverload.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/time/PreferJavaTimeOverload.java @@ -64,6 +64,7 @@ import java.util.concurrent.TimeUnit; import java.util.function.Predicate; import javax.annotation.Nullable; +import javax.inject.Inject; /** This check suggests the use of {@code java.time}-based APIs, when available. */ @BugPattern( @@ -135,6 +136,7 @@ public final class PreferJavaTimeOverload extends BugChecker private final boolean hasJava8LibSupport; + @Inject public PreferJavaTimeOverload(ErrorProneFlags flags) { this.hasJava8LibSupport = flags.getBoolean("Android:Java8Libs").orElse(false); } diff --git a/core/src/test/java/com/google/errorprone/ErrorProneCompilerIntegrationTest.java b/core/src/test/java/com/google/errorprone/ErrorProneCompilerIntegrationTest.java index 9474639aab9..632896a4d87 100644 --- a/core/src/test/java/com/google/errorprone/ErrorProneCompilerIntegrationTest.java +++ b/core/src/test/java/com/google/errorprone/ErrorProneCompilerIntegrationTest.java @@ -59,6 +59,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; +import javax.inject.Inject; import javax.lang.model.element.Name; import javax.tools.Diagnostic; import javax.tools.JavaFileObject; @@ -598,6 +599,7 @@ public void compilationWithError() { public static class ForbiddenString extends BugChecker implements ReturnTreeMatcher { private final String forbiddenString; + @Inject public ForbiddenString(ErrorProneFlags flags) { forbiddenString = flags.get("Forbidden").orElse("default"); }