use of spoon.reflect.code.CtBinaryOperator in project spoon by INRIA.
the class TypeTest method testTypeAccessForTypeAccessInInstanceOf.
@Test
public void testTypeAccessForTypeAccessInInstanceOf() throws Exception {
// contract: the right hand operator must be a CtTypeAccess.
final String target = "./target/type";
final Launcher launcher = new Launcher();
launcher.addInputResource("./src/test/java/spoon/test/type/testclasses");
launcher.setSourceOutputDirectory(target);
launcher.getEnvironment().setNoClasspath(true);
launcher.run();
final CtClass<Pozole> aPozole = launcher.getFactory().Class().get(Pozole.class);
final CtMethod<?> eat = aPozole.getMethodsByName("eat").get(0);
final List<CtTypeAccess<?>> typeAccesses = eat.getElements(new TypeFilter<CtTypeAccess<?>>(CtTypeAccess.class));
assertEquals(2, typeAccesses.size());
assertTrue(typeAccesses.get(0).getParent() instanceof CtBinaryOperator);
assertEquals(BinaryOperatorKind.INSTANCEOF, ((CtBinaryOperator) typeAccesses.get(0).getParent()).getKind());
assertEquals("a instanceof java.lang.String", typeAccesses.get(0).getParent().toString());
assertTrue(typeAccesses.get(1).getParent() instanceof CtBinaryOperator);
assertEquals(BinaryOperatorKind.INSTANCEOF, ((CtBinaryOperator) typeAccesses.get(1).getParent()).getKind());
assertEquals("a instanceof java.util.Collection<?>", typeAccesses.get(1).getParent().toString());
}
Aggregations