Search in sources :

Example 1 with AnnotatedConstructor

use of javax.enterprise.inject.spi.AnnotatedConstructor in project jersey by jersey.

the class CdiComponentProvider method processAnnotatedType.

@SuppressWarnings("unused")
private void processAnnotatedType(@Observes final //                                              PathParam.class})
ProcessAnnotatedType processAnnotatedType) {
    final AnnotatedType<?> annotatedType = processAnnotatedType.getAnnotatedType();
    // if one of the JAX-RS annotations is present in the currently seen class, add it to the "whitelist"
    if (containsJaxRsConstructorInjection(annotatedType) || containsJaxRsFieldInjection(annotatedType) || containsJaxRsMethodInjection(annotatedType)) {
        jaxrsInjectableTypes.add(annotatedType.getBaseType());
    }
    if (customHk2TypesProvider != null) {
        final Type baseType = annotatedType.getBaseType();
        if (customHk2TypesProvider.getHk2Types().contains(baseType)) {
            processAnnotatedType.veto();
            jerseyVetoedTypes.add(baseType);
        }
    }
    if (containsJaxRsParameterizedCtor(annotatedType)) {
        processAnnotatedType.setAnnotatedType(new AnnotatedType() {

            @Override
            public Class getJavaClass() {
                return annotatedType.getJavaClass();
            }

            @Override
            public Set<AnnotatedConstructor> getConstructors() {
                final Set<AnnotatedConstructor> result = new HashSet<>();
                for (final AnnotatedConstructor c : annotatedType.getConstructors()) {
                    result.add(enrichedConstructor(c));
                }
                return result;
            }

            @Override
            public Set getMethods() {
                return annotatedType.getMethods();
            }

            @Override
            public Set getFields() {
                return annotatedType.getFields();
            }

            @Override
            public Type getBaseType() {
                return annotatedType.getBaseType();
            }

            @Override
            public Set<Type> getTypeClosure() {
                return annotatedType.getTypeClosure();
            }

            @Override
            public <T extends Annotation> T getAnnotation(final Class<T> annotationType) {
                return annotatedType.getAnnotation(annotationType);
            }

            @Override
            public Set<Annotation> getAnnotations() {
                return annotatedType.getAnnotations();
            }

            @Override
            public boolean isAnnotationPresent(final Class<? extends Annotation> annotationType) {
                return annotatedType.isAnnotationPresent(annotationType);
            }
        });
    }
}
Also used : ProcessAnnotatedType(javax.enterprise.inject.spi.ProcessAnnotatedType) Type(java.lang.reflect.Type) AnnotatedType(javax.enterprise.inject.spi.AnnotatedType) ParameterizedType(java.lang.reflect.ParameterizedType) ProcessAnnotatedType(javax.enterprise.inject.spi.ProcessAnnotatedType) AnnotatedType(javax.enterprise.inject.spi.AnnotatedType) Set(java.util.Set) HashSet(java.util.HashSet) AnnotatedConstructor(javax.enterprise.inject.spi.AnnotatedConstructor)

Example 2 with AnnotatedConstructor

use of javax.enterprise.inject.spi.AnnotatedConstructor 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)

Aggregations

AnnotatedConstructor (javax.enterprise.inject.spi.AnnotatedConstructor)2 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 AnnotatedParameter (javax.enterprise.inject.spi.AnnotatedParameter)1 AnnotatedType (javax.enterprise.inject.spi.AnnotatedType)1 ProcessAnnotatedType (javax.enterprise.inject.spi.ProcessAnnotatedType)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