Search in sources :

Example 1 with X

use of spoon.test.ctType.testclasses.X in project spoon by INRIA.

the class CtTypeTest method testIsSubTypeOfonTypeParameters.

@Test
public void testIsSubTypeOfonTypeParameters() throws Exception {
    CtType<X> xCtType = buildClass(X.class);
    Factory factory = xCtType.getFactory();
    CtType<?> oCtType = factory.Type().get("spoon.test.ctType.testclasses.O");
    CtType<?> pCtType = factory.Type().get("spoon.test.ctType.testclasses.P");
    CtTypeReference<?> objectCtTypeRef = factory.Type().OBJECT;
    List<CtTypeParameter> oTypeParameters = oCtType.getFormalCtTypeParameters();
    assertTrue(oTypeParameters.size() == 1);
    List<CtTypeParameter> pTypeParameters = pCtType.getFormalCtTypeParameters();
    assertTrue(pTypeParameters.size() == 2);
    CtType<?> O_A_CtType = oTypeParameters.get(0);
    CtType<?> P_D_CtType = pTypeParameters.get(0);
    CtType<?> P_F_CtType = pTypeParameters.get(1);
    CtMethod<?> O_FooMethod = oCtType.filterChildren(new NamedElementFilter<>(CtMethod.class, "foo")).first();
    CtMethod<?> P_FooMethod = pCtType.filterChildren(new NamedElementFilter<>(CtMethod.class, "foo")).first();
    CtType<?> O_B_CtType = O_FooMethod.getType().getDeclaration();
    CtType<?> P_E_CtType = P_FooMethod.getType().getDeclaration();
    assertTrue(O_B_CtType.isSubtypeOf(xCtType.getReference()));
    assertTrue(O_B_CtType.isSubtypeOf(O_A_CtType.getReference()));
    assertTrue(P_E_CtType.isSubtypeOf(xCtType.getReference()));
    assertTrue(P_E_CtType.isSubtypeOf(P_D_CtType.getReference()));
    assertTrue(P_E_CtType.isSubtypeOf(O_A_CtType.getReference()));
    assertTrue(P_D_CtType.isSubtypeOf(O_A_CtType.getReference()));
    assertTrue(P_E_CtType.isSubtypeOf(O_B_CtType.getReference()));
    assertTrue(P_E_CtType.isSubtypeOf(objectCtTypeRef));
    assertTrue(P_F_CtType.isSubtypeOf(objectCtTypeRef));
}
Also used : CtTypeParameter(spoon.reflect.declaration.CtTypeParameter) X(spoon.test.ctType.testclasses.X) NamedElementFilter(spoon.reflect.visitor.filter.NamedElementFilter) ModelUtils.createFactory(spoon.testing.utils.ModelUtils.createFactory) Factory(spoon.reflect.factory.Factory) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 CtTypeParameter (spoon.reflect.declaration.CtTypeParameter)1 Factory (spoon.reflect.factory.Factory)1 NamedElementFilter (spoon.reflect.visitor.filter.NamedElementFilter)1 X (spoon.test.ctType.testclasses.X)1 ModelUtils.createFactory (spoon.testing.utils.ModelUtils.createFactory)1