本文整理汇总了Java中com.puppycrawl.tools.checkstyle.api.TokenTypes.OBJBLOCK属性的典型用法代码示例。如果您正苦于以下问题:Java TokenTypes.OBJBLOCK属性的具体用法?Java TokenTypes.OBJBLOCK怎么用?Java TokenTypes.OBJBLOCK使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.puppycrawl.tools.checkstyle.api.TokenTypes
的用法示例。
在下文中一共展示了TokenTypes.OBJBLOCK属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testGetDefaultTokens
@Test
public void testGetDefaultTokens() {
final ModifierOrderCheck modifierOrderCheckObj = new ModifierOrderCheck();
final int[] actual = modifierOrderCheckObj.getDefaultTokens();
final int[] expected = {TokenTypes.MODIFIERS};
final int[] unexpectedArray = {
TokenTypes.MODIFIERS,
TokenTypes.OBJBLOCK,
};
assertArrayEquals("Default tokens are invalid", expected, actual);
final int[] unexpectedEmptyArray = CommonUtils.EMPTY_INT_ARRAY;
Assert.assertNotSame("Default tokens should not be empty array",
unexpectedEmptyArray, actual);
Assert.assertNotSame("Invalid default tokens", unexpectedArray, actual);
Assert.assertNotNull("Default tokens should not be null", actual);
}
示例2: testGetAcceptableTokens
@Test
public void testGetAcceptableTokens() {
final ModifierOrderCheck modifierOrderCheckObj = new ModifierOrderCheck();
final int[] actual = modifierOrderCheckObj.getAcceptableTokens();
final int[] expected = {TokenTypes.MODIFIERS};
final int[] unexpectedArray = {
TokenTypes.MODIFIERS,
TokenTypes.OBJBLOCK,
};
assertArrayEquals("Default acceptable tokens are invalid", expected, actual);
final int[] unexpectedEmptyArray = CommonUtils.EMPTY_INT_ARRAY;
Assert.assertNotSame("Default tokens should not be empty array",
unexpectedEmptyArray, actual);
Assert.assertNotSame("Invalid acceptable tokens", unexpectedArray, actual);
Assert.assertNotNull("Acceptable tokens should not be null", actual);
}
示例3: getRequiredTokens
@Override
public int[] getRequiredTokens() {
return new int[] {
TokenTypes.OBJBLOCK,
TokenTypes.LITERAL_FOR,
TokenTypes.FOR_ITERATOR,
TokenTypes.FOR_EACH_CLAUSE,
TokenTypes.ASSIGN,
TokenTypes.PLUS_ASSIGN,
TokenTypes.MINUS_ASSIGN,
TokenTypes.STAR_ASSIGN,
TokenTypes.DIV_ASSIGN,
TokenTypes.MOD_ASSIGN,
TokenTypes.SR_ASSIGN,
TokenTypes.BSR_ASSIGN,
TokenTypes.SL_ASSIGN,
TokenTypes.BAND_ASSIGN,
TokenTypes.BXOR_ASSIGN,
TokenTypes.BOR_ASSIGN,
TokenTypes.INC,
TokenTypes.POST_INC,
TokenTypes.DEC,
TokenTypes.POST_DEC,
};
}
示例4: collectFirstNodes
/**
* Finds first nodes on line and puts them into Map.
*
* @param firstNode First node to start examining.
* @param lastNode Last node to examine inclusively.
* @return NavigableMap which contains lines numbers as a key and first
* nodes on lines as a values.
*/
private NavigableMap<Integer, DetailAST> collectFirstNodes(DetailAST firstNode,
DetailAST lastNode) {
final NavigableMap<Integer, DetailAST> result = new TreeMap<Integer, DetailAST>();
result.put(firstNode.getLineNo(), firstNode);
DetailAST curNode = firstNode.getFirstChild();
while (curNode != lastNode) {
if (curNode.getType() == TokenTypes.OBJBLOCK
|| curNode.getType() == TokenTypes.SLIST) {
curNode = curNode.getLastChild();
}
final DetailAST firstTokenOnLine = result.get(curNode.getLineNo());
if (firstTokenOnLine == null
|| expandedTabsColumnNo(firstTokenOnLine) >= expandedTabsColumnNo(curNode)) {
result.put(curNode.getLineNo(), curNode);
}
curNode = getNextCurNode(curNode);
}
return result;
}
示例5: 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,
};
}
示例6: getRequiredTokens
@Override
public int[] getRequiredTokens() {
return new int[] {
TokenTypes.IDENT,
TokenTypes.CTOR_DEF,
TokenTypes.METHOD_DEF,
TokenTypes.SLIST,
TokenTypes.OBJBLOCK,
TokenTypes.LITERAL_BREAK,
};
}
示例7: getDefaultTokens
@Override
public int[] getDefaultTokens() {
return new int[] {
TokenTypes.IDENT,
TokenTypes.CTOR_DEF,
TokenTypes.METHOD_DEF,
TokenTypes.SLIST,
TokenTypes.OBJBLOCK,
TokenTypes.LITERAL_BREAK,
TokenTypes.VARIABLE_DEF,
};
}
示例8: getAcceptableTokens
@Override
public int[] getAcceptableTokens() {
return new int[] {
TokenTypes.IDENT,
TokenTypes.CTOR_DEF,
TokenTypes.METHOD_DEF,
TokenTypes.SLIST,
TokenTypes.OBJBLOCK,
TokenTypes.LITERAL_BREAK,
TokenTypes.VARIABLE_DEF,
TokenTypes.PARAMETER_DEF,
};
}
示例9: 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());
}
}
}
示例10: testGetAcceptableTokens
@Test
public void testGetAcceptableTokens() {
final LeftCurlyCheck check = new LeftCurlyCheck();
final int[] actual = check.getAcceptableTokens();
final int[] expected = {
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, };
assertArrayEquals("Default acceptable tokens are invalid", expected, actual);
}
示例11: visitToken
@Override
public void visitToken(DetailAST ast) {
final int parentType = ast.getParent().getType();
switch (ast.getType()) {
case TokenTypes.OBJBLOCK:
scopeStates.push(new ScopeState());
break;
case TokenTypes.MODIFIERS:
if (parentType == TokenTypes.VARIABLE_DEF
&& ast.getParent().getParent().getType() == TokenTypes.OBJBLOCK) {
processModifiers(ast);
}
break;
case TokenTypes.CTOR_DEF:
if (parentType == TokenTypes.OBJBLOCK) {
processConstructor(ast);
}
break;
case TokenTypes.METHOD_DEF:
if (parentType == TokenTypes.OBJBLOCK) {
final ScopeState state = scopeStates.peek();
// nothing can be bigger than method's state
state.currentScopeState = STATE_METHOD_DEF;
}
break;
case TokenTypes.VARIABLE_DEF:
if (ScopeUtils.isClassFieldDef(ast)) {
final DetailAST fieldDef = ast.findFirstToken(TokenTypes.IDENT);
classFieldNames.add(fieldDef.getText());
}
break;
default:
break;
}
}
示例12: visitToken
@Override
public void visitToken(DetailAST ast) {
switch (ast.getType()) {
case TokenTypes.OBJBLOCK:
enterBlock();
break;
case TokenTypes.LITERAL_FOR:
case TokenTypes.FOR_ITERATOR:
case TokenTypes.FOR_EACH_CLAUSE:
//we need that Tokens only at leaveToken()
break;
case TokenTypes.ASSIGN:
case TokenTypes.PLUS_ASSIGN:
case TokenTypes.MINUS_ASSIGN:
case TokenTypes.STAR_ASSIGN:
case TokenTypes.DIV_ASSIGN:
case TokenTypes.MOD_ASSIGN:
case TokenTypes.SR_ASSIGN:
case TokenTypes.BSR_ASSIGN:
case TokenTypes.SL_ASSIGN:
case TokenTypes.BAND_ASSIGN:
case TokenTypes.BXOR_ASSIGN:
case TokenTypes.BOR_ASSIGN:
case TokenTypes.INC:
case TokenTypes.POST_INC:
case TokenTypes.DEC:
case TokenTypes.POST_DEC:
checkIdent(ast);
break;
default:
throw new IllegalStateException(ILLEGAL_TYPE_OF_TOKEN + ast);
}
}
示例13: visitToken
@Override
public void visitToken(DetailAST ast) {
final int parentType = ast.getParent().getType();
final DetailAST modifiers = ast.getFirstChild();
if (parentType != TokenTypes.OBJBLOCK
&& (!ignoreFinal || modifiers.findFirstToken(TokenTypes.FINAL) == null)) {
final DetailAST variable = ast.findFirstToken(TokenTypes.IDENT);
if (!isVariableMatchesIgnorePattern(variable.getText())) {
final DetailAST semicolonAst = ast.getNextSibling();
final Entry<DetailAST, Integer> entry;
if (validateBetweenScopes) {
entry = calculateDistanceBetweenScopes(semicolonAst, variable);
}
else {
entry = calculateDistanceInSingleScope(semicolonAst, variable);
}
final DetailAST variableUsageAst = entry.getKey();
final int dist = entry.getValue();
if (dist > allowedDistance
&& !isInitializationSequence(variableUsageAst, variable.getText())) {
if (ignoreFinal) {
log(variable.getLineNo(),
MSG_KEY_EXT, variable.getText(), dist, allowedDistance);
}
else {
log(variable.getLineNo(),
MSG_KEY, variable.getText(), dist, allowedDistance);
}
}
}
}
}
示例14: visitVariableDef
/**
* Checks variable definition.
* @param ast variable def node for check
*/
private void visitVariableDef(DetailAST ast) {
if (checking && ast.getParent().getType() == TokenTypes.OBJBLOCK) {
final DetailAST modifiersAST =
ast.findFirstToken(TokenTypes.MODIFIERS);
if (modifiersAST.findFirstToken(TokenTypes.FINAL) == null) {
log(ast.getLineNo(), ast.getColumnNo(), MSG_KEY,
ast.findFirstToken(TokenTypes.IDENT).getText());
}
}
}
示例15: 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;
}