Search in sources :

Example 16 with ClassesArchive

use of org.apache.xbean.finder.archive.ClassesArchive in project geronimo-xbean by apache.

the class AnnotatedParametersTest method testFindAnnotatedMethodParameters.

@Test
public void testFindAnnotatedMethodParameters() {
    final AnnotationFinder finder = new AnnotationFinder(new ClassesArchive(FullyAnnotated.class, NotAnnotated.class));
    List<Parameter<Method>> methodParameters = finder.findAnnotatedMethodParameters(ParamA.class);
    assertEquals(1, methodParameters.size());
    Parameter<Method> parameter = methodParameters.get(0);
    assertEquals(0, parameter.getIndex());
    assertEquals(FullyAnnotated.class, parameter.getDeclaringExecutable().getDeclaringClass());
    assertEquals("setMoreStrings", parameter.getDeclaringExecutable().getName());
    assertEquals(1, parameter.getDeclaringExecutable().getParameterTypes().length);
    assertEquals(String[][].class, parameter.getDeclaringExecutable().getParameterTypes()[0]);
    assertTrue(parameter.isAnnotationPresent(ParamA.class));
}
Also used : ClassesArchive(org.apache.xbean.finder.archive.ClassesArchive) FullyAnnotated(org.acme.bar.FullyAnnotated) Method(java.lang.reflect.Method) ParamA(org.acme.bar.ParamA) NotAnnotated(org.acme.NotAnnotated) Test(org.junit.Test)

Example 17 with ClassesArchive

use of org.apache.xbean.finder.archive.ClassesArchive in project geronimo-xbean by apache.

the class AnnotatedParametersTest method testFindAnnotatedConstructorParameters.

@Test
public void testFindAnnotatedConstructorParameters() {
    final AnnotationFinder finder = new AnnotationFinder(new ClassesArchive(FullyAnnotated.class, NotAnnotated.class));
    List<Parameter<Constructor<?>>> constructorParameters = finder.findAnnotatedConstructorParameters(ParamA.class);
    assertEquals(1, constructorParameters.size());
    Parameter<Constructor<?>> parameter = constructorParameters.get(0);
    assertEquals(0, parameter.getIndex());
    assertEquals(FullyAnnotated.class, parameter.getDeclaringExecutable().getDeclaringClass());
    assertEquals(2, parameter.getDeclaringExecutable().getParameterTypes().length);
    assertEquals(String.class, parameter.getDeclaringExecutable().getParameterTypes()[0]);
    assertEquals(int.class, parameter.getDeclaringExecutable().getParameterTypes()[1]);
    assertTrue(parameter.isAnnotationPresent(ParamA.class));
}
Also used : Constructor(java.lang.reflect.Constructor) ClassesArchive(org.apache.xbean.finder.archive.ClassesArchive) FullyAnnotated(org.acme.bar.FullyAnnotated) ParamA(org.acme.bar.ParamA) NotAnnotated(org.acme.NotAnnotated) Test(org.junit.Test)

Example 18 with ClassesArchive

use of org.apache.xbean.finder.archive.ClassesArchive in project geronimo-xbean by apache.

the class ClassFinderDepthTest method testFindAnnotatedInterfaceImplementationsAfterGet.

public void testFindAnnotatedInterfaceImplementationsAfterGet() {
    for (int i = 0; i < 10; i++) {
        final ClassesArchive archive = new ClassesArchive(TargetImpl.class);
        for (final AnnotationFinder finder : new AnnotationFinder[] { new AnnotationFinder(archive) }) {
            assertEquals(Collections.singletonList(TargetImpl.class), finder.findAnnotatedClasses(Deprecated.class));
            finder.link();
            assertImplementations(finder, java.lang.annotation.Target.class, TargetImpl.class);
        }
    }
}
Also used : ClassesArchive(org.apache.xbean.finder.archive.ClassesArchive)

Example 19 with ClassesArchive

use of org.apache.xbean.finder.archive.ClassesArchive in project geronimo-xbean by apache.

the class FinderSelectTest method test.

@Test
public void test() throws Exception {
    final AnnotationFinder all = new AnnotationFinder(new ClassesArchive(Red.class, Green.class, Blue.class));
    final AnnotationFinder finder = all.select(Red.class.getName());
    final List<Class<?>> classes = finder.findAnnotatedClasses(Color.class);
    for (Class<?> aClass : classes) {
        System.out.println(aClass);
    }
}
Also used : ClassesArchive(org.apache.xbean.finder.archive.ClassesArchive) Test(org.junit.Test)

Example 20 with ClassesArchive

use of org.apache.xbean.finder.archive.ClassesArchive in project geronimo-xbean by apache.

the class ClassAnnotationFinderTest method checkClassAnnotationOnMethod.

@Test
public void checkClassAnnotationOnMethod() throws Exception {
    final AnnotationFinder finder = new AnnotationFinder(new ClassesArchive(ClassAnnotatedClass.class, NotAnnotated.class), false);
    final List<Method> annotations = finder.findAnnotatedMethods(ClassAnnotation.class);
    assertEquals(1, annotations.size());
    assertEquals(ClassAnnotatedClass.class.getDeclaredMethod("green"), annotations.get(0));
}
Also used : ClassAnnotatedClass(org.acme.ClassAnnotatedClass) ClassesArchive(org.apache.xbean.finder.archive.ClassesArchive) Method(java.lang.reflect.Method) NotAnnotated(org.acme.NotAnnotated) Test(org.junit.Test)

Aggregations

ClassesArchive (org.apache.xbean.finder.archive.ClassesArchive)33 Test (org.junit.Test)14 AnnotationFinder (org.apache.xbean.finder.AnnotationFinder)12 NotAnnotated (org.acme.NotAnnotated)10 ClassAnnotatedClass (org.acme.ClassAnnotatedClass)8 Method (java.lang.reflect.Method)7 URL (java.net.URL)7 CompositeArchive (org.apache.xbean.finder.archive.CompositeArchive)7 FilteredArchive (org.apache.xbean.finder.archive.FilteredArchive)7 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 EjbModule (org.apache.openejb.config.EjbModule)6 EjbJar (org.apache.openejb.jee.EjbJar)6 Archive (org.apache.xbean.finder.archive.Archive)6 MalformedURLException (java.net.MalformedURLException)5 AppModule (org.apache.openejb.config.AppModule)5 File (java.io.File)4 Field (java.lang.reflect.Field)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4