Search in sources :

Example 11 with CtBinaryOperator

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());
}
Also used : Pozole(spoon.test.type.testclasses.Pozole) CtBinaryOperator(spoon.reflect.code.CtBinaryOperator) Launcher(spoon.Launcher) CtTypeAccess(spoon.reflect.code.CtTypeAccess) Test(org.junit.Test)

Aggregations

CtBinaryOperator (spoon.reflect.code.CtBinaryOperator)11 Test (org.junit.Test)9 Launcher (spoon.Launcher)6 Factory (spoon.reflect.factory.Factory)6 CtMethod (spoon.reflect.declaration.CtMethod)5 CtIf (spoon.reflect.code.CtIf)4 CtBlock (spoon.reflect.code.CtBlock)3 CtInvocation (spoon.reflect.code.CtInvocation)3 CtStatement (spoon.reflect.code.CtStatement)3 CtClass (spoon.reflect.declaration.CtClass)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Ignore (org.junit.Ignore)2 CtConditional (spoon.reflect.code.CtConditional)2 CtLiteral (spoon.reflect.code.CtLiteral)2 CtNewArray (spoon.reflect.code.CtNewArray)2 CtReturn (spoon.reflect.code.CtReturn)2 CtStatementList (spoon.reflect.code.CtStatementList)2 CtSwitch (spoon.reflect.code.CtSwitch)2