Class MoreAnnotations

java.lang.Object
com.google.errorprone.util.MoreAnnotations

public final class MoreAnnotations
extends Object
Annotation-related utilities.
  • 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

      public static Optional<Integer> asIntegerValue​(AnnotationValue a)
      Converts the given attribute to an integer value.
    • asStringValue

      public static Optional<String> asStringValue​(AnnotationValue a)
      Converts the given attribute to an string value.
    • asEnumValue

      public static <T extends Enum<T>> Optional<T> asEnumValue​(Class<T> clazz, AnnotationValue a)
      Converts the given attribute to an enum value.
    • asTypeValue

      public static Optional<TypeMirror> asTypeValue​(AnnotationValue a)
      Converts the given attribute to an enum value.
    • asStrings

      public static Stream<String> asStrings​(AnnotationValue v)
      Converts the given annotation value to one or more strings.
    • asTypes

      public static Stream<TypeMirror> asTypes​(AnnotationValue v)
      Converts the given annotation value to one or more annotations.
    • asStrings

      @Deprecated public static Stream<String> asStrings​(com.sun.tools.javac.code.Attribute v)
      Deprecated.
      Continues to exist only to allow migration to wider asStrings(AnnotationValue) for targets which have this symbol compiled in. Please invoke that target, with an explicit cast if necessary.
      Converts the given attribute to one or more strings.