Search in sources :

Example 1 with PlugableValidator

use of org.jboss.weld.module.PlugableValidator in project core by weld.

the class Validator method validateInjectionPointForDefinitionErrors.

/**
 * Checks for definition errors associated with a given {@link InjectionPoint}
 */
public void validateInjectionPointForDefinitionErrors(InjectionPoint ij, Bean<?> bean, BeanManagerImpl beanManager) {
    if (ij.getAnnotated().getAnnotation(New.class) != null && ij.getQualifiers().size() > 1) {
        throw ValidatorLogger.LOG.newWithQualifiers(ij, Formats.formatAsStackTraceElement(ij));
    }
    if (ij.getType() instanceof TypeVariable<?>) {
        throw ValidatorLogger.LOG.injectionPointWithTypeVariable(ij, Formats.formatAsStackTraceElement(ij));
    }
    // WELD-1739
    if (ij.getMember() instanceof Executable && ij.getAnnotated().isAnnotationPresent(Named.class) && ij.getAnnotated().getAnnotation(Named.class).value().equals("")) {
        Executable executable = (Executable) ij.getMember();
        AnnotatedParameter<?> annotatedParameter = (AnnotatedParameter<?>) ij.getAnnotated();
        if (!executable.getParameters()[annotatedParameter.getPosition()].isNamePresent()) {
            // No parameters info available
            throw ValidatorLogger.LOG.nonFieldInjectionPointCannotUseNamed(ij, Formats.formatAsStackTraceElement(ij));
        }
    }
    if (ij.getAnnotated().isAnnotationPresent(Produces.class)) {
        if (bean != null) {
            throw BeanLogger.LOG.injectedFieldCannotBeProducer(ij.getAnnotated(), bean);
        } else {
            throw BeanLogger.LOG.injectedFieldCannotBeProducer(ij.getAnnotated(), Reflections.<AnnotatedField<?>>cast(ij.getAnnotated()).getDeclaringType());
        }
    }
    boolean newBean = (bean instanceof NewBean);
    if (!newBean) {
        checkScopeAnnotations(ij, beanManager.getServices().get(MetaAnnotationStore.class));
    }
    checkFacadeInjectionPoint(ij, Instance.class);
    checkFacadeInjectionPoint(ij, Event.class);
    if (InterceptionFactory.class.equals(Reflections.getRawType(ij.getType())) && !(bean instanceof ProducerMethod<?, ?>)) {
        throw ValidatorLogger.LOG.invalidInterceptionFactoryInjectionPoint(ij, Formats.formatAsStackTraceElement(ij));
    }
    for (PlugableValidator validator : plugableValidators) {
        validator.validateInjectionPointForDefinitionErrors(ij, bean, beanManager);
    }
}
Also used : PlugableValidator(org.jboss.weld.module.PlugableValidator) Named(javax.inject.Named) TypeVariable(java.lang.reflect.TypeVariable) AnnotatedParameter(javax.enterprise.inject.spi.AnnotatedParameter) MetaAnnotationStore(org.jboss.weld.metadata.cache.MetaAnnotationStore) NewBean(org.jboss.weld.bean.NewBean) InterceptionFactory(javax.enterprise.inject.spi.InterceptionFactory) Executable(java.lang.reflect.Executable) AnnotatedField(javax.enterprise.inject.spi.AnnotatedField)

Aggregations

Executable (java.lang.reflect.Executable)1 TypeVariable (java.lang.reflect.TypeVariable)1 AnnotatedField (javax.enterprise.inject.spi.AnnotatedField)1 AnnotatedParameter (javax.enterprise.inject.spi.AnnotatedParameter)1 InterceptionFactory (javax.enterprise.inject.spi.InterceptionFactory)1 Named (javax.inject.Named)1 NewBean (org.jboss.weld.bean.NewBean)1 MetaAnnotationStore (org.jboss.weld.metadata.cache.MetaAnnotationStore)1 PlugableValidator (org.jboss.weld.module.PlugableValidator)1