Top Description Inners Fields Constructors Methods
com.google.auto.common

public final Class AnnotationValues

extends Object
Class Inheritance
Static Imports
com.google.auto.common.MoreStreams.toImmutableList, com.google.common.base.Preconditions.checkNotNull

A utility class for working with AnnotationValue instances.
Author
Christian Gruber

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class
private static class
private static class
private static class

Field Summary

Modifier and TypeField and Description
private static final AnnotationValues.ArrayVisitor<AnnotationMirror>
private static final Equivalence<AnnotationValue>
private static final AnnotationValues.ArrayVisitor<AnnotationValue>
private static final AnnotationValues.ArrayVisitor<Boolean>
private static final AnnotationValues.ArrayVisitor<Byte>
private static final AnnotationValues.ArrayVisitor<Character>
private static final AnnotationValues.ArrayVisitor<Double>
private static final AnnotationValues.ArrayVisitor<VariableElement>
private static final AnnotationValues.ArrayVisitor<Float>
private static final AnnotationValues.ArrayVisitor<Integer>
private static final AnnotationValues.ArrayVisitor<Long>
private static final AnnotationValues.ArrayVisitor<Short>
private static final AnnotationValues.ArrayVisitor<String>
private static final AnnotationValues.ArrayVisitor<DeclaredType>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static Equivalence<AnnotationValue>
equivalence()

Returns an Equivalence for AnnotationValue as annotation values may contain AnnotationMirror instances some of whose implementations delegate equality tests to Object#equals whereas the documentation explicitly states that instance/reference equality is not the proper test.

public static AnnotationMirror
getAnnotationMirror(AnnotationValue value)

Returns the value as an AnnotationMirror.

public static ImmutableList<AnnotationMirror>
getAnnotationMirrors(AnnotationValue value)

Returns the value as a list of annotations.

public static ImmutableList<AnnotationValue>
getAnnotationValues(AnnotationValue value)

Returns the value as a list of AnnotationValues.

public static boolean
getBoolean(AnnotationValue value)

Returns the value as a boolean.

public static ImmutableList<Boolean>
getBooleans(AnnotationValue value)

Returns the value as a list of booleans.

public static byte
getByte(AnnotationValue value)

Returns the value as a byte.

public static ImmutableList<Byte>
getBytes(AnnotationValue value)

Returns the value as a list of bytes.

public static char
getChar(AnnotationValue value)

Returns the value as a char.

public static ImmutableList<Character>
getChars(AnnotationValue value)

Returns the value as a list of characters.

public static double
getDouble(AnnotationValue value)

Returns the value as a double.

public static ImmutableList<Double>
getDoubles(AnnotationValue value)

Returns the value as a list of doubles.

public static VariableElement
getEnum(AnnotationValue value)

Returns the value as a VariableElement.

public static ImmutableList<VariableElement>
getEnums(AnnotationValue value)

Returns the value as a list of enums.

public static float
getFloat(AnnotationValue value)

Returns the value as a float.

public static ImmutableList<Float>
getFloats(AnnotationValue value)

Returns the value as a list of floats.

public static int
getInt(AnnotationValue value)

Returns the value as an int.

public static ImmutableList<Integer>
getInts(AnnotationValue value)

Returns the value as a list of integers.

public static long
getLong(AnnotationValue value)

Returns the value as a long.

public static ImmutableList<Long>
getLongs(AnnotationValue value)

Returns the value as a list of longs.

public static short
getShort(AnnotationValue value)

Returns the value as a short.

public static ImmutableList<Short>
getShorts(AnnotationValue value)

Returns the value as a list of shorts.

public static String
getString(AnnotationValue value)

Returns the value as a string.

public static ImmutableList<String>
getStrings(AnnotationValue value)

Returns the value as a list of strings.

public static DeclaredType
getTypeMirror(AnnotationValue value)

Returns the value as a class.

public static ImmutableList<DeclaredType>
getTypeMirrors(AnnotationValue value)

Returns the value as a list of classes.

