Package org.mule.runtime.ast.api.util
Class MuleArtifactAstCopyUtils
java.lang.Object
org.mule.runtime.ast.api.util.MuleArtifactAstCopyUtils
Provides common utility methods to do AST transformations.
- Since:
- 1.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic ComponentAstcopyComponentTreeRecursively(ComponentAst source, UnaryOperator<ComponentAst> componentMapper) Copies and transforms a givenComponentAst, mapping it and its childrenComponentAstinstances recursively with the providedcompoenentMapperfunction.static ArtifactAstcopyRecursively(ArtifactAst source, UnaryOperator<ComponentAst> componentMapper) Copies and transforms a givenArtifactAst, mapping its internalComponentAstinstances with the providedcompoenentMapperfunction.static ArtifactAstcopyRecursively(ArtifactAst source, UnaryOperator<ComponentAst> componentMapper, Supplier<List<ComponentAst>> topLeveltoAdd, Predicate<ComponentAst> topLevelToRemove) Copies and transforms a givenArtifactAst, mapping its internalComponentAstinstances with the providedcompoenentMapperfunction.
-
Method Details
-
copyRecursively
public static ArtifactAst copyRecursively(ArtifactAst source, UnaryOperator<ComponentAst> componentMapper) Copies and transforms a givenArtifactAst, mapping its internalComponentAstinstances with the providedcompoenentMapperfunction.- Parameters:
source- theArtifactAstto copy and transform.componentMapper- transformation to apply to eachComponentAstfromsource. If no transformation is to be done for a givenComponentAst, the same instance must be returned.- Returns:
- a transformed copy of the
sourceAST.
-
copyRecursively
public static ArtifactAst copyRecursively(ArtifactAst source, UnaryOperator<ComponentAst> componentMapper, Supplier<List<ComponentAst>> topLeveltoAdd, Predicate<ComponentAst> topLevelToRemove) Copies and transforms a givenArtifactAst, mapping its internalComponentAstinstances with the providedcompoenentMapperfunction.This method also allows for adding or removing top level elements from the transformed AST.
In the case that for a newly added component,
topLevelToRemovereturnstrue, that component will NOT be on the returned AST.- Parameters:
source- theArtifactAstto copy and transform.componentMapper- transformation to apply to eachComponentAstfromsource. If no transformation is to be done for a givenComponentAst, the same instance must be returned.topLeveltoAdd- components to be added as top-level elements in the transformed ASTtopLevelToRemove- any top-level elements for which this returns true will be removed from the returned AST.- Returns:
- a transformed copy of the
sourceAST.
-
copyComponentTreeRecursively
public static ComponentAst copyComponentTreeRecursively(ComponentAst source, UnaryOperator<ComponentAst> componentMapper) Copies and transforms a givenComponentAst, mapping it and its childrenComponentAstinstances recursively with the providedcompoenentMapperfunction.- Parameters:
source- theComponentAstto copy and transform recursively.componentMapper- transformation to apply to eachComponentAstfromsource. If no transformation is to be done for a givenComponentAst, the same instance must be returned.- Returns:
- a transformed copy of the
sourceAST.
-