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));
}
Aggregations