aboutsummaryrefslogtreecommitdiff
path: root/java/dagger/internal/codegen/validation/BindingElementValidator.java
diff options
context:
space:
mode:
authorAurimas Liutikas <aurimas@google.com>2021-05-12 22:53:00 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2021-05-12 22:53:00 +0000
commit8630738d0a775a2f8e5bc09c437556bd75d8b620 (patch)
tree6f59a75348d07612173246ac6c4fca04bde0df2c /java/dagger/internal/codegen/validation/BindingElementValidator.java
parent0cd6a8551365e02a1687415356215ba2061739cd (diff)
parent5480a6c05f0c4727b3dd154709f40fdae8d8b4a2 (diff)
downloaddagger2-8630738d0a775a2f8e5bc09c437556bd75d8b620.tar.gz
Merge "Revert "Merge commit 'upstream/dagger-2.35.1^'"" am: 5882ce8935 am: 5480a6c05f
Original change: https://android-review.googlesource.com/c/platform/external/dagger2/+/1705751 Change-Id: I2f7a4d61b9f48965273925620a8dc0afc43c9bef
Diffstat (limited to 'java/dagger/internal/codegen/validation/BindingElementValidator.java')
-rw-r--r--java/dagger/internal/codegen/validation/BindingElementValidator.java44
1 files changed, 18 insertions, 26 deletions
diff --git a/java/dagger/internal/codegen/validation/BindingElementValidator.java b/java/dagger/internal/codegen/validation/BindingElementValidator.java
index b8f9912b4..4557745ee 100644
--- a/java/dagger/internal/codegen/validation/BindingElementValidator.java
+++ b/java/dagger/internal/codegen/validation/BindingElementValidator.java
@@ -17,6 +17,7 @@
package dagger.internal.codegen.validation;
import static com.google.auto.common.MoreTypes.asTypeElement;
+import static com.google.common.base.Preconditions.checkState;
import static com.google.common.base.Verify.verifyNotNull;
import static dagger.internal.codegen.base.Scopes.scopesOf;
import static dagger.internal.codegen.base.Util.reentrantComputeIfAbsent;
@@ -141,12 +142,10 @@ public abstract class BindingElementValidator<E extends Element> {
protected abstract class ElementValidator {
protected final E element;
protected final ValidationReport.Builder<E> report;
- private final ImmutableCollection<? extends AnnotationMirror> qualifiers;
protected ElementValidator(E element) {
this.element = element;
this.report = ValidationReport.about(element);
- qualifiers = injectionAnnotations.getQualifiers(element);
}
/** Checks the element for validity. */
@@ -186,15 +185,10 @@ public abstract class BindingElementValidator<E extends Element> {
protected void checkType() {
switch (ContributionType.fromBindingElement(element)) {
case UNIQUE:
- // Validate that a unique binding is not attempting to bind a framework type. This
- // validation is only appropriate for unique bindings because multibindings may collect
- // framework types. E.g. Set<Provider<Foo>> is perfectly reasonable.
+ /* Validate that a unique binding is not attempting to bind a framework type. This
+ * validation is only appropriate for unique bindings because multibindings may collect
+ * framework types. E.g. Set<Provider<Foo>> is perfectly reasonable. */
checkFrameworkType();
-
- // Validate that a unique binding is not attempting to bind an unqualified assisted type.
- // This validation is only appropriate for unique bindings because multibindings may
- // collect assisted types.
- checkAssistedType();
// fall through
case SET:
@@ -214,26 +208,22 @@ public abstract class BindingElementValidator<E extends Element> {
TypeKind kind = keyType.getKind();
if (kind.equals(VOID)) {
report.addError(bindingElements("must %s a value (not void)", bindingElementTypeVerb()));
- } else if (!(kind.isPrimitive()
- || kind.equals(DECLARED)
- || kind.equals(ARRAY)
- || kind.equals(TYPEVAR))) {
+ } else if (kind == DECLARED) {
+ checkNotAssistedInject(keyType);
+ } else if (!(kind.isPrimitive() || kind.equals(ARRAY) || kind.equals(TYPEVAR))) {
report.addError(badTypeMessage());
}
}
- /** Adds errors for unqualified assisted types. */
- private void checkAssistedType() {
- if (qualifiers.isEmpty()
- && bindingElementType().isPresent()
- && bindingElementType().get().getKind() == DECLARED) {
- TypeElement keyElement = asTypeElement(bindingElementType().get());
- if (isAssistedInjectionType(keyElement)) {
- report.addError("Dagger does not support providing @AssistedInject types.", keyElement);
- }
- if (isAssistedFactoryType(keyElement)) {
- report.addError("Dagger does not support providing @AssistedFactory types.", keyElement);
- }
+ /** Adds errors for a method return type. */
+ private void checkNotAssistedInject(TypeMirror keyType) {
+ checkState(keyType.getKind() == TypeKind.DECLARED);
+ TypeElement keyElement = asTypeElement(keyType);
+ if (isAssistedInjectionType(keyElement)) {
+ report.addError("Dagger does not support providing @AssistedInject types.", keyElement);
+ }
+ if (isAssistedFactoryType(keyElement)) {
+ report.addError("Dagger does not support providing @AssistedFactory types.", keyElement);
}
}
@@ -264,6 +254,8 @@ public abstract class BindingElementValidator<E extends Element> {
* Adds an error if the element has more than one {@linkplain Qualifier qualifier} annotation.
*/
private void checkQualifiers() {
+ ImmutableCollection<? extends AnnotationMirror> qualifiers =
+ injectionAnnotations.getQualifiers(element);
if (qualifiers.size() > 1) {
for (AnnotationMirror qualifier : qualifiers) {
report.addError(