Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<CodeTransformer> transformers)
implements CodeTransformer, Serializable {
public static CodeTransformer compose(CodeTransformer... transformers) {
return compose(ImmutableList.copyOf(transformers));
}

public static CodeTransformer compose(Iterable<? extends CodeTransformer> transformers) {
return new AutoValue_CompositeCodeTransformer(ImmutableList.copyOf(transformers));
return new CompositeCodeTransformer(ImmutableList.copyOf(transformers));
}

CompositeCodeTransformer() {}

public abstract ImmutableList<CodeTransformer> transformers();

@Override
public void apply(TreePath path, Context context, DescriptionListener listener) {
for (CodeTransformer transformer : transformers()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -103,31 +103,25 @@ public enum Severity {
ERROR
}

@AutoValue
abstract static class PatchingOptions {
record PatchingOptions(
ImmutableSet<String> namedCheckers,
boolean inPlace,
String baseDirectory,
Optional<Supplier<CodeTransformer>> customRefactorer,
ImportOrganizer importOrganizer) {
final boolean doRefactor() {
return inPlace() || !baseDirectory().isEmpty();
}

abstract ImmutableSet<String> namedCheckers();

abstract boolean inPlace();

abstract String baseDirectory();

abstract Optional<Supplier<CodeTransformer>> 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<String> checkers);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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");
Expand All @@ -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: "
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -55,19 +54,9 @@
* local variable {@code x} is represented by {base = Some x, fields = "foo" :: "foo()" :: nil}
*
* @author [email protected] (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<String> path();

private static AccessPath create(@Nullable Element base, ImmutableList<String> path) {
return new AutoValue_AccessPath(base, path);
}

public record AccessPath(@Nullable Element base, ImmutableList<String> path) {
/**
* Check whether {@code tree} is an AutoValue accessor. A tree is an AutoValue accessor iff:
*
Expand Down Expand Up @@ -126,31 +115,31 @@ 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();
}

// 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());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -38,20 +37,10 @@
*
* @author [email protected] (Benno Stein)
*/
@AutoValue
public abstract class AccessPathStore<V extends AbstractValue<V>>
public record AccessPathStore<V extends AbstractValue<V>>(ImmutableMap<AccessPath, V> heap)
implements Store<AccessPathStore<V>>, AccessPathValues<V> {

public abstract ImmutableMap<AccessPath, V> heap();

private static <V extends AbstractValue<V>> AccessPathStore<V> create(
ImmutableMap<AccessPath, V> heap) {
return new AutoValue_AccessPathStore<>(heap);
}

@SuppressWarnings({"unchecked", "rawtypes"}) // fully variant
private static final AccessPathStore<?> EMPTY =
AccessPathStore.<AbstractValue>create(ImmutableMap.of());
private static final AccessPathStore<?> EMPTY = new AccessPathStore(ImmutableMap.of());

@SuppressWarnings("unchecked") // fully variant
public static <V extends AbstractValue<V>> AccessPathStore<V> empty() {
Expand Down Expand Up @@ -84,7 +73,7 @@ public AccessPathStore<V> leastUpperBound(AccessPathStore<V> 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
Expand Down Expand Up @@ -122,7 +111,7 @@ public Builder<V> setInformation(AccessPath aPath, V value) {
}

public AccessPathStore<V> build() {
return AccessPathStore.create(ImmutableMap.copyOf(heap));
return new AccessPathStore<>(ImmutableMap.copyOf(heap));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Integer> range, String replaceWith) {
/**
* Creates a {@link Replacement}. Start and end positions are represented as code unit indices in
* a Unicode 16-bit string.
Expand All @@ -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. */
Expand All @@ -58,14 +60,8 @@ public int endPosition() {
return range().upperEndpoint();
}

/** The {@link Range} to be replaced. */
public abstract Range<Integer> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1375,7 +1374,7 @@ public Result compile(ImmutableList<String> extraOptions) {
} catch (IOException e) {
throw new UncheckedIOException(e);
}
return Result.create(diagnosticListener.getDiagnostics());
return new Result(diagnosticListener.getDiagnostics());
}

private Context createContext() {
Expand Down Expand Up @@ -1448,14 +1447,7 @@ public CharSequence getCharContent(boolean ignoreEncodingErrors) {
}

/** The result of the compilation. */
@AutoValue
public abstract static class Result {
public abstract List<Diagnostic<? extends JavaFileObject>> diagnostics();

private static Result create(List<Diagnostic<? extends JavaFileObject>> diagnostics) {
return new AutoValue_SuggestedFixes_FixCompiler_Result(diagnostics);
}
}
public record Result(List<Diagnostic<? extends JavaFileObject>> diagnostics) {}
}

private static final ImmutableSet<String> SOURCE_TARGET_OPTIONS =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -39,27 +38,19 @@ public interface MultiMatcher<T extends Tree, N extends Tree> extends Matcher<T>
/**
* 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<N extends Tree> {
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<N> matchingNodes();

public record MultiMatchResult<N extends Tree>(boolean matches, ImmutableList<N> matchingNodes) {
public final N onlyMatchingNode() {
return getOnlyElement(matchingNodes());
}

static <N extends Tree> MultiMatchResult<N> create(boolean matches, List<N> matchingNodes) {
return new AutoValue_MultiMatcher_MultiMatchResult<>(
matches, ImmutableList.copyOf(matchingNodes));
return new MultiMatchResult<>(matches, ImmutableList.copyOf(matchingNodes));
}
}
}
Loading
Loading