private < Y > void checkObserverMethod ( EnhancedAnnotatedMethod < T , Y > annotated ) { // Make sure exactly one and only one parameter is annotated with Observes or ObservesAsync List < EnhancedAnnotatedParameter < ? , Y > > eventObjects = annotated . getEnhancedParameters ( Observes . class ) ; eventObjects . addAll ( annotated . getEnhancedParameters ( ObservesAsync . class ) ) ; if ( this . reception . equals ( Reception . IF_EXISTS ) && declaringBean . getScope ( ) . equals ( Dependent . class ) ) { throw EventLogger . LOG . invalidScopedConditionalObserver ( this , Formats . formatAsStackTraceElement ( annotated . getJavaMember ( ) ) ) ; } if ( eventObjects . size ( ) > 1 ) { throw EventLogger . LOG . multipleEventParameters ( this , Formats . formatAsStackTraceElement ( annotated . getJavaMember ( ) ) ) ; } EnhancedAnnotatedParameter < ? , Y > eventParameter = eventObjects . iterator ( ) . next ( ) ; checkRequiredTypeAnnotations ( eventParameter ) ; // Check for parameters annotated with @Disposes List < ? > disposeParams = annotated . getEnhancedParameters ( Disposes . class ) ; if ( disposeParams . size ( ) > 0 ) { throw EventLogger . LOG . invalidDisposesParameter ( this , Formats . formatAsStackTraceElement ( annotated . getJavaMember ( ) ) ) ; } // Check annotations on the method to make sure this is not a producer // method, initializer method, or destructor method. if ( this . observerMethod . getAnnotated ( ) . isAnnotationPresent ( Produces . class ) ) { throw EventLogger . LOG . invalidProducer ( this , Formats . formatAsStackTraceElement ( annotated . getJavaMember ( ) ) ) ; } if ( this . observerMethod . getAnnotated ( ) . isAnnotationPresent ( Inject . class ) ) { throw EventLogger . LOG . invalidInitializer ( this , Formats . formatAsStackTraceElement ( annotated . getJavaMember ( ) ) ) ; } boolean containerLifecycleObserverMethod = Observers . isContainerLifecycleObserverMethod ( this ) ; for ( EnhancedAnnotatedParameter < ? , ? > parameter : annotated . getEnhancedParameters ( ) ) { // if this is an observer method for container lifecycle event, it must not inject anything besides BeanManager if ( containerLifecycleObserverMethod && ! parameter . isAnnotationPresent ( Observes . class ) && ! parameter . isAnnotationPresent ( ObservesAsync . class ) && ! BeanManager . class . equals ( parameter . getBaseType ( ) ) ) { throw EventLogger . LOG . invalidInjectionPoint ( this , Formats . formatAsStackTraceElement ( annotated . getJavaMember ( ) ) ) ; } } }
Performs validation of the observer method for compliance with the specifications .