Class MoreAnnotations
java.lang.Object
com.google.errorprone.util.MoreAnnotations
Annotation-related utilities.
-
Method Summary
Modifier and TypeMethodDescriptionstatic Stream<AnnotationMirror> Converts the given annotation value to one or more annotations.static Optional<AnnotationMirror> Converts the given attribute to an annotation mirror.Converts the given attribute to a boolean value.static com.sun.tools.javac.code.Symbol.TypeSymbolasElement(AnnotationMirror annotationMirror) Returns theSymbol.TypeSymbolrepresenting the declaration of the annotation mirror.asEnumValue(Class<T> clazz, AnnotationValue a) Deprecated.static Optional<com.sun.tools.javac.code.Symbol.VarSymbol> Converts the given attribute to an enum value.asEnumValues(Class<T> clazz, AnnotationValue a) Deprecated.PreferasEnumValues(AnnotationValue).static Stream<com.sun.tools.javac.code.Symbol.VarSymbol> Converts the given annotation value to one or more enum values.Converts the given attribute to an integer value.Converts the given annotation value to one or more strings.Converts the given attribute to a string value.static Stream<TypeMirror> Converts the given annotation value to one or more types.static Optional<TypeMirror> Converts the given attribute to a type.static Optional<com.sun.tools.javac.code.Attribute.Compound> getAnnotation(Element sym, String qualifiedName) Returns the annotation on the given element with the specified qualified binary or canonical name.static Optional<com.sun.tools.javac.code.Attribute.Compound> getAnnotation(Element sym, Name qualifiedName) Returns the annotation on the given element with the specified qualified name.static Optional<AnnotationValue> getAnnotationValue(com.sun.tools.javac.code.Attribute.Compound attribute, String name) Deprecated.static Optional<AnnotationValue> getAnnotationValue(AnnotationMirror annotationMirror, String name) Deprecated.UsegetValue(AnnotationMirror, String)instead.static Optional<com.sun.tools.javac.code.Attribute.Compound> getAnnotationWithSimpleName(Element sym, String simpleName) Returns the annotation on the given element with the specified simple name.getBooleanValue(AnnotationMirror attribute, String name) Shorthand for extracting a boolean value of a named element from an annotation mirror.getBooleanValue(Element sym, String annotationName) Shorthand for extracting the "value" boolean of a named annotation on an element.static Optional<com.sun.tools.javac.code.Symbol.VarSymbol> getEnumValue(AnnotationMirror attribute, String name) Shorthand for extracting an enum value of a named element from an annotation mirror.static Optional<com.sun.tools.javac.code.Symbol.VarSymbol> getEnumValue(Element sym, String annotationName) Shorthand for extracting the "value" enum of a named annotation on an element.static com.google.common.collect.ImmutableList<com.sun.tools.javac.code.Symbol.VarSymbol> getEnumValues(AnnotationMirror attribute, String name) Shorthand for extracting enum values of a named element from an annotation mirror.static com.google.common.collect.ImmutableList<com.sun.tools.javac.code.Symbol.VarSymbol> getEnumValues(Element sym, String annotationName) Shorthand for extracting the "value" enum values of a named annotation on an element.static RetentionPolicygetRetentionPolicy(Element annotationSymbol) Returns the effectiveRetentionPolicyof the annotation symbol (defaulting toRetentionPolicy.CLASSper JLS 9.6.4.2 if omitted or not found).static com.google.common.collect.ImmutableList<String> getStrings(AnnotationMirror attribute, String name) Shorthand for extracting a list of strings for a named element (e.g. array or single string).static com.google.common.collect.ImmutableList<String> getStrings(Element sym, String annotationName) Shorthand for extracting a list of strings from the "value" element of a named annotation on an element.getStringValue(AnnotationMirror attribute, String name) Shorthand for extracting a string value of a named element from an annotation mirror.getStringValue(Element sym, String annotationName) Shorthand for extracting the "value" string of a named annotation on an element.static @Nullable Set<ElementType> getTargetElementTypes(Element annotationSymbol) Returns the set ofElementTypetargets specified in the annotation's@Targetmeta-annotation, ornullif no@Targetmeta-annotation is present.static com.google.common.collect.ImmutableList<TypeMirror> getTypes(AnnotationMirror attribute, String name) Shorthand for extracting a list of types for a named element (e.g.static com.google.common.collect.ImmutableList<TypeMirror> Shorthand for extracting a list of types from the "value" element of a named annotation on an element.static Optional<TypeMirror> getTypeValue(AnnotationMirror attribute, String name) Shorthand for extracting a type value of a named element from an annotation mirror.static Optional<TypeMirror> getTypeValue(Element sym, String annotationName) Shorthand for extracting the "value" type of a named annotation on an element.static Optional<com.sun.tools.javac.code.Attribute> Deprecated.static Optional<AnnotationValue> getValue(AnnotationMirror annotationMirror, String name) Returns the value of the annotation element-value pair with the given name if it is explicitly set.static booleanisTypeAnnotation(Element annotationSymbol) Returns whether the annotation is a type annotation (i.e. its@TargetincludesElementType.TYPE_USEorElementType.TYPE_PARAMETER).static booleantargetsElement(Element annotationSymbol, ElementType target) Returns whether the annotation applies to the givenElementType.
-
Method Details
-
getAnnotation
-
getAnnotation
-
getAnnotationWithSimpleName
-
getValue
Returns the value of the annotation element-value pair with the given name if it is explicitly set. -
getValue
@InlineMe(replacement="MoreAnnotations.getValue((AnnotationMirror) attribute, name).map(Attribute.class::cast)", imports={"com.google.errorprone.util.MoreAnnotations","com.sun.tools.javac.code.Attribute","javax.lang.model.element.AnnotationMirror"}) @Deprecated public static Optional<com.sun.tools.javac.code.Attribute> getValue(com.sun.tools.javac.code.Attribute.Compound attribute, String name) Deprecated.Returns the value of the annotation element-value pair with the given name if it is explicitly set. -
getStringValue
Shorthand for extracting a string value of a named element from an annotation mirror. -
getStringValue
-
getBooleanValue
Shorthand for extracting a boolean value of a named element from an annotation mirror. -
getBooleanValue
-
getEnumValue
public static Optional<com.sun.tools.javac.code.Symbol.VarSymbol> getEnumValue(AnnotationMirror attribute, String name) Shorthand for extracting an enum value of a named element from an annotation mirror. -
getEnumValue
-
getEnumValues
public static com.google.common.collect.ImmutableList<com.sun.tools.javac.code.Symbol.VarSymbol> getEnumValues(AnnotationMirror attribute, String name) Shorthand for extracting enum values of a named element from an annotation mirror. -
getEnumValues
-
getStrings
public static com.google.common.collect.ImmutableList<String> getStrings(AnnotationMirror attribute, String name) Shorthand for extracting a list of strings for a named element (e.g. array or single string). -
getStrings
-
getTypes
public static com.google.common.collect.ImmutableList<TypeMirror> getTypes(AnnotationMirror attribute, String name) Shorthand for extracting a list of types for a named element (e.g. Class[] or Class). -
getTypes
public static com.google.common.collect.ImmutableList<TypeMirror> getTypes(Element sym, String annotationName) Shorthand for extracting a list of types from the "value" element of a named annotation on an element. -
getTypeValue
Shorthand for extracting a type value of a named element from an annotation mirror. -
getTypeValue
Shorthand for extracting the "value" type of a named annotation on an element. -
asBooleanValue
Converts the given attribute to a boolean value. -
asIntegerValue
Converts the given attribute to an integer value. -
asStringValue
Converts the given attribute to a string value. -
asEnumValue
Converts the given attribute to an enum value. -
asEnumValue
@Deprecated public static <T extends Enum<T>> Optional<T> asEnumValue(Class<T> clazz, AnnotationValue a) Deprecated.PreferasEnumValue(AnnotationValue).Converts the given attribute to an enum value. -
asEnumValues
Converts the given annotation value to one or more enum values. -
asEnumValues
@Deprecated public static <T extends Enum<T>> EnumSet<T> asEnumValues(Class<T> clazz, AnnotationValue a) Deprecated.PreferasEnumValues(AnnotationValue).Converts the given attribute to enum values. -
asTypeValue
Converts the given attribute to a type. -
asStrings
Converts the given annotation value to one or more strings. -
asAnnotationValue
Converts the given attribute to an annotation mirror. -
asAnnotations
Converts the given annotation value to one or more annotations. -
asTypes
Converts the given annotation value to one or more types. -
getAnnotationValue
@InlineMe(replacement="MoreAnnotations.getValue(annotationMirror, name)", imports="com.google.errorprone.util.MoreAnnotations") @Deprecated public static Optional<AnnotationValue> getAnnotationValue(AnnotationMirror annotationMirror, String name) Deprecated.UsegetValue(AnnotationMirror, String)instead. -
getAnnotationValue
@InlineMe(replacement="MoreAnnotations.getValue((AnnotationMirror) attribute, name)", imports={"com.google.errorprone.util.MoreAnnotations","javax.lang.model.element.AnnotationMirror"}) @Deprecated public static Optional<AnnotationValue> getAnnotationValue(com.sun.tools.javac.code.Attribute.Compound attribute, String name) Deprecated. -
asElement
public static com.sun.tools.javac.code.Symbol.TypeSymbol asElement(AnnotationMirror annotationMirror) Returns theSymbol.TypeSymbolrepresenting the declaration of the annotation mirror. -
getTargetElementTypes
Returns the set ofElementTypetargets specified in the annotation's@Targetmeta-annotation, ornullif no@Targetmeta-annotation is present. -
isTypeAnnotation
Returns whether the annotation is a type annotation (i.e. its@TargetincludesElementType.TYPE_USEorElementType.TYPE_PARAMETER). -
getRetentionPolicy
Returns the effectiveRetentionPolicyof the annotation symbol (defaulting toRetentionPolicy.CLASSper JLS 9.6.4.2 if omitted or not found). -
targetsElement
Returns whether the annotation applies to the givenElementType. If the annotation has no@Targetmeta-annotation, it is applicable in all declaration contexts (per JLS 9.6.4.1), which includes all element types exceptElementType.TYPE_USEandElementType.TYPE_PARAMETER.
-
asEnumValue(AnnotationValue).