use of spoon.SpoonAPI in project spoon by INRIA.
the class JavaDocTest method testJavaDocReprint.
@Test
public void testJavaDocReprint() throws Exception {
SpoonAPI launcher = new Launcher();
launcher.getEnvironment().setAutoImports(true);
launcher.getEnvironment().setNoClasspath(true);
launcher.getEnvironment().setCommentEnabled(true);
launcher.getEnvironment().setCopyResources(false);
launcher.addInputResource("./src/test/java/spoon/test/javadoc/testclasses/");
launcher.setSourceOutputDirectory("./target/spooned/");
launcher.run();
Factory factory = launcher.getFactory();
CtClass<?> aClass = factory.Class().get(Bar.class);
assertEquals("public class Bar {" + System.lineSeparator() + " /**" + System.lineSeparator() + " * Creates an annotation type." + System.lineSeparator() + " *" + System.lineSeparator() + " * @param owner" + System.lineSeparator() + " * \t\tthe package of the annotation type" + System.lineSeparator() + " * @param simpleName" + System.lineSeparator() + " * \t\tthe name of annotation" + System.lineSeparator() + " */" + System.lineSeparator() + " public <T> CtAnnotationType<?> create(CtPackage owner, String simpleName) {" + System.lineSeparator() + " return null;" + System.lineSeparator() + " }" + System.lineSeparator() + "}", aClass.toString());
// contract: getDocComment never returns null, it returns an empty string if no comment
assertEquals("", aClass.getDocComment());
// contract: getDocComment returns the comment content together with the tag content
assertEquals("Creates an annotation type." + System.lineSeparator() + "@param owner" + System.lineSeparator() + "\t\tthe package of the annotation type" + System.lineSeparator() + "@param simpleName" + System.lineSeparator() + "\t\tthe name of annotation" + System.lineSeparator(), aClass.getMethodsByName("create").get(0).getDocComment());
assertEquals(2, aClass.getMethodsByName("create").get(0).getComments().get(0).asJavaDoc().getTags().size());
}
Aggregations