Skip to content

Commit

Permalink
Automatic code cleanup.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 499956864
  • Loading branch information
graememorgan authored and Error Prone Team committed Jan 5, 2023
1 parent 8d518bf commit bb2563e
Show file tree
Hide file tree
Showing 42 changed files with 84 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -136,6 +137,7 @@ void validate(MethodInvocationTree tree, String argument) {

private final ConstantExpressions constantExpressions;

@Inject
public AlwaysThrows(ErrorProneFlags flags) {
this.constantExpressions = ConstantExpressions.fromFlags(flags);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -139,6 +140,7 @@ public MethodKind getMethodKind(MethodSymbol method) {
private final MessageTrailerStyle messageTrailerStyle;
private final ResultUsePolicyEvaluator<VisitorState, Symbol, MethodSymbol> evaluator;

@Inject
public CheckReturnValue(ErrorProneFlags flags) {
super(flags);
this.messageTrailerStyle =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -200,6 +201,7 @@ String replacement() {

private final boolean byteArrayOutputStreamToString;

@Inject
public DefaultCharset(ErrorProneFlags flags) {
this.byteArrayOutputStreamToString =
flags.getBoolean("DefaultCharset:ByteArrayOutputStreamToString").orElse(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -66,6 +67,7 @@ public class EqualsIncompatibleType extends BugChecker

private final TypeCompatibilityUtils typeCompatibilityUtils;

@Inject
public EqualsIncompatibleType(ErrorProneFlags flags) {
this.typeCompatibilityUtils = TypeCompatibilityUtils.fromFlags(flags);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -61,6 +62,7 @@ public IgnoredPureGetter() {
this(ErrorProneFlags.empty());
}

@Inject
public IgnoredPureGetter(ErrorProneFlags flags) {
super(flags);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand All @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -68,6 +69,7 @@ public class ParameterName extends BugChecker

private final ImmutableList<String> exemptPackages;

@Inject
public ParameterName(ErrorProneFlags errorProneFlags) {
this.exemptPackages =
errorProneFlags
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -419,6 +420,7 @@ public ReturnValueIgnored() {
this.matcher = anyOf(ALL_MATCHERS);
}

@Inject
public ReturnValueIgnored(ErrorProneFlags flags) {
super(flags);
this.matcher = createMatcher(flags);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand All @@ -60,6 +61,7 @@ public UnsynchronizedOverridesSynchronized() {
this(ErrorProneFlags.empty());
}

@Inject
public UnsynchronizedOverridesSynchronized(ErrorProneFlags flags) {
this.constantExpressions = ConstantExpressions.fromFlags(flags);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -169,6 +170,7 @@ public final class UnusedVariable extends BugChecker implements CompilationUnitT

private final boolean reportInjectedFields;

@Inject
public UnusedVariable(ErrorProneFlags flags) {
ImmutableSet.Builder<String> methodAnnotationsExemptingParameters =
ImmutableSet.<String>builder().add("org.robolectric.annotation.Implementation");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}
Expand Down
Loading

0 comments on commit bb2563e

Please sign in to comment.