Search in sources :

Example 1 with TagInfo

use of com.puppycrawl.tools.checkstyle.checks.javadoc.utils.TagInfo 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

InvalidJavadocTag (com.puppycrawl.tools.checkstyle.checks.javadoc.InvalidJavadocTag)1 JavadocTag (com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTag)1 JavadocTagInfo (com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTagInfo)1 JavadocTags (com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTags)1 TagInfo (com.puppycrawl.tools.checkstyle.checks.javadoc.utils.TagInfo)1 ArrayList (java.util.ArrayList)1