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;
}
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);
}
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;
}
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;
}
}
}
}
}
}
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);
}
}
Aggregations