@@ -100,18 +100,7 @@ public Optional<Scope> getScope(XElement element) {
100100 public ImmutableSet <Scope > getScopes (XElement element ) {
101101 superficialValidation .validateTypeOf (element );
102102 ImmutableSet <Scope > scopes =
103- getScopesFromScopeMetadata (element )
104- .orElseGet (
105- () -> {
106- // Validate the annotation types before we check for @Scope, otherwise the @Scope
107- // annotation may appear to be missing (b/213880825).
108- superficialValidation .validateAnnotationTypesOf (element );
109- return element .getAllAnnotations ().stream ()
110- .filter (InjectionAnnotations ::hasScopeAnnotation )
111- .map (DaggerAnnotation ::from )
112- .map (Scope ::scope )
113- .collect (toImmutableSet ());
114- });
103+ getScopesWithMetadata (element ).orElseGet (() -> getScopesWithoutMetadata (element ));
115104
116105 // Fully validate each scope to ensure its values are also valid.
117106 scopes .stream ()
@@ -120,7 +109,18 @@ public ImmutableSet<Scope> getScopes(XElement element) {
120109 return scopes ;
121110 }
122111
123- private Optional <ImmutableSet <Scope >> getScopesFromScopeMetadata (XElement element ) {
112+ private ImmutableSet <Scope > getScopesWithoutMetadata (XElement element ) {
113+ // Validate the annotation types before we check for @Scope, otherwise the @Scope
114+ // annotation may appear to be missing (b/213880825).
115+ superficialValidation .validateAnnotationTypesOf (element );
116+ return element .getAllAnnotations ().stream ()
117+ .filter (InjectionAnnotations ::hasScopeAnnotation )
118+ .map (DaggerAnnotation ::from )
119+ .map (Scope ::scope )
120+ .collect (toImmutableSet ());
121+ }
122+
123+ private Optional <ImmutableSet <Scope >> getScopesWithMetadata (XElement element ) {
124124 Optional <XAnnotation > scopeMetadata = getScopeMetadata (element );
125125 if (!scopeMetadata .isPresent ()) {
126126 return Optional .empty ();
@@ -203,16 +203,8 @@ public Optional<XAnnotation> getQualifier(XElement element) {
203203 public ImmutableSet <XAnnotation > getQualifiers (XElement element ) {
204204 superficialValidation .validateTypeOf (element );
205205 ImmutableSet <XAnnotation > qualifiers =
206- getQualifiersFromQualifierMetadata (element )
207- .orElseGet (
208- () -> {
209- // Validate the annotation types before we check for @Qualifier, otherwise the
210- // @Qualifier annotation may appear to be missing (b/213880825).
211- superficialValidation .validateAnnotationTypesOf (element );
212- return element .getAllAnnotations ().stream ()
213- .filter (InjectionAnnotations ::hasQualifierAnnotation )
214- .collect (toImmutableSet ());
215- });
206+ getQualifiersWithMetadata (element )
207+ .orElseGet (() -> getQualifiersWithoutMetadata (element ));
216208
217209 if (isField (element )) {
218210 XFieldElement field = asField (element );
@@ -237,7 +229,16 @@ && hasInjectAnnotation(field)
237229 return qualifiers ;
238230 }
239231
240- private Optional <ImmutableSet <XAnnotation >> getQualifiersFromQualifierMetadata (XElement element ) {
232+ private ImmutableSet <XAnnotation > getQualifiersWithoutMetadata (XElement element ) {
233+ // Validate the annotation types before we check for @Qualifier, otherwise the
234+ // @Qualifier annotation may appear to be missing (b/213880825).
235+ superficialValidation .validateAnnotationTypesOf (element );
236+ return element .getAllAnnotations ().stream ()
237+ .filter (InjectionAnnotations ::hasQualifierAnnotation )
238+ .collect (toImmutableSet ());
239+ }
240+
241+ private Optional <ImmutableSet <XAnnotation >> getQualifiersWithMetadata (XElement element ) {
241242 Optional <XAnnotation > qualifierMetadata = getQualifierMetadata (element );
242243 if (!qualifierMetadata .isPresent ()) {
243244 return Optional .empty ();
0 commit comments