14
14
import java .util .List ;
15
15
import java .util .Map ;
16
16
import java .util .Map .Entry ;
17
+ import java .util .Objects ;
17
18
import java .util .Set ;
18
19
import java .util .concurrent .ConcurrentHashMap ;
19
20
import java .util .concurrent .CopyOnWriteArrayList ;
@@ -55,8 +56,8 @@ public class BeanDeployment {
55
56
56
57
private final BuildContextImpl buildContext ;
57
58
58
- private final IndexView beanArchiveIndex ;
59
-
59
+ private final IndexView beanArchiveComputingIndex ;
60
+ private final IndexView beanArchiveImmutableIndex ;
60
61
private final IndexView applicationIndex ;
61
62
62
63
private final Map <DotName , ClassInfo > qualifiers ;
@@ -124,7 +125,8 @@ public class BeanDeployment {
124
125
}
125
126
this .beanDefiningAnnotations = beanDefiningAnnotations ;
126
127
this .resourceAnnotations = new HashSet <>(builder .resourceAnnotations );
127
- this .beanArchiveIndex = builder .beanArchiveIndex ;
128
+ this .beanArchiveComputingIndex = builder .beanArchiveComputingIndex ;
129
+ this .beanArchiveImmutableIndex = Objects .requireNonNull (builder .beanArchiveImmutableIndex );
128
130
this .applicationIndex = builder .applicationIndex ;
129
131
this .annotationStore = new AnnotationStore (initAndSort (builder .annotationTransformers , buildContext ), buildContext );
130
132
if (buildContext != null ) {
@@ -141,11 +143,11 @@ public class BeanDeployment {
141
143
this .excludeTypes = builder .excludeTypes != null ? new ArrayList <>(builder .excludeTypes ) : Collections .emptyList ();
142
144
143
145
qualifierNonbindingMembers = new HashMap <>();
144
- qualifiers = findQualifiers (this . beanArchiveIndex );
146
+ qualifiers = findQualifiers ();
145
147
for (QualifierRegistrar registrar : builder .qualifierRegistrars ) {
146
148
for (Map .Entry <DotName , Set <String >> entry : registrar .getAdditionalQualifiers ().entrySet ()) {
147
149
DotName dotName = entry .getKey ();
148
- ClassInfo classInfo = getClassByName (this . beanArchiveIndex , dotName );
150
+ ClassInfo classInfo = getClassByName (getBeanArchiveIndex () , dotName );
149
151
if (classInfo != null ) {
150
152
Set <String > nonbindingMembers = entry .getValue ();
151
153
if (nonbindingMembers == null ) {
@@ -156,15 +158,15 @@ public class BeanDeployment {
156
158
}
157
159
}
158
160
}
159
- repeatingQualifierAnnotations = findContainerAnnotations (qualifiers , this . beanArchiveIndex );
161
+ repeatingQualifierAnnotations = findContainerAnnotations (qualifiers );
160
162
buildContextPut (Key .QUALIFIERS .asString (), Collections .unmodifiableMap (qualifiers ));
161
163
162
164
interceptorNonbindingMembers = new HashMap <>();
163
- interceptorBindings = findInterceptorBindings (this . beanArchiveIndex );
165
+ interceptorBindings = findInterceptorBindings ();
164
166
for (InterceptorBindingRegistrar registrar : builder .interceptorBindingRegistrars ) {
165
167
for (InterceptorBindingRegistrar .InterceptorBinding binding : registrar .getAdditionalBindings ()) {
166
168
DotName dotName = binding .getName ();
167
- ClassInfo annotationClass = getClassByName (this . beanArchiveIndex , dotName );
169
+ ClassInfo annotationClass = getClassByName (getBeanArchiveIndex () , dotName );
168
170
if (annotationClass != null ) {
169
171
Set <String > nonbinding = new HashSet <>();
170
172
for (MethodInfo method : annotationClass .methods ()) {
@@ -177,20 +179,19 @@ public class BeanDeployment {
177
179
interceptorBindings .put (dotName , annotationClass );
178
180
}
179
181
}
180
- repeatingInterceptorBindingAnnotations = findContainerAnnotations (interceptorBindings , this . beanArchiveIndex );
182
+ repeatingInterceptorBindingAnnotations = findContainerAnnotations (interceptorBindings );
181
183
buildContextPut (Key .INTERCEPTOR_BINDINGS .asString (), Collections .unmodifiableMap (interceptorBindings ));
182
184
183
185
Set <DotName > additionalStereotypes = new HashSet <>();
184
186
for (StereotypeRegistrar stereotypeRegistrar : builder .stereotypeRegistrars ) {
185
187
additionalStereotypes .addAll (stereotypeRegistrar .getAdditionalStereotypes ());
186
188
}
187
189
188
- this .stereotypes = findStereotypes (this . beanArchiveIndex , interceptorBindings , customContexts , additionalStereotypes ,
190
+ this .stereotypes = findStereotypes (interceptorBindings , customContexts , additionalStereotypes ,
189
191
annotationStore );
190
192
buildContextPut (Key .STEREOTYPES .asString (), Collections .unmodifiableMap (stereotypes ));
191
193
192
194
this .transitiveInterceptorBindings = findTransitiveInterceptorBindings (interceptorBindings .keySet (),
193
- this .beanArchiveIndex ,
194
195
new HashMap <>(), interceptorBindings , annotationStore );
195
196
196
197
this .injectionPoints = new CopyOnWriteArrayList <>();
@@ -199,7 +200,7 @@ public class BeanDeployment {
199
200
this .beans = new CopyOnWriteArrayList <>();
200
201
this .observers = new CopyOnWriteArrayList <>();
201
202
202
- this .assignabilityCheck = new AssignabilityCheck (beanArchiveIndex , applicationIndex );
203
+ this .assignabilityCheck = new AssignabilityCheck (getBeanArchiveIndex () , applicationIndex );
203
204
this .beanResolver = new BeanResolverImpl (this );
204
205
this .delegateInjectionPointResolver = new DelegateInjectionPointResolverImpl (this );
205
206
this .interceptorResolver = new InterceptorResolver (this );
@@ -517,12 +518,17 @@ public Collection<StereotypeInfo> getStereotypes() {
517
518
}
518
519
519
520
/**
520
- * This index was used to discover components (beans, interceptors, qualifiers, etc.) and during type-safe resolution.
521
+ * Returns the index that was used during discovery and type-safe resolution.
522
+ * <p>
523
+ * In general, the returned index is usually "computing" which means that it attempts to compute the information for the
524
+ * classes that were not part of the initial bean archive index. I.e. the returned index corresponds to
525
+ * {@link BeanProcessor.Builder#setComputingBeanArchiveIndex(IndexView)}. However, if the computing index was not set then
526
+ * the index set by {@link BeanProcessor.Builder#setImmutableBeanArchiveIndex(IndexView)} is used instead.
521
527
*
522
528
* @return the bean archive index
523
529
*/
524
530
public IndexView getBeanArchiveIndex () {
525
- return beanArchiveIndex ;
531
+ return beanArchiveComputingIndex != null ? beanArchiveComputingIndex : beanArchiveImmutableIndex ;
526
532
}
527
533
528
534
/**
@@ -670,9 +676,9 @@ private void buildContextPut(String key, Object value) {
670
676
}
671
677
}
672
678
673
- private Map <DotName , ClassInfo > findQualifiers (IndexView index ) {
679
+ private Map <DotName , ClassInfo > findQualifiers () {
674
680
Map <DotName , ClassInfo > qualifiers = new HashMap <>();
675
- for (AnnotationInstance qualifier : index .getAnnotations (DotNames .QUALIFIER )) {
681
+ for (AnnotationInstance qualifier : beanArchiveImmutableIndex .getAnnotations (DotNames .QUALIFIER )) {
676
682
ClassInfo qualifierClass = qualifier .target ().asClass ();
677
683
if (isExcluded (qualifierClass )) {
678
684
continue ;
@@ -682,23 +688,23 @@ private Map<DotName, ClassInfo> findQualifiers(IndexView index) {
682
688
return qualifiers ;
683
689
}
684
690
685
- private Map <DotName , ClassInfo > findContainerAnnotations (Map <DotName , ClassInfo > annotations , IndexView index ) {
691
+ private Map <DotName , ClassInfo > findContainerAnnotations (Map <DotName , ClassInfo > annotations ) {
686
692
Map <DotName , ClassInfo > containerAnnotations = new HashMap <>();
687
693
for (ClassInfo annotation : annotations .values ()) {
688
694
AnnotationInstance repeatableMetaAnnotation = annotation .declaredAnnotation (DotNames .REPEATABLE );
689
695
if (repeatableMetaAnnotation != null ) {
690
696
DotName containerAnnotationName = repeatableMetaAnnotation .value ().asClass ().name ();
691
- ClassInfo containerClass = getClassByName (index , containerAnnotationName );
697
+ ClassInfo containerClass = getClassByName (getBeanArchiveIndex () , containerAnnotationName );
692
698
containerAnnotations .put (containerAnnotationName , containerClass );
693
699
}
694
700
}
695
701
return containerAnnotations ;
696
702
}
697
703
698
- private Map <DotName , ClassInfo > findInterceptorBindings (IndexView index ) {
704
+ private Map <DotName , ClassInfo > findInterceptorBindings () {
699
705
Map <DotName , ClassInfo > bindings = new HashMap <>();
700
706
// Note: doesn't use AnnotationStore, this will operate on classes without applying annotation transformers
701
- for (AnnotationInstance binding : index .getAnnotations (DotNames .INTERCEPTOR_BINDING )) {
707
+ for (AnnotationInstance binding : beanArchiveImmutableIndex .getAnnotations (DotNames .INTERCEPTOR_BINDING )) {
702
708
ClassInfo bindingClass = binding .target ().asClass ();
703
709
if (isExcluded (bindingClass )) {
704
710
continue ;
@@ -709,7 +715,6 @@ private Map<DotName, ClassInfo> findInterceptorBindings(IndexView index) {
709
715
}
710
716
711
717
private static Map <DotName , Set <AnnotationInstance >> findTransitiveInterceptorBindings (Collection <DotName > initialBindings ,
712
- IndexView index ,
713
718
Map <DotName , Set <AnnotationInstance >> result , Map <DotName , ClassInfo > interceptorBindings ,
714
719
AnnotationStore annotationStore ) {
715
720
// for all known interceptor bindings
@@ -748,20 +753,20 @@ private static Set<AnnotationInstance> recursiveBuild(DotName name,
748
753
return result ;
749
754
}
750
755
751
- private Map <DotName , StereotypeInfo > findStereotypes (IndexView index , Map <DotName , ClassInfo > interceptorBindings ,
756
+ private Map <DotName , StereotypeInfo > findStereotypes (Map <DotName , ClassInfo > interceptorBindings ,
752
757
Map <ScopeInfo , Function <MethodCreator , ResultHandle >> customContexts ,
753
758
Set <DotName > additionalStereotypes , AnnotationStore annotationStore ) {
754
759
755
760
Map <DotName , StereotypeInfo > stereotypes = new HashMap <>();
756
761
757
762
Set <DotName > stereotypeNames = new HashSet <>();
758
- for (AnnotationInstance annotation : index .getAnnotations (DotNames .STEREOTYPE )) {
763
+ for (AnnotationInstance annotation : beanArchiveImmutableIndex .getAnnotations (DotNames .STEREOTYPE )) {
759
764
stereotypeNames .add (annotation .target ().asClass ().name ());
760
765
}
761
766
stereotypeNames .addAll (additionalStereotypes );
762
767
763
768
for (DotName stereotypeName : stereotypeNames ) {
764
- ClassInfo stereotypeClass = getClassByName (index , stereotypeName );
769
+ ClassInfo stereotypeClass = getClassByName (getBeanArchiveIndex () , stereotypeName );
765
770
if (stereotypeClass != null && !isExcluded (stereotypeClass )) {
766
771
767
772
boolean isAlternative = false ;
@@ -852,7 +857,8 @@ private List<BeanInfo> findBeans(Collection<DotName> beanDefiningAnnotations, Li
852
857
.map (StereotypeInfo ::getName )
853
858
.collect (Collectors .toSet ());
854
859
855
- for (ClassInfo beanClass : beanArchiveIndex .getKnownClasses ()) {
860
+ // If needed use the specialized immutable index to discover beans
861
+ for (ClassInfo beanClass : beanArchiveImmutableIndex .getKnownClasses ()) {
856
862
857
863
if (Modifier .isInterface (beanClass .flags ()) || Modifier .isAbstract (beanClass .flags ())
858
864
|| beanClass .isAnnotation () || beanClass .isEnum ()) {
@@ -987,7 +993,7 @@ private List<BeanInfo> findBeans(Collection<DotName> beanDefiningAnnotations, Li
987
993
}
988
994
DotName superType = aClass .superName ();
989
995
aClass = superType != null && !superType .equals (DotNames .OBJECT )
990
- ? getClassByName (beanArchiveIndex , superType )
996
+ ? getClassByName (getBeanArchiveIndex () , superType )
991
997
: null ;
992
998
}
993
999
for (FieldInfo field : beanClass .fields ()) {
@@ -1233,7 +1239,7 @@ static void processErrors(List<Throwable> errors) {
1233
1239
1234
1240
private List <InterceptorInfo > findInterceptors (List <InjectionPointInfo > injectionPoints ) {
1235
1241
Map <DotName , ClassInfo > interceptorClasses = new HashMap <>();
1236
- for (AnnotationInstance annotation : beanArchiveIndex .getAnnotations (DotNames .INTERCEPTOR )) {
1242
+ for (AnnotationInstance annotation : beanArchiveImmutableIndex .getAnnotations (DotNames .INTERCEPTOR )) {
1237
1243
if (Kind .CLASS .equals (annotation .target ().kind ())) {
1238
1244
interceptorClasses .put (annotation .target ().asClass ().name (), annotation .target ().asClass ());
1239
1245
}
@@ -1260,7 +1266,7 @@ private List<InterceptorInfo> findInterceptors(List<InjectionPointInfo> injectio
1260
1266
1261
1267
private List <DecoratorInfo > findDecorators (List <InjectionPointInfo > injectionPoints ) {
1262
1268
Map <DotName , ClassInfo > decoratorClasses = new HashMap <>();
1263
- for (AnnotationInstance annotation : beanArchiveIndex .getAnnotations (DotNames .DECORATOR )) {
1269
+ for (AnnotationInstance annotation : beanArchiveImmutableIndex .getAnnotations (DotNames .DECORATOR )) {
1264
1270
if (Kind .CLASS .equals (annotation .target ().kind ())) {
1265
1271
decoratorClasses .put (annotation .target ().asClass ().name (), annotation .target ().asClass ());
1266
1272
}
0 commit comments