Class Transformation<I,O>

java.lang.Object
ca.mcscert.jpipe.compiler.model.Transformation<I,O>
Type Parameters:
I - input type.
O - output type.
Direct Known Subclasses:
ActionListInterpretation, ActionListProvider, CharStreamProvider, Checker, DiagnosticReport, ExportToDot, ExportToJpipe, ExportToJson, ExportToPython, Lexer, LoadResolver, Parser, RenderWithDot, SelectModel

public abstract class Transformation<I,O> extends Object
A single step in a compilation chain: a function I → O.

Concrete steps implement run(I, CompilationContext). Callers always go through fire(I, CompilationContext), which adds logging, null-output detection, fast-fail on accumulated fatal errors, and uniform error wrapping. Steps are composed via andThen(Transformation).

  • Field Details

    • logger

      protected static final org.apache.logging.log4j.Logger logger
  • Constructor Details

    • Transformation

      public Transformation()
  • Method Details

    • of

      public static <I,O> Transformation<I,O> of(Transformation.Step<I,O> step)
      Create a Transformation from a lambda or method reference.
      Type Parameters:
      I - input type.
      O - output type.
      Parameters:
      step - the lambda implementing the step logic.
      Returns:
      a Transformation that delegates run(I, CompilationContext) to step.
    • stepName

      protected String stepName()
      Human-readable name used in diagnostic messages. Named subclasses inherit the default (their simple class name). Composed transformations produced by andThen(Transformation) override this to propagate the name of the leftmost step so that "pipeline aborted" messages point to the first step that would have done work.
    • shouldLog

      protected boolean shouldLog()
      Whether fire(I, CompilationContext) should emit a DEBUG log entry for this step. Returns true for all named (concrete) steps. Overridden to false in the anonymous composition wrappers produced by andThen(Transformation), so that only real pipeline steps appear in the log — not the N intermediate wrappers created by composition.
    • run

      protected abstract O run(I input, CompilationContext ctx)
      Business logic of this step. Must not return null; may throw any exception. Use ctx to report non-fatal diagnostics or inspect previously accumulated errors.
      Parameters:
      input - the value produced by the previous step.
      ctx - compilation context carrying the source path and diagnostic bag.
      Returns:
      the transformed value — never null.
      Throws:
      RuntimeException - if anything goes wrong.
    • fire

      public final O fire(I in, CompilationContext ctx)
      Public entry-point: runs this step with logging and error handling.
      • Fast-fails if the context already holds fatal errors (a previous step marked the pipeline as broken).
      • Wraps any checked exception in CompilationException.
      • Rejects a null return from run(I, CompilationContext) as a programming error in the step implementation.
      Parameters:
      in - the input value.
      ctx - compilation context.
      Returns:
      the output value — never null.
    • andThen

      public final <R> Transformation<I,R> andThen(Transformation<O,R> next)
      Compose this transformation with next, producing a new transformation that runs both in sequence.
        this : I → O
        next : O → R
        this.andThen(next) : I → R
      
      Type Parameters:
      R - output type of the composed transformation.
      Parameters:
      next - transformation to apply after this one.
      Returns:
      a new anonymous transformation implementing next ∘ this.