Esempio 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;
 }
Esempio n. 2
0
  /**
   * Checks whether node contains any node of specified type among children on any deep level.
   *
   * @param node DetailNode
   * @param type token type
   * @return true if node contains any node of type type among children on any deep level.
   */
  public static boolean branchContains(DetailNode node, int type) {
    DetailNode curNode = node;
    while (true) {

      if (type == curNode.getType()) {
        return true;
      }

      DetailNode toVisit = getFirstChild(curNode);
      while (curNode != null && toVisit == null) {
        toVisit = getNextSibling(curNode);
        if (toVisit == null) {
          curNode = curNode.getParent();
        }
      }

      if (curNode == toVisit) {
        break;
      }

      curNode = toVisit;
    }

    return false;
  }
Esempio n. 3
0
 /**
  * Gets previous sibling of specified node.
  *
  * @param node DetailNode
  * @return previous sibling
  */
 public static DetailNode getPreviousSibling(DetailNode node) {
   final DetailNode parent = node.getParent();
   final int previousSiblingIndex = node.getIndex() - 1;
   final DetailNode[] children = parent.getChildren();
   if (previousSiblingIndex >= 0) {
     return children[previousSiblingIndex];
   }
   return null;
 }
Esempio n. 4
0
 /**
  * Returns the first child token that has a specified type.
  *
  * @param node Javadoc AST node
  * @param type the token type to match
  * @return the matching token, or null if no match
  */
 public static DetailNode findFirstToken(DetailNode node, int type) {
   DetailNode retVal = null;
   for (DetailNode i = getFirstChild(node); i != null; i = getNextSibling(i)) {
     if (i.getType() == type) {
       retVal = i;
       break;
     }
   }
   return retVal;
 }
 /**
  * Finds and returns chars till first dot.
  *
  * @param textNode node with javadoc text.
  * @return String with chars till first dot.
  */
 private static String getCharsTillDot(DetailNode textNode) {
   final StringBuilder result = new StringBuilder();
   for (DetailNode child : textNode.getChildren()) {
     result.append(child.getText());
     if (PERIOD.equals(child.getText())
         && JavadocUtils.getNextSibling(child).getType() == JavadocTokenTypes.WS) {
       break;
     }
   }
   return result.toString();
 }
Esempio n. 6
0
 /**
  * Gets next sibling of specified node.
  *
  * @param node DetailNode
  * @return next sibling.
  */
 public static DetailNode getNextSibling(DetailNode node) {
   final DetailNode parent = node.getParent();
   if (parent != null) {
     final int nextSiblingIndex = node.getIndex() + 1;
     final DetailNode[] children = parent.getChildren();
     if (nextSiblingIndex <= children.length - 1) {
       return children[nextSiblingIndex];
     }
   }
   return null;
 }
 @Override
 public void visitJavadocToken(DetailNode ast) {
   String firstSentence = getFirstSentence(ast);
   final int endOfSentence = firstSentence.lastIndexOf(period);
   if (endOfSentence == -1) {
     log(ast.getLineNumber(), MSG_SUMMARY_FIRST_SENTENCE);
   } else {
     firstSentence = firstSentence.substring(0, endOfSentence);
     if (containsForbiddenFragment(firstSentence)) {
       log(ast.getLineNumber(), MSG_SUMMARY_JAVADOC);
     }
   }
 }
 /**
  * Finds and returns first sentence.
  *
  * @param ast Javadoc root node.
  * @return first sentence.
  */
 private static String getFirstSentence(DetailNode ast) {
   final StringBuilder result = new StringBuilder();
   final String periodSuffix = PERIOD + ' ';
   for (DetailNode child : ast.getChildren()) {
     if (child.getType() != JavadocTokenTypes.JAVADOC_INLINE_TAG
         && child.getText().contains(periodSuffix)) {
       result.append(getCharsTillDot(child));
       break;
     } else {
       result.append(child.getText());
     }
   }
   return result.toString();
 }
 @Override
 public void visitJavadocToken(DetailNode ast) {
   if (isSingleLineJavadoc(getBlockCommentAst())
       && (hasJavadocTags(ast) || !ignoreInlineTags && hasJavadocInlineTags(ast))) {
     log(ast.getLineNumber(), "singleline.javadoc");
   }
 }
Esempio n. 10
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;
 }
Esempio n. 11
0
 /**
  * Gets first child node of specified node.
  *
  * @param node DetailNode
  * @return first child
  */
 public static DetailNode getFirstChild(DetailNode node) {
   return node.getChildren().length > 0 ? node.getChildren()[0] : null;
 }
 @Override
 public void visitJavadocToken(DetailNode ast) {
   if (isEmptyTag(ast.getParent())) {
     log(ast.getLineNumber(), MSG_KEY, ast.getText());
   }
 }