public static String
toString(AnnotationValue annotationValue)

Returns a string representation of the given annotation value, suitable for inclusion in a Java source file as part of an annotation.

private static <T> T
valueOfType(AnnotationValue annotationValue, Class<T> type)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ANNOTATION_MIRRORS_VISITORback to summary
private static final AnnotationValues.ArrayVisitor<AnnotationMirror> ANNOTATION_MIRRORS_VISITOR
ANNOTATION_VALUE_EQUIVALENCEback to summary
private static final Equivalence<AnnotationValue> ANNOTATION_VALUE_EQUIVALENCE
ANNOTATION_VALUES_VISITORback to summary
private static final AnnotationValues.ArrayVisitor<AnnotationValue> ANNOTATION_VALUES_VISITOR
BOOLEANS_VISITORback to summary
private static final AnnotationValues.ArrayVisitor<Boolean> BOOLEANS_VISITOR
BYTES_VISITORback to summary
private static final AnnotationValues.ArrayVisitor<Byte> BYTES_VISITOR
CHARS_VISITORback to summary
private static final AnnotationValues.ArrayVisitor<Character> CHARS_VISITOR
DOUBLES_VISITORback to summary
private static final AnnotationValues.ArrayVisitor<Double> DOUBLES_VISITOR
ENUMS_VISITORback to summary
private static final AnnotationValues.ArrayVisitor<VariableElement> ENUMS_VISITOR
FLOATS_VISITORback to summary
private static final AnnotationValues.ArrayVisitor<Float> FLOATS_VISITOR
INTS_VISITORback to summary
private static final AnnotationValues.ArrayVisitor<Integer> INTS_VISITOR
LONGS_VISITORback to summary
private static final AnnotationValues.ArrayVisitor<Long> LONGS_VISITOR
SHORTS_VISITORback to summary
private static final AnnotationValues.ArrayVisitor<Short> SHORTS_VISITOR
STRINGS_VISITORback to summary
private static final AnnotationValues.ArrayVisitor<String> STRINGS_VISITOR
TYPE_MIRRORS_VISITORback to summary
private static final AnnotationValues.ArrayVisitor<DeclaredType> TYPE_MIRRORS_VISITOR

Constructor Detail

AnnotationValuesback to summary
private AnnotationValues()

Method Detail

equivalenceback to summary
public static Equivalence<AnnotationValue> equivalence()

Returns an Equivalence for AnnotationValue as annotation values may contain AnnotationMirror instances some of whose implementations delegate equality tests to Object#equals whereas the documentation explicitly states that instance/reference equality is not the proper test.

See Also
AnnotationMirrors#equivalence()
getAnnotationMirrorback to summary
public static AnnotationMirror getAnnotationMirror(AnnotationValue value)

Returns the value as an AnnotationMirror.

Exceptions
IllegalArgumentException:
if the value is not an annotation.
getAnnotationMirrorsback to summary
public static ImmutableList<AnnotationMirror> getAnnotationMirrors(AnnotationValue value)

Returns the value as a list of annotations.

Exceptions
IllegalArgumentException:
if the value if not an array of annotations.
getAnnotationValuesback to summary
public static ImmutableList<AnnotationValue> getAnnotationValues(AnnotationValue value)

Returns the value as a list of AnnotationValues.

Exceptions
IllegalArgumentException:
if the value is not an array.
getBooleanback to summary
public static boolean getBoolean(AnnotationValue value)

Returns the value as a boolean.

Exceptions
IllegalArgumentException:
if the value is not a boolean.
getBooleansback to summary
public static ImmutableList<Boolean> getBooleans(AnnotationValue value)

Returns the value as a list of booleans.

Exceptions
IllegalArgumentException:
if the value is not an array of booleans.
getByteback to summary
public static byte getByte(AnnotationValue value)

Returns the value as a byte.

Exceptions
IllegalArgumentException:
if the value is not a byte.
getBytesback to summary
public static ImmutableList<Byte> getBytes(AnnotationValue value)

