Search in sources :

Example 6 with JavadocTags

use of com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTags in project checkstyle by checkstyle.

the class JavadocUtilsTest method testTagType.

@Test
public void testTagType() {
    final String[] text = { "/** @see block", " * {@link List inline}, {@link List#add(Object)}" };
    final Comment comment = new Comment(text, 1, 2, text[1].length());
    final JavadocTags blockTags = JavadocUtils.getJavadocTags(comment, JavadocUtils.JavadocTagType.BLOCK);
    final JavadocTags inlineTags = JavadocUtils.getJavadocTags(comment, JavadocUtils.JavadocTagType.INLINE);
    assertEquals(1, blockTags.getValidTags().size());
    assertEquals(2, inlineTags.getValidTags().size());
}
Also used : Comment(com.puppycrawl.tools.checkstyle.api.Comment) JavadocTags(com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTags) Test(org.junit.Test)

Example 7 with JavadocTags

use of com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTags in project checkstyle by checkstyle.

the class JavadocUtilsTest method testInvalidTags.

@Test
public void testInvalidTags() {
    final String[] text = { "/** @fake block", " * {@bogus inline}", " * {@link List valid}" };
    final Comment comment = new Comment(text, 1, 3, text[2].length());
    final JavadocTags allTags = JavadocUtils.getJavadocTags(comment, JavadocUtils.JavadocTagType.ALL);
    assertEquals(2, allTags.getInvalidTags().size());
    assertEquals(1, allTags.getValidTags().size());
}
Also used : Comment(com.puppycrawl.tools.checkstyle.api.Comment) JavadocTags(com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTags) Test(org.junit.Test)

Example 8 with JavadocTags

use of com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTags in project checkstyle by checkstyle.

the class JavadocUtilTest method testTags.

@Test
public void testTags() {
    final String[] text = { "/** @see elsewhere ", " * {@link List }, {@link List link text }", "   {@link List#add(Object) link text}", " * {@link Class link text}" };
    final Comment comment = new Comment(text, 1, 4, text[3].length());
    final JavadocTags allTags = JavadocUtil.getJavadocTags(comment, JavadocUtil.JavadocTagType.ALL);
    assertWithMessage("Invalid valid tags size").that(allTags.getValidTags()).hasSize(5);
}
Also used : Comment(com.puppycrawl.tools.checkstyle.api.Comment) JavadocTags(com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTags) Test(org.junit.jupiter.api.Test)

Example 9 with JavadocTags

use of com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTags in project checkstyle by checkstyle.

the class JavadocUtilTest method testTagType.

@Test
public void testTagType() {
    final String[] text = { "/** @see block", " * {@link List inline}, {@link List#add(Object)}" };
    final Comment comment = new Comment(text, 1, 2, text[1].length());
    final JavadocTags blockTags = JavadocUtil.getJavadocTags(comment, JavadocUtil.JavadocTagType.BLOCK);
    final JavadocTags inlineTags = JavadocUtil.getJavadocTags(comment, JavadocUtil.JavadocTagType.INLINE);
    assertWithMessage("Invalid valid tags size").that(blockTags.getValidTags()).hasSize(1);
    assertWithMessage("Invalid valid tags size").that(inlineTags.getValidTags()).hasSize(2);
}
Also used : Comment(com.puppycrawl.tools.checkstyle.api.Comment) JavadocTags(com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTags) Test(org.junit.jupiter.api.Test)

Example 10 with JavadocTags

use of com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTags in project checkstyle by checkstyle.

the class JavadocUtil method getJavadocTags.

/**
 * Gets validTags from a given piece of Javadoc.
 *
 * @param textBlock
 *        the Javadoc comment to process.
 * @param tagType
 *        the type of validTags we're interested in
 * @return all standalone validTags from the given javadoc.
 */
public static JavadocTags getJavadocTags(TextBlock textBlock, JavadocTagType tagType) {
    final boolean getBlockTags = tagType == JavadocTagType.ALL || tagType == JavadocTagType.BLOCK;
    final boolean getInlineTags = tagType == JavadocTagType.ALL || tagType == JavadocTagType.INLINE;
    final List<TagInfo> tags = new ArrayList<>();
    if (getBlockTags) {
        tags.addAll(BlockTagUtil.extractBlockTags(textBlock.getText()));
    }
    if (getInlineTags) {
        tags.addAll(InlineTagUtil.extractInlineTags(textBlock.getText()));
    }
    final List<JavadocTag> validTags = new ArrayList<>();
    final List<InvalidJavadocTag> invalidTags = new ArrayList<>();
    for (TagInfo tag : tags) {
        final int col = tag.getPosition().getColumn();
        // Add the starting line of the comment to the line number to get the actual line number
        // in the source.
        // Lines are one-indexed, so need a off-by-one correction.
        final int line = textBlock.getStartLineNo() + tag.getPosition().getLine() - 1;
        if (JavadocTagInfo.isValidName(tag.getName())) {
            validTags.add(new JavadocTag(line, col, tag.getName(), tag.getValue()));
        } else {
            invalidTags.add(new InvalidJavadocTag(line, col, tag.getName()));
        }
    }
    return new JavadocTags(validTags, invalidTags);
}
Also used : JavadocTagInfo(com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTagInfo) TagInfo(com.puppycrawl.tools.checkstyle.checks.javadoc.utils.TagInfo) ArrayList(java.util.ArrayList) InvalidJavadocTag(com.puppycrawl.tools.checkstyle.checks.javadoc.InvalidJavadocTag) InvalidJavadocTag(com.puppycrawl.tools.checkstyle.checks.javadoc.InvalidJavadocTag) JavadocTag(com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTag) JavadocTags(com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTags)

Aggregations

JavadocTags (com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTags)11 Comment (com.puppycrawl.tools.checkstyle.api.Comment)7 InvalidJavadocTag (com.puppycrawl.tools.checkstyle.checks.javadoc.InvalidJavadocTag)5 JavadocTag (com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTag)5 Test (org.junit.jupiter.api.Test)4 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 Matcher (java.util.regex.Matcher)2 FileContents (com.puppycrawl.tools.checkstyle.api.FileContents)1 TextBlock (com.puppycrawl.tools.checkstyle.api.TextBlock)1 JavadocTagInfo (com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTagInfo)1 TagInfo (com.puppycrawl.tools.checkstyle.checks.javadoc.utils.TagInfo)1 Pattern (java.util.regex.Pattern)1