Search in sources :

Example 1 with ImmutableInjectionPoint

use of org.apache.deltaspike.core.util.metadata.builder.ImmutableInjectionPoint in project deltaspike by apache.

the class BeanUtils method createInjectionPoints.

/**
     * Given a method, and the bean on which the method is declared, create a
     * collection of injection points representing the parameters of the method.
     *
     * @param <X>           the type declaring the method
     * @param method        the method
     * @param declaringBean the bean on which the method is declared
     * @param beanManager   the bean manager to use to create the injection points
     * @return the injection points
     */
public static <X> List<InjectionPoint> createInjectionPoints(AnnotatedMethod<X> method, Bean<?> declaringBean, BeanManager beanManager) {
    List<InjectionPoint> injectionPoints = new ArrayList<InjectionPoint>();
    for (AnnotatedParameter<X> parameter : method.getParameters()) {
        InjectionPoint injectionPoint = new ImmutableInjectionPoint(parameter, beanManager, declaringBean, false, false);
        injectionPoints.add(injectionPoint);
    }
    return injectionPoints;
}
Also used : ImmutableInjectionPoint(org.apache.deltaspike.core.util.metadata.builder.ImmutableInjectionPoint) InjectionPoint(javax.enterprise.inject.spi.InjectionPoint) ArrayList(java.util.ArrayList) ImmutableInjectionPoint(org.apache.deltaspike.core.util.metadata.builder.ImmutableInjectionPoint)

Example 2 with ImmutableInjectionPoint

use of org.apache.deltaspike.core.util.metadata.builder.ImmutableInjectionPoint in project deltaspike by apache.

the class BeanBuilderTest method assertNonNullInjectionPointsWhenOverriding.

@Test
public void assertNonNullInjectionPointsWhenOverriding() {
    final BeanBuilder beanBuilder = new BeanBuilder(beanManager);
    final AnnotatedType<?> at = beanManager.createAnnotatedType(WithInjectionPoint.class);
    beanBuilder.readFromType(at);
    // It's not easy to actually create these in the state we need, so we have to get the InjectionPonits,
    // create new ones with the correct info, null out the bean, set them as the new injection points
    // then move on.
    final Set<InjectionPoint> origInjectionPoints = beanBuilder.getInjectionPoints();
    beanBuilder.injectionPoints(beanBuilder.getInjectionPoints());
    final Set<InjectionPoint> newInjectionPoints = new HashSet<InjectionPoint>();
    for (InjectionPoint ip : origInjectionPoints) {
        newInjectionPoints.add(new ImmutableInjectionPoint((AnnotatedField) ip.getAnnotated(), ip.getQualifiers(), null, ip.isTransient(), ip.isDelegate()));
    }
    beanBuilder.injectionPoints(newInjectionPoints);
    final Bean<?> newInjectionBean = beanBuilder.create();
    for (final InjectionPoint ip : newInjectionBean.getInjectionPoints()) {
        Assert.assertNotNull(ip);
    }
}
Also used : BeanBuilder(org.apache.deltaspike.core.util.bean.BeanBuilder) ImmutableInjectionPoint(org.apache.deltaspike.core.util.metadata.builder.ImmutableInjectionPoint) InjectionPoint(javax.enterprise.inject.spi.InjectionPoint) AnnotatedField(javax.enterprise.inject.spi.AnnotatedField) ImmutableInjectionPoint(org.apache.deltaspike.core.util.metadata.builder.ImmutableInjectionPoint) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

InjectionPoint (javax.enterprise.inject.spi.InjectionPoint)2 ImmutableInjectionPoint (org.apache.deltaspike.core.util.metadata.builder.ImmutableInjectionPoint)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 AnnotatedField (javax.enterprise.inject.spi.AnnotatedField)1 BeanBuilder (org.apache.deltaspike.core.util.bean.BeanBuilder)1 Test (org.junit.Test)1