本文整理汇总了Java中com.puppycrawl.tools.checkstyle.api.TokenTypes.ANNOTATION属性的典型用法代码示例。如果您正苦于以下问题:Java TokenTypes.ANNOTATION属性的具体用法?Java TokenTypes.ANNOTATION怎么用?Java TokenTypes.ANNOTATION使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.puppycrawl.tools.checkstyle.api.TokenTypes
的用法示例。
在下文中一共展示了TokenTypes.ANNOTATION属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitToken
@Override
public void visitToken(DetailAST ast) {
DetailAST nodeWithAnnotations = ast;
if (ast.getType() == TokenTypes.TYPECAST) {
nodeWithAnnotations = ast.findFirstToken(TokenTypes.TYPE);
}
DetailAST modifiersNode = nodeWithAnnotations.findFirstToken(TokenTypes.MODIFIERS);
if (modifiersNode == null) {
modifiersNode = nodeWithAnnotations.findFirstToken(TokenTypes.ANNOTATIONS);
}
if (modifiersNode != null) {
for (DetailAST annotationNode = modifiersNode.getFirstChild();
annotationNode != null;
annotationNode = annotationNode.getNextSibling()) {
if (annotationNode.getType() == TokenTypes.ANNOTATION
&& annotationNode.getLineNo() != getNextNode(annotationNode).getLineNo()) {
log(annotationNode.getLineNo(), MSG_KEY_ANNOTATION_ON_SAME_LINE,
getAnnotationName(annotationNode));
}
}
}
}
示例2: visitToken
@Override
public void visitToken(DetailAST ast) {
final List<DetailAST> mods = new ArrayList<DetailAST>();
DetailAST modifier = ast.getFirstChild();
while (modifier != null) {
mods.add(modifier);
modifier = modifier.getNextSibling();
}
if (!mods.isEmpty()) {
final DetailAST error = checkOrderSuggestedByJls(mods);
if (error != null) {
if (error.getType() == TokenTypes.ANNOTATION) {
log(error.getLineNo(), error.getColumnNo(),
MSG_ANNOTATION_ORDER,
error.getFirstChild().getText()
+ error.getFirstChild().getNextSibling()
.getText());
}
else {
log(error.getLineNo(), error.getColumnNo(),
MSG_MODIFIER_ORDER, error.getText());
}
}
}
}
示例3: isOverriddenMethod
/**
* Checks whether a method is annotated with Override annotation.
* @param ast method parameter definition token.
* @return true if a method is annotated with Override annotation.
*/
private static boolean isOverriddenMethod(DetailAST ast) {
boolean overridden = false;
final DetailAST parent = ast.getParent().getParent();
final Optional<DetailAST> annotation =
Optional.ofNullable(parent.getFirstChild().getFirstChild());
if (annotation.isPresent()
&& annotation.get().getType() == TokenTypes.ANNOTATION) {
final Optional<DetailAST> overrideToken =
Optional.ofNullable(annotation.get().findFirstToken(TokenTypes.IDENT));
if (overrideToken.isPresent() && "Override".equals(overrideToken.get().getText())) {
overridden = true;
}
}
return overridden;
}
示例4: makeAcceptableTokens
/**
* Returns array of acceptable tokens.
* @return acceptableTokens.
*/
private static int[] makeAcceptableTokens() {
return new int[] {TokenTypes.ANNOTATION,
TokenTypes.ANNOTATION_FIELD_DEF,
TokenTypes.CTOR_CALL,
TokenTypes.CTOR_DEF,
TokenTypes.DOT,
TokenTypes.ENUM_CONSTANT_DEF,
TokenTypes.EXPR,
TokenTypes.LITERAL_CATCH,
TokenTypes.LITERAL_DO,
TokenTypes.LITERAL_FOR,
TokenTypes.LITERAL_IF,
TokenTypes.LITERAL_NEW,
TokenTypes.LITERAL_SWITCH,
TokenTypes.LITERAL_SYNCHRONIZED,
TokenTypes.LITERAL_WHILE,
TokenTypes.METHOD_CALL,
TokenTypes.METHOD_DEF,
TokenTypes.QUESTION,
TokenTypes.RESOURCE_SPECIFICATION,
TokenTypes.SUPER_CTOR_CALL,
TokenTypes.LAMBDA,
};
}
示例5: hasAllowedAnnotations
/**
* Some javadoc.
* @param methodDef Some javadoc.
* @return Some javadoc.
*/
private boolean hasAllowedAnnotations(DetailAST methodDef) {
boolean result = false;
final DetailAST modifiersNode = methodDef.findFirstToken(TokenTypes.MODIFIERS);
DetailAST annotationNode = modifiersNode.findFirstToken(TokenTypes.ANNOTATION);
while (annotationNode != null && annotationNode.getType() == TokenTypes.ANNOTATION) {
DetailAST identNode = annotationNode.findFirstToken(TokenTypes.IDENT);
if (identNode == null) {
identNode = annotationNode.findFirstToken(TokenTypes.DOT)
.findFirstToken(TokenTypes.IDENT);
}
if (allowedAnnotations.contains(identNode.getText())) {
result = true;
break;
}
annotationNode = annotationNode.getNextSibling();
}
return result;
}
示例6: 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 };
}
示例7: getValueAsAnnotations
public static List<DetailAST> getValueAsAnnotations(DetailAST annotationKeyValueAst) {
// can be in curly bracket or only one annotation!
DetailAST annotationValueNode = getAnnotationValueNode(annotationKeyValueAst);
return annotationValueNode.getType() == TokenTypes.ANNOTATION ?
Collections.singletonList(annotationValueNode) :
CommonUtil.getChildsByType(annotationValueNode, TokenTypes.ANNOTATION);
}
示例8: getFirstModifierAst
/**
* Retrieves the first modifier that is not an annotation.
* @param modifiers The ast to examine.
* @return The first modifier or {@code null} if none found.
*/
private static DetailAST getFirstModifierAst(DetailAST modifiers) {
DetailAST modifier = modifiers.getFirstChild();
while (modifier != null && modifier.getType() == TokenTypes.ANNOTATION) {
modifier = modifier.getNextSibling();
}
return modifier;
}
示例9: getMethodAnnotationsList
/**
* Gets the list of annotations on method definition.
* @param methodDef method definition node
* @return List of annotations
*/
private static List<DetailAST> getMethodAnnotationsList(DetailAST methodDef) {
final List<DetailAST> annotationsList = new ArrayList<DetailAST>();
final DetailAST modifiers = methodDef.findFirstToken(TokenTypes.MODIFIERS);
DetailAST modifier = modifiers.getFirstChild();
while (modifier != null) {
if (modifier.getType() == TokenTypes.ANNOTATION) {
annotationsList.add(modifier);
}
modifier = modifier.getNextSibling();
}
return annotationsList;
}
示例10: isOnEnumConstant
/**
* Node is on enum constant.
* @param blockComment DetailAST
* @return true if node is before enum constant
*/
public static boolean isOnEnumConstant(DetailAST blockComment) {
final boolean isOnPlainConst = blockComment.getParent() != null
&& blockComment.getParent().getType() == TokenTypes.ENUM_CONSTANT_DEF
&& getPrevSiblingSkipComments(blockComment).getType() == TokenTypes.ANNOTATIONS
&& getPrevSiblingSkipComments(blockComment).getChildCount() == 0;
final boolean isOnConstWithAnnotation = !isOnPlainConst && blockComment.getParent() != null
&& blockComment.getParent().getType() == TokenTypes.ANNOTATION
&& blockComment.getParent().getParent().getParent().getType()
== TokenTypes.ENUM_CONSTANT_DEF;
return isOnPlainConst || isOnConstWithAnnotation;
}
示例11: skipAnnotations
/**
* Skip all annotations in modifier block.
* @param modifierIterator iterator for collection of modifiers
* @return modifier next to last annotation
*/
private static DetailAST skipAnnotations(Iterator<DetailAST> modifierIterator) {
DetailAST modifier;
do {
modifier = modifierIterator.next();
} while (modifierIterator.hasNext() && modifier.getType() == TokenTypes.ANNOTATION);
return modifier;
}
示例12: findLastAnnotation
/**
* Find the last token of type {@code TokenTypes.ANNOTATION}
* under the given set of modifiers.
* @param modifiers {@code DetailAST}.
* @return {@code DetailAST} or null if there are no annotations.
*/
private static DetailAST findLastAnnotation(DetailAST modifiers) {
DetailAST annotation = modifiers.findFirstToken(TokenTypes.ANNOTATION);
while (annotation != null && annotation.getNextSibling() != null
&& annotation.getNextSibling().getType() == TokenTypes.ANNOTATION) {
annotation = annotation.getNextSibling();
}
return annotation;
}
示例13: visitToken
@Override
public void visitToken(DetailAST ast) {
switch (ast.getType()) {
case TokenTypes.METHOD_CALL:
processLeft(ast);
processRight(ast.findFirstToken(TokenTypes.RPAREN));
break;
case TokenTypes.DOT:
case TokenTypes.EXPR:
case TokenTypes.QUESTION:
processExpression(ast);
break;
case TokenTypes.LITERAL_FOR:
visitLiteralFor(ast);
break;
case TokenTypes.ANNOTATION:
case TokenTypes.ENUM_CONSTANT_DEF:
case TokenTypes.LITERAL_NEW:
case TokenTypes.LITERAL_SYNCHRONIZED:
case TokenTypes.LAMBDA:
visitTokenWithOptionalParentheses(ast);
break;
case TokenTypes.RESOURCE_SPECIFICATION:
visitResourceSpecification(ast);
break;
default:
processLeft(ast.findFirstToken(TokenTypes.LPAREN));
processRight(ast.findFirstToken(TokenTypes.RPAREN));
}
}
示例14: getAnnotation
/**
* Checks to see if the AST is annotated with
* the passed in annotation and return the AST
* representing that annotation.
*
* <p>
* This method will not look for imports or package
* statements to detect the passed in annotation.
* </p>
*
* <p>
* To check if an AST contains a passed in annotation
* taking into account fully-qualified names
* (ex: java.lang.Override, Override)
* this method will need to be called twice. Once for each
* name given.
* </p>
*
* @param ast the current node
* @param annotation the annotation name to check for
* @return the AST representing that annotation
*/
public static DetailAST getAnnotation(final DetailAST ast,
String annotation) {
if (ast == null) {
throw new IllegalArgumentException(THE_AST_IS_NULL);
}
if (annotation == null) {
throw new IllegalArgumentException("the annotation is null");
}
if (CommonUtils.isBlank(annotation)) {
throw new IllegalArgumentException(
"the annotation is empty or spaces");
}
final DetailAST holder = getAnnotationHolder(ast);
DetailAST result = null;
for (DetailAST child = holder.getFirstChild();
child != null; child = child.getNextSibling()) {
if (child.getType() == TokenTypes.ANNOTATION) {
final DetailAST firstChild = child.findFirstToken(TokenTypes.AT);
final String name =
FullIdent.createFullIdent(firstChild.getNextSibling()).getText();
if (annotation.equals(name)) {
result = child;
break;
}
}
}
return result;
}
示例15: getDefaultTokens
@Override
public int[] getDefaultTokens() {
return new int[] {TokenTypes.ANNOTATION};
}