public final class AnnotationUtil extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
private static java.lang.String |
THE_AST_IS_NULL
Common message.
|
| Modifier | Constructor and Description |
|---|---|
private |
AnnotationUtil()
Private utility constructor.
|
| Modifier and Type | Method and Description |
|---|---|
static boolean |
containsAnnotation(DetailAST ast)
Checks if the AST is annotated with any annotation.
|
static boolean |
containsAnnotation(DetailAST ast,
java.util.List<java.lang.String> annotations)
Checks if the given AST element is annotated with any of the specified annotations.
|
static boolean |
containsAnnotation(DetailAST ast,
java.lang.String annotation)
Checks if the AST is annotated with the passed in annotation.
|
private static DetailAST |
findFirstAnnotation(DetailAST ast,
java.util.function.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 DetailAST |
getAnnotation(DetailAST ast,
java.lang.String annotation)
Checks if the AST is annotated with the passed in annotation
and returns the AST representing that annotation.
|
static DetailAST |
getAnnotationHolder(DetailAST ast)
Gets the AST that holds a series of annotations for the
potentially annotated AST.
|
private static final java.lang.String THE_AST_IS_NULL
private AnnotationUtil()
java.lang.UnsupportedOperationException - if calledpublic static boolean containsAnnotation(DetailAST ast, java.lang.String 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.
ast - the current nodeannotation - the annotation name to check forpublic static boolean containsAnnotation(DetailAST ast)
ast - the current nodetrue if the AST contains at least one annotationjava.lang.IllegalArgumentException - when ast is nullpublic static boolean containsAnnotation(DetailAST ast, java.util.List<java.lang.String> annotations)
This method accepts both simple and fully-qualified names, e.g. "Override" will match both java.lang.Override and Override.
ast - The type or method definition.annotations - A collection of annotations to look for.true if the given AST element is annotated with
at least one of the specified annotations;
false otherwise.java.lang.IllegalArgumentException - when ast or annotations are nullpublic static DetailAST getAnnotationHolder(DetailAST ast)
null
if the passed in AST does not have an Annotation Holder.ast - the current nodejava.lang.IllegalArgumentException - when ast is nullpublic static DetailAST getAnnotation(DetailAST ast, java.lang.String 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.
ast - the current nodeannotation - the annotation name to check forjava.lang.IllegalArgumentException - when ast or annotations are null; when annotation is blankprivate static DetailAST findFirstAnnotation(DetailAST ast, java.util.function.Predicate<DetailAST> predicate)
This method will not look for imports or package statements to detect the passed in annotation.
ast - the current nodepredicate - The predicate which decides if an annotation matchesCopyright © 2001-2022. All Rights Reserved.