Record Class PropertyInitialiser
java.lang.Object
java.lang.Record
org.ek9lang.compiler.support.PropertyInitialiser
- Record Components:
property- the property whose initialiser the node is inaggregateParts- the body of the aggregate that property belongs to
public record PropertyInitialiser(EK9Parser.AggregatePropertyContext property, EK9Parser.AggregatePartsContext aggregateParts)
extends Record
THE answer to "is this node inside a property's initialiser, and which properties of that type are set by then?"
Use this wherever a check depends on a property initialiser - do not re-walk the tree for it.
An aggregate's property initialisers run in declaration order, in _i_init, BEFORE the constructor body. So while one runs, the only properties of the same type with a value are those declared earlier that have an initialiser of their own; and the object as a whole is never complete. Code that read a later property, a property set in the constructor, or called a method of the object, compiled clean and failed with a NullPointerException when the object was built (front-end audit FE32).
"The same type" is decided by where a property is declared: within the same aggregate body. A dynamic class declared inside an initialiser has its own body, so its properties are not the outer type's.
-
Constructor Summary
ConstructorsConstructorDescriptionPropertyInitialiser(EK9Parser.AggregatePropertyContext property, EK9Parser.AggregatePartsContext aggregateParts) Creates an instance of aPropertyInitialiserrecord class. -
Method Summary
Modifier and TypeMethodDescriptionReturns the value of theaggregatePartsrecord component.booleanTrue if this property is declared in the same aggregate body as the initialiser.static Optional<PropertyInitialiser> enclosing(org.antlr.v4.runtime.tree.ParseTree node) The property initialiser this node is in, if any.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.booleanisDeclaredBefore(ISymbol candidate) True if this property is declared before the property whose initialiser this is - so its own initialiser, if it has one, has already run.property()Returns the value of thepropertyrecord component.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
PropertyInitialiser
public PropertyInitialiser(EK9Parser.AggregatePropertyContext property, EK9Parser.AggregatePartsContext aggregateParts) Creates an instance of aPropertyInitialiserrecord class.- Parameters:
property- the value for thepropertyrecord componentaggregateParts- the value for theaggregatePartsrecord component
-
-
Method Details
-
enclosing
The property initialiser this node is in, if any. The walk stops where code no longer runs as part of the initialiser: a block of statements (a method body), an aggregate body (a dynamic class declared in the initialiser has its own), and a dynamic function's body, which runs when the function is called. A dynamic function's or class's capture list is evaluated by the initialiser, so the walk passes through those. -
declares
True if this property is declared in the same aggregate body as the initialiser. -
isDeclaredBefore
True if this property is declared before the property whose initialiser this is - so its own initialiser, if it has one, has already run. The property being initialised is not declared before itself. -
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. All components in this record class are compared withObjects::equals(Object,Object). -
property
-
aggregateParts
Returns the value of theaggregatePartsrecord component.- Returns:
- the value of the
aggregatePartsrecord component
-