public abstract class BuilderRequiredProperties extends Object
Every property in an @AutoValue or @AutoBuilder builder must be set before the
build() method is called, with a few exceptions like @Nullable and Optional properties. That means we must keep track of which ones have in fact been set. We do
that in two ways: for reference (non-primitive) types, we use null to indicate that the
value has not been set, while for primitive types we use a bitmask where each bit indicates
whether a certain primitive property has been set.
Additionally, for Kotlin constructors with default parameters, we track exactly which properties have been set so we can invoke the constructor thas has a bitmask indicating the properties to be defaulted.
The public methods in this class are accessed reflectively from the builder.vm
template. In that template, $builderRequiredProperties references an instance of this
class corresponding to the builder being generated. A reference like $builderRequiredProperties.markAsSet($p) calls the method markAsSet(com.google.auto.value.processor.AutoValueishProcessor.Property) with the given
parameter. A reference like $builderRequiredProperties.requiredProperties is shorthand
for $builderRequiredProperties.getProperties().
| Modifier and Type | Method and Description |
|---|---|
abstract String |
getAnyMissing()
Returns an expression that is true if any required properties have not been set.
|
abstract String |
getDefaultedBitmaskParameters()
Returns additional constructor parameters to indicate what properties have been defaulted, or
an empty string if there are none.
|
com.google.common.collect.ImmutableList<String> |
getFieldDeclarations()
Returns code to declare any fields needed to track which properties have been set.
|
com.google.common.collect.ImmutableList<String> |
getInitToAllSet()
Returns code to indicate that all tracked properties have received a value.
|
com.google.common.collect.ImmutableSet<AutoValueishProcessor.Property> |
getRequiredProperties() |
String |
markAsSet(AutoValueishProcessor.Property p)
Returns code to indicate that the given property has been set, if assigning to the property
field is not enough.
|
String |
missingRequiredProperty(AutoValueishProcessor.Property p)
Returns an expression that is true if the given property is required but has not been set.
|
String |
noValueToGet(AutoValueishProcessor.Property p)
Returns an expression that is true if the given property has not been given a value.
|
public com.google.common.collect.ImmutableSet<AutoValueishProcessor.Property> getRequiredProperties()
public com.google.common.collect.ImmutableList<String> getFieldDeclarations()
public com.google.common.collect.ImmutableList<String> getInitToAllSet()
toBuilder() constructor, since it assigns to the corresponding fields directly
without going through their setters.public String markAsSet(AutoValueishProcessor.Property p)
public String missingRequiredProperty(AutoValueishProcessor.Property p)
public String noValueToGet(AutoValueishProcessor.Property p)
missingRequiredProperty(com.google.auto.value.processor.AutoValueishProcessor.Property) if the property has a Kotlin default. If
so, we don't require it to be set at build time (because Kotlin will supply the default), but
we do require it to be set if it is accessed with a getter on the builder. We don't have access
to Kotlin parameter defaults so we can't arrange for the builder field to have the same default
value. Rather than returning a bogus zero value we say the value is unset.public abstract String getAnyMissing()
public abstract String getDefaultedBitmaskParameters()
Copyright © 2022 Google LLC. All rights reserved.