Search in sources :

Example 11 with AnnotatedType

use of javax.enterprise.inject.spi.AnnotatedType in project kie-wb-common by kiegroup.

the class ControllerExtensionTest method createAnnotatedType.

protected ProcessAnnotatedType createAnnotatedType(final Class aClass) {
    final ProcessAnnotatedType processAnnotatedType = mock(ProcessAnnotatedType.class);
    final AnnotatedType annotatedType = mock(AnnotatedType.class);
    when(processAnnotatedType.getAnnotatedType()).thenReturn(annotatedType);
    when(annotatedType.getJavaClass()).thenReturn(aClass);
    return processAnnotatedType;
}
Also used : ProcessAnnotatedType(javax.enterprise.inject.spi.ProcessAnnotatedType) ProcessAnnotatedType(javax.enterprise.inject.spi.ProcessAnnotatedType) AnnotatedType(javax.enterprise.inject.spi.AnnotatedType)

Example 12 with AnnotatedType

use of javax.enterprise.inject.spi.AnnotatedType in project core by weld.

the class JsonObjectsTest method getFooAnnotatedMethod.

private static AnnotatedMethod<Foo> getFooAnnotatedMethod(String name) {
    final Method method = findDeclaredFooMethod(name);
    return new AnnotatedMethod<Foo>() {

        @Override
        public List<AnnotatedParameter<Foo>> getParameters() {
            Type[] paramTypes = method.getGenericParameterTypes();
            if (paramTypes.length == 0) {
                return Collections.emptyList();
            }
            List<AnnotatedParameter<Foo>> params = new ArrayList<>();
            for (int i = 0; i < paramTypes.length; i++) {
                final Type baseType = paramTypes[i];
                final Annotation[] annotations = method.getParameterAnnotations()[i];
                params.add(new AnnotatedParameter<Foo>() {

                    @Override
                    public Type getBaseType() {
                        return baseType;
                    }

                    @Override
                    public Set<Type> getTypeClosure() {
                        throw new UnsupportedOperationException();
                    }

                    @Override
                    public <T extends Annotation> T getAnnotation(Class<T> annotationType) {
                        throw new UnsupportedOperationException();
                    }

                    @Override
                    public Set<Annotation> getAnnotations() {
                        return new HashSet<>(Arrays.asList(annotations));
                    }

                    @Override
                    public boolean isAnnotationPresent(Class<? extends Annotation> annotationType) {
                        throw new UnsupportedOperationException();
                    }

                    @Override
                    public int getPosition() {
                        throw new UnsupportedOperationException();
                    }

                    @Override
                    public AnnotatedCallable<Foo> getDeclaringCallable() {
                        throw new UnsupportedOperationException();
                    }
                });
            }
            return params;
        }

        @Override
        public boolean isStatic() {
            throw new UnsupportedOperationException();
        }

        @Override
        public AnnotatedType<Foo> getDeclaringType() {
            return new AnnotatedType<Foo>() {

                @Override
                public Type getBaseType() {
                    throw new UnsupportedOperationException();
                }

                @Override
                public Set<Type> getTypeClosure() {
                    throw new UnsupportedOperationException();
                }

                @Override
                public <T extends Annotation> T getAnnotation(Class<T> annotationType) {
                    throw new UnsupportedOperationException();
                }

                @Override
                public Set<Annotation> getAnnotations() {
                    throw new UnsupportedOperationException();
                }

                @Override
                public boolean isAnnotationPresent(Class<? extends Annotation> annotationType) {
                    throw new UnsupportedOperationException();
                }

                @Override
                public Class<Foo> getJavaClass() {
                    return Foo.class;
                }

                @Override
                public Set<AnnotatedConstructor<Foo>> getConstructors() {
                    throw new UnsupportedOperationException();
                }

                @Override
                public Set<AnnotatedMethod<? super Foo>> getMethods() {
                    throw new UnsupportedOperationException();
                }

                @Override
                public Set<AnnotatedField<? super Foo>> getFields() {
                    throw new UnsupportedOperationException();
                }
            };
        }

        @Override
        public Type getBaseType() {
            throw new UnsupportedOperationException();
        }

        @Override
        public Set<Type> getTypeClosure() {
            throw new UnsupportedOperationException();
        }

        @Override
        public <T extends Annotation> T getAnnotation(Class<T> annotationType) {
            throw new UnsupportedOperationException();
        }

        @Override
        public Set<Annotation> getAnnotations() {
            return new HashSet<>(Arrays.asList(method.getAnnotations()));
        }

        @Override
        public boolean isAnnotationPresent(Class<? extends Annotation> annotationType) {
            throw new UnsupportedOperationException();
        }

        @Override
        public Method getJavaMember() {
            return method;
        }
    };
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) AnnotatedMethod(javax.enterprise.inject.spi.AnnotatedMethod) AnnotatedParameter(javax.enterprise.inject.spi.AnnotatedParameter) ArrayList(java.util.ArrayList) AnnotatedCallable(javax.enterprise.inject.spi.AnnotatedCallable) AnnotatedConstructor(javax.enterprise.inject.spi.AnnotatedConstructor) HashSet(java.util.HashSet) Method(java.lang.reflect.Method) AnnotatedMethod(javax.enterprise.inject.spi.AnnotatedMethod) Annotation(java.lang.annotation.Annotation) AnnotatedType(javax.enterprise.inject.spi.AnnotatedType) Type(java.lang.reflect.Type) AnnotatedType(javax.enterprise.inject.spi.AnnotatedType) AnnotatedField(javax.enterprise.inject.spi.AnnotatedField)

