java.lang.Object
com.darkcollective.relix.optimizer.internal.OptimizationContext

public final class OptimizationContext extends Object
Mutable accumulator for TransformationRecords produced during a query optimization run.

Rules call record(OptimizationCode, String, String, SourceLocation) each time they fire. After optimization is complete the accumulated records are available via records() and can be passed to the console's optimization report for rendering.

This class is not thread-safe. A fresh instance should be created for each optimization run.

Every record(com.darkcollective.relix.optimizer.OptimizationCode, java.lang.String, java.lang.String, com.darkcollective.relix.ast.SourceLocation) also emits a QueryEvent to the QueryEventListener supplied at construction (default QueryEventListener.NONE), so a consumer can observe rule firings live.

Usage by rule implementations

 // inside OptimizationRule.apply():
 if (ruleApplies) {
     ctx.record(OptimizationCode.EXPR_001, queryName,
                "2 * 3 folded to 6", node.location());
     return rewrittenNode;
 }
 return node; // no change, nothing recorded