Search in sources :

Example 1 with Javadoc

use of com.github.javaparser.javadoc.Javadoc in project javaparser by javaparser.

the class JavadocParserTest method parseParamBlockTags.

@Test
public void parseParamBlockTags() {
    String text = EOL + "     * Add a field to this and automatically add the import of the type if needed" + EOL + "     *" + EOL + "     * @param typeClass the type of the field" + EOL + "     * @param name the name of the field" + EOL + "     * @param modifiers the modifiers like {@link Modifier#PUBLIC}" + EOL + "     * @return the {@link FieldDeclaration} created" + EOL + "     ";
    Javadoc res = JavadocParser.parse(text);
    assertEquals(new Javadoc(JavadocDescription.parseText("Add a field to this and automatically add the import of the type if needed")).addBlockTag(JavadocBlockTag.createParamBlockTag("typeClass", "the type of the field")).addBlockTag(JavadocBlockTag.createParamBlockTag("name", "the name of the field")).addBlockTag(JavadocBlockTag.createParamBlockTag("modifiers", "the modifiers like {@link Modifier#PUBLIC}")).addBlockTag(new JavadocBlockTag(JavadocBlockTag.Type.RETURN, "the {@link FieldDeclaration} created")), res);
}
Also used : Javadoc(com.github.javaparser.javadoc.Javadoc) JavadocBlockTag(com.github.javaparser.javadoc.JavadocBlockTag) Test(org.junit.Test)

Example 2 with Javadoc

use of com.github.javaparser.javadoc.Javadoc in project javaparser by javaparser.

the class JavadocParserTest method parseBlockTagsAndEmptyDescription.

@Test
public void parseBlockTagsAndEmptyDescription() {
    String text = EOL + "   * @deprecated" + EOL + "   * @see #getEndColumn" + EOL + "   ";
    assertEquals(new Javadoc(JavadocDescription.parseText("")).addBlockTag(new JavadocBlockTag(JavadocBlockTag.Type.DEPRECATED, "")).addBlockTag(new JavadocBlockTag(JavadocBlockTag.Type.SEE, "#getEndColumn")), JavadocParser.parse(text));
}
Also used : Javadoc(com.github.javaparser.javadoc.Javadoc) JavadocBlockTag(com.github.javaparser.javadoc.JavadocBlockTag) Test(org.junit.Test)

Example 3 with Javadoc

use of com.github.javaparser.javadoc.Javadoc in project javaparser by javaparser.

the class JavadocParser method parse.

public static Javadoc parse(String commentContent) {
    List<String> cleanLines = cleanLines(normalizeEolInTextBlock(commentContent, EOL));
    int indexOfFirstBlockTag = cleanLines.stream().filter(JavadocParser::isABlockLine).map(cleanLines::indexOf).findFirst().orElse(-1);
    List<String> blockLines;
    String descriptionText;
    if (indexOfFirstBlockTag == -1) {
        descriptionText = trimRight(String.join(EOL, cleanLines));
        blockLines = Collections.emptyList();
    } else {
        descriptionText = trimRight(String.join(EOL, cleanLines.subList(0, indexOfFirstBlockTag)));
        // Combine cleaned lines, but only starting with the first block tag till the end
        // In this combined string it is easier to handle multiple lines which actually belong together
        String tagBlock = cleanLines.subList(indexOfFirstBlockTag, cleanLines.size()).stream().collect(Collectors.joining(EOL));
        // Split up the entire tag back again, considering now that some lines belong to the same block tag.
        // The pattern splits the block at each new line starting with the '@' symbol, thus the symbol
        // then needs to be added again so that the block parsers handles everything correctly.
        blockLines = BLOCK_PATTERN.splitAsStream(tagBlock).filter(STRING_NOT_EMPTY).map(s -> BLOCK_TAG_PREFIX + s).collect(Collectors.toList());
    }
    Javadoc document = new Javadoc(JavadocDescription.parseText(descriptionText));
    blockLines.forEach(l -> document.addBlockTag(parseBlockTag(l)));
    return document;
}
Also used : Javadoc(com.github.javaparser.javadoc.Javadoc)

Example 4 with Javadoc

use of com.github.javaparser.javadoc.Javadoc in project javaparser by javaparser.

the class JavadocParserTest method parseCommentWithNewLines.

@Test
public void parseCommentWithNewLines() {
    String text = EOL + "   * The version identifier for this Serializable class." + EOL + "   * Increment only if the <i>serialized</i> form of the" + EOL + "   * class changes." + EOL + "   ";
    assertEquals(new Javadoc(JavadocDescription.parseText("The version identifier for this Serializable class." + EOL + "Increment only if the <i>serialized</i> form of the" + EOL + "class changes.")), JavadocParser.parse(text));
}
Also used : Javadoc(com.github.javaparser.javadoc.Javadoc) Test(org.junit.Test)

Example 5 with Javadoc

use of com.github.javaparser.javadoc.Javadoc in project javaparser by javaparser.

the class JavadocParserTest method parseBlockTagsAndProvideTagName.

@Test
public void parseBlockTagsAndProvideTagName() {
    String expectedText = EOL + "   * @unofficial" + EOL + " " + "   ";
    Javadoc underTest = new Javadoc(JavadocDescription.parseText("")).addBlockTag(new JavadocBlockTag("unofficial", ""));
    assertEquals(underTest, JavadocParser.parse(expectedText));
    assertEquals(1, underTest.getBlockTags().size());
    assertEquals("unofficial", underTest.getBlockTags().get(0).getTagName());
}
Also used : Javadoc(com.github.javaparser.javadoc.Javadoc) JavadocBlockTag(com.github.javaparser.javadoc.JavadocBlockTag) Test(org.junit.Test)

Aggregations

Javadoc (com.github.javaparser.javadoc.Javadoc)7 Test (org.junit.Test)6 JavadocBlockTag (com.github.javaparser.javadoc.JavadocBlockTag)4