Class MuleAstUtils

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

public final class MuleAstUtils extends Object
Set of utility methods for working with ArtifactAsts and ComponentAsts.
Since:
1.0
  • Method Details

    • resolveOrphanComponents

      public static Set<ComponentAst> resolveOrphanComponents(ArtifactAst appModel)
      Given an ArtifactAst, return all those components within it that are not accessible from a top-level component.
      Parameters:
      appModel - the model to determine orphan components from.
      Returns:
      components within the provided appModel that are not accessible from a top-level component.
    • emptyArtifact

      public static ArtifactAst emptyArtifact()
      Provides a singleton empty ArtifactAst instance.
      Returns:
      an ArtifactAst without components.
    • parameterOfType

      public static Optional<ComponentParameterAst> parameterOfType(ComponentAst referent, org.mule.runtime.api.meta.model.stereotype.StereotypeModel referenceStereotype)
      Given a ComponentAst, lookup for a parameter that references an object with a certain stereotype.
      Parameters:
      referent - the ComponentAst that will be checked for the reference.
      referenceStereotype - the StereotypeModel to check for.
      Returns:
      any ComponentParameterAst representing a parameter of referent that references an object assignable to referenceStereotype, if it exists.
    • parametersOfType

      public static List<ComponentParameterAst> parametersOfType(ComponentAst referent, org.mule.runtime.api.meta.model.stereotype.StereotypeModel referenceStereotype)
      Given a ComponentAst, lookup for all parameters that reference an object with a certain stereotype.
      Parameters:
      referent - the ComponentAst that will be checked for the reference.
      referenceStereotype - the StereotypeModel to check for.
      Returns:
      all ComponentParameterAsts representing parameters of referent that reference an object assignable to referenceStereotype.
    • doOnParamComponents

      public static void doOnParamComponents(ComponentParameterAst param, Consumer<ComponentAst> action)
      Performs a given action on the ComponentAsts that form the value of the provided parameter.
      Parameters:
      param - the parameter on which complex parameter values the action will be called.
      action - the callback to perform on each found parameter item.
    • recursiveStreamWithHierarchy

      public static Stream<org.mule.runtime.api.util.Pair<ComponentAst,List<ComponentAst>>> recursiveStreamWithHierarchy(ArtifactAst artifact)
      Similar to ArtifactAst.recursiveStream(), but it enhances the Stream by adding hierarchy context to each item. The ArtifactAst is traversed in TOP_DOWN direction.

      The elements of the Stream are Pairs:

      • the first element is the same component that would be obtained by calling ArtifactAst.recursiveStream().
      • the second element is the hierarchy that was traversed to get to the first element, the first element being a root and the last being the direct parent of the first element of the pair.
      Parameters:
      artifact - the ArtifactAst to generate a Stream for.
      Returns:
      an enhanced Stream with hierarchy context.
    • recursiveStreamWithHierarchy

      public static Stream<org.mule.runtime.api.util.Pair<ComponentAst,List<ComponentAst>>> recursiveStreamWithHierarchy(ArtifactAst artifact, AstTraversalDirection direction)
      Similar to ArtifactAst.recursiveStream(), but it enhances the Stream by adding hierarchy context to each item. The ArtifactAst is traversed in AstTraversalDirection direction

      The elements of the Stream are Pairs:

      • the first element is the same component that would be obtained by calling ArtifactAst.recursiveStream().
      • the second element is the hierarchy that was traversed to get to the first element, the first element being a root and the last being the direct parent of the first element of the pair.
      Parameters:
      artifact - the ArtifactAst to generate a Stream for.
      direction - the AstTraversalDirection used to navigate the artifact.
      ignoreParameterComplexValues - whether the returned Stream will contain any complex values in component parameters.
      Returns:
      an enhanced Stream with hierarchy context.
    • recursiveStreamWithHierarchy

      public static Stream<org.mule.runtime.api.util.Pair<ComponentAst,List<ComponentAst>>> recursiveStreamWithHierarchy(ArtifactAst artifact, AstTraversalDirection direction, boolean ignoreParameterComplexValues)
      Similar to ArtifactAst.recursiveStream(), but it enhances the Stream by adding hierarchy context to each item. The ArtifactAst is traversed in AstTraversalDirection direction

      The elements of the Stream are Pairs:

      • the first element is the same component that would be obtained by calling ArtifactAst.recursiveStream().
      • the second element is the hierarchy that was traversed to get to the first element, the first element being a root and the last being the direct parent of the first element of the pair.
      Parameters:
      artifact - the ArtifactAst to generate a Stream for.
      direction - the AstTraversalDirection used to navigate the artifact.
      ignoreParameterComplexValues - whether the returned Stream will contain any complex values in component parameters.
      Returns:
      an enhanced Stream with hierarchy context.
    • hasPropertyPlaceholder

      public static boolean hasPropertyPlaceholder(String v)
      Determines if a value depends on a property, as defined by the
       ${...}
       
      markers.
      Parameters:
      v - the value to evaluate.
      Returns:
      true if the provided value contains a property placeholder, false otherwise.
      Since:
      1.1
    • validatorBuilder

      public static ArtifactAstValidatorBuilder validatorBuilder()
      Provides a way to execute validations on an ArtifactAst.
      Returns:
      a builder for an ArtifactAstValidator.
      Since:
      1.1
    • createComponentParameterizationFromComponentAst

      public static <T extends org.mule.runtime.api.meta.model.parameter.ParameterizedModel> org.mule.runtime.api.parameterization.ComponentParameterization<T> createComponentParameterizationFromComponentAst(ComponentAst componentAst)
      Provides a way to create a ComponentParameterization from a ComponentAst.
      Parameters:
      componentAst - the ComponentAst to be transformed.
      Returns:
      a ComponentParameterization.
      Throws:
      IllegalArgumentException - if the ComponentAst model is not a ParameterizedModel
      Since:
      1.1
    • validate

      @Deprecated public static ValidationResult validate(ArtifactAst artifact)
      Deprecated.
      since 1.1, use validatorBuilder() instead.
      Runs all validations available from the current Thread.getContextClassLoader().

      All validations will be run even if failures are found in some. The result will contain all failures.

      Parameters:
      artifact - the artifact to validate
      Returns:
      the result of the validation
    • validate

      @Deprecated public static ValidationResult validate(ArtifactAst artifact, Consumer<ValidationsProvider> validationEnricher)
      Deprecated.
      since 1.1, use validatorBuilder() instead.
      Runs all validations available from the current Thread.getContextClassLoader().

      All validations will be run even if failures are found in some. The result will contain all failures.

      Parameters:
      artifact - the artifact to validate
      validationEnricher - a postprocessor to apply on every discovered ValidationsProvider.
      Returns:
      the result of the validation
    • validate

      @Deprecated public static ValidationResult validate(ArtifactAst artifact, Predicate<Validation> validationsFilter)
      Deprecated.
      since 1.1, use validatorBuilder() instead.
      Runs all validations available from the current Thread.getContextClassLoader().

      All validations will be run even if failures are found in some. The result will contain all failures.

      Parameters:
      artifact - the artifact to validate
      validationsFilter - additional filter to apply on the discovered validations before evaluating them.
      Returns:
      the result of the validation
    • validate

      @Deprecated public static ValidationResult validate(ArtifactAst artifact, Consumer<ValidationsProvider> validationEnricher, Predicate<Validation> validationsFilter, ClassLoader artifactRegionClassLoader)
      Deprecated.
      since 1.1, use validatorBuilder() instead.
      Runs all validations available from the current Thread.getContextClassLoader().

      All validations will be run even if failures are found in some. The result will contain all failures.

      Parameters:
      artifact - the artifact to validate
      validationEnricher - a postprocessor to apply on every discovered ValidationsProvider.
      validationsFilter - additional filter to apply on the discovered validations before evaluating them.
      artifactRegionClassLoader - the classLoader to use to load any resources referenced by the artifact
      Returns:
      the result of the validation
      Since:
      1.1
    • filteredArtifactAst

      public static ArtifactAst filteredArtifactAst(ArtifactAst artifactAst, Predicate<ComponentAst> componentFilter)
      Parameters:
      artifactAst - full ArtifactAst to filter.
      componentFilter - a Predicate to filter the AST components.
      Returns:
      an ArtifactAst with the components filtered by the given componentFilter.
      Since:
      1.4
    • areComponentsEquals

      public static boolean areComponentsEquals(ComponentAst compA, ComponentAst compB)
      Compares the values of the given ComponentAsts for equality behavior-wise.

      `behavior-wise` comparison means that attributes of the ComponentAst that do not affect the behavior of the component (for instance the parsing metadata) are NOT taken into account.

      Parameters:
      compA - one component to compare, non-null.
      compB - the other component to compare, non-null.
      Returns:
      true if the given components are equals behavior-wise, false otherwise.
      Since:
      1.5
    • areParametersEquals

      public static boolean areParametersEquals(ComponentParameterAst paramA, ComponentParameterAst paramB)
      Compares the values of the given ComponentParameterAsts for equality.
      Parameters:
      paramA - one parameter to compare, non-null.
      paramB - the other parameter to compare, non-null.
      Returns:
      true if the values of the given params are equals, false otherwise.
      Since:
      1.5