Class SafeGenericContainers

java.lang.Object
org.ek9lang.compiler.phase5.SafeGenericContainers

final class SafeGenericContainers extends Object
THE shared "which of Result, Optional or Iterator is this symbol" (the containers whose unwrapping method ok()/error(), get() or next() must be preceded by a check, E08030), and the three-way dispatch onto SymbolsAndScopes' record, is-safe and mark operations. It was a trio of HasTypeOfGeneric plus an if/else-if chain built in five places; use this, never a fourth.

The test is always Result, then Optional, then Iterator (exclusive by construction: a type has one generic base). A Result has two guarded accessors, so only the OK accessor is recorded, marked and tested here; the error accessor is handled by name in SafeSymbolAccess and SafeAccessConjuncts.

  • Constructor Details

    • SafeGenericContainers

      SafeGenericContainers(SymbolsAndScopes symbolsAndScopes)
  • Method Details

    • of

    • isContainer

      boolean isContainer(ISymbol symbol)
      Is the symbol a Result, Optional or Iterator.
    • recordDeclaration

      void recordDeclaration(ISymbol symbol)
      Record the declaration of a variable of a container type, so that its unwrapping call needs a check.
    • isAccessSafe

      boolean isAccessSafe(ISymbol symbol)
      Is the (OK for a Result) unwrapping access of this symbol safe in the scope it is used in. False for a symbol that is not a container.
    • markAccessSafe

      void markAccessSafe(ISymbol symbol, IScope scopeMadeSafe)
      Mark the (OK for a Result) unwrapping access of this symbol safe in the scope; nothing for other symbols.