本文整理汇总了Java中com.puppycrawl.tools.checkstyle.api.TokenTypes.LITERAL_DEFAULT属性的典型用法代码示例。如果您正苦于以下问题:Java TokenTypes.LITERAL_DEFAULT属性的具体用法?Java TokenTypes.LITERAL_DEFAULT怎么用?Java TokenTypes.LITERAL_DEFAULT使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.puppycrawl.tools.checkstyle.api.TokenTypes
的用法示例。
在下文中一共展示了TokenTypes.LITERAL_DEFAULT属性的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,
};
}
示例2: 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));
}
}
}
示例3: 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,
};
}
示例4: findLeftCurly
/**
* Calculates the left curly corresponding to the block to be checked.
*
* @param ast a {@code DetailAST} value
* @return the left curly corresponding to the block to be checked
*/
private static DetailAST findLeftCurly(DetailAST ast) {
final DetailAST leftCurly;
final DetailAST slistAST = ast.findFirstToken(TokenTypes.SLIST);
if ((ast.getType() == TokenTypes.LITERAL_CASE
|| ast.getType() == TokenTypes.LITERAL_DEFAULT)
&& ast.getNextSibling() != null
&& ast.getNextSibling().getFirstChild() != null
&& ast.getNextSibling().getFirstChild().getType() == TokenTypes.SLIST) {
leftCurly = ast.getNextSibling().getFirstChild();
}
else if (slistAST == null) {
leftCurly = ast.findFirstToken(TokenTypes.LCURLY);
}
else {
leftCurly = slistAST;
}
return leftCurly;
}
示例5: visitToken
@Override
public void visitToken(DetailAST ast) {
final DetailAST parent = ast.getParent();
//we do not want to check colon for cases and defaults
if (ast.getType() != TokenTypes.COLON
|| parent.getType() != TokenTypes.LITERAL_DEFAULT
&& parent.getType() != TokenTypes.LITERAL_CASE) {
final String text = ast.getText();
final int colNo = ast.getColumnNo();
final int lineNo = ast.getLineNo();
final String currentLine = getLine(lineNo - 1);
// Check if rest of line is whitespace, and not just the operator
// by itself. This last bit is to handle the operator on a line by
// itself.
if (option == WrapOption.NL
&& !text.equals(currentLine.trim())
&& CommonUtils.isBlank(currentLine.substring(colNo + text.length()))) {
log(lineNo, colNo, MSG_LINE_NEW, text);
}
else if (option == WrapOption.EOL
&& CommonUtils.hasWhitespaceBefore(colNo - 1, currentLine)) {
log(lineNo, colNo, MSG_LINE_PREVIOUS, text);
}
}
}
示例6: 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);
}
示例7: 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);
}
示例8: 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;
}
}
示例9: 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,
};
}
示例10: 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);
}
示例11: 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,
};
}
示例12: 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;
}
示例13: 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);
}
示例14: 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);
}
示例15: visitToken
@Override
public void visitToken(DetailAST ast) {
switch (ast.getType()) {
case TokenTypes.LITERAL_IF:
case TokenTypes.LITERAL_SWITCH:
case TokenTypes.LITERAL_WHILE:
case TokenTypes.LITERAL_DO:
case TokenTypes.LITERAL_FOR:
visitConditional(ast, 1);
break;
case TokenTypes.QUESTION:
visitUnitaryOperator(ast, 2);
break;
case TokenTypes.LITERAL_RETURN:
visitUnitaryOperator(ast, 0);
break;
case TokenTypes.CASE_GROUP:
final int caseNumber = countCaseTokens(ast);
branchVisited = true;
pushValue(caseNumber);
break;
case TokenTypes.LITERAL_ELSE:
branchVisited = true;
if (currentRangeValue.equals(BigInteger.ZERO)) {
currentRangeValue = BigInteger.ONE;
}
pushValue(0);
break;
case TokenTypes.LITERAL_TRY:
case TokenTypes.LITERAL_CATCH:
case TokenTypes.LITERAL_DEFAULT:
pushValue(1);
break;
case TokenTypes.CTOR_DEF:
case TokenTypes.METHOD_DEF:
case TokenTypes.INSTANCE_INIT:
case TokenTypes.STATIC_INIT:
pushValue(0);
break;
default:
break;
}
}