本文整理汇总了Java中com.puppycrawl.tools.checkstyle.api.TokenTypes.FOR_INIT属性的典型用法代码示例。如果您正苦于以下问题:Java TokenTypes.FOR_INIT属性的具体用法?Java TokenTypes.FOR_INIT怎么用?Java TokenTypes.FOR_INIT使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.puppycrawl.tools.checkstyle.api.TokenTypes
的用法示例。
在下文中一共展示了TokenTypes.FOR_INIT属性的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitToken
@Override
public void visitToken(DetailAST ast) {
DetailAST nextNode = ast.getNextSibling();
if (nextNode != null) {
final boolean isCommaSeparated = nextNode.getType() == TokenTypes.COMMA;
if (isCommaSeparated
|| nextNode.getType() == TokenTypes.SEMI) {
nextNode = nextNode.getNextSibling();
}
if (nextNode != null
&& nextNode.getType() == TokenTypes.VARIABLE_DEF) {
final DetailAST firstNode = CheckUtils.getFirstNode(ast);
if (isCommaSeparated) {
// Check if the multiple variable declarations are in a
// for loop initializer. If they are, then no warning
// should be displayed. Declaring multiple variables in
// a for loop initializer is a good way to minimize
// variable scope. Refer Feature Request Id - 2895985
// for more details
if (ast.getParent().getType() != TokenTypes.FOR_INIT) {
log(firstNode, MSG_MULTIPLE_COMMA);
}
}
else {
final DetailAST lastNode = getLastNode(ast);
final DetailAST firstNextNode = CheckUtils.getFirstNode(nextNode);
if (firstNextNode.getLineNo() == lastNode.getLineNo()) {
log(firstNode, MSG_MULTIPLE);
}
}
}
}
}
示例2: getRequiredTokens
@Override
public int[] getRequiredTokens() {
return new int[] {
TokenTypes.SEMI,
TokenTypes.FOR_INIT,
TokenTypes.FOR_ITERATOR,
TokenTypes.LAMBDA,
};
}
示例3: isInEmptyForInitializerOrCondition
/**
* Checks that semicolon is in empty for initializer or condition.
* @param semicolonAst DetailAST of semicolon.
* @return true if semicolon is in empty for initializer or condition.
*/
private static boolean isInEmptyForInitializerOrCondition(DetailAST semicolonAst) {
boolean result = false;
if (semicolonAst.getType() == TokenTypes.SEMI) {
final DetailAST sibling = semicolonAst.getPreviousSibling();
if (sibling != null
&& (sibling.getType() == TokenTypes.FOR_INIT
|| sibling.getType() == TokenTypes.FOR_CONDITION)
&& sibling.getChildCount() == 0) {
result = true;
}
}
return result;
}
示例4: testGetRequiredTokens
@Test
public void testGetRequiredTokens() {
final EmptyForInitializerPadCheck checkObj = new EmptyForInitializerPadCheck();
final int[] expected = {TokenTypes.FOR_INIT};
assertArrayEquals("Default required tokens are invalid",
expected, checkObj.getRequiredTokens());
}
示例5: testGetAcceptableTokens
@Test
public void testGetAcceptableTokens() {
final EmptyForInitializerPadCheck emptyForInitializerPadCheckObj =
new EmptyForInitializerPadCheck();
final int[] actual = emptyForInitializerPadCheckObj.getAcceptableTokens();
final int[] expected = {
TokenTypes.FOR_INIT,
};
assertArrayEquals("Default acceptable tokens are invalid", expected, actual);
}
示例6: isForLoopVariable
/**
* Checks if a variable is the loop's one.
* @param variableDef variable definition.
* @return true if a variable is the loop's one.
*/
private static boolean isForLoopVariable(DetailAST variableDef) {
final int parentType = variableDef.getParent().getType();
return parentType == TokenTypes.FOR_INIT
|| parentType == TokenTypes.FOR_EACH_CLAUSE;
}
示例7: getRequiredTokens
@Override
public int[] getRequiredTokens() {
return new int[] {TokenTypes.FOR_INIT};
}
示例8: isVariableInForInit
/**
* Checks if current variable is defined in
* {@link TokenTypes#FOR_INIT for-loop init}, e.g.:
* <p>
* {@code
* for (int i = 0, j = 0; i < j; i++) { . . . }
* }
* </p>
* {@code i, j} are defined in {@link TokenTypes#FOR_INIT for-loop init}
* @param variableDef variable definition node.
* @return true if variable is defined in {@link TokenTypes#FOR_INIT for-loop init}
*/
private static boolean isVariableInForInit(DetailAST variableDef) {
return variableDef.getParent().getType() == TokenTypes.FOR_INIT;
}