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


Java TokenTypes.RCURLY属性代码示例

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


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

示例1: searchVariableUsageExpressions

/**
 * Searches variable usages starting from specified statement.
 * @param variableAst Variable that is used.
 * @param statementAst DetailAST to start searching from.
 * @return entry which contains list with found expressions that use the variable
 *     and distance from specified statement to first found expression.
 */
private static Entry<List<DetailAST>, Integer>
    searchVariableUsageExpressions(final DetailAST variableAst, final DetailAST statementAst) {
    final List<DetailAST> variableUsageExpressions = new ArrayList<DetailAST>();
    int distance = 0;
    DetailAST currentStatementAst = statementAst;
    while (currentStatementAst != null
            && currentStatementAst.getType() != TokenTypes.RCURLY) {
        if (currentStatementAst.getFirstChild() != null) {
            if (isChild(currentStatementAst, variableAst)) {
                variableUsageExpressions.add(currentStatementAst);
            }
            // If expression doesn't contain variable and this variable
            // hasn't been met yet, than distance + 1.
            else if (variableUsageExpressions.isEmpty()
                    && currentStatementAst.getType() != TokenTypes.VARIABLE_DEF) {
                distance++;
            }
        }
        currentStatementAst = currentStatementAst.getNextSibling();
    }
    return new SimpleEntry<List<DetailAST>, Integer>(variableUsageExpressions, distance);
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:29,代码来源:VariableDeclarationUsageDistanceCheck.java

示例2: isEndOfScope

/**
 * Checks line for end of scope.  Handles occurrences of close braces and close parenthesis on
 * the same line.
 *
 * @param lastAnnotationNode the last node of the annotation
 * @param node the node indicating where to begin checking
 * @return true if all the nodes up to the last annotation node are end of scope nodes
 *         false otherwise
 */
private static boolean isEndOfScope(final DetailAST lastAnnotationNode, final DetailAST node) {
    DetailAST checkNode = node;
    boolean endOfScope = true;
    while (endOfScope && !checkNode.equals(lastAnnotationNode)) {
        switch (checkNode.getType()) {
            case TokenTypes.RCURLY:
            case TokenTypes.RBRACK:
                while (checkNode.getNextSibling() == null) {
                    checkNode = checkNode.getParent();
                }
                checkNode = checkNode.getNextSibling();
                break;
            default:
                endOfScope = false;

        }

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

示例3: hasLineBreakAfter

/**
 * Checks if left curly has line break after.
 * @param leftCurly
 *        Left curly token.
 * @return
 *        True, left curly has line break after.
 */
private boolean hasLineBreakAfter(DetailAST leftCurly) {
    DetailAST nextToken = null;
    if (leftCurly.getType() == TokenTypes.SLIST) {
        nextToken = leftCurly.getFirstChild();
    }
    else {
        if (!ignoreEnums
                && leftCurly.getParent().getParent().getType() == TokenTypes.ENUM_DEF) {
            nextToken = leftCurly.getNextSibling();
        }
    }
    return nextToken == null
            || nextToken.getType() == TokenTypes.RCURLY
            || leftCurly.getLineNo() != nextToken.getLineNo();
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:22,代码来源:LeftCurlyCheck.java

示例4: isEmptyBlock

/**
 * Tests if a given {@code DetailAST} is part of an empty block.
 * An example empty block might look like the following
 * <p>
 * <pre>   public void myMethod(int val) {}</pre>
 * </p>
 * In the above, the method body is an empty block ("{}").
 *
 * @param ast the {@code DetailAST} to test.
 * @param parentType the token type of {@code ast}'s parent.
 * @param match the parent token type we're looking to match.
 * @return {@code true} if {@code ast} makes up part of an
 *         empty block contained under a {@code match} token type
 *         node.
 */
private static boolean isEmptyBlock(DetailAST ast, int parentType, int match) {
    final boolean result;
    final int type = ast.getType();
    if (type == TokenTypes.RCURLY) {
        final DetailAST parent = ast.getParent();
        final DetailAST grandParent = ast.getParent().getParent();
        result = parentType == TokenTypes.SLIST
                && parent.getFirstChild().getType() == TokenTypes.RCURLY
                && grandParent.getType() == match;
    }
    else {
        result = type == TokenTypes.SLIST
            && parentType == match
            && ast.getFirstChild().getType() == TokenTypes.RCURLY;
    }
    return result;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:32,代码来源:WhitespaceAroundCheck.java

示例5: checkSlist

/**
 * Checks if a given SLIST terminated by return, throw or,
 * if allowed break, continue.
 * @param slistAst SLIST to check
 * @param useBreak should we consider break as terminator.
 * @param useContinue should we consider continue as terminator.
 * @return true if SLIST is terminated.
 */
private boolean checkSlist(final DetailAST slistAst, boolean useBreak,
                           boolean useContinue) {
    DetailAST lastStmt = slistAst.getLastChild();

    if (lastStmt.getType() == TokenTypes.RCURLY) {
        lastStmt = lastStmt.getPreviousSibling();
    }

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

示例6: checkSwitch

/**
 * Checks if a given switch terminated by return, throw or,
 * if allowed break, continue.
 * @param literalSwitchAst loop to check
 * @param useContinue should we consider continue as terminator.
 * @return true if switch is terminated.
 */
private boolean checkSwitch(final DetailAST literalSwitchAst, boolean useContinue) {
    DetailAST caseGroup = literalSwitchAst.findFirstToken(TokenTypes.CASE_GROUP);
    boolean isTerminated = caseGroup != null;
    while (isTerminated && caseGroup.getType() != TokenTypes.RCURLY) {
        final DetailAST caseBody =
            caseGroup.findFirstToken(TokenTypes.SLIST);
        isTerminated = caseBody != null && isTerminated(caseBody, false, useContinue);
        caseGroup = caseGroup.getNextSibling();
    }
    return isTerminated;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:18,代码来源:FallThroughCheck.java

示例7: calculateDistanceInSingleScope

/**
 * Calculates distance between declaration of variable and its first usage
 * in single scope.
 * @param semicolonAst
 *        Regular node of Ast which is checked for content of checking
 *        variable.
 * @param variableIdentAst
 *        Variable which distance is calculated for.
 * @return entry which contains expression with variable usage and distance.
 */
private static Entry<DetailAST, Integer> calculateDistanceInSingleScope(
        DetailAST semicolonAst, DetailAST variableIdentAst) {
    int dist = 0;
    boolean firstUsageFound = false;
    DetailAST currentAst = semicolonAst;
    DetailAST variableUsageAst = null;

    while (!firstUsageFound && currentAst != null
            && currentAst.getType() != TokenTypes.RCURLY) {
        if (currentAst.getFirstChild() != null) {

            if (isChild(currentAst, variableIdentAst)) {
                dist = getDistToVariableUsageInChildNode(currentAst, variableIdentAst, dist);
                variableUsageAst = currentAst;
                firstUsageFound = true;
            }
            else if (currentAst.getType() != TokenTypes.VARIABLE_DEF) {
                dist++;
            }
        }
        currentAst = currentAst.getNextSibling();
    }

    // If variable wasn't used after its declaration, distance is 0.
    if (!firstUsageFound) {
        dist = 0;
    }

    return new SimpleEntry<DetailAST, Integer>(variableUsageAst, dist);
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:40,代码来源:VariableDeclarationUsageDistanceCheck.java

示例8: isEmptyCatchBlock

/**
 * Checks if catch block is empty or contains only comments.
 * @param catchAst {@link TokenTypes#LITERAL_CATCH LITERAL_CATCH}
 * @return true if catch block is empty.
 */
private static boolean isEmptyCatchBlock(DetailAST catchAst) {
    boolean result = true;
    final DetailAST slistToken = catchAst.findFirstToken(TokenTypes.SLIST);
    DetailAST catchBlockStmt = slistToken.getFirstChild();
    while (catchBlockStmt.getType() != TokenTypes.RCURLY) {
        if (catchBlockStmt.getType() != TokenTypes.SINGLE_LINE_COMMENT
             && catchBlockStmt.getType() != TokenTypes.BLOCK_COMMENT_BEGIN) {
            result = false;
            break;
        }
        catchBlockStmt = catchBlockStmt.getNextSibling();
    }
    return result;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:19,代码来源:EmptyCatchBlockCheck.java

示例9: visitToken

@Override
public void visitToken(DetailAST ast) {
    if (hasMultipleLinesBefore(ast)) {
        log(ast.getLineNo(), MSG_MULTIPLE_LINES, ast.getText());
    }
    if (!allowMultipleEmptyLinesInsideClassMembers) {
        processMultipleLinesInside(ast);
    }

    DetailAST nextToken = ast.getNextSibling();
    while (nextToken != null && isComment(nextToken)) {
        nextToken = nextToken.getNextSibling();
    }
    if (nextToken != null) {
        final int astType = ast.getType();
        switch (astType) {
            case TokenTypes.VARIABLE_DEF:
                processVariableDef(ast, nextToken);
                break;
            case TokenTypes.IMPORT:
                processImport(ast, nextToken, astType);
                break;
            case TokenTypes.PACKAGE_DEF:
                processPackage(ast, nextToken);
                break;
            default:
                if (nextToken.getType() == TokenTypes.RCURLY) {
                    if (hasNotAllowedTwoEmptyLinesBefore(nextToken)) {
                        log(ast.getLineNo(), MSG_MULTIPLE_LINES_AFTER, ast.getText());
                    }
                }
                else if (!hasEmptyLineAfter(ast)) {
                    log(nextToken.getLineNo(), MSG_SHOULD_BE_SEPARATED,
                        nextToken.getText());
                }
        }
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:38,代码来源:EmptyLineSeparatorCheck.java

示例10: isViolatingEmptyLineBetweenFieldsPolicy

/**
 * Checks whether token placement violates policy of empty line between fields.
 * @param detailAST token to be analyzed
 * @return true if policy is violated and warning should be raised; false otherwise
 */
private boolean isViolatingEmptyLineBetweenFieldsPolicy(DetailAST detailAST) {
    return allowNoEmptyLineBetweenFields
                && detailAST.getType() != TokenTypes.VARIABLE_DEF
                && detailAST.getType() != TokenTypes.RCURLY
            || !allowNoEmptyLineBetweenFields
                && detailAST.getType() != TokenTypes.RCURLY;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:12,代码来源:EmptyLineSeparatorCheck.java

示例11: isAnonymousInnerClassEnd

/**
 * Check for "})" or "};" or "},". Happens with anon-inners
 * @param currentType token
 * @param nextChar next symbol
 * @return true is that is end of anon inner class
 */
private static boolean isAnonymousInnerClassEnd(int currentType, char nextChar) {
    return currentType == TokenTypes.RCURLY
            && (nextChar == ')'
                    || nextChar == ';'
                    || nextChar == ','
                    || nextChar == '.');
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:13,代码来源:WhitespaceAroundCheck.java

示例12: isPartOfDoubleBraceInitializerForPreviousToken

/**
 * Check if given ast is part of double brace initializer and if it
 * should omit checking if previous token is separated by whitespace.
 * @param ast ast to check
 * @return true if it should omit checking for previous token, false otherwise
 */
private static boolean isPartOfDoubleBraceInitializerForPreviousToken(DetailAST ast) {
    final boolean initializerBeginsAfterClassBegins = ast.getType() == TokenTypes.SLIST
            && ast.getParent().getType() == TokenTypes.INSTANCE_INIT;
    final boolean classEndsAfterInitializerEnds = ast.getType() == TokenTypes.RCURLY
            && ast.getPreviousSibling() != null
            && ast.getPreviousSibling().getType() == TokenTypes.INSTANCE_INIT;
    return initializerBeginsAfterClassBegins || classEndsAfterInitializerEnds;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:14,代码来源:WhitespaceAroundCheck.java

示例13: isPartOfDoubleBraceInitializerForNextToken

/**
 * Check if given ast is part of double brace initializer and if it
 * should omit checking if next token is separated by whitespace.
 * See <a href="https://github.com/checkstyle/checkstyle/pull/2845">
 * PR#2845</a> for more information why this function was needed.
 * @param ast ast to check
 * @return true if it should omit checking for next token, false otherwise
 */
private static boolean isPartOfDoubleBraceInitializerForNextToken(DetailAST ast) {
    final boolean classBeginBeforeInitializerBegin = ast.getType() == TokenTypes.LCURLY
        && ast.getNextSibling().getType() == TokenTypes.INSTANCE_INIT;
    final boolean initalizerEndsBeforeClassEnds = ast.getType() == TokenTypes.RCURLY
        && ast.getParent().getType() == TokenTypes.SLIST
        && ast.getParent().getParent().getType() == TokenTypes.INSTANCE_INIT
        && ast.getParent().getParent().getNextSibling().getType() == TokenTypes.RCURLY;
    return classBeginBeforeInitializerBegin || initalizerEndsBeforeClassEnds;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:17,代码来源:WhitespaceAroundCheck.java

示例14: testGetAcceptableTokens

@Test
public void testGetAcceptableTokens() {
    final WhitespaceAroundCheck whitespaceAroundCheckObj = new WhitespaceAroundCheck();
    final int[] actual = whitespaceAroundCheckObj.getAcceptableTokens();
    final int[] expected = {
        TokenTypes.ASSIGN,
        TokenTypes.ARRAY_INIT,
        TokenTypes.BAND,
        TokenTypes.BAND_ASSIGN,
        TokenTypes.BOR,
        TokenTypes.BOR_ASSIGN,
        TokenTypes.BSR,
        TokenTypes.BSR_ASSIGN,
        TokenTypes.BXOR,
        TokenTypes.BXOR_ASSIGN,
        TokenTypes.COLON,
        TokenTypes.DIV,
        TokenTypes.DIV_ASSIGN,
        TokenTypes.DO_WHILE,
        TokenTypes.EQUAL,
        TokenTypes.GE,
        TokenTypes.GT,
        TokenTypes.LAMBDA,
        TokenTypes.LAND,
        TokenTypes.LCURLY,
        TokenTypes.LE,
        TokenTypes.LITERAL_CATCH,
        TokenTypes.LITERAL_DO,
        TokenTypes.LITERAL_ELSE,
        TokenTypes.LITERAL_FINALLY,
        TokenTypes.LITERAL_FOR,
        TokenTypes.LITERAL_IF,
        TokenTypes.LITERAL_RETURN,
        TokenTypes.LITERAL_SWITCH,
        TokenTypes.LITERAL_SYNCHRONIZED,
        TokenTypes.LITERAL_TRY,
        TokenTypes.LITERAL_WHILE,
        TokenTypes.LOR,
        TokenTypes.LT,
        TokenTypes.MINUS,
        TokenTypes.MINUS_ASSIGN,
        TokenTypes.MOD,
        TokenTypes.MOD_ASSIGN,
        TokenTypes.NOT_EQUAL,
        TokenTypes.PLUS,
        TokenTypes.PLUS_ASSIGN,
        TokenTypes.QUESTION,
        TokenTypes.RCURLY,
        TokenTypes.SL,
        TokenTypes.SLIST,
        TokenTypes.SL_ASSIGN,
        TokenTypes.SR,
        TokenTypes.SR_ASSIGN,
        TokenTypes.STAR,
        TokenTypes.STAR_ASSIGN,
        TokenTypes.LITERAL_ASSERT,
        TokenTypes.TYPE_EXTENSION_AND,
        TokenTypes.WILDCARD_TYPE,
        TokenTypes.GENERIC_START,
        TokenTypes.GENERIC_END,
        TokenTypes.ELLIPSIS,
    };
    assertArrayEquals("Default acceptable tokens are invalid", expected, actual);
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:64,代码来源:WhitespaceAroundCheckTest.java

示例15: getDefaultTokens

@Override
public int[] getDefaultTokens() {
    return new int[] {
        TokenTypes.ASSIGN,
        TokenTypes.BAND,
        TokenTypes.BAND_ASSIGN,
        TokenTypes.BOR,
        TokenTypes.BOR_ASSIGN,
        TokenTypes.BSR,
        TokenTypes.BSR_ASSIGN,
        TokenTypes.BXOR,
        TokenTypes.BXOR_ASSIGN,
        TokenTypes.COLON,
        TokenTypes.DIV,
        TokenTypes.DIV_ASSIGN,
        TokenTypes.DO_WHILE,
        TokenTypes.EQUAL,
        TokenTypes.GE,
        TokenTypes.GT,
        TokenTypes.LAMBDA,
        TokenTypes.LAND,
        TokenTypes.LCURLY,
        TokenTypes.LE,
        TokenTypes.LITERAL_CATCH,
        TokenTypes.LITERAL_DO,
        TokenTypes.LITERAL_ELSE,
        TokenTypes.LITERAL_FINALLY,
        TokenTypes.LITERAL_FOR,
        TokenTypes.LITERAL_IF,
        TokenTypes.LITERAL_RETURN,
        TokenTypes.LITERAL_SWITCH,
        TokenTypes.LITERAL_SYNCHRONIZED,
        TokenTypes.LITERAL_TRY,
        TokenTypes.LITERAL_WHILE,
        TokenTypes.LOR,
        TokenTypes.LT,
        TokenTypes.MINUS,
        TokenTypes.MINUS_ASSIGN,
        TokenTypes.MOD,
        TokenTypes.MOD_ASSIGN,
        TokenTypes.NOT_EQUAL,
        TokenTypes.PLUS,
        TokenTypes.PLUS_ASSIGN,
        TokenTypes.QUESTION,
        TokenTypes.RCURLY,
        TokenTypes.SL,
        TokenTypes.SLIST,
        TokenTypes.SL_ASSIGN,
        TokenTypes.SR,
        TokenTypes.SR_ASSIGN,
        TokenTypes.STAR,
        TokenTypes.STAR_ASSIGN,
        TokenTypes.LITERAL_ASSERT,
        TokenTypes.TYPE_EXTENSION_AND,
    };
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:56,代码来源:WhitespaceAroundCheck.java


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