当前位置: 首页>>代码示例>>Java>>正文


Java DetailNode类代码示例

本文整理汇总了Java中com.puppycrawl.tools.checkstyle.api.DetailNode的典型用法代码示例。如果您正苦于以下问题:Java DetailNode类的具体用法?Java DetailNode怎么用?Java DetailNode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DetailNode类属于com.puppycrawl.tools.checkstyle.api包,在下文中一共展示了DetailNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: visitJavadocToken

import com.puppycrawl.tools.checkstyle.api.DetailNode; //导入依赖的package包/类
@Override
public void visitJavadocToken(DetailNode ast) {
    if (!startsWithInheritDoc(ast)) {
        final String summaryDoc = getSummarySentence(ast);
        if (summaryDoc.isEmpty()) {
            log(ast.getLineNumber(), MSG_SUMMARY_JAVADOC_MISSING);
        }
        else if (!period.isEmpty()) {
            final String firstSentence = getFirstSentence(ast);
            final int endOfSentence = firstSentence.lastIndexOf(period);
            if (!summaryDoc.contains(period)) {
                log(ast.getLineNumber(), MSG_SUMMARY_FIRST_SENTENCE);
            }
            if (endOfSentence != -1
                    && containsForbiddenFragment(firstSentence.substring(0, endOfSentence))) {
                log(ast.getLineNumber(), MSG_SUMMARY_JAVADOC);
            }
        }
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:21,代码来源:SummaryJavadocCheck.java

示例2: startsWithInheritDoc

import com.puppycrawl.tools.checkstyle.api.DetailNode; //导入依赖的package包/类
/**
 * Checks if the node starts with an {@inheritDoc}.
 * @param root The root node to examine.
 * @return {@code true} if the javadoc starts with an {@inheritDoc}.
 */
private static boolean startsWithInheritDoc(DetailNode root) {
    boolean found = false;
    final DetailNode[] children = root.getChildren();

    for (int i = 0; !found && i < children.length - 1; i++) {
        final DetailNode child = children[i];
        if (child.getType() == JavadocTokenTypes.JAVADOC_INLINE_TAG
                && child.getChildren()[1].getType() == JavadocTokenTypes.INHERIT_DOC_LITERAL) {
            found = true;
        }
        else if (child.getType() != JavadocTokenTypes.LEADING_ASTERISK
                && !CommonUtils.isBlank(child.getText())) {
            break;
        }
    }

    return found;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:24,代码来源:SummaryJavadocCheck.java

示例3: getSummarySentence

import com.puppycrawl.tools.checkstyle.api.DetailNode; //导入依赖的package包/类
/**
 * Checks if period is at the end of sentence.
 * @param ast Javadoc root node.
 * @return error string
 */
private static String getSummarySentence(DetailNode ast) {
    boolean flag = true;
    final StringBuilder result = new StringBuilder(256);
    for (DetailNode child : ast.getChildren()) {
        if (ALLOWED_TYPES.contains(child.getType())) {
            result.append(child.getText());
        }
        else if (child.getType() == JavadocTokenTypes.HTML_ELEMENT
                && CommonUtils.isBlank(result.toString().trim())) {
            result.append(getStringInsideTag(result.toString(),
                    child.getChildren()[0].getChildren()[0]));
        }
        else if (child.getType() == JavadocTokenTypes.JAVADOC_TAG) {
            flag = false;
        }
        if (!flag) {
            break;
        }
    }
    return result.toString().trim();
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:27,代码来源:SummaryJavadocCheck.java

示例4: getFirstSentence

import com.puppycrawl.tools.checkstyle.api.DetailNode; //导入依赖的package包/类
/**
 * Finds and returns first sentence.
 * @param ast Javadoc root node.
 * @return first sentence.
 */
private static String getFirstSentence(DetailNode ast) {
    final StringBuilder result = new StringBuilder(256);
    final String periodSuffix = PERIOD + ' ';
    for (DetailNode child : ast.getChildren()) {
        final String text;
        if (child.getChildren().length == 0) {
            text = child.getText();
        }
        else {
            text = getFirstSentence(child);
        }

        if (child.getType() != JavadocTokenTypes.JAVADOC_INLINE_TAG
            && text.contains(periodSuffix)) {
            result.append(text.substring(0, text.indexOf(periodSuffix) + 1));
            break;
        }
        else {
            result.append(text);
        }
    }
    return result.toString();
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:29,代码来源:SummaryJavadocCheck.java

示例5: checkOrderInTagSection

import com.puppycrawl.tools.checkstyle.api.DetailNode; //导入依赖的package包/类
/**
 * Checks order of atclauses in tag section node.
 * @param javadoc Javadoc root node.
 */
private void checkOrderInTagSection(DetailNode javadoc) {
    int maxIndexOfPreviousTag = 0;

    for (DetailNode node : javadoc.getChildren()) {
        if (node.getType() == JavadocTokenTypes.JAVADOC_TAG) {
            final String tagText = JavadocUtils.getFirstChild(node).getText();
            final int indexOfCurrentTag = tagOrder.indexOf(tagText);

            if (indexOfCurrentTag != -1) {
                if (indexOfCurrentTag < maxIndexOfPreviousTag) {
                    log(node.getLineNumber(), MSG_KEY, tagOrder.toString());
                }
                else {
                    maxIndexOfPreviousTag = indexOfCurrentTag;
                }
            }
        }
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:24,代码来源:AtclauseOrderCheck.java

示例6: isFirstParagraph

import com.puppycrawl.tools.checkstyle.api.DetailNode; //导入依赖的package包/类
/**
 * Determines whether or not the line with paragraph tag is first line in javadoc.
 * @param paragraphTag paragraph tag.
 * @return true, if line with paragraph tag is first line in javadoc.
 */
private static boolean isFirstParagraph(DetailNode paragraphTag) {
    boolean result = true;
    DetailNode previousNode = JavadocUtils.getPreviousSibling(paragraphTag);
    while (previousNode != null) {
        if (previousNode.getType() == JavadocTokenTypes.TEXT
                && !CommonUtils.isBlank(previousNode.getText())
            || previousNode.getType() != JavadocTokenTypes.LEADING_ASTERISK
                && previousNode.getType() != JavadocTokenTypes.NEWLINE
                && previousNode.getType() != JavadocTokenTypes.TEXT) {
            result = false;
            break;
        }
        previousNode = JavadocUtils.getPreviousSibling(previousNode);
    }
    return result;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:22,代码来源:JavadocParagraphCheck.java

示例7: visitJavadocToken

import com.puppycrawl.tools.checkstyle.api.DetailNode; //导入依赖的package包/类
@Override
public void visitJavadocToken(DetailNode ast) {
    if (!isInlineDescription(ast)) {
        final List<DetailNode> textNodes = getAllNewlineNodes(ast);
        for (DetailNode newlineNode : textNodes) {
            final DetailNode textNode = JavadocUtils.getNextSibling(JavadocUtils
                    .getNextSibling(newlineNode));
            if (textNode != null && textNode.getType() == JavadocTokenTypes.TEXT) {
                final String text = textNode.getText();
                if (!CommonUtils.isBlank(text.trim())
                        && (text.length() <= offset
                                || !text.substring(1, offset + 1).trim().isEmpty())) {
                    log(textNode.getLineNumber(), MSG_KEY, offset);
                }
            }
        }
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:19,代码来源:JavadocTagContinuationIndentationCheck.java

示例8: printTree

import com.puppycrawl.tools.checkstyle.api.DetailNode; //导入依赖的package包/类
/**
 * 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(JavadocUtils.getTokenName(node.getType())).append(" -> ")
                .append(JavadocUtils.escapeAllControlChars(node.getText())).append(" [")
                .append(node.getLineNumber()).append(':').append(node.getColumnNumber())
                .append(']').append(LINE_SEPARATOR)
                .append(printTree(JavadocUtils.getFirstChild(node), rootPrefix, prefix));
        node = JavadocUtils.getNextSibling(node);
    }
    return messageBuilder.toString();
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:28,代码来源:DetailNodeTreeStringPrinter.java

示例9: containsInBranch

import com.puppycrawl.tools.checkstyle.api.DetailNode; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:29,代码来源:JavadocUtils.java

示例10: createJavadocNode

import com.puppycrawl.tools.checkstyle.api.DetailNode; //导入依赖的package包/类
/**
 * Creates JavadocNodeImpl node on base of ParseTree node.
 *
 * @param parseTree ParseTree node
 * @param parent DetailNode that will be parent of new node
 * @param index child index that has new node
 * @return JavadocNodeImpl node on base of ParseTree node.
 */
private JavadocNodeImpl createJavadocNode(ParseTree parseTree, DetailNode parent, int index) {
    final JavadocNodeImpl node = new JavadocNodeImpl();
    if (parseTree.getChildCount() == 0
            || "Text".equals(getNodeClassNameWithoutContext(parseTree))) {
        node.setText(parseTree.getText());
    }
    else {
        node.setText(getFormattedNodeClassNameWithoutContext(parseTree));
    }
    node.setColumnNumber(getColumn(parseTree));
    node.setLineNumber(getLine(parseTree) + blockCommentLineNumber);
    node.setIndex(index);
    node.setType(getTokenType(parseTree));
    node.setParent(parent);
    node.setChildren((DetailNode[]) new JavadocNodeImpl[parseTree.getChildCount()]);
    return node;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:26,代码来源:JavadocDetailNodeParser.java

示例11: getChildCount

import com.puppycrawl.tools.checkstyle.api.DetailNode; //导入依赖的package包/类
/**
 * Returns the number of children of parent.
 * @param parent the node to count children for.
 * @return the number of children of the node parent.
 */
public int getChildCount(Object parent) {
    final int result;

    if (parent instanceof DetailNode) {
        result = ((DetailNode) parent).getChildren().length;
    }
    else {
        if (parseMode == ParseMode.JAVA_WITH_JAVADOC_AND_COMMENTS
                && ((AST) parent).getType() == TokenTypes.COMMENT_CONTENT
                && JavadocUtils.isJavadocComment(((DetailAST) parent).getParent())) {
            //getChildCount return 0 on COMMENT_CONTENT,
            //but we need to attach javadoc tree, that is separate tree
            result = 1;
        }
        else {
            result = ((DetailAST) parent).getChildCount();
        }
    }

    return result;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:27,代码来源:ParseTreeTablePresentation.java

示例12: getValueAtDetailNode

import com.puppycrawl.tools.checkstyle.api.DetailNode; //导入依赖的package包/类
/**
 * 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 = JavadocUtils.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;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:32,代码来源:ParseTreeTablePresentation.java

示例13: testGetFirstToken

import com.puppycrawl.tools.checkstyle.api.DetailNode; //导入依赖的package包/类
@Test
public void testGetFirstToken() {
    final JavadocNodeImpl javadocNode = new JavadocNodeImpl();
    final JavadocNodeImpl basetag = new JavadocNodeImpl();
    basetag.setType(JavadocTokenTypes.BASE_TAG);
    final JavadocNodeImpl body = new JavadocNodeImpl();
    body.setType(JavadocTokenTypes.BODY);

    body.setParent(javadocNode);
    basetag.setParent(javadocNode);
    javadocNode.setChildren(basetag, body);

    final DetailNode result = JavadocUtils.findFirstToken(javadocNode, JavadocTokenTypes.BODY);

    assertEquals("Invalid first token", body, result);
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:17,代码来源:JavadocUtilsTest.java

示例14: printTree

import com.puppycrawl.tools.checkstyle.api.DetailNode; //导入依赖的package包/类
public static void printTree(DetailNode aRoot)
{

    if (aRoot.getChildren().length != 0) {
        for (DetailNode node : aRoot.getChildren()) {
            System.out.println(getLevel(node) + node.toString()
                    + " : ["
                    + node.getText().replaceAll("\n", "\\\\n").replaceAll("\r", "\\\\r")
                    .replaceAll("\t", "\\\\t")
                    + "]");

            if (node.getType() == JavadocTokenTypes.TEXT) {
                continue;
            }

            printTree(node);
        }
    }
}
 
开发者ID:checkstyle,项目名称:contribution,代码行数:20,代码来源:JavadocTreePrinter.java

示例15: walk

import com.puppycrawl.tools.checkstyle.api.DetailNode; //导入依赖的package包/类
/**
 * 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 = JavadocUtils.getFirstChild(curNode);
        while (curNode != null && toVisit == null) {
            if (waitsForProcessing) {
                leaveJavadocToken(curNode);
            }

            toVisit = JavadocUtils.getNextSibling(curNode);
            if (toVisit == null) {
                curNode = curNode.getParent();
                if (curNode != null) {
                    waitsForProcessing = shouldBeProcessed(curNode);
                }
            }
        }
        curNode = toVisit;
    }
}
 
开发者ID:checkstyle,项目名称:checkstyle,代码行数:31,代码来源:AbstractJavadocCheck.java


注:本文中的com.puppycrawl.tools.checkstyle.api.DetailNode类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。