Search in sources :

Example 1 with CtTypeProcessor

use of spoon.test.processing.testclasses.CtTypeProcessor in project spoon by INRIA.

the class ProcessingTest method testCallProcessorWithMultipleTypes.

@Test
public void testCallProcessorWithMultipleTypes() {
    // contract: when calling a processor capable of treating CtClass and another capable of treating CtType, they are called on the right types
    Launcher spoon = new Launcher();
    spoon.addInputResource("./src/test/java/spoon/test/imports/testclasses");
    CtClassProcessor classProcessor = new CtClassProcessor();
    spoon.addProcessor(classProcessor);
    CtTypeProcessor typeProcessor = new CtTypeProcessor();
    spoon.addProcessor(typeProcessor);
    CtInterfaceProcessor interfaceProcessor = new CtInterfaceProcessor();
    spoon.addProcessor(interfaceProcessor);
    spoon.run();
    assertFalse(classProcessor.elements.isEmpty());
    for (CtType type : classProcessor.elements) {
        assertTrue("Type " + type.getSimpleName() + " is not a class", type instanceof CtClass);
    }
    assertFalse(classProcessor.elements.isEmpty());
    for (CtType type : interfaceProcessor.elements) {
        assertTrue("Type " + type.getSimpleName() + " is not an interface", type instanceof CtInterface);
    }
    assertFalse(typeProcessor.elements.isEmpty());
    for (CtType type : typeProcessor.elements) {
        if (type instanceof CtClass) {
            assertTrue(classProcessor.elements.contains(type));
            assertFalse(interfaceProcessor.elements.contains(type));
        } else if (type instanceof CtInterface) {
            assertFalse(classProcessor.elements.contains(type));
            assertTrue(interfaceProcessor.elements.contains(type));
        } else {
            assertFalse(classProcessor.elements.contains(type));
            assertFalse(interfaceProcessor.elements.contains(type));
        }
    }
}
Also used : CtClass(spoon.reflect.declaration.CtClass) CtInterface(spoon.reflect.declaration.CtInterface) CtType(spoon.reflect.declaration.CtType) Launcher(spoon.Launcher) CtInterfaceProcessor(spoon.test.processing.testclasses.CtInterfaceProcessor) CtClassProcessor(spoon.test.processing.testclasses.CtClassProcessor) CtTypeProcessor(spoon.test.processing.testclasses.CtTypeProcessor) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 Launcher (spoon.Launcher)1 CtClass (spoon.reflect.declaration.CtClass)1 CtInterface (spoon.reflect.declaration.CtInterface)1 CtType (spoon.reflect.declaration.CtType)1 CtClassProcessor (spoon.test.processing.testclasses.CtClassProcessor)1 CtInterfaceProcessor (spoon.test.processing.testclasses.CtInterfaceProcessor)1 CtTypeProcessor (spoon.test.processing.testclasses.CtTypeProcessor)1