Record Class ConstructorBody
java.lang.Object
java.lang.Record
io.micronaut.sourcegen.bytecode.core.ConstructorBody
- Record Components:
implicitSuper- Whether the writer writes the call of the superclass's no-argument constructor firsthoistedCall- The constructor call moved to the front of the statements, if anyinitializedFields- The instance fields whose initializers run after the constructor call, in declaration orderstatements- The statements, without a hoisted call
@Internal
public record ConstructorBody(boolean implicitSuper, @Nullable StatementDef hoistedCall, List<FieldDef> initializedFields, List<StatementDef> statements)
extends Record
The body of a constructor as both bytecode writers write it: the constructor call first, then the initializers of
the instance fields, then the rest of the statements.
- A constructor calling no other constructor calls the superclass's no-argument one, which the writer writes
itself:
implicitSuper(). - Field initializers run straight after the constructor call, so the call is moved to the front -
hoistedCall()- only when there are any; otherwise the statements stay as they are, because the call may use locals defined before it. - A record has no fields of its own, only the ones backing its components, which its canonical constructor assigns.
Both writers run the field initializers once on a constructor delegating to this(...), as javac does -
ConstructorBody.InitializersAfterThis.SKIP; ConstructorBody.InitializersAfterThis.RERUN is kept for a writer running them again.
- Since:
- 2.3
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumWhether the field initializers run after a delegation tothis(...). -
Constructor Summary
ConstructorsConstructorDescriptionConstructorBody(boolean implicitSuper, @Nullable StatementDef hoistedCall, List<FieldDef> initializedFields, List<StatementDef> statements) Creates an instance of aConstructorBodyrecord class. -
Method Summary
Modifier and TypeMethodDescriptionThe whole body as statements: the call of the superclass's no-argument constructor where it is implicit, the hoisted call, the assignments of the field initializers and the statements.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.@Nullable StatementDefReturns the value of thehoistedCallrecord component.booleanReturns the value of theimplicitSuperrecord component.Returns the value of theinitializedFieldsrecord component.initializedFields(ObjectDef objectDef) The instance fields of a class that have an initializer, in declaration order; a record has none of its own.static booleanisConstructorInvocation(StatementDef statement) Whether a statement calls another constructor:super(...), or the deprecated form of an instance invocation of a constructor, onthisor onsuper.static ConstructorBodyof(@Nullable ObjectDef objectDef, List<StatementDef> statements, ConstructorBody.InitializersAfterThis mode) Normalizes the statements of a constructor.Returns the value of thestatementsrecord component.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
ConstructorBody
public ConstructorBody(boolean implicitSuper, @Nullable StatementDef hoistedCall, List<FieldDef> initializedFields, List<StatementDef> statements) Creates an instance of aConstructorBodyrecord class.- Parameters:
implicitSuper- the value for theimplicitSuperrecord componenthoistedCall- the value for thehoistedCallrecord componentinitializedFields- the value for theinitializedFieldsrecord componentstatements- the value for thestatementsrecord component
-
-
Method Details
-
of
public static ConstructorBody of(@Nullable ObjectDef objectDef, List<StatementDef> statements, ConstructorBody.InitializersAfterThis mode) Normalizes the statements of a constructor.- Parameters:
objectDef- The definition declaring the constructorstatements- The statements of the constructormode- Whether the field initializers run after a delegation tothis(...)- Returns:
- The body
-
initializedFields
-
isConstructorInvocation
Whether a statement calls another constructor:super(...), or the deprecated form of an instance invocation of a constructor, onthisor onsuper.- Parameters:
statement- The statement- Returns:
- true for a constructor call
-
asStatements
The whole body as statements: the call of the superclass's no-argument constructor where it is implicit, the hoisted call, the assignments of the field initializers and the statements.- Returns:
- The statements
-
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with thecomparemethod from their corresponding wrapper classes. -
implicitSuper
public boolean implicitSuper()Returns the value of theimplicitSuperrecord component.- Returns:
- the value of the
implicitSuperrecord component
-
hoistedCall
Returns the value of thehoistedCallrecord component.- Returns:
- the value of the
hoistedCallrecord component
-
initializedFields
Returns the value of theinitializedFieldsrecord component.- Returns:
- the value of the
initializedFieldsrecord component
-
statements
Returns the value of thestatementsrecord component.- Returns:
- the value of the
statementsrecord component
-