Class EnumIteratorClassGenerator

java.lang.Object
org.ek9lang.compiler.backend.jvm.EnumIteratorClassGenerator

final class EnumIteratorClassGenerator extends Object
Generates the anonymous iterator class for enum iteration.

When an enum's iterator() method is called, it returns an Iterator of EnumType. This class generates a synthetic inner class (EnumType$EnumIterator) that:

  • Extends the parameterized Iterator wrapper (_Iterator_HASH...)
  • Contains a java.util.Iterator field for direct Java iteration
  • Implements hasNext(), next(), _isSet() by delegating to the Java iterator

This approach maintains the EK9 type hierarchy while providing efficient iteration over enum values at the JVM level.

  • Constructor Details

    • EnumIteratorClassGenerator

      EnumIteratorClassGenerator(File targetFile)
      Create an enum iterator class generator.
      Parameters:
      targetFile - The target file for the enum class (used to derive output directory)
  • Method Details

    • generate

      String generate(String enumTypeName, String superTypeName)
      Generate the anonymous iterator class for the enum.
      Parameters:
      enumTypeName - Fully qualified enum type name (e.g., "synthetic.enumIterator::Colour")
      superTypeName - Fully qualified super type name (e.g., "org.ek9.lang::_Iterator_HASH...")
      Returns:
      The JVM class name of the generated iterator class