Skip to content

Commit

Permalink
Fill out some missing combinations of ASTHelpers.hasAnnotation(), and…
Browse files Browse the repository at this point in the history
… fix some javadoc too

RELNOTES: None

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=186492858
  • Loading branch information
ronshapiro committed Feb 22, 2018
1 parent e967416 commit dcf628b
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions check_api/src/main/java/com/google/errorprone/util/ASTHelpers.java
Expand Up @@ -558,6 +558,7 @@ public static Set<MethodSymbol> findMatchingMethods(
*
* @param annotationClass the binary class name of the annotation (e.g.
* "javax.annotation.Nullable", or "some.package.OuterClassName$InnerClassName")
* @return true if the symbol is annotated with given type.
*/
public static boolean hasAnnotation(Symbol sym, String annotationClass, VisitorState state) {
Name annotationName = state.getName(annotationClass);
Expand Down Expand Up @@ -603,12 +604,23 @@ public static boolean hasAnnotation(
/**
* Check for the presence of an annotation, considering annotation inheritance.
*
* @return the annotation of given type on the tree's symbol, or null.
* @param annotationClass the binary class name of the annotation (e.g.
* "javax.annotation.Nullable", or "some.package.OuterClassName$InnerClassName")
* @return true if the tree is annotated with given type.
*/
public static boolean hasAnnotation(Tree tree, String annotationClass, VisitorState state) {
Symbol sym = getDeclaredSymbol(tree);
return hasAnnotation(sym, annotationClass, state);
}

/**
* Check for the presence of an annotation, considering annotation inheritance.
*
* @return true if the tree is annotated with given type.
*/
public static boolean hasAnnotation(
Tree tree, Class<? extends Annotation> annotationClass, VisitorState state) {
Symbol sym = getDeclaredSymbol(tree);
return hasAnnotation(sym, annotationClass.getName(), state);
return hasAnnotation(tree, annotationClass.getName(), state);
}

/**
Expand All @@ -628,6 +640,18 @@ public static boolean hasDirectAnnotationWithSimpleName(Symbol sym, String simpl
return false;
}

/**
* Check for the presence of an annotation with a specific simple name directly on this symbol.
* Does *not* consider annotation inheritance.
*
* @param tree the tree to check for the presence of the annotation
* @param simpleName the simple name of the annotation to look for, e.g. "Nullable" or
* "CheckReturnValue"
*/
public static boolean hasDirectAnnotationWithSimpleName(Tree tree, String simpleName) {
return hasDirectAnnotationWithSimpleName(getDeclaredSymbol(tree), simpleName);
}

/**
* Retrieve an annotation, considering annotation inheritance.
*
Expand Down

0 comments on commit dcf628b

Please sign in to comment.