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


Java TokenTypes.CASE_GROUP属性代码示例

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


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

示例1: getRequiredTokens

@Override
public int[] getRequiredTokens() {
    return new int[] {
        TokenTypes.CTOR_DEF,
        TokenTypes.METHOD_DEF,
        TokenTypes.STATIC_INIT,
        TokenTypes.INSTANCE_INIT,
        TokenTypes.LITERAL_WHILE,
        TokenTypes.LITERAL_DO,
        TokenTypes.LITERAL_FOR,
        TokenTypes.LITERAL_IF,
        TokenTypes.LITERAL_ELSE,
        TokenTypes.LITERAL_SWITCH,
        TokenTypes.CASE_GROUP,
        TokenTypes.LITERAL_TRY,
        TokenTypes.LITERAL_CATCH,
        TokenTypes.QUESTION,
        TokenTypes.LITERAL_RETURN,
        TokenTypes.LITERAL_DEFAULT,
    };
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:21,代码来源:NPathComplexityCheck.java

示例2: visitToken

@Override
public void visitToken(DetailAST ast) {
    final DetailAST nextGroup = ast.getNextSibling();
    final boolean isLastGroup = nextGroup.getType() != TokenTypes.CASE_GROUP;
    if (!isLastGroup || checkLastCaseGroup) {
        final DetailAST slist = ast.findFirstToken(TokenTypes.SLIST);

        if (slist != null && !isTerminated(slist, true, true)
            && !hasFallThroughComment(ast, nextGroup)) {
            if (isLastGroup) {
                log(ast, MSG_FALL_THROUGH_LAST);
            }
            else {
                log(nextGroup, MSG_FALL_THROUGH);
            }
        }
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:18,代码来源:FallThroughCheck.java

示例3: getBlockEndToken

/**
 * Returns the token which ends the code block.
 * @param blockNameIdent block name identifier.
 * @param blockStartToken token which starts the block.
 * @return the token which ends the code block.
 */
private static DetailAST getBlockEndToken(DetailAST blockNameIdent, DetailAST blockStartToken) {
    DetailAST blockEndToken = null;
    final DetailAST blockNameIdentParent = blockNameIdent.getParent();
    if (blockNameIdentParent.getType() == TokenTypes.CASE_GROUP) {
        blockEndToken = blockNameIdentParent.getNextSibling();
    }
    else {
        final Set<DetailAST> rcurlyTokens = getAllTokensOfType(blockNameIdent,
                TokenTypes.RCURLY);
        for (DetailAST currentRcurly : rcurlyTokens) {
            final DetailAST parent = currentRcurly.getParent();
            if (blockStartToken.getLineNo() == parent.getLineNo()) {
                blockEndToken = currentRcurly;
            }
        }
    }
    return blockEndToken;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:24,代码来源:RequireThisCheck.java

示例4: handleCommentAtTheEndOfTheCodeBlock

/**
 * Handles a comment which is placed at the end of non empty code block.
 * Note, if single line comment is placed at the end of non empty block the comment should have
 * the same indentation level as the previous statement. For example:
 * <p>
 * {@code
 *    if (a == true) {
 *        int b = 1;
 *        // comment
 *    }
 * }
 * </p>
 * @param prevStmt previous statement.
 * @param comment comment to check.
 * @param nextStmt next statement.
 */
private void handleCommentAtTheEndOfTheCodeBlock(DetailAST prevStmt, DetailAST comment,
                                                 DetailAST nextStmt) {
    if (prevStmt != null) {
        if (prevStmt.getType() == TokenTypes.LITERAL_CASE
                || prevStmt.getType() == TokenTypes.CASE_GROUP
                || prevStmt.getType() == TokenTypes.LITERAL_DEFAULT) {
            if (comment.getColumnNo() < nextStmt.getColumnNo()) {
                log(comment.getLineNo(), getMessageKey(comment), nextStmt.getLineNo(),
                    comment.getColumnNo(), nextStmt.getColumnNo());
            }
        }
        else if (isCommentForMultiblock(nextStmt)) {
            if (!areSameLevelIndented(comment, prevStmt, nextStmt)) {
                logMultilineIndentation(prevStmt, comment, nextStmt);
            }
        }
        else if (!areSameLevelIndented(comment, prevStmt, prevStmt)) {
            final int prevStmtLineNo = prevStmt.getLineNo();
            log(comment.getLineNo(), getMessageKey(comment), prevStmtLineNo,
                    comment.getColumnNo(), getLineStart(prevStmtLineNo));
        }
    }

}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:40,代码来源:CommentsIndentationCheck.java

示例5: getNextToken

/**
 * Get the token to start counting the number of lines to add to the distance aim from.
 * @param checkedStatement the checked statement.
 * @return the token to start counting the number of lines to add to the distance aim from.
 */
private DetailAST getNextToken(DetailAST checkedStatement) {
    DetailAST nextToken;
    if (checkedStatement.getType() == TokenTypes.SLIST
            || checkedStatement.getType() == TokenTypes.ARRAY_INIT
            || checkedStatement.getType() == TokenTypes.CASE_GROUP) {
        nextToken = checkedStatement.getFirstChild();
    }
    else {
        nextToken = checkedStatement.getNextSibling();
    }
    if (nextToken != null && isComment(nextToken) && isTrailingComment(nextToken)) {
        nextToken = nextToken.getNextSibling();
    }
    return nextToken;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:20,代码来源:CommentsIndentationCheck.java

示例6: isNotRelevantSituation

/**
 * Is ast not a target of Check.
 * @param ast ast
 * @param currentType type of ast
 * @return true is ok to skip validation
 */
private boolean isNotRelevantSituation(DetailAST ast, int currentType) {
    final int parentType = ast.getParent().getType();
    final boolean starImport = currentType == TokenTypes.STAR
            && parentType == TokenTypes.DOT;
    final boolean slistInsideCaseGroup = currentType == TokenTypes.SLIST
            && parentType == TokenTypes.CASE_GROUP;

    final boolean starImportOrSlistInsideCaseGroup = starImport || slistInsideCaseGroup;
    final boolean colonOfCaseOrDefaultOrForEach =
            isColonOfCaseOrDefault(currentType, parentType)
                    || isColonOfForEach(currentType, parentType);
    final boolean emptyBlockOrType =
            isEmptyBlock(ast, parentType)
                || allowEmptyTypes && isEmptyType(ast);

    return starImportOrSlistInsideCaseGroup
            || colonOfCaseOrDefaultOrForEach
            || emptyBlockOrType
            || isArrayInitialization(currentType, parentType);
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:26,代码来源:WhitespaceAroundCheck.java

示例7: testGetAcceptableTokens

@Test
public void testGetAcceptableTokens() {
    final NPathComplexityCheck npathComplexityCheckObj = new NPathComplexityCheck();
    final int[] actual = npathComplexityCheckObj.getAcceptableTokens();
    final int[] expected = {
        TokenTypes.CTOR_DEF,
        TokenTypes.METHOD_DEF,
        TokenTypes.STATIC_INIT,
        TokenTypes.INSTANCE_INIT,
        TokenTypes.LITERAL_WHILE,
        TokenTypes.LITERAL_DO,
        TokenTypes.LITERAL_FOR,
        TokenTypes.LITERAL_IF,
        TokenTypes.LITERAL_ELSE,
        TokenTypes.LITERAL_SWITCH,
        TokenTypes.CASE_GROUP,
        TokenTypes.LITERAL_TRY,
        TokenTypes.LITERAL_CATCH,
        TokenTypes.QUESTION,
        TokenTypes.LITERAL_RETURN,
        TokenTypes.LITERAL_DEFAULT,
    };
    Assert.assertNotNull("Acceptable tokens should not be null", actual);
    Assert.assertArrayEquals("Invalid acceptable tokens", expected, actual);
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:25,代码来源:NPathComplexityCheckTest.java

示例8: handleSwitch

/**
 * processes a switch statement and resolves references in it
 *
 * @param block the <code>BlockDef</code> to process
 */
private void handleSwitch(BlockDef block) {
    SymTabAST node = block.getTreeNode();

    SymTabAST expr = node.findFirstToken(TokenTypes.EXPR);
    resolveExpression(expr, block, null, true);

    SymTabAST caseGroup = (SymTabAST) (expr.getNextSibling());
    while (caseGroup != null
        && (caseGroup.getType() != TokenTypes.CASE_GROUP)) {
        caseGroup = (SymTabAST) caseGroup.getNextSibling();
    }
    if (caseGroup != null) {
        while (caseGroup.getType() == TokenTypes.CASE_GROUP) {
            SymTabAST caseNode =
                caseGroup.findFirstToken(TokenTypes.LITERAL_CASE);
            while (caseNode != null
                && caseNode.getType() == TokenTypes.LITERAL_CASE) {
                resolveExpression(
                    (SymTabAST) caseNode.getFirstChild(),
                    block,
                    null,
                    true);
                caseNode = (SymTabAST) caseNode.getNextSibling();
            }

            SymTabAST caseSlist =
                caseGroup.findFirstToken(TokenTypes.SLIST);
            handleSList(caseSlist, block);

            caseGroup = (SymTabAST) (caseGroup.getNextSibling());
        }
    }
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:38,代码来源:Resolver.java

示例9: leaveToken

@Override
public void leaveToken(DetailAST ast) {
    switch (ast.getType()) {
        case TokenTypes.LITERAL_WHILE:
        case TokenTypes.LITERAL_DO:
        case TokenTypes.LITERAL_FOR:
        case TokenTypes.LITERAL_IF:
        case TokenTypes.LITERAL_SWITCH:
            leaveConditional();
            break;
        case TokenTypes.LITERAL_TRY:
            leaveMultiplyingConditional();
            break;
        case TokenTypes.LITERAL_RETURN:
        case TokenTypes.QUESTION:
            leaveUnitaryOperator();
            break;
        case TokenTypes.LITERAL_CATCH:
            leaveAddingConditional();
            break;
        case TokenTypes.LITERAL_DEFAULT:
            leaveBranch();
            break;
        case TokenTypes.LITERAL_ELSE:
        case TokenTypes.CASE_GROUP:
            leaveBranch();
            branchVisited = false;
            break;
        case TokenTypes.CTOR_DEF:
        case TokenTypes.METHOD_DEF:
        case TokenTypes.INSTANCE_INIT:
        case TokenTypes.STATIC_INIT:
            leaveMethodDef(ast);
            break;
        default:
            break;
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:38,代码来源:NPathComplexityCheck.java

示例10: leaveToken

@Override
public void leaveToken(DetailAST ast) {
    Map<String, FinalVariableCandidate> scope = null;
    switch (ast.getType()) {
        case TokenTypes.OBJBLOCK:
        case TokenTypes.CTOR_DEF:
        case TokenTypes.METHOD_DEF:
            scope = scopeStack.pop().scope;
            break;
        case TokenTypes.SLIST:
            // [email protected][MoveVariableInsideIf] assignment value is modified later so it can't be
            // moved
            final Deque<DetailAST> prevScopeUninitializedVariableData =
                prevScopeUninitializedVariables.peek();
            boolean containsBreak = false;
            if (ast.getParent().getType() != TokenTypes.CASE_GROUP
                || findLastChildWhichContainsSpecifiedToken(ast.getParent().getParent(),
                        TokenTypes.CASE_GROUP, TokenTypes.SLIST) == ast.getParent()) {
                containsBreak = scopeStack.peek().containsBreak;
                scope = scopeStack.pop().scope;
                prevScopeUninitializedVariables.pop();
            }
            final DetailAST parent = ast.getParent();
            if (containsBreak || shouldUpdateUninitializedVariables(parent)) {
                updateAllUninitializedVariables(prevScopeUninitializedVariableData);
            }
            updateCurrentScopeAssignedVariables();
            break;
        default:
            // do nothing
    }
    if (scope != null) {
        for (FinalVariableCandidate candidate : scope.values()) {
            final DetailAST ident = candidate.variableIdent;
            log(ident.getLineNo(), ident.getColumnNo(), MSG_KEY, ident.getText());
        }
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:38,代码来源:FinalLocalVariableCheck.java

示例11: getFirstNodeInsideSwitchBlock

/**
 * Gets first Ast node inside SWITCH block if variable usage is met
 * only inside the block (not in its declaration!).
 * @param block
 *        Ast node represents SWITCH block.
 * @param variable
 *        Variable which is checked for content in block.
 * @return If variable usage is met only inside the block
 *         (not in its declaration!) than return the first Ast node
 *         of this block, otherwise - null.
 */
private static DetailAST getFirstNodeInsideSwitchBlock(
        DetailAST block, DetailAST variable) {

    DetailAST currentNode = block
            .findFirstToken(TokenTypes.CASE_GROUP);
    final List<DetailAST> variableUsageExpressions =
            new ArrayList<DetailAST>();

    // Checking variable usage inside all CASE blocks.
    while (currentNode.getType() == TokenTypes.CASE_GROUP) {
        final DetailAST lastNodeInCaseGroup =
                currentNode.getLastChild();

        if (isChild(lastNodeInCaseGroup, variable)) {
            variableUsageExpressions.add(lastNodeInCaseGroup);
        }
        currentNode = currentNode.getNextSibling();
    }

    // If variable usage exists in several related blocks, then
    // firstNodeInsideBlock = null, otherwise if variable usage exists
    // only inside one block, then get node from
    // variableUsageExpressions.
    DetailAST firstNodeInsideBlock = null;
    if (variableUsageExpressions.size() == 1) {
        firstNodeInsideBlock = variableUsageExpressions.get(0);
    }

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

示例12: isInEmptyCaseBlock

/**
 * Checks whether case block is empty.
 * @param nextStmt previous statement.
 * @param prevStmt next statement.
 * @return true if case block is empty.
 */
private static boolean isInEmptyCaseBlock(DetailAST prevStmt, DetailAST nextStmt) {
    return prevStmt != null
        && nextStmt != null
        && (prevStmt.getType() == TokenTypes.LITERAL_CASE
            || prevStmt.getType() == TokenTypes.CASE_GROUP)
        && (nextStmt.getType() == TokenTypes.LITERAL_CASE
            || nextStmt.getType() == TokenTypes.LITERAL_DEFAULT);
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:14,代码来源:CommentsIndentationCheck.java

示例13: isBlockStart

/**
 * Whether the AST node starts a block.
 * @param root the AST node to check.
 * @return true if the AST node starts a block.
 */
private static boolean isBlockStart(DetailAST root) {
    return root.getType() == TokenTypes.SLIST
            || root.getType() == TokenTypes.OBJBLOCK
            || root.getType() == TokenTypes.ARRAY_INIT
            || root.getType() == TokenTypes.CASE_GROUP;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:11,代码来源:CommentsIndentationCheck.java

示例14: getPrevStatementFromSwitchBlock

/**
 * Gets comment's previous statement from switch block.
 * @param comment {@link TokenTypes#SINGLE_LINE_COMMENT single-line comment}.
 * @return comment's previous statement or null if previous statement is absent.
 */
private static DetailAST getPrevStatementFromSwitchBlock(DetailAST comment) {
    final DetailAST prevStmt;
    final DetailAST parentStatement = comment.getParent();
    if (parentStatement.getType() == TokenTypes.CASE_GROUP) {
        prevStmt = getPrevStatementWhenCommentIsUnderCase(parentStatement);
    }
    else {
        prevStmt = getPrevCaseToken(parentStatement);
    }
    return prevStmt;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:16,代码来源:CommentsIndentationCheck.java

示例15: visitToken

@Override
public void visitToken(DetailAST ast) {
    final DetailAST leftCurly = findLeftCurly(ast);
    if (leftCurly != null) {
        if (option == BlockOption.STATEMENT) {
            final boolean emptyBlock;
            if (leftCurly.getType() == TokenTypes.LCURLY) {
                emptyBlock = leftCurly.getNextSibling().getType() != TokenTypes.CASE_GROUP;
            }
            else {
                emptyBlock = leftCurly.getChildCount() <= 1;
            }
            if (emptyBlock) {
                log(leftCurly.getLineNo(),
                    leftCurly.getColumnNo(),
                    MSG_KEY_BLOCK_NO_STATEMENT,
                    ast.getText());
            }
        }
        else if (!hasText(leftCurly)) {
            log(leftCurly.getLineNo(),
                leftCurly.getColumnNo(),
                MSG_KEY_BLOCK_EMPTY,
                ast.getText());
        }
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:27,代码来源:EmptyBlockCheck.java


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