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


Java TokenTypes.LABELED_STAT属性代码示例

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


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

示例1: getColumn

/**
 * gets a column number for the tree;  if the current SymTabAST node does not have one associated
 * with it, traverse its children until a column number is found.  Failure results in column
 * number value of 0.
 *
 * @param tree the SymTabAST to process
 *
 * @return int the resulting line number (0 if none is found)
 */
public static int getColumn(SymTabAST tree) {
    SymTabAST indexedNode = tree;

    // find a node that actually has line number info
    // REDTAG -- a label's ':' is a real token and has (the wrong) column info
    // because it is the parent of the ident node that people will want
    if (indexedNode.getColumnNo() == 0
        || indexedNode.getType() == TokenTypes.LABELED_STAT) {
        indexedNode = (SymTabAST) indexedNode.getFirstChild();

        while (indexedNode != null && indexedNode.getColumnNo() == 0) {
            indexedNode = (SymTabAST) indexedNode.getNextSibling();
        }

        if (indexedNode == null) {
            // we're screwed
            indexedNode = tree;
        }
    }

    return indexedNode.getColumnNo();
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:31,代码来源:ASTUtil.java

示例2: convertToString

/**
 * Converts given AST node to string representation.
 * @param ast node to be represented as string
 * @return string representation of AST node
 */
private static String convertToString(DetailAST ast) {
    final String tokenText;
    switch (ast.getType()) {
        case TokenTypes.LABELED_STAT:
            tokenText = ast.getFirstChild().getText() + ast.getText();
            break;
        // multiline tokens need to become singlelined
        case TokenTypes.COMMENT_CONTENT:
            tokenText = JavadocUtils.escapeAllControlChars(ast.getText());
            break;
        default:
            tokenText = ast.getText();
            break;
    }
    return tokenText;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:21,代码来源:IllegalTokenCheck.java

示例3: getRequiredTokens

@Override
public int[] getRequiredTokens() {
    return new int[] {
        TokenTypes.CLASS_DEF,
        TokenTypes.INTERFACE_DEF,
        TokenTypes.METHOD_DEF,
        TokenTypes.CTOR_DEF,
        TokenTypes.INSTANCE_INIT,
        TokenTypes.STATIC_INIT,
        TokenTypes.PACKAGE_DEF,
        TokenTypes.IMPORT,
        TokenTypes.VARIABLE_DEF,
        TokenTypes.CTOR_CALL,
        TokenTypes.SUPER_CTOR_CALL,
        TokenTypes.LITERAL_IF,
        TokenTypes.LITERAL_ELSE,
        TokenTypes.LITERAL_WHILE,
        TokenTypes.LITERAL_DO,
        TokenTypes.LITERAL_FOR,
        TokenTypes.LITERAL_SWITCH,
        TokenTypes.LITERAL_BREAK,
        TokenTypes.LITERAL_CONTINUE,
        TokenTypes.LITERAL_RETURN,
        TokenTypes.LITERAL_THROW,
        TokenTypes.LITERAL_SYNCHRONIZED,
        TokenTypes.LITERAL_CATCH,
        TokenTypes.LITERAL_FINALLY,
        TokenTypes.EXPR,
        TokenTypes.LABELED_STAT,
        TokenTypes.LITERAL_CASE,
        TokenTypes.LITERAL_DEFAULT,
    };
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:33,代码来源:JavaNCSSCheck.java

示例4: isExpressionCountable

/**
 * Checks if an expression is countable for the ncss metric.
 *
 * @param ast the AST
 * @return true if the expression is countable, false otherwise
 */
private static boolean isExpressionCountable(DetailAST ast) {
    final boolean countable;

    //count expressions only if they are direct child to a slist (method
    // body, for loop...)
    //or direct child of label,if,else,do,while,for
    final int parentType = ast.getParent().getType();
    switch (parentType) {
        case TokenTypes.SLIST :
        case TokenTypes.LABELED_STAT :
        case TokenTypes.LITERAL_FOR :
        case TokenTypes.LITERAL_DO :
        case TokenTypes.LITERAL_WHILE :
        case TokenTypes.LITERAL_IF :
        case TokenTypes.LITERAL_ELSE :
            //don't count if or loop conditions
            final DetailAST prevSibling = ast.getPreviousSibling();
            countable = prevSibling == null
                || prevSibling.getType() != TokenTypes.LPAREN;
            break;
        default :
            countable = false;
            break;
    }
    return countable;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:32,代码来源:JavaNCSSCheck.java

示例5: getDistToVariableUsageInChildNode

/**
 * Returns the distance to variable usage for in the child node.
 * @param childNode child node.
 * @param varIdent variable variable identifier.
 * @param currentDistToVarUsage current distance to the variable usage.
 * @return the distance to variable usage for in the child node.
 */
private static int getDistToVariableUsageInChildNode(DetailAST childNode, DetailAST varIdent,
                                                     int currentDistToVarUsage) {
    DetailAST examineNode = childNode;
    if (examineNode.getType() == TokenTypes.LABELED_STAT) {
        examineNode = examineNode.getFirstChild().getNextSibling();
    }

    int resultDist = currentDistToVarUsage;
    switch (examineNode.getType()) {
        case TokenTypes.VARIABLE_DEF:
            resultDist++;
            break;
        case TokenTypes.SLIST:
            resultDist = 0;
            break;
        case TokenTypes.LITERAL_FOR:
        case TokenTypes.LITERAL_WHILE:
        case TokenTypes.LITERAL_DO:
        case TokenTypes.LITERAL_IF:
        case TokenTypes.LITERAL_SWITCH:
            if (isVariableInOperatorExpr(examineNode, varIdent)) {
                resultDist++;
            }
            else {
                // variable usage is in inner scope
                // reset counters, because we can't determine distance
                resultDist = 0;
            }
            break;
        default:
            if (examineNode.findFirstToken(TokenTypes.SLIST) == null) {
                resultDist++;
            }
            else {
                resultDist = 0;
            }
    }
    return resultDist;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:46,代码来源:VariableDeclarationUsageDistanceCheck.java

示例6: testGetAcceptableTokens

@Test
public void testGetAcceptableTokens() {
    final JavaNCSSCheck javaNcssCheckObj = new JavaNCSSCheck();
    final int[] actual = javaNcssCheckObj.getAcceptableTokens();
    final int[] expected = {
        TokenTypes.CLASS_DEF,
        TokenTypes.INTERFACE_DEF,
        TokenTypes.METHOD_DEF,
        TokenTypes.CTOR_DEF,
        TokenTypes.INSTANCE_INIT,
        TokenTypes.STATIC_INIT,
        TokenTypes.PACKAGE_DEF,
        TokenTypes.IMPORT,
        TokenTypes.VARIABLE_DEF,
        TokenTypes.CTOR_CALL,
        TokenTypes.SUPER_CTOR_CALL,
        TokenTypes.LITERAL_IF,
        TokenTypes.LITERAL_ELSE,
        TokenTypes.LITERAL_WHILE,
        TokenTypes.LITERAL_DO,
        TokenTypes.LITERAL_FOR,
        TokenTypes.LITERAL_SWITCH,
        TokenTypes.LITERAL_BREAK,
        TokenTypes.LITERAL_CONTINUE,
        TokenTypes.LITERAL_RETURN,
        TokenTypes.LITERAL_THROW,
        TokenTypes.LITERAL_SYNCHRONIZED,
        TokenTypes.LITERAL_CATCH,
        TokenTypes.LITERAL_FINALLY,
        TokenTypes.EXPR,
        TokenTypes.LABELED_STAT,
        TokenTypes.LITERAL_CASE,
        TokenTypes.LITERAL_DEFAULT,
    };
    Assert.assertNotNull("Acceptable tokens should not be null", actual);
    Assert.assertArrayEquals("Invalid acceptable tokens", expected, actual);
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:37,代码来源:JavaNCSSCheckTest.java

示例7: testGetRequiredTokens

@Test
public void testGetRequiredTokens() {
    final JavaNCSSCheck javaNcssCheckObj = new JavaNCSSCheck();
    final int[] actual = javaNcssCheckObj.getRequiredTokens();
    final int[] expected = {
        TokenTypes.CLASS_DEF,
        TokenTypes.INTERFACE_DEF,
        TokenTypes.METHOD_DEF,
        TokenTypes.CTOR_DEF,
        TokenTypes.INSTANCE_INIT,
        TokenTypes.STATIC_INIT,
        TokenTypes.PACKAGE_DEF,
        TokenTypes.IMPORT,
        TokenTypes.VARIABLE_DEF,
        TokenTypes.CTOR_CALL,
        TokenTypes.SUPER_CTOR_CALL,
        TokenTypes.LITERAL_IF,
        TokenTypes.LITERAL_ELSE,
        TokenTypes.LITERAL_WHILE,
        TokenTypes.LITERAL_DO,
        TokenTypes.LITERAL_FOR,
        TokenTypes.LITERAL_SWITCH,
        TokenTypes.LITERAL_BREAK,
        TokenTypes.LITERAL_CONTINUE,
        TokenTypes.LITERAL_RETURN,
        TokenTypes.LITERAL_THROW,
        TokenTypes.LITERAL_SYNCHRONIZED,
        TokenTypes.LITERAL_CATCH,
        TokenTypes.LITERAL_FINALLY,
        TokenTypes.EXPR,
        TokenTypes.LABELED_STAT,
        TokenTypes.LITERAL_CASE,
        TokenTypes.LITERAL_DEFAULT,
    };
    Assert.assertNotNull("Required tokens should not be null", actual);
    Assert.assertArrayEquals("Invalid required tokens", expected, actual);
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:37,代码来源:JavaNCSSCheckTest.java

示例8: getDefaultTokens

@Override
public int[] getDefaultTokens() {
    return new int[] {
        TokenTypes.LABELED_STAT,
    };
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:6,代码来源:IllegalTokenCheck.java

示例9: hasLabelBefore

/**
 * Check if the top level token has label before.
 * @return true if the top level token has label before.
 */
private boolean hasLabelBefore() {
    final DetailAST parent = getTopLevelAst().getParent();
    return parent.getType() == TokenTypes.LABELED_STAT
        && parent.getLineNo() == getTopLevelAst().getLineNo();
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:9,代码来源:BlockParentHandler.java


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