Top Description Inners Fields Constructors Methods
com.google.auto.value.extension.toprettystring.processor

public final Class ToPrettyStringExtension

extends AutoValueExtension
Class Inheritance
Annotations
@AutoService:AutoValueExtension
Static Imports
com.google.auto.common.MoreElements.getLocalAndInheritedMethods, .MoreStreams.toImmutableList, .MoreTypes.asTypeElement, com.google.auto.value.extension.toprettystring.processor.ExtensionClassTypeSpecBuilder.extensionClassTypeSpecBuilder, .ToPrettyStringMethods.toPrettyStringMethod, .ToPrettyStringMethods.toPrettyStringMethods, com.google.common.collect.Iterables.getLast, .Iterables.getOnlyElement, .Sets.intersection, com.squareup.javapoet.MethodSpec.methodBuilder, javax.lang.model.element.Modifier.FINAL, javax.lang.model.element.Modifier.PRIVATE, javax.lang.model.element.Modifier.PROTECTED, javax.lang.model.element.Modifier.PUBLIC, javax.lang.model.element.Modifier.STATIC

Generates implementations of com.google.auto.value.extension.toprettystring.ToPrettyString annotated methods in com.google.auto.value.AutoValue types.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static enum
private static class

Field Summary

Modifier and TypeField and Description
private static final String
private static final String
private static final ImmutableSet<javax.lang.model.element.Modifier>
private static final CodeBlock

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
applicable(AutoValueExtension.Context
The Context of the code generation for this class.
context
)

Overrides com.google.auto.value.extension.AutoValueExtension.applicable.

Determines whether this Extension applies to the given context.

public ImmutableSet<javax.lang.model.element.ExecutableElement>
consumeMethods(AutoValueExtension.Context
the Context of the code generation for this class.
context
)

Overrides com.google.auto.value.extension.AutoValueExtension.consumeMethods.

Returns a possible empty set of abstract methods that this Extension intends to implement.

public String
generateClass(AutoValueExtension.Context
The Context of the code generation for this class.
context
,
String
The simple name of the resulting class. The returned code will be written to a file named accordingly.
className
,
String
The simple name of the direct parent of the generated class. This could be the AutoValue generated class, or a class generated as the result of another Extension.
classToExtend
,
boolean
True if this class is the last class in the chain, meaning it should be marked as final. Otherwise it should be marked as abstract.
isFinal
)

Implements abstract com.google.auto.value.extension.AutoValueExtension.generateClass.

Returns the generated source code of the class named className to extend classToExtend, or null if this extension does not generate a class in the hierarchy.

public AutoValueExtension.IncrementalExtensionType
incrementalType(javax.annotation.processing.ProcessingEnvironment processingEnvironment)

Overrides com.google.auto.value.extension.AutoValueExtension.incrementalType.

Determines the incremental type of this Extension.

private static MethodSpec
private ImmutableList<MethodSpec>
Inherited from com.google.auto.value.extension.AutoValueExtension:
consumePropertiesgetSupportedOptionsmustBeFinal

Field Detail

INDENTback to summary
private static final String INDENT
INDENT_METHOD_NAMEback to summary
private static final String INDENT_METHOD_NAME
INHERITED_VISIBILITY_MODIFIERSback to summary
private static final ImmutableSet<javax.lang.model.element.Modifier> INHERITED_VISIBILITY_MODIFIERS
KEY_VALUE_SEPARATORback to summary
private static final CodeBlock KEY_VALUE_SEPARATOR

Constructor Detail

ToPrettyStringExtensionback to summary
public ToPrettyStringExtension()

Method Detail

applicableback to summary
public boolean applicable(AutoValueExtension.Context context)

Overrides com.google.auto.value.extension.AutoValueExtension.applicable.

Doc from com.google.auto.value.extension.AutoValueExtension.applicable.

Determines whether this Extension applies to the given context. If an Extension returns false for a given class, it will not be called again during the processing of that class. An Extension can return true and still choose not to generate any code for the class, by returning null from generateClass. That is often a more flexible approach.

Parameters
context:AutoValueExtension.Context

The Context of the code generation for this class.

Annotations
@Override
consumeMethodsback to summary
public ImmutableSet<javax.lang.model.element.ExecutableElement> consumeMethods(AutoValueExtension.Context context)

Overrides com.google.auto.value.extension.AutoValueExtension.consumeMethods.

Doc from com.google.auto.value.extension.AutoValueExtension.consumeMethods.

