Class AnnotationUtil
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanChecks if the AST is annotated with any annotation.static booleancontainsAnnotation(DetailAST ast, String annotation) Checks if the AST is annotated with the passed in annotation.static booleancontainsAnnotation(DetailAST ast, Set<String> annotations) Checks if the given AST element is annotated with any of the specified annotations.private static DetailASTfindFirstAnnotation(DetailAST ast, Predicate<DetailAST> predicate) Checks if the given AST is annotated with at least one annotation that matches the given predicate and returns the AST representing the first matching annotation.static DetailASTgetAnnotation(DetailAST ast, String annotation) Checks if the AST is annotated with the passed in annotation and returns the AST representing that annotation.private static StringgetAnnotationFullIdent(DetailAST annotationNode) Gets the full ident text of the annotation AST.static DetailASTGets the AST that holds a series of annotations for the potentially annotated AST.static booleanChecks if the AST is annotated withOverrideorjava.lang.Overrideannotation.
-
Field Details
-
Constructor Details
-
AnnotationUtil
private AnnotationUtil()Private utility constructor.- Throws:
UnsupportedOperationException- if called
-
-
Method Details
-
containsAnnotation
Checks if the AST is annotated with the passed in annotation.This method will not look for imports or package statements to detect the passed in annotation.
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.
- Parameters:
ast- the current nodeannotation- the annotation name to check for- Returns:
- true if contains the annotation
-
containsAnnotation
Checks if the AST is annotated with any annotation.- Parameters:
ast- the current node- Returns:
trueif the AST contains at least one annotation- Throws:
IllegalArgumentException- when ast is null
-
containsAnnotation
Checks if the given AST element is annotated with any of the specified annotations.This method accepts both simple and fully-qualified names, e.g. "Override" will match both java.lang.Override and Override.
- Parameters:
ast- The type or method definition.annotations- A collection of annotations to look for.- Returns:
trueif the given AST element is annotated with at least one of the specified annotations;falseotherwise.- Throws:
IllegalArgumentException- when ast or annotations are null
-
getAnnotationFullIdent
Gets the full ident text of the annotation AST.- Parameters:
annotationNode- The annotation AST.- Returns:
- The full ident text.
-
hasOverrideAnnotation
Checks if the AST is annotated withOverrideorjava.lang.Overrideannotation.- Parameters:
ast- the current node- Returns:
trueif the AST contains Override annotation- Throws:
IllegalArgumentException- when ast is null
-
getAnnotationHolder
Gets the AST that holds a series of annotations for the potentially annotated AST. Returnsnullif the passed in AST does not have an Annotation Holder.- Parameters:
ast- the current node- Returns:
- the Annotation Holder
- Throws:
IllegalArgumentException- when ast is null
-
getAnnotation
Checks if the AST is annotated with the passed in annotation and returns the AST representing that annotation.This method will not look for imports or package statements to detect the passed in annotation.
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.
- Parameters:
ast- the current nodeannotation- the annotation name to check for- Returns:
- the AST representing that annotation
- Throws:
IllegalArgumentException- when ast or annotations are null; when annotation is blank
-
findFirstAnnotation
Checks if the given AST is annotated with at least one annotation that matches the given predicate and returns the AST representing the first matching annotation.This method will not look for imports or package statements to detect the passed in annotation.
- Parameters:
ast- the current nodepredicate- The predicate which decides if an annotation matches- Returns:
- the AST representing that annotation
-