Skip to content

Commit 6db6f95

Browse files
graememorganError Prone Team
authored andcommitted
Do some AutoValue -> record migration.
I tried to clean up the InlineMes left behind, but do point out anything I missed. PiperOrigin-RevId: 834213609
1 parent 13a7a12 commit 6db6f95

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+379
-748
lines changed

check_api/src/main/java/com/google/errorprone/CompositeCodeTransformer.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package com.google.errorprone;
1818

19-
import com.google.auto.value.AutoValue;
2019
import com.google.common.collect.ImmutableClassToInstanceMap;
2120
import com.google.common.collect.ImmutableList;
2221
import com.sun.source.util.TreePath;
@@ -25,20 +24,16 @@
2524
import java.lang.annotation.Annotation;
2625

2726
/** Combines multiple {@code CodeTransformer}s into one. */
28-
@AutoValue
29-
public abstract class CompositeCodeTransformer implements CodeTransformer, Serializable {
27+
public record CompositeCodeTransformer(ImmutableList<CodeTransformer> transformers)
28+
implements CodeTransformer, Serializable {
3029
public static CodeTransformer compose(CodeTransformer... transformers) {
3130
return compose(ImmutableList.copyOf(transformers));
3231
}
3332

3433
public static CodeTransformer compose(Iterable<? extends CodeTransformer> transformers) {
35-
return new AutoValue_CompositeCodeTransformer(ImmutableList.copyOf(transformers));
34+
return new CompositeCodeTransformer(ImmutableList.copyOf(transformers));
3635
}
3736

38-
CompositeCodeTransformer() {}
39-
40-
public abstract ImmutableList<CodeTransformer> transformers();
41-
4237
@Override
4338
public void apply(TreePath path, Context context, DescriptionListener listener) {
4439
for (CodeTransformer transformer : transformers()) {

check_api/src/main/java/com/google/errorprone/ErrorProneOptions.java

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package com.google.errorprone;
1818

19-
import com.google.auto.value.AutoValue;
19+
import com.google.auto.value.AutoBuilder;
2020
import com.google.common.base.Optional;
2121
import com.google.common.base.Preconditions;
2222
import com.google.common.base.Splitter;
@@ -103,31 +103,25 @@ public enum Severity {
103103
ERROR
104104
}
105105

106-
@AutoValue
107-
abstract static class PatchingOptions {
106+
record PatchingOptions(
107+
ImmutableSet<String> namedCheckers,
108+
boolean inPlace,
109+
String baseDirectory,
110+
Optional<Supplier<CodeTransformer>> customRefactorer,
111+
ImportOrganizer importOrganizer) {
108112
final boolean doRefactor() {
109113
return inPlace() || !baseDirectory().isEmpty();
110114
}
111115

112-
abstract ImmutableSet<String> namedCheckers();
113-
114-
abstract boolean inPlace();
115-
116-
abstract String baseDirectory();
117-
118-
abstract Optional<Supplier<CodeTransformer>> customRefactorer();
119-
120-
abstract ImportOrganizer importOrganizer();
121-
122116
static Builder builder() {
123-
return new AutoValue_ErrorProneOptions_PatchingOptions.Builder()
117+
return new AutoBuilder_ErrorProneOptions_PatchingOptions_Builder()
124118
.baseDirectory("")
125119
.inPlace(false)
126120
.namedCheckers(ImmutableSet.of())
127121
.importOrganizer(ImportOrganizer.STATIC_FIRST_ORGANIZER);
128122
}
129123

130-
@AutoValue.Builder
124+
@AutoBuilder
131125
abstract static class Builder {
132126

133127
abstract Builder namedCheckers(ImmutableSet<String> checkers);

check_api/src/main/java/com/google/errorprone/RefactoringCollection.java

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import static java.nio.file.StandardOpenOption.APPEND;
2121
import static java.nio.file.StandardOpenOption.CREATE;
2222

23-
import com.google.auto.value.AutoValue;
2423
import com.google.common.collect.HashMultimap;
2524
import com.google.common.collect.Iterables;
2625
import com.google.common.collect.SetMultimap;
@@ -62,16 +61,7 @@ public class RefactoringCollection implements DescriptionListener.Factory {
6261
private final DescriptionListener.Factory descriptionsFactory;
6362
private final ImportOrganizer importOrganizer;
6463

65-
@AutoValue
66-
abstract static class RefactoringResult {
67-
abstract String message();
68-
69-
abstract RefactoringResultType type();
70-
71-
private static RefactoringResult create(String message, RefactoringResultType type) {
72-
return new AutoValue_RefactoringCollection_RefactoringResult(message, type);
73-
}
74-
}
64+
record RefactoringResult(String message, RefactoringResultType type) {}
7565

7666
enum RefactoringResultType {
7767
NO_CHANGES,
@@ -86,13 +76,14 @@ static RefactoringCollection refactor(PatchingOptions patchingOptions, Context c
8676
if (patchingOptions.inPlace()) {
8777
fileDestination = new FsFileDestination(rootPath);
8878
postProcess =
89-
uri ->
90-
RefactoringResult.create(
91-
String.format(
92-
"Refactoring changes were successfully applied to %s,"
93-
+ " please check the refactored code and recompile.",
94-
uri),
95-
RefactoringResultType.CHANGED);
79+
uri -> {
80+
String message =
81+
String.format(
82+
"Refactoring changes were successfully applied to %s,"
83+
+ " please check the refactored code and recompile.",
84+
uri);
85+
return new RefactoringResult(message, RefactoringResultType.CHANGED);
86+
};
9687
} else {
9788
Path baseDir = rootPath.resolve(patchingOptions.baseDirectory());
9889
Path patchFilePath = baseDir.resolve("error-prone.patch");
@@ -106,7 +97,7 @@ static RefactoringCollection refactor(PatchingOptions patchingOptions, Context c
10697
public RefactoringResult apply(URI uri) {
10798
try {
10899
writePatchFile(first, uri, patchFileDestination, patchFilePath);
109-
return RefactoringResult.create(
100+
return new RefactoringResult(
110101
"Changes were written to "
111102
+ patchFilePath
112103
+ ". Please inspect the file and apply with: "
@@ -164,7 +155,7 @@ RefactoringResult applyChanges(URI uri) throws Exception {
164155
return postProcess.apply(uri);
165156
}
166157

167-
return RefactoringResult.create("", RefactoringResultType.NO_CHANGES);
158+
return new RefactoringResult("", RefactoringResultType.NO_CHANGES);
168159
}
169160

170161
private static void writePatchFile(

check_api/src/main/java/com/google/errorprone/dataflow/AccessPath.java

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package com.google.errorprone.dataflow;
1717

18-
import com.google.auto.value.AutoValue;
1918
import com.google.common.collect.ImmutableList;
2019
import com.google.errorprone.util.MoreAnnotations;
2120
import com.sun.source.tree.IdentifierTree;
@@ -55,19 +54,9 @@
5554
* local variable {@code x} is represented by {base = Some x, fields = "foo" :: "foo()" :: nil}
5655
*
5756
* @author [email protected] (Benno Stein)
57+
* @param base If present, base of access path is contained Element; if absent, base is `this`
5858
*/
59-
@AutoValue
60-
public abstract class AccessPath {
61-
62-
/** If present, base of access path is contained Element; if absent, base is `this` */
63-
public abstract @Nullable Element base();
64-
65-
public abstract ImmutableList<String> path();
66-
67-
private static AccessPath create(@Nullable Element base, ImmutableList<String> path) {
68-
return new AutoValue_AccessPath(base, path);
69-
}
70-
59+
public record AccessPath(@Nullable Element base, ImmutableList<String> path) {
7160
/**
7261
* Check whether {@code tree} is an AutoValue accessor. A tree is an AutoValue accessor iff:
7362
*
@@ -126,31 +115,31 @@ public static boolean isAutoValueAccessor(Tree tree) {
126115

127116
if (tree instanceof IdentifierTree) {
128117
// Implicit `this` receiver
129-
return AccessPath.create(/* base= */ null, pathBuilder.build());
118+
return new AccessPath(null, pathBuilder.build());
130119
}
131120

132121
tree = ((MemberSelectTree) tree).getExpression();
133122
}
134123

135124
// Explicit `this` receiver
136125
if (tree instanceof IdentifierTree id && id.getName().contentEquals("this")) {
137-
return AccessPath.create(/* base= */ null, pathBuilder.build());
126+
return new AccessPath(null, pathBuilder.build());
138127
}
139128

140129
// Local variable receiver
141130
if (tree instanceof IdentifierTree) {
142-
return AccessPath.create(TreeUtils.elementFromTree(tree), pathBuilder.build());
131+
return new AccessPath(TreeUtils.elementFromTree(tree), pathBuilder.build());
143132
}
144133

145134
return null;
146135
}
147136

148137
public static AccessPath fromLocalVariable(LocalVariableNode node) {
149-
return AccessPath.create(node.getElement(), ImmutableList.of());
138+
return new AccessPath(node.getElement(), ImmutableList.of());
150139
}
151140

152141
public static AccessPath fromVariableDecl(VariableDeclarationNode node) {
153-
return AccessPath.create(TreeUtils.elementFromDeclaration(node.getTree()), ImmutableList.of());
142+
return new AccessPath(TreeUtils.elementFromDeclaration(node.getTree()), ImmutableList.of());
154143
}
155144

156145
/**

check_api/src/main/java/com/google/errorprone/dataflow/AccessPathStore.java

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import static com.google.common.base.Preconditions.checkNotNull;
2020
import static com.google.common.collect.Sets.intersection;
2121

22-
import com.google.auto.value.AutoValue;
2322
import com.google.common.collect.ImmutableMap;
2423
import com.google.errorprone.annotations.CanIgnoreReturnValue;
2524
import java.util.LinkedHashMap;
@@ -38,20 +37,10 @@
3837
*
3938
* @author [email protected] (Benno Stein)
4039
*/
41-
@AutoValue
42-
public abstract class AccessPathStore<V extends AbstractValue<V>>
40+
public record AccessPathStore<V extends AbstractValue<V>>(ImmutableMap<AccessPath, V> heap)
4341
implements Store<AccessPathStore<V>>, AccessPathValues<V> {
44-
45-
public abstract ImmutableMap<AccessPath, V> heap();
46-
47-
private static <V extends AbstractValue<V>> AccessPathStore<V> create(
48-
ImmutableMap<AccessPath, V> heap) {
49-
return new AutoValue_AccessPathStore<>(heap);
50-
}
51-
5242
@SuppressWarnings({"unchecked", "rawtypes"}) // fully variant
53-
private static final AccessPathStore<?> EMPTY =
54-
AccessPathStore.<AbstractValue>create(ImmutableMap.of());
43+
private static final AccessPathStore<?> EMPTY = new AccessPathStore(ImmutableMap.of());
5544

5645
@SuppressWarnings("unchecked") // fully variant
5746
public static <V extends AbstractValue<V>> AccessPathStore<V> empty() {
@@ -84,7 +73,7 @@ public AccessPathStore<V> leastUpperBound(AccessPathStore<V> other) {
8473
for (AccessPath aPath : intersection(heap().keySet(), other.heap().keySet())) {
8574
resultHeap.put(aPath, heap().get(aPath).leastUpperBound(other.heap().get(aPath)));
8675
}
87-
return AccessPathStore.create(resultHeap.buildOrThrow());
76+
return new AccessPathStore<>(resultHeap.buildOrThrow());
8877
}
8978

9079
@Override
@@ -122,7 +111,7 @@ public Builder<V> setInformation(AccessPath aPath, V value) {
122111
}
123112

124113
public AccessPathStore<V> build() {
125-
return AccessPathStore.create(ImmutableMap.copyOf(heap));
114+
return new AccessPathStore<>(ImmutableMap.copyOf(heap));
126115
}
127116
}
128117
}

check_api/src/main/java/com/google/errorprone/fixes/Replacement.java

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@
1818

1919
import static com.google.common.base.Preconditions.checkArgument;
2020

21-
import com.google.auto.value.AutoValue;
2221
import com.google.common.collect.Range;
2322

24-
/** A replaced section of a source file. */
25-
@AutoValue
26-
public abstract class Replacement {
27-
23+
/**
24+
* A replaced section of a source file.
25+
*
26+
* @param range The {@link Range} to be replaced.
27+
* @param replaceWith The source text to appear in the output.
28+
*/
29+
public record Replacement(Range<Integer> range, String replaceWith) {
2830
/**
2931
* Creates a {@link Replacement}. Start and end positions are represented as code unit indices in
3032
* a Unicode 16-bit string.
@@ -40,7 +42,7 @@ public static Replacement create(int startPosition, int endPosition, String repl
4042
startPosition,
4143
endPosition,
4244
replaceWith);
43-
return new AutoValue_Replacement(Range.closedOpen(startPosition, endPosition), replaceWith);
45+
return new Replacement(Range.closedOpen(startPosition, endPosition), replaceWith);
4446
}
4547

4648
/** The beginning of the replacement range. */
@@ -58,14 +60,8 @@ public int endPosition() {
5860
return range().upperEndpoint();
5961
}
6062

61-
/** The {@link Range} to be replaced. */
62-
public abstract Range<Integer> range();
63-
64-
/** The source text to appear in the output. */
65-
public abstract String replaceWith();
66-
6763
/** Creates a new replacement at the same range with different text. */
6864
Replacement withDifferentText(String replaceWith) {
69-
return new AutoValue_Replacement(range(), replaceWith);
65+
return new Replacement(range(), replaceWith);
7066
}
7167
}

check_api/src/main/java/com/google/errorprone/fixes/SuggestedFixes.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import static java.util.Arrays.stream;
3535
import static java.util.stream.Collectors.joining;
3636

37-
import com.google.auto.value.AutoValue;
3837
import com.google.common.annotations.VisibleForTesting;
3938
import com.google.common.base.Joiner;
4039
import com.google.common.base.Objects;
@@ -1375,7 +1374,7 @@ public Result compile(ImmutableList<String> extraOptions) {
13751374
} catch (IOException e) {
13761375
throw new UncheckedIOException(e);
13771376
}
1378-
return Result.create(diagnosticListener.getDiagnostics());
1377+
return new Result(diagnosticListener.getDiagnostics());
13791378
}
13801379

13811380
private Context createContext() {
@@ -1448,14 +1447,7 @@ public CharSequence getCharContent(boolean ignoreEncodingErrors) {
14481447
}
14491448

14501449
/** The result of the compilation. */
1451-
@AutoValue
1452-
public abstract static class Result {
1453-
public abstract List<Diagnostic<? extends JavaFileObject>> diagnostics();
1454-
1455-
private static Result create(List<Diagnostic<? extends JavaFileObject>> diagnostics) {
1456-
return new AutoValue_SuggestedFixes_FixCompiler_Result(diagnostics);
1457-
}
1458-
}
1450+
public record Result(List<Diagnostic<? extends JavaFileObject>> diagnostics) {}
14591451
}
14601452

14611453
private static final ImmutableSet<String> SOURCE_TARGET_OPTIONS =

check_api/src/main/java/com/google/errorprone/matchers/MultiMatcher.java

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import static com.google.common.collect.Iterables.getOnlyElement;
2020

21-
import com.google.auto.value.AutoValue;
2221
import com.google.common.collect.ImmutableList;
2322
import com.google.errorprone.VisitorState;
2423
import com.sun.source.tree.Tree;
@@ -39,27 +38,19 @@ public interface MultiMatcher<T extends Tree, N extends Tree> extends Matcher<T>
3938
/**
4039
* A result from the call of {@link MultiMatcher#multiMatchResult(Tree, VisitorState)}, containing
4140
* information about whether it matched, and if so, what nodes matched.
41+
*
42+
* @param matches True if the MultiMatcher matched the nodes expected.
43+
* @param matchingNodes The list of nodes which matched the MultiMatcher's expectations (could be
44+
* empty if the match type was ALL and there were no child nodes). Only sensical if {@link
45+
* #matches()} is true.
4246
*/
43-
@AutoValue
44-
abstract class MultiMatchResult<N extends Tree> {
45-
MultiMatchResult() {}
46-
47-
/** True if the MultiMatcher matched the nodes expected. */
48-
public abstract boolean matches();
49-
50-
/**
51-
* The list of nodes which matched the MultiMatcher's expectations (could be empty if the match
52-
* type was ALL and there were no child nodes). Only sensical if {@link #matches()} is true.
53-
*/
54-
public abstract ImmutableList<N> matchingNodes();
55-
47+
public record MultiMatchResult<N extends Tree>(boolean matches, ImmutableList<N> matchingNodes) {
5648
public final N onlyMatchingNode() {
5749
return getOnlyElement(matchingNodes());
5850
}
5951

6052
static <N extends Tree> MultiMatchResult<N> create(boolean matches, List<N> matchingNodes) {
61-
return new AutoValue_MultiMatcher_MultiMatchResult<>(
62-
matches, ImmutableList.copyOf(matchingNodes));
53+
return new MultiMatchResult<>(matches, ImmutableList.copyOf(matchingNodes));
6354
}
6455
}
6556
}

0 commit comments

Comments
 (0)