Record Class PropertyInitialiser

java.lang.Object
java.lang.Record
org.ek9lang.compiler.support.PropertyInitialiser
Record Components:
property - the property whose initialiser the node is in
aggregateParts - 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 Details

  • Method Details

    • enclosing

      public static Optional<PropertyInitialiser> enclosing(org.antlr.v4.runtime.tree.ParseTree node)
      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

      public boolean declares(ISymbol candidate)
      True if this property is declared in the same aggregate body as the initialiser.
    • isDeclaredBefore

      public boolean isDeclaredBefore(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. The property being initialised is not declared before itself.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • property

      Returns the value of the property record component.
      Returns:
      the value of the property record component
    • aggregateParts

      public EK9Parser.AggregatePartsContext aggregateParts()
      Returns the value of the aggregateParts record component.
      Returns:
      the value of the aggregateParts record component