本文整理汇总了Java中com.puppycrawl.tools.checkstyle.api.TokenTypes.LITERAL_ELSE属性的典型用法代码示例。如果您正苦于以下问题:Java TokenTypes.LITERAL_ELSE属性的具体用法?Java TokenTypes.LITERAL_ELSE怎么用?Java TokenTypes.LITERAL_ELSE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.puppycrawl.tools.checkstyle.api.TokenTypes
的用法示例。
在下文中一共展示了TokenTypes.LITERAL_ELSE属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processIf
/**
* process the given SymTabAST as an if block
*
* @param tree the SymTabAST to process
* @return <code>void</code>
* @see #makeBlock(SymTabAST)
* @see #walkTree(SymTabAST, boolean)
* @see #processElse(SymTabAST)
*/
public void processIf(SymTabAST tree) {
BlockDef block = makeBlock(tree);
SymTabAST expr = tree.findFirstToken(TokenTypes.EXPR);
SymTabAST ifBranch = (SymTabAST)expr.getNextSibling();
// handle Checkstyle grammar
if (ifBranch.getType() == TokenTypes.RPAREN) {
ifBranch = (SymTabAST) ifBranch.getNextSibling();
}
SymTabAST elseBranch = (SymTabAST)ifBranch.getNextSibling();
// handle Checkstyle grammar
if ((elseBranch != null) && (elseBranch.getType() == TokenTypes.SEMI)) {
elseBranch = (SymTabAST) elseBranch.getNextSibling();
}
if ((elseBranch != null) && (elseBranch.getType() == TokenTypes.LITERAL_ELSE)) {
elseBranch = (SymTabAST) elseBranch.getFirstChild();
}
symbolTable.pushScope( block );
walkTree(expr, false);
walkTree(ifBranch, false);
symbolTable.popScope();
processElse(elseBranch);
}
示例2: testGetRequiredTokens
@Test
public void testGetRequiredTokens() {
final NPathComplexityCheck npathComplexityCheckObj = new NPathComplexityCheck();
final int[] actual = npathComplexityCheckObj.getRequiredTokens();
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("Required tokens should not be null", actual);
Assert.assertArrayEquals("Invalid required tokens", expected, actual);
}
示例3: getDefaultTokens
@Override
public int[] getDefaultTokens() {
return new int[] {
TokenTypes.LITERAL_WHILE,
TokenTypes.LITERAL_TRY,
TokenTypes.LITERAL_FINALLY,
TokenTypes.LITERAL_DO,
TokenTypes.LITERAL_IF,
TokenTypes.LITERAL_ELSE,
TokenTypes.LITERAL_FOR,
TokenTypes.INSTANCE_INIT,
TokenTypes.STATIC_INIT,
TokenTypes.LITERAL_SWITCH,
TokenTypes.LITERAL_SYNCHRONIZED,
};
}
示例4: getAcceptableTokens
@Override
public int[] getAcceptableTokens() {
return new int[] {
TokenTypes.LITERAL_TRY,
TokenTypes.LITERAL_CATCH,
TokenTypes.LITERAL_FINALLY,
TokenTypes.LITERAL_IF,
TokenTypes.LITERAL_ELSE,
TokenTypes.CLASS_DEF,
TokenTypes.METHOD_DEF,
TokenTypes.CTOR_DEF,
TokenTypes.LITERAL_FOR,
TokenTypes.LITERAL_WHILE,
TokenTypes.LITERAL_DO,
TokenTypes.STATIC_INIT,
TokenTypes.INSTANCE_INIT,
TokenTypes.LAMBDA,
};
}
示例5: visitToken
@Override
public void visitToken(DetailAST ast) {
final DetailAST slistAST = ast.findFirstToken(TokenTypes.SLIST);
boolean isElseIf = false;
if (ast.getType() == TokenTypes.LITERAL_ELSE
&& ast.findFirstToken(TokenTypes.LITERAL_IF) != null) {
isElseIf = true;
}
final boolean isDefaultInAnnotation = isDefaultInAnnotation(ast);
final boolean skipStatement = isSkipStatement(ast);
final boolean skipEmptyLoopBody = allowEmptyLoopBody && isEmptyLoopBody(ast);
if (slistAST == null && !isElseIf && !isDefaultInAnnotation
&& !skipStatement && !skipEmptyLoopBody) {
log(ast.getLineNo(), MSG_KEY_NEED_BRACES, ast.getText());
}
}
示例6: isSingleLineIf
/**
* Checks if current if statement is single-line statement, e.g.:
* <p>
* {@code
* if (obj.isValid()) return true;
* }
* </p>
* @param literalIf {@link TokenTypes#LITERAL_IF if statement}.
* @return true if current if statement is single-line statement.
*/
private static boolean isSingleLineIf(DetailAST literalIf) {
boolean result = false;
if (literalIf.getParent().getType() == TokenTypes.SLIST) {
final DetailAST literalIfLastChild = literalIf.getLastChild();
final DetailAST block;
if (literalIfLastChild.getType() == TokenTypes.LITERAL_ELSE) {
block = literalIfLastChild.getPreviousSibling();
}
else {
block = literalIfLastChild;
}
final DetailAST ifCondition = literalIf.findFirstToken(TokenTypes.EXPR);
result = ifCondition.getLineNo() == block.getLineNo();
}
return result;
}
示例7: getAcceptableTokens
@Override
public int[] getAcceptableTokens() {
return new int[] {
TokenTypes.COMMA,
TokenTypes.SEMI,
TokenTypes.TYPECAST,
TokenTypes.LITERAL_IF,
TokenTypes.LITERAL_ELSE,
TokenTypes.LITERAL_WHILE,
TokenTypes.LITERAL_DO,
TokenTypes.LITERAL_FOR,
TokenTypes.DO_WHILE,
};
}
示例8: 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);
}
示例9: 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;
}
示例10: isIfAfterElse
/**
* Determines if this 'if' statement is part of an 'else' clause
* and on the same line.
*
* @return true if this 'if' is part of an 'else', false otherwise
*/
private boolean isIfAfterElse() {
// check if there is an 'else' and an 'if' on the same line
final DetailAST parent = getMainAst().getParent();
return parent.getType() == TokenTypes.LITERAL_ELSE
&& parent.getLineNo() == getMainAst().getLineNo();
}
示例11: getDefaultTokens
@Override
public int[] getDefaultTokens() {
return new int[] {
TokenTypes.LITERAL_TRY,
TokenTypes.LITERAL_CATCH,
TokenTypes.LITERAL_FINALLY,
TokenTypes.LITERAL_IF,
TokenTypes.LITERAL_ELSE,
};
}
示例12: getDefaultTokens
@Override
public int[] getDefaultTokens() {
return new int[] {
TokenTypes.LITERAL_DO,
TokenTypes.LITERAL_ELSE,
TokenTypes.LITERAL_FOR,
TokenTypes.LITERAL_IF,
TokenTypes.LITERAL_WHILE,
};
}
示例13: getAcceptableTokens
@Override
public int[] getAcceptableTokens() {
return new int[] {
TokenTypes.LITERAL_DO,
TokenTypes.LITERAL_ELSE,
TokenTypes.LITERAL_FOR,
TokenTypes.LITERAL_IF,
TokenTypes.LITERAL_WHILE,
TokenTypes.LITERAL_CASE,
TokenTypes.LITERAL_DEFAULT,
TokenTypes.LAMBDA,
};
}
示例14: handleIf
/**
* processes an if statement and resolves references in it
*
* @param block the <code>BlockDef</code> to process
*/
private void handleIf(BlockDef block) {
SymTabAST node = block.getTreeNode();
SymTabAST conditional =
(node.findFirstToken(TokenTypes.EXPR));
resolveExpression(conditional, block, null, true);
SymTabAST body = (SymTabAST) conditional.getNextSibling();
// Handle Checkstyle grammar
if (body.getType() == TokenTypes.RPAREN) {
body = (SymTabAST) body.getNextSibling();
}
if (body != null) {
if (body.getType() == TokenTypes.SLIST) {
handleSList(body, block);
}
else {
resolveExpression(body, block, null, true);
}
SymTabAST elseBody = (SymTabAST) body.getNextSibling();
//handle Checkstyle grammar
while ((elseBody != null)
&& (elseBody.getType() != TokenTypes.LITERAL_ELSE)) {
elseBody = (SymTabAST) elseBody.getNextSibling();
}
/*
if (elseBody != null && elseBody.getType() == TokenTypes.SLIST) {
handleSList(elseBody, block);
}else{
resolveExpression(elseBody, block, null, true);
}
*/
if (elseBody != null) {
elseBody = (SymTabAST) elseBody.getFirstChild();
}
if (elseBody != null) {
resolveExpression(elseBody, block.getParentScope(), null, true);
}
}
}
示例15: getAcceptableTokens
@Override
public int[] getAcceptableTokens() {
return new int[] {
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,
};
}