Search in sources :

Example 21 with SpoonAPI

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());
}
Also used : Launcher(spoon.Launcher) Factory(spoon.reflect.factory.Factory) SpoonAPI(spoon.SpoonAPI) Test(org.junit.Test)

Aggregations

Launcher (spoon.Launcher)21 SpoonAPI (spoon.SpoonAPI)21 Test (org.junit.Test)19 CtType (spoon.reflect.declaration.CtType)9 ArrayList (java.util.ArrayList)8 CtField (spoon.reflect.declaration.CtField)6 CtMethod (spoon.reflect.declaration.CtMethod)6 Factory (spoon.reflect.factory.Factory)6 CtClass (spoon.reflect.declaration.CtClass)5 CtTypeReference (spoon.reflect.reference.CtTypeReference)5 TypeFilter (spoon.reflect.visitor.filter.TypeFilter)5 File (java.io.File)4 Collections (java.util.Collections)4 List (java.util.List)4 Set (java.util.Set)4 Assert.assertTrue (org.junit.Assert.assertTrue)4 CtElement (spoon.reflect.declaration.CtElement)4 ModifierKind (spoon.reflect.declaration.ModifierKind)4 Arrays (java.util.Arrays)3 Collectors (java.util.stream.Collectors)3