Class StepChain

java.lang.Object
nz.org.riskscape.rl.ast.StepChain
All Implemented Interfaces:
AST, PipelineAST

public class StepChain extends Object implements PipelineAST

AST for a list of StepDeclarations that are chained together.

Steps that are chained together should have their output connected to the input of the following step in the chain.

Steps that are declared (but not chained to another) will be on the only step in the step chain. In this case it would be expected that the the same step be present in another step chain to be chained together with other steps.

  • Field Details

    • CHAIN_TOKEN

      public static final Token CHAIN_TOKEN

      A handy constant for building AST in code (instead of parsing it)

    • EMPTY

      public static final StepChain EMPTY

      A special "empty" instance of a StepChain that can be used in place of null in various situations. Note that an empty StepChain is not a valid part of a pipeline.

  • Constructor Details

  • Method Details

    • getBoundary

      public Optional<Pair<Token,Token>> getBoundary()
      Specified by:
      getBoundary in interface AST
      Returns:
      a pair of tokens that represent the start and end of this expression, to be used when giving users information about where errors have occurred. If the expression has been rebuilt then the boundary may be empty or it may be from the original AST. Intended for use in problems to trace errors back to their source.
    • append

      public StepChain append(StepChain appendStepsFrom)

      Returns a new StepChain with all the steps from the given chain appended to this chain

    • append

      public StepChain append(StepDeclaration stepDeclaration)

      Returns a new StepChain with the given step appended

    • appendSource

      protected void appendSource(StringBuilder appendTo)

      Implementers extend this to append their source to the given string builder. Done via string builder to encourage a more efficient implementation than is possible with concatenating multiple toString calls that typically contruct a string builder anyway.

    • appendString

      protected void appendString(StringBuilder appendTo)

      Append a simplified string representation to the builder. Default implementation uses appendSource. Subclasses can override to provide a more concise representation.

    • getFirst

      public StepDeclaration getFirst()

      Nicer form of StepChain#getSteps().get(0)

      Throws:
      IndexOutOfBoundsException - if this chain is empty
    • getLast

      public StepDeclaration getLast()

      Nicer form of StepChain.getSteps().get(StepChain.getSteps().size() - 1);

      Throws:
      IndexOutOfBoundsException - if this chain is empty
    • getLink

      public StepLink getLink(int index)
    • getLinkCount

      public int getLinkCount()
    • size

      public int size()
      Returns:
      the number of steps in this chain
    • replace

      public StepChain replace(StepDeclaration step, StepDeclaration replacement)

      Replace step with `replacement, returning a new StepChain that includes the change.

    • accept

      public <T, R> R accept(PipelineVisitor<T,R> visitor, T data)
      Specified by:
      accept in interface PipelineAST
    • equals

      public boolean equals(Object o)
    • canEqual

      protected boolean canEqual(Object other)
    • hashCode

      public int hashCode()
    • getSteps

      public List<StepDeclaration> getSteps()
    • appendSource

      protected static void appendSource(AST ast, StringBuilder appendTo)

      Helper method for appending the source of another ast element to a string builder, efficiently if possible.

    • toString

      public final String toString()

      Returns a simplified view of the ast in a source-like fashion, but with a lot of details left out for conciseness

      Overrides:
      toString in class Object
    • toSource

      public final String toSource()
      Specified by:
      toSource in interface AST
      Returns:
      a normalized version of the AST that can be parsed to be exactly the same AST as this