Returns the value as a list of bytes.

Exceptions
IllegalArgumentException:
if the value is not an array of bytes.
getCharback to summary
public static char getChar(AnnotationValue value)

Returns the value as a char.

Exceptions
IllegalArgumentException:
if the value is not a char.
getCharsback to summary
public static ImmutableList<Character> getChars(AnnotationValue value)

Returns the value as a list of characters.

Exceptions
IllegalArgumentException:
if the value is not an array of chars.
getDoubleback to summary
public static double getDouble(AnnotationValue value)

Returns the value as a double.

Exceptions
IllegalArgumentException:
if the value is not a double.
getDoublesback to summary
public static ImmutableList<Double> getDoubles(AnnotationValue value)

Returns the value as a list of doubles.

Exceptions
IllegalArgumentException:
if the value is not an array of doubles.
getEnumback to summary
public static VariableElement getEnum(AnnotationValue value)

Returns the value as a VariableElement.

Exceptions
IllegalArgumentException:
if the value is not an enum.
getEnumsback to summary
public static ImmutableList<VariableElement> getEnums(AnnotationValue value)

Returns the value as a list of enums.

Exceptions
IllegalArgumentException:
if the value is not an array of enums.
getFloatback to summary
public static float getFloat(AnnotationValue value)

Returns the value as a float.

Exceptions
IllegalArgumentException:
if the value is not a float.
getFloatsback to summary
public static ImmutableList<Float> getFloats(AnnotationValue value)

Returns the value as a list of floats.

Exceptions
IllegalArgumentException:
if the value is not an array of floats.
getIntback to summary
public static int getInt(AnnotationValue value)

Returns the value as an int.

Exceptions
IllegalArgumentException:
if the value is not an int.
getIntsback to summary
public static ImmutableList<Integer> getInts(AnnotationValue value)

Returns the value as a list of integers.

Exceptions
IllegalArgumentException:
if the value is not an array of ints.
getLongback to summary
public static long getLong(AnnotationValue value)

Returns the value as a long.

Exceptions
IllegalArgumentException:
if the value is not a long.
getLongsback to summary
public static ImmutableList<Long> getLongs(AnnotationValue value)

Returns the value as a list of longs.

Exceptions
IllegalArgumentException:
if the value is not an array of longs.
getShortback to summary
public static short getShort(AnnotationValue value)

Returns the value as a short.

Exceptions
IllegalArgumentException:
if the value is not a short.
getShortsback to summary
public static ImmutableList<Short> getShorts(AnnotationValue value)

Returns the value as a list of shorts.

Exceptions
IllegalArgumentException:
if the value is not an array of shorts.
getStringback to summary
public static String getString(AnnotationValue value)

Returns the value as a string.

Exceptions
IllegalArgumentException:
if the value is not a string.
getStringsback to summary
public static ImmutableList<String> getStrings(AnnotationValue value)

Returns the value as a list of strings.

Exceptions
IllegalArgumentException:
if the value is not an array of strings.
getTypeMirrorback to summary
public static DeclaredType getTypeMirror(AnnotationValue value)

Returns the value as a class.

Exceptions
IllegalArgumentException:
if the value is not a class.
getTypeMirrorsback to summary
public static ImmutableList<DeclaredType> getTypeMirrors(AnnotationValue value)

Returns the value as a list of classes.

