Search in sources :

Example 1 with AnnotatedParameter

use of javax.enterprise.inject.spi.AnnotatedParameter in project deltaspike by apache.

the class AnnotatedTypeBuilderTest method modifyAnnotationsOnConstructorParameter.

@Test
public void modifyAnnotationsOnConstructorParameter() throws NoSuchMethodException {
    final AnnotatedTypeBuilder<Cat> builder = new AnnotatedTypeBuilder<Cat>();
    builder.readFromType(Cat.class, true);
    builder.removeFromConstructorParameter(Cat.class.getConstructor(String.class, String.class), 1, Default.class);
    builder.addToConstructorParameter(Cat.class.getConstructor(String.class, String.class), 1, new AnyLiteral());
    final AnnotatedType<Cat> catAnnotatedType = builder.create();
    Set<AnnotatedConstructor<Cat>> catCtors = catAnnotatedType.getConstructors();
    assertThat(catCtors.size(), is(2));
    for (AnnotatedConstructor<Cat> ctor : catCtors) {
        if (ctor.getParameters().size() == 2) {
            List<AnnotatedParameter<Cat>> ctorParams = ctor.getParameters();
            assertThat(ctorParams.get(1).getAnnotations().size(), is(1));
            assertThat((AnyLiteral) ctorParams.get(1).getAnnotations().toArray()[0], is(new AnyLiteral()));
        }
    }
}
Also used : AnnotatedTypeBuilder(org.apache.deltaspike.core.util.metadata.builder.AnnotatedTypeBuilder) AnnotatedConstructor(javax.enterprise.inject.spi.AnnotatedConstructor) AnnotatedParameter(javax.enterprise.inject.spi.AnnotatedParameter) AnyLiteral(org.apache.deltaspike.core.api.literal.AnyLiteral) Test(org.junit.Test)

Example 2 with AnnotatedParameter

use of javax.enterprise.inject.spi.AnnotatedParameter in project deltaspike by apache.

the class AnnotatedCallableImpl method getAnnotatedParameters.

private static <X, Y extends Member> List<AnnotatedParameter<X>> getAnnotatedParameters(AnnotatedCallableImpl<X, Y> callable, Class<?>[] parameterTypes, Type[] genericTypes, Map<Integer, AnnotationStore> parameterAnnotations, Map<Integer, Type> parameterTypeOverrides) {
    List<AnnotatedParameter<X>> parameters = new ArrayList<AnnotatedParameter<X>>();
    int len = parameterTypes.length;
    for (int i = 0; i < len; ++i) {
        AnnotationBuilder builder = new AnnotationBuilder();
        if (parameterAnnotations != null && parameterAnnotations.containsKey(i)) {
            builder.addAll(parameterAnnotations.get(i));
        }
        Type over = null;
        if (parameterTypeOverrides != null) {
            over = parameterTypeOverrides.get(i);
        }
        AnnotatedParameterImpl<X> p = new AnnotatedParameterImpl<X>(callable, parameterTypes[i], i, builder.create(), genericTypes[i], over);
        parameters.add(p);
    }
    return parameters;
}
Also used : Type(java.lang.reflect.Type) AnnotatedType(javax.enterprise.inject.spi.AnnotatedType) AnnotatedParameter(javax.enterprise.inject.spi.AnnotatedParameter) ArrayList(java.util.ArrayList)

Aggregations

AnnotatedParameter (javax.enterprise.inject.spi.AnnotatedParameter)2 Type (java.lang.reflect.Type)1 ArrayList (java.util.ArrayList)1 AnnotatedConstructor (javax.enterprise.inject.spi.AnnotatedConstructor)1 AnnotatedType (javax.enterprise.inject.spi.AnnotatedType)1 AnyLiteral (org.apache.deltaspike.core.api.literal.AnyLiteral)1 AnnotatedTypeBuilder (org.apache.deltaspike.core.util.metadata.builder.AnnotatedTypeBuilder)1 Test (org.junit.Test)1