use of spoon.SpoonModelBuilder in project spoon by INRIA.
the class InterfaceTest method setUp.
@Before
public void setUp() throws Exception {
final File testDirectory = new File("./src/test/java/spoon/test/interfaces/testclasses/");
final Launcher launcher = new Launcher();
this.factory = launcher.createFactory();
factory.getEnvironment().setComplianceLevel(8);
SpoonModelBuilder compiler = launcher.createCompiler(this.factory);
compiler.addInputSource(testDirectory);
compiler.build();
}
use of spoon.SpoonModelBuilder in project spoon by INRIA.
the class ImportScannerTest method testMultiCatchImport.
@Test
public void testMultiCatchImport() throws Exception {
Launcher spoon = new Launcher();
Factory factory = spoon.createFactory();
SpoonModelBuilder compiler = spoon.createCompiler(factory, SpoonResourceHelper.resources("./src/test/java/spoon/test/imports/testclasses/MultiCatch.java"));
compiler.build();
final List<CtClass> classes = Query.getElements(factory, new NamedElementFilter<>(CtClass.class, "MultiCatch"));
ImportScanner importScanner = new ImportScannerImpl();
importScanner.computeImports(classes.get(0));
// as ArithmeticException come from java.lang it is not imported anymore
// assertTrue( importScanner.isImported( factory.Type().createReference( ArithmeticException.class ) ));
assertTrue(importScanner.isImported(factory.Type().createReference(AccessControlException.class)));
}
use of spoon.SpoonModelBuilder in project spoon by INRIA.
the class JarTest method testFile.
@Test
public void testFile() throws Exception {
Launcher launcher = new Launcher();
SpoonModelBuilder compiler = launcher.createCompiler(launcher.getFactory(), Arrays.asList(SpoonResourceHelper.createFile(new File("./src/test/resources/spoon/test/api/Foo.java"))));
Assert.assertTrue(compiler.build());
Assert.assertNotNull(launcher.getFactory().Type().get("Foo"));
}
use of spoon.SpoonModelBuilder in project spoon by INRIA.
the class DefaultPrettyPrinterTest method testPrintAClassWithImports.
@Test
public void testPrintAClassWithImports() throws Exception {
final Launcher launcher = new Launcher();
final Factory factory = launcher.getFactory();
factory.getEnvironment().setAutoImports(true);
final SpoonModelBuilder compiler = launcher.createCompiler();
compiler.addInputSource(new File("./src/test/java/spoon/test/prettyprinter/testclasses/"));
compiler.build();
final String expected = "public class AClass {" + nl + " public List<?> aMethod() {" + nl + " return new ArrayList<>();" + nl + " }" + nl + "" + nl + " public List<? extends ArrayList> aMethodWithGeneric() {" + nl + " return new ArrayList<>();" + nl + " }" + nl + "}";
final CtClass<?> aClass = (CtClass<?>) factory.Type().get(AClass.class);
assertEquals(expected, aClass.toString());
final CtConstructorCall<?> constructorCall = aClass.getElements(new TypeFilter<CtConstructorCall<?>>(CtConstructorCall.class)).get(0);
final CtTypeReference<?> ctTypeReference = constructorCall.getType().getActualTypeArguments().get(0);
assertTrue(ctTypeReference.isImplicit());
assertEquals("Object", ctTypeReference.getSimpleName());
}
use of spoon.SpoonModelBuilder in project spoon by INRIA.
the class DefaultPrettyPrinterTest method testPrintAMethodWithGeneric.
@Test
public void testPrintAMethodWithGeneric() throws Exception {
final Launcher launcher = new Launcher();
final Factory factory = launcher.getFactory();
factory.getEnvironment().setAutoImports(true);
final SpoonModelBuilder compiler = launcher.createCompiler();
compiler.addInputSource(new File("./src/test/java/spoon/test/prettyprinter/testclasses/"));
compiler.build();
final CtClass<?> aClass = (CtClass<?>) factory.Type().get(AClass.class);
final String expected = "public List<? extends ArrayList> aMethodWithGeneric() {" + System.lineSeparator() + " return new ArrayList<>();" + System.lineSeparator() + "}";
assertEquals(expected, aClass.getMethodsByName("aMethodWithGeneric").get(0).toString());
final CtConstructorCall<?> constructorCall = aClass.getElements(new TypeFilter<CtConstructorCall<?>>(CtConstructorCall.class)).get(0);
final CtTypeReference<?> ctTypeReference = constructorCall.getType().getActualTypeArguments().get(0);
assertTrue(ctTypeReference.isImplicit());
assertEquals("Object", ctTypeReference.getSimpleName());
}
Aggregations