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());
}
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());
}
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);
}
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);
}
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);
}
Aggregations