Search in sources :

Example 1 with CompilationUnitFilter

use of spoon.support.compiler.jdt.CompilationUnitFilter in project spoon by INRIA.

the class CUFilterTest method testSingleExcludeWithFilter.

@Test
public void testSingleExcludeWithFilter() {
    final Launcher launcher = new Launcher();
    launcher.getEnvironment().setNoClasspath(true);
    launcher.addInputResource("./src/test/resources/noclasspath/same-package");
    launcher.getModelBuilder().addCompilationUnitFilter(new CompilationUnitFilter() {

        @Override
        public boolean exclude(final String path) {
            return path.endsWith("B.java");
        }
    });
    launcher.buildModel();
    final CtModel model = launcher.getModel();
    assertEquals(1, model.getAllTypes().size());
    // make sure `B` is not available in `model.getAllTypes`
    assertEquals("A", model.getAllTypes().iterator().next().getSimpleName());
    // make sure declaration of `B` is known in `model`
    final CtReturn ctReturn = model.getAllTypes().iterator().next().getMethod("createB").getBody().getStatement(0);
    final CtConstructorCall ctConstructorCall = (CtConstructorCall) ctReturn.getReturnedExpression();
    assertEquals("spoon.test.same.B", ctConstructorCall.getType().getQualifiedName());
}
Also used : CompilationUnitFilter(spoon.support.compiler.jdt.CompilationUnitFilter) CtReturn(spoon.reflect.code.CtReturn) CtConstructorCall(spoon.reflect.code.CtConstructorCall) Launcher(spoon.Launcher) CtModel(spoon.reflect.CtModel) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 Launcher (spoon.Launcher)1 CtModel (spoon.reflect.CtModel)1 CtConstructorCall (spoon.reflect.code.CtConstructorCall)1 CtReturn (spoon.reflect.code.CtReturn)1 CompilationUnitFilter (spoon.support.compiler.jdt.CompilationUnitFilter)1