本文整理汇总了Java中com.puppycrawl.tools.checkstyle.api.TokenTypes.LITERAL_IF属性的典型用法代码示例。如果您正苦于以下问题:Java TokenTypes.LITERAL_IF属性的具体用法?Java TokenTypes.LITERAL_IF怎么用?Java TokenTypes.LITERAL_IF使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.puppycrawl.tools.checkstyle.api.TokenTypes
的用法示例。
在下文中一共展示了TokenTypes.LITERAL_IF属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAcceptableTokens
@Override
public int[] getAcceptableTokens() {
return new int[] {
TokenTypes.CTOR_DEF,
TokenTypes.METHOD_DEF,
TokenTypes.INSTANCE_INIT,
TokenTypes.STATIC_INIT,
TokenTypes.LITERAL_WHILE,
TokenTypes.LITERAL_DO,
TokenTypes.LITERAL_FOR,
TokenTypes.LITERAL_IF,
TokenTypes.LITERAL_SWITCH,
TokenTypes.LITERAL_CASE,
TokenTypes.LITERAL_CATCH,
TokenTypes.QUESTION,
TokenTypes.LAND,
TokenTypes.LOR,
};
}
示例2: getRequiredTokens
@Override
public int[] getRequiredTokens() {
return new int[] {
TokenTypes.METHOD_CALL,
TokenTypes.CLASS_DEF,
TokenTypes.METHOD_DEF,
TokenTypes.LITERAL_IF,
TokenTypes.LITERAL_FOR,
TokenTypes.LITERAL_WHILE,
TokenTypes.LITERAL_DO,
TokenTypes.LITERAL_CATCH,
TokenTypes.LITERAL_TRY,
TokenTypes.VARIABLE_DEF,
TokenTypes.PARAMETER_DEF,
TokenTypes.CTOR_DEF,
TokenTypes.SLIST,
TokenTypes.ENUM_DEF,
TokenTypes.ENUM_CONSTANT_DEF,
TokenTypes.LITERAL_NEW,
};
}
示例3: testGetAcceptableTokens
@Test
public void testGetAcceptableTokens() {
final CyclomaticComplexityCheck cyclomaticComplexityCheckObj =
new CyclomaticComplexityCheck();
final int[] actual = cyclomaticComplexityCheckObj.getAcceptableTokens();
final int[] expected = {
TokenTypes.CTOR_DEF,
TokenTypes.METHOD_DEF,
TokenTypes.INSTANCE_INIT,
TokenTypes.STATIC_INIT,
TokenTypes.LITERAL_WHILE,
TokenTypes.LITERAL_DO,
TokenTypes.LITERAL_FOR,
TokenTypes.LITERAL_IF,
TokenTypes.LITERAL_SWITCH,
TokenTypes.LITERAL_CASE,
TokenTypes.LITERAL_CATCH,
TokenTypes.QUESTION,
TokenTypes.LAND,
TokenTypes.LOR,
};
Assert.assertArrayEquals("Invalid acceptable tokens", expected, actual);
}
示例4: 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);
}
示例5: makeAcceptableTokens
/**
* Returns array of acceptable tokens.
* @return acceptableTokens.
*/
private static int[] makeAcceptableTokens() {
return new int[] {TokenTypes.ANNOTATION,
TokenTypes.ANNOTATION_FIELD_DEF,
TokenTypes.CTOR_CALL,
TokenTypes.CTOR_DEF,
TokenTypes.DOT,
TokenTypes.ENUM_CONSTANT_DEF,
TokenTypes.EXPR,
TokenTypes.LITERAL_CATCH,
TokenTypes.LITERAL_DO,
TokenTypes.LITERAL_FOR,
TokenTypes.LITERAL_IF,
TokenTypes.LITERAL_NEW,
TokenTypes.LITERAL_SWITCH,
TokenTypes.LITERAL_SYNCHRONIZED,
TokenTypes.LITERAL_WHILE,
TokenTypes.METHOD_CALL,
TokenTypes.METHOD_DEF,
TokenTypes.QUESTION,
TokenTypes.RESOURCE_SPECIFICATION,
TokenTypes.SUPER_CTOR_CALL,
TokenTypes.LAMBDA,
};
}
示例6: 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,
};
}
示例7: getAcceptableTokens
@Override
public int[] getAcceptableTokens() {
return new int[] {
TokenTypes.LITERAL_WHILE,
TokenTypes.LITERAL_TRY,
TokenTypes.LITERAL_CATCH,
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,
TokenTypes.LITERAL_CASE,
TokenTypes.LITERAL_DEFAULT,
TokenTypes.ARRAY_INIT,
};
}
示例8: getAcceptableTokens
@Override
public int[] getAcceptableTokens() {
return new int[] {
TokenTypes.INTERFACE_DEF,
TokenTypes.CLASS_DEF,
TokenTypes.ANNOTATION_DEF,
TokenTypes.ENUM_DEF,
TokenTypes.CTOR_DEF,
TokenTypes.METHOD_DEF,
TokenTypes.ENUM_CONSTANT_DEF,
TokenTypes.LITERAL_WHILE,
TokenTypes.LITERAL_TRY,
TokenTypes.LITERAL_CATCH,
TokenTypes.LITERAL_FINALLY,
TokenTypes.LITERAL_SYNCHRONIZED,
TokenTypes.LITERAL_SWITCH,
TokenTypes.LITERAL_DO,
TokenTypes.LITERAL_IF,
TokenTypes.LITERAL_ELSE,
TokenTypes.LITERAL_FOR,
TokenTypes.STATIC_INIT,
TokenTypes.OBJBLOCK,
TokenTypes.LAMBDA,
};
}
示例9: processElse
/**
* process the given SymTabAST as an else block
*
* @param tree the SymTabAST to process
* @return <code>void</code>
* @see #processIf(SymTabAST)
* @see #makeElseBlock(SymTabAST)
*/
public void processElse(SymTabAST tree) {
if (tree != null) {
if (tree.getType() == TokenTypes.LITERAL_IF) {
processIf(tree);
}
else {
makeElseBlock(tree);
}
}
}
示例10: isSingleLineStatement
/**
* Checks if current statement is single-line statement, e.g.:
* <p>
* {@code
* if (obj.isValid()) return true;
* }
* </p>
* <p>
* {@code
* while (obj.isValid()) return true;
* }
* </p>
* @param statement if, for, while, do-while, lambda, else, case, default statements.
* @return true if current statement is single-line statement.
*/
private static boolean isSingleLineStatement(DetailAST statement) {
final boolean result;
switch (statement.getType()) {
case TokenTypes.LITERAL_IF:
result = isSingleLineIf(statement);
break;
case TokenTypes.LITERAL_FOR:
result = isSingleLineFor(statement);
break;
case TokenTypes.LITERAL_DO:
result = isSingleLineDoWhile(statement);
break;
case TokenTypes.LITERAL_WHILE:
result = isSingleLineWhile(statement);
break;
case TokenTypes.LAMBDA:
result = isSingleLineLambda(statement);
break;
case TokenTypes.LITERAL_CASE:
result = isSingleLineCase(statement);
break;
case TokenTypes.LITERAL_DEFAULT:
result = isSingleLineDefault(statement);
break;
default:
result = isSingleLineElse(statement);
break;
}
return result;
}
示例11: getDetailsForIfElse
/**
* Collects validation details for LITERAL_IF and LITERAL_ELSE.
* @param ast a {@code DetailAST} value
* @return object containing all details to make a validation
*/
private static Details getDetailsForIfElse(DetailAST ast) {
boolean shouldCheckLastRcurly = false;
DetailAST rcurly = null;
final DetailAST lcurly;
DetailAST nextToken;
final int tokenType = ast.getType();
if (tokenType == TokenTypes.LITERAL_IF) {
nextToken = ast.findFirstToken(TokenTypes.LITERAL_ELSE);
if (nextToken == null) {
shouldCheckLastRcurly = true;
nextToken = getNextToken(ast);
lcurly = ast.getLastChild();
}
else {
lcurly = nextToken.getPreviousSibling();
}
if (lcurly.getType() == TokenTypes.SLIST) {
rcurly = lcurly.getLastChild();
}
}
else {
shouldCheckLastRcurly = true;
nextToken = getNextToken(ast);
lcurly = ast.getFirstChild();
if (lcurly.getType() == TokenTypes.SLIST) {
rcurly = lcurly.getLastChild();
}
}
return new Details(lcurly, rcurly, nextToken, shouldCheckLastRcurly);
}
示例12: getDetails
/**
* Collects validation Details.
* @param ast a {@code DetailAST} value
* @return object containing all details to make a validation
*/
private static Details getDetails(DetailAST ast) {
final Details details;
switch (ast.getType()) {
case TokenTypes.LITERAL_TRY:
case TokenTypes.LITERAL_CATCH:
case TokenTypes.LITERAL_FINALLY:
details = getDetailsForTryCatchFinally(ast);
break;
case TokenTypes.LITERAL_IF:
case TokenTypes.LITERAL_ELSE:
details = getDetailsForIfElse(ast);
break;
case TokenTypes.LITERAL_DO:
case TokenTypes.LITERAL_WHILE:
case TokenTypes.LITERAL_FOR:
details = getDetailsForLoops(ast);
break;
case TokenTypes.LAMBDA:
details = getDetailsForLambda(ast);
break;
default:
details = getDetailsForOthers(ast);
break;
}
return details;
}
示例13: 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,
};
}
示例14: 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;
}
示例15: getDefaultTokens
@Override
public int[] getDefaultTokens() {
return new int[] {
TokenTypes.LITERAL_TRY,
TokenTypes.LITERAL_CATCH,
TokenTypes.LITERAL_FINALLY,
TokenTypes.LITERAL_IF,
TokenTypes.LITERAL_ELSE,
};
}