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


Java DetailAST.getNextSibling方法代码示例

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


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

示例1: testGetAccessModifierFromModifiersToken

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Test
public void testGetAccessModifierFromModifiersToken() throws Exception {
    final DetailAST privateVariable = getNodeFromFile(TokenTypes.VARIABLE_DEF);
    final DetailAST protectedVariable = privateVariable.getNextSibling();
    final DetailAST publicVariable = protectedVariable.getNextSibling();
    final DetailAST packageVariable = publicVariable.getNextSibling();

    assertEquals("Invalid access modifier", AccessModifier.PRIVATE,
            CheckUtils.getAccessModifierFromModifiersToken(privateVariable.getFirstChild()));
    assertEquals("Invalid access modifier", AccessModifier.PROTECTED,
            CheckUtils.getAccessModifierFromModifiersToken(protectedVariable.getFirstChild()));
    assertEquals("Invalid access modifier", AccessModifier.PUBLIC,
            CheckUtils.getAccessModifierFromModifiersToken(publicVariable.getFirstChild()));
    assertEquals("Invalid access modifier", AccessModifier.PACKAGE,
            CheckUtils.getAccessModifierFromModifiersToken(packageVariable.getFirstChild()));
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:17,代码来源:CheckUtilsTest.java

示例2: testQueryAllMethodDefinitionsInContext

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Test
public void testQueryAllMethodDefinitionsInContext() throws Exception {
    final String objectXpath = "/CLASS_DEF[@text='InputXpathMapperAst']//OBJBLOCK";
    final RootNode rootNode = getRootNode("InputXpathMapperAst.java");
    final List<Item> objectNodes = getXpathItems(objectXpath, rootNode);
    assertEquals("Invalid number of nodes", 1, objectNodes.size());
    final AbstractNode objNode = (AbstractNode) objectNodes.get(0);
    final String methodsXpath = "METHOD_DEF";
    final List<Item> methodsNodes = getXpathItems(methodsXpath, objNode);
    assertEquals("Invalid number of nodes", 2, methodsNodes.size());
    final DetailAST[] actual = convertToArray(methodsNodes);
    final DetailAST expectedMethodDefNode = getSiblingByType(rootNode.getUnderlyingNode(),
            TokenTypes.CLASS_DEF)
            .findFirstToken(TokenTypes.OBJBLOCK)
            .findFirstToken(TokenTypes.METHOD_DEF);
    final DetailAST[] expected = {expectedMethodDefNode,
        expectedMethodDefNode.getNextSibling()};
    assertArrayEquals("Result nodes differ from expected", expected, actual);
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:20,代码来源:XpathMapperTest.java

示例3: containsDefaultSwitch

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * Checks if the case group or its sibling contain the 'default' switch.
 * @param caseGroupAst first case group to check.
 * @return true if 'default' switch found.
 */
private static boolean containsDefaultSwitch(DetailAST caseGroupAst) {
    DetailAST nextAst = caseGroupAst;
    boolean found = false;

    while (nextAst != null) {
        if (nextAst.findFirstToken(TokenTypes.LITERAL_DEFAULT) != null) {
            found = true;
            break;
        }

        nextAst = nextAst.getNextSibling();
    }

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

示例4: isSingleLineCase

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * Checks if current case statement is single-line statement, e.g.:
 * <p>
 * {@code
 * case 1: doSomeStuff(); break;
 * case 2: doSomeStuff(); break;
 * case 3: ;
 * }
 * </p>
 * @param literalCase {@link TokenTypes#LITERAL_CASE case statement}.
 * @return true if current case statement is single-line statement.
 */
private static boolean isSingleLineCase(DetailAST literalCase) {
    boolean result = false;
    final DetailAST slist = literalCase.getNextSibling();
    if (slist == null) {
        result = true;
    }
    else {
        final DetailAST block = slist.getFirstChild();
        if (block.getType() != TokenTypes.SLIST) {
            final DetailAST caseBreak = slist.findFirstToken(TokenTypes.LITERAL_BREAK);
            if (caseBreak != null) {
                final boolean atOneLine = literalCase.getLineNo() == block.getLineNo();
                result = atOneLine && block.getLineNo() == caseBreak.getLineNo();
            }
        }
    }
    return result;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:31,代码来源:NeedBracesCheck.java

示例5: isCorrectJavadocPosition

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * Checks Javadoc comment it's in right place.
 * <p>From Javadoc util documentation:
 * "Placement of comments - Documentation comments are recognized only when placed
 * immediately before class, interface, constructor, method, field or annotation field
 * declarations -- see the class example, method example, and field example.
 * Documentation comments placed in the body of a method are ignored."</p>
 * <p>If there are many documentation comments per declaration statement,
 * only the last one will be recognized.</p>
 *
 * @param blockComment Block comment AST
 * @return true if Javadoc is in right place
 * @see <a href="https://docs.oracle.com/javase/8/docs/technotes/tools/unix/javadoc.html">
 *     Javadoc util documentation</a>
 */
private static boolean isCorrectJavadocPosition(DetailAST blockComment) {
    // We must be sure that after this one there are no other documentation comments.
    DetailAST sibling = blockComment.getNextSibling();
    while (sibling != null) {
        if (sibling.getType() == TokenTypes.BLOCK_COMMENT_BEGIN) {
            if (isJavadocComment(getBlockCommentContent(sibling))) {
                // Found another javadoc comment, so this one should be ignored.
                break;
            }
            sibling = sibling.getNextSibling();
        }
        else if (sibling.getType() == TokenTypes.SINGLE_LINE_COMMENT) {
            sibling = sibling.getNextSibling();
        }
        else {
            // Annotation, declaration or modifier is here. Do not check further.
            sibling = null;
        }
    }
    return sibling == null
        && (BlockCommentPosition.isOnType(blockComment)
            || BlockCommentPosition.isOnMember(blockComment));
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:39,代码来源:JavadocUtils.java

示例6: processExpression

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * Checks parens inside {@link TokenTypes#EXPR}, {@link TokenTypes#QUESTION}
 * and {@link TokenTypes#METHOD_CALL}.
 * @param ast the token to check.
 */
private void processExpression(DetailAST ast) {
    if (ast.branchContains(TokenTypes.LPAREN)) {
        DetailAST childAst = ast.getFirstChild();
        while (childAst != null) {
            if (childAst.getType() == TokenTypes.LPAREN) {
                processLeft(childAst);
            }
            else if (childAst.getType() == TokenTypes.RPAREN && !isInTypecast(childAst)) {
                processRight(childAst);
            }
            else if (!isAcceptableToken(childAst)) {
                //Traverse all subtree tokens which will never be configured
                //to be launched in visitToken()
                processExpression(childAst);
            }
            childAst = childAst.getNextSibling();
        }
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:25,代码来源:ParenPadCheck.java

示例7: getNextSubTreeNode

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * Gets the next node of a syntactical tree (child of a current node or
 * sibling of a current node, or sibling of a parent of a current node).
 * @param currentNodeAst Current node in considering
 * @param subTreeRootAst SubTree root
 * @return Current node after bypassing, if current node reached the root of a subtree
 *        method returns null
 */
private static DetailAST
    getNextSubTreeNode(DetailAST currentNodeAst, DetailAST subTreeRootAst) {
    DetailAST currentNode = currentNodeAst;
    DetailAST toVisitAst = currentNode.getFirstChild();
    while (toVisitAst == null) {
        toVisitAst = currentNode.getNextSibling();
        if (toVisitAst == null) {
            if (currentNode.getParent().equals(subTreeRootAst)
                     && currentNode.getParent().getColumnNo() == subTreeRootAst.getColumnNo()) {
                break;
            }
            currentNode = currentNode.getParent();
        }
    }
    return toVisitAst;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:25,代码来源:VisibilityModifierCheck.java

示例8: checkIf

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * Checks if a given IF terminated by return, throw or,
 * if allowed break, continue.
 * @param ast IF to check
 * @param useBreak should we consider break as terminator.
 * @param useContinue should we consider continue as terminator.
 * @return true if IF is terminated.
 */
private boolean checkIf(final DetailAST ast, boolean useBreak,
                        boolean useContinue) {
    final DetailAST thenStmt = ast.findFirstToken(TokenTypes.RPAREN)
            .getNextSibling();
    final DetailAST elseStmt = thenStmt.getNextSibling();
    boolean isTerminated = isTerminated(thenStmt, useBreak, useContinue);

    if (isTerminated && elseStmt != null) {
        isTerminated = isTerminated(elseStmt.getFirstChild(),
            useBreak, useContinue);
    }
    else if (elseStmt == null) {
        isTerminated = false;
    }
    return isTerminated;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:25,代码来源:FallThroughCheck.java

示例9: findLeftCurly

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * Calculates the left curly corresponding to the block to be checked.
 *
 * @param ast a {@code DetailAST} value
 * @return the left curly corresponding to the block to be checked
 */
private static DetailAST findLeftCurly(DetailAST ast) {
    final DetailAST leftCurly;
    final DetailAST slistAST = ast.findFirstToken(TokenTypes.SLIST);
    if ((ast.getType() == TokenTypes.LITERAL_CASE
            || ast.getType() == TokenTypes.LITERAL_DEFAULT)
            && ast.getNextSibling() != null
            && ast.getNextSibling().getFirstChild() != null
            && ast.getNextSibling().getFirstChild().getType() == TokenTypes.SLIST) {
        leftCurly = ast.getNextSibling().getFirstChild();
    }
    else if (slistAST == null) {
        leftCurly = ast.findFirstToken(TokenTypes.LCURLY);
    }
    else {
        leftCurly = slistAST;
    }
    return leftCurly;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:25,代码来源:EmptyBlockCheck.java

示例10: createChildren

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * Iterates children of the current node and
 * recursively creates new Xpath-nodes.
 */
private void createChildren() {
    DetailAST currentChild = detailAst.getFirstChild();
    while (currentChild != null) {
        if (currentChild.getType() != TokenTypes.IDENT) {
            final ElementNode child = new ElementNode(root, this, currentChild);
            addChild(child);
        }
        currentChild = currentChild.getNextSibling();
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:15,代码来源:ElementNode.java

示例11: getNextSiblingSkipComments

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * Get next sibling node skipping any comment nodes.
 * @param node current node
 * @return next sibling
 */
private static DetailAST getNextSiblingSkipComments(DetailAST node) {
    DetailAST result = node.getNextSibling();
    while (result.getType() == TokenTypes.SINGLE_LINE_COMMENT
            || result.getType() == TokenTypes.BLOCK_COMMENT_BEGIN) {
        result = result.getNextSibling();
    }
    return result;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:14,代码来源:BlockCommentPosition.java

示例12: isCommentForMultiblock

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * Whether the comment might have been used for the next block in a multi-block structure.
 * @param endBlockStmt the end of the current block.
 * @return true, if the comment might have been used for the next
 *     block in a multi-block structure.
 */
private static boolean isCommentForMultiblock(DetailAST endBlockStmt) {
    final DetailAST nextBlock = endBlockStmt.getParent().getNextSibling();
    final int endBlockLineNo = endBlockStmt.getLineNo();
    final DetailAST catchAst = endBlockStmt.getParent().getParent();
    final DetailAST finallyAst = catchAst.getNextSibling();
    return nextBlock != null && nextBlock.getLineNo() == endBlockLineNo
            || finallyAst != null
                && catchAst.getType() == TokenTypes.LITERAL_CATCH
                && finallyAst.getLineNo() == endBlockLineNo;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:17,代码来源:CommentsIndentationCheck.java

示例13: printTree

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * Print AST.
 * @param ast the root AST node.
 * @return string AST.
 */
private static String printTree(DetailAST ast) {
    final StringBuilder messageBuilder = new StringBuilder(1024);
    DetailAST node = ast;
    while (node != null) {
        messageBuilder.append(getIndentation(node))
                .append(getNodeInfo(node))
                .append(LINE_SEPARATOR)
                .append(printTree(node.getFirstChild()));
        node = node.getNextSibling();
    }
    return messageBuilder.toString();
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:18,代码来源:AstTreeStringPrinter.java

示例14: isEmptyLoopBody

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * Checks if current loop statement does not have body, e.g.:
 * <p>
 * {@code
 *   while (value.incrementValue() < 5);
 *   ...
 *   for(int i = 0; i < 10; value.incrementValue());
 * }
 * </p>
 * @param ast ast token.
 * @return true if current loop statement does not have body.
 */
private static boolean isEmptyLoopBody(DetailAST ast) {
    boolean noBodyLoop = false;

    if (ast.getType() == TokenTypes.LITERAL_FOR
            || ast.getType() == TokenTypes.LITERAL_WHILE) {
        DetailAST currentToken = ast.getFirstChild();
        while (currentToken.getNextSibling() != null) {
            currentToken = currentToken.getNextSibling();
        }
        noBodyLoop = currentToken.getType() == TokenTypes.EMPTY_STAT;
    }
    return noBodyLoop;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:26,代码来源:NeedBracesCheck.java

示例15: getNextStmt

import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
 * Returns the next statement of a comment.
 * @param comment comment.
 * @return the next statement of a comment.
 */
private static DetailAST getNextStmt(DetailAST comment) {
    DetailAST nextStmt = comment.getNextSibling();
    while (nextStmt != null
            && isComment(nextStmt)
            && comment.getColumnNo() != nextStmt.getColumnNo()) {
        nextStmt = nextStmt.getNextSibling();
    }
    return nextStmt;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:15,代码来源:CommentsIndentationCheck.java


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