Package com.google.auto.common
Class AnnotationValues
- java.lang.Object
-
- com.google.auto.common.AnnotationValues
-
public final class AnnotationValues extends java.lang.ObjectA utility class for working withAnnotationValueinstances.- Author:
- Christian Gruber
-
-
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 anEquivalenceforAnnotationValueas annotation values may containAnnotationMirrorinstances some of whose implementations delegate equality tests toObject.equals(java.lang.Object)whereas the documentation explicitly states that instance/reference equality is not the proper test.static javax.lang.model.element.AnnotationMirrorgetAnnotationMirror(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 ofAnnotationValues.static booleangetBoolean(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 bytegetByte(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 chargetChar(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 doublegetDouble(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.VariableElementgetEnum(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 floatgetFloat(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 intgetInt(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 longgetLong(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 shortgetShort(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.StringgetString(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.DeclaredTypegetTypeMirror(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.static java.lang.StringtoString(javax.lang.model.element.AnnotationValue annotationValue)Returns a string representation of the given annotation value, suitable for inclusion in a Java source file as part of an annotation.
-
-
-
Method Detail
-
equivalence
public static com.google.common.base.Equivalence<javax.lang.model.element.AnnotationValue> equivalence()
Returns anEquivalenceforAnnotationValueas annotation values may containAnnotationMirrorinstances some of whose implementations delegate equality tests toObject.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.
-
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 ofAnnotationValues.- Throws:
java.lang.IllegalArgumentException- if the value is not an array.
-
toString
public static java.lang.String toString(javax.lang.model.element.AnnotationValue annotationValue)
Returns a string representation of the given annotation value, suitable for inclusion in a Java source file as part of an annotation. For example, ifannotationValuerepresents the stringuncheckedin the annotation@SuppressWarnings("unchecked"), this method will return the string"unchecked", which you can then use as part of an annotation being generated.For all annotation values other than nested annotations, the returned string can also be used to initialize a variable of the appropriate type.
Fully qualified names are used for types in annotations, class literals, and enum constants, ensuring that the source form will compile without requiring additional imports.
-
-