Tidy up Dagger's `@CheckReturnValue` / `@CanIgnoreReturnValue` annotations (including pushing `@CanIgnoreReturnValue` annotations down from the class-level to method-level).
RELNOTES=n/a
PiperOrigin-RevId: 455264073
diff --git a/java/dagger/internal/codegen/binding/ComponentDescriptor.java b/java/dagger/internal/codegen/binding/ComponentDescriptor.java
index 1d0dd92..096554f 100644
--- a/java/dagger/internal/codegen/binding/ComponentDescriptor.java
+++ b/java/dagger/internal/codegen/binding/ComponentDescriptor.java
@@ -65,6 +65,7 @@
* represent a synthetic component for the module, where there is an entry point for each binding in
* the module.
*/
+@CheckReturnValue
@AutoValue
public abstract class ComponentDescriptor {
/**
@@ -367,19 +368,23 @@
/** A builder of {@link ComponentMethodDescriptor}s. */
@AutoValue.Builder
- @CanIgnoreReturnValue
public interface Builder {
/** @see ComponentMethodDescriptor#methodElement() */
Builder methodElement(XMethodElement methodElement);
- /** @see ComponentMethodDescriptor#dependencyRequest() */
+ /**
+ * @see ComponentMethodDescriptor#dependencyRequest()
+ */
+ @CanIgnoreReturnValue // TODO(kak): remove this once open-source checkers understand AutoValue
Builder dependencyRequest(DependencyRequest dependencyRequest);
- /** @see ComponentMethodDescriptor#subcomponent() */
+ /**
+ * @see ComponentMethodDescriptor#subcomponent()
+ */
+ @CanIgnoreReturnValue // TODO(kak): remove this once open-source checkers understand AutoValue
Builder subcomponent(ComponentDescriptor subcomponent);
/** Builds the descriptor. */
- @CheckReturnValue
ComponentMethodDescriptor build();
}
}
diff --git a/java/dagger/internal/codegen/binding/ContributionBinding.java b/java/dagger/internal/codegen/binding/ContributionBinding.java
index 4a78e39..796e073 100644
--- a/java/dagger/internal/codegen/binding/ContributionBinding.java
+++ b/java/dagger/internal/codegen/binding/ContributionBinding.java
@@ -40,6 +40,7 @@
* An abstract class for a value object representing the mechanism by which a {@link Key} can be
* contributed to a dependency graph.
*/
+@CheckReturnValue
public abstract class ContributionBinding extends Binding implements HasContributionType {
/** Returns the type that specifies this' nullability, absent if not nullable. */
@@ -100,37 +101,47 @@
* Base builder for {@link com.google.auto.value.AutoValue @AutoValue} subclasses of {@link
* ContributionBinding}.
*/
- @CanIgnoreReturnValue
public abstract static class Builder<C extends ContributionBinding, B extends Builder<C, B>> {
+ @CanIgnoreReturnValue
public abstract B dependencies(Iterable<DependencyRequest> dependencies);
+ @CanIgnoreReturnValue
public B dependencies(DependencyRequest... dependencies) {
return dependencies(asList(dependencies));
}
+ @CanIgnoreReturnValue
public abstract B unresolved(C unresolved);
+ @CanIgnoreReturnValue
public abstract B contributionType(ContributionType contributionType);
+ @CanIgnoreReturnValue
public abstract B bindingElement(XElement bindingElement);
+ @CanIgnoreReturnValue
abstract B bindingElement(Optional<XElement> bindingElement);
+ @CanIgnoreReturnValue
public final B clearBindingElement() {
return bindingElement(Optional.empty());
};
+ @CanIgnoreReturnValue
abstract B contributingModule(XTypeElement contributingModule);
+ @CanIgnoreReturnValue
public abstract B key(Key key);
+ @CanIgnoreReturnValue
public abstract B nullableType(Optional<XType> nullableType);
+ @CanIgnoreReturnValue
abstract B mapKey(Optional<DaggerAnnotation> mapKey);
+ @CanIgnoreReturnValue
public abstract B kind(BindingKind kind);
- @CheckReturnValue
abstract C build();
}
}
diff --git a/java/dagger/internal/codegen/binding/ProductionBinding.java b/java/dagger/internal/codegen/binding/ProductionBinding.java
index bceec44..8f49abc 100644
--- a/java/dagger/internal/codegen/binding/ProductionBinding.java
+++ b/java/dagger/internal/codegen/binding/ProductionBinding.java
@@ -26,6 +26,7 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
+import com.google.errorprone.annotations.CheckReturnValue;
import dagger.internal.codegen.base.ContributionType;
import dagger.internal.codegen.base.SetType;
import dagger.spi.model.DependencyRequest;
@@ -34,6 +35,7 @@
import java.util.stream.Stream;
/** A value object representing the mechanism by which a {@link Key} can be produced. */
+@CheckReturnValue
@AutoValue
public abstract class ProductionBinding extends ContributionBinding {
@@ -126,10 +128,10 @@
/** A {@link ProductionBinding} builder. */
@AutoValue.Builder
- @CanIgnoreReturnValue
public abstract static class Builder
extends ContributionBinding.Builder<ProductionBinding, Builder> {
+ @CanIgnoreReturnValue
@Override
public Builder dependencies(Iterable<DependencyRequest> dependencies) {
return explicitDependencies(dependencies);
diff --git a/java/dagger/internal/codegen/binding/ProvisionBinding.java b/java/dagger/internal/codegen/binding/ProvisionBinding.java
index 2447e30..ad61677 100644
--- a/java/dagger/internal/codegen/binding/ProvisionBinding.java
+++ b/java/dagger/internal/codegen/binding/ProvisionBinding.java
@@ -25,6 +25,7 @@
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedSet;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
+import com.google.errorprone.annotations.CheckReturnValue;
import dagger.internal.codegen.binding.MembersInjectionBinding.InjectionSite;
import dagger.internal.codegen.compileroption.CompilerOptions;
import dagger.spi.model.BindingKind;
@@ -34,6 +35,7 @@
import java.util.Optional;
/** A value object representing the mechanism by which a {@link Key} can be provided. */
+@CheckReturnValue
@AutoValue
public abstract class ProvisionBinding extends ContributionBinding {
@@ -115,10 +117,10 @@
/** A {@link ProvisionBinding} builder. */
@AutoValue.Builder
- @CanIgnoreReturnValue
public abstract static class Builder
extends ContributionBinding.Builder<ProvisionBinding, Builder> {
+ @CanIgnoreReturnValue
@Override
public Builder dependencies(Iterable<DependencyRequest> dependencies) {
return provisionDependencies(dependencies);
@@ -128,6 +130,7 @@
public abstract Builder injectionSites(ImmutableSortedSet<InjectionSite> injectionSites);
+ @CanIgnoreReturnValue // TODO(kak): remove this once open-source checkers understand AutoValue
@Override
public abstract Builder unresolved(ProvisionBinding unresolved);
diff --git a/java/dagger/internal/codegen/validation/ValidationReport.java b/java/dagger/internal/codegen/validation/ValidationReport.java
index b88d4b9..6267d89 100644
--- a/java/dagger/internal/codegen/validation/ValidationReport.java
+++ b/java/dagger/internal/codegen/validation/ValidationReport.java
@@ -37,6 +37,7 @@
import javax.tools.Diagnostic.Kind;
/** A collection of issues to report for source code. */
+@CheckReturnValue
public final class ValidationReport {
private static final Traverser<ValidationReport> SUBREPORTS =
Traverser.forTree(report -> report.subreports);
@@ -145,7 +146,6 @@
}
/** A {@link ValidationReport} builder. */
- @CanIgnoreReturnValue
public static final class Builder {
private final XElement subject;
private final ImmutableSet.Builder<Item> items = ImmutableSet.builder();
@@ -156,23 +156,28 @@
this.subject = subject;
}
+ @CanIgnoreReturnValue
Builder addItems(Iterable<Item> newItems) {
items.addAll(newItems);
return this;
}
+ @CanIgnoreReturnValue
public Builder addError(String message) {
return addError(message, subject);
}
+ @CanIgnoreReturnValue
public Builder addError(String message, XElement element) {
return addItem(message, ERROR, element);
}
+ @CanIgnoreReturnValue
public Builder addError(String message, XElement element, XAnnotation annotation) {
return addItem(message, ERROR, element, annotation);
}
+ @CanIgnoreReturnValue
public Builder addError(
String message,
XElement element,
@@ -181,18 +186,22 @@
return addItem(message, ERROR, element, annotation, annotationValue);
}
+ @CanIgnoreReturnValue
Builder addWarning(String message) {
return addWarning(message, subject);
}
+ @CanIgnoreReturnValue
Builder addWarning(String message, XElement element) {
return addItem(message, WARNING, element);
}
+ @CanIgnoreReturnValue
Builder addWarning(String message, XElement element, XAnnotation annotation) {
return addItem(message, WARNING, element, annotation);
}
+ @CanIgnoreReturnValue
Builder addWarning(
String message,
XElement element,
@@ -201,18 +210,22 @@
return addItem(message, WARNING, element, annotation, annotationValue);
}
+ @CanIgnoreReturnValue
Builder addNote(String message) {
return addNote(message, subject);
}
+ @CanIgnoreReturnValue
Builder addNote(String message, XElement element) {
return addItem(message, NOTE, element);
}
+ @CanIgnoreReturnValue
Builder addNote(String message, XElement element, XAnnotation annotation) {
return addItem(message, NOTE, element, annotation);
}
+ @CanIgnoreReturnValue
Builder addNote(
String message,
XElement element,
@@ -221,14 +234,17 @@
return addItem(message, NOTE, element, annotation, annotationValue);
}
+ @CanIgnoreReturnValue
Builder addItem(String message, Kind kind, XElement element) {
return addItem(message, kind, element, Optional.empty(), Optional.empty());
}
+ @CanIgnoreReturnValue
Builder addItem(String message, Kind kind, XElement element, XAnnotation annotation) {
return addItem(message, kind, element, Optional.of(annotation), Optional.empty());
}
+ @CanIgnoreReturnValue
Builder addItem(
String message,
Kind kind,
@@ -238,6 +254,7 @@
return addItem(message, kind, element, Optional.of(annotation), Optional.of(annotationValue));
}
+ @CanIgnoreReturnValue
private Builder addItem(
String message,
Kind kind,
@@ -262,12 +279,12 @@
this.markedDirty = true;
}
+ @CanIgnoreReturnValue
public Builder addSubreport(ValidationReport subreport) {
subreports.add(subreport);
return this;
}
- @CheckReturnValue
public ValidationReport build() {
return new ValidationReport(subject, items.build(), subreports.build(), markedDirty);
}
diff --git a/java/dagger/model/DependencyRequest.java b/java/dagger/model/DependencyRequest.java
index 607b5ec..b9b134c 100644
--- a/java/dagger/model/DependencyRequest.java
+++ b/java/dagger/model/DependencyRequest.java
@@ -18,7 +18,6 @@
import com.google.auto.value.AutoValue;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
-import com.google.errorprone.annotations.CheckReturnValue;
import dagger.Provides;
import java.util.Optional;
import javax.inject.Inject;
@@ -60,18 +59,17 @@
}
/** A builder of {@link DependencyRequest}s. */
- @CanIgnoreReturnValue
@AutoValue.Builder
public abstract static class Builder {
public abstract Builder kind(RequestKind kind);
public abstract Builder key(Key key);
+ @CanIgnoreReturnValue // TODO(kak): remove this once open-source checkers understand AutoValue
public abstract Builder requestElement(Element element);
public abstract Builder isNullable(boolean isNullable);
- @CheckReturnValue
public abstract DependencyRequest build();
}
}
diff --git a/java/dagger/model/Key.java b/java/dagger/model/Key.java
index aeeabdf..6916951 100644
--- a/java/dagger/model/Key.java
+++ b/java/dagger/model/Key.java
@@ -28,7 +28,6 @@
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableMap;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
-import com.google.errorprone.annotations.CheckReturnValue;
import com.squareup.javapoet.CodeBlock;
import java.util.List;
import java.util.Objects;
@@ -178,11 +177,11 @@
}
/** A builder for {@link Key}s. */
- @CanIgnoreReturnValue
@AutoValue.Builder
public abstract static class Builder {
abstract Builder wrappedType(Equivalence.Wrapper<TypeMirror> wrappedType);
+ @CanIgnoreReturnValue
public final Builder type(TypeMirror type) {
return wrappedType(MoreTypes.equivalence().wrap(checkNotNull(type)));
}
@@ -192,10 +191,12 @@
abstract Builder wrappedQualifier(Equivalence.Wrapper<AnnotationMirror> wrappedQualifier);
+ @CanIgnoreReturnValue
public final Builder qualifier(AnnotationMirror qualifier) {
return wrappedQualifier(AnnotationMirrors.equivalence().wrap(checkNotNull(qualifier)));
}
+ @CanIgnoreReturnValue
public final Builder qualifier(Optional<AnnotationMirror> qualifier) {
return wrappedQualifier(checkNotNull(qualifier).map(AnnotationMirrors.equivalence()::wrap));
}
@@ -206,7 +207,6 @@
public abstract Builder multibindingContributionIdentifier(
MultibindingContributionIdentifier identifier);
- @CheckReturnValue
public abstract Key build();
}
diff --git a/java/dagger/spi/model/DependencyRequest.java b/java/dagger/spi/model/DependencyRequest.java
index 64c0f28..912a828 100644
--- a/java/dagger/spi/model/DependencyRequest.java
+++ b/java/dagger/spi/model/DependencyRequest.java
@@ -17,8 +17,6 @@
package dagger.spi.model;
import com.google.auto.value.AutoValue;
-import com.google.errorprone.annotations.CanIgnoreReturnValue;
-import com.google.errorprone.annotations.CheckReturnValue;
import dagger.Provides;
import java.util.Optional;
import javax.inject.Inject;
@@ -59,7 +57,6 @@
}
/** A builder of {@link DependencyRequest}s. */
- @CanIgnoreReturnValue
@AutoValue.Builder
public abstract static class Builder {
public abstract Builder kind(RequestKind kind);
@@ -70,7 +67,6 @@
public abstract Builder isNullable(boolean isNullable);
- @CheckReturnValue
public abstract DependencyRequest build();
}
}
diff --git a/java/dagger/spi/model/Key.java b/java/dagger/spi/model/Key.java
index d42933b..43ee799 100644
--- a/java/dagger/spi/model/Key.java
+++ b/java/dagger/spi/model/Key.java
@@ -23,8 +23,6 @@
import com.google.auto.value.AutoValue;
import com.google.auto.value.extension.memoized.Memoized;
import com.google.common.base.Joiner;
-import com.google.errorprone.annotations.CanIgnoreReturnValue;
-import com.google.errorprone.annotations.CheckReturnValue;
import java.util.Objects;
import java.util.Optional;
import javax.lang.model.element.ExecutableElement;
@@ -85,7 +83,6 @@
}
/** A builder for {@link Key}s. */
- @CanIgnoreReturnValue
@AutoValue.Builder
public abstract static class Builder {
public abstract Builder type(DaggerType type);
@@ -100,7 +97,6 @@
public abstract Builder multibindingContributionIdentifier(
MultibindingContributionIdentifier identifier);
- @CheckReturnValue
public abstract Key build();
}