Skip to content

Commit

Permalink
Internal changes
Browse files Browse the repository at this point in the history
RELNOTES=N/A
PiperOrigin-RevId: 568310453
  • Loading branch information
bcorso authored and Dagger Team committed Sep 25, 2023
1 parent 76bde06 commit 7412301
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions java/dagger/internal/codegen/binding/InjectionAnnotations.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,7 @@ public Optional<Scope> getScope(XElement element) {
public ImmutableSet<Scope> getScopes(XElement element) {
superficialValidation.validateTypeOf(element);
ImmutableSet<Scope> scopes =
getScopesFromScopeMetadata(element)
.orElseGet(
() -> {
// Validate the annotation types before we check for @Scope, otherwise the @Scope
// annotation may appear to be missing (b/213880825).
superficialValidation.validateAnnotationTypesOf(element);
return element.getAllAnnotations().stream()
.filter(InjectionAnnotations::hasScopeAnnotation)
.map(DaggerAnnotation::from)
.map(Scope::scope)
.collect(toImmutableSet());
});
getScopesWithMetadata(element).orElseGet(() -> getScopesWithoutMetadata(element));

// Fully validate each scope to ensure its values are also valid.
scopes.stream()
Expand All @@ -120,7 +109,18 @@ public ImmutableSet<Scope> getScopes(XElement element) {
return scopes;
}

private Optional<ImmutableSet<Scope>> getScopesFromScopeMetadata(XElement element) {
private ImmutableSet<Scope> getScopesWithoutMetadata(XElement element) {
// Validate the annotation types before we check for @Scope, otherwise the @Scope
// annotation may appear to be missing (b/213880825).
superficialValidation.validateAnnotationTypesOf(element);
return element.getAllAnnotations().stream()
.filter(InjectionAnnotations::hasScopeAnnotation)
.map(DaggerAnnotation::from)
.map(Scope::scope)
.collect(toImmutableSet());
}

private Optional<ImmutableSet<Scope>> getScopesWithMetadata(XElement element) {
Optional<XAnnotation> scopeMetadata = getScopeMetadata(element);
if (!scopeMetadata.isPresent()) {
return Optional.empty();
Expand Down Expand Up @@ -203,16 +203,8 @@ public Optional<XAnnotation> getQualifier(XElement element) {
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());
});
getQualifiersWithMetadata(element)
.orElseGet(() -> getQualifiersWithoutMetadata(element));

if (isField(element)) {
XFieldElement field = asField(element);
Expand All @@ -237,7 +229,16 @@ && hasInjectAnnotation(field)
return qualifiers;
}

private Optional<ImmutableSet<XAnnotation>> getQualifiersFromQualifierMetadata(XElement element) {
private ImmutableSet<XAnnotation> getQualifiersWithoutMetadata(XElement element) {
// 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());
}

private Optional<ImmutableSet<XAnnotation>> getQualifiersWithMetadata(XElement element) {
Optional<XAnnotation> qualifierMetadata = getQualifierMetadata(element);
if (!qualifierMetadata.isPresent()) {
return Optional.empty();
Expand Down

0 comments on commit 7412301

Please sign in to comment.