Top Description Fields Constructors Methods
com.google.auto.value.processor

public Class AutoBuilderProcessor

extends AutoValueishProcessor
Class Inheritance
Annotations
@AutoService:javax.annotation.processing.Processor
@javax.annotation.processing.SupportedAnnotationTypes
@IncrementalAnnotationProcessor:ISOLATING
Static Imports
com.google.auto.common.GeneratedAnnotations.generatedAnnotation, .MoreElements.getLocalAndInheritedMethods, .MoreElements.getPackage, .MoreStreams.toImmutableList, .MoreStreams.toImmutableMap, .MoreStreams.toImmutableSet, .MoreTypes.asTypeElement, com.google.auto.value.processor.AutoValueProcessor.OMIT_IDENTIFIERS_OPTION, .ClassNames.AUTO_ANNOTATION_NAME, .ClassNames.AUTO_BUILDER_NAME, .ClassNames.KOTLIN_METADATA_NAME, java.util.stream.Collectors.joining, .Collectors.toMap, javax.lang.model.util.ElementFilter.constructorsIn, javax.lang.model.util.ElementFilter.methodsIn

Javac annotation processor (compiler plugin) for builders; user code never references this class.
Author
Éamonn McManus
See Also
AutoValue User's Guide

Field Summary

Modifier and TypeField and Description
private static final String
private static final String
private static final javax.lang.model.element.ElementKind
private javax.lang.model.type.TypeMirror

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private static AutoValueishProcessor.Property
annotationBuilderProperty(javax.lang.model.element.ExecutableElement annotationMethod, Nullables nullables)

private ImmutableSet<AutoValueishProcessor.Property>
annotationBuilderPropertySet(javax.lang.model.element.TypeElement annotationType)

private void
buildAnnotation(javax.lang.model.element.TypeElement autoBuilderType, javax.lang.model.element.TypeElement annotationType, String callMethod)

private static javax.lang.model.element.ElementKind
private String
private boolean
executableMatches(Executable executable, ImmutableSet<javax.lang.model.element.ExecutableElement> methodsInAutoBuilderType)

private String
findCallMethodValue(javax.lang.model.element.AnnotationMirror autoBuilderAnnotation)

private Executable
findExecutable(javax.lang.model.element.TypeElement ofClass, String callMethod, javax.lang.model.element.TypeElement autoBuilderType, ImmutableSet<javax.lang.model.element.ExecutableElement> methodsInAutoBuilderType)

private javax.lang.model.element.TypeElement
findOfClassValue(javax.lang.model.element.AnnotationMirror autoBuilderAnnotation)

private ImmutableList<Executable>
findRelevantExecutables(javax.lang.model.element.TypeElement ofClass, String callMethod, javax.lang.model.element.TypeElement autoBuilderType)

private void
generateForwardingClass(String forwardingClassName, Executable executable, javax.lang.model.type.TypeMirror builtType, javax.lang.model.element.TypeElement autoBuilderType)

Generates a class that will call the synthetic Kotlin constructor that is used to specify which optional parameters are defaulted.

private javax.lang.model.element.TypeElement
getOfClass(javax.lang.model.element.TypeElement autoBuilderType, javax.lang.model.element.AnnotationMirror autoBuilderAnnotation)

public Set<String>
public synchronized void
init(javax.annotation.processing.ProcessingEnvironment processingEnv)

Overrides com.google.auto.value.processor.AutoValueishProcessor.init.

private static int[]
intArrayValue(javax.lang.model.element.AnnotationValue value)

private ImmutableList<Executable>
kotlinConstructorsIn(javax.lang.model.element.AnnotationMirror metadata, javax.lang.model.element.TypeElement ofClass)

Use Kotlin reflection to build Executable instances for the constructors in ofClass that include information about which parameters have default values.

private Optional<javax.lang.model.element.AnnotationMirror>
kotlinMetadataAnnotation(javax.lang.model.element.Element element)

private Executable
matchingExecutable(javax.lang.model.element.TypeElement autoBuilderType, List<Executable> executables, ImmutableSet<javax.lang.model.element.ExecutableElement> methodsInAutoBuilderType, String description)

private Optional<String>
maybeForwardingClass(javax.lang.model.element.TypeElement autoBuilderType, Executable executable)

private AutoValueishProcessor.Property
newProperty(javax.lang.model.element.VariableElement var, String identifier, String getterName, Optional<String> builderInitializer, boolean hasDefault, Nullables nullables)

pack-priv Optional<String>
nullableAnnotationForMethod(javax.lang.model.element.ExecutableElement propertyMethod)

Implements abstract com.google.auto.value.processor.AutoValueishProcessor.nullableAnnotationForMethod.

Returns the appropriate @Nullable annotation to put on the implementation of the given property method, and indicates whether the property is in fact nullable.

private static ImmutableSet<String>
parameterNames(javax.lang.model.element.ExecutableElement executableElement)

