/** * Find start and end selection positions from DetailNode line and Column. * @param detailNode DetailNode node for which selection finds */ private void findSelectionPositions(DetailNode detailNode) { selectionStart = lines2position.get(detailNode.getLineNumber()) + detailNode.getColumnNumber(); selectionEnd = findLastPosition(detailNode); }
/** * Print AST. * @param ast the root AST node. * @param rootPrefix prefix for the root node * @param prefix prefix for other nodes * @return string AST. */ public static String printTree(DetailNode ast, String rootPrefix, String prefix) { final StringBuilder messageBuilder = new StringBuilder(1024); DetailNode node = ast; while (node != null) { if (node.getType() == JavadocTokenTypes.JAVADOC) { messageBuilder.append(rootPrefix); } else { messageBuilder.append(prefix); } messageBuilder.append(getIndentation(node)) .append(JavadocUtil.getTokenName(node.getType())).append(" -> ") .append(JavadocUtil.escapeAllControlChars(node.getText())).append(" [") .append(node.getLineNumber()).append(':').append(node.getColumnNumber()) .append(']').append(LINE_SEPARATOR) .append(printTree(JavadocUtil.getFirstChild(node), rootPrefix, prefix)); node = JavadocUtil.getNextSibling(node); } return messageBuilder.toString(); }
/** * Finds the last position of node without children. * @param detailNode DetailNode node. * @return Last position of node without children. */ private int findLastPosition(final DetailNode detailNode) { final int lastPosition; if (detailNode.getChildren().length == 0) { lastPosition = lines2position.get(detailNode.getLineNumber()) + detailNode.getColumnNumber() + detailNode.getText().length(); } else { final DetailNode lastChild = detailNode.getChildren()[detailNode.getChildren().length - 1]; lastPosition = findLastPosition(lastChild); } return lastPosition; }
/** * Adjust first line nodes to javadoc indent. * @param tree DetailNode tree root * @param javadocColumnNumber javadoc indent */ private void adjustFirstLineToJavadocIndent(DetailNode tree, int javadocColumnNumber) { if (tree.getLineNumber() == blockCommentLineNumber) { ((JavadocNodeImpl) tree).setColumnNumber(tree.getColumnNumber() + javadocColumnNumber); final DetailNode[] children = tree.getChildren(); for (DetailNode child : children) { adjustFirstLineToJavadocIndent(child, javadocColumnNumber); } } }
@Override public void visitJavadocToken(DetailNode ast) { if (reportVisitJavadocToken) { log(ast.getLineNumber(), ast.getColumnNumber(), MSG_SUMMARY_FIRST_SENTENCE); } }
@Override public void visitJavadocToken(DetailNode ast) { if (reportVisitJavadocToken) { log(ast.getLineNumber(), ast.getColumnNumber(), MSG_SUMMARY_FIRST_SENTENCE); } }
/** * Gets a value for DetailNode object. * @param node DetailNode(Javadoc) node. * @param column column index. * @return value at specified column. */ private static Object getValueAtDetailNode(DetailNode node, int column) { final Object value; switch (column) { case 0: // first column is tree model. no value needed value = null; break; case 1: value = JavadocUtil.getTokenName(node.getType()); break; case 2: value = node.getLineNumber(); break; case 3: value = node.getColumnNumber(); break; case 4: value = node.getText(); break; default: throw new IllegalStateException(UNKNOWN_COLUMN_MSG); } return value; }
/** * Find start and end selection positions from DetailNode line and Column. * @param detailNode DetailNode node for which selection finds */ private void findSelectionPositions(DetailNode detailNode) { selectionStart = lines2position.get(detailNode.getLineNumber()) + detailNode.getColumnNumber(); selectionEnd = findLastPosition(detailNode); }
/** * Print AST. * @param ast the root AST node. * @param rootPrefix prefix for the root node * @param prefix prefix for other nodes * @return string AST. */ public static String printTree(DetailNode ast, String rootPrefix, String prefix) { final StringBuilder messageBuilder = new StringBuilder(1024); DetailNode node = ast; while (node != null) { if (node.getType() == JavadocTokenTypes.JAVADOC) { messageBuilder.append(rootPrefix); } else { messageBuilder.append(prefix); } messageBuilder.append(getIndentation(node)) .append(JavadocUtil.getTokenName(node.getType())).append(" -> ") .append(JavadocUtil.escapeAllControlChars(node.getText())).append(" [") .append(node.getLineNumber()).append(':').append(node.getColumnNumber()) .append(']').append(LINE_SEPARATOR) .append(printTree(JavadocUtil.getFirstChild(node), rootPrefix, prefix)); node = JavadocUtil.getNextSibling(node); } return messageBuilder.toString(); }
/** * Finds the last position of node without children. * @param detailNode DetailNode node. * @return Last position of node without children. */ private int findLastPosition(final DetailNode detailNode) { final int lastPosition; if (detailNode.getChildren().length == 0) { lastPosition = lines2position.get(detailNode.getLineNumber()) + detailNode.getColumnNumber() + detailNode.getText().length(); } else { final DetailNode lastChild = detailNode.getChildren()[detailNode.getChildren().length - 1]; lastPosition = findLastPosition(lastChild); } return lastPosition; }
/** * Adjust first line nodes to javadoc indent. * @param tree DetailNode tree root * @param javadocColumnNumber javadoc indent */ private void adjustFirstLineToJavadocIndent(DetailNode tree, int javadocColumnNumber) { if (tree.getLineNumber() == blockCommentLineNumber) { ((JavadocNodeImpl) tree).setColumnNumber(tree.getColumnNumber() + javadocColumnNumber); final DetailNode[] children = tree.getChildren(); for (DetailNode child : children) { adjustFirstLineToJavadocIndent(child, javadocColumnNumber); } } }
/** * Gets a value for DetailNode object. * @param node DetailNode(Javadoc) node. * @param column column index. * @return value at specified column. */ private static Object getValueAtDetailNode(DetailNode node, int column) { final Object value; switch (column) { case 0: // first column is tree model. no value needed value = null; break; case 1: value = JavadocUtil.getTokenName(node.getType()); break; case 2: value = node.getLineNumber(); break; case 3: value = node.getColumnNumber(); break; case 4: value = node.getText(); break; default: throw new IllegalStateException(UNKNOWN_COLUMN_MSG); } return value; }