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
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).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceFunctional interface for theof(Transformation.Step)factory — allows steps to be expressed as lambdas or method references. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal <R> Transformation<I, R> andThen(Transformation<O, R> next) Compose this transformation withnext, producing a new transformation that runs both in sequence.final Ofire(I in, CompilationContext ctx) Public entry-point: runs this step with logging and error handling.static <I,O> Transformation <I, O> of(Transformation.Step<I, O> step) Create aTransformationfrom a lambda or method reference.protected abstract Orun(I input, CompilationContext ctx) Business logic of this step.protected booleanWhetherfire(I, CompilationContext)should emit a DEBUG log entry for this step.protected StringstepName()Human-readable name used in diagnostic messages.
-
Field Details
-
logger
protected static final org.apache.logging.log4j.Logger logger
-
-
Constructor Details
-
Transformation
public Transformation()
-
-
Method Details
-
of
Create aTransformationfrom a lambda or method reference.- Type Parameters:
I- input type.O- output type.- Parameters:
step- the lambda implementing the step logic.- Returns:
- a
Transformationthat delegatesrun(I, CompilationContext)tostep.
-
stepName
Human-readable name used in diagnostic messages. Named subclasses inherit the default (their simple class name). Composed transformations produced byandThen(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()Whetherfire(I, CompilationContext)should emit a DEBUG log entry for this step. Returnstruefor all named (concrete) steps. Overridden tofalsein the anonymous composition wrappers produced byandThen(Transformation), so that only real pipeline steps appear in the log — not the N intermediate wrappers created by composition. -
run
Business logic of this step. Must not returnnull; may throw any exception. Usectxto 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 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
nullreturn fromrun(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
Compose this transformation withnext, 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.
-