Class MoreAnnotations
java.lang.Object
com.google.errorprone.util.MoreAnnotations
Annotation-related utilities.
-
Method Summary
Modifier and TypeMethodDescriptionasEnumValue
(Class<T> clazz, AnnotationValue a) Converts the given attribute to an enum value.Converts the given attribute to an integer value.Converts the given annotation value to one or more strings.Converts the given attribute to an string value.static Stream
<TypeMirror> Converts the given annotation value to one or more annotations.static Optional
<TypeMirror> 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 Stream
<com.sun.tools.javac.code.Attribute.TypeCompound> getTopLevelTypeAttributes
(com.sun.tools.javac.code.Symbol sym) Returns "top-level" type annotations of the given symbol, including: Type annotations of the return type of a method.static Optional
<com.sun.tools.javac.code.Attribute> 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. -
getTopLevelTypeAttributes
public static Stream<com.sun.tools.javac.code.Attribute.TypeCompound> getTopLevelTypeAttributes(com.sun.tools.javac.code.Symbol sym) Returns "top-level" type annotations of the given symbol, including:- Type annotations of the return type of a method.
- Type annotations on the type of a formal parameter or field.
These annotations are not always included in those returned by
Type.getAnnotationMirrors()
because javac doesn't associate type annotation information with types for symbols completed from class files. These type annotations won't be included when the symbol is not in the current compilation. -
getValue
-
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.
-