本文整理汇总了Java中com.puppycrawl.tools.checkstyle.api.TokenTypes.CASE_GROUP属性的典型用法代码示例。如果您正苦于以下问题:Java TokenTypes.CASE_GROUP属性的具体用法?Java TokenTypes.CASE_GROUP怎么用?Java TokenTypes.CASE_GROUP使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.puppycrawl.tools.checkstyle.api.TokenTypes
的用法示例。
在下文中一共展示了TokenTypes.CASE_GROUP属性的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: visitToken
@Override
public void visitToken(DetailAST ast) {
final DetailAST nextGroup = ast.getNextSibling();
final boolean isLastGroup = nextGroup.getType() != TokenTypes.CASE_GROUP;
if (!isLastGroup || checkLastCaseGroup) {
final DetailAST slist = ast.findFirstToken(TokenTypes.SLIST);
if (slist != null && !isTerminated(slist, true, true)
&& !hasFallThroughComment(ast, nextGroup)) {
if (isLastGroup) {
log(ast, MSG_FALL_THROUGH_LAST);
}
else {
log(nextGroup, MSG_FALL_THROUGH);
}
}
}
}
示例3: getBlockEndToken
/**
* Returns the token which ends the code block.
* @param blockNameIdent block name identifier.
* @param blockStartToken token which starts the block.
* @return the token which ends the code block.
*/
private static DetailAST getBlockEndToken(DetailAST blockNameIdent, DetailAST blockStartToken) {
DetailAST blockEndToken = null;
final DetailAST blockNameIdentParent = blockNameIdent.getParent();
if (blockNameIdentParent.getType() == TokenTypes.CASE_GROUP) {
blockEndToken = blockNameIdentParent.getNextSibling();
}
else {
final Set<DetailAST> rcurlyTokens = getAllTokensOfType(blockNameIdent,
TokenTypes.RCURLY);
for (DetailAST currentRcurly : rcurlyTokens) {
final DetailAST parent = currentRcurly.getParent();
if (blockStartToken.getLineNo() == parent.getLineNo()) {
blockEndToken = currentRcurly;
}
}
}
return blockEndToken;
}
示例4: 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));
}
}
}
示例5: getNextToken
/**
* Get the token to start counting the number of lines to add to the distance aim from.
* @param checkedStatement the checked statement.
* @return the token to start counting the number of lines to add to the distance aim from.
*/
private DetailAST getNextToken(DetailAST checkedStatement) {
DetailAST nextToken;
if (checkedStatement.getType() == TokenTypes.SLIST
|| checkedStatement.getType() == TokenTypes.ARRAY_INIT
|| checkedStatement.getType() == TokenTypes.CASE_GROUP) {
nextToken = checkedStatement.getFirstChild();
}
else {
nextToken = checkedStatement.getNextSibling();
}
if (nextToken != null && isComment(nextToken) && isTrailingComment(nextToken)) {
nextToken = nextToken.getNextSibling();
}
return nextToken;
}
示例6: isNotRelevantSituation
/**
* Is ast not a target of Check.
* @param ast ast
* @param currentType type of ast
* @return true is ok to skip validation
*/
private boolean isNotRelevantSituation(DetailAST ast, int currentType) {
final int parentType = ast.getParent().getType();
final boolean starImport = currentType == TokenTypes.STAR
&& parentType == TokenTypes.DOT;
final boolean slistInsideCaseGroup = currentType == TokenTypes.SLIST
&& parentType == TokenTypes.CASE_GROUP;
final boolean starImportOrSlistInsideCaseGroup = starImport || slistInsideCaseGroup;
final boolean colonOfCaseOrDefaultOrForEach =
isColonOfCaseOrDefault(currentType, parentType)
|| isColonOfForEach(currentType, parentType);
final boolean emptyBlockOrType =
isEmptyBlock(ast, parentType)
|| allowEmptyTypes && isEmptyType(ast);
return starImportOrSlistInsideCaseGroup
|| colonOfCaseOrDefaultOrForEach
|| emptyBlockOrType
|| isArrayInitialization(currentType, parentType);
}
示例7: 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);
}
示例8: handleSwitch
/**
* processes a switch statement and resolves references in it
*
* @param block the <code>BlockDef</code> to process
*/
private void handleSwitch(BlockDef block) {
SymTabAST node = block.getTreeNode();
SymTabAST expr = node.findFirstToken(TokenTypes.EXPR);
resolveExpression(expr, block, null, true);
SymTabAST caseGroup = (SymTabAST) (expr.getNextSibling());
while (caseGroup != null
&& (caseGroup.getType() != TokenTypes.CASE_GROUP)) {
caseGroup = (SymTabAST) caseGroup.getNextSibling();
}
if (caseGroup != null) {
while (caseGroup.getType() == TokenTypes.CASE_GROUP) {
SymTabAST caseNode =
caseGroup.findFirstToken(TokenTypes.LITERAL_CASE);
while (caseNode != null
&& caseNode.getType() == TokenTypes.LITERAL_CASE) {
resolveExpression(
(SymTabAST) caseNode.getFirstChild(),
block,
null,
true);
caseNode = (SymTabAST) caseNode.getNextSibling();
}
SymTabAST caseSlist =
caseGroup.findFirstToken(TokenTypes.SLIST);
handleSList(caseSlist, block);
caseGroup = (SymTabAST) (caseGroup.getNextSibling());
}
}
}
示例9: 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;
}
}
示例10: leaveToken
@Override
public void leaveToken(DetailAST ast) {
Map<String, FinalVariableCandidate> scope = null;
switch (ast.getType()) {
case TokenTypes.OBJBLOCK:
case TokenTypes.CTOR_DEF:
case TokenTypes.METHOD_DEF:
scope = scopeStack.pop().scope;
break;
case TokenTypes.SLIST:
// [email protected][MoveVariableInsideIf] assignment value is modified later so it can't be
// moved
final Deque<DetailAST> prevScopeUninitializedVariableData =
prevScopeUninitializedVariables.peek();
boolean containsBreak = false;
if (ast.getParent().getType() != TokenTypes.CASE_GROUP
|| findLastChildWhichContainsSpecifiedToken(ast.getParent().getParent(),
TokenTypes.CASE_GROUP, TokenTypes.SLIST) == ast.getParent()) {
containsBreak = scopeStack.peek().containsBreak;
scope = scopeStack.pop().scope;
prevScopeUninitializedVariables.pop();
}
final DetailAST parent = ast.getParent();
if (containsBreak || shouldUpdateUninitializedVariables(parent)) {
updateAllUninitializedVariables(prevScopeUninitializedVariableData);
}
updateCurrentScopeAssignedVariables();
break;
default:
// do nothing
}
if (scope != null) {
for (FinalVariableCandidate candidate : scope.values()) {
final DetailAST ident = candidate.variableIdent;
log(ident.getLineNo(), ident.getColumnNo(), MSG_KEY, ident.getText());
}
}
}
示例11: getFirstNodeInsideSwitchBlock
/**
* Gets first Ast node inside SWITCH block if variable usage is met
* only inside the block (not in its declaration!).
* @param block
* Ast node represents SWITCH block.
* @param variable
* Variable which is checked for content in block.
* @return If variable usage is met only inside the block
* (not in its declaration!) than return the first Ast node
* of this block, otherwise - null.
*/
private static DetailAST getFirstNodeInsideSwitchBlock(
DetailAST block, DetailAST variable) {
DetailAST currentNode = block
.findFirstToken(TokenTypes.CASE_GROUP);
final List<DetailAST> variableUsageExpressions =
new ArrayList<DetailAST>();
// Checking variable usage inside all CASE blocks.
while (currentNode.getType() == TokenTypes.CASE_GROUP) {
final DetailAST lastNodeInCaseGroup =
currentNode.getLastChild();
if (isChild(lastNodeInCaseGroup, variable)) {
variableUsageExpressions.add(lastNodeInCaseGroup);
}
currentNode = currentNode.getNextSibling();
}
// If variable usage exists in several related blocks, then
// firstNodeInsideBlock = null, otherwise if variable usage exists
// only inside one block, then get node from
// variableUsageExpressions.
DetailAST firstNodeInsideBlock = null;
if (variableUsageExpressions.size() == 1) {
firstNodeInsideBlock = variableUsageExpressions.get(0);
}
return firstNodeInsideBlock;
}
示例12: 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);
}
示例13: isBlockStart
/**
* Whether the AST node starts a block.
* @param root the AST node to check.
* @return true if the AST node starts a block.
*/
private static boolean isBlockStart(DetailAST root) {
return root.getType() == TokenTypes.SLIST
|| root.getType() == TokenTypes.OBJBLOCK
|| root.getType() == TokenTypes.ARRAY_INIT
|| root.getType() == TokenTypes.CASE_GROUP;
}
示例14: getPrevStatementFromSwitchBlock
/**
* Gets comment's previous statement from switch block.
* @param comment {@link TokenTypes#SINGLE_LINE_COMMENT single-line comment}.
* @return comment's previous statement or null if previous statement is absent.
*/
private static DetailAST getPrevStatementFromSwitchBlock(DetailAST comment) {
final DetailAST prevStmt;
final DetailAST parentStatement = comment.getParent();
if (parentStatement.getType() == TokenTypes.CASE_GROUP) {
prevStmt = getPrevStatementWhenCommentIsUnderCase(parentStatement);
}
else {
prevStmt = getPrevCaseToken(parentStatement);
}
return prevStmt;
}
示例15: visitToken
@Override
public void visitToken(DetailAST ast) {
final DetailAST leftCurly = findLeftCurly(ast);
if (leftCurly != null) {
if (option == BlockOption.STATEMENT) {
final boolean emptyBlock;
if (leftCurly.getType() == TokenTypes.LCURLY) {
emptyBlock = leftCurly.getNextSibling().getType() != TokenTypes.CASE_GROUP;
}
else {
emptyBlock = leftCurly.getChildCount() <= 1;
}
if (emptyBlock) {
log(leftCurly.getLineNo(),
leftCurly.getColumnNo(),
MSG_KEY_BLOCK_NO_STATEMENT,
ast.getText());
}
}
else if (!hasText(leftCurly)) {
log(leftCurly.getLineNo(),
leftCurly.getColumnNo(),
MSG_KEY_BLOCK_EMPTY,
ast.getText());
}
}
}