pack-priv void
processType(javax.lang.model.element.TypeElement
the class with the @AutoValue or @AutoOneOf annotation.
autoBuilderType
)

Implements abstract com.google.auto.value.processor.AutoValueishProcessor.processType.

Analyzes a single @AutoValue (etc) class, and outputs the corresponding implementation class or classes.

private void
processType(javax.lang.model.element.TypeElement autoBuilderType, javax.lang.model.element.TypeElement ofClass, String callMethod)

private ImmutableMap<String, String>
propertyInitializers(javax.lang.model.element.TypeElement autoBuilderType, Executable executable)

private ImmutableSet<AutoValueishProcessor.Property>
propertySet(Executable executable, Map<String, String> propertyToGetterName, ImmutableMap<String, String> builderInitializers, Nullables nullables)

private ImmutableMap<String, String>
propertyToGetterName(Executable executable, javax.lang.model.element.TypeElement autoBuilderType)

Returns a map from property names to the corresponding getters in the built type.

private static String[]
stringArrayValue(javax.lang.model.element.AnnotationValue value)

private boolean
visibleFrom(javax.lang.model.element.Element element, javax.lang.model.element.PackageElement fromPackage)

Inherited from com.google.auto.value.processor.AutoValueishProcessor:
abstractMethodsInaddDeferredTypeannotationsToCopyannotationStringscheckModifiersIfNestedcheckModifiersIfNestedcheckReturnTypecopiedClassAnnotationscopyAnnotationsdeferredTypeNamesdefineSharedVarsForTypeelementUtilsequalsParameterTypeerrorReporterfixReservedIdentifiersgeneratedClassNamegetAnnotationMirrorgetAnnotationsMarkedWithInheritedgetExcludedAnnotationClassNamesgetSerialVersionUIDgetSupportedSourceVersionhasAnnotationMirrorhasVisibleNoArgConstructorisPrefixedGetternameWithoutPrefixnullableAnnotationForobjectMethodToOverrideprefixedGettersInprocesspropertiesCanBeVoidpropertyFieldAnnotationMappropertyMethodAnnotationMappropertyMethodAnnotationspropertyMethodsInpropertyNameToMethodMappropertySettypeUtilswriteSourceFile

Field Detail

ALLOW_OPTIONback to summary
private static final String ALLOW_OPTION
AUTO_ANNOTATION_CLASS_PREFIXback to summary
private static final String AUTO_ANNOTATION_CLASS_PREFIX
ELEMENT_KIND_RECORDback to summary
private static final javax.lang.model.element.ElementKind ELEMENT_KIND_RECORD
javaLangVoidback to summary
private javax.lang.model.type.TypeMirror javaLangVoid

Constructor Detail

AutoBuilderProcessorback to summary
public AutoBuilderProcessor()

Method Detail

annotationBuilderPropertyback to summary
private static AutoValueishProcessor.Property annotationBuilderProperty(javax.lang.model.element.ExecutableElement annotationMethod, Nullables nullables)
annotationBuilderPropertySetback to summary
private ImmutableSet<AutoValueishProcessor.Property> annotationBuilderPropertySet(javax.lang.model.element.TypeElement annotationType)
buildAnnotationback to summary
private void buildAnnotation(javax.lang.model.element.TypeElement autoBuilderType, javax.lang.model.element.TypeElement annotationType, String callMethod)
elementKindRecordback to summary
private static javax.lang.model.element.ElementKind elementKindRecord()
executableListStringback to summary
private String executableListString(List<Executable> executables)
executableMatchesback to summary
private boolean executableMatches(Executable executable, ImmutableSet<javax.lang.model.element.ExecutableElement> methodsInAutoBuilderType)
findCallMethodValueback to summary
private String findCallMethodValue(javax.lang.model.element.AnnotationMirror autoBuilderAnnotation)
findExecutableback to summary
private Executable findExecutable(javax.lang.model.element.TypeElement ofClass, String callMethod, javax.lang.model.element.TypeElement autoBuilderType, ImmutableSet<javax.lang.model.element.ExecutableElement> methodsInAutoBuilderType)
findOfClassValueback to summary
private javax.lang.model.element.TypeElement findOfClassValue(javax.lang.model.element.AnnotationMirror autoBuilderAnnotation)
findRelevantExecutablesback to summary
private ImmutableList<Executable> findRelevantExecutables(javax.lang.model.element.TypeElement ofClass, String callMethod, javax.lang.model.element.TypeElement autoBuilderType)
generateForwardingClassback to summary
private void generateForwardingClass(String forwardingClassName, Executable executable, javax.lang.model.type.TypeMirror builtType, javax.lang.model.element.TypeElement autoBuilderType)

Generates a class that will call the synthetic Kotlin constructor that is used to specify which optional parameters are defaulted. Because it is synthetic, it can't be called from Java source code. Instead, Java source code calls the of method in the class we generate here.

