Class TemplateMutationGenerator
java.lang.Object
org.ek9lang.compiler.fuzz.TemplateMutationGenerator
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:
- Drop modifier — remove
as pure,as open,override, etc. - Add modifier — insert
abstractbefore a method line - Swap type —
String↔Integer↔Float↔Boolean - Rename identifier — append/truncate/change case of a random identifier
- Change operator —
<-↔:=↔:=?,+↔- - Delete line — remove a random non-structural code line
- Change indent — add/remove 2 spaces from a random code line
- Duplicate line — copy a declaration line to create a duplicate
- Swap user type — replace a user-defined type name with a different one
- Duplicate operand — copy one side of a comparison to the other (targets E08081/E08082)
- Strip guard — remove
if/whilefrom a guard expression (targets E08030/E08040) - Swap lines — swap two adjacent statements at the same indent (targets E08010)
- Inject boolean literal — append
== trueto a boolean condition (targets E08083) - Strip sanitized — remove
sanitizedkeyword from parameter (targets E07930-E07950) - Strip override — remove
overridekeyword from method (targets E05120-E05160) - Toggle purity — add or remove
as purefrom method (targets E05190/E08120) - Strip abstract — remove
abstractfrom class/method (targets E05020/E05070) - Remove isSet operator — delete
override operator ?line (targets E05120) - Discard return — remove variable capture from function call (targets E11066)
- Privatize method — add
privateto a method declaration (targets E05130/E05140) - Strip generic param — remove
of Typefrom generic usage (targets E04080/E06030) - Duplicate method — copy a method declaration to create duplicate (targets E02030)
- 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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordResult of a mutation: the mutated source and a label describing the mutation type. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionApply exactly one random mutation to the given source.
-
Constructor Details
-
TemplateMutationGenerator
public TemplateMutationGenerator()
-
-
Method Details
-
mutate
Apply exactly one random mutation to the given source.- Parameters:
source- the original (compilable) EK9 sourcerandom- the random source for mutation selection- Returns:
- the mutated source with a label, or null if no mutation could be applied
-