From 6db6f95c1a2b40ed1c2858ad03ea6d659b04b81a Mon Sep 17 00:00:00 2001 From: ghm Date: Wed, 19 Nov 2025 03:20:09 -0800 Subject: [PATCH] Do some AutoValue -> record migration. I tried to clean up the InlineMes left behind, but do point out anything I missed. PiperOrigin-RevId: 834213609 --- .../errorprone/CompositeCodeTransformer.java | 11 +- .../google/errorprone/ErrorProneOptions.java | 24 +-- .../errorprone/RefactoringCollection.java | 31 +-- .../errorprone/dataflow/AccessPath.java | 25 +-- .../errorprone/dataflow/AccessPathStore.java | 19 +- .../google/errorprone/fixes/Replacement.java | 22 +- .../errorprone/fixes/SuggestedFixes.java | 12 +- .../errorprone/matchers/MultiMatcher.java | 23 +- .../method/ConstructorMatchState.java | 16 +- .../method/MethodInvocationMatcher.java | 50 ++--- .../com/google/errorprone/util/Commented.java | 19 +- .../google/errorprone/util/TargetType.java | 11 +- .../dataflow/AccessPathStoreTest.java | 6 +- .../bugpatterns/AbstractMockChecker.java | 24 +-- .../bugpatterns/AutoValueBoxedValues.java | 9 +- .../ImmutableMemberCollection.java | 13 +- .../MixedMutabilityReturnType.java | 19 +- .../bugpatterns/RedundantSetterCall.java | 85 ++------ .../StatementSwitchToExpressionSwitch.java | 200 +++++++----------- .../errorprone/bugpatterns/StaticImports.java | 33 ++- .../bugpatterns/ThrowSpecificExceptions.java | 10 +- .../bugpatterns/TypeCompatibility.java | 22 +- .../bugpatterns/apidiff/ApiDiff.java | 44 ++-- .../ArgumentChangeFinder.java | 24 +-- .../InvocationInfo.java | 26 +-- .../argumentselectiondefects/Parameter.java | 21 +- .../bugpatterns/checkreturnvalue/Api.java | 25 +-- .../checkreturnvalue/ResultUseRule.java | 23 +- ...ractCollectionIncompatibleTypeMatcher.java | 19 +- .../formatstring/FormatStringValidation.java | 15 +- .../inlineme/InlinabilityResult.java | 17 +- .../bugpatterns/nullness/NullnessUtils.java | 18 +- .../overloading/ParameterTree.java | 18 +- .../overloading/ParameterTrie.java | 6 +- .../threadsafety/GuardedByUtils.java | 12 +- .../threadsafety/ThreadSafety.java | 17 +- .../time/InvalidJavaTimeConstant.java | 37 +--- .../errorprone/refaster/LocalVarBinding.java | 14 +- .../refaster/PlaceholderMethod.java | 23 +- .../PlaceholderUnificationVisitor.java | 2 +- .../PlaceholderVerificationVisitor.java | 2 +- .../google/errorprone/refaster/UBlank.java | 8 +- .../errorprone/refaster/UFreeIdent.java | 2 +- .../com/google/errorprone/refaster/UIf.java | 25 ++- .../errorprone/refaster/ULocalVarIdent.java | 3 +- .../refaster/UPlaceholderStatement.java | 29 +-- .../errorprone/refaster/UStatement.java | 11 +- .../errorprone/refaster/UVariableDecl.java | 2 +- 48 files changed, 379 insertions(+), 748 deletions(-) diff --git a/check_api/src/main/java/com/google/errorprone/CompositeCodeTransformer.java b/check_api/src/main/java/com/google/errorprone/CompositeCodeTransformer.java index 95bcaee61c6..ffb9bea958b 100644 --- a/check_api/src/main/java/com/google/errorprone/CompositeCodeTransformer.java +++ b/check_api/src/main/java/com/google/errorprone/CompositeCodeTransformer.java @@ -16,7 +16,6 @@ package com.google.errorprone; -import com.google.auto.value.AutoValue; import com.google.common.collect.ImmutableClassToInstanceMap; import com.google.common.collect.ImmutableList; import com.sun.source.util.TreePath; @@ -25,20 +24,16 @@ import java.lang.annotation.Annotation; /** Combines multiple {@code CodeTransformer}s into one. */ -@AutoValue -public abstract class CompositeCodeTransformer implements CodeTransformer, Serializable { +public record CompositeCodeTransformer(ImmutableList transformers) + implements CodeTransformer, Serializable { public static CodeTransformer compose(CodeTransformer... transformers) { return compose(ImmutableList.copyOf(transformers)); } public static CodeTransformer compose(Iterable transformers) { - return new AutoValue_CompositeCodeTransformer(ImmutableList.copyOf(transformers)); + return new CompositeCodeTransformer(ImmutableList.copyOf(transformers)); } - CompositeCodeTransformer() {} - - public abstract ImmutableList transformers(); - @Override public void apply(TreePath path, Context context, DescriptionListener listener) { for (CodeTransformer transformer : transformers()) { diff --git a/check_api/src/main/java/com/google/errorprone/ErrorProneOptions.java b/check_api/src/main/java/com/google/errorprone/ErrorProneOptions.java index 0c650497812..35f131c4117 100644 --- a/check_api/src/main/java/com/google/errorprone/ErrorProneOptions.java +++ b/check_api/src/main/java/com/google/errorprone/ErrorProneOptions.java @@ -16,7 +16,7 @@ package com.google.errorprone; -import com.google.auto.value.AutoValue; +import com.google.auto.value.AutoBuilder; import com.google.common.base.Optional; import com.google.common.base.Preconditions; import com.google.common.base.Splitter; @@ -103,31 +103,25 @@ public enum Severity { ERROR } - @AutoValue - abstract static class PatchingOptions { + record PatchingOptions( + ImmutableSet namedCheckers, + boolean inPlace, + String baseDirectory, + Optional> customRefactorer, + ImportOrganizer importOrganizer) { final boolean doRefactor() { return inPlace() || !baseDirectory().isEmpty(); } - abstract ImmutableSet namedCheckers(); - - abstract boolean inPlace(); - - abstract String baseDirectory(); - - abstract Optional> customRefactorer(); - - abstract ImportOrganizer importOrganizer(); - static Builder builder() { - return new AutoValue_ErrorProneOptions_PatchingOptions.Builder() + return new AutoBuilder_ErrorProneOptions_PatchingOptions_Builder() .baseDirectory("") .inPlace(false) .namedCheckers(ImmutableSet.of()) .importOrganizer(ImportOrganizer.STATIC_FIRST_ORGANIZER); } - @AutoValue.Builder + @AutoBuilder abstract static class Builder { abstract Builder namedCheckers(ImmutableSet checkers); diff --git a/check_api/src/main/java/com/google/errorprone/RefactoringCollection.java b/check_api/src/main/java/com/google/errorprone/RefactoringCollection.java index ddec3fa26b0..70aea5a0ef3 100644 --- a/check_api/src/main/java/com/google/errorprone/RefactoringCollection.java +++ b/check_api/src/main/java/com/google/errorprone/RefactoringCollection.java @@ -20,7 +20,6 @@ import static java.nio.file.StandardOpenOption.APPEND; import static java.nio.file.StandardOpenOption.CREATE; -import com.google.auto.value.AutoValue; import com.google.common.collect.HashMultimap; import com.google.common.collect.Iterables; import com.google.common.collect.SetMultimap; @@ -62,16 +61,7 @@ public class RefactoringCollection implements DescriptionListener.Factory { private final DescriptionListener.Factory descriptionsFactory; private final ImportOrganizer importOrganizer; - @AutoValue - abstract static class RefactoringResult { - abstract String message(); - - abstract RefactoringResultType type(); - - private static RefactoringResult create(String message, RefactoringResultType type) { - return new AutoValue_RefactoringCollection_RefactoringResult(message, type); - } - } + record RefactoringResult(String message, RefactoringResultType type) {} enum RefactoringResultType { NO_CHANGES, @@ -86,13 +76,14 @@ static RefactoringCollection refactor(PatchingOptions patchingOptions, Context c if (patchingOptions.inPlace()) { fileDestination = new FsFileDestination(rootPath); postProcess = - uri -> - RefactoringResult.create( - String.format( - "Refactoring changes were successfully applied to %s," - + " please check the refactored code and recompile.", - uri), - RefactoringResultType.CHANGED); + uri -> { + String message = + String.format( + "Refactoring changes were successfully applied to %s," + + " please check the refactored code and recompile.", + uri); + return new RefactoringResult(message, RefactoringResultType.CHANGED); + }; } else { Path baseDir = rootPath.resolve(patchingOptions.baseDirectory()); Path patchFilePath = baseDir.resolve("error-prone.patch"); @@ -106,7 +97,7 @@ static RefactoringCollection refactor(PatchingOptions patchingOptions, Context c public RefactoringResult apply(URI uri) { try { writePatchFile(first, uri, patchFileDestination, patchFilePath); - return RefactoringResult.create( + return new RefactoringResult( "Changes were written to " + patchFilePath + ". Please inspect the file and apply with: " @@ -164,7 +155,7 @@ RefactoringResult applyChanges(URI uri) throws Exception { return postProcess.apply(uri); } - return RefactoringResult.create("", RefactoringResultType.NO_CHANGES); + return new RefactoringResult("", RefactoringResultType.NO_CHANGES); } private static void writePatchFile( diff --git a/check_api/src/main/java/com/google/errorprone/dataflow/AccessPath.java b/check_api/src/main/java/com/google/errorprone/dataflow/AccessPath.java index 265e3a3af02..a66e129f702 100644 --- a/check_api/src/main/java/com/google/errorprone/dataflow/AccessPath.java +++ b/check_api/src/main/java/com/google/errorprone/dataflow/AccessPath.java @@ -15,7 +15,6 @@ */ package com.google.errorprone.dataflow; -import com.google.auto.value.AutoValue; import com.google.common.collect.ImmutableList; import com.google.errorprone.util.MoreAnnotations; import com.sun.source.tree.IdentifierTree; @@ -55,19 +54,9 @@ * local variable {@code x} is represented by {base = Some x, fields = "foo" :: "foo()" :: nil} * * @author bennostein@google.com (Benno Stein) + * @param base If present, base of access path is contained Element; if absent, base is `this` */ -@AutoValue -public abstract class AccessPath { - - /** If present, base of access path is contained Element; if absent, base is `this` */ - public abstract @Nullable Element base(); - - public abstract ImmutableList path(); - - private static AccessPath create(@Nullable Element base, ImmutableList path) { - return new AutoValue_AccessPath(base, path); - } - +public record AccessPath(@Nullable Element base, ImmutableList path) { /** * Check whether {@code tree} is an AutoValue accessor. A tree is an AutoValue accessor iff: * @@ -126,7 +115,7 @@ public static boolean isAutoValueAccessor(Tree tree) { if (tree instanceof IdentifierTree) { // Implicit `this` receiver - return AccessPath.create(/* base= */ null, pathBuilder.build()); + return new AccessPath(null, pathBuilder.build()); } tree = ((MemberSelectTree) tree).getExpression(); @@ -134,23 +123,23 @@ public static boolean isAutoValueAccessor(Tree tree) { // Explicit `this` receiver if (tree instanceof IdentifierTree id && id.getName().contentEquals("this")) { - return AccessPath.create(/* base= */ null, pathBuilder.build()); + return new AccessPath(null, pathBuilder.build()); } // Local variable receiver if (tree instanceof IdentifierTree) { - return AccessPath.create(TreeUtils.elementFromTree(tree), pathBuilder.build()); + return new AccessPath(TreeUtils.elementFromTree(tree), pathBuilder.build()); } return null; } public static AccessPath fromLocalVariable(LocalVariableNode node) { - return AccessPath.create(node.getElement(), ImmutableList.of()); + return new AccessPath(node.getElement(), ImmutableList.of()); } public static AccessPath fromVariableDecl(VariableDeclarationNode node) { - return AccessPath.create(TreeUtils.elementFromDeclaration(node.getTree()), ImmutableList.of()); + return new AccessPath(TreeUtils.elementFromDeclaration(node.getTree()), ImmutableList.of()); } /** diff --git a/check_api/src/main/java/com/google/errorprone/dataflow/AccessPathStore.java b/check_api/src/main/java/com/google/errorprone/dataflow/AccessPathStore.java index c27a474ae35..8deacdac22f 100644 --- a/check_api/src/main/java/com/google/errorprone/dataflow/AccessPathStore.java +++ b/check_api/src/main/java/com/google/errorprone/dataflow/AccessPathStore.java @@ -19,7 +19,6 @@ import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.collect.Sets.intersection; -import com.google.auto.value.AutoValue; import com.google.common.collect.ImmutableMap; import com.google.errorprone.annotations.CanIgnoreReturnValue; import java.util.LinkedHashMap; @@ -38,20 +37,10 @@ * * @author bennostein@google.com (Benno Stein) */ -@AutoValue -public abstract class AccessPathStore> +public record AccessPathStore>(ImmutableMap heap) implements Store>, AccessPathValues { - - public abstract ImmutableMap heap(); - - private static > AccessPathStore create( - ImmutableMap heap) { - return new AutoValue_AccessPathStore<>(heap); - } - @SuppressWarnings({"unchecked", "rawtypes"}) // fully variant - private static final AccessPathStore EMPTY = - AccessPathStore.create(ImmutableMap.of()); + private static final AccessPathStore EMPTY = new AccessPathStore(ImmutableMap.of()); @SuppressWarnings("unchecked") // fully variant public static > AccessPathStore empty() { @@ -84,7 +73,7 @@ public AccessPathStore leastUpperBound(AccessPathStore other) { for (AccessPath aPath : intersection(heap().keySet(), other.heap().keySet())) { resultHeap.put(aPath, heap().get(aPath).leastUpperBound(other.heap().get(aPath))); } - return AccessPathStore.create(resultHeap.buildOrThrow()); + return new AccessPathStore<>(resultHeap.buildOrThrow()); } @Override @@ -122,7 +111,7 @@ public Builder setInformation(AccessPath aPath, V value) { } public AccessPathStore build() { - return AccessPathStore.create(ImmutableMap.copyOf(heap)); + return new AccessPathStore<>(ImmutableMap.copyOf(heap)); } } } diff --git a/check_api/src/main/java/com/google/errorprone/fixes/Replacement.java b/check_api/src/main/java/com/google/errorprone/fixes/Replacement.java index 50818caaa50..cb9f38f8762 100644 --- a/check_api/src/main/java/com/google/errorprone/fixes/Replacement.java +++ b/check_api/src/main/java/com/google/errorprone/fixes/Replacement.java @@ -18,13 +18,15 @@ import static com.google.common.base.Preconditions.checkArgument; -import com.google.auto.value.AutoValue; import com.google.common.collect.Range; -/** A replaced section of a source file. */ -@AutoValue -public abstract class Replacement { - +/** + * A replaced section of a source file. + * + * @param range The {@link Range} to be replaced. + * @param replaceWith The source text to appear in the output. + */ +public record Replacement(Range range, String replaceWith) { /** * Creates a {@link Replacement}. Start and end positions are represented as code unit indices in * a Unicode 16-bit string. @@ -40,7 +42,7 @@ public static Replacement create(int startPosition, int endPosition, String repl startPosition, endPosition, replaceWith); - return new AutoValue_Replacement(Range.closedOpen(startPosition, endPosition), replaceWith); + return new Replacement(Range.closedOpen(startPosition, endPosition), replaceWith); } /** The beginning of the replacement range. */ @@ -58,14 +60,8 @@ public int endPosition() { return range().upperEndpoint(); } - /** The {@link Range} to be replaced. */ - public abstract Range range(); - - /** The source text to appear in the output. */ - public abstract String replaceWith(); - /** Creates a new replacement at the same range with different text. */ Replacement withDifferentText(String replaceWith) { - return new AutoValue_Replacement(range(), replaceWith); + return new Replacement(range(), replaceWith); } } diff --git a/check_api/src/main/java/com/google/errorprone/fixes/SuggestedFixes.java b/check_api/src/main/java/com/google/errorprone/fixes/SuggestedFixes.java index 4d68f99f72e..ce4a4d55126 100644 --- a/check_api/src/main/java/com/google/errorprone/fixes/SuggestedFixes.java +++ b/check_api/src/main/java/com/google/errorprone/fixes/SuggestedFixes.java @@ -34,7 +34,6 @@ import static java.util.Arrays.stream; import static java.util.stream.Collectors.joining; -import com.google.auto.value.AutoValue; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Joiner; import com.google.common.base.Objects; @@ -1375,7 +1374,7 @@ public Result compile(ImmutableList extraOptions) { } catch (IOException e) { throw new UncheckedIOException(e); } - return Result.create(diagnosticListener.getDiagnostics()); + return new Result(diagnosticListener.getDiagnostics()); } private Context createContext() { @@ -1448,14 +1447,7 @@ public CharSequence getCharContent(boolean ignoreEncodingErrors) { } /** The result of the compilation. */ - @AutoValue - public abstract static class Result { - public abstract List> diagnostics(); - - private static Result create(List> diagnostics) { - return new AutoValue_SuggestedFixes_FixCompiler_Result(diagnostics); - } - } + public record Result(List> diagnostics) {} } private static final ImmutableSet SOURCE_TARGET_OPTIONS = diff --git a/check_api/src/main/java/com/google/errorprone/matchers/MultiMatcher.java b/check_api/src/main/java/com/google/errorprone/matchers/MultiMatcher.java index 25b9d39f86e..f988c0afbcd 100644 --- a/check_api/src/main/java/com/google/errorprone/matchers/MultiMatcher.java +++ b/check_api/src/main/java/com/google/errorprone/matchers/MultiMatcher.java @@ -18,7 +18,6 @@ import static com.google.common.collect.Iterables.getOnlyElement; -import com.google.auto.value.AutoValue; import com.google.common.collect.ImmutableList; import com.google.errorprone.VisitorState; import com.sun.source.tree.Tree; @@ -39,27 +38,19 @@ public interface MultiMatcher extends Matcher /** * A result from the call of {@link MultiMatcher#multiMatchResult(Tree, VisitorState)}, containing * information about whether it matched, and if so, what nodes matched. + * + * @param matches True if the MultiMatcher matched the nodes expected. + * @param matchingNodes The list of nodes which matched the MultiMatcher's expectations (could be + * empty if the match type was ALL and there were no child nodes). Only sensical if {@link + * #matches()} is true. */ - @AutoValue - abstract class MultiMatchResult { - MultiMatchResult() {} - - /** True if the MultiMatcher matched the nodes expected. */ - public abstract boolean matches(); - - /** - * The list of nodes which matched the MultiMatcher's expectations (could be empty if the match - * type was ALL and there were no child nodes). Only sensical if {@link #matches()} is true. - */ - public abstract ImmutableList matchingNodes(); - + public record MultiMatchResult(boolean matches, ImmutableList matchingNodes) { public final N onlyMatchingNode() { return getOnlyElement(matchingNodes()); } static MultiMatchResult create(boolean matches, List matchingNodes) { - return new AutoValue_MultiMatcher_MultiMatchResult<>( - matches, ImmutableList.copyOf(matchingNodes)); + return new MultiMatchResult<>(matches, ImmutableList.copyOf(matchingNodes)); } } } diff --git a/check_api/src/main/java/com/google/errorprone/matchers/method/ConstructorMatchState.java b/check_api/src/main/java/com/google/errorprone/matchers/method/ConstructorMatchState.java index 45a8011c62a..12c57463ebd 100644 --- a/check_api/src/main/java/com/google/errorprone/matchers/method/ConstructorMatchState.java +++ b/check_api/src/main/java/com/google/errorprone/matchers/method/ConstructorMatchState.java @@ -15,24 +15,22 @@ */ package com.google.errorprone.matchers.method; -import com.google.auto.value.AutoValue; import com.sun.tools.javac.code.Symbol.MethodSymbol; import com.sun.tools.javac.code.Type; -/** The state that is propagated across a match operation for constructors. */ -@AutoValue -public abstract class ConstructorMatchState implements MatchState { +/** + * The state that is propagated across a match operation for constructors. + * + * @param sym The method being matched. + */ +public record ConstructorMatchState(MethodSymbol sym) implements MatchState { /** The type of the class in which a member method or constructor is declared. */ @Override public Type ownerType() { return sym().owner.type; } - /** The method being matched. */ - @Override - public abstract MethodSymbol sym(); - static MatchState create(MethodSymbol methodSymbol) { - return new AutoValue_ConstructorMatchState(methodSymbol); + return new ConstructorMatchState(methodSymbol); } } diff --git a/check_api/src/main/java/com/google/errorprone/matchers/method/MethodInvocationMatcher.java b/check_api/src/main/java/com/google/errorprone/matchers/method/MethodInvocationMatcher.java index ff50adb256b..9bfe75c27f8 100644 --- a/check_api/src/main/java/com/google/errorprone/matchers/method/MethodInvocationMatcher.java +++ b/check_api/src/main/java/com/google/errorprone/matchers/method/MethodInvocationMatcher.java @@ -16,7 +16,6 @@ package com.google.errorprone.matchers.method; -import com.google.auto.value.AutoValue; import com.google.common.base.Preconditions; import com.google.common.collect.HashBasedTable; import com.google.common.collect.HashMultimap; @@ -157,12 +156,9 @@ public interface Token { Object comparisonKey(); /** A token limiting the {@link Kind} of invocation to match. */ - @AutoValue - abstract class Kind implements Token { - public abstract MethodKind kind(); - + public record Kind(MethodKind kind) implements Token { public static Kind create(MethodKind kind) { - return new AutoValue_MethodInvocationMatcher_Token_Kind(kind); + return new Kind(kind); } @Override @@ -177,10 +173,7 @@ public TokenType type() { } /** A token limiting the name of the method being invoked. */ - @AutoValue - abstract class MethodName implements Token { - public abstract String methodName(); - + public record MethodName(String methodName) implements Token { @Override public Object comparisonKey() { return methodName(); @@ -192,15 +185,12 @@ public TokenType type() { } public static MethodName create(String methodName) { - return new AutoValue_MethodInvocationMatcher_Token_MethodName(methodName); + return new MethodName(methodName); } } /** A token limiting the types of the formal parameters of the method being invoked. */ - @AutoValue - abstract class ParameterTypes implements Token { - public abstract ImmutableList parameterTypes(); - + public record ParameterTypes(ImmutableList parameterTypes) implements Token { @Override public TokenType type() { return TokenType.PARAMETER_TYPES; @@ -212,17 +202,14 @@ public Object comparisonKey() { } public static ParameterTypes create(ImmutableList types) { - return new AutoValue_MethodInvocationMatcher_Token_ParameterTypes(types); + return new ParameterTypes(types); } } /** A token specifying the class or interface in which the invoked method was defined. */ - @AutoValue - abstract class DefinedIn implements Token { - public abstract String owner(); - + public record DefinedIn(String owner) implements Token { public static DefinedIn create(String owner) { - return new AutoValue_MethodInvocationMatcher_Token_DefinedIn(owner); + return new DefinedIn(owner); } @Override @@ -240,12 +227,9 @@ public Object comparisonKey() { * A token specifying the exact type of the object on which the method is being invoked (or the * class in which it is defined, for static methods). */ - @AutoValue - abstract class ReceiverType implements Token { - public abstract String receiverType(); - + public record ReceiverType(String receiverType) implements Token { public static ReceiverType create(String receiverType) { - return new AutoValue_MethodInvocationMatcher_Token_ReceiverType(receiverType); + return new ReceiverType(receiverType); } @Override @@ -263,17 +247,14 @@ public TokenType type() { * A token specifying that the class of the object on which the method is being invoked must be * a subtype of another type. */ - @AutoValue - abstract class ReceiverSupertype implements Token { - public abstract String receiverSupertype(); - + public record ReceiverSupertype(String receiverSupertype) implements Token { @Override public TokenType type() { return TokenType.RECEIVER_SUPERTYPE; } public static ReceiverSupertype create(String receiverSupertype) { - return new AutoValue_MethodInvocationMatcher_Token_ReceiverSupertype(receiverSupertype); + return new ReceiverSupertype(receiverSupertype); } @Override @@ -293,16 +274,13 @@ public Object comparisonKey() { * Consider using the fluent API from MethodMatcher, and the associated helpers in Matchers, when * possible. */ - @AutoValue - public abstract static class Rule { - + public record Rule(ImmutableMap> required) { /** Builds a Rule object from a map. */ public static Rule create(ImmutableMap> required) { - return new AutoValue_MethodInvocationMatcher_Rule(required); + return new Rule(required); } // An absent token means to allow any value for this token type - public abstract ImmutableMap> required(); } /** A Node is just a type synonym for Object - it's just a unique pointer. */ diff --git a/check_api/src/main/java/com/google/errorprone/util/Commented.java b/check_api/src/main/java/com/google/errorprone/util/Commented.java index 509db54d114..b526be3068a 100644 --- a/check_api/src/main/java/com/google/errorprone/util/Commented.java +++ b/check_api/src/main/java/com/google/errorprone/util/Commented.java @@ -16,15 +16,16 @@ package com.google.errorprone.util; -import com.google.auto.value.AutoValue; +import com.google.auto.value.AutoBuilder; import com.google.common.collect.ImmutableList; import com.google.errorprone.annotations.CanIgnoreReturnValue; import com.sun.source.tree.Tree; /** Class to hold AST nodes annotated with the comments that are associated with them */ -@AutoValue -public abstract class Commented { - +public record Commented( + T tree, + ImmutableList beforeComments, + ImmutableList afterComments) { /** Identifies the position of a comment relative to the associated treenode. */ public enum Position { BEFORE, @@ -32,17 +33,11 @@ public enum Position { ANY } - public abstract T tree(); - - public abstract ImmutableList beforeComments(); - - public abstract ImmutableList afterComments(); - static Builder builder() { - return new AutoValue_Commented.Builder(); + return new AutoBuilder_Commented_Builder(); } - @AutoValue.Builder + @AutoBuilder abstract static class Builder { abstract Builder setTree(T tree); diff --git a/check_api/src/main/java/com/google/errorprone/util/TargetType.java b/check_api/src/main/java/com/google/errorprone/util/TargetType.java index a8f91a5a077..a86cc620dd5 100644 --- a/check_api/src/main/java/com/google/errorprone/util/TargetType.java +++ b/check_api/src/main/java/com/google/errorprone/util/TargetType.java @@ -25,7 +25,6 @@ import static com.google.errorprone.util.ASTHelpers.isSameType; import static com.google.errorprone.util.ASTHelpers.streamSuperMethods; -import com.google.auto.value.AutoValue; import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; @@ -84,9 +83,7 @@ import org.jspecify.annotations.Nullable; /** An expression's target type, see {@link #targetType}. */ -@AutoValue -public abstract class TargetType { - +public record TargetType(Type type, TreePath path) { /** * Returns the target type of the tree at the given {@link VisitorState}'s path, or else {@code * null}. @@ -130,12 +127,8 @@ public abstract class TargetType { return create(type, parent); } - public abstract Type type(); - - public abstract TreePath path(); - static TargetType create(Type type, TreePath path) { - return new AutoValue_TargetType(type, path); + return new TargetType(type, path); } private static final @Nullable Class CONSTANT_CASE_LABEL_TREE = constantCaseLabelTree(); diff --git a/check_api/src/test/java/com/google/errorprone/dataflow/AccessPathStoreTest.java b/check_api/src/test/java/com/google/errorprone/dataflow/AccessPathStoreTest.java index 3c80fbc05e2..e7303bbe15b 100644 --- a/check_api/src/test/java/com/google/errorprone/dataflow/AccessPathStoreTest.java +++ b/check_api/src/test/java/com/google/errorprone/dataflow/AccessPathStoreTest.java @@ -16,8 +16,8 @@ package com.google.errorprone.dataflow; import static com.google.common.truth.Truth.assertThat; -import static org.mockito.Mockito.mock; +import com.google.common.collect.ImmutableList; import com.google.errorprone.dataflow.nullnesspropagation.Nullness; import org.junit.Test; import org.junit.runner.RunWith; @@ -37,8 +37,8 @@ public void leastUpperBoundEmpty() { @Test public void buildAndGet() { AccessPathStore.Builder builder = newStore().toBuilder(); - AccessPath path1 = mock(AccessPath.class); - AccessPath path2 = mock(AccessPath.class); + AccessPath path1 = new AccessPath(null, ImmutableList.of("foo")); + AccessPath path2 = new AccessPath(null, ImmutableList.of("bar")); builder.setInformation(path1, Nullness.NULL); builder.setInformation(path2, Nullness.NONNULL); assertThat(builder.build().valueOfAccessPath(path1, Nullness.BOTTOM)).isEqualTo(Nullness.NULL); diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/AbstractMockChecker.java b/core/src/main/java/com/google/errorprone/bugpatterns/AbstractMockChecker.java index 2783cb923f5..c6c478a264d 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/AbstractMockChecker.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/AbstractMockChecker.java @@ -19,7 +19,6 @@ import static com.google.common.collect.Iterables.getOnlyElement; import static com.google.errorprone.matchers.Description.NO_MATCH; -import com.google.auto.value.AutoValue; import com.google.common.base.Strings; import com.google.common.base.Suppliers; import com.google.common.collect.Lists; @@ -85,22 +84,17 @@ public interface MockForbidder { Optional forbidReason(Type type, VisitorState state); } - /** An explanation of what type should not be mocked, and the reason why. */ - @AutoValue - public abstract static class Reason { - + /** + * An explanation of what type should not be mocked, and the reason why. + * + * @param unmockableClass A Type object representing the class that should not be mocked. + * @param reason The reason this class should not be mocked, which may be as simple as "it is + * annotated to forbid mocking" but may also provide a suggested workaround. + */ + public record Reason(Type unmockableClass, String reason) { public static Reason of(Type t, String reason) { - return new AutoValue_AbstractMockChecker_Reason(t, reason); + return new Reason(t, reason); } - - /** A Type object representing the class that should not be mocked. */ - public abstract Type unmockableClass(); - - /** - * The reason this class should not be mocked, which may be as simple as "it is annotated to - * forbid mocking" but may also provide a suggested workaround. - */ - public abstract String reason(); } /** diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/AutoValueBoxedValues.java b/core/src/main/java/com/google/errorprone/bugpatterns/AutoValueBoxedValues.java index 7bf65535d28..5908ce57892 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/AutoValueBoxedValues.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/AutoValueBoxedValues.java @@ -364,14 +364,9 @@ private static void suggestRemoveUnnecessaryBoxing( fix.replace(tree, unbox(state, type).tsym.getSimpleName().toString()); } - @AutoValue - abstract static class Getter { - abstract MethodTree method(); - - abstract SuggestedFix.Builder fix(); - + private record Getter(MethodTree method, SuggestedFix.Builder fix) { static Getter of(MethodTree method) { - return new AutoValue_AutoValueBoxedValues_Getter(method, SuggestedFix.builder()); + return new Getter(method, SuggestedFix.builder()); } } } diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/ImmutableMemberCollection.java b/core/src/main/java/com/google/errorprone/bugpatterns/ImmutableMemberCollection.java index 5dffb611301..d66354b2e8c 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/ImmutableMemberCollection.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/ImmutableMemberCollection.java @@ -26,7 +26,6 @@ import static com.google.errorprone.util.ASTHelpers.getReceiver; import static com.google.errorprone.util.ASTHelpers.getSymbol; -import com.google.auto.value.AutoValue; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableListMultimap; import com.google.common.collect.ImmutableMap; @@ -222,17 +221,9 @@ static ReplaceableType create(Class interfaceType, Class } } - @AutoValue - abstract static class ReplaceableVar { - abstract Symbol symbol(); - - abstract ReplaceableType type(); - - abstract Tree declaredType(); - + record ReplaceableVar(Symbol symbol, ReplaceableType type, Tree declaredType) { static ReplaceableVar create(VariableTree variableTree, ReplaceableType type) { - return new AutoValue_ImmutableMemberCollection_ReplaceableVar( - getSymbol(variableTree), type, variableTree.getType()); + return new ReplaceableVar(getSymbol(variableTree), type, variableTree.getType()); } private SuggestedFix getFix(ImmutableSet initTrees, VisitorState state) { diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/MixedMutabilityReturnType.java b/core/src/main/java/com/google/errorprone/bugpatterns/MixedMutabilityReturnType.java index a2dc5bae6e7..68d3316b12e 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/MixedMutabilityReturnType.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/MixedMutabilityReturnType.java @@ -30,7 +30,6 @@ import static com.google.errorprone.util.ASTHelpers.hasImplicitType; import static com.google.errorprone.util.ASTHelpers.methodCanBeOverridden; -import com.google.auto.value.AutoValue; import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; import com.google.common.collect.ImmutableCollection; @@ -432,20 +431,14 @@ public Void visitIdentifier(IdentifierTree identifier, Void unused) { } } - @AutoValue - abstract static class TypeDetails { - abstract String immutableType(); - - abstract String builderType(); - - abstract Matcher appendMethods(); - - abstract Matcher skipTypes(); - + record TypeDetails( + String immutableType, + String builderType, + Matcher appendMethods, + Matcher skipTypes) { static TypeDetails of( String immutableType, Matcher appendMethods, Matcher skipTypes) { - return new AutoValue_MixedMutabilityReturnType_TypeDetails( - immutableType, immutableType + ".Builder", appendMethods, skipTypes); + return new TypeDetails(immutableType, immutableType + ".Builder", appendMethods, skipTypes); } } } diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/RedundantSetterCall.java b/core/src/main/java/com/google/errorprone/bugpatterns/RedundantSetterCall.java index 78b04f6c0b1..7350a0c5a1a 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/RedundantSetterCall.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/RedundantSetterCall.java @@ -38,7 +38,6 @@ import static com.google.errorprone.util.ASTHelpers.isSubtype; import static java.util.stream.Collectors.joining; -import com.google.auto.value.AutoValue; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; @@ -162,7 +161,7 @@ public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState for (FieldType fieldType : FieldType.values()) { FieldWithValue match = fieldType.match(methodName, method, state); if (match != null) { - setters.put(match.getField(), match); + setters.put(match.field(), match); if (oneOfSetters.containsKey(methodName)) { setters.put(oneOfSetters.get(methodName), match); } @@ -190,7 +189,7 @@ private ImmutableMap scanForOneOfSetters(Symbol proto, Visit if (!ONE_OF_ENUM.apply(element.type, state)) { continue; } - var oneOfField = OneOfField.of(element.getSimpleName().toString().replaceFirst("Case$", "")); + var oneOfField = new OneOfField(element.getSimpleName().toString().replaceFirst("Case$", "")); for (String enumName : enumValues(element.type.tsym)) { if (enumName.equals("ONEOF_NOT_SET")) { continue; @@ -228,16 +227,16 @@ private Description describe( // where the correct fix is probably to replace the second 'setFoo' with 'setBar'. SuggestedFix.Builder fix = SuggestedFix.builder(); long values = - locations.stream().map(l -> state.getSourceForNode(l.getArgument())).distinct().count(); + locations.stream().map(l -> state.getSourceForNode(l.argument())).distinct().count(); if (field.identicalValuesShouldBeRemoved() && values == 1) { for (FieldWithValue fieldWithValue : Iterables.skip(locations, 1)) { - MethodInvocationTree method = fieldWithValue.getMethodInvocation(); + MethodInvocationTree method = fieldWithValue.methodInvocation(); int startPos = state.getEndPosition(ASTHelpers.getReceiver(method)); int endPos = state.getEndPosition(method); fix.replace(startPos, endPos, ""); } } - return buildDescription(locations.iterator().next().getArgument()) + return buildDescription(locations.iterator().next().argument()) .setMessage( String.format( "%s was called %s%s. Setting the same field multiple times is redundant, and " @@ -261,7 +260,8 @@ enum FieldType { @Nullable FieldWithValue match(String name, MethodInvocationTree tree, VisitorState state) { if ((name.startsWith("set") || isWithinAutoValueBuilder(getSymbol(tree), state)) && tree.getArguments().size() == 1) { - return FieldWithValue.of(SingleField.of(name), tree, tree.getArguments().get(0)); + Field field = new SingleField(name); + return new FieldWithValue(field, tree, tree.getArguments().get(0)); } return null; } @@ -272,8 +272,8 @@ enum FieldType { if (name.startsWith("set") && tree.getArguments().size() == 2) { Integer index = ASTHelpers.constValue(tree.getArguments().get(0), Integer.class); if (index != null) { - return FieldWithValue.of( - RepeatedField.of(name, index), tree, tree.getArguments().get(1)); + Field field = new RepeatedField(name, index); + return new FieldWithValue(field, tree, tree.getArguments().get(1)); } } return null; @@ -285,7 +285,8 @@ enum FieldType { if (name.startsWith("put") && tree.getArguments().size() == 2) { Object key = ASTHelpers.constValue(tree.getArguments().get(0), Object.class); if (key != null) { - return FieldWithValue.of(MapField.of(name, key), tree, tree.getArguments().get(1)); + Field field = new MapField(name, key); + return new FieldWithValue(field, tree, tree.getArguments().get(1)); } } return null; @@ -311,17 +312,10 @@ interface Field { String toString(Iterable locations); } - @AutoValue - abstract static class SingleField implements Field { - abstract String getName(); - - static SingleField of(String name) { - return new AutoValue_RedundantSetterCall_SingleField(name); - } - + record SingleField(String name) implements Field { @Override public final String toString(Iterable locations) { - return String.format("%s(..)", getName()); + return String.format("%s(..)", this.name()); } @Override @@ -330,19 +324,10 @@ public boolean identicalValuesShouldBeRemoved() { } } - @AutoValue - abstract static class RepeatedField implements Field { - abstract String getName(); - - abstract int getIndex(); - - static RepeatedField of(String name, int index) { - return new AutoValue_RedundantSetterCall_RepeatedField(name, index); - } - + record RepeatedField(String name, int index) implements Field { @Override public final String toString(Iterable locations) { - return String.format("%s(%s, ..)", getName(), getIndex()); + return String.format("%s(%s, ..)", this.name(), this.index()); } @Override @@ -351,19 +336,10 @@ public boolean identicalValuesShouldBeRemoved() { } } - @AutoValue - abstract static class MapField implements Field { - abstract String getName(); - - abstract Object getKey(); - - static MapField of(String name, Object key) { - return new AutoValue_RedundantSetterCall_MapField(name, key); - } - + record MapField(String name, Object key) implements Field { @Override public final String toString(Iterable locations) { - return String.format("%s(%s, ..)", getName(), getKey()); + return String.format("%s(%s, ..)", this.name(), this.key()); } @Override @@ -372,21 +348,14 @@ public boolean identicalValuesShouldBeRemoved() { } } - @AutoValue - abstract static class OneOfField implements Field { - abstract String oneOfName(); - - static OneOfField of(String oneOfName) { - return new AutoValue_RedundantSetterCall_OneOfField(oneOfName); - } - + record OneOfField(String oneOfName) implements Field { @Override public final String toString(Iterable locations) { return String.format( "The oneof `%s` (set via %s)", oneOfName(), stream(locations) - .map(l -> getSymbol(l.getMethodInvocation()).getSimpleName().toString()) + .map(l -> getSymbol(l.methodInvocation()).getSimpleName().toString()) .distinct() .sorted() .collect(joining(", "))); @@ -398,18 +367,6 @@ public boolean identicalValuesShouldBeRemoved() { } } - @AutoValue - abstract static class FieldWithValue { - abstract Field getField(); - - abstract MethodInvocationTree getMethodInvocation(); - - abstract ExpressionTree getArgument(); - - static FieldWithValue of( - Field field, MethodInvocationTree methodInvocationTree, ExpressionTree argumentTree) { - return new AutoValue_RedundantSetterCall_FieldWithValue( - field, methodInvocationTree, argumentTree); - } - } + record FieldWithValue( + Field field, MethodInvocationTree methodInvocation, ExpressionTree argument) {} } diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/StatementSwitchToExpressionSwitch.java b/core/src/main/java/com/google/errorprone/bugpatterns/StatementSwitchToExpressionSwitch.java index 7fb0fa0bc62..671ed16ff5c 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/StatementSwitchToExpressionSwitch.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/StatementSwitchToExpressionSwitch.java @@ -31,7 +31,6 @@ import static com.sun.source.tree.Tree.Kind.THROW; import static java.util.stream.Collectors.joining; -import com.google.auto.value.AutoValue; import com.google.common.base.Joiner; import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; @@ -118,7 +117,7 @@ public final class StatementSwitchToExpressionSwitch extends BugChecker * immutable. */ private static final AssignmentSwitchAnalysisResult DEFAULT_ASSIGNMENT_SWITCH_ANALYSIS_RESULT = - AssignmentSwitchAnalysisResult.of( + new AssignmentSwitchAnalysisResult( /* canConvertToAssignmentSwitch= */ false, /* precedingVariableDeclaration= */ Optional.empty(), /* assignmentTargetOptional= */ Optional.empty(), @@ -127,13 +126,13 @@ public final class StatementSwitchToExpressionSwitch extends BugChecker /** Default (negative) result for overall analysis. Note that the value is immutable. */ private static final AnalysisResult DEFAULT_ANALYSIS_RESULT = - AnalysisResult.of( - /* canConvertDirectlyToExpressionSwitch= */ false, - /* canConvertToReturnSwitch= */ false, - /* canRemoveDefault= */ false, + new AnalysisResult( + false, + false, + false, DEFAULT_ASSIGNMENT_SWITCH_ANALYSIS_RESULT, - /* groupedWithNextCase= */ ImmutableList.of(), - /* symbolsToHoist= */ ImmutableBiMap.of()); + ImmutableList.of(), + ImmutableBiMap.of()); private static final String EQUALS_STRING = "="; private static final Matcher COMPILE_TIME_CONSTANT_MATCHER = @@ -289,12 +288,17 @@ private static AnalysisResult analyzeSwitchTree(SwitchTree switchTree, VisitorSt // Does each case consist solely of returning a (non-void) expression? CaseQualifications returnSwitchCaseQualifications = CaseQualifications.NO_CASES_ASSESSED; // Does each case consist solely of a throw or the same symbol assigned in the same way? - AssignmentSwitchAnalysisState assignmentSwitchAnalysisState = - AssignmentSwitchAnalysisState.of( - /* assignmentSwitchCaseQualifications= */ CaseQualifications.NO_CASES_ASSESSED, - /* assignmentTargetOptional= */ Optional.empty(), - /* assignmentKindOptional= */ Optional.empty(), - /* assignmentTreeOptional= */ Optional.empty()); + Optional assignmentTargetOptional = Optional.empty(); + Optional assignmentKindOptional = Optional.empty(); + /* assignmentSwitchCaseQualifications= */ + /* assignmentTargetOptional= */ + /* assignmentKindOptional= */ + /* assignmentTreeOptional= */ AssignmentSwitchAnalysisState assignmentSwitchAnalysisState = + new AssignmentSwitchAnalysisState( + CaseQualifications.NO_CASES_ASSESSED, + assignmentTargetOptional, + assignmentKindOptional, + Optional.empty()); boolean hasDefaultCase = false; // One-pass scan through each case in switch @@ -464,11 +468,11 @@ && isSwitchExhaustiveWithoutDefault( target -> findCombinableVariableTree(target, precedingStatements, state)) : Optional.empty(); - return AnalysisResult.of( + return new AnalysisResult( canConvertDirectlyToExpressionSwitch, canConvertToReturnSwitch, canRemoveDefault, - AssignmentSwitchAnalysisResult.of( + new AssignmentSwitchAnalysisResult( canConvertToAssignmentSwitch, combinableVariableTree, assignmentSwitchAnalysisState.assignmentTargetOptional(), @@ -699,7 +703,7 @@ private static AssignmentSwitchAnalysisState analyzeCaseForAssignmentSwitch( if (statements.isEmpty()) { return isLastCaseInSwitch // An empty last case cannot be an assignment - ? AssignmentSwitchAnalysisState.of( + ? new AssignmentSwitchAnalysisState( CaseQualifications.SOME_OR_ALL_CASES_DONT_QUALIFY, assignmentTargetOptional, assignmentExpressionKindOptional, @@ -721,7 +725,7 @@ private static AssignmentSwitchAnalysisState analyzeCaseForAssignmentSwitch( && breakTree.getLabel() == null); if (!expressionOrExpressionBreak) { // Conversion of this block is not supported - return AssignmentSwitchAnalysisState.of( + return new AssignmentSwitchAnalysisState( CaseQualifications.SOME_OR_ALL_CASES_DONT_QUALIFY, assignmentTargetOptional, assignmentExpressionKindOptional, @@ -772,17 +776,15 @@ private static AssignmentSwitchAnalysisState analyzeCaseForAssignmentSwitch( } // Save the assignment target/kind in the state, but never overwrite existing target/kind - return AssignmentSwitchAnalysisState.of( + return new AssignmentSwitchAnalysisState( caseQualifications, - /* assignmentTargetOptional= */ assignmentTargetOptional.isEmpty() + assignmentTargetOptional.isEmpty() ? caseAssignmentTargetOptional : assignmentTargetOptional, - /* assignmentKindOptional= */ assignmentExpressionKindOptional.isEmpty() + assignmentExpressionKindOptional.isEmpty() ? caseAssignmentKindOptional : assignmentExpressionKindOptional, - /* assignmentTreeOptional= */ assignmentTreeOptional.isEmpty() - ? caseAssignmentTreeOptional - : assignmentTreeOptional); + assignmentTreeOptional.isEmpty() ? caseAssignmentTreeOptional : assignmentTreeOptional); } /** @@ -1860,107 +1862,55 @@ private static NullDefaultKind analyzeCaseForNullAndDefault(CaseTree caseTree) { return NullDefaultKind.KIND_NEITHER; } - @AutoValue - abstract static class AnalysisResult { - /** Whether the statement switch can be directly converted to an expression switch */ - abstract boolean canConvertDirectlyToExpressionSwitch(); - - /** Whether the statement switch can be converted to a return switch */ - abstract boolean canConvertToReturnSwitch(); - - /** - * Whether the assignment switch is exhaustive even in the absence of the default case that - * exists in the original switch statement - */ - abstract boolean canRemoveDefault(); - - /** Results of the analysis for conversion to an assignment switch */ - abstract AssignmentSwitchAnalysisResult assignmentSwitchAnalysisResult(); - - /** - * List of whether each case tree can be grouped with its successor in transformed source code - */ - abstract ImmutableList groupedWithNextCase(); - - /** - * Bidirectional map from symbols to hoist to the top of the switch statement to their - * declaration trees - */ - abstract ImmutableBiMap symbolsToHoist(); - - static AnalysisResult of( - boolean canConvertDirectlyToExpressionSwitch, - boolean canConvertToReturnSwitch, - boolean canRemoveDefault, - AssignmentSwitchAnalysisResult assignmentSwitchAnalysisResult, - ImmutableList groupedWithNextCase, - ImmutableBiMap symbolsToHoist) { - return new AutoValue_StatementSwitchToExpressionSwitch_AnalysisResult( - canConvertDirectlyToExpressionSwitch, - canConvertToReturnSwitch, - canRemoveDefault, - assignmentSwitchAnalysisResult, - groupedWithNextCase, - symbolsToHoist); - } - } - - @AutoValue - abstract static class AssignmentSwitchAnalysisResult { - /** Whether the statement switch can be converted to an assignment switch */ - abstract boolean canConvertToAssignmentSwitch(); - - /** The immediately preceding variable declaration if this switch can be combined with it. */ - abstract Optional precedingVariableDeclaration(); - - /** Target of the assignment switch, if any */ - abstract Optional assignmentTargetOptional(); - - /** Kind of assignment made by the assignment switch, if any */ - abstract Optional assignmentKindOptional(); - - /** Java source code of the assignment switch's operator, e.g. "+=" */ - abstract Optional assignmentSourceCodeOptional(); - - static AssignmentSwitchAnalysisResult of( - boolean canConvertToAssignmentSwitch, - Optional precedingVariableDeclaration, - Optional assignmentTargetOptional, - Optional assignmentKindOptional, - Optional assignmentSourceCodeOptional) { - return new AutoValue_StatementSwitchToExpressionSwitch_AssignmentSwitchAnalysisResult( - canConvertToAssignmentSwitch, - precedingVariableDeclaration, - assignmentTargetOptional, - assignmentKindOptional, - assignmentSourceCodeOptional); - } - } - - @AutoValue - abstract static class AssignmentSwitchAnalysisState { - /** Overall qualification of the switch statement for conversion to an assignment switch */ - abstract CaseQualifications assignmentSwitchCaseQualifications(); - - /** Target of the first assignment seen, if any */ - abstract Optional assignmentTargetOptional(); - - /** Kind of the first assignment seen, if any */ - abstract Optional assignmentExpressionKindOptional(); + /** + * @param canConvertDirectlyToExpressionSwitch Whether the statement switch can be directly + * converted to an expression switch + * @param canConvertToReturnSwitch Whether the statement switch can be converted to a return + * switch + * @param canRemoveDefault Whether the assignment switch is exhaustive even in the absence of the + * default case that exists in the original switch statement + * @param assignmentSwitchAnalysisResult Results of the analysis for conversion to an assignment + * switch + * @param groupedWithNextCase List of whether each case tree can be grouped with its successor in + * transformed source code + * @param symbolsToHoist Bidirectional map from symbols to hoist to the top of the switch + * statement to their declaration trees + */ + record AnalysisResult( + boolean canConvertDirectlyToExpressionSwitch, + boolean canConvertToReturnSwitch, + boolean canRemoveDefault, + AssignmentSwitchAnalysisResult assignmentSwitchAnalysisResult, + ImmutableList groupedWithNextCase, + ImmutableBiMap symbolsToHoist) {} - /** ExpressionTree of the first assignment seen, if any */ - abstract Optional assignmentTreeOptional(); + /** + * @param canConvertToAssignmentSwitch Whether the statement switch can be converted to an + * assignment switch + * @param precedingVariableDeclaration The immediately preceding variable declaration if this + * switch can be combined with it. + * @param assignmentTargetOptional Target of the assignment switch, if any + * @param assignmentKindOptional Kind of assignment made by the assignment switch, if any + * @param assignmentSourceCodeOptional Java source code of the assignment switch's operator, e.g. + * "+=" + */ + record AssignmentSwitchAnalysisResult( + boolean canConvertToAssignmentSwitch, + Optional precedingVariableDeclaration, + Optional assignmentTargetOptional, + Optional assignmentKindOptional, + Optional assignmentSourceCodeOptional) {} - static AssignmentSwitchAnalysisState of( - CaseQualifications assignmentSwitchCaseQualifications, - Optional assignmentTargetOptional, - Optional assignmentKindOptional, - Optional assignmentTreeOptional) { - return new AutoValue_StatementSwitchToExpressionSwitch_AssignmentSwitchAnalysisState( - assignmentSwitchCaseQualifications, - assignmentTargetOptional, - assignmentKindOptional, - assignmentTreeOptional); - } - } + /** + * @param assignmentSwitchCaseQualifications Overall qualification of the switch statement for + * conversion to an assignment switch + * @param assignmentTargetOptional Target of the first assignment seen, if any + * @param assignmentExpressionKindOptional Kind of the first assignment seen, if any + * @param assignmentTreeOptional ExpressionTree of the first assignment seen, if any + */ + record AssignmentSwitchAnalysisState( + CaseQualifications assignmentSwitchCaseQualifications, + Optional assignmentTargetOptional, + Optional assignmentExpressionKindOptional, + Optional assignmentTreeOptional) {} } diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/StaticImports.java b/core/src/main/java/com/google/errorprone/bugpatterns/StaticImports.java index 3218eff6e5c..934d82129cb 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/StaticImports.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/StaticImports.java @@ -21,7 +21,6 @@ import static com.google.errorprone.util.ASTHelpers.getSymbol; import static com.google.errorprone.util.ASTHelpers.isStatic; -import com.google.auto.value.AutoValue; import com.google.common.base.Optional; import com.google.common.collect.ImmutableSet; import com.google.errorprone.VisitorState; @@ -42,21 +41,19 @@ */ public final class StaticImports { - /** Information about a static import. */ - @AutoValue - public abstract static class StaticImportInfo { - /** The fully qualified name used to import the type (possibly non-canonical). */ - public abstract String importedName(); - - /** The fully-qualified canonical name of the type. */ - public abstract String canonicalName(); - - /** The simple name of the imported member. */ - public abstract Optional simpleName(); - - /** The field or variable symbol for a static non-type member import. */ - public abstract ImmutableSet members(); - + /** + * Information about a static import. + * + * @param importedName The fully qualified name used to import the type (possibly non-canonical). + * @param canonicalName The fully-qualified canonical name of the type. + * @param simpleName The simple name of the imported member. + * @param members The field or variable symbol for a static non-type member import. + */ + public record StaticImportInfo( + String importedName, + String canonicalName, + Optional simpleName, + ImmutableSet members) { /** * Returns whether the import is canonical, i.e. the fully qualified name used to import the * type matches the scopes it was declared in. @@ -75,13 +72,13 @@ public String importStatement() { } private static StaticImportInfo create(String importedName, String canonicalName) { - return new AutoValue_StaticImports_StaticImportInfo( + return new StaticImportInfo( importedName, canonicalName, Optional.absent(), ImmutableSet.of()); } private static StaticImportInfo create( String importedName, String canonicalName, String simpleName, Iterable members) { - return new AutoValue_StaticImports_StaticImportInfo( + return new StaticImportInfo( importedName, canonicalName, Optional.of(simpleName), ImmutableSet.copyOf(members)); } } diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/ThrowSpecificExceptions.java b/core/src/main/java/com/google/errorprone/bugpatterns/ThrowSpecificExceptions.java index 052232a5dde..7b53b76eb08 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/ThrowSpecificExceptions.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/ThrowSpecificExceptions.java @@ -18,7 +18,6 @@ import static com.google.errorprone.BugPattern.SeverityLevel.WARNING; -import com.google.auto.value.AutoValue; import com.google.common.base.VerifyException; import com.google.common.collect.ImmutableList; import com.google.errorprone.BugPattern; @@ -72,14 +71,9 @@ public Description matchNewClass(NewClassTree tree, VisitorState state) { return Description.NO_MATCH; } - @AutoValue - abstract static class AbstractLikeException { - abstract Matcher matcher(); - - abstract String replacement(); - + private record AbstractLikeException(Matcher matcher, String replacement) { static AbstractLikeException of(Class abstractLikeException, Class replacement) { - return new AutoValue_ThrowSpecificExceptions_AbstractLikeException( + return new AbstractLikeException( Matchers.constructor().forClass(abstractLikeException.getName()), replacement.getName()); } } diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/TypeCompatibility.java b/core/src/main/java/com/google/errorprone/bugpatterns/TypeCompatibility.java index e9c4a21da38..3f4cdea5678 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/TypeCompatibility.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/TypeCompatibility.java @@ -25,7 +25,6 @@ import static com.google.errorprone.util.ASTHelpers.isSameType; import static com.google.errorprone.util.ASTHelpers.isSubtype; -import com.google.auto.value.AutoValue; import com.google.common.collect.Streams; import com.google.errorprone.ErrorProneFlags; import com.google.errorprone.VisitorState; @@ -359,18 +358,15 @@ private static TreeSet typeSet(VisitorState state) { state.getTypes().isSameType(t1, t2) ? 0 : t1.toString().compareTo(t2.toString())); } - @AutoValue - public abstract static class TypeCompatibilityReport { + /** + * The result of a {@link TypeCompatibility#compatibilityOfTypes} call. + * + *

If {@link #isCompatible} is {@code true}, the other fields are {@code null}. + */ + public record TypeCompatibilityReport( + boolean isCompatible, @Nullable Type lhs, @Nullable Type rhs, @Nullable String extraReason) { private static final TypeCompatibilityReport COMPATIBLE = - new AutoValue_TypeCompatibility_TypeCompatibilityReport(true, null, null, null); - - public abstract boolean isCompatible(); - - public abstract @Nullable Type lhs(); - - public abstract @Nullable Type rhs(); - - public abstract @Nullable String extraReason(); + new TypeCompatibilityReport(true, null, null, null); static TypeCompatibilityReport compatible() { return COMPATIBLE; @@ -381,7 +377,7 @@ static TypeCompatibilityReport incompatible(Type lhs, Type rhs) { } static TypeCompatibilityReport incompatible(Type lhs, Type rhs, String extraReason) { - return new AutoValue_TypeCompatibility_TypeCompatibilityReport(false, lhs, rhs, extraReason); + return new TypeCompatibilityReport(false, lhs, rhs, extraReason); } } diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/apidiff/ApiDiff.java b/core/src/main/java/com/google/errorprone/bugpatterns/apidiff/ApiDiff.java index 71666a91dd2..912011cd901 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/apidiff/ApiDiff.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/apidiff/ApiDiff.java @@ -16,29 +16,31 @@ package com.google.errorprone.bugpatterns.apidiff; -import com.google.auto.value.AutoValue; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSetMultimap; import com.google.common.collect.Multimap; import com.google.errorprone.bugpatterns.apidiff.ApiDiffProto.Diff; import java.util.Set; -/** The difference between two APIs. */ -@AutoValue -public abstract class ApiDiff { - - /** A per class unique identifier for a field or method. */ - @AutoValue - public abstract static class ClassMemberKey { - - /** The simple name of the member. */ - public abstract String identifier(); - - /** The JVMS 4.3 member descriptor. */ - public abstract String descriptor(); - +/** + * The difference between two APIs. + * + * @param unsupportedClasses Binary names of classes only present in the new API. + * @param unsupportedMembersByClass Members only present in the new API, grouped by binary name of + * their declaring class. + */ +public record ApiDiff( + ImmutableSet unsupportedClasses, + ImmutableSetMultimap unsupportedMembersByClass) { + /** + * A per class unique identifier for a field or method. + * + * @param identifier The simple name of the member. + * @param descriptor The JVMS 4.3 member descriptor. + */ + public record ClassMemberKey(String identifier, String descriptor) { public static ClassMemberKey create(String identifier, String descriptor) { - return new AutoValue_ApiDiff_ClassMemberKey(identifier, descriptor); + return new ClassMemberKey(identifier, descriptor); } @Override @@ -47,12 +49,6 @@ public final String toString() { } } - /** Binary names of classes only present in the new API. */ - public abstract ImmutableSet unsupportedClasses(); - - /** Members only present in the new API, grouped by binary name of their declaring class. */ - public abstract ImmutableSetMultimap unsupportedMembersByClass(); - /** Returns true if the class with the given binary name is unsupported. */ boolean isClassUnsupported(String className) { return unsupportedClasses().contains(className); @@ -67,7 +63,7 @@ boolean isMemberUnsupported(String className, ClassMemberKey memberKey) { public static ApiDiff fromMembers( Set unsupportedClasses, Multimap unsupportedMembersByClass) { - return new AutoValue_ApiDiff( + return new ApiDiff( ImmutableSet.copyOf(unsupportedClasses), ImmutableSetMultimap.copyOf(unsupportedMembersByClass)); } @@ -91,7 +87,7 @@ public static ApiDiff fromProto(Diff diff) { default -> throw new AssertionError(c.getDiffCase()); } } - return new AutoValue_ApiDiff(unsupportedClasses.build(), unsupportedMembersByClass.build()); + return new ApiDiff(unsupportedClasses.build(), unsupportedMembersByClass.build()); } /** Converts a {@link ApiDiff} to a {@link ApiDiffProto.Diff}. */ diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/argumentselectiondefects/ArgumentChangeFinder.java b/core/src/main/java/com/google/errorprone/bugpatterns/argumentselectiondefects/ArgumentChangeFinder.java index 8b6bf999aa0..bed29c92673 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/argumentselectiondefects/ArgumentChangeFinder.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/argumentselectiondefects/ArgumentChangeFinder.java @@ -16,7 +16,7 @@ package com.google.errorprone.bugpatterns.argumentselectiondefects; -import com.google.auto.value.AutoValue; +import com.google.auto.value.AutoBuilder; import com.google.common.collect.ImmutableList; import com.google.errorprone.annotations.CanIgnoreReturnValue; import java.util.function.Function; @@ -29,24 +29,18 @@ * match on the bi-partite graph mapping parameters to assignable arguments. * * @author andrewrice@google.com (Andrew Rice) + * @param distanceFunction The distance function to use when comparing formal and actual parameters. + * The function should return 0 for highly similar names and larger positive values as names are + * more different. + * @param heuristics List of heuristics to apply to eliminate spurious suggestions. */ -@AutoValue -abstract class ArgumentChangeFinder { - - /** - * The distance function to use when comparing formal and actual parameters. The function should - * return 0 for highly similar names and larger positive values as names are more different. - */ - abstract Function distanceFunction(); - - /** List of heuristics to apply to eliminate spurious suggestions. */ - abstract ImmutableList heuristics(); - +record ArgumentChangeFinder( + Function distanceFunction, ImmutableList heuristics) { static Builder builder() { - return new AutoValue_ArgumentChangeFinder.Builder(); + return new AutoBuilder_ArgumentChangeFinder_Builder(); } - @AutoValue.Builder + @AutoBuilder abstract static class Builder { /** Set the distance function that {@link ArgumentChangeFinder} should use. */ diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/argumentselectiondefects/InvocationInfo.java b/core/src/main/java/com/google/errorprone/bugpatterns/argumentselectiondefects/InvocationInfo.java index 408dcd70958..25998e2a39e 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/argumentselectiondefects/InvocationInfo.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/argumentselectiondefects/InvocationInfo.java @@ -19,7 +19,6 @@ import static com.google.errorprone.util.ASTHelpers.canonicalConstructor; import static com.google.errorprone.util.ASTHelpers.getSymbol; -import com.google.auto.value.AutoValue; import com.google.common.collect.ImmutableList; import com.google.errorprone.VisitorState; import com.sun.source.tree.BindingPatternTree; @@ -38,22 +37,15 @@ * * @author andrewrice@google.com (Andrew Rice) */ -@AutoValue -abstract class InvocationInfo { - - abstract Tree tree(); - - abstract MethodSymbol symbol(); - - abstract ImmutableList actualParameters(); - - abstract ImmutableList formalParameters(); - - abstract VisitorState state(); - +record InvocationInfo( + Tree tree, + MethodSymbol symbol, + ImmutableList actualParameters, + ImmutableList formalParameters, + VisitorState state) { static InvocationInfo createFromMethodInvocation( MethodInvocationTree tree, MethodSymbol symbol, VisitorState state) { - return new AutoValue_InvocationInfo( + return new InvocationInfo( tree, symbol, ImmutableList.copyOf(tree.getArguments()), @@ -63,7 +55,7 @@ static InvocationInfo createFromMethodInvocation( static InvocationInfo createFromNewClass( NewClassTree tree, MethodSymbol symbol, VisitorState state) { - return new AutoValue_InvocationInfo( + return new InvocationInfo( tree, symbol, ImmutableList.copyOf(tree.getArguments()), @@ -88,7 +80,7 @@ static InvocationInfo createFromNewClass( formals.add(constructor.getParameters().get(i)); } } - return new AutoValue_InvocationInfo(tree, constructor, actuals.build(), formals.build(), state); + return new InvocationInfo(tree, constructor, actuals.build(), formals.build(), state); } private static ImmutableList getFormalParametersWithoutVarArgs( diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/argumentselectiondefects/Parameter.java b/core/src/main/java/com/google/errorprone/bugpatterns/argumentselectiondefects/Parameter.java index acf2fcf4ae8..23a3329ff74 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/argumentselectiondefects/Parameter.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/argumentselectiondefects/Parameter.java @@ -18,7 +18,6 @@ import static com.google.common.collect.ImmutableList.toImmutableList; -import com.google.auto.value.AutoValue; import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; @@ -52,9 +51,7 @@ * * @author andrewrice@google.com (Andrew Rice) */ -@AutoValue -abstract class Parameter { - +record Parameter(String name, Type type, int index, String text, Kind kind, boolean constant) { private static final ImmutableSet METHODNAME_PREFIXES_TO_REMOVE = ImmutableSet.of("get", "set", "is"); @@ -64,23 +61,11 @@ abstract class Parameter { /** We use this placeholder to indicate a name which we couldn't get a canonical string for. */ @VisibleForTesting static final String NAME_NOT_PRESENT = "*NOT_PRESENT*"; - abstract String name(); - - abstract Type type(); - - abstract int index(); - - abstract String text(); - - abstract Kind kind(); - - abstract boolean constant(); - static ImmutableList createListFromVarSymbols(List varSymbols) { return Streams.mapWithIndex( varSymbols.stream(), (s, i) -> - new AutoValue_Parameter( + new Parameter( s.getSimpleName().toString(), s.asType(), (int) i, @@ -94,7 +79,7 @@ static ImmutableList createListFromExpressionTrees(List - new AutoValue_Parameter( + new Parameter( getArgumentName(t), Optional.ofNullable( t instanceof ExpressionTree expressionTree diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/checkreturnvalue/Api.java b/core/src/main/java/com/google/errorprone/bugpatterns/checkreturnvalue/Api.java index 8c9fc534980..7aec30f6d84 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/checkreturnvalue/Api.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/checkreturnvalue/Api.java @@ -20,7 +20,6 @@ import static java.lang.Character.isJavaIdentifierPart; import static java.lang.Character.isJavaIdentifierStart; -import com.google.auto.value.AutoValue; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Joiner; import com.google.common.collect.ImmutableList; @@ -30,26 +29,18 @@ * Represents a Java method or constructor. * *

Provides a method to parse an API from a string format, and emit an API as the same sting. + * + * @param className Returns the fully qualified type that contains the given method/constructor. + * @param methodName Returns the simple name of the method. If the API is a constructor (i.e., + * {@code isConstructor() == true}), then {@code ""} is returned. + * @param parameterTypes Returns the list of fully qualified parameter types for the given + * method/constructor. */ // TODO(kak): do we want to be able to represent classes in addition to methods/constructors? // TODO(kak): if not, then consider renaming to `MethodSignature` or something -@AutoValue -public abstract class Api { - +public record Api(String className, String methodName, ImmutableList parameterTypes) { private static final Joiner COMMA_JOINER = Joiner.on(','); - /** Returns the fully qualified type that contains the given method/constructor. */ - public abstract String className(); - - /** - * Returns the simple name of the method. If the API is a constructor (i.e., {@code - * isConstructor() == true}), then {@code ""} is returned. - */ - public abstract String methodName(); - - /** Returns the list of fully qualified parameter types for the given method/constructor. */ - public abstract ImmutableList parameterTypes(); - @Override public final String toString() { return String.format( @@ -98,7 +89,7 @@ static Api parseFromStringWithoutWhitespace(String api) { } static Api internalCreate(String className, String methodName, ImmutableList params) { - return new AutoValue_Api(className, methodName, params); + return new Api(className, methodName, params); } /** diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/checkreturnvalue/ResultUseRule.java b/core/src/main/java/com/google/errorprone/bugpatterns/checkreturnvalue/ResultUseRule.java index 744a0758ece..b5751192f31 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/checkreturnvalue/ResultUseRule.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/checkreturnvalue/ResultUseRule.java @@ -20,7 +20,6 @@ import static com.google.errorprone.bugpatterns.checkreturnvalue.ResultUseRule.RuleScope.GLOBAL; import static com.google.errorprone.bugpatterns.checkreturnvalue.ResultUseRule.RuleScope.METHOD; -import com.google.auto.value.AutoValue; import com.google.common.collect.ImmutableSet; import java.util.Optional; @@ -142,25 +141,17 @@ public enum RuleScope { * An evaluation that a rule makes. * * @param the type of symbols + * @param rule The rule that made this evaluation. + * @param scope The scope at which the evaluation was made. + * @param element The specific element in the scope for which the evaluation was made. + * @param policy The policy the rule selected. */ - @AutoValue - public abstract static class Evaluation { + public record Evaluation( + ResultUseRule rule, RuleScope scope, S element, ResultUsePolicy policy) { /** Creates a new {@link Evaluation}. */ public static Evaluation create( ResultUseRule rule, RuleScope scope, S element, ResultUsePolicy policy) { - return new AutoValue_ResultUseRule_Evaluation<>(rule, scope, element, policy); + return new Evaluation<>(rule, scope, element, policy); } - - /** The rule that made this evaluation. */ - public abstract ResultUseRule rule(); - - /** The scope at which the evaluation was made. */ - public abstract RuleScope scope(); - - /** The specific element in the scope for which the evaluation was made. */ - public abstract S element(); - - /** The policy the rule selected. */ - public abstract ResultUsePolicy policy(); } } diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/collectionincompatibletype/AbstractCollectionIncompatibleTypeMatcher.java b/core/src/main/java/com/google/errorprone/bugpatterns/collectionincompatibletype/AbstractCollectionIncompatibleTypeMatcher.java index 637756e9d66..cc96e734241 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/collectionincompatibletype/AbstractCollectionIncompatibleTypeMatcher.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/collectionincompatibletype/AbstractCollectionIncompatibleTypeMatcher.java @@ -16,7 +16,6 @@ package com.google.errorprone.bugpatterns.collectionincompatibletype; -import com.google.auto.value.AutoValue; import com.google.errorprone.VisitorState; import com.google.errorprone.fixes.Fix; import com.google.errorprone.matchers.Matcher; @@ -100,23 +99,17 @@ public abstract class AbstractCollectionIncompatibleTypeMatcher { * Encapsulates the result of matching a {@link Collection#contains}-like call, including the * source and target types. */ - @AutoValue - public abstract static class MatchResult { - public abstract ExpressionTree sourceTree(); - - public abstract Type sourceType(); - - public abstract Type targetType(); - - public abstract AbstractCollectionIncompatibleTypeMatcher matcher(); - + public record MatchResult( + ExpressionTree sourceTree, + Type sourceType, + Type targetType, + AbstractCollectionIncompatibleTypeMatcher matcher) { public static MatchResult create( ExpressionTree sourceTree, Type sourceType, Type targetType, AbstractCollectionIncompatibleTypeMatcher matcher) { - return new AutoValue_AbstractCollectionIncompatibleTypeMatcher_MatchResult( - sourceTree, sourceType, targetType, matcher); + return new MatchResult(sourceTree, sourceType, targetType, matcher); } public String message(String sourceType, String targetType) { diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/formatstring/FormatStringValidation.java b/core/src/main/java/com/google/errorprone/bugpatterns/formatstring/FormatStringValidation.java index f3476a1478a..d606a2ed74f 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/formatstring/FormatStringValidation.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/formatstring/FormatStringValidation.java @@ -20,7 +20,6 @@ import static com.google.errorprone.util.ASTHelpers.isSameType; import static java.util.Arrays.asList; -import com.google.auto.value.AutoValue; import com.google.common.base.Preconditions; import com.google.common.collect.Iterables; import com.google.errorprone.VisitorState; @@ -66,14 +65,14 @@ /** Utilities for validating format strings. */ public final class FormatStringValidation { - /** Description of an incorrect format method call. */ - @AutoValue - public abstract static class ValidationResult { - /** A human-readable diagnostic message. */ - public abstract String message(); - + /** + * Description of an incorrect format method call. + * + * @param message A human-readable diagnostic message. + */ + public record ValidationResult(String message) { public static ValidationResult create(String message) { - return new AutoValue_FormatStringValidation_ValidationResult(message); + return new ValidationResult(message); } } diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/inlineme/InlinabilityResult.java b/core/src/main/java/com/google/errorprone/bugpatterns/inlineme/InlinabilityResult.java index ea97d68a677..928d86b7a27 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/inlineme/InlinabilityResult.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/inlineme/InlinabilityResult.java @@ -23,7 +23,6 @@ import static com.google.errorprone.util.ASTHelpers.isSuper; import static com.google.errorprone.util.ASTHelpers.methodCanBeOverridden; -import com.google.auto.value.AutoValue; import com.google.common.collect.ImmutableSet; import com.google.errorprone.VisitorState; import com.google.errorprone.util.ASTHelpers; @@ -55,14 +54,10 @@ import org.jspecify.annotations.Nullable; /** Whether an API can have {@code @InlineMe} applied to it or not. */ -@AutoValue -abstract class InlinabilityResult { - - abstract @Nullable InlineValidationErrorReason error(); - - abstract @Nullable ExpressionTree body(); - - abstract @Nullable String additionalErrorInfo(); +record InlinabilityResult( + @Nullable InlineValidationErrorReason error, + @Nullable ExpressionTree body, + @Nullable String additionalErrorInfo) { final String errorMessage() { checkState(error() != null); @@ -84,11 +79,11 @@ static InlinabilityResult fromError( static InlinabilityResult fromError( InlineValidationErrorReason errorReason, ExpressionTree body, String additionalErrorInfo) { - return new AutoValue_InlinabilityResult(errorReason, body, additionalErrorInfo); + return new InlinabilityResult(errorReason, body, additionalErrorInfo); } static InlinabilityResult inlinable(ExpressionTree body) { - return new AutoValue_InlinabilityResult(null, body, null); + return new InlinabilityResult(null, body, null); } boolean isValidForSuggester() { diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/nullness/NullnessUtils.java b/core/src/main/java/com/google/errorprone/bugpatterns/nullness/NullnessUtils.java index b805af14169..6f9ba7285cc 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/nullness/NullnessUtils.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/nullness/NullnessUtils.java @@ -38,7 +38,6 @@ import static java.lang.Boolean.TRUE; import static java.util.Objects.requireNonNull; -import com.google.auto.value.AutoValue; import com.google.common.collect.ImmutableSet; import com.google.errorprone.ErrorProneFlags; import com.google.errorprone.VisitorState; @@ -270,10 +269,10 @@ static boolean hasExtraParameterForEnclosingInstance(MethodSymbol symbol) { return enclosingClass(constructedClass) != null && !constructedClass.isStatic(); } - @AutoValue - abstract static class NullableAnnotationToUse { + record NullableAnnotationToUse( + @Nullable String importToAdd, String use, boolean isTypeUse, boolean isAlreadyInScope) { static NullableAnnotationToUse annotationToBeImported(String qualifiedName, boolean isTypeUse) { - return new AutoValue_NullnessUtils_NullableAnnotationToUse( + return new NullableAnnotationToUse( qualifiedName, qualifiedName.replaceFirst(".*[.]", ""), isTypeUse, @@ -282,8 +281,7 @@ static NullableAnnotationToUse annotationToBeImported(String qualifiedName, bool static NullableAnnotationToUse annotationWithoutImporting( String name, boolean isTypeUse, boolean isAlreadyInScope) { - return new AutoValue_NullnessUtils_NullableAnnotationToUse( - null, name, isTypeUse, isAlreadyInScope); + return new NullableAnnotationToUse(null, name, isTypeUse, isAlreadyInScope); } /** @@ -312,14 +310,6 @@ final SuggestedFix fixPrefixingOnto( return prepareBuilder(state, suppressionToRemove).prefixWith(tree, "@" + use() + " ").build(); } - abstract @Nullable String importToAdd(); - - abstract String use(); - - abstract boolean isTypeUse(); - - abstract boolean isAlreadyInScope(); - private SuggestedFix.Builder prepareBuilder( VisitorState state, @Nullable String suppressionToRemove) { SuggestedFix.Builder builder = SuggestedFix.builder(); diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/overloading/ParameterTree.java b/core/src/main/java/com/google/errorprone/bugpatterns/overloading/ParameterTree.java index 23e37bde8ad..d5207d208a0 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/overloading/ParameterTree.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/overloading/ParameterTree.java @@ -16,7 +16,6 @@ package com.google.errorprone.bugpatterns.overloading; -import com.google.auto.value.AutoValue; import com.google.common.base.Preconditions; import com.google.errorprone.util.ASTHelpers; import com.sun.source.tree.Tree; @@ -42,14 +41,7 @@ * * @author hanuszczak@google.com (Ɓukasz Hanuszczak) */ -@AutoValue -abstract class ParameterTree { - - public abstract Name getName(); - - public abstract Tree getType(); - - public abstract boolean isVarArgs(); +record ParameterTree(Name name, Tree type, boolean varArgs) { public static ParameterTree create(VariableTree variableTree) { Preconditions.checkArgument(isValidParameterTree(variableTree)); @@ -57,7 +49,7 @@ public static ParameterTree create(VariableTree variableTree) { Name name = variableTree.getName(); Tree type = variableTree.getType(); boolean isVarargs = isVariableTreeVarArgs(variableTree); - return new AutoValue_ParameterTree(name, type, isVarargs); + return new ParameterTree(name, type, isVarargs); } private static boolean isValidParameterTree(VariableTree variableTree) { @@ -73,11 +65,11 @@ private static boolean isValidParameterTree(VariableTree variableTree) { @Override public final String toString() { - String type = getType().toString(); - String name = getName().toString(); + String type = this.type().toString(); + String name = this.name().toString(); // Hacky fix to improve pretty-printing of varargs (otherwise they are printed as Type[]). - if (isVarArgs()) { + if (this.varArgs()) { type = type.substring(0, type.length() - 2) + "..."; } diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/overloading/ParameterTrie.java b/core/src/main/java/com/google/errorprone/bugpatterns/overloading/ParameterTrie.java index 83e0a107eb1..7697291827f 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/overloading/ParameterTrie.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/overloading/ParameterTrie.java @@ -133,7 +133,7 @@ private void walk(ParameterTrie trie) { Preconditions.checkArgument(trie != null); for (Parameter parameter : inputParameters) { - if (parameter.tree().isVarArgs() || !trie.children.containsKey(parameter.name())) { + if (parameter.tree().varArgs() || !trie.children.containsKey(parameter.name())) { continue; } @@ -170,7 +170,7 @@ private void expand(ParameterTrie trie) { outputParameters.add(parameter); ParameterTrie allocatedTrie = new ParameterTrie(); - if (!parameter.tree().isVarArgs()) { + if (!parameter.tree().varArgs()) { trie.children.put(parameter.name(), allocatedTrie); } expand(allocatedTrie); @@ -227,7 +227,7 @@ private ParameterTree getParameterTree(int position) { */ private record Parameter(ParameterTree tree, int position) { Name name() { - return tree().getName(); + return this.tree().name(); } static Parameter create(MethodTree methodTree, int position) { diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/threadsafety/GuardedByUtils.java b/core/src/main/java/com/google/errorprone/bugpatterns/threadsafety/GuardedByUtils.java index cb59bc9456a..a1a089875a1 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/threadsafety/GuardedByUtils.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/threadsafety/GuardedByUtils.java @@ -20,7 +20,6 @@ import static com.google.errorprone.util.ASTHelpers.getSymbol; import static com.google.errorprone.util.ASTHelpers.isStatic; -import com.google.auto.value.AutoValue; import com.google.common.collect.ImmutableSet; import com.google.errorprone.VisitorState; import com.google.errorprone.bugpatterns.threadsafety.GuardedByExpression.Select; @@ -94,18 +93,13 @@ static JCTree.JCExpression parseString(String guardedByString, Context context) return exp; } - @AutoValue - abstract static class GuardedByValidationResult { - abstract String message(); - - abstract boolean isValid(); - + record GuardedByValidationResult(String message, boolean isValid) { static GuardedByValidationResult invalid(String message) { - return new AutoValue_GuardedByUtils_GuardedByValidationResult(message, false); + return new GuardedByValidationResult(message, false); } static GuardedByValidationResult ok() { - return new AutoValue_GuardedByUtils_GuardedByValidationResult("", true); + return new GuardedByValidationResult("", true); } } diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/threadsafety/ThreadSafety.java b/core/src/main/java/com/google/errorprone/bugpatterns/threadsafety/ThreadSafety.java index bbeb8a08716..0f62569aa04 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/threadsafety/ThreadSafety.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/threadsafety/ThreadSafety.java @@ -21,7 +21,6 @@ import static com.google.errorprone.util.ASTHelpers.isStatic; import com.google.auto.value.AutoBuilder; -import com.google.auto.value.AutoValue; import com.google.common.base.Joiner; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableListMultimap; @@ -232,12 +231,13 @@ String mutableOrNotThreadSafe() { * *

An absent explanation indicates either an annotated type with no violations, or a type * without the annotation. + * + * @param path The list of steps in the explanation. + *

Example: ["Foo has field 'xs' of type 'int[]'", "arrays are not thread-safe"] */ - @AutoValue - public abstract static class Violation { - + public record Violation(ConsPStack path) { public static Violation create(ConsPStack path) { - return new AutoValue_ThreadSafety_Violation(path); + return new Violation(path); } /** Returns true if a violation was found. */ @@ -250,13 +250,6 @@ public String message() { return Joiner.on(", ").join(path()); } - /** - * The list of steps in the explanation. - * - *

Example: ["Foo has field 'xs' of type 'int[]'", "arrays are not thread-safe"] - */ - public abstract ConsPStack path(); - /** Adds a step. */ public Violation plus(String edge) { return create(path().plus(edge)); diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/time/InvalidJavaTimeConstant.java b/core/src/main/java/com/google/errorprone/bugpatterns/time/InvalidJavaTimeConstant.java index 72b3a551c78..5cd4924a057 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/time/InvalidJavaTimeConstant.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/time/InvalidJavaTimeConstant.java @@ -35,7 +35,7 @@ import static java.time.temporal.ChronoField.YEAR; import static java.util.Arrays.stream; -import com.google.auto.value.AutoValue; +import com.google.auto.value.AutoBuilder; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; @@ -68,43 +68,28 @@ public final class InvalidJavaTimeConstant extends BugChecker implements MethodInvocationTreeMatcher { - @AutoValue - abstract static class MatcherWithUnits { - abstract Matcher matcher(); + record MatcherWithUnits(Matcher matcher, ImmutableList units) {} - abstract ImmutableList units(); - } - - @AutoValue - abstract static class Param { - abstract String type(); - - abstract ChronoField unit(); - } + record Param(String type, ChronoField unit) {} private static Param intP(ChronoField unit) { - return new AutoValue_InvalidJavaTimeConstant_Param("int", unit); + return new Param("int", unit); } private static Param longP(ChronoField unit) { - return new AutoValue_InvalidJavaTimeConstant_Param("long", unit); + return new Param("long", unit); } private static Param monthP(ChronoField unit) { - return new AutoValue_InvalidJavaTimeConstant_Param("java.time.Month", unit); + return new Param("java.time.Month", unit); } - @AutoValue - abstract static class JavaTimeType { - abstract String className(); - - abstract ImmutableList methods(); - + record JavaTimeType(String className, ImmutableList methods) { public static Builder builder() { - return new AutoValue_InvalidJavaTimeConstant_JavaTimeType.Builder(); + return new AutoBuilder_InvalidJavaTimeConstant_JavaTimeType_Builder(); } - @AutoValue.Builder + @AutoBuilder public abstract static class Builder { public abstract Builder setClassName(String className); @@ -116,7 +101,7 @@ public abstract static class Builder { public Builder addStaticMethod(String methodName, Param... params) { methodsBuilder() .add( - new AutoValue_InvalidJavaTimeConstant_MatcherWithUnits( + new MatcherWithUnits( staticMethod() .onClass(className()) .named(methodName) @@ -129,7 +114,7 @@ public Builder addStaticMethod(String methodName, Param... params) { public Builder addInstanceMethod(String methodName, Param... params) { methodsBuilder() .add( - new AutoValue_InvalidJavaTimeConstant_MatcherWithUnits( + new MatcherWithUnits( instanceMethod() .onExactClass(className()) .named(methodName) diff --git a/core/src/main/java/com/google/errorprone/refaster/LocalVarBinding.java b/core/src/main/java/com/google/errorprone/refaster/LocalVarBinding.java index 2c280699a9a..b082f3a2c7a 100644 --- a/core/src/main/java/com/google/errorprone/refaster/LocalVarBinding.java +++ b/core/src/main/java/com/google/errorprone/refaster/LocalVarBinding.java @@ -16,7 +16,6 @@ package com.google.errorprone.refaster; -import com.google.auto.value.AutoValue; import com.sun.source.tree.ModifiersTree; import com.sun.tools.javac.code.Symbol.VarSymbol; import com.sun.tools.javac.util.Name; @@ -26,22 +25,17 @@ * * @author lowasser@google.com (Louis Wasserman) */ -@AutoValue -public abstract class LocalVarBinding { +public record LocalVarBinding(VarSymbol symbol, ModifiersTree modifiers) { public static LocalVarBinding create(VarSymbol symbol, ModifiersTree modifiers) { - return new AutoValue_LocalVarBinding(symbol, modifiers); + return new LocalVarBinding(symbol, modifiers); } - public abstract VarSymbol getSymbol(); - - public abstract ModifiersTree getModifiers(); - public Name getName() { - return getSymbol().getSimpleName(); + return this.symbol().getSimpleName(); } @Override public final String toString() { - return getSymbol().getSimpleName().toString(); + return this.symbol().getSimpleName().toString(); } } diff --git a/core/src/main/java/com/google/errorprone/refaster/PlaceholderMethod.java b/core/src/main/java/com/google/errorprone/refaster/PlaceholderMethod.java index 520e6137295..a3590cc7817 100644 --- a/core/src/main/java/com/google/errorprone/refaster/PlaceholderMethod.java +++ b/core/src/main/java/com/google/errorprone/refaster/PlaceholderMethod.java @@ -14,7 +14,6 @@ package com.google.errorprone.refaster; -import com.google.auto.value.AutoValue; import com.google.common.base.Predicates; import com.google.common.collect.ClassToInstanceMap; import com.google.common.collect.ImmutableClassToInstanceMap; @@ -47,8 +46,13 @@ * * @author lowasser@google.com (Louis Wasserman) */ -@AutoValue -abstract class PlaceholderMethod implements Serializable { +record PlaceholderMethod( + StringName name, + UType returnType, + ImmutableMap> annotatedParameters, + Matcher matcher, + ImmutableClassToInstanceMap annotations) + implements Serializable { static PlaceholderMethod create( CharSequence name, UType returnType, @@ -81,7 +85,7 @@ public boolean matches(ExpressionTree t, VisitorState state) { } } } - return new AutoValue_PlaceholderMethod( + return new PlaceholderMethod( StringName.of(name), returnType, parameters, @@ -89,17 +93,6 @@ public boolean matches(ExpressionTree t, VisitorState state) { ImmutableClassToInstanceMap.copyOf(annotations)); } - abstract StringName name(); - - abstract UType returnType(); - - abstract ImmutableMap> - annotatedParameters(); - - abstract Matcher matcher(); - - abstract ImmutableClassToInstanceMap annotations(); - ImmutableSet parameters() { return annotatedParameters().keySet(); } diff --git a/core/src/main/java/com/google/errorprone/refaster/PlaceholderUnificationVisitor.java b/core/src/main/java/com/google/errorprone/refaster/PlaceholderUnificationVisitor.java index d135f93d82f..baa422dc553 100644 --- a/core/src/main/java/com/google/errorprone/refaster/PlaceholderUnificationVisitor.java +++ b/core/src/main/java/com/google/errorprone/refaster/PlaceholderUnificationVisitor.java @@ -235,7 +235,7 @@ protected Boolean defaultAction(Tree node, Unifier unifier) { public Boolean visitIdentifier(IdentifierTree node, Unifier unifier) { for (LocalVarBinding localBinding : Iterables.filter(unifier.getBindings().values(), LocalVarBinding.class)) { - if (localBinding.getSymbol().equals(ASTHelpers.getSymbol(node))) { + if (localBinding.symbol().equals(ASTHelpers.getSymbol(node))) { return true; } } diff --git a/core/src/main/java/com/google/errorprone/refaster/PlaceholderVerificationVisitor.java b/core/src/main/java/com/google/errorprone/refaster/PlaceholderVerificationVisitor.java index c3699d3c38f..9251aec7148 100644 --- a/core/src/main/java/com/google/errorprone/refaster/PlaceholderVerificationVisitor.java +++ b/core/src/main/java/com/google/errorprone/refaster/PlaceholderVerificationVisitor.java @@ -91,7 +91,7 @@ public Boolean scan(Tree node, Unifier unifier) { public Boolean visitIdentifier(IdentifierTree node, Unifier unifier) { for (LocalVarBinding localBinding : Iterables.filter(unifier.getBindings().values(), LocalVarBinding.class)) { - if (localBinding.getSymbol().equals(ASTHelpers.getSymbol(node))) { + if (localBinding.symbol().equals(ASTHelpers.getSymbol(node))) { return false; } } diff --git a/core/src/main/java/com/google/errorprone/refaster/UBlank.java b/core/src/main/java/com/google/errorprone/refaster/UBlank.java index 9c2d79c6392..9fbd6291b6a 100644 --- a/core/src/main/java/com/google/errorprone/refaster/UBlank.java +++ b/core/src/main/java/com/google/errorprone/refaster/UBlank.java @@ -18,7 +18,6 @@ import static com.google.common.base.MoreObjects.firstNonNull; -import com.google.auto.value.AutoValue; import com.google.common.collect.ContiguousSet; import com.google.common.collect.DiscreteDomain; import com.google.common.collect.ImmutableList; @@ -34,14 +33,11 @@ import java.util.UUID; /** Equivalent to a no-arg block placeholder invocation. */ -@AutoValue -abstract class UBlank implements UStatement { +record UBlank(UUID unique) implements UStatement { static UBlank create() { - return new AutoValue_UBlank(UUID.randomUUID()); + return new UBlank(UUID.randomUUID()); } - abstract UUID unique(); - Key key() { return new Key(unique()); } diff --git a/core/src/main/java/com/google/errorprone/refaster/UFreeIdent.java b/core/src/main/java/com/google/errorprone/refaster/UFreeIdent.java index 6e91400853d..d6c2dd4e48b 100644 --- a/core/src/main/java/com/google/errorprone/refaster/UFreeIdent.java +++ b/core/src/main/java/com/google/errorprone/refaster/UFreeIdent.java @@ -88,7 +88,7 @@ public Boolean visitIdentifier(IdentifierTree ident, Void v) { Symbol identSym = ASTHelpers.getSymbol(ident); for (ULocalVarIdent.Key key : Iterables.filter(unifier.getBindings().keySet(), ULocalVarIdent.Key.class)) { - if (identSym == unifier.getBinding(key).getSymbol()) { + if (identSym == unifier.getBinding(key).symbol()) { return false; } } diff --git a/core/src/main/java/com/google/errorprone/refaster/UIf.java b/core/src/main/java/com/google/errorprone/refaster/UIf.java index 5e91e76951c..5745118ec32 100644 --- a/core/src/main/java/com/google/errorprone/refaster/UIf.java +++ b/core/src/main/java/com/google/errorprone/refaster/UIf.java @@ -16,7 +16,6 @@ package com.google.errorprone.refaster; -import com.google.auto.value.AutoValue; import com.google.common.base.Function; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; @@ -34,21 +33,27 @@ * * @author lowasser@google.com (Louis Wasserman) */ -@AutoValue -abstract class UIf implements UStatement, IfTree { - public static UIf create( - UExpression condition, UStatement thenStatement, UStatement elseStatement) { - return new AutoValue_UIf(condition, thenStatement, elseStatement); +record UIf(UExpression condition, UStatement thenStatement, @Nullable UStatement elseStatement) + implements UStatement, IfTree { + @Override + public UExpression getCondition() { + return condition(); } @Override - public abstract UExpression getCondition(); + public UStatement getThenStatement() { + return thenStatement(); + } @Override - public abstract UStatement getThenStatement(); + public @Nullable UStatement getElseStatement() { + return elseStatement(); + } - @Override - public abstract @Nullable UStatement getElseStatement(); + public static UIf create( + UExpression condition, UStatement thenStatement, UStatement elseStatement) { + return new UIf(condition, thenStatement, elseStatement); + } @Override public R accept(TreeVisitor visitor, D data) { diff --git a/core/src/main/java/com/google/errorprone/refaster/ULocalVarIdent.java b/core/src/main/java/com/google/errorprone/refaster/ULocalVarIdent.java index f4ae4a8e4f7..275f8beced4 100644 --- a/core/src/main/java/com/google/errorprone/refaster/ULocalVarIdent.java +++ b/core/src/main/java/com/google/errorprone/refaster/ULocalVarIdent.java @@ -52,8 +52,7 @@ private Key key() { public Choice visitIdentifier(IdentifierTree ident, Unifier unifier) { LocalVarBinding binding = unifier.getBinding(key()); return Choice.condition( - binding != null && Objects.equals(ASTHelpers.getSymbol(ident), binding.getSymbol()), - unifier); + binding != null && Objects.equals(ASTHelpers.getSymbol(ident), binding.symbol()), unifier); } @Override diff --git a/core/src/main/java/com/google/errorprone/refaster/UPlaceholderStatement.java b/core/src/main/java/com/google/errorprone/refaster/UPlaceholderStatement.java index 75fda6aecc8..c5ec4354556 100644 --- a/core/src/main/java/com/google/errorprone/refaster/UPlaceholderStatement.java +++ b/core/src/main/java/com/google/errorprone/refaster/UPlaceholderStatement.java @@ -16,7 +16,6 @@ package com.google.errorprone.refaster; -import com.google.auto.value.AutoValue; import com.google.common.base.Functions; import com.google.common.base.MoreObjects; import com.google.common.collect.Collections2; @@ -38,8 +37,12 @@ * * @author lowasser@google.com (Louis Wasserman) */ -@AutoValue -abstract class UPlaceholderStatement implements UStatement { +record UPlaceholderStatement( + PlaceholderMethod placeholder, + ImmutableMap arguments, + ControlFlowVisitor.Result implementationFlow) + implements UStatement { + static UPlaceholderStatement create( PlaceholderMethod placeholder, Iterable arguments, @@ -50,16 +53,9 @@ static UPlaceholderStatement create( for (int i = 0; i < placeholderParams.size(); i++) { builder.put(placeholderParams.get(i), argumentsList.get(i)); } - return new AutoValue_UPlaceholderStatement( - placeholder, builder.buildOrThrow(), implementationFlow); + return new UPlaceholderStatement(placeholder, builder.buildOrThrow(), implementationFlow); } - abstract PlaceholderMethod placeholder(); - - abstract ImmutableMap arguments(); - - abstract ControlFlowVisitor.Result implementationFlow(); - @Override public Kind getKind() { return Kind.OTHER; @@ -70,18 +66,13 @@ public R accept(TreeVisitor visitor, D data) { return visitor.visitOther(this, data); } - @AutoValue - abstract static class ConsumptionState { + record ConsumptionState(int consumedStatements, List placeholderImplInReverseOrder) { static ConsumptionState empty() { - return new AutoValue_UPlaceholderStatement_ConsumptionState(0, List.nil()); + return new ConsumptionState(0, List.nil()); } - abstract int consumedStatements(); - - abstract List placeholderImplInReverseOrder(); - ConsumptionState consume(JCStatement impl) { - return new AutoValue_UPlaceholderStatement_ConsumptionState( + return new ConsumptionState( consumedStatements() + 1, placeholderImplInReverseOrder().prepend(impl)); } } diff --git a/core/src/main/java/com/google/errorprone/refaster/UStatement.java b/core/src/main/java/com/google/errorprone/refaster/UStatement.java index 8e056127660..b612f408d3f 100644 --- a/core/src/main/java/com/google/errorprone/refaster/UStatement.java +++ b/core/src/main/java/com/google/errorprone/refaster/UStatement.java @@ -14,7 +14,6 @@ package com.google.errorprone.refaster; -import com.google.auto.value.AutoValue; import com.google.common.base.Function; import com.google.common.collect.ImmutableList; import com.google.errorprone.refaster.UStatement.UnifierWithUnconsumedStatements; @@ -33,17 +32,13 @@ public interface UStatement StatementTree, Function> { /** Tuple of a Unifier and a list of statements that are still waiting to be matched. */ - @AutoValue - abstract class UnifierWithUnconsumedStatements { + public record UnifierWithUnconsumedStatements( + Unifier unifier, ImmutableList unconsumedStatements) { public static UnifierWithUnconsumedStatements create( Unifier unifier, List unconsumedStatements) { - return new AutoValue_UStatement_UnifierWithUnconsumedStatements( + return new UnifierWithUnconsumedStatements( unifier, ImmutableList.copyOf(unconsumedStatements)); } - - public abstract Unifier unifier(); - - public abstract ImmutableList unconsumedStatements(); } com.sun.tools.javac.util.List inlineStatements(Inliner inliner) diff --git a/core/src/main/java/com/google/errorprone/refaster/UVariableDecl.java b/core/src/main/java/com/google/errorprone/refaster/UVariableDecl.java index 6fe68d19770..991ca35d18e 100644 --- a/core/src/main/java/com/google/errorprone/refaster/UVariableDecl.java +++ b/core/src/main/java/com/google/errorprone/refaster/UVariableDecl.java @@ -102,7 +102,7 @@ private JCVariableDecl inline(@Nullable UExpression type, Inliner inliner) Name name; TreeMaker maker = inliner.maker(); if (binding.isPresent()) { - modifiers = (JCModifiers) binding.get().getModifiers(); + modifiers = (JCModifiers) binding.get().modifiers(); name = binding.get().getName(); } else { modifiers = maker.Modifiers(0L);