Package com.google.auto.common
Class AnnotationValues
- java.lang.Object
-
- com.google.auto.common.AnnotationValues
-
public final class AnnotationValues extends java.lang.Object
A utility class for working withAnnotationValue
instances.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
AnnotationValues.AnnotationMirrorVisitor
private static class
AnnotationValues.ArrayVisitor<T>
private static class
AnnotationValues.DefaultVisitor<T>
private static class
AnnotationValues.EnumVisitor
private static class
AnnotationValues.TypeMirrorVisitor
-
Field Summary
Fields Modifier and Type Field Description private static AnnotationValues.ArrayVisitor<javax.lang.model.element.AnnotationMirror>
ANNOTATION_MIRRORS_VISITOR
private static com.google.common.base.Equivalence<javax.lang.model.element.AnnotationValue>
ANNOTATION_VALUE_EQUIVALENCE
private static AnnotationValues.ArrayVisitor<javax.lang.model.element.AnnotationValue>
ANNOTATION_VALUES_VISITOR
private static AnnotationValues.ArrayVisitor<java.lang.Boolean>
BOOLEANS_VISITOR
private static AnnotationValues.ArrayVisitor<java.lang.Byte>
BYTES_VISITOR
private static AnnotationValues.ArrayVisitor<java.lang.Character>
CHARS_VISITOR
private static AnnotationValues.ArrayVisitor<java.lang.Double>
DOUBLES_VISITOR
private static AnnotationValues.ArrayVisitor<javax.lang.model.element.VariableElement>
ENUMS_VISITOR
private static AnnotationValues.ArrayVisitor<java.lang.Float>
FLOATS_VISITOR
private static AnnotationValues.ArrayVisitor<java.lang.Integer>
INTS_VISITOR
private static AnnotationValues.ArrayVisitor<java.lang.Long>
LONGS_VISITOR
private static AnnotationValues.ArrayVisitor<java.lang.Short>
SHORTS_VISITOR
private static AnnotationValues.ArrayVisitor<java.lang.String>
STRINGS_VISITOR
private static AnnotationValues.ArrayVisitor<javax.lang.model.type.DeclaredType>
TYPE_MIRRORS_VISITOR
-
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 anEquivalence
forAnnotationValue
as annotation values may containAnnotationMirror
instances 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.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 ofAnnotationValue
s.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)
-
-
-
Field Detail
-
ANNOTATION_VALUE_EQUIVALENCE
private static final com.google.common.base.Equivalence<javax.lang.model.element.AnnotationValue> ANNOTATION_VALUE_EQUIVALENCE
-
TYPE_MIRRORS_VISITOR
private static final AnnotationValues.ArrayVisitor<javax.lang.model.type.DeclaredType> TYPE_MIRRORS_VISITOR
-
ANNOTATION_MIRRORS_VISITOR
private static final AnnotationValues.ArrayVisitor<javax.lang.model.element.AnnotationMirror> ANNOTATION_MIRRORS_VISITOR
-
ENUMS_VISITOR
private static final AnnotationValues.ArrayVisitor<javax.lang.model.element.VariableElement> ENUMS_VISITOR
-
STRINGS_VISITOR
private static final AnnotationValues.ArrayVisitor<java.lang.String> STRINGS_VISITOR
-
INTS_VISITOR
private static final AnnotationValues.ArrayVisitor<java.lang.Integer> INTS_VISITOR
-
LONGS_VISITOR
private static final AnnotationValues.ArrayVisitor<java.lang.Long> LONGS_VISITOR
-
BYTES_VISITOR
private static final AnnotationValues.ArrayVisitor<java.lang.Byte> BYTES_VISITOR
-
SHORTS_VISITOR
private static final AnnotationValues.ArrayVisitor<java.lang.Short> SHORTS_VISITOR
-
FLOATS_VISITOR
private static final AnnotationValues.ArrayVisitor<java.lang.Float> FLOATS_VISITOR
-
DOUBLES_VISITOR
private static final AnnotationValues.ArrayVisitor<java.lang.Double> DOUBLES_VISITOR
-
BOOLEANS_VISITOR
private static final AnnotationValues.ArrayVisitor<java.lang.Boolean> BOOLEANS_VISITOR
-
CHARS_VISITOR
private static final AnnotationValues.ArrayVisitor<java.lang.Character> CHARS_VISITOR
-
ANNOTATION_VALUES_VISITOR
private static final AnnotationValues.ArrayVisitor<javax.lang.model.element.AnnotationValue> ANNOTATION_VALUES_VISITOR
-
-
Method Detail
-
equivalence
public static com.google.common.base.Equivalence<javax.lang.model.element.AnnotationValue> equivalence()
Returns anEquivalence
forAnnotationValue
as annotation values may containAnnotationMirror
instances 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.
-
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 ofAnnotationValue
s.- Throws:
java.lang.IllegalArgumentException
- if the value is not an array.
-
-