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 with the given
parameter. A reference like $builderRequiredProperties.requiredProperties is shorthand
for $builderRequiredProperties..
| Modifier and Type | Class and Description |
|---|---|
| private static class | BuilderRequiredProperties.
Represents a field in which we will record which tracked properties from a certain set have been given a value. |
| private static class | BuilderRequiredProperties.
Subclass for when there are no Kotlin default properties. |
| private static class | BuilderRequiredProperties.
Subclass for when there are Kotlin default properties. |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv final ImmutableList | bitmaskFields
The integer fields that store the bitmask. |
| pack-priv static final BuilderRequiredProperties | |
| pack-priv final ImmutableSet | requiredProperties
All required properties. |
| pack-priv final ImmutableMap | trackedPropertyToIndex
The bit index for each tracked property. |
| Access | Constructor and Description |
|---|---|
| private | BuilderRequiredProperties(ImmutableSet<AutoValueishProcessor.
|
| Modifier and Type | Method and Description |
|---|---|
| pack-priv abstract String | allRequiredBitmask(ImmutableList<AutoValueishProcessor.
|
| private static String | |
| private static Class | classForBits(int bits)
The smallest primitive integer type that has at least this many bits, or |
| public abstract String | |
| public abstract String | getDefaultedBitmaskParameters()
Returns additional constructor parameters to indicate what properties have been defaulted, or an empty string if there are none. |
| public ImmutableList | getFieldDeclarations()
Returns code to declare any fields needed to track which properties have been set. |
| public ImmutableList | |
| public ImmutableSet | |
| pack-priv static String | |
| public String | markAsSet(AutoValueishProcessor.
Returns code to indicate that the given property has been set, if assigning to the property field is not enough. |
| public String | missingRequiredProperty(AutoValueishProcessor.
Returns an expression that is true if the given property is required but has not been set. |
| public String | noValueToGet(AutoValueishProcessor.
Returns an expression that is true if the given property has not been given a value. |
| pack-priv static BuilderRequiredProperties | of(ImmutableSet<AutoValueishProcessor.
|
| private String |
| bitmaskFields | back to summary |
|---|---|
| pack-priv final ImmutableList<BuilderRequiredProperties. The integer fields that store the bitmask. In the usual case, where there are ≤32 tracked
properties, we can pack the bitmask into one integer field. Its type is the smallest one that
fits the required number of bits, for example If there are >32 tracked properties, we will pack them into as few integer fields
as possible. For example if there are 75 tracked properties (this can happen) then we will put
numbers 0 to 31 in an When there are >32 tracked properties, we could potentially pack them better if
we used | |
| EMPTY | back to summary |
|---|---|
| pack-priv static final BuilderRequiredProperties EMPTY | |
| requiredProperties | back to summary |
|---|---|
| pack-priv final ImmutableSet<AutoValueishProcessor. All required properties. | |
| trackedPropertyToIndex | back to summary |
|---|---|
| pack-priv final ImmutableMap<AutoValueishProcessor. The bit index for each tracked property. Properties are tracked if they are primitive, or if this is a Kotlin constructor with default parameters. Non-tracked properties do not appear in this map. | |
| BuilderRequiredProperties | back to summary |
|---|---|
| private BuilderRequiredProperties(ImmutableSet<AutoValueishProcessor. | |
| allRequiredBitmask | back to summary |
|---|---|
| pack-priv abstract String allRequiredBitmask(ImmutableList<AutoValueishProcessor. | |
| cast | back to summary |
|---|---|
| private static String cast(Class<?> type, String number) | |
| classForBits | back to summary |
|---|---|
| private static Class The smallest primitive integer type that has at least this many bits, or | |
| getAnyMissing | back to summary |
|---|---|
| public abstract String getAnyMissing() Returns an expression that is true if any required properties have not been set. Should not be called if there are no required properties. | |
| getDefaultedBitmaskParameters | back to summary |
|---|---|
| public abstract String getDefaultedBitmaskParameters() Returns additional constructor parameters to indicate what properties have been defaulted, or an empty string if there are none. | |
| getFieldDeclarations | back to summary |
|---|---|
| public ImmutableList Returns code to declare any fields needed to track which properties have been set. Each line in the returned list should appear on a line of its own. | |
| getInitToAllSet | back to summary |
|---|---|
| public ImmutableList Returns code to indicate that all tracked properties have received a value. This is needed in
the | |
| getRequiredProperties | back to summary |
|---|---|
| public ImmutableSet | |
| hex | back to summary |
|---|---|
pack-priv static String hex(int number)
| |
| markAsSet | back to summary |
|---|---|
| public String markAsSet(AutoValueishProcessor. Returns code to indicate that the given property has been set, if assigning to the property field is not enough. For reference (non-primitive) properties, assignment is enough, but for primitive properties we also need to set a bit in the bitmask. | |
| missingRequiredProperty | back to summary |
|---|---|
| public String missingRequiredProperty(AutoValueishProcessor. Returns an expression that is true if the given property is required but has not been set. Returns null if the property is not required. | |
| noValueToGet | back to summary |
|---|---|
| public String noValueToGet(AutoValueishProcessor. Returns an expression that is true if the given property has not been given a value. That's
only different from | |
| of | back to summary |
|---|---|
| pack-priv static BuilderRequiredProperties of(ImmutableSet<AutoValueishProcessor. | |
| propertyNotSet | back to summary |
|---|---|
| private String propertyNotSet(AutoValueishProcessor. | |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv final String | allRequiredBitmask
The source representation of the value this field has when all required properties have been given a value. |
| pack-priv final String | allSetBitmask
The source representation of the value this field has when all properties have been given a value. |
| pack-priv final String | |
| pack-priv final Class |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| allRequiredBitmask | back to summary |
|---|---|
| pack-priv final String allRequiredBitmask The source representation of the value this field has when all required properties have been given a value. | |
| allSetBitmask | back to summary |
|---|---|
| pack-priv final String allSetBitmask The source representation of the value this field has when all properties have been given a value. | |
| name | back to summary |
|---|---|
| pack-priv final String name | |
| type | back to summary |
|---|---|
| pack-priv final Class<?> type | |
| BitmaskField | back to summary |
|---|---|
| pack-priv BitmaskField(Class<?> type, String name, String allSetBitmask, String allRequiredBitmask) | |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv String | allRequiredBitmask(ImmutableList<AutoValueishProcessor.
Implements abstract com.
|
| public String | getAnyMissing()
Implements abstract com. Returns an expression that is true if any required properties have not been set. |
| public String | getDefaultedBitmaskParameters()
Implements abstract com. Returns additional constructor parameters to indicate what properties have been defaulted, or an empty string if there are none. |
| private static ImmutableList |
| NoDefaults | back to summary |
|---|---|
| pack-priv NoDefaults(ImmutableSet<AutoValueishProcessor. | |
| allRequiredBitmask | back to summary |
|---|---|
| pack-priv String allRequiredBitmask(ImmutableList<AutoValueishProcessor. Implements abstract com.
| |
| getAnyMissing | back to summary |
|---|---|
| public String getAnyMissing() Implements abstract com. Doc from com. Returns an expression that is true if any required properties have not been set. Should not be called if there are no required properties. We check the bitmask for primitive properties, and null checks for non-primitive ones.
| |
| getDefaultedBitmaskParameters | back to summary |
|---|---|
| public String getDefaultedBitmaskParameters() Implements abstract com. Doc from com. Returns additional constructor parameters to indicate what properties have been defaulted, or an empty string if there are none.
| |
| primitivePropertiesIn | back to summary |
|---|---|
| private static ImmutableList | |
| Modifier and Type | Field and Description |
|---|---|
| private final ImmutableList |
| Access | Constructor and Description |
|---|---|
| pack-priv | WithDefaults(ImmutableSet<AutoValueishProcessor.
|
| Modifier and Type | Method and Description |
|---|---|
| pack-priv String | allRequiredBitmask(ImmutableList<AutoValueishProcessor.
Implements abstract com.
|
| public String | getAnyMissing()
Implements abstract com. Returns an expression that is true if any required properties have not been set. |
| public String | getDefaultedBitmaskParameters()
Implements abstract com. Returns additional constructor parameters to indicate what properties have been defaulted, or an empty string if there are none. |
| allProperties | back to summary |
|---|---|
| private final ImmutableList<AutoValueishProcessor. | |
| WithDefaults | back to summary |
|---|---|
| pack-priv WithDefaults(ImmutableSet<AutoValueishProcessor. | |
| allRequiredBitmask | back to summary |
|---|---|
| pack-priv String allRequiredBitmask(ImmutableList<AutoValueishProcessor. Implements abstract com.
| |
| getAnyMissing | back to summary |
|---|---|
| public String getAnyMissing() Implements abstract com. Doc from com. Returns an expression that is true if any required properties have not been set. Should not be called if there are no required properties. Everything can be checked with bitmask operations. If bit i represents a required property then it must be 1 in the bitmask field. So if we invert it we must get 0, and if we do that for the field as a whole and AND with a bitmask selecting only required properties we should get 0.
| |
| getDefaultedBitmaskParameters | back to summary |
|---|---|
| public String getDefaultedBitmaskParameters() Implements abstract com. Doc from com. Returns additional constructor parameters to indicate what properties have been defaulted, or an empty string if there are none. When there are default parameters, we're calling the special constructor that has one or more bitmask parameters at the end. Bit i is set if parameter i (zero-origin) has its default value, and then the actual value passed for that parameter is ignored. Our bitmask field has a 1 for any parameter that has been set, meaning it has a 0 for any parameter that has been defaulted. So we need to invert it, and we also want to AND it with a bitmask that selects just the bits for parameters with defaults. (The AND probably isn't strictly necessary, since the constructor code doesn't actually look at those other bits, but it seems cleaner.) If the bitmask for parameters with defaults is 0 then we can just use 0 for that bitmask, and if it is ~0 (all 1 bits) then we can skip the AND. That special constructor has an additional dummy parameter of type
| |