Class TemplateMutationGenerator

java.lang.Object
org.ek9lang.compiler.fuzz.TemplateMutationGenerator

public final class TemplateMutationGenerator extends Object
Strand 3: Template Mutation. Takes a working qaExample source string and applies exactly one random mutation to introduce a controlled error. The original compiles — the mutation breaks it.

Nine mutation categories with equal probability:

  1. Drop modifier — remove as pure, as open, override, etc.
  2. Add modifier — insert abstract before a method line
  3. Swap type — StringIntegerFloatBoolean
  4. Rename identifier — append/truncate/change case of a random identifier
  5. Change operator — <-:=:=?, +-
  6. Delete line — remove a random non-structural code line
  7. Change indent — add/remove 2 spaces from a random code line
  8. Duplicate line — copy a declaration line to create a duplicate
  9. Swap user type — replace a user-defined type name with a different one
  10. Duplicate operand — copy one side of a comparison to the other (targets E08081/E08082)
  11. Strip guard — remove if/while from a guard expression (targets E08030/E08040)
  12. Swap lines — swap two adjacent statements at the same indent (targets E08010)
  13. Inject boolean literal — append == true to a boolean condition (targets E08083)
  14. Strip sanitized — remove sanitized keyword from parameter (targets E07930-E07950)
  15. Strip override — remove override keyword from method (targets E05120-E05160)
  16. Toggle purity — add or remove as pure from method (targets E05190/E08120)
  17. Strip abstract — remove abstract from class/method (targets E05020/E05070)
  18. Remove isSet operator — delete override operator ? line (targets E05120)
  19. Discard return — remove variable capture from function call (targets E11066)
  20. Privatize method — add private to a method declaration (targets E05130/E05140)
  21. Strip generic param — remove of Type from generic usage (targets E04080/E06030)
  22. Duplicate method — copy a method declaration to create duplicate (targets E02030)
  23. Break indentation — shift a block's child lines by +/-2 spaces (indentation errors)

Line-based mutations — no ANTLR parsing required. Skips JSON header, shebang, EOF marker, empty lines, and comment-only lines.

  • Constructor Details

    • TemplateMutationGenerator

      public TemplateMutationGenerator()
  • Method Details

    • mutate

      public TemplateMutationGenerator.MutationResult mutate(String source, Random random)
      Apply exactly one random mutation to the given source.
      Parameters:
      source - the original (compilable) EK9 source
      random - the random source for mutation selection
      Returns:
      the mutated source with a label, or null if no mutation could be applied