getOfClassback to summary
private javax.lang.model.element.TypeElement getOfClass(javax.lang.model.element.TypeElement autoBuilderType, javax.lang.model.element.AnnotationMirror autoBuilderAnnotation)
getSupportedOptionsback to summary
public Set<String> getSupportedOptions()
Annotations
@Override
initback to summary
public synchronized void init(javax.annotation.processing.ProcessingEnvironment processingEnv)

Overrides com.google.auto.value.processor.AutoValueishProcessor.init.

Annotations
@Override
intArrayValueback to summary
private static int[] intArrayValue(javax.lang.model.element.AnnotationValue value)
kotlinConstructorsInback to summary
private ImmutableList<Executable> kotlinConstructorsIn(javax.lang.model.element.AnnotationMirror metadata, javax.lang.model.element.TypeElement ofClass)

Use Kotlin reflection to build Executable instances for the constructors in ofClass that include information about which parameters have default values.

kotlinMetadataAnnotationback to summary
private Optional<javax.lang.model.element.AnnotationMirror> kotlinMetadataAnnotation(javax.lang.model.element.Element element)
matchingExecutableback to summary
private Executable matchingExecutable(javax.lang.model.element.TypeElement autoBuilderType, List<Executable> executables, ImmutableSet<javax.lang.model.element.ExecutableElement> methodsInAutoBuilderType, String description)
maybeForwardingClassback to summary
private Optional<String> maybeForwardingClass(javax.lang.model.element.TypeElement autoBuilderType, Executable executable)
newPropertyback to summary
private AutoValueishProcessor.Property newProperty(javax.lang.model.element.VariableElement var, String identifier, String getterName, Optional<String> builderInitializer, boolean hasDefault, Nullables nullables)
nullableAnnotationForMethodback to summary
pack-priv Optional<String> nullableAnnotationForMethod(javax.lang.model.element.ExecutableElement propertyMethod)

Implements abstract com.google.auto.value.processor.AutoValueishProcessor.nullableAnnotationForMethod.

Doc from com.google.auto.value.processor.AutoValueishProcessor.nullableAnnotationForMethod.

Returns the appropriate @Nullable annotation to put on the implementation of the given property method, and indicates whether the property is in fact nullable. The annotation in question is on the method, not its return type. If instead the return type is @Nullable, this method returns Optional.of(""), to indicate that the property is nullable but the method isn't. The @Nullable annotation will instead appear when the return type of the method is spelled out in the implementation.

Annotations
@Override
parameterNamesback to summary
private static ImmutableSet<String> parameterNames(javax.lang.model.element.ExecutableElement executableElement)
processTypeback to summary
pack-priv void processType(javax.lang.model.element.TypeElement autoBuilderType)

Implements abstract com.google.auto.value.processor.AutoValueishProcessor.processType.

Doc from com.google.auto.value.processor.AutoValueishProcessor.processType.

Analyzes a single @AutoValue (etc) class, and outputs the corresponding implementation class or classes.

Parameters
autoBuilderType:javax.lang.model.element.TypeElement

the class with the @AutoValue or @AutoOneOf annotation.

Annotations
@Override
processTypeback to summary
private void processType(javax.lang.model.element.TypeElement autoBuilderType, javax.lang.model.element.TypeElement ofClass, String callMethod)
propertyInitializersback to summary
private ImmutableMap<String, String> propertyInitializers(javax.lang.model.element.TypeElement autoBuilderType, Executable executable)
propertySetback to summary
private ImmutableSet<AutoValueishProcessor.Property> propertySet(Executable executable, Map<String, String> propertyToGetterName, ImmutableMap<String, String> builderInitializers, Nullables nullables)
propertyToGetterNameback to summary
private ImmutableMap<String, String> propertyToGetterName(Executable executable, javax.lang.model.element.TypeElement autoBuilderType)

Returns a map from property names to the corresponding getters in the built type. The built type is the return type of the given executable, and the property names are the names of its parameters. If the return type is a DeclaredType Foo and if every property name bar matches a method bar() or getBar() in Foo, then the method returns a map where bar maps to bar or getBar. If these conditions are not met then the method returns an empty map.

The method name match is case-insensitive, so we will also accept baR() or getbar(). For a property of type boolean, we also accept isBar() (or isbar() etc).

The return type of each getter method must match the type of the corresponding parameter exactly. This will always be true for our principal use cases, Java records and Kotlin data classes. For other use cases, we may in the future accept getters where we know how to convert, for example if the getter has type ImmutableList<Baz> and the parameter has type Baz[]. We already have similar logic for the parameter types of builder setters.

stringArrayValueback to summary
private static String[] stringArrayValue(javax.lang.model.element.AnnotationValue value)
visibleFromback to summary
private boolean visibleFrom(javax.lang.model.element.Element element, javax.lang.model.element.PackageElement fromPackage)