Class StructuralReorderer

java.lang.Object
org.ek9lang.compiler.formatter.StructuralReorderer

final class StructuralReorderer extends Object
Pass 2 of the EK9 source formatter: Structural Reordering.

Phase 1: Module-level reordering:

  • Reference sorting: sorts identifierReference entries within a references block lexicographically
  • Module block ordering: orders defines blocks by canonical type (constant, type, record, trait, class, function, component, text, service, application, program, package)
Phase 2: Aggregate internal reordering (class, record, trait, component):
  • Constructor colocation: constructors grouped at top of methods
  • Overload colocation: same-name methods grouped together
  • Operator canonical ordering: operators sorted by canonical order
Same-type blocks and same-name overloads preserve their original relative order. Doc comments travel with the construct they precede.
  • Constructor Details

    • StructuralReorderer

      StructuralReorderer()
  • Method Details

    • reorder

      String reorder(String source)
      Apply structural reordering to the given canonically indented EK9 source.
      Parameters:
      source - The canonically indented EK9 source code.
      Returns:
      The source with references sorted and module blocks reordered, or null if parsing fails.
    • parseToTree

      Parse the source to a CompilationUnitContext. Returns null if parsing encounters errors.