Exceptions
IllegalArgumentException:
if the value is not an array of classes.
toStringback to summary
public static String toString(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, if annotationValue represents the string unchecked in 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.

valueOfTypeback to summary
private static <T> T valueOfType(AnnotationValue annotationValue, Class<T> type)
com.google.auto.common back to summary

private final Class AnnotationValues.AnnotationMirrorVisitor

extends AnnotationValues.DefaultVisitor<AnnotationMirror>
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv static final AnnotationValues.AnnotationMirrorVisitor
Inherited from com.google.auto.common.AnnotationValues.DefaultVisitor:
clazz

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public AnnotationMirror
visitAnnotation(AnnotationMirror
the value being visited
value
,
Void
a visitor-specified parameter
unused
)

Overrides javax.lang.model.util.SimpleAnnotationValueVisitor6.visitAnnotation.

Implements javax.lang.model.element.AnnotationValueVisitor.visitAnnotation.

Visits an annotation value in an annotation.
Inherited from com.google.auto.common.AnnotationValues.DefaultVisitor:
defaultAction

Field Detail

INSTANCEback to summary
pack-priv static final AnnotationValues.AnnotationMirrorVisitor INSTANCE

Constructor Detail

AnnotationMirrorVisitorback to summary
pack-priv AnnotationMirrorVisitor()

Method Detail

visitAnnotationback to summary
public AnnotationMirror visitAnnotation(AnnotationMirror value, Void unused)

Overrides javax.lang.model.util.SimpleAnnotationValueVisitor6.visitAnnotation.

Implements javax.lang.model.element.AnnotationValueVisitor.visitAnnotation.

Doc from javax.lang.model.util.SimpleAnnotationValueVisitor6.visitAnnotation.

Visits an annotation value in an annotation.

Parameters
value:AnnotationMirror

the value being visited

unused:Void

a visitor-specified parameter

Returns:AnnotationMirror

the result of defaultAction

Annotations
@Override
com.google.auto.common back to summary

private final Class AnnotationValues.ArrayVisitor<T>

extends SimpleAnnotationValueVisitor8<ImmutableList<T>, Void>
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv final Function<AnnotationValue, T>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public ImmutableList<T>
defaultAction(Object
the value of the annotation
o
,
Void
a visitor-specified parameter
unused
)

Overrides javax.lang.model.util.SimpleAnnotationValueVisitor6.defaultAction.

The default action for visit methods.
public ImmutableList<T>
visitArray(List<? extends AnnotationValue>
the value being visited
values
,
Void
a visitor-specified parameter
unused
)

Overrides javax.lang.model.util.SimpleAnnotationValueVisitor6.visitArray.

Implements javax.lang.model.element.AnnotationValueVisitor.visitArray.

Visits an array value in an annotation.

Field Detail

visitTback to summary
pack-priv final Function<AnnotationValue, T> visitT

Constructor Detail

ArrayVisitorback to summary
pack-priv ArrayVisitor(Function<AnnotationValue, T> visitT)

Method Detail

defaultActionback to summary
public ImmutableList<T> defaultAction(Object o, Void unused)

Overrides javax.lang.model.util.SimpleAnnotationValueVisitor6.defaultAction.

Doc from javax.lang.model.util.SimpleAnnotationValueVisitor6.defaultAction.

The default action for visit methods.

Parameters
o:Object

the value of the annotation

unused:Void

a visitor-specified parameter

Returns:ImmutableList<T>

DEFAULT_VALUE unless overridden

Annotations
@Override
visitArrayback to summary
public ImmutableList<T> visitArray(List<? extends AnnotationValue> values, Void unused)

Overrides javax.lang.model.util.SimpleAnnotationValueVisitor6.visitArray.

Implements javax.lang.model.element.AnnotationValueVisitor.visitArray.

Doc from javax.lang.model.util.SimpleAnnotationValueVisitor6.visitArray.

Visits an array value in an annotation.

Parameters
values:List<? extends AnnotationValue>

the value being visited

unused:Void

a visitor-specified parameter

Returns:ImmutableList<T>

the result of defaultAction

Annotations
@Override
com.google.auto.common back to summary

private Class AnnotationValues.DefaultVisitor<T>

extends SimpleAnnotationValueVisitor8<T, Void>
Class Inheritance
Known Direct Subclasses
com.google.auto.common.AnnotationValues.TypeMirrorVisitor, com.google.auto.common.AnnotationValues.AnnotationMirrorVisitor, com.google.auto.common.AnnotationValues.EnumVisitor

Field Summary

Modifier and TypeField and Description
pack-priv final Class<T>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public T
defaultAction(Object
the value of the annotation
o
,
Void
a visitor-specified parameter
unused
)

Overrides javax.lang.model.util.SimpleAnnotationValueVisitor6.defaultAction.

The default action for visit methods.

Field Detail

clazzback to summary
pack-priv final Class<T> clazz

Constructor Detail

DefaultVisitorback to summary
pack-priv DefaultVisitor(Class<T> clazz)

Method Detail

defaultActionback to summary
public T defaultAction(Object o, Void unused)

Overrides javax.lang.model.util.SimpleAnnotationValueVisitor6.defaultAction.

Doc from javax.lang.model.util.SimpleAnnotationValueVisitor6.defaultAction.

The default action for visit methods.

Parameters
o:Object

the value of the annotation

unused:Void

a visitor-specified parameter

Returns:T

DEFAULT_VALUE unless overridden

Annotations
@Override
com.google.auto.common back to summary

private final Class AnnotationValues.EnumVisitor

extends AnnotationValues.DefaultVisitor<VariableElement>
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv static final AnnotationValues.EnumVisitor
Inherited from com.google.auto.common.AnnotationValues.DefaultVisitor:
clazz

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public VariableElement
visitEnumConstant(VariableElement
the value being visited
value
,
Void
a visitor-specified parameter
unused
)

Overrides javax.lang.model.util.SimpleAnnotationValueVisitor6.visitEnumConstant.

Implements javax.lang.model.element.AnnotationValueVisitor.visitEnumConstant.

Visits an enum value in an annotation.
Inherited from com.google.auto.common.AnnotationValues.DefaultVisitor:
defaultAction

Field Detail

INSTANCEback to summary
pack-priv static final AnnotationValues.EnumVisitor INSTANCE

Constructor Detail

EnumVisitorback to summary
pack-priv EnumVisitor()

Method Detail

visitEnumConstantback to summary
public VariableElement visitEnumConstant(VariableElement value, Void unused)

Overrides javax.lang.model.util.SimpleAnnotationValueVisitor6.visitEnumConstant.

Implements javax.lang.model.element.AnnotationValueVisitor.visitEnumConstant.

Doc from javax.lang.model.util.SimpleAnnotationValueVisitor6.visitEnumConstant.

Visits an enum value in an annotation.

Parameters
value:VariableElement

the value being visited

unused:Void

a visitor-specified parameter

Returns:VariableElement

the result of defaultAction

Annotations
@Override
com.google.auto.common back to summary

private final Class AnnotationValues.TypeMirrorVisitor

extends AnnotationValues.DefaultVisitor<DeclaredType>
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv static final AnnotationValues.TypeMirrorVisitor
Inherited from com.google.auto.common.AnnotationValues.DefaultVisitor:
clazz

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public DeclaredType
visitType(TypeMirror
the value being visited
value
,
Void
a visitor-specified parameter
unused
)

Overrides javax.lang.model.util.SimpleAnnotationValueVisitor6.visitType.

Implements javax.lang.model.element.AnnotationValueVisitor.visitType.

Visits a type value in an annotation.
Inherited from com.google.auto.common.AnnotationValues.DefaultVisitor:
defaultAction

Field Detail

INSTANCEback to summary
pack-priv static final AnnotationValues.TypeMirrorVisitor INSTANCE

Constructor Detail

TypeMirrorVisitorback to summary
pack-priv TypeMirrorVisitor()

Method Detail

visitTypeback to summary
public DeclaredType visitType(TypeMirror value, Void unused)

Overrides javax.lang.model.util.SimpleAnnotationValueVisitor6.visitType.

Implements javax.lang.model.element.AnnotationValueVisitor.visitType.

Doc from javax.lang.model.util.SimpleAnnotationValueVisitor6.visitType.

Visits a type value in an annotation.

Parameters
value:TypeMirror

the value being visited

unused:Void

a visitor-specified parameter

Returns:DeclaredType

the result of defaultAction

Annotations
@Override