Class MuleArtifactAstCopyUtils

java.lang.Object
org.mule.runtime.ast.api.util.MuleArtifactAstCopyUtils

public final class MuleArtifactAstCopyUtils extends Object
Provides common utility methods to do AST transformations.
Since:
1.0
  • Method Details

    • copyRecursively

      public static ArtifactAst copyRecursively(ArtifactAst source, UnaryOperator<ComponentAst> componentMapper)
      Copies and transforms a given ArtifactAst, mapping its internal ComponentAst instances with the provided compoenentMapper function.
      Parameters:
      source - the ArtifactAst to copy and transform.
      componentMapper - transformation to apply to each ComponentAst from source. If no transformation is to be done for a given ComponentAst, the same instance must be returned.
      Returns:
      a transformed copy of the source AST.
    • copyRecursively

      public static ArtifactAst copyRecursively(ArtifactAst source, UnaryOperator<ComponentAst> componentMapper, Supplier<List<ComponentAst>> topLeveltoAdd, Predicate<ComponentAst> topLevelToRemove)
      Copies and transforms a given ArtifactAst, mapping its internal ComponentAst instances with the provided compoenentMapper function.

      This method also allows for adding or removing top level elements from the transformed AST.

      In the case that for a newly added component, topLevelToRemove returns true, that component will NOT be on the returned AST.

      Parameters:
      source - the ArtifactAst to copy and transform.
      componentMapper - transformation to apply to each ComponentAst from source. If no transformation is to be done for a given ComponentAst, the same instance must be returned.
      topLeveltoAdd - components to be added as top-level elements in the transformed AST
      topLevelToRemove - any top-level elements for which this returns true will be removed from the returned AST.
      Returns:
      a transformed copy of the source AST.
    • copyComponentTreeRecursively

      public static ComponentAst copyComponentTreeRecursively(ComponentAst source, UnaryOperator<ComponentAst> componentMapper)
      Copies and transforms a given ComponentAst, mapping it and its children ComponentAst instances recursively with the provided compoenentMapper function.
      Parameters:
      source - the ComponentAst to copy and transform recursively.
      componentMapper - transformation to apply to each ComponentAst from source. If no transformation is to be done for a given ComponentAst, the same instance must be returned.
      Returns:
      a transformed copy of the source AST.