use of com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTags in project checkstyle by checkstyle.
the class JavadocUtilsTest 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 = JavadocUtils.getJavadocTags(comment, JavadocUtils.JavadocTagType.ALL);
assertEquals(5, allTags.getValidTags().size());
}
use of com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTags in project checkstyle by checkstyle.
the class JavadocUtils 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 String[] text = textBlock.getText();
final List<JavadocTag> tags = new ArrayList<>();
final List<InvalidJavadocTag> invalidTags = new ArrayList<>();
for (int i = 0; i < text.length; i++) {
final String textValue = text[i];
final Matcher blockTagMatcher = getBlockTagPattern(i).matcher(textValue);
if ((tagType == JavadocTagType.ALL || tagType == JavadocTagType.BLOCK) && blockTagMatcher.find()) {
final String tagName = blockTagMatcher.group(1);
String content = textValue.substring(blockTagMatcher.end(1));
if (content.endsWith("*/")) {
content = content.substring(0, content.length() - 2);
}
final int line = textBlock.getStartLineNo() + i;
int col = blockTagMatcher.start(1) - 1;
if (i == 0) {
col += textBlock.getStartColNo();
}
if (JavadocTagInfo.isValidName(tagName)) {
tags.add(new JavadocTag(line, col, tagName, content.trim()));
} else {
invalidTags.add(new InvalidJavadocTag(line, col, tagName));
}
} else // No block tag, so look for inline validTags
if (tagType == JavadocTagType.ALL || tagType == JavadocTagType.INLINE) {
lookForInlineTags(textBlock, i, tags, invalidTags);
}
}
return new JavadocTags(tags, invalidTags);
}
use of com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTags in project debezium by debezium.
the class UnusedImports method processJavaDocLinkParameters.
protected void processJavaDocLinkParameters(DetailAST aAST) {
final FileContents contents = getFileContents();
final int lineNo = aAST.getLineNo();
final TextBlock cmt = contents.getJavadocBefore(lineNo);
if (cmt != null) {
final JavadocTags tags = JavaDocUtil.getJavadocTags(cmt, JavadocUtils.JavadocTagType.ALL);
for (final JavadocTag tag : tags.getValidTags()) {
processJavaDocTag(tag);
}
for (final InvalidJavadocTag tag : tags.getInvalidTags()) {
log(tag.getLine(), tag.getCol(), "import.invalidJavaDocTag", tag.getName());
}
}
}
use of com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTags in project checkstyle by checkstyle.
the class JavadocUtilTest 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 = JavadocUtil.getJavadocTags(comment, JavadocUtil.JavadocTagType.ALL);
assertWithMessage("Unexpected invalid tags size").that(allTags.getInvalidTags()).hasSize(2);
assertTag("Unexpected invalid tag", new InvalidJavadocTag(1, 4, "fake"), allTags.getInvalidTags().get(0));
assertTag("Unexpected invalid tag", new InvalidJavadocTag(2, 4, "bogus"), allTags.getInvalidTags().get(1));
assertWithMessage("Unexpected valid tags size").that(allTags.getValidTags()).hasSize(1);
assertTag("Unexpected valid tag", new JavadocTag(3, 4, "link", "List valid"), allTags.getValidTags().get(0));
}
use of com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTags in project checkstyle by checkstyle.
the class JavadocUtilTest method testBlockTag.
@Test
public void testBlockTag() {
final String[] text = { "/** @see elsewhere ", " */" };
final Comment comment = new Comment(text, 1, 4, text[1].length());
final JavadocTags allTags = JavadocUtil.getJavadocTags(comment, JavadocUtil.JavadocTagType.ALL);
assertWithMessage("Invalid valid tags size").that(allTags.getValidTags()).hasSize(1);
}
Aggregations