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

pack-priv final Class AnnotationOutput

extends Object
Class Inheritance
Static Imports
com.google.auto.common.MoreTypes.asTypeElement

Handling of default values for annotation members.
Author
[email protected] (Éamonn McManus)

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
AnnotationOutput.SourceFormVisitor

Visitor that produces a string representation of an annotation value, suitable for inclusion in a Java source file as an annotation member or as the initializer of a variable of the appropriate type.

Field Summary

Modifier and TypeField and Description
private static final AnnotationValueVisitor<AnnotationValue, AnnotationValue>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static void
private static StringBuilder
private static StringBuilder
private static AnnotationValue
private static Optional<AnnotationValue>
pack-priv static String
toString(AnnotationValue annotationValue)

Returns a string representation of the given annotation value, suitable for inclusion in a Java source file as the initializer of a variable of the appropriate type.

pack-priv static String
toString(AnnotationMirror annotationMirror)

Returns a string representation of the given annotation mirror, suitable for inclusion in a Java source file to reproduce the annotation in source form.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ARRAY_VISITORback to summary
private static final AnnotationValueVisitor<AnnotationValue, AnnotationValue> ARRAY_VISITOR

Constructor Detail

AnnotationOutputback to summary
private AnnotationOutput()

Method Detail

appendEscapedback to summary
private static void appendEscaped(StringBuilder sb, char c)
appendQuotedback to summary
private static StringBuilder appendQuoted(StringBuilder sb, String s)
appendQuotedback to summary
private static StringBuilder appendQuoted(StringBuilder sb, char c)
maybeShortenback to summary
private static AnnotationValue maybeShorten(AnnotationValue value)
shortFormback to summary
private static Optional<AnnotationValue> shortForm(Map<ExecutableElement, AnnotationValue> values)
toStringback to summary
pack-priv static String toString(AnnotationValue annotationValue)

Returns a string representation of the given annotation value, suitable for inclusion in a Java source file as the initializer of a variable of the appropriate type.

toStringback to summary
pack-priv static String toString(AnnotationMirror annotationMirror)

Returns a string representation of the given annotation mirror, suitable for inclusion in a Java source file to reproduce the annotation in source form.

com.google.auto.common back to summary

private Class AnnotationOutput.SourceFormVisitor

extends SimpleAnnotationValueVisitor8<@Nullable Void, StringBuilder>
Class Inheritance

Visitor that produces a string representation of an annotation value, suitable for inclusion in a Java source file as an annotation member or as the initializer of a variable of the appropriate type. The syntax for the two is the same except for annotation members that are themselves annotations. Within an annotation, an annotation member can be written as @NestedAnnotation(...), while in an initializer it must be written as an object, for example the construction of an @AutoAnnotation class. That's why we have this abstract class and two concrete subclasses.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
protected @Nullable Void
defaultAction(Object
the value of the annotation
value
,
StringBuilder
a visitor-specified parameter
sb
)

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

The default action for visit methods.
private String
formatType(TypeMirror typeMirror)

public @Nullable Void
visitAnnotation(AnnotationMirror
the value being visited
a
,
StringBuilder
a visitor-specified parameter
sb
)

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

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

Visits an annotation value in an annotation.
public @Nullable Void
visitArray(List<? extends AnnotationValue>
the value being visited
values
,
StringBuilder
a visitor-specified parameter
sb
)

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

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

Visits an array value in an annotation.
public @Nullable Void
visitByte(byte
the value being visited
b
,
StringBuilder
a visitor-specified parameter
sb
)

Overrides javax.lang.model.util.SimpleAnnotationValueVisitor6.visitByte.

Implements javax.lang.model.element.AnnotationValueVisitor.visitByte.

Visits a byte value in an annotation.
public @Nullable Void
visitChar(char
the value being visited
c
,
StringBuilder
a visitor-specified parameter
sb
)

Overrides javax.lang.model.util.SimpleAnnotationValueVisitor6.visitChar.

Implements javax.lang.model.element.AnnotationValueVisitor.visitChar.

Visits a char value in an annotation.
public @Nullable Void
visitDouble(double
the value being visited
d
,
StringBuilder
a visitor-specified parameter
sb
)

Overrides javax.lang.model.util.SimpleAnnotationValueVisitor6.visitDouble.

Implements javax.lang.model.element.AnnotationValueVisitor.visitDouble.

Visits a double value in an annotation.
public @Nullable Void
visitEnumConstant(VariableElement
the value being visited
c
,
StringBuilder
a visitor-specified parameter
sb
)

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

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

Visits an enum value in an annotation.
public @Nullable Void
visitFloat(float
the value being visited
f
,
StringBuilder
a visitor-specified parameter
sb
)

Overrides javax.lang.model.util.SimpleAnnotationValueVisitor6.visitFloat.

Implements javax.lang.model.element.AnnotationValueVisitor.visitFloat.

Visits a float value in an annotation.
public @Nullable Void
visitLong(long
the value being visited
i
,
StringBuilder
a visitor-specified parameter
sb
)

Overrides javax.lang.model.util.SimpleAnnotationValueVisitor6.visitLong.

Implements javax.lang.model.element.AnnotationValueVisitor.visitLong.

Visits a long value in an annotation.
public @Nullable Void
visitShort(short
the value being visited
s
,
StringBuilder
a visitor-specified parameter
sb
)

Overrides javax.lang.model.util.SimpleAnnotationValueVisitor6.visitShort.

Implements javax.lang.model.element.AnnotationValueVisitor.visitShort.

Visits a short value in an annotation.
public @Nullable Void
visitString(String
the value being visited
s
,
StringBuilder
a visitor-specified parameter
sb
)

Overrides javax.lang.model.util.SimpleAnnotationValueVisitor6.visitString.

Implements javax.lang.model.element.AnnotationValueVisitor.visitString.

Visits a string value in an annotation.
public @Nullable Void
visitType(TypeMirror
the value being visited
classConstant
,
StringBuilder
a visitor-specified parameter
sb
)

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

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

Visits a type value in an annotation.

Constructor Detail

SourceFormVisitorback to summary
private SourceFormVisitor()

Method Detail

defaultActionback to summary
protected @Nullable Void defaultAction(Object value, StringBuilder sb)

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

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

The default action for visit methods.

Parameters
value:Object

the value of the annotation

sb:StringBuilder

a visitor-specified parameter

Returns:@Nullable Void

DEFAULT_VALUE unless overridden

Annotations
@Override
formatTypeback to summary
private String formatType(TypeMirror typeMirror)
visitAnnotationback to summary
public @Nullable Void visitAnnotation(AnnotationMirror a, StringBuilder sb)

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
a:AnnotationMirror

the value being visited

sb:StringBuilder

a visitor-specified parameter

Returns:@Nullable Void

the result of defaultAction

Annotations
@Override
visitArrayback to summary
public @Nullable Void visitArray(List<? extends AnnotationValue> values, StringBuilder sb)

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

sb:StringBuilder

a visitor-specified parameter

Returns:@Nullable Void

the result of defaultAction

Annotations
@Override
visitByteback to summary
public @Nullable Void visitByte(byte b, StringBuilder sb)

Overrides javax.lang.model.util.SimpleAnnotationValueVisitor6.visitByte.

Implements javax.lang.model.element.AnnotationValueVisitor.visitByte.

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

Visits a byte value in an annotation.

Parameters
b:byte

the value being visited

sb:StringBuilder

a visitor-specified parameter

Returns:@Nullable Void

the result of defaultAction

Annotations
@Override
visitCharback to summary
public @Nullable Void visitChar(char c, StringBuilder sb)

Overrides javax.lang.model.util.SimpleAnnotationValueVisitor6.visitChar.

Implements javax.lang.model.element.AnnotationValueVisitor.visitChar.

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

Visits a char value in an annotation.

Parameters
c:char

the value being visited

sb:StringBuilder

a visitor-specified parameter

Returns:@Nullable Void

the result of defaultAction

Annotations
@Override
visitDoubleback to summary
public @Nullable Void visitDouble(double d, StringBuilder sb)

Overrides javax.lang.model.util.SimpleAnnotationValueVisitor6.visitDouble.

Implements javax.lang.model.element.AnnotationValueVisitor.visitDouble.

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

Visits a double value in an annotation.

Parameters
d:double

the value being visited

sb:StringBuilder

a visitor-specified parameter

Returns:@Nullable Void

the result of defaultAction

Annotations
@Override
visitEnumConstantback to summary
public @Nullable Void visitEnumConstant(VariableElement c, StringBuilder sb)

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
c:VariableElement

the value being visited

sb:StringBuilder

a visitor-specified parameter

Returns:@Nullable Void

the result of defaultAction

Annotations
@Override
visitFloatback to summary
public @Nullable Void visitFloat(float f, StringBuilder sb)

Overrides javax.lang.model.util.SimpleAnnotationValueVisitor6.visitFloat.

Implements javax.lang.model.element.AnnotationValueVisitor.visitFloat.

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

Visits a float value in an annotation.

Parameters
f:float

the value being visited

sb:StringBuilder

a visitor-specified parameter

Returns:@Nullable Void

the result of defaultAction

Annotations
@Override
visitLongback to summary
public @Nullable Void visitLong(long i, StringBuilder sb)

Overrides javax.lang.model.util.SimpleAnnotationValueVisitor6.visitLong.

Implements javax.lang.model.element.AnnotationValueVisitor.visitLong.

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

Visits a long value in an annotation.

Parameters
i:long

the value being visited

sb:StringBuilder

a visitor-specified parameter

Returns:@Nullable Void

the result of defaultAction

Annotations
@Override
visitShortback to summary
public @Nullable Void visitShort(short s, StringBuilder sb)

Overrides javax.lang.model.util.SimpleAnnotationValueVisitor6.visitShort.

Implements javax.lang.model.element.AnnotationValueVisitor.visitShort.

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

Visits a short value in an annotation.

Parameters
s:short

the value being visited

sb:StringBuilder

a visitor-specified parameter

Returns:@Nullable Void

the result of defaultAction

Annotations
@Override
visitStringback to summary
public @Nullable Void visitString(String s, StringBuilder sb)

Overrides javax.lang.model.util.SimpleAnnotationValueVisitor6.visitString.

Implements javax.lang.model.element.AnnotationValueVisitor.visitString.

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

Visits a string value in an annotation.

Parameters
s:String

the value being visited

sb:StringBuilder

a visitor-specified parameter

Returns:@Nullable Void

the result of defaultAction

Annotations
@Override
visitTypeback to summary
public @Nullable Void visitType(TypeMirror classConstant, StringBuilder sb)

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
classConstant:TypeMirror

the value being visited

sb:StringBuilder

a visitor-specified parameter

Returns:@Nullable Void

the result of defaultAction

Annotations
@Override