Class PipelineDeclaration
- All Implemented Interfaces:
PipelineExpression
AST for a pipeline declaration - the root of the AST.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Simple value holder for the results of finding a step via thefind(BiPredicate)
method. -
Field Summary
-
Constructor Summary
ConstructorDescriptionPipelineDeclaration
(List<StepChain> chains) Construct a newPipelineDeclaration
without any metadata.PipelineDeclaration
(List<StepChain> chains, PipelineMetadata metadata) -
Method Summary
Modifier and TypeMethodDescriptionReturn a newPipelineDeclaration
with the given step chain added to the end of thisPipelineDeclaration
's list of chainsadd
(PipelineDeclaration toAdd) Return a newPipelineDeclaration
that is the combination of this pipeline and the other - no merge or squishing or anything clever is going onprotected void
appendSource
(StringBuilder appendTo) protected void
appendString
(StringBuilder appendTo) protected boolean
checkValid
(Function<StepDeclaration, String> nameFunction) Check that thisPipelineDeclaration
is valid.boolean
find
(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) int
hashCode()
boolean
isEmpty()
Return a newPipelineDeclaration
, with a replacement step chainreplaceParameters
(Map<ParameterToken, Expression> replacements) Builds a new PipelineDeclaration by replacing tokens with those specified, while trying to preserve whitespaceint
size()
final String
toSource()
final String
toString()
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.
-
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
PipelineDeclaration
without any metadata. -
PipelineDeclaration
-
-
Method Details
-
getBoundary
-
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.Found
objects 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
PipelineDeclaration
with the replacement made - Throws:
IllegalStateException
- if found is not part of this pipeline declaration
-
findParameters
-
replaceParameters
public Pair<PipelineDeclaration,List<ParameterToken>> replaceParameters(Map<ParameterToken, Expression> replacements) Builds a new PipelineDeclaration by replacing tokens with those specified, while trying to preserve whitespace
- Parameters:
replacements
- parameter tokens mapped to replacement expressions.- Returns:
- a new
PipelineDeclaration
, as well as a list of all the parameter tokens found in the pipeline declaration that were not replaced. As long as the original pipeline has been parsed (rather than built programmatically) these tokens can be used to report errors, along with locations, back to the user.
-
add
Return a new
PipelineDeclaration
with the given step chain added to the end of thisPipelineDeclaration
's list of chains- Parameters:
toAdd
- the chain to add- Returns:
- a new
PipelineDeclaration
containing the given chain
-
add
Return a new
PipelineDeclaration
that 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
-
appendSource
-
stepDefinitionIterator
- Returns:
- an
Iterator
that yields all of theStepDefinition
s in this pipeline declaration in the order they appear in the source. Skips all theStepReference
s.
-
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
PipelineDeclaration
is 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.
-
equals
-
canEqual
-
hashCode
public int hashCode() -
getChains
-
getMetadata
-
toString
Returns a simplified view of the ast in a source-like fashion, but with a lot of details left out for conciseness
-
toSource
- Specified by:
toSource
in interfacePipelineExpression
- Returns:
- a string that can be parsed back in to the same ast as this one. It might not be whitespace-faithful...
-