59
59
import java .lang .annotation .Annotation ;
60
60
import java .lang .reflect .Method ;
61
61
import java .lang .reflect .Type ;
62
+ import java .lang .reflect .TypeVariable ;
63
+ import java .lang .reflect .WildcardType ;
62
64
import java .util .*;
63
65
import java .util .function .Function ;
64
66
@@ -230,6 +232,7 @@ public <X> Bean<? extends X> resolve(Set<Bean<? extends X>> beans) {
230
232
@ Override
231
233
public void validate (InjectionPoint injectionPoint ) {
232
234
assertAfterBeanDiscovery ();
235
+ validateInjectionPointType (injectionPoint );
233
236
Annotated annotated = injectionPoint .getAnnotated ();
234
237
if (annotated instanceof AnnotatedField ) { // InjectionPoint on Field
235
238
validateFieldInjectionPoint (injectionPoint );
@@ -243,6 +246,22 @@ public void validate(InjectionPoint injectionPoint) {
243
246
}
244
247
}
245
248
249
+ /**
250
+ * Any legal bean type may be the required type of an injection point.
251
+ * Furthermore, the required type of an injection point may contain a wildcard type parameter.
252
+ * However, a type variable is not a legal injection point type.
253
+ *
254
+ * @param injectionPoint {@link InjectionPoint}
255
+ * @throws DefinitionException If an injection point type is a type variable, the container automatically
256
+ * detects the problem and treats it as a definition error.
257
+ */
258
+ private void validateInjectionPointType (InjectionPoint injectionPoint ) throws DefinitionException {
259
+ Type type = injectionPoint .getType ();
260
+ if (type instanceof TypeVariable ){
261
+ throw newDefinitionException ("A type variable[%s] is not a legal injection point[%s] type" ,type ,injectionPoint );
262
+ }
263
+ }
264
+
246
265
/**
247
266
* @param injectionPoint {@link InjectionPoint}
248
267
* @throws DefinitionException If an injected field is annotated @Produces, the container automatically detects
@@ -276,52 +295,6 @@ private void validateMethodParameterInjectionPoint(InjectionPoint injectionPoint
276
295
validateForbiddenAnnotation (injectionPoint , ObservesAsync .class );
277
296
}
278
297
279
- /**
280
- * Is defining annotation type or not.
281
- * <p>
282
- * A bean class may have a bean defining annotation, allowing it to be placed anywhere in an application,
283
- * as defined in Bean archives. A bean class with a bean defining annotation is said to be an implicit bean.
284
- * The set of bean defining annotations contains:
285
- * <ul>
286
- * <li>{@link ApplicationScoped @ApplicationScoped}, {@link SessionScoped @SessionScoped},
287
- * {@link ConversationScoped @ConversationScoped} and {@link RequestScoped @RequestScoped} annotations
288
- * </li>
289
- * <li>all other normal scope types</li>
290
- * <li>{@link javax.interceptor.Interceptor @Interceptor} and {@link javax.decorator.Decorator @Decorator} annotations</li>
291
- * <li>all stereotype annotations (i.e. annotations annotated with {@link Stereotype @Stereotype})</li>
292
- * <li>the {@link Dependent @Dependent} scope annotation</li>
293
- * </ul>
294
- *
295
- * @param type
296
- * @param includedInterceptor
297
- * @param includedDecorator
298
- * @return
299
- */
300
- public boolean isDefiningAnnotationType (Class <?> type , boolean includedInterceptor , boolean includedDecorator ) {
301
-
302
- if (includedInterceptor && interceptorManager .isInterceptorClass (type )) {
303
- return true ;
304
- }
305
- if (includedDecorator && isDecorator (type )) {
306
- return true ;
307
- }
308
-
309
- boolean hasDefiningAnnotation = false ;
310
-
311
- Annotation [] annotations = type .getAnnotations ();
312
- for (Annotation annotation : annotations ) {
313
- Class <? extends Annotation > annotationType = annotation .annotationType ();
314
- if (isScope (annotationType ) ||
315
- isNormalScope (annotationType ) ||
316
- isStereotype (annotationType )) {
317
- hasDefiningAnnotation = true ;
318
- break ;
319
- }
320
- }
321
-
322
- return hasDefiningAnnotation ;
323
- }
324
-
325
298
@ Override
326
299
@ Deprecated
327
300
public void fireEvent (Object event , Annotation ... qualifiers ) {
@@ -566,6 +539,53 @@ public void initialize() {
566
539
// TODO
567
540
}
568
541
542
+
543
+ /**
544
+ * Is defining annotation type or not.
545
+ * <p>
546
+ * A bean class may have a bean defining annotation, allowing it to be placed anywhere in an application,
547
+ * as defined in Bean archives. A bean class with a bean defining annotation is said to be an implicit bean.
548
+ * The set of bean defining annotations contains:
549
+ * <ul>
550
+ * <li>{@link ApplicationScoped @ApplicationScoped}, {@link SessionScoped @SessionScoped},
551
+ * {@link ConversationScoped @ConversationScoped} and {@link RequestScoped @RequestScoped} annotations
552
+ * </li>
553
+ * <li>all other normal scope types</li>
554
+ * <li>{@link javax.interceptor.Interceptor @Interceptor} and {@link javax.decorator.Decorator @Decorator} annotations</li>
555
+ * <li>all stereotype annotations (i.e. annotations annotated with {@link Stereotype @Stereotype})</li>
556
+ * <li>the {@link Dependent @Dependent} scope annotation</li>
557
+ * </ul>
558
+ *
559
+ * @param type
560
+ * @param includedInterceptor
561
+ * @param includedDecorator
562
+ * @return
563
+ */
564
+ public boolean isDefiningAnnotationType (Class <?> type , boolean includedInterceptor , boolean includedDecorator ) {
565
+
566
+ if (includedInterceptor && interceptorManager .isInterceptorClass (type )) {
567
+ return true ;
568
+ }
569
+ if (includedDecorator && isDecorator (type )) {
570
+ return true ;
571
+ }
572
+
573
+ boolean hasDefiningAnnotation = false ;
574
+
575
+ Annotation [] annotations = type .getAnnotations ();
576
+ for (Annotation annotation : annotations ) {
577
+ Class <? extends Annotation > annotationType = annotation .annotationType ();
578
+ if (isScope (annotationType ) ||
579
+ isNormalScope (annotationType ) ||
580
+ isStereotype (annotationType )) {
581
+ hasDefiningAnnotation = true ;
582
+ break ;
583
+ }
584
+ }
585
+
586
+ return hasDefiningAnnotation ;
587
+ }
588
+
569
589
public void addDefinitionError (Throwable t ) {
570
590
this .definitionErrors .add (new DefinitionException (t ));
571
591
}
0 commit comments