Search in sources :

Example 1 with AnnotatedParameter

use of jakarta.enterprise.inject.spi.AnnotatedParameter in project core by weld.

the class ObserverMethodConfiguratorImpl method read.

@Override
public ObserverMethodConfigurator<T> read(AnnotatedMethod<?> method) {
    checkArgumentNotNull(method);
    Set<AnnotatedParameter<?>> eventParameters = method.getParameters().stream().filter((p) -> p.isAnnotationPresent(Observes.class) || p.isAnnotationPresent(ObservesAsync.class)).collect(Collectors.toSet());
    checkEventParams(eventParameters, method.getJavaMember());
    AnnotatedParameter<?> eventParameter = eventParameters.iterator().next();
    Observes observesAnnotation = eventParameter.getAnnotation(Observes.class);
    if (observesAnnotation != null) {
        reception(observesAnnotation.notifyObserver());
        transactionPhase(observesAnnotation.during());
        async(false);
    } else {
        reception(eventParameter.getAnnotation(ObservesAsync.class).notifyObserver());
        async(true);
    }
    Priority priority = method.getAnnotation(Priority.class);
    if (priority != null) {
        priority(priority.value());
    }
    beanClass(eventParameter.getDeclaringCallable().getDeclaringType().getJavaClass());
    observedType(eventParameter.getBaseType());
    qualifiers(Configurators.getQualifiers(eventParameter));
    return this;
}
Also used : EventLogger(org.jboss.weld.logging.EventLogger) Observes(jakarta.enterprise.event.Observes) ObserverMethodConfigurator(jakarta.enterprise.inject.spi.configurator.ObserverMethodConfigurator) Preconditions.checkArgumentNotNull(org.jboss.weld.util.Preconditions.checkArgumentNotNull) Reception(jakarta.enterprise.event.Reception) ObservesAsync(jakarta.enterprise.event.ObservesAsync) HashSet(java.util.HashSet) AnnotatedMethod(jakarta.enterprise.inject.spi.AnnotatedMethod) Extension(jakarta.enterprise.inject.spi.Extension) AnnotatedParameter(jakarta.enterprise.inject.spi.AnnotatedParameter) Parameter(java.lang.reflect.Parameter) ObserverException(jakarta.enterprise.event.ObserverException) Formats(org.jboss.weld.util.reflection.Formats) Priority(jakarta.annotation.Priority) Method(java.lang.reflect.Method) TransactionPhase(jakarta.enterprise.event.TransactionPhase) SyntheticObserverMethod(org.jboss.weld.event.SyntheticObserverMethod) CovariantTypes(org.jboss.weld.resolution.CovariantTypes) ImmutableSet(org.jboss.weld.util.collections.ImmutableSet) Set(java.util.Set) ObserverMethod(jakarta.enterprise.inject.spi.ObserverMethod) Collectors(java.util.stream.Collectors) EventContext(jakarta.enterprise.inject.spi.EventContext) Type(java.lang.reflect.Type) Annotation(java.lang.annotation.Annotation) Collections(java.util.Collections) ObservesAsync(jakarta.enterprise.event.ObservesAsync) AnnotatedParameter(jakarta.enterprise.inject.spi.AnnotatedParameter) Observes(jakarta.enterprise.event.Observes) Priority(jakarta.annotation.Priority)

Example 2 with AnnotatedParameter

use of jakarta.enterprise.inject.spi.AnnotatedParameter in project core by weld.

the class InterceptionFactoryBean method newInstance.

@Override
protected InterceptionFactory<?> newInstance(InjectionPoint ip, CreationalContext<InterceptionFactory<?>> creationalContext) {
    AnnotatedParameter<?> annotatedParameter = (AnnotatedParameter<?>) ip.getAnnotated();
    ParameterizedType parameterizedType = (ParameterizedType) annotatedParameter.getBaseType();
    AnnotatedType<?> annotatedType = beanManager.createAnnotatedType(Reflections.getRawType(parameterizedType.getActualTypeArguments()[0]));
    return InterceptionFactoryImpl.of(beanManager, creationalContext, annotatedType);
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) AnnotatedParameter(jakarta.enterprise.inject.spi.AnnotatedParameter)

Example 3 with AnnotatedParameter

use of jakarta.enterprise.inject.spi.AnnotatedParameter in project helidon by oracle.

the class JpaExtension method isEligiblePersistenceUnitSetterMethod.

/**
 * Returns {@code true} if the supplied {@link AnnotatedMethod} is
 * annotated with {@link PersistenceUnit}, is not annotated with
 * {@link Inject} and has at least one parameter whose type is
 * assignable to {@link EntityManagerFactory}.
 *
 * @param m the {@link AnnotatedMethod} in question; may be {@code
 * null} in which case {@code false} will be returned
 *
 * @return {@code true} if the supplied {@link AnnotatedMethod} is
 * annotated with {@link PersistenceUnit}, is not annotated with
 * {@link Inject} and has at least one parameter whose type is
 * assignable to {@link EntityManagerFactory}
 */
private static <T> boolean isEligiblePersistenceUnitSetterMethod(final AnnotatedMethod<T> m) {
    final String cn = JpaExtension.class.getName();
    final String mn = "isEligiblePersistenceUnitSetterMethod";
    if (LOGGER.isLoggable(Level.FINER)) {
        LOGGER.entering(cn, mn, m);
    }
    final boolean returnValue;
    if (m != null && m.isAnnotationPresent(PersistenceUnit.class) && !m.isAnnotationPresent(Inject.class)) {
        final List<AnnotatedParameter<T>> parameters = m.getParameters();
        if (parameters != null && !parameters.isEmpty()) {
            boolean temp = false;
            for (final Annotated parameter : parameters) {
                final Type type = parameter.getBaseType();
                if (type instanceof Class && EntityManagerFactory.class.isAssignableFrom((Class<?>) type)) {
                    if (temp) {
                        temp = false;
                        break;
                    } else {
                        temp = true;
                    }
                }
            }
            returnValue = temp;
        } else {
            returnValue = false;
        }
    } else {
        returnValue = false;
    }
    if (LOGGER.isLoggable(Level.FINER)) {
        LOGGER.exiting(cn, mn, Boolean.valueOf(returnValue));
    }
    return returnValue;
}
Also used : Annotated(jakarta.enterprise.inject.spi.Annotated) SynchronizationType(jakarta.persistence.SynchronizationType) PersistenceContextType(jakarta.persistence.PersistenceContextType) Type(java.lang.reflect.Type) AnnotatedType(jakarta.enterprise.inject.spi.AnnotatedType) ProcessAnnotatedType(jakarta.enterprise.inject.spi.ProcessAnnotatedType) AnnotatedParameter(jakarta.enterprise.inject.spi.AnnotatedParameter) EntityManagerFactory(jakarta.persistence.EntityManagerFactory)

Example 4 with AnnotatedParameter

use of jakarta.enterprise.inject.spi.AnnotatedParameter in project helidon by oracle.

the class ConfigCdiExtension method harvestConfigPropertyInjectionPointsFromEnabledObserverMethod.

private <X> void harvestConfigPropertyInjectionPointsFromEnabledObserverMethod(@Observes ProcessObserverMethod<?, X> event, BeanManager beanManager) {
    AnnotatedMethod<X> annotatedMethod = event.getAnnotatedMethod();
    List<AnnotatedParameter<X>> annotatedParameters = annotatedMethod.getParameters();
    if (annotatedParameters != null) {
        for (AnnotatedParameter<?> annotatedParameter : annotatedParameters) {
            if ((annotatedParameter != null) && !annotatedParameter.isAnnotationPresent(Observes.class)) {
                InjectionPoint injectionPoint = beanManager.createInjectionPoint(annotatedParameter);
                Set<Annotation> qualifiers = injectionPoint.getQualifiers();
                assert qualifiers != null;
                for (Annotation qualifier : qualifiers) {
                    if (qualifier instanceof ConfigProperty) {
                        ips.add(injectionPoint);
                        break;
                    }
                }
            }
        }
    }
}
Also used : InjectionPoint(jakarta.enterprise.inject.spi.InjectionPoint) AnnotatedParameter(jakarta.enterprise.inject.spi.AnnotatedParameter) ConfigProperty(org.eclipse.microprofile.config.inject.ConfigProperty) Annotation(java.lang.annotation.Annotation)

Example 5 with AnnotatedParameter

use of jakarta.enterprise.inject.spi.AnnotatedParameter 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.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());
        }
    }
    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(jakarta.inject.Named) TypeVariable(java.lang.reflect.TypeVariable) AnnotatedParameter(jakarta.enterprise.inject.spi.AnnotatedParameter) MetaAnnotationStore(org.jboss.weld.metadata.cache.MetaAnnotationStore) InterceptionFactory(jakarta.enterprise.inject.spi.InterceptionFactory) Executable(java.lang.reflect.Executable) AnnotatedField(jakarta.enterprise.inject.spi.AnnotatedField)

Aggregations

AnnotatedParameter (jakarta.enterprise.inject.spi.AnnotatedParameter)13 AnnotatedField (jakarta.enterprise.inject.spi.AnnotatedField)5 Method (java.lang.reflect.Method)5 Annotated (jakarta.enterprise.inject.spi.Annotated)4 AnnotatedMethod (jakarta.enterprise.inject.spi.AnnotatedMethod)4 Member (java.lang.reflect.Member)4 Type (java.lang.reflect.Type)4 AnnotatedType (jakarta.enterprise.inject.spi.AnnotatedType)3 InjectionPoint (jakarta.enterprise.inject.spi.InjectionPoint)3 Annotation (java.lang.annotation.Annotation)3 ProcessAnnotatedType (jakarta.enterprise.inject.spi.ProcessAnnotatedType)2 Named (jakarta.inject.Named)2 PersistenceContextType (jakarta.persistence.PersistenceContextType)2 SynchronizationType (jakarta.persistence.SynchronizationType)2 Constructor (java.lang.reflect.Constructor)2 Executable (java.lang.reflect.Executable)2 Parameter (java.lang.reflect.Parameter)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 Priority (jakarta.annotation.Priority)1