use of spoon.test.prettyprinter.testclasses.AClass in project spoon by INRIA.
the class DefaultPrettyPrinterTest method testPrintAMethodWithImports.
@Test
public void testPrintAMethodWithImports() 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 List<?> aMethod() {" + nl + " return new ArrayList<>();" + nl + "}";
final CtClass<?> aClass = (CtClass<?>) factory.Type().get(AClass.class);
assertEquals(expected, aClass.getMethodsByName("aMethod").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());
}
use of spoon.test.prettyprinter.testclasses.AClass 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.test.prettyprinter.testclasses.AClass in project spoon by INRIA.
the class DefaultPrettyPrinterTest method useFullyQualifiedNamesInCtElementImpl_toString.
@Test
public void useFullyQualifiedNamesInCtElementImpl_toString() throws Exception {
Factory factory = build(AClass.class);
factory.getEnvironment().setAutoImports(false);
final CtClass<?> aClass = (CtClass<?>) factory.Type().get(AClass.class);
String computed = aClass.getMethodsByName("aMethod").get(0).toString();
final String expected = "public java.util.List<?> aMethod() {" + nl + " return new java.util.ArrayList<>();" + nl + "}";
assertEquals("the toString method of CtElementImpl should not shorten type names as it has no context or import statements", expected, computed);
}
use of spoon.test.prettyprinter.testclasses.AClass 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