List of usage examples for org.eclipse.jdt.internal.compiler.batch CompilationUnit getFileName
@Override public char[] getFileName()
From source file:spoon.test.compilation.CompilationTest.java
License:Open Source License
@Test public void testFilterResourcesDir() { // shows how to filter input java dir // only in package called "reference" Launcher launcher = new Launcher() { @Override/*from w w w.j av a 2 s . c o m*/ public SpoonModelBuilder createCompiler() { return new JDTBasedSpoonCompiler(getFactory()) { @Override protected JDTBatchCompiler createBatchCompiler() { return new JDTBatchCompiler(this) { @Override public CompilationUnit[] getCompilationUnits() { List<CompilationUnit> units = new ArrayList<>(); for (CompilationUnit u : super.getCompilationUnits()) { if (new String(u.getFileName()).replace('\\', '/').contains("/reference/")) { units.add(u); } } return units.toArray(new CompilationUnit[0]); } }; } }; } }; launcher.addInputResource("./src/test/java/spoon/test"); launcher.buildModel(); // we indeed only have types declared in a file in package reference int n = 0; for (CtType<?> t : launcher.getModel().getAllTypes()) { n++; assertTrue(t.getQualifiedName().contains("reference")); } assertTrue(n >= 2); }