Class LoadResolver

java.lang.Object
ca.mcscert.jpipe.compiler.model.Transformation<List<Command>, List<Command>>
ca.mcscert.jpipe.compiler.steps.transformations.LoadResolver

public final class LoadResolver extends Transformation<List<Command>, List<Command>>
Eliminates all LoadResolver.LoadDirectives from the command list by recursively parsing each referenced file and splicing its prefixed commands in place.

LoadResolver runs after ActionListProvider and before ActionListInterpretation, so the ExecutionEngine always receives a flat list that contains no LoadResolver.LoadDirectives.

Algorithm for each load "path" as ns directive found in the list:

  1. Resolve path relative to the directory of the file currently being compiled (taken from the CompilationContext.sourcePath()). When path is a glob pattern it expands to every matched file instead of one; its literal prefix is resolved the same way, so a pattern may point below that directory, above it (../library/*.jd) or at an absolute location — see anchor(Path, String).
  2. Detect cycles: if the resolved path is already being compiled in the current call stack, report a FATAL and skip.
  3. Parse the referenced file up to and including ActionListProvider using a fresh CompilationContext tied to the sub-file.
  4. Recursively resolve any LoadResolver.LoadDirectives found in that sub-list.
  5. Prefix every model name in the expanded sub-list with ns + ":" via prefix(String, List).
  6. Splice the prefixed commands into the result in place of the LoadResolver.LoadDirective.

Because step 3 gives every loaded file a CompilationContext of its own, step 1 always resolves against the file that contains the load — never against the file that started the compilation, and never against the process working directory. A relative path therefore denotes the same file wherever the compiler is invoked from, and a file that is loaded from two different places still resolves its own loads against itself.

Diagnostics produced while compiling a sub-file are always forwarded to the parent CompilationContext, so the caller sees a unified error report.

  • Constructor Details

  • Method Details

    • run

      protected List<Command> run(List<Command> commands, CompilationContext ctx)
      Description copied from class: Transformation
      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.
      Specified by:
      run in class Transformation<List<Command>, List<Command>>
      Parameters:
      commands - the value produced by the previous step.
      ctx - compilation context carrying the source path and diagnostic bag.
      Returns:
      the transformed value — never null.