Class PipelineDeclaration
- All Implemented Interfaces:
AST,PipelineAST
AST for a pipeline declaration - the root of the AST.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classSimple value holder for the results of finding a step via thefind(BiPredicate)method. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionPipelineDeclaration(List<StepChain> chains) Construct a newPipelineDeclarationwithout any metadata.PipelineDeclaration(List<StepChain> chains, PipelineMetadata metadata) -
Method Summary
Modifier and TypeMethodDescription<T,R> R accept(PipelineVisitor<T, R> visitor, T data) Return a newPipelineDeclarationwith the given step chain added to the end of thisPipelineDeclaration's list of chainsadd(PipelineDeclaration toAdd) Return a newPipelineDeclarationthat is the combination of this pipeline and the other - no merge or squishing or anything clever is going onprotected voidappendSource(StringBuilder appendTo) Implementers extend this to append their source to the given string builder.protected static voidappendSource(AST ast, StringBuilder appendTo) Helper method for appending the source of another ast element to a string builder, efficiently if possible.protected voidappendString(StringBuilder appendTo) Append a simplified string representation to the builder.protected booleancheckValid(Function<StepDeclaration, String> nameFunction) Check that thisPipelineDeclarationis valid.booleanfind(BiPredicate<StepChain, StepDeclaration> predicate) General purpose step-finding method.find(Predicate<StepDeclaration> predicate) Convenience version offind(BiPredicate)that drops the chain from the predicatefindAll(BiPredicate<StepChain, StepDeclaration> predicate) General purpose step-finding method.findDefinition(@NonNull String stepName) Search through for the definition of a step with the given name, using either the step id or aliasgetFirst()getLast()getStepNameFunction(StepNamingPolicy policy) inthashCode()booleanisEmpty()Return a newPipelineDeclaration, with a replacement step chainreplaceParameters(Map<String, Expression> replacements) Builds a new PipelineDeclaration by replacing tokens with those specified, while trying to preserve whitespaceintsize()final StringtoSource()final StringtoString()Returns a simplified view of the ast in a source-like fashion, but with a lot of details left out for concisenesswithMetadata(PipelineMetadata newMetadata) Clones this PipelineDeclaration but with different metadata.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface nz.org.riskscape.rl.ast.AST
isA, switchType, toSource
-
Field Details
-
EMPTY
An empty
PipelineDeclaration. Useful in various situations where a null might otherwise be used, or might require a different API method to handle a base case.
-
-
Constructor Details
-
PipelineDeclaration
Construct a new
PipelineDeclarationwithout any metadata. -
PipelineDeclaration
-
-
Method Details
-
getBoundary
- Specified by:
getBoundaryin interfaceAST- 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.
-
findDefinition
Search through for the definition of a step with the given name, using either the step id or alias
- Parameters:
stepName- name (id or alias) of a step to look for- Returns:
- the first found declaration of the found step, along with the step chain that it was found in, or empty if nothing was found
-
find
Convenience version of
find(BiPredicate)that drops the chain from the predicate -
find
General purpose step-finding method. Find a step using a predicate, returning the first step that matches (in ast order).
- Parameters:
predicate- test each step against this predicate- Returns:
- the first step (and chain) that matched, or empty if nothing found.
-
findAll
General purpose step-finding method. Find a list of steps using a predicate, returning all steps that match (in ast order).
- Parameters:
predicate- test each step against this predicate- Returns:
- a list of
PipelineDeclaration.Foundobjects for the steps that matched the predicate
-
replace
public PipelineDeclaration replace(@NonNull @NonNull StepChain found, @NonNull @NonNull StepChain newChain) throws IllegalStateException Return a new
PipelineDeclaration, with a replacement step chain- Parameters:
found- the step chain to replacenewChain- the replacement chain- Returns:
- a new
PipelineDeclarationwith the replacement made - Throws:
IllegalStateException- if found is not part of this pipeline declaration
-
getUniqueParameters
- Returns:
- a the unique set of
ParameterTokens in thisPipelineDeclaration, but as aListto preserve the order that they were found in.
-
getAllParameters
- Returns:
- the list of all
ParameterTokens in this pipeline, one for each occurrence within the AST.
-
replaceParameters
Builds a new PipelineDeclaration by replacing tokens with those specified, while trying to preserve whitespace
- Parameters:
replacements- parameter names mapped to replacement expressions.- Returns:
- a new
PipelineDeclaration, or problems if any of the parameter tokens found in the pipeline declaration that were not replaced.
-
add
Return a new
PipelineDeclarationwith the given step chain added to the end of thisPipelineDeclaration's list of chains- Parameters:
toAdd- the chain to add- Returns:
- a new
PipelineDeclarationcontaining the given chain
-
add
Return a new
PipelineDeclarationthat is the combination of this pipeline and the other - no merge or squishing or anything clever is going on -
getFirst
- Returns:
- the 0th chain in this declaration
- Throws:
IndexOutOfBoundsException- if this declaration is empty
-
getLast
- Returns:
- the last chain in this declaration
- Throws:
IndexOutOfBoundsException- if this declaration is empty
-
isEmpty
public boolean isEmpty()- Returns:
- true if this declaration has no chains
-
appendString
Append a simplified string representation to the builder. Default implementation uses appendSource. Subclasses can override to provide a more concise representation.
-
appendSource
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.
-
stepDefinitionIterator
- Returns:
- an
Iteratorthat yields all of theStepDefinitions in this pipeline declaration in the order they appear in the source. Skips all theStepReferences.
-
size
public int size()- Returns:
- the number of chains (not steps) in this pipeline declaration
-
getStepNameFunction
- Parameters:
policy- the step naming policy that will be applied- Returns:
- a function that gives the name for a step definition, returning either a unique generated name, if none was assigned, or the explicitly assigned name
-
checkValid
public ResultOrProblems<PipelineDeclaration> checkValid(Function<StepDeclaration, String> nameFunction) Check that this
PipelineDeclarationis valid. This check includes checking for step redefinition and pipeline cycles.- Parameters:
nameFunction- maps a StepDefinition to a name, seegetStepNameFunction(StepNamingPolicy)- Returns:
- function that provides step names for this pipeline or errors found
-
withMetadata
Clones this PipelineDeclaration but with different metadata.
-
accept
- Specified by:
acceptin interfacePipelineAST
-
equals
-
canEqual
-
hashCode
public int hashCode() -
getChains
-
getMetadata
-
appendSource
Helper method for appending the source of another ast element to a string builder, efficiently if possible.
-
toString
Returns a simplified view of the ast in a source-like fashion, but with a lot of details left out for conciseness
-
toSource
-