Search in sources :

Example 1 with DaggerAnnotation

use of dagger.spi.model.DaggerAnnotation in project dapper by jbock-java.

the class InjectionAnnotations method getQualifiers.

/*
   * Returns the qualifiers on the given element, or an empty set if none exist.
   *
   * <p>The {@code QualifierMetadata} is used to avoid superficial validation on unnecessary
   * annotations. If the {@code QualifierMetadata} does not exist, then all annotations must be
   * superficially validated before we can determine if they are qualifiers or not.
   */
public ImmutableSet<XAnnotation> getQualifiers(XElement element) {
    superficialValidation.validateTypeOf(element);
    ImmutableSet<XAnnotation> qualifiers = getQualifiersFromQualifierMetadata(element).orElseGet(() -> {
        // Validate the annotation types before we check for @Qualifier, otherwise the
        // @Qualifier annotation may appear to be missing (b/213880825).
        superficialValidation.validateAnnotationTypesOf(element);
        return element.getAllAnnotations().stream().filter(InjectionAnnotations::hasQualifierAnnotation).collect(toImmutableSet());
    });
    if (isField(element)) {
        XFieldElement field = asField(element);
        // no need to get qualifier from kotlin metadata
        if (!field.isStatic() && isTypeElement(field.getEnclosingElement()) && hasInjectAnnotation(field) && kotlinMetadataUtil.hasMetadata(field)) {
            qualifiers = Stream.concat(qualifiers.stream(), getQualifiersForKotlinProperty(field).stream()).map(// Wrap in DaggerAnnotation to deduplicate
            DaggerAnnotation::from).distinct().map(DaggerAnnotation::xprocessing).collect(toImmutableSet());
        }
    }
    // Fully validate each qualifier to ensure its values are also valid.
    qualifiers.forEach(qualifier -> superficialValidation.validateAnnotationOf(element, qualifier));
    return qualifiers;
}
Also used : XAnnotation(dagger.internal.codegen.xprocessing.XAnnotation) DaggerAnnotation(dagger.spi.model.DaggerAnnotation) XFieldElement(dagger.internal.codegen.xprocessing.XFieldElement)

Aggregations

XAnnotation (dagger.internal.codegen.xprocessing.XAnnotation)1 XFieldElement (dagger.internal.codegen.xprocessing.XFieldElement)1 DaggerAnnotation (dagger.spi.model.DaggerAnnotation)1