use of com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTag in project checkstyle by checkstyle.
the class JavadocUtils method lookForInlineTags.
/**
* Looks for inline tags in comment and adds them to the proper tags collection.
* @param comment comment text block
* @param lineNumber line number in the comment
* @param validTags collection of valid tags
* @param invalidTags collection of invalid tags
*/
private static void lookForInlineTags(TextBlock comment, int lineNumber, final List<JavadocTag> validTags, final List<InvalidJavadocTag> invalidTags) {
final String text = comment.getText()[lineNumber];
// Match Javadoc text after comment characters
final Matcher commentMatcher = COMMENT_PATTERN.matcher(text);
final String commentContents;
// offset including comment characters
final int commentOffset;
if (commentMatcher.find()) {
commentContents = commentMatcher.group(1);
commentOffset = commentMatcher.start(1) - 1;
} else {
// No leading asterisks, still valid
commentContents = text;
commentOffset = 0;
}
final Matcher tagMatcher = INLINE_TAG_PATTERN.matcher(commentContents);
while (tagMatcher.find()) {
final String tagName = tagMatcher.group(1);
final String tagValue = tagMatcher.group(2).trim();
final int line = comment.getStartLineNo() + lineNumber;
int col = commentOffset + tagMatcher.start(1) - 1;
if (lineNumber == 0) {
col += comment.getStartColNo();
}
if (JavadocTagInfo.isValidName(tagName)) {
validTags.add(new JavadocTag(line, col, tagName, tagValue));
} else {
invalidTags.add(new InvalidJavadocTag(line, col, tagName));
}
}
}
use of com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTag in project checkstyle by checkstyle.
the class JavadocUtilsTest method testInlineTagLinkText.
@Test
public void testInlineTagLinkText() {
final String[] text = { "/** {@link List link text }" };
final Comment comment = new Comment(text, 1, 1, text[0].length());
final List<JavadocTag> tags = JavadocUtils.getJavadocTags(comment, JavadocUtils.JavadocTagType.ALL).getValidTags();
assertEquals("List link text", tags.get(0).getFirstArg());
}
use of com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTag in project checkstyle by checkstyle.
the class JavadocUtilsTest method testTagPositions.
@Test
public void testTagPositions() {
final String[] text = { "/** @see elsewhere", " also {@link Name value} */" };
final Comment comment = new Comment(text, 1, 2, text[1].length());
final List<JavadocTag> tags = JavadocUtils.getJavadocTags(comment, JavadocUtils.JavadocTagType.ALL).getValidTags();
assertEquals(2, tags.size());
for (final JavadocTag tag : tags) {
if (JavadocTagInfo.SEE.getName().equals(tag.getTagName())) {
assertEquals(1, tag.getLineNo());
assertEquals(5, tag.getColumnNo());
} else if (JavadocTagInfo.LINK.getName().equals(tag.getTagName())) {
assertEquals(2, tag.getLineNo());
assertEquals(10, tag.getColumnNo());
} else {
fail("Unexpected tag: " + tag);
}
}
}
use of com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTag in project checkstyle by checkstyle.
the class JavadocUtilTest method testInlineTagMethodRef.
@Test
public void testInlineTagMethodRef() {
final String[] text = { "/** {@link List#add(Object)}" };
final Comment comment = new Comment(text, 1, 1, text[0].length());
final List<JavadocTag> tags = JavadocUtil.getJavadocTags(comment, JavadocUtil.JavadocTagType.ALL).getValidTags();
assertWithMessage("Invalid first arg").that(tags.get(0).getFirstArg()).isEqualTo("List#add(Object)");
}
use of com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTag in project checkstyle by checkstyle.
the class JavadocUtilTest method testTagPositions.
@Test
public void testTagPositions() {
final String[] text = { "/** @see elsewhere", " also {@link Name value} */" };
final Comment comment = new Comment(text, 1, 2, text[1].length());
final List<JavadocTag> tags = JavadocUtil.getJavadocTags(comment, JavadocUtil.JavadocTagType.ALL).getValidTags();
assertWithMessage("Invalid tags size").that(tags).hasSize(2);
final JavadocTag seeTag = tags.get(0);
assertWithMessage("Invalid tag name").that(seeTag.getTagName()).isEqualTo(JavadocTagInfo.SEE.getName());
assertWithMessage("Invalid line number").that(seeTag.getLineNo()).isEqualTo(1);
assertWithMessage("Invalid column number").that(seeTag.getColumnNo()).isEqualTo(4);
final JavadocTag linkTag = tags.get(1);
assertWithMessage("Invalid tag name").that(linkTag.getTagName()).isEqualTo(JavadocTagInfo.LINK.getName());
assertWithMessage("Invalid line number").that(linkTag.getLineNo()).isEqualTo(2);
assertWithMessage("Invalid column number").that(linkTag.getColumnNo()).isEqualTo(10);
}
Aggregations