Class AnnotationValues


  • public final class AnnotationValues
    extends java.lang.Object
    A utility class for working with AnnotationValue instances.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private AnnotationValues()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static com.google.common.base.Equivalence<javax.lang.model.element.AnnotationValue> equivalence()
      Returns an Equivalence for AnnotationValue as annotation values may contain AnnotationMirror instances some of whose implementations delegate equality tests to Object.equals(java.lang.Object) whereas the documentation explicitly states that instance/reference equality is not the proper test.
      static javax.lang.model.element.AnnotationMirror getAnnotationMirror​(javax.lang.model.element.AnnotationValue value)
      Returns the value as an AnnotationMirror.
      static com.google.common.collect.ImmutableList<javax.lang.model.element.AnnotationMirror> getAnnotationMirrors​(javax.lang.model.element.AnnotationValue value)
      Returns the value as a list of annotations.
      static com.google.common.collect.ImmutableList<javax.lang.model.element.AnnotationValue> getAnnotationValues​(javax.lang.model.element.AnnotationValue value)
      Returns the value as a list of AnnotationValues.
      static boolean getBoolean​(javax.lang.model.element.AnnotationValue value)
      Returns the value as a boolean.
      static com.google.common.collect.ImmutableList<java.lang.Boolean> getBooleans​(javax.lang.model.element.AnnotationValue value)
      Returns the value as a list of booleans.
      static byte getByte​(javax.lang.model.element.AnnotationValue value)
      Returns the value as a byte.
      static com.google.common.collect.ImmutableList<java.lang.Byte> getBytes​(javax.lang.model.element.AnnotationValue value)
      Returns the value as a list of bytes.
      static char getChar​(javax.lang.model.element.AnnotationValue value)
      Returns the value as a char.
      static com.google.common.collect.ImmutableList<java.lang.Character> getChars​(javax.lang.model.element.AnnotationValue value)
      Returns the value as a list of characters.
      static double getDouble​(javax.lang.model.element.AnnotationValue value)
      Returns the value as a double.
      static com.google.common.collect.ImmutableList<java.lang.Double> getDoubles​(javax.lang.model.element.AnnotationValue value)
      Returns the value as a list of doubles.
      static javax.lang.model.element.VariableElement getEnum​(javax.lang.model.element.AnnotationValue value)
      Returns the value as a VariableElement.
      static com.google.common.collect.ImmutableList<javax.lang.model.element.VariableElement> getEnums​(javax.lang.model.element.AnnotationValue value)
      Returns the value as a list of enums.
      static float getFloat​(javax.lang.model.element.AnnotationValue value)
      Returns the value as a float.
      static com.google.common.collect.ImmutableList<java.lang.Float> getFloats​(javax.lang.model.element.AnnotationValue value)
      Returns the value as a list of floats.
      static int getInt​(javax.lang.model.element.AnnotationValue value)
      Returns the value as an int.
      static com.google.common.collect.ImmutableList<java.lang.Integer> getInts​(javax.lang.model.element.AnnotationValue value)
      Returns the value as a list of integers.
      static long getLong​(javax.lang.model.element.AnnotationValue value)
      Returns the value as a long.
      static com.google.common.collect.ImmutableList<java.lang.Long> getLongs​(javax.lang.model.element.AnnotationValue value)
      Returns the value as a list of longs.
      static short getShort​(javax.lang.model.element.AnnotationValue value)
      Returns the value as a short.
      static com.google.common.collect.ImmutableList<java.lang.Short> getShorts​(javax.lang.model.element.AnnotationValue value)
      Returns the value as a list of shorts.
      static java.lang.String getString​(javax.lang.model.element.AnnotationValue value)
      Returns the value as a string.
      static com.google.common.collect.ImmutableList<java.lang.String> getStrings​(javax.lang.model.element.AnnotationValue value)
      Returns the value as a list of strings.
      static javax.lang.model.type.DeclaredType getTypeMirror​(javax.lang.model.element.AnnotationValue value)
      Returns the value as a class.
      static com.google.common.collect.ImmutableList<javax.lang.model.type.DeclaredType> getTypeMirrors​(javax.lang.model.element.AnnotationValue value)
      Returns the value as a list of classes.
      private static <T> T valueOfType​(javax.lang.model.element.AnnotationValue annotationValue, java.lang.Class<T> type)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AnnotationValues

        private AnnotationValues()
    • Method Detail

      • equivalence

        public static com.google.common.base.Equivalence<javax.lang.model.element.AnnotationValue> equivalence()
        Returns an Equivalence for AnnotationValue as annotation values may contain AnnotationMirror instances some of whose implementations delegate equality tests to Object.equals(java.lang.Object) whereas the documentation explicitly states that instance/reference equality is not the proper test.
        See Also:
        AnnotationMirrors.equivalence()
      • getTypeMirror

        public static javax.lang.model.type.DeclaredType getTypeMirror​(javax.lang.model.element.AnnotationValue value)
        Returns the value as a class.
        Throws:
        java.lang.IllegalArgumentException - if the value is not a class.
      • getAnnotationMirror

        public static javax.lang.model.element.AnnotationMirror getAnnotationMirror​(javax.lang.model.element.AnnotationValue value)
        Returns the value as an AnnotationMirror.
        Throws:
        java.lang.IllegalArgumentException - if the value is not an annotation.
      • getEnum

        public static javax.lang.model.element.VariableElement getEnum​(javax.lang.model.element.AnnotationValue value)
        Returns the value as a VariableElement.
        Throws:
        java.lang.IllegalArgumentException - if the value is not an enum.
      • valueOfType

        private static <T> T valueOfType​(javax.lang.model.element.AnnotationValue annotationValue,
                                         java.lang.Class<T> type)
      • getString

        public static java.lang.String getString​(javax.lang.model.element.AnnotationValue value)
        Returns the value as a string.
        Throws:
        java.lang.IllegalArgumentException - if the value is not a string.
      • getInt

        public static int getInt​(javax.lang.model.element.AnnotationValue value)
        Returns the value as an int.
        Throws:
        java.lang.IllegalArgumentException - if the value is not an int.
      • getLong

        public static long getLong​(javax.lang.model.element.AnnotationValue value)
        Returns the value as a long.
        Throws:
        java.lang.IllegalArgumentException - if the value is not a long.
      • getByte

        public static byte getByte​(javax.lang.model.element.AnnotationValue value)
        Returns the value as a byte.
        Throws:
        java.lang.IllegalArgumentException - if the value is not a byte.
      • getShort

        public static short getShort​(javax.lang.model.element.AnnotationValue value)
        Returns the value as a short.
        Throws:
        java.lang.IllegalArgumentException - if the value is not a short.
      • getFloat

        public static float getFloat​(javax.lang.model.element.AnnotationValue value)
        Returns the value as a float.
        Throws:
        java.lang.IllegalArgumentException - if the value is not a float.
      • getDouble

        public static double getDouble​(javax.lang.model.element.AnnotationValue value)
        Returns the value as a double.
        Throws:
        java.lang.IllegalArgumentException - if the value is not a double.
      • getBoolean

        public static boolean getBoolean​(javax.lang.model.element.AnnotationValue value)
        Returns the value as a boolean.
        Throws:
        java.lang.IllegalArgumentException - if the value is not a boolean.
      • getChar

        public static char getChar​(javax.lang.model.element.AnnotationValue value)
        Returns the value as a char.
        Throws:
        java.lang.IllegalArgumentException - if the value is not a char.
      • getTypeMirrors

        public static com.google.common.collect.ImmutableList<javax.lang.model.type.DeclaredType> getTypeMirrors​(javax.lang.model.element.AnnotationValue value)
        Returns the value as a list of classes.
        Throws:
        java.lang.IllegalArgumentException - if the value is not an array of classes.
      • getAnnotationMirrors

        public static com.google.common.collect.ImmutableList<javax.lang.model.element.AnnotationMirror> getAnnotationMirrors​(javax.lang.model.element.AnnotationValue value)
        Returns the value as a list of annotations.
        Throws:
        java.lang.IllegalArgumentException - if the value if not an array of annotations.
      • getEnums

        public static com.google.common.collect.ImmutableList<javax.lang.model.element.VariableElement> getEnums​(javax.lang.model.element.AnnotationValue value)
        Returns the value as a list of enums.
        Throws:
        java.lang.IllegalArgumentException - if the value is not an array of enums.
      • getStrings

        public static com.google.common.collect.ImmutableList<java.lang.String> getStrings​(javax.lang.model.element.AnnotationValue value)
        Returns the value as a list of strings.
        Throws:
        java.lang.IllegalArgumentException - if the value is not an array of strings.
      • getInts

        public static com.google.common.collect.ImmutableList<java.lang.Integer> getInts​(javax.lang.model.element.AnnotationValue value)
        Returns the value as a list of integers.
        Throws:
        java.lang.IllegalArgumentException - if the value is not an array of ints.
      • getLongs

        public static com.google.common.collect.ImmutableList<java.lang.Long> getLongs​(javax.lang.model.element.AnnotationValue value)
        Returns the value as a list of longs.
        Throws:
        java.lang.IllegalArgumentException - if the value is not an array of longs.
      • getBytes

        public static com.google.common.collect.ImmutableList<java.lang.Byte> getBytes​(javax.lang.model.element.AnnotationValue value)
        Returns the value as a list of bytes.
        Throws:
        java.lang.IllegalArgumentException - if the value is not an array of bytes.
      • getShorts

        public static com.google.common.collect.ImmutableList<java.lang.Short> getShorts​(javax.lang.model.element.AnnotationValue value)
        Returns the value as a list of shorts.
        Throws:
        java.lang.IllegalArgumentException - if the value is not an array of shorts.
      • getFloats

        public static com.google.common.collect.ImmutableList<java.lang.Float> getFloats​(javax.lang.model.element.AnnotationValue value)
        Returns the value as a list of floats.
        Throws:
        java.lang.IllegalArgumentException - if the value is not an array of floats.
      • getDoubles

        public static com.google.common.collect.ImmutableList<java.lang.Double> getDoubles​(javax.lang.model.element.AnnotationValue value)
        Returns the value as a list of doubles.
        Throws:
        java.lang.IllegalArgumentException - if the value is not an array of doubles.
      • getBooleans

        public static com.google.common.collect.ImmutableList<java.lang.Boolean> getBooleans​(javax.lang.model.element.AnnotationValue value)
        Returns the value as a list of booleans.
        Throws:
        java.lang.IllegalArgumentException - if the value is not an array of booleans.
      • getChars

        public static com.google.common.collect.ImmutableList<java.lang.Character> getChars​(javax.lang.model.element.AnnotationValue value)
        Returns the value as a list of characters.
        Throws:
        java.lang.IllegalArgumentException - if the value is not an array of chars.
      • getAnnotationValues

        public static com.google.common.collect.ImmutableList<javax.lang.model.element.AnnotationValue> getAnnotationValues​(javax.lang.model.element.AnnotationValue value)
        Returns the value as a list of AnnotationValues.
        Throws:
        java.lang.IllegalArgumentException - if the value is not an array.