Class ConstructorStateExtractor

java.lang.Object
org.ek9lang.compiler.phase5.flow.ConstructorStateExtractor

public final class ConstructorStateExtractor extends Object
Extracts collection/container state information from constructor calls and literal expressions.

Detects constructor calls on built-in collection and container types (List, Dict, Optional) and literal expressions ([...], {...}) to determine their initial SET/UNSET and EMPTY/NON-EMPTY state at construction time.

Detection rules:

  • [1, 2, 3] (list literal) → SET and NON-EMPTY
  • {"key": 1} (dict literal) → SET and NON-EMPTY
  • List() of String → SET and EMPTY
  • Dict() of (String, Integer) → SET and EMPTY
  • Optional("hello") → SET and NON-EMPTY
  • Optional() of String → UNSET and EMPTY
  • Constructor Details

  • Method Details

    • extractFromAssignment

      public CollectionStateValue extractFromAssignment(EK9Parser.AssignmentExpressionContext assignExpr)
      Extract a CollectionStateValue from an assignment expression if it is a collection/container constructor or literal.
      Parameters:
      assignExpr - the assignment expression to examine
      Returns:
      a CollectionStateValue if a known constructor pattern is detected, null otherwise
    • extractFromExpression

      public CollectionStateValue extractFromExpression(EK9Parser.ExpressionContext expr)
      Extract a CollectionStateValue from an expression if it is a collection/container constructor or literal.
      Parameters:
      expr - the expression to examine
      Returns:
      a CollectionStateValue if a known pattern is detected, null otherwise