Search in sources :

Example 1 with A

use of spoon.test.visibility.testclasses.A in project spoon by INRIA.

the class VisibilityTest method testFullyQualifiedNameOfTypeReferenceWithGeneric.

@Test
public void testFullyQualifiedNameOfTypeReferenceWithGeneric() throws Exception {
    // contract: Generics are written when there are specified in the return type of a method.
    final String target = "./target/spooned/spoon/test/visibility_generics/testclasses/";
    final SpoonAPI launcher = new Launcher();
    launcher.addInputResource("./src/test/java/spoon/test/visibility/testclasses/A.java");
    launcher.addInputResource("./src/test/java/spoon/test/visibility/testclasses/A2.java");
    launcher.addInputResource("./src/test/java/spoon/test/visibility/testclasses/Foo.java");
    launcher.setSourceOutputDirectory(target);
    launcher.run();
    final CtClass<A> aClass = launcher.getFactory().Class().get(A.class);
    CtType<?> nestedB = aClass.getNestedType("B");
    List<CtFieldAccess> elements = nestedB.getElements(new TypeFilter<>(CtFieldAccess.class));
    assertEquals(1, elements.size());
    assertEquals("(spoon.test.visibility.testclasses.A.B.i)", elements.get(0).toString());
    CtMethod<?> instanceOf = aClass.getMethodsByName("instanceOf").get(0);
    List<CtBinaryOperator> elements1 = instanceOf.getElements(new TypeFilter<>(CtBinaryOperator.class));
    assertEquals(1, elements1.size());
    assertEquals("spoon.test.visibility.testclasses.A.B", elements1.get(0).getRightHandOperand().toString());
    CtMethod<?> returnType = aClass.getMethodsByName("returnType").get(0);
    assertEquals("spoon.test.visibility.testclasses.A<T>.C<T>", returnType.getType().toString());
    final CtClass<A2> secondClass = launcher.getFactory().Class().get(A2.class);
    nestedB = secondClass.getNestedType("B");
    elements = nestedB.getElements(new TypeFilter<>(CtFieldAccess.class));
    assertEquals(1, elements.size());
    assertEquals("(spoon.test.visibility.testclasses.A2.B.i)", elements.get(0).toString());
    instanceOf = secondClass.getMethodsByName("instanceOf").get(0);
    elements1 = instanceOf.getElements(new TypeFilter<>(CtBinaryOperator.class));
    assertEquals(1, elements1.size());
    assertEquals("spoon.test.visibility.testclasses.A2.B", elements1.get(0).getRightHandOperand().toString());
    returnType = secondClass.getMethodsByName("returnType").get(0);
    assertEquals("spoon.test.visibility.testclasses.A2.C<java.lang.String>", returnType.getType().toString());
    returnType = secondClass.getMethodsByName("returnType2").get(0);
    assertEquals("spoon.test.visibility.testclasses.Foo<java.lang.String>.Bar<java.lang.String>", returnType.getType().toString());
    canBeBuilt(target, 8);
}
Also used : A(spoon.test.visibility.testclasses.A) CtFieldAccess(spoon.reflect.code.CtFieldAccess) CtBinaryOperator(spoon.reflect.code.CtBinaryOperator) TypeFilter(spoon.reflect.visitor.filter.TypeFilter) A2(spoon.test.visibility.testclasses.A2) Launcher(spoon.Launcher) SpoonAPI(spoon.SpoonAPI) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 Launcher (spoon.Launcher)1 SpoonAPI (spoon.SpoonAPI)1 CtBinaryOperator (spoon.reflect.code.CtBinaryOperator)1 CtFieldAccess (spoon.reflect.code.CtFieldAccess)1 TypeFilter (spoon.reflect.visitor.filter.TypeFilter)1 A (spoon.test.visibility.testclasses.A)1 A2 (spoon.test.visibility.testclasses.A2)1