/** * Checks, if description node is a description of in-line tag. * @param description DESCRIPTION node. * @return true, if description node is a description of in-line tag. */ private static boolean isInlineDescription(DetailNode description) { boolean isInline = false; DetailNode inlineTag = description.getParent(); while (inlineTag != null) { if (inlineTag.getType() == JavadocTokenTypes.JAVADOC_INLINE_TAG) { isInline = true; break; } inlineTag = inlineTag.getParent(); } return isInline; }
/** * Gets previous sibling of specified node. * @param node DetailNode * @return previous sibling */ public static DetailNode getPreviousSibling(DetailNode node) { DetailNode previousSibling = null; final int previousSiblingIndex = node.getIndex() - 1; if (previousSiblingIndex >= 0) { final DetailNode parent = node.getParent(); final DetailNode[] children = parent.getChildren(); previousSibling = children[previousSiblingIndex]; } return previousSibling; }
/** * Gets next sibling of specified node. * * @param node DetailNode * @return next sibling. */ public static DetailNode getNextSibling(DetailNode node) { DetailNode nextSibling = null; final DetailNode parent = node.getParent(); if (parent != null) { final int nextSiblingIndex = node.getIndex() + 1; final DetailNode[] children = parent.getChildren(); if (nextSiblingIndex <= children.length - 1) { nextSibling = children[nextSiblingIndex]; } } return nextSibling; }
@Override public void visitJavadocToken(DetailNode ast) { if (isEmptyTag(ast.getParent())) { log(ast.getLineNumber(), MSG_KEY, ast.getText()); } }
/** * 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 containsInBranch(DetailNode node, int type) { boolean result = true; DetailNode curNode = node; while (type != curNode.getType()) { DetailNode toVisit = getFirstChild(curNode); while (curNode != null && toVisit == null) { toVisit = getNextSibling(curNode); if (toVisit == null) { curNode = curNode.getParent(); } } if (curNode == toVisit) { result = false; break; } curNode = toVisit; } return result; }
/** * Determines whether or not the line is empty line. * @param newLine NEWLINE node. * @return true, if line is empty line. */ private static boolean isEmptyLine(DetailNode newLine) { boolean result = false; DetailNode previousSibling = JavadocUtil.getPreviousSibling(newLine); if (previousSibling != null && previousSibling.getParent().getType() == JavadocTokenTypes.JAVADOC) { if (previousSibling.getType() == JavadocTokenTypes.TEXT && CommonUtil.isBlank(previousSibling.getText())) { previousSibling = JavadocUtil.getPreviousSibling(previousSibling); } result = previousSibling != null && previousSibling.getType() == JavadocTokenTypes.LEADING_ASTERISK; } return result; }
/** * Processes a node calling Check at interested nodes. * @param root * the root of tree for process */ private void walk(DetailNode root) { DetailNode curNode = root; while (curNode != null) { boolean waitsForProcessing = shouldBeProcessed(curNode); if (waitsForProcessing) { visitJavadocToken(curNode); } DetailNode toVisit = JavadocUtil.getFirstChild(curNode); while (curNode != null && toVisit == null) { if (waitsForProcessing) { leaveJavadocToken(curNode); } toVisit = JavadocUtil.getNextSibling(curNode); if (toVisit == null) { curNode = curNode.getParent(); if (curNode != null) { waitsForProcessing = shouldBeProcessed(curNode); } } } curNode = toVisit; } }
/** * Checks, if description node is a description of in-line tag. * @param description DESCRIPTION node. * @return true, if description node is a description of in-line tag. */ private static boolean isInlineDescription(DetailNode description) { boolean isInline = false; DetailNode inlineTag = description.getParent(); while (inlineTag != null) { if (inlineTag.getType() == JavadocTokenTypes.JAVADOC_INLINE_TAG) { isInline = true; break; } inlineTag = inlineTag.getParent(); } return isInline; }
/** * Gets previous sibling of specified node. * @param node DetailNode * @return previous sibling */ public static DetailNode getPreviousSibling(DetailNode node) { DetailNode previousSibling = null; final int previousSiblingIndex = node.getIndex() - 1; if (previousSiblingIndex >= 0) { final DetailNode parent = node.getParent(); final DetailNode[] children = parent.getChildren(); previousSibling = children[previousSiblingIndex]; } return previousSibling; }
/** * Gets next sibling of specified node. * * @param node DetailNode * @return next sibling. */ public static DetailNode getNextSibling(DetailNode node) { DetailNode nextSibling = null; final DetailNode parent = node.getParent(); if (parent != null) { final int nextSiblingIndex = node.getIndex() + 1; final DetailNode[] children = parent.getChildren(); if (nextSiblingIndex <= children.length - 1) { nextSibling = children[nextSiblingIndex]; } } return nextSibling; }
@Override public void visitJavadocToken(DetailNode ast) { if (isEmptyTag(ast.getParent())) { log(ast.getLineNumber(), MSG_KEY, ast.getText()); } }
/** * 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 containsInBranch(DetailNode node, int type) { boolean result = true; DetailNode curNode = node; while (type != curNode.getType()) { DetailNode toVisit = getFirstChild(curNode); while (curNode != null && toVisit == null) { toVisit = getNextSibling(curNode); if (toVisit == null) { curNode = curNode.getParent(); } } if (curNode == toVisit) { result = false; break; } curNode = toVisit; } return result; }
/** * Determines whether or not the line is empty line. * @param newLine NEWLINE node. * @return true, if line is empty line. */ private static boolean isEmptyLine(DetailNode newLine) { boolean result = false; DetailNode previousSibling = JavadocUtil.getPreviousSibling(newLine); if (previousSibling != null && previousSibling.getParent().getType() == JavadocTokenTypes.JAVADOC) { if (previousSibling.getType() == JavadocTokenTypes.TEXT && CommonUtil.isBlank(previousSibling.getText())) { previousSibling = JavadocUtil.getPreviousSibling(previousSibling); } result = previousSibling != null && previousSibling.getType() == JavadocTokenTypes.LEADING_ASTERISK; } return result; }
/** * Processes a node calling Check at interested nodes. * @param root * the root of tree for process */ private void walk(DetailNode root) { DetailNode curNode = root; while (curNode != null) { boolean waitsForProcessing = shouldBeProcessed(curNode); if (waitsForProcessing) { visitJavadocToken(curNode); } DetailNode toVisit = JavadocUtil.getFirstChild(curNode); while (curNode != null && toVisit == null) { if (waitsForProcessing) { leaveJavadocToken(curNode); } toVisit = JavadocUtil.getNextSibling(curNode); if (toVisit == null) { curNode = curNode.getParent(); if (curNode != null) { waitsForProcessing = shouldBeProcessed(curNode); } } } curNode = toVisit; } }