Package com.google.errorprone.util
Class MoreAnnotations
java.lang.Object
com.google.errorprone.util.MoreAnnotations
public final class MoreAnnotations extends Object
Annotation-related utilities.
-
Method Summary
Modifier and Type Method Description static <T extends Enum<T>>
Optional<T>asEnumValue(Class<T> clazz, AnnotationValue a)
Converts the given attribute to an enum value.static Optional<Integer>
asIntegerValue(AnnotationValue a)
Converts the given attribute to an integer value.static Stream<String>
asStrings(AnnotationValue v)
Converts the given annotation value to one or more strings.static Optional<String>
asStringValue(AnnotationValue a)
Converts the given attribute to an string value.static Stream<TypeMirror>
asTypes(AnnotationValue v)
Converts the given annotation value to one or more annotations.static Optional<TypeMirror>
asTypeValue(AnnotationValue a)
Converts the given attribute to an enum value.static Optional<AnnotationValue>
getAnnotationValue(com.sun.tools.javac.code.Attribute.Compound attribute, String name)
Returns the value of the annotation element-value pair with the given name if it is explicitly set.static Stream<com.sun.tools.javac.code.Attribute.Compound>
getDeclarationAndTypeAttributes(com.sun.tools.javac.code.Symbol sym)
Returns declaration annotations of the given symbol, as well as 'top-level' type annotations, including : Type annotations of the return type of a method.static Optional<com.sun.tools.javac.code.Attribute>
getValue(com.sun.tools.javac.code.Attribute.Compound attribute, String name)
Returns the value of the annotation element-value pair with the given name if it is explicitly set.
-
Method Details
-
getDeclarationAndTypeAttributes
public static Stream<com.sun.tools.javac.code.Attribute.Compound> getDeclarationAndTypeAttributes(com.sun.tools.javac.code.Symbol sym)Returns declaration annotations of the given symbol, as well as 'top-level' type annotations, including :- Type annotations of the return type of a method.
- Type annotations on the type of a formal parameter or field.
One might expect this to be equivalent to information returned by
Type.getAnnotationMirrors()
, but javac doesn't associate type annotation information with types for symbols completed from class files, so that approach doesn't work across compilation boundaries. -
getValue
public static Optional<com.sun.tools.javac.code.Attribute> getValue(com.sun.tools.javac.code.Attribute.Compound attribute, String name)Returns the value of the annotation element-value pair with the given name if it is explicitly set. -
getAnnotationValue
public static Optional<AnnotationValue> getAnnotationValue(com.sun.tools.javac.code.Attribute.Compound attribute, String name)Returns the value of the annotation element-value pair with the given name if it is explicitly set. -
asIntegerValue
Converts the given attribute to an integer value. -
asStringValue
Converts the given attribute to an string value. -
asEnumValue
Converts the given attribute to an enum value. -
asTypeValue
Converts the given attribute to an enum value. -
asStrings
Converts the given annotation value to one or more strings. -
asTypes
Converts the given annotation value to one or more annotations.
-