Exemplo n.º 1
0
 /**
  * Gets next sibling of specified node with the specified type.
  *
  * @param node DetailNode
  * @param tokenType javadoc token type
  * @return next sibling.
  */
 public static DetailNode getNextSibling(DetailNode node, int tokenType) {
   DetailNode nextSibling = JavadocUtils.getNextSibling(node);
   while (nextSibling != null && nextSibling.getType() != tokenType) {
     nextSibling = JavadocUtils.getNextSibling(nextSibling);
   }
   return nextSibling;
 }
Exemplo n.º 2
0
 /**
  * Gets tag name from javadocTagSection.
  *
  * @param javadocTagSection to get tag name from.
  * @return name, of the javadocTagSection's tag.
  */
 public static String getTagName(DetailNode javadocTagSection) {
   String javadocTagName;
   if (javadocTagSection.getType() == JavadocTokenTypes.JAVADOC_INLINE_TAG) {
     javadocTagName =
         JavadocUtils.getNextSibling(JavadocUtils.getFirstChild(javadocTagSection)).getText();
   } else {
     javadocTagName = JavadocUtils.getFirstChild(javadocTagSection).getText();
   }
   return javadocTagName;
 }
 @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());
 }
 /**
  * Checks if comment has in-line tags which are not ignored.
  *
  * @param javadocRoot javadoc root node.
  * @return true, if comment has in-line tags which are not ignored.
  * @see <a href=
  *     http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javadoc.html#javadoctags>
  *     JavadocTags</a>
  */
 private boolean hasJavadocInlineTags(DetailNode javadocRoot) {
   DetailNode javadocTagSection =
       JavadocUtils.findFirstToken(javadocRoot, JavadocTokenTypes.JAVADOC_INLINE_TAG);
   boolean foundTag = false;
   while (javadocTagSection != null) {
     if (!isTagIgnored(javadocTagSection)) {
       foundTag = true;
       break;
     }
     javadocTagSection =
         JavadocUtils.getNextSibling(javadocTagSection, JavadocTokenTypes.JAVADOC_INLINE_TAG);
   }
   return foundTag;
 }
 @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 =
       JavadocUtils.getJavadocTags(comment, JavadocUtils.JavadocTagType.ALL).getValidTags();
   assertEquals("List#add(Object)", tags.get(0).getArg1());
 }
  @Test
  public void testBranchContains() {
    JavadocNodeImpl node = new JavadocNodeImpl();
    JavadocNodeImpl firstChild = new JavadocNodeImpl();
    JavadocNodeImpl secondChild = new JavadocNodeImpl();

    node.setType(JavadocTokenTypes.JAVADOC);
    firstChild.setType(JavadocTokenTypes.BODY_TAG_OPEN);
    secondChild.setType(JavadocTokenTypes.CODE_LITERAL);

    node.setChildren(firstChild, secondChild);
    assertFalse(JavadocUtils.branchContains(node, JavadocTokenTypes.AUTHOR_LITERAL));

    firstChild.setParent(node);
    secondChild.setParent(node);
    assertFalse(JavadocUtils.branchContains(node, JavadocTokenTypes.AUTHOR_LITERAL));

    secondChild.setType(JavadocTokenTypes.AUTHOR_LITERAL);
    assertTrue(JavadocUtils.branchContains(node, JavadocTokenTypes.AUTHOR_LITERAL));
  }
 @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());
 }
 @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());
 }
  @Test
  public void testEmptyJavadocCommentAst() {
    DetailAST commentBegin = new DetailAST();
    commentBegin.setType(TokenTypes.BLOCK_COMMENT_BEGIN);
    commentBegin.setText("/*");

    DetailAST javadocCommentContent = new DetailAST();
    javadocCommentContent.setType(TokenTypes.COMMENT_CONTENT);
    javadocCommentContent.setText("*");

    DetailAST commentEnd = new DetailAST();
    commentEnd.setType(TokenTypes.BLOCK_COMMENT_END);
    commentEnd.setText("*/");

    commentBegin.setFirstChild(javadocCommentContent);
    javadocCommentContent.setNextSibling(commentEnd);

    assertTrue(JavadocUtils.isJavadocComment(commentBegin));
  }
  @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);
      }
    }
  }
 /**
  * Checks if list of ignored tags contains javadocTagSection's javadoc tag.
  *
  * @param javadocTagSection to check javadoc tag in.
  * @return true, if ignoredTags contains javadocTagSection's javadoc tag.
  */
 private boolean isTagIgnored(DetailNode javadocTagSection) {
   return ignoredTags.contains(JavadocUtils.getTagName(javadocTagSection));
 }
 /**
  * Checks if comment has javadoc tags which are not ignored. Also works on custom tags. As block
  * tags can be interpreted only at the beginning of a line, only the first instance is checked.
  *
  * @param javadocRoot javadoc root node.
  * @return true, if comment has javadoc tags which are not ignored.
  * @see <a href=
  *     http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javadoc.html#blockandinlinetags>
  *     Block and inline tags</a>
  */
 private boolean hasJavadocTags(DetailNode javadocRoot) {
   final DetailNode javadocTagSection =
       JavadocUtils.findFirstToken(javadocRoot, JavadocTokenTypes.JAVADOC_TAG);
   return javadocTagSection != null && !isTagIgnored(javadocTagSection);
 }
 @Test
 public void testEmptyJavadocComment() {
   final String emptyJavadocComment = "*";
   assertTrue(JavadocUtils.isJavadocComment(emptyJavadocComment));
 }
 @Test
 public void testEmptyBlockComment() {
   final String emptyComment = "";
   assertFalse(JavadocUtils.isJavadocComment(emptyComment));
 }
 /**
  * Tests if at-clause tag is empty.
  *
  * @param tagNode at-clause tag.
  * @return true, if at-clause tag is empty.
  */
 private boolean isEmptyTag(DetailNode tagNode) {
   final DetailNode tagDescription =
       JavadocUtils.findFirstToken(tagNode, JavadocTokenTypes.DESCRIPTION);
   return tagDescription == null;
 }