Search in sources :

Example 1 with InjectionPoint

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());
}
Also used : InjectionPoint(jakarta.enterprise.inject.spi.InjectionPoint) Test(org.junit.Test)

Example 2 with InjectionPoint

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());
}
Also used : InjectionPoint(jakarta.enterprise.inject.spi.InjectionPoint) Test(org.junit.Test)

Example 3 with InjectionPoint

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());
    }
}
Also used : InjectionPoint(jakarta.enterprise.inject.spi.InjectionPoint) WeldContainer(org.jboss.weld.environment.se.WeldContainer) Weld(org.jboss.weld.environment.se.Weld) Test(org.junit.Test)

Example 4 with InjectionPoint

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);
        }
    }
}
Also used : InjectionPoint(jakarta.enterprise.inject.spi.InjectionPoint)

Example 5 with InjectionPoint

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;
}
Also used : InjectionPoint(jakarta.enterprise.inject.spi.InjectionPoint) AmbiguousResolutionException(jakarta.enterprise.inject.AmbiguousResolutionException) Annotation(java.lang.annotation.Annotation) HashSet(java.util.HashSet) SessionBean(org.jboss.weld.bean.SessionBean) ExtensionBean(org.jboss.weld.bean.builtin.ExtensionBean) Bean(jakarta.enterprise.inject.spi.Bean) ForwardingBean(org.jboss.weld.bean.ForwardingBean) ManagedBean(org.jboss.weld.bean.ManagedBean) AbstractBuiltInBean(org.jboss.weld.bean.builtin.AbstractBuiltInBean)

Aggregations

InjectionPoint (jakarta.enterprise.inject.spi.InjectionPoint)58 Test (org.junit.Test)22 Annotation (java.lang.annotation.Annotation)17 ProcessInjectionPoint (jakarta.enterprise.inject.spi.ProcessInjectionPoint)16 Type (java.lang.reflect.Type)14 ParameterizedType (java.lang.reflect.ParameterizedType)7 Default (jakarta.enterprise.inject.Default)6 Bean (jakarta.enterprise.inject.spi.Bean)6 Named (jakarta.inject.Named)6 AnnotatedParameter (jakarta.enterprise.inject.spi.AnnotatedParameter)4 ApplicationScoped (jakarta.enterprise.context.ApplicationScoped)3 CreationalContext (jakarta.enterprise.context.spi.CreationalContext)3 AmbiguousResolutionException (jakarta.enterprise.inject.AmbiguousResolutionException)3 Annotated (jakarta.enterprise.inject.spi.Annotated)3 AnnotatedType (jakarta.enterprise.inject.spi.AnnotatedType)3 BeanManager (jakarta.enterprise.inject.spi.BeanManager)3 Decorator (jakarta.enterprise.inject.spi.Decorator)3 HashSet (java.util.HashSet)3 Set (java.util.Set)3 Dependent (jakarta.enterprise.context.Dependent)2