本文整理汇总了Java中com.puppycrawl.tools.checkstyle.api.TokenTypes.TYPE属性的典型用法代码示例。如果您正苦于以下问题:Java TokenTypes.TYPE属性的具体用法?Java TokenTypes.TYPE怎么用?Java TokenTypes.TYPE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.puppycrawl.tools.checkstyle.api.TokenTypes
的用法示例。
在下文中一共展示了TokenTypes.TYPE属性的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getFieldWithoutThis
/**
* Returns the frame where the field is declared, if the given field is used without
* 'this', and null otherwise.
* @param ast field definition ast token.
* @param parentType type of the parent.
* @return the frame where the field is declared, if the given field is used without
* 'this' and null otherwise.
*/
private AbstractFrame getFieldWithoutThis(DetailAST ast, int parentType) {
final boolean importOrPackage = ScopeUtils.getSurroundingScope(ast) == null;
final boolean methodNameInMethodCall = parentType == TokenTypes.DOT
&& ast.getPreviousSibling() != null;
final boolean typeName = parentType == TokenTypes.TYPE
|| parentType == TokenTypes.LITERAL_NEW;
AbstractFrame frame = null;
if (!importOrPackage
&& !methodNameInMethodCall
&& !typeName
&& !isDeclarationToken(parentType)
&& !isLambdaParameter(ast)) {
final AbstractFrame fieldFrame = findClassFrame(ast, false);
if (fieldFrame != null && ((ClassFrame) fieldFrame).hasInstanceMember(ast)) {
frame = getClassFrameWhereViolationIsFound(ast);
}
}
return frame;
}
示例2: visitToken
@Override
public void visitToken(DetailAST ast) {
final DetailAST typeAST = ast.getParent();
if (typeAST.getType() == TokenTypes.TYPE
// Do not check method's return type.
// We have no alternatives here.
&& typeAST.getParent().getType() != TokenTypes.METHOD_DEF) {
final DetailAST variableAST = typeAST.getNextSibling();
if (variableAST != null) {
final boolean isJavaStyle =
variableAST.getLineNo() > ast.getLineNo()
|| variableAST.getColumnNo() - ast.getColumnNo() > -1;
if (isJavaStyle != javaStyle) {
log(ast.getLineNo(), ast.getColumnNo(), MSG_KEY);
}
}
}
}
示例3: testGetAcceptableTokens
@Test
public void testGetAcceptableTokens() {
final ClassFanOutComplexityCheck classFanOutComplexityCheckObj =
new ClassFanOutComplexityCheck();
final int[] actual = classFanOutComplexityCheckObj.getAcceptableTokens();
final int[] expected = {
TokenTypes.PACKAGE_DEF,
TokenTypes.IMPORT,
TokenTypes.CLASS_DEF,
TokenTypes.INTERFACE_DEF,
TokenTypes.ENUM_DEF,
TokenTypes.TYPE,
TokenTypes.LITERAL_NEW,
TokenTypes.LITERAL_THROWS,
TokenTypes.ANNOTATION_DEF,
};
Assert.assertNotNull("Acceptable tokens should not be null", actual);
Assert.assertArrayEquals("Invalid acceptable tokens", expected, actual);
}
示例4: getDefaultTokens
/**
* @return the tokens that are delivered from the parser to this class.
*/
@Override
public int[] getDefaultTokens() {
return new int[] { TokenTypes.ABSTRACT, TokenTypes.PACKAGE_DEF, TokenTypes.INTERFACE_DEF, TokenTypes.CLASS_DEF,
TokenTypes.ANNOTATION, TokenTypes.IMPORT, TokenTypes.IMPLEMENTS_CLAUSE, TokenTypes.EXTENDS_CLAUSE,
TokenTypes.TYPE };
}
示例5: visitToken
@Override
public void visitToken(DetailAST ast) {
switch (ast.getType()) {
case TokenTypes.PACKAGE_DEF:
visitPackageDef(ast);
break;
case TokenTypes.IMPORT:
fileContext.registerImport(ast);
break;
case TokenTypes.CLASS_DEF:
case TokenTypes.INTERFACE_DEF:
case TokenTypes.ANNOTATION_DEF:
case TokenTypes.ENUM_DEF:
visitClassDef(ast);
break;
case TokenTypes.TYPE:
fileContext.visitType(ast);
break;
case TokenTypes.LITERAL_NEW:
fileContext.visitLiteralNew(ast);
break;
case TokenTypes.LITERAL_THROWS:
fileContext.visitLiteralThrows(ast);
break;
default:
throw new IllegalArgumentException("Unknown type: " + ast);
}
}
示例6: getRequiredTokens
@Override
public int[] getRequiredTokens() {
return new int[] {
TokenTypes.PACKAGE_DEF,
TokenTypes.IMPORT,
TokenTypes.CLASS_DEF,
TokenTypes.INTERFACE_DEF,
TokenTypes.ENUM_DEF,
TokenTypes.TYPE,
TokenTypes.LITERAL_NEW,
TokenTypes.LITERAL_THROWS,
TokenTypes.ANNOTATION_DEF,
};
}
示例7: getAcceptableParent
/**
* Returns parent of given ast if parent has one of the following types:
* ANNOTATION_DEF, PACKAGE_DEF, CLASS_DEF, ENUM_DEF, ENUM_CONSTANT_DEF, CTOR_DEF,
* METHOD_DEF, PARAMETER_DEF, VARIABLE_DEF, ANNOTATION_FIELD_DEF, TYPE, LITERAL_NEW,
* LITERAL_THROWS, TYPE_ARGUMENT, IMPLEMENTS_CLAUSE, DOT.
* @param child an ast
* @return returns ast - parent of given
*/
private static DetailAST getAcceptableParent(DetailAST child) {
final DetailAST result;
final DetailAST parent = child.getParent();
switch (parent.getType()) {
case TokenTypes.ANNOTATION_DEF:
case TokenTypes.PACKAGE_DEF:
case TokenTypes.CLASS_DEF:
case TokenTypes.INTERFACE_DEF:
case TokenTypes.ENUM_DEF:
case TokenTypes.ENUM_CONSTANT_DEF:
case TokenTypes.CTOR_DEF:
case TokenTypes.METHOD_DEF:
case TokenTypes.PARAMETER_DEF:
case TokenTypes.VARIABLE_DEF:
case TokenTypes.ANNOTATION_FIELD_DEF:
case TokenTypes.TYPE:
case TokenTypes.LITERAL_NEW:
case TokenTypes.LITERAL_THROWS:
case TokenTypes.TYPE_ARGUMENT:
case TokenTypes.IMPLEMENTS_CLAUSE:
case TokenTypes.DOT:
result = parent;
break;
default:
// it's possible case, but shouldn't be processed here
result = null;
}
return result;
}
示例8: getParentType
/**
* Returns type of parent node.
* @param commentBlock child node.
* @return parent type.
*/
private static int getParentType(DetailAST commentBlock) {
final DetailAST parentNode = commentBlock.getParent();
int type = parentNode.getType();
if (type == TokenTypes.TYPE || type == TokenTypes.MODIFIERS) {
type = parentNode.getParent().getType();
}
return type;
}
示例9: isOnPlainClassMember
/**
* Checks that block comment is on specified class member without any modifiers.
* @param blockComment block comment start DetailAST
* @param memberType parent token type
* @return true if block comment is on specified token without modifiers
*/
private static boolean isOnPlainClassMember(DetailAST blockComment, int memberType) {
DetailAST parent = blockComment.getParent();
// type could be in fully qualified form, so we go up to Type token
while (parent != null && parent.getType() == TokenTypes.DOT) {
parent = parent.getParent();
}
return parent != null
&& parent.getType() == TokenTypes.TYPE
&& parent.getParent().getType() == memberType
// previous parent sibling is always TokenTypes.MODIFIERS
&& parent.getPreviousSibling().getChildCount() == 0;
}
示例10: visitToken
/** {@inheritDoc} */
@Override
public void visitToken(DetailAST ast) {
logAstDetails(ast);
if (this.isInnerClass) {
// ignore Inner classes
return;
}
int tokenType = ast.getType();
switch (tokenType) {
case TokenTypes.PACKAGE_DEF:
addPackagename(ast);
break;
case TokenTypes.IMPORT:
addImport(ast);
break;
case TokenTypes.ABSTRACT:
setAbstractType(ast);
break;
case TokenTypes.CLASS_DEF:
if (this.currentClass.getClassName() != null) {
this.isInnerClass = true;
return;
}
setClassType(ast);
break;
case TokenTypes.ANNOTATION_DEF:
setAnnotationType(ast);
break;
case TokenTypes.INTERFACE_DEF:
setInterfaceType(ast);
break;
case TokenTypes.ANNOTATION:
addAnnotation(ast);
break;
case TokenTypes.EXTENDS_CLAUSE:
addBaseClass(ast);
break;
case TokenTypes.IMPLEMENTS_CLAUSE:
addInterface(ast);
break;
case TokenTypes.TYPE:
addImportFromFullQualifiedType(ast);
break;
default:
break;
}
}
示例11: 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;
}
示例12: isPipeOperator
/**
* Checks if {@link TokenTypes#BOR binary OR} is applied to exceptions
* in
* <a href="https://docs.oracle.com/javase/specs/jls/se8/html/jls-14.html#jls-14.20">
* multi-catch</a> (pipe-syntax).
* @param binaryOr {@link TokenTypes#BOR binary or}
* @return true if binary or is applied to exceptions in multi-catch.
*/
private static boolean isPipeOperator(DetailAST binaryOr) {
return binaryOr.getParent().getType() == TokenTypes.TYPE;
}