Example 13 with AnnotatedType

use of javax.enterprise.inject.spi.AnnotatedType in project core by weld.

the class WeldClassTest method testMemberClassWithGenericTypes.

/*
    * description = "WELD-216"
    */
@Test
public void testMemberClassWithGenericTypes() {
    final AnnotatedType<?> at = transformer.getEnhancedAnnotatedType(new Kangaroo().procreate().getClass(), AnnotatedTypeIdentifier.NULL_BDA_ID);
    transformer.getEnhancedAnnotatedType(new ForwardingAnnotatedType() {

        @Override
        public AnnotatedType delegate() {
            return at;
        }
    }, AnnotatedTypeIdentifier.NULL_BDA_ID);
}
Also used : ForwardingAnnotatedType(org.jboss.weld.util.annotated.ForwardingAnnotatedType) AnnotatedType(javax.enterprise.inject.spi.AnnotatedType) EnhancedAnnotatedType(org.jboss.weld.annotated.enhanced.EnhancedAnnotatedType) ForwardingAnnotatedType(org.jboss.weld.util.annotated.ForwardingAnnotatedType) Test(org.junit.Test)

Example 14 with AnnotatedType

use of javax.enterprise.inject.spi.AnnotatedType in project core by weld.

the class WeldClassTest method testLocalClassWithGenericTypes.

/*
    * description = "WELD-216"
    */
@Test
public /*
    *  Not isolated, depends on someone else initializing Containers.
    *
    *  getUnproxyableClassException() catch(NoSuchMethodException)
    *           InstantiatorFactory.useInstantiators() <-- Needs Containers
    */
void testLocalClassWithGenericTypes() {
    final AnnotatedType<?> at = transformer.getEnhancedAnnotatedType(new Koala().procreate().getClass(), AnnotatedTypeIdentifier.NULL_BDA_ID);
    transformer.getEnhancedAnnotatedType(new ForwardingAnnotatedType() {

        @Override
        public AnnotatedType delegate() {
            return at;
        }
    }, AnnotatedTypeIdentifier.NULL_BDA_ID);
}
Also used : ForwardingAnnotatedType(org.jboss.weld.util.annotated.ForwardingAnnotatedType) AnnotatedType(javax.enterprise.inject.spi.AnnotatedType) EnhancedAnnotatedType(org.jboss.weld.annotated.enhanced.EnhancedAnnotatedType) ForwardingAnnotatedType(org.jboss.weld.util.annotated.ForwardingAnnotatedType) Test(org.junit.Test)

Example 15 with AnnotatedType

use of javax.enterprise.inject.spi.AnnotatedType in project core by weld.

the class WeldClassTest method testAnonymousClassWithGenericTypes.

/*
    * description = "WELD-216"
    */
@Test
public /*
    *  Not isolated, depends on someone else initializing Containers.
    *
    *  getUnproxyableClassException() catch(NoSuchMethodException)
    *           InstantiatorFactory.useInstantiators() <-- Needs Containers
    */
void testAnonymousClassWithGenericTypes() {
    final AnnotatedType<?> at = transformer.getEnhancedAnnotatedType(new Possum().procreate().getClass(), AnnotatedTypeIdentifier.NULL_BDA_ID);
    transformer.getEnhancedAnnotatedType(new ForwardingAnnotatedType() {

        @Override
        public AnnotatedType delegate() {
            return at;
        }
    }, AnnotatedTypeIdentifier.NULL_BDA_ID);
}
Also used : ForwardingAnnotatedType(org.jboss.weld.util.annotated.ForwardingAnnotatedType) AnnotatedType(javax.enterprise.inject.spi.AnnotatedType) EnhancedAnnotatedType(org.jboss.weld.annotated.enhanced.EnhancedAnnotatedType) ForwardingAnnotatedType(org.jboss.weld.util.annotated.ForwardingAnnotatedType) Test(org.junit.Test)

Aggregations

AnnotatedType (javax.enterprise.inject.spi.AnnotatedType)24 AnnotatedMethod (javax.enterprise.inject.spi.AnnotatedMethod)7 Annotation (java.lang.annotation.Annotation)5 Method (java.lang.reflect.Method)5 Type (java.lang.reflect.Type)5 HashSet (java.util.HashSet)4 Set (java.util.Set)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 ProcessAnnotatedType (javax.enterprise.inject.spi.ProcessAnnotatedType)4 Test (org.junit.Test)4 InjectionTarget (javax.enterprise.inject.spi.InjectionTarget)3 EnhancedAnnotatedType (org.jboss.weld.annotated.enhanced.EnhancedAnnotatedType)3 ForwardingAnnotatedType (org.jboss.weld.util.annotated.ForwardingAnnotatedType)3 Field (java.lang.reflect.Field)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Logger (java.util.logging.Logger)2 CreationalContext (javax.enterprise.context.spi.CreationalContext)2 Alternative (javax.enterprise.inject.Alternative)2