Returns a possible empty set of abstract methods that this Extension intends to implement. This will prevent AutoValue from generating an implementation, in cases where it would have, and it will also avoid warnings about abstract methods that AutoValue doesn't expect. The default set returned by this method is empty.

Each returned method must be one of the abstract methods in Context#abstractMethods().

For example, Android's Parcelable interface includes a method void writeToParcel(Parcel, int). Normally AutoValue would not know what to do with that abstract method. But an AutoValueExtension that understands Parcelable can provide a useful implementation and return the writeToParcel method here. That will prevent a warning about the method from AutoValue.

Parameters
context:AutoValueExtension.Context

the Context of the code generation for this class.

Annotations
@Override
generateClassback to summary
public String generateClass(AutoValueExtension.Context context, String className, String classToExtend, boolean isFinal)

Implements abstract com.google.auto.value.extension.AutoValueExtension.generateClass.

Doc from com.google.auto.value.extension.AutoValueExtension.generateClass.

Returns the generated source code of the class named className to extend classToExtend, or null if this extension does not generate a class in the hierarchy. If there is a generated class, it should be final if isFinal is true; otherwise it should be abstract. The returned string should be a complete Java class definition of the class className in the package context.packageName().

The returned string will typically look like this:

package <package>;
...
<finalOrAbstract> class <className> extends <classToExtend> {
  // Constructor
  <className>(<constructorParameters>) {
    super(<constructorParameterNames>);
    ...
  }
  ...
}

Here, <package> is Context#packageName(); <finalOrAbstract> is the keyword final if isFinal is true or abstract otherwise; and <className> and <classToExtend> are the values of this method's parameters of the same name. The <constructorParameters> and <constructorParameterNames> are typically derived from Context#propertyTypes().

Parameters
context:AutoValueExtension.Context

The Context of the code generation for this class.

className:String

The simple name of the resulting class. The returned code will be written to a file named accordingly.

classToExtend:String

The simple name of the direct parent of the generated class. This could be the AutoValue generated class, or a class generated as the result of another Extension.

isFinal:boolean

True if this class is the last class in the chain, meaning it should be marked as final. Otherwise it should be marked as abstract.

Returns:String

The source code of the generated class, or null if this extension does not generate a class in the hierarchy.

Annotations
@Override
incrementalTypeback to summary
public AutoValueExtension.IncrementalExtensionType incrementalType(javax.annotation.processing.ProcessingEnvironment processingEnvironment)

Overrides com.google.auto.value.extension.AutoValueExtension.incrementalType.

Doc from com.google.auto.value.extension.AutoValueExtension.incrementalType.

Determines the incremental type of this Extension.

The ProcessingEnvironment can be used, among other things, to obtain the processor options, using ProcessingEnvironment#getOptions().

The actual incremental type of the AutoValue processor as a whole will be the loosest incremental types of the Extensions present in the annotation processor path. The default returned value is IncrementalExtensionType#UNKNOWN, which will disable incremental annotation processing entirely.

Annotations
@Override
indentMethodback to summary
private static MethodSpec indentMethod()
toPrettyStringMethodSpecsback to summary
private ImmutableList<MethodSpec> toPrettyStringMethodSpecs(AutoValueExtension.Context context)
com.google.auto.value.extension.toprettystring.processor back to summary

pack-priv final Enum ToPrettyStringExtension.PrettyPrintableKind

extends Enum<ToPrettyStringExtension.PrettyPrintableKind>
Class Inheritance

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class

Field Summary

Modifier and TypeField and Description
public static final ToPrettyStringExtension.PrettyPrintableKind
public static final ToPrettyStringExtension.PrettyPrintableKind
public static final ToPrettyStringExtension.PrettyPrintableKind
public static final ToPrettyStringExtension.PrettyPrintableKind
public static final ToPrettyStringExtension.PrettyPrintableKind
private static final ImmutableMap<String, ToPrettyStringExtension.PrettyPrintableKind>
private static final ImmutableMap<String, ToPrettyStringExtension.PrettyPrintableKind>
public static final ToPrettyStringExtension.PrettyPrintableKind
public static final ToPrettyStringExtension.PrettyPrintableKind
public static final ToPrettyStringExtension.PrettyPrintableKind
public static final ToPrettyStringExtension.PrettyPrintableKind
public static final ToPrettyStringExtension.PrettyPrintableKind

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static ToPrettyStringExtension.PrettyPrintableKind
public static ToPrettyStringExtension.PrettyPrintableKind[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

ARRAYback to summary
public static final ToPrettyStringExtension.PrettyPrintableKind ARRAY
COLLECTIONback to summary
public static final ToPrettyStringExtension.PrettyPrintableKind COLLECTION
GUAVA_OPTIONALback to summary
public static final ToPrettyStringExtension.PrettyPrintableKind GUAVA_OPTIONAL
HAS_TO_PRETTY_STRING_METHODback to summary
public static final ToPrettyStringExtension.PrettyPrintableKind HAS_TO_PRETTY_STRING_METHOD
IMMUTABLE_PRIMITIVE_ARRAYback to summary
public static final ToPrettyStringExtension.PrettyPrintableKind IMMUTABLE_PRIMITIVE_ARRAY
KINDS_BY_EXACT_TYPEback to summary
private static final ImmutableMap<String, ToPrettyStringExtension.PrettyPrintableKind> KINDS_BY_EXACT_TYPE
KINDS_BY_SUPERTYPEback to summary
private static final ImmutableMap<String, ToPrettyStringExtension.PrettyPrintableKind> KINDS_BY_SUPERTYPE
MAPback to summary
public static final ToPrettyStringExtension.PrettyPrintableKind MAP
MULTIMAPback to summary
public static final ToPrettyStringExtension.PrettyPrintableKind MULTIMAP
OPTIONALback to summary
public static final ToPrettyStringExtension.PrettyPrintableKind OPTIONAL
PRIMITIVEback to summary
public static final ToPrettyStringExtension.PrettyPrintableKind PRIMITIVE
REGULAR_OBJECTback to summary
public static final ToPrettyStringExtension.PrettyPrintableKind REGULAR_OBJECT

Constructor Detail

PrettyPrintableKindback to summary
private PrettyPrintableKind()

Method Detail

valueOfback to summary
public static ToPrettyStringExtension.PrettyPrintableKind valueOf(String name)
valuesback to summary
public static ToPrettyStringExtension.PrettyPrintableKind[] values()
com.google.auto.value.extension.toprettystring.processor back to summary

pack-priv Class ToPrettyStringExtension.PrettyPrintableKind.KindVisitor

extends javax.lang.model.util.SimpleTypeVisitor8
Class Inheritance
  • java.lang.Object
  • ⋱
  • javax.lang.model.util.SimpleTypeVisitor8
  • com.google.auto.value.extension.toprettystring.processor.ToPrettyStringExtension.PrettyPrintableKind.KindVisitor

Field Summary

Modifier and TypeField and Description
private final javax.lang.model.util.Elements
private final javax.lang.model.util.Types

Constructor Summary

AccessConstructor and Description
pack-priv
KindVisitor(javax.lang.model.util.Types types, javax.lang.model.util.Elements elements)

Method Summary

Modifier and TypeMethod and Description
public ToPrettyStringExtension.PrettyPrintableKind
visitArray(javax.lang.model.type.ArrayType arrayType, Void v)

public ToPrettyStringExtension.PrettyPrintableKind
visitDeclared(javax.lang.model.type.DeclaredType declaredType, Void v)

public ToPrettyStringExtension.PrettyPrintableKind
visitPrimitive(javax.lang.model.type.PrimitiveType primitiveType, Void v)

Field Detail

elementsback to summary
private final javax.lang.model.util.Elements elements
typesback to summary
private final javax.lang.model.util.Types types

Constructor Detail

KindVisitorback to summary
pack-priv KindVisitor(javax.lang.model.util.Types types, javax.lang.model.util.Elements elements)

Method Detail

visitArrayback to summary
public ToPrettyStringExtension.PrettyPrintableKind visitArray(javax.lang.model.type.ArrayType arrayType, Void v)
Annotations
@Override
visitDeclaredback to summary
public ToPrettyStringExtension.PrettyPrintableKind visitDeclared(javax.lang.model.type.DeclaredType declaredType, Void v)
Annotations
@Override
visitPrimitiveback to summary
public ToPrettyStringExtension.PrettyPrintableKind visitPrimitive(javax.lang.model.type.PrimitiveType primitiveType, Void v)
Annotations
@Override
com.google.auto.value.extension.toprettystring.processor back to summary

private Class ToPrettyStringExtension.ToPrettyStringImplementation

extends Object
Class Inheritance
  • java.lang.Object
  • com.google.auto.value.extension.toprettystring.processor.ToPrettyStringExtension.ToPrettyStringImplementation

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
ToPrettyStringExtension.ToPrettyStringImplementation.DelegateMethod

Parameter object to simplify the branches of format(CodeBlock, CodeBlock, TypeMirror) that call a delegate method.

Field Summary

Modifier and TypeField and Description
private final Map<Equivalence.Wrapper<javax.lang.model.type.TypeMirror>, MethodSpec>
private final javax.lang.model.util.Elements
private final Set<String>
private final CodeBlock.Builder
private final javax.lang.model.util.Types

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private javax.lang.model.type.DeclaredType
collectionOf(javax.lang.model.type.TypeMirror elementType)

pack-priv static ToPrettyStringExtension.ToPrettyStringImplementation
private CodeBlock
forEachLoopMethodBody(javax.lang.model.type.TypeMirror elementType)

private CodeBlock
forEachMapEntryMethodBody(javax.lang.model.type.TypeMirror keyType, javax.lang.model.type.TypeMirror valueType, String propertyAccess)

private CodeBlock
private CodeBlock
format(CodeBlock
a reference to the variable that should be formatted.
propertyAccess
,
CodeBlock
a reference to an int representing how many indent levels should be used for this property.
indentAccess
,
javax.lang.model.type.TypeMirror
the type of the propertyAccess.
type
)

Returns propertyAccess formatted for use within the com.google.auto.value.extension.toprettystring.ToPrettyString implementation.

private CodeBlock
formatMap(javax.lang.model.type.TypeMirror type, ToPrettyStringExtension.ToPrettyStringImplementation.DelegateMethod delegateMethod)

private CodeBlock
formatMultimap(javax.lang.model.type.TypeMirror type, ToPrettyStringExtension.ToPrettyStringImplementation.DelegateMethod delegateMethod)

pack-priv boolean
isMapOrMultimap(javax.lang.model.type.TypeMirror type)

private CodeBlock
loopMethodBody(String openSymbol, String closeSymbol, CodeBlock loopDeclaration, CodeBlock... appendedValues)

private CodeBlock
mapMethodBody(javax.lang.model.type.TypeMirror keyType, javax.lang.model.type.TypeMirror valueType)

private javax.lang.model.type.DeclaredType
mapOf(javax.lang.model.type.TypeMirror keyType, javax.lang.model.type.TypeMirror valueType)

private CodeBlock
multimapMethodBody(javax.lang.model.type.TypeMirror keyType, javax.lang.model.type.TypeMirror valueType)

private javax.lang.model.type.DeclaredType
multimapOf(javax.lang.model.type.TypeMirror keyType, javax.lang.model.type.TypeMirror valueType)

private String
nameForType(javax.lang.model.type.TypeMirror type)

Returns a valid Java identifier for method or variable of type type.

private CodeBlock
optionalMethodBody(javax.lang.model.type.TypeMirror optionalType, ToPrettyStringExtension.PrettyPrintableKind printableKind)

private CodeBlock
reindent(CharSequence methodName)

private ImmutableList<javax.lang.model.type.TypeMirror>
resolvedTypeParameters(javax.lang.model.type.TypeMirror propertyType, String interfaceName)

private String
simpleNameForType(javax.lang.model.type.TypeMirror type)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

delegateMethodsback to summary
private final Map<Equivalence.Wrapper<javax.lang.model.type.TypeMirror>, MethodSpec> delegateMethods
elementsback to summary
private final javax.lang.model.util.Elements elements
methodNamesback to summary
private final Set<String> methodNames
toStringCodeBlockback to summary
private final CodeBlock.Builder toStringCodeBlock
typesback to summary
private final javax.lang.model.util.Types types

Constructor Detail

ToPrettyStringImplementationback to summary
private ToPrettyStringImplementation(AutoValueExtension.Context context)

Method Detail

collectionOfback to summary
private javax.lang.model.type.DeclaredType collectionOf(javax.lang.model.type.TypeMirror elementType)
createback to summary
pack-priv static ToPrettyStringExtension.ToPrettyStringImplementation create(AutoValueExtension.Context context)
forEachLoopMethodBodyback to summary
private CodeBlock forEachLoopMethodBody(javax.lang.model.type.TypeMirror elementType)
forEachMapEntryMethodBodyback to summary
private CodeBlock forEachMapEntryMethodBody(javax.lang.model.type.TypeMirror keyType, javax.lang.model.type.TypeMirror valueType, String propertyAccess)
forLoopMethodBodyback to summary
private CodeBlock forLoopMethodBody()
formatback to summary
private CodeBlock format(CodeBlock propertyAccess, CodeBlock indentAccess, javax.lang.model.type.TypeMirror type)

Returns propertyAccess formatted for use within the com.google.auto.value.extension.toprettystring.ToPrettyString implementation.

If a helper method is necessary for formatting, a MethodSpec will be added to delegateMethods.

Parameters
propertyAccess:CodeBlock

a reference to the variable that should be formatted.

indentAccess:CodeBlock

a reference to an int representing how many indent levels should be used for this property.

type:javax.lang.model.type.TypeMirror

the type of the propertyAccess.

formatMapback to summary
private CodeBlock formatMap(javax.lang.model.type.TypeMirror type, ToPrettyStringExtension.ToPrettyStringImplementation.DelegateMethod delegateMethod)
formatMultimapback to summary
private CodeBlock formatMultimap(javax.lang.model.type.TypeMirror type, ToPrettyStringExtension.ToPrettyStringImplementation.DelegateMethod delegateMethod)
isMapOrMultimapback to summary
pack-priv boolean isMapOrMultimap(javax.lang.model.type.TypeMirror type)
loopMethodBodyback to summary
private CodeBlock loopMethodBody(String openSymbol, String closeSymbol, CodeBlock loopDeclaration, CodeBlock... appendedValues)
mapMethodBodyback to summary
private CodeBlock mapMethodBody(javax.lang.model.type.TypeMirror keyType, javax.lang.model.type.TypeMirror valueType)
mapOfback to summary
private javax.lang.model.type.DeclaredType mapOf(javax.lang.model.type.TypeMirror keyType, javax.lang.model.type.TypeMirror valueType)
multimapMethodBodyback to summary
private CodeBlock multimapMethodBody(javax.lang.model.type.TypeMirror keyType, javax.lang.model.type.TypeMirror valueType)
multimapOfback to summary
private javax.lang.model.type.DeclaredType multimapOf(javax.lang.model.type.TypeMirror keyType, javax.lang.model.type.TypeMirror valueType)
nameForTypeback to summary
private String nameForType(javax.lang.model.type.TypeMirror type)

Returns a valid Java identifier for method or variable of type type.

optionalMethodBodyback to summary
private CodeBlock optionalMethodBody(javax.lang.model.type.TypeMirror optionalType, ToPrettyStringExtension.PrettyPrintableKind printableKind)
reindentback to summary
private CodeBlock reindent(CharSequence methodName)
resolvedTypeParametersback to summary
private ImmutableList<javax.lang.model.type.TypeMirror> resolvedTypeParameters(javax.lang.model.type.TypeMirror propertyType, String interfaceName)
simpleNameForTypeback to summary
private String simpleNameForType(javax.lang.model.type.TypeMirror type)
com.google.auto.value.extension.toprettystring.processor back to summary

private Class ToPrettyStringExtension.ToPrettyStringImplementation.DelegateMethod

extends Object
Class Inheritance
  • java.lang.Object
  • com.google.auto.value.extension.toprettystring.processor.ToPrettyStringExtension.ToPrettyStringImplementation.DelegateMethod

Parameter object to simplify the branches of format(CodeBlock, CodeBlock, TypeMirror) that call a delegate method.

Field Summary

Modifier and TypeField and Description
private final CodeBlock
private Optional<String>
private final CodeBlock

Constructor Summary

AccessConstructor and Description
pack-priv
DelegateMethod(CodeBlock propertyAccess, CodeBlock indentAccess)

Method Summary

Modifier and TypeMethod and Description
private MethodSpec
createMethod(String methodName, javax.lang.model.type.TypeMirror type, Supplier<CodeBlock> methodBody)

pack-priv CodeBlock
invocation(javax.lang.model.type.TypeMirror parameterType, Supplier<CodeBlock> methodBody)

pack-priv ToPrettyStringExtension.ToPrettyStringImplementation.DelegateMethod
methodName(String methodName)

private String
newDelegateMethodName(javax.lang.model.type.TypeMirror type)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

indentAccessback to summary
private final CodeBlock indentAccess
methodNameback to summary
private Optional<String> methodName
propertyAccessback to summary
private final CodeBlock propertyAccess

Constructor Detail

DelegateMethodback to summary
pack-priv DelegateMethod(CodeBlock propertyAccess, CodeBlock indentAccess)

Method Detail

createMethodback to summary
private MethodSpec createMethod(String methodName, javax.lang.model.type.TypeMirror type, Supplier<CodeBlock> methodBody)
invocationback to summary
pack-priv CodeBlock invocation(javax.lang.model.type.TypeMirror parameterType, Supplier<CodeBlock> methodBody)
methodNameback to summary
pack-priv ToPrettyStringExtension.ToPrettyStringImplementation.DelegateMethod methodName(String methodName)
newDelegateMethodNameback to summary
private String newDelegateMethodName(javax.lang.model.type.TypeMirror type)