Skip to content

Commit

Permalink
Automatic code cleanup.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 458454778
Change-Id: I9159e96f407ee70cdb81d05ff5715bcb84d6bbf5
  • Loading branch information
kluever authored and copybara-github committed Jul 1, 2022
1 parent 07db6a4 commit 255e8f5
Show file tree
Hide file tree
Showing 24 changed files with 160 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.google.devtools.build.importdeps.AbstractClassEntryState.MissingState;
import com.google.devtools.build.importdeps.ClassInfo.MemberInfo;
import org.objectweb.asm.Opcodes;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -412,11 +413,13 @@ void setNames(String name, String superName, String[] interfaces) {
superClasses = combineWithoutNull(superName, interfaces);
}

@CanIgnoreReturnValue
public ClassInfoBuilder setJarPath(Path jarPath) {
this.jarPath = jarPath;
return this;
}

@CanIgnoreReturnValue
public ClassInfoBuilder setDirect(boolean direct) {
this.directDep = direct;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.google.common.collect.ImmutableSet;
import com.google.devtools.build.importdeps.ClassInfo.MemberInfo;
import org.objectweb.asm.Opcodes;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.util.Optional;
import javax.annotation.Nullable;
import org.objectweb.asm.AnnotationVisitor;
Expand Down Expand Up @@ -233,6 +234,7 @@ private class DepsCheckerAnnotationVisitor extends AnnotationVisitor {
super(Opcodes.ASM9);
}

@CanIgnoreReturnValue
@Override
public AnnotationVisitor visitAnnotation(String name, String desc) {
checkDescriptor(desc);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static com.google.common.truth.Truth.assertWithMessage;
import static java.nio.charset.StandardCharsets.UTF_8;

import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
Expand Down Expand Up @@ -135,56 +136,65 @@ public void assertNext(ZipInputStream zipInput) throws IOException {

private final List<FakeZipEntry> entries = new ArrayList<>();

@CanIgnoreReturnValue
public FakeZipFile addEntry(String name, String content) {
entries.add(new FakeZipEntry(name, null, content, null, EntryMode.DONT_CARE));
return this;
}

@CanIgnoreReturnValue
public FakeZipFile addEntry(String name, String content, boolean compressed) {
entries.add(new FakeZipEntry(name, null, content, null,
compressed ? EntryMode.EXPECT_DEFLATE : EntryMode.EXPECT_STORED));
return this;
}

@CanIgnoreReturnValue
public FakeZipFile addEntry(String name, Date date, String content) {
entries.add(new FakeZipEntry(name, date, content, null, EntryMode.DONT_CARE));
return this;
}

@CanIgnoreReturnValue
public FakeZipFile addEntry(String name, Date date, String content, boolean compressed) {
entries.add(new FakeZipEntry(name, date, content, null,
compressed ? EntryMode.EXPECT_DEFLATE : EntryMode.EXPECT_STORED));
return this;
}

@CanIgnoreReturnValue
public FakeZipFile addEntry(String name, ByteValidator content) {
entries.add(new FakeZipEntry(name, null, content, null, EntryMode.DONT_CARE));
return this;
}

@CanIgnoreReturnValue
public FakeZipFile addEntry(String name, ByteValidator content, boolean compressed) {
entries.add(new FakeZipEntry(name, null, content, null,
compressed ? EntryMode.EXPECT_DEFLATE : EntryMode.EXPECT_STORED));
return this;
}

@CanIgnoreReturnValue
public FakeZipFile addEntry(String name, Date date, ByteValidator content) {
entries.add(new FakeZipEntry(name, date, content, null, EntryMode.DONT_CARE));
return this;
}

public FakeZipFile addEntry(String name, Date date, ByteValidator content,
boolean compressed) {
@CanIgnoreReturnValue
public FakeZipFile addEntry(String name, Date date, ByteValidator content, boolean compressed) {
entries.add(new FakeZipEntry(name, date, content, null,
compressed ? EntryMode.EXPECT_DEFLATE : EntryMode.EXPECT_STORED));
return this;
}

@CanIgnoreReturnValue
public FakeZipFile addEntry(String name, byte[] extra) {
entries.add(new FakeZipEntry(name, null, (String) null, extra, EntryMode.DONT_CARE));
return this;
}

@CanIgnoreReturnValue
public FakeZipFile addEntry(String name, byte[] extra, boolean compressed) {
entries.add(new FakeZipEntry(name, null, (String) null, extra,
compressed ? EntryMode.EXPECT_DEFLATE : EntryMode.EXPECT_STORED));
Expand All @@ -193,6 +203,7 @@ public FakeZipFile addEntry(String name, byte[] extra, boolean compressed) {

private byte[] preamble = null;

@CanIgnoreReturnValue
public FakeZipFile addPreamble(byte[] contents) {
preamble = Arrays.copyOf(contents, contents.length);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import static java.nio.charset.StandardCharsets.ISO_8859_1;

import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
Expand Down Expand Up @@ -49,21 +50,25 @@ private void addEntry(String name, byte[] content, boolean compressed) {
entries.add(new Entry(name, content, compressed));
}

@CanIgnoreReturnValue
public ZipFactory addFile(String name, String content) {
addEntry(name, content.getBytes(ISO_8859_1), true);
return this;
}

@CanIgnoreReturnValue
public ZipFactory addFile(String name, byte[] content) {
addEntry(name, content.clone(), true);
return this;
}

@CanIgnoreReturnValue
public ZipFactory addFile(String name, String content, boolean compressed) {
addEntry(name, content.getBytes(ISO_8859_1), compressed);
return this;
}

@CanIgnoreReturnValue
public ZipFactory addFile(String name, byte[] content, boolean compressed) {
addEntry(name, content.clone(), compressed);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import com.google.devtools.common.options.OptionsBase;
import com.google.devtools.common.options.OptionsParsingResult;
import com.google.devtools.common.options.OptionsProvider;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -89,51 +90,61 @@ public static final class Builder {

private Builder() {}

@CanIgnoreReturnValue
public Builder setId(UUID id) {
this.id = id;
return this;
}

@CanIgnoreReturnValue
public Builder setOptions(OptionsParsingResult options) {
this.options = options;
return this;
}

@CanIgnoreReturnValue
public Builder setStartupOptions(OptionsParsingResult startupOptions) {
this.startupOptions = startupOptions;
return this;
}

@CanIgnoreReturnValue
public Builder setCommandName(String commandName) {
this.commandName = commandName;
return this;
}

@CanIgnoreReturnValue
public Builder setOutErr(OutErr outErr) {
this.outErr = outErr;
return this;
}

@CanIgnoreReturnValue
public Builder setTargets(List<String> targets) {
this.targets = targets;
return this;
}

@CanIgnoreReturnValue
public Builder setStartTimeMillis(long startTimeMillis) {
this.startTimeMillis = startTimeMillis;
return this;
}

@CanIgnoreReturnValue
public Builder setNeedsInstrumentationFilter(boolean needsInstrumentationFilter) {
this.needsInstrumentationFilter = needsInstrumentationFilter;
return this;
}

@CanIgnoreReturnValue
public Builder setRunTests(boolean runTests) {
this.runTests = runTests;
return this;
}

@CanIgnoreReturnValue
public Builder setCheckforActionConflicts(boolean checkForActionConflicts) {
this.checkForActionConflicts = checkForActionConflicts;
return this;
Expand All @@ -148,6 +159,7 @@ public Builder setCheckforActionConflicts(boolean checkForActionConflicts) {
* output) and false for queries (where users want to understand target relationships or
* diagnose why incompatible targets are incompatible).
*/
@CanIgnoreReturnValue
public Builder setReportIncompatibleTargets(boolean report) {
this.reportIncompatibleTargets = report;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.google.devtools.build.lib.util.ExitCode;
import com.google.devtools.build.lib.util.Pair;
import com.google.devtools.build.lib.vfs.Path;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.protobuf.ByteString;
import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -281,6 +282,7 @@ public static final class BuildToolLogCollection {
private final List<LogFileEntry> localFiles = new ArrayList<>();
private boolean frozen;

@CanIgnoreReturnValue
public BuildToolLogCollection freeze() {
frozen = true;
return this;
Expand All @@ -291,18 +293,21 @@ public List<LogFileEntry> getLocalFiles() {
return localFiles;
}

@CanIgnoreReturnValue
public BuildToolLogCollection addDirectValue(String name, byte[] data) {
Preconditions.checkState(!frozen);
this.directValues.add(Pair.of(name, ByteString.copyFrom(data)));
return this;
}

@CanIgnoreReturnValue
public BuildToolLogCollection addUri(String name, String uri) {
Preconditions.checkState(!frozen);
this.futureUris.add(Pair.of(name, Futures.immediateFuture(uri)));
return this;
}

@CanIgnoreReturnValue
public BuildToolLogCollection addUriFuture(String name, ListenableFuture<String> uriFuture) {
Preconditions.checkState(!frozen);
this.futureUris.add(Pair.of(name, uriFuture));
Expand All @@ -313,6 +318,7 @@ public BuildToolLogCollection addLocalFile(String name, Path path) {
return addLocalFile(name, path, LocalFileType.LOG, LocalFileCompression.NONE);
}

@CanIgnoreReturnValue
public BuildToolLogCollection addLocalFile(
String name, Path path, LocalFileType localFileType, LocalFileCompression compression) {
Preconditions.checkState(!frozen);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package com.google.devtools.build.lib.concurrent;

import com.google.common.base.Preconditions;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinTask;
Expand Down Expand Up @@ -43,20 +44,22 @@ private Builder() {
}

/**
* Sets the {@link ForkJoinPool} that will be used by the to-be-built
* {@link ForkJoinQuiescingExecutor}. The given {@link ForkJoinPool} will be shut down on
* completion of the {@link ForkJoinQuiescingExecutor}.
* Sets the {@link ForkJoinPool} that will be used by the to-be-built {@link
* ForkJoinQuiescingExecutor}. The given {@link ForkJoinPool} will be shut down on completion of
* the {@link ForkJoinQuiescingExecutor}.
*/
@CanIgnoreReturnValue
public Builder withOwnershipOf(ForkJoinPool forkJoinPool) {
Preconditions.checkState(this.forkJoinPool == null);
this.forkJoinPool = forkJoinPool;
return this;
}

/**
* Sets the {@link ErrorClassifier} that will be used by the to-be-built
* {@link ForkJoinQuiescingExecutor}.
* Sets the {@link ErrorClassifier} that will be used by the to-be-built {@link
* ForkJoinQuiescingExecutor}.
*/
@CanIgnoreReturnValue
public Builder setErrorClassifier(ErrorClassifier errorClassifier) {
this.errorClassifier = errorClassifier;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.google.common.collect.HashMultiset;
import com.google.common.collect.Multiset;
import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.util.Set;
import java.util.concurrent.Semaphore;

Expand Down Expand Up @@ -83,6 +84,7 @@ private Builder() {
* Sets the maximum number of unique values for which permits can be held at once in the
* to-be-constructed {@link MultisetSemaphore}.
*/
@CanIgnoreReturnValue
public Builder maxNumUniqueValues(int maxNumUniqueValues) {
Preconditions.checkState(
maxNumUniqueValues > 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.google.devtools.build.lib.skyframe.serialization.ObjectCodec;
import com.google.devtools.build.lib.skyframe.serialization.SerializationContext;
import com.google.devtools.build.lib.skyframe.serialization.SerializationException;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.protobuf.CodedInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -156,12 +157,14 @@ public final Builder<T> addSubjects(T... subjects) {
}

/** Add subjects to be tested for serialization/deserialization. */
@CanIgnoreReturnValue
public Builder<T> addSubjects(ImmutableList<T> subjects) {
subjectsBuilder.addAll(subjects);
return this;
}

/** Add subjects to be tested for serialization/deserialization. */
@CanIgnoreReturnValue
public final <D> Builder<T> addDependency(Class<? super D> type, D dependency) {
dependenciesBuilder.put(type, dependency);
return this;
Expand All @@ -171,21 +174,24 @@ public final <D> Builder<T> addDependency(Class<? super D> type, D dependency) {
* Skip tests that check for the ability to detect bad data. This may be useful for simpler
* codecs which don't do any error verification.
*/
@CanIgnoreReturnValue
public Builder<T> skipBadDataTest() {
this.skipBadDataTest = true;
return this;
}

/**
* Sets {@link ObjectCodecTester.VerificationFunction} for verifying deserialization. Default
* is simple equality assertion, a custom version may be provided for more, or less, detailed
* Sets {@link ObjectCodecTester.VerificationFunction} for verifying deserialization. Default is
* simple equality assertion, a custom version may be provided for more, or less, detailed
* checks.
*/
@CanIgnoreReturnValue
public Builder<T> verificationFunction(VerificationFunction<T> verificationFunction) {
this.verificationFunction = Preconditions.checkNotNull(verificationFunction);
return this;
}

@CanIgnoreReturnValue
public Builder<T> setRepetitions(int repetitions) {
this.repetitions = repetitions;
return this;
Expand Down
Loading

0 comments on commit 255e8f5

Please sign in to comment.