List of usage examples for org.eclipse.jdt.internal.compiler.batch CompilationUnit getMainTypeName
@Override public char[] getMainTypeName()
From source file:spoon.test.compilation.CompilationTest.java
License:Open Source License
@Test public void testFilterResourcesFile() { // shows how to filter input java files, for https://github.com/INRIA/spoon/issues/877 Launcher launcher = new Launcher() { @Override/* w w w . j a v a 2s . 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.getMainTypeName()).contains("Foo")) { units.add(u); } } return units.toArray(new CompilationUnit[0]); } }; } }; } }; launcher.addInputResource("./src/test/java/spoon/test/imports"); launcher.buildModel(); int n = 0; // we indeed only have types declared in a file called *Foo* for (CtType<?> t : launcher.getFactory().getModel().getAllTypes()) { n++; assertTrue(t.getPosition().getFile().getAbsolutePath().contains("Foo")); } assertTrue(n >= 2); }