本文整理汇总了Java中com.puppycrawl.tools.checkstyle.api.TokenTypes.ARRAY_DECLARATOR属性的典型用法代码示例。如果您正苦于以下问题:Java TokenTypes.ARRAY_DECLARATOR属性的具体用法?Java TokenTypes.ARRAY_DECLARATOR怎么用?Java TokenTypes.ARRAY_DECLARATOR使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.puppycrawl.tools.checkstyle.api.TokenTypes
的用法示例。
在下文中一共展示了TokenTypes.ARRAY_DECLARATOR属性的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: postProcessLiteralNew
/**
* Processes one of the collected "new" tokens when walking tree
* has finished.
* @param newTokenAst the "new" token.
*/
private void postProcessLiteralNew(DetailAST newTokenAst) {
final DetailAST typeNameAst = newTokenAst.getFirstChild();
final AST nameSibling = typeNameAst.getNextSibling();
if (nameSibling.getType() != TokenTypes.ARRAY_DECLARATOR) {
// ast != "new Boolean[]"
final FullIdent typeIdent = FullIdent.createFullIdent(typeNameAst);
final String typeName = typeIdent.getText();
final String fqClassName = getIllegalInstantiation(typeName);
if (fqClassName != null) {
final int lineNo = newTokenAst.getLineNo();
final int colNo = newTokenAst.getColumnNo();
log(lineNo, colNo, MSG_KEY, fqClassName);
}
}
}
示例2: getDefaultTokens
@Override
public int[] getDefaultTokens() {
return new int[] {
TokenTypes.ARRAY_INIT,
TokenTypes.AT,
TokenTypes.INC,
TokenTypes.DEC,
TokenTypes.UNARY_MINUS,
TokenTypes.UNARY_PLUS,
TokenTypes.BNOT,
TokenTypes.LNOT,
TokenTypes.DOT,
TokenTypes.ARRAY_DECLARATOR,
TokenTypes.INDEX_OP,
};
}
示例3: getAcceptableTokens
@Override
public int[] getAcceptableTokens() {
return new int[] {
TokenTypes.ARRAY_INIT,
TokenTypes.AT,
TokenTypes.INC,
TokenTypes.DEC,
TokenTypes.UNARY_MINUS,
TokenTypes.UNARY_PLUS,
TokenTypes.BNOT,
TokenTypes.LNOT,
TokenTypes.DOT,
TokenTypes.TYPECAST,
TokenTypes.ARRAY_DECLARATOR,
TokenTypes.INDEX_OP,
TokenTypes.LITERAL_SYNCHRONIZED,
TokenTypes.METHOD_REF,
};
}
示例4: getWhitespaceFollowedNode
/**
* For a visited ast node returns node that should be checked
* for not being followed by whitespace.
* @param ast
* , visited node.
* @return node before ast.
*/
private static DetailAST getWhitespaceFollowedNode(DetailAST ast) {
final DetailAST whitespaceFollowedAst;
switch (ast.getType()) {
case TokenTypes.TYPECAST:
whitespaceFollowedAst = ast.findFirstToken(TokenTypes.RPAREN);
break;
case TokenTypes.ARRAY_DECLARATOR:
whitespaceFollowedAst = getArrayDeclaratorPreviousElement(ast);
break;
case TokenTypes.INDEX_OP:
whitespaceFollowedAst = getIndexOpPreviousElement(ast);
break;
default:
whitespaceFollowedAst = ast;
}
return whitespaceFollowedAst;
}
示例5: getType
/**
* gets the classDef that represents the type of the given definition
*
*
* @param def the definition whose type to find
* @param typeNode the TokenTypes.TYPE node associated with the def
*
* @return the resulting class definition
*/
protected IClass getType( Definition def, SymTabAST typeNode ) {
IClass result = null;
SymTabAST typeClassNode = null;
boolean isArray = false;
if ( typeNode.getFirstChild().getType()
== TokenTypes.ARRAY_DECLARATOR ) {
isArray = true;
typeClassNode = (SymTabAST)typeNode.getFirstChild().getFirstChild();
}
else {
typeClassNode = (SymTabAST)typeNode.getFirstChild();
}
Scope lookupScope = null;
if (def instanceof Scope) {
lookupScope = (Scope)def;
}
else {
lookupScope = def.getParentScope();
}
Resolver resolver = new Resolver(symbolTable);
IClass typeClass = resolver.resolveClass(typeClassNode, lookupScope, null, false);
if ( isArray ) {
result = new ArrayDef( typeClass );
}
else {
result = typeClass;
}
return result;
}
示例6: finish
/**
*
* Finishes the variable by setting the Type
* @return <code>void</code>
* @see #getType(Definition, SymTabAST)
* @see net.sourceforge.transmogrify.symtab.VariableDef
*/
public void finish() {
SymTabAST typeNode = _node.findFirstToken(TokenTypes.TYPE);
SymTabAST typeTextNode = (SymTabAST)(typeNode.getFirstChild());
if ( typeTextNode.getType() == TokenTypes.ARRAY_DECLARATOR ) {
typeTextNode = (SymTabAST)(typeTextNode.getFirstChild());
}
typeTextNode.setLine(ASTUtil.getLine( _def.getTreeNode() ));
IClass varType = getType(_def, typeNode);
_def.setType( varType );
}
示例7: getFirstNonArrayDeclaratorParent
/**
* Get node that owns {@link TokenTypes#ARRAY_DECLARATOR ARRAY_DECLARATOR} sequence.
* @param ast
* , {@link TokenTypes#ARRAY_DECLARATOR ARRAY_DECLARATOR} node.
* @return owner node.
*/
private static DetailAST getFirstNonArrayDeclaratorParent(DetailAST ast) {
DetailAST parent = ast.getParent();
while (parent.getType() == TokenTypes.ARRAY_DECLARATOR) {
parent = parent.getParent();
}
return parent;
}
示例8: getAcceptableTokens
@Override
public int[] getAcceptableTokens() {
return new int[] {
TokenTypes.DOT,
TokenTypes.COMMA,
TokenTypes.SEMI,
TokenTypes.ELLIPSIS,
TokenTypes.AT,
TokenTypes.LPAREN,
TokenTypes.RPAREN,
TokenTypes.ARRAY_DECLARATOR,
TokenTypes.RBRACK,
TokenTypes.METHOD_REF,
};
}
示例9: testGetRequiredTokens
@Test
public void testGetRequiredTokens() {
final ArrayTypeStyleCheck checkObj = new ArrayTypeStyleCheck();
final int[] expected = {TokenTypes.ARRAY_DECLARATOR};
assertArrayEquals("Required tokens differs from expected",
expected, checkObj.getRequiredTokens());
}
示例10: testGetAcceptableTokens
@Test
public void testGetAcceptableTokens() {
final int[] expected = {TokenTypes.ARRAY_DECLARATOR };
final ArrayTypeStyleCheck check = new ArrayTypeStyleCheck();
final int[] actual = check.getAcceptableTokens();
assertEquals("Amount of acceptable tokens differs from expected",
1, actual.length);
assertArrayEquals("Acceptable tokens differs from expected",
expected, actual);
}
示例11: resolveTypecast
private IClass resolveTypecast(
SymTabAST node,
Scope location,
IClass context,
boolean referencePhase) {
SymTabAST typeNode = (SymTabAST) node.getFirstChild();
SymTabAST exprNode = (SymTabAST) typeNode.getNextSibling();
//handle Checkstyle grammar
if (exprNode.getType() == TokenTypes.RPAREN) {
exprNode = (SymTabAST) exprNode.getNextSibling();
}
IClass type = null;
final SymTabAST child = (SymTabAST) typeNode.getFirstChild();
// TODO: Checkstyle change.
// Do not create references from typecast.
// Original transmogrify code is equivalent to
// final boolean createReference = referencePhase;
// which creates non-existant references for variables.
final boolean createReference = false;
if (child.getType()
== TokenTypes.ARRAY_DECLARATOR) {
type =
new ArrayDef(
resolveType(
(SymTabAST) typeNode.getFirstChild(),
location,
context,
createReference));
}
else {
type = resolveType(typeNode, location, context, createReference);
}
resolveExpression(exprNode, location, context, referencePhase);
//TODO: Checkstyle change. Can this be ignored?
if (type != null) {
((SymTabAST) typeNode.getFirstChild()).setDefinition(
type,
location,
referencePhase);
}
return type;
}
示例12: isObjectType
/**
* Determines if a given type is an object type.
* @param type type to check.
* @return true if it is an object type.
*/
private static boolean isObjectType(DetailAST type) {
final int objectType = type.getFirstChild().getType();
return objectType == TokenTypes.IDENT || objectType == TokenTypes.DOT
|| objectType == TokenTypes.ARRAY_DECLARATOR;
}
示例13: getArrayDeclaratorPreviousElement
/**
* Returns proper argument for getPositionAfter method, it is a token after
* {@link TokenTypes#ARRAY_DECLARATOR ARRAY_DECLARATOR}, in can be {@link TokenTypes#RBRACK
* RBRACK}, {@link TokenTypes#IDENT IDENT} or an array type definition (literal).
* @param ast
* , {@link TokenTypes#ARRAY_DECLARATOR ARRAY_DECLARATOR} node.
* @return previous node by text order.
*/
private static DetailAST getArrayDeclaratorPreviousElement(DetailAST ast) {
final DetailAST previousElement;
final DetailAST firstChild = ast.getFirstChild();
if (firstChild.getType() == TokenTypes.ARRAY_DECLARATOR) {
// second or higher array index
previousElement = firstChild.findFirstToken(TokenTypes.RBRACK);
}
else {
// first array index, is preceded with identifier or type
final DetailAST parent = getFirstNonArrayDeclaratorParent(ast);
switch (parent.getType()) {
// generics
case TokenTypes.TYPE_ARGUMENT:
final DetailAST wildcard = parent.findFirstToken(TokenTypes.WILDCARD_TYPE);
if (wildcard == null) {
// usual generic type argument like <char[]>
previousElement = getTypeLastNode(ast);
}
else {
// constructions with wildcard like <? extends String[]>
previousElement = getTypeLastNode(ast.getFirstChild());
}
break;
// 'new' is a special case with its own subtree structure
case TokenTypes.LITERAL_NEW:
previousElement = getTypeLastNode(parent);
break;
// mundane array declaration, can be either java style or C style
case TokenTypes.TYPE:
previousElement = getPreviousNodeWithParentOfTypeAst(ast, parent);
break;
// i.e. boolean[].class
case TokenTypes.DOT:
previousElement = getTypeLastNode(ast);
break;
// java 8 method reference
case TokenTypes.METHOD_REF:
final DetailAST ident = getIdentLastToken(ast);
if (ident == null) {
//i.e. int[]::new
previousElement = ast.getFirstChild();
}
else {
previousElement = ident;
}
break;
default:
throw new IllegalStateException("unexpected ast syntax " + parent);
}
}
return previousElement;
}
示例14: getRequiredTokens
@Override
public int[] getRequiredTokens() {
return new int[] {TokenTypes.ARRAY_DECLARATOR};
}