use of jakarta.enterprise.inject.spi.InjectionPoint in project core by weld.
the class CreateInjectionPointTest method testMethodParameter.
@Test
public void testMethodParameter() {
AnnotatedType<?> type = manager.createAnnotatedType(Library.class);
assertEquals(1, type.getMethods().size());
AnnotatedMethod<?> method = type.getMethods().iterator().next();
AnnotatedParameter<?> parameter = method.getParameters().get(2);
InjectionPoint ip = manager.createInjectionPoint(parameter);
validateParameterizedType(ip.getType(), Book.class, Integer.class);
BeanUtilities.verifyQualifierTypes(ip.getQualifiers(), Default.class);
assertNull(ip.getBean());
assertEquals(method.getJavaMember(), ip.getMember());
assertNotNull(ip.getAnnotated());
assertFalse(ip.isDelegate());
assertFalse(ip.isTransient());
}
use of jakarta.enterprise.inject.spi.InjectionPoint in project core by weld.
the class CreateInjectionPointTest method testConstructorParameter.
@Test
public void testConstructorParameter() {
AnnotatedType<?> type = manager.createAnnotatedType(Library.class);
assertEquals(1, type.getConstructors().size());
AnnotatedConstructor<?> constructor = type.getConstructors().iterator().next();
AnnotatedParameter<?> parameter = constructor.getParameters().get(1);
InjectionPoint ip = manager.createInjectionPoint(parameter);
validateParameterizedType(ip.getType(), Book.class, String.class);
BeanUtilities.verifyQualifierTypes(ip.getQualifiers(), Fictional.class);
assertNull(ip.getBean());
assertEquals(constructor.getJavaMember(), ip.getMember());
assertNotNull(ip.getAnnotated());
assertFalse(ip.isDelegate());
assertFalse(ip.isTransient());
}
use of jakarta.enterprise.inject.spi.InjectionPoint in project core by weld.
the class InjectionPointTest method testInjectionPoint.
@Test
public void testInjectionPoint() throws Exception {
try (WeldContainer weld = new Weld().disableDiscovery().beanClasses(Foo.class).initialize()) {
final InjectionPoint ip = weld.select(Foo.class).get().getIp();
assertEquals(Foo.class, ip.getType());
}
}
use of jakarta.enterprise.inject.spi.InjectionPoint in project core by weld.
the class Validator method validateObserverMethods.
protected void validateObserverMethods(Iterable<ObserverInitializationContext<?, ?>> observers, BeanManagerImpl beanManager) {
for (ObserverInitializationContext<?, ?> omi : observers) {
for (InjectionPoint ip : omi.getObserver().getInjectionPoints()) {
validateInjectionPointForDefinitionErrors(ip, ip.getBean(), beanManager);
validateMetadataInjectionPoint(ip, null, ValidatorLogger.INJECTION_INTO_NON_BEAN);
validateInjectionPointForDeploymentProblems(ip, ip.getBean(), beanManager);
}
}
}
use of jakarta.enterprise.inject.spi.InjectionPoint in project core by weld.
the class Components method getDependencies.
/**
* @param bean
* @param beanManager
* @param probe
* @return the set of dependencies
*/
static Set<Dependency> getDependencies(Bean<?> bean, BeanManager beanManager, Probe probe) {
Set<Dependency> dependencies = new HashSet<Dependency>();
Set<InjectionPoint> injectionPoints = bean.getInjectionPoints();
if (injectionPoints != null && !injectionPoints.isEmpty()) {
for (InjectionPoint injectionPoint : injectionPoints) {
if (injectionPoint.isDelegate()) {
// Do not include delegate injection points
continue;
}
Set<Bean<?>> beans = beanManager.getBeans(injectionPoint.getType(), injectionPoint.getQualifiers().toArray(new Annotation[injectionPoint.getQualifiers().size()]));
if (beans.isEmpty()) {
dependencies.add(Dependency.createUnsatisfied(injectionPoint, null));
} else {
try {
Bean<?> dependency = beanManager.resolve(beans);
if (isBuiltinBeanButNotExtension(dependency)) {
dependency = probe.getBean(Components.getBuiltinBeanId((AbstractBuiltInBean<?>) dependency));
}
dependencies.add(new Dependency(dependency, injectionPoint));
} catch (AmbiguousResolutionException e) {
dependencies.add(Dependency.createAmbiguous(injectionPoint, null));
}
}
}
}
return dependencies;
}
Aggregations