java.lang.Object
org.mule.runtime.ast.api.util.MuleAstUtils
Set of utility methods for working with
ArtifactAsts and ComponentAsts.- Since:
- 1.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanareComponentsEquals(ComponentAst compA, ComponentAst compB) Compares the values of the givenComponentAsts for equality behavior-wise.static booleanareParametersEquals(ComponentParameterAst paramA, ComponentParameterAst paramB) Compares the values of the givenComponentParameterAsts for equality.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 aComponentParameterizationfrom aComponentAst.static voiddoOnParamComponents(ComponentParameterAst param, Consumer<ComponentAst> action) Performs a given action on theComponentAsts that form the value of the provided parameter.static ArtifactAstProvides a singleton emptyArtifactAstinstance.static ArtifactAstfilteredArtifactAst(ArtifactAst artifactAst, Predicate<ComponentAst> componentFilter) static booleanDetermines if a value depends on a property, as defined by thestatic Optional<ComponentParameterAst>parameterOfType(ComponentAst referent, org.mule.runtime.api.meta.model.stereotype.StereotypeModel referenceStereotype) Given aComponentAst, lookup for a parameter that references an object with a certain stereotype.static List<ComponentParameterAst>parametersOfType(ComponentAst referent, org.mule.runtime.api.meta.model.stereotype.StereotypeModel referenceStereotype) Given aComponentAst, lookup for all parameters that reference an object with a certain stereotype.static Stream<org.mule.runtime.api.util.Pair<ComponentAst,List<ComponentAst>>> recursiveStreamWithHierarchy(ArtifactAst artifact) Similar toArtifactAst.recursiveStream(), but it enhances theStreamby adding hierarchy context to each item.static Stream<org.mule.runtime.api.util.Pair<ComponentAst,List<ComponentAst>>> recursiveStreamWithHierarchy(ArtifactAst artifact, AstTraversalDirection direction) Similar toArtifactAst.recursiveStream(), but it enhances theStreamby adding hierarchy context to each item.static Stream<org.mule.runtime.api.util.Pair<ComponentAst,List<ComponentAst>>> recursiveStreamWithHierarchy(ArtifactAst artifact, AstTraversalDirection direction, boolean ignoreParameterComplexValues) Similar toArtifactAst.recursiveStream(), but it enhances theStreamby adding hierarchy context to each item.static Set<ComponentAst>resolveOrphanComponents(ArtifactAst appModel) Given anArtifactAst, return all those components within it that are not accessible from a top-level component.static ValidationResultvalidate(ArtifactAst artifact) Deprecated.static ValidationResultvalidate(ArtifactAst artifact, Consumer<ValidationsProvider> validationEnricher) Deprecated.since 1.1, usevalidatorBuilder()instead.static ValidationResultvalidate(ArtifactAst artifact, Consumer<ValidationsProvider> validationEnricher, Predicate<Validation> validationsFilter, ClassLoader artifactRegionClassLoader) Deprecated.since 1.1, usevalidatorBuilder()instead.static ValidationResultvalidate(ArtifactAst artifact, Predicate<Validation> validationsFilter) Deprecated.since 1.1, usevalidatorBuilder()instead.static ArtifactAstValidatorBuilderProvides a way to execute validations on anArtifactAst.
-
Method Details
-
resolveOrphanComponents
Given anArtifactAst, 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
appModelthat are not accessible from a top-level component.
-
emptyArtifact
Provides a singleton emptyArtifactAstinstance.- Returns:
- an
ArtifactAstwithout components.
-
parameterOfType
public static Optional<ComponentParameterAst> parameterOfType(ComponentAst referent, org.mule.runtime.api.meta.model.stereotype.StereotypeModel referenceStereotype) Given aComponentAst, lookup for a parameter that references an object with a certain stereotype.- Parameters:
referent- theComponentAstthat will be checked for the reference.referenceStereotype- theStereotypeModelto check for.- Returns:
- any
ComponentParameterAstrepresenting a parameter ofreferentthat references an object assignable toreferenceStereotype, if it exists.
-
parametersOfType
public static List<ComponentParameterAst> parametersOfType(ComponentAst referent, org.mule.runtime.api.meta.model.stereotype.StereotypeModel referenceStereotype) Given aComponentAst, lookup for all parameters that reference an object with a certain stereotype.- Parameters:
referent- theComponentAstthat will be checked for the reference.referenceStereotype- theStereotypeModelto check for.- Returns:
- all
ComponentParameterAsts representing parameters ofreferentthat reference an object assignable toreferenceStereotype.
-
doOnParamComponents
Performs a given action on theComponentAsts that form the value of the provided parameter.- Parameters:
param- the parameter on which complex parameter values theactionwill 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 toArtifactAst.recursiveStream(), but it enhances theStreamby adding hierarchy context to each item. TheArtifactAstis traversed inTOP_DOWNdirection.The elements of the
StreamarePairs:- 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- theArtifactAstto generate aStreamfor.- Returns:
- an enhanced
Streamwith hierarchy context.
- the first element is the same component that would be obtained by calling
-
recursiveStreamWithHierarchy
public static Stream<org.mule.runtime.api.util.Pair<ComponentAst,List<ComponentAst>>> recursiveStreamWithHierarchy(ArtifactAst artifact, AstTraversalDirection direction) Similar toArtifactAst.recursiveStream(), but it enhances theStreamby adding hierarchy context to each item. TheArtifactAstis traversed inAstTraversalDirectiondirectionThe elements of the
StreamarePairs:- 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- theArtifactAstto generate aStreamfor.direction- theAstTraversalDirectionused to navigate theartifact.ignoreParameterComplexValues- whether the returnedStreamwill contain any complex values in component parameters.- Returns:
- an enhanced
Streamwith hierarchy context.
- the first element is the same component that would be obtained by calling
-
recursiveStreamWithHierarchy
public static Stream<org.mule.runtime.api.util.Pair<ComponentAst,List<ComponentAst>>> recursiveStreamWithHierarchy(ArtifactAst artifact, AstTraversalDirection direction, boolean ignoreParameterComplexValues) Similar toArtifactAst.recursiveStream(), but it enhances theStreamby adding hierarchy context to each item. TheArtifactAstis traversed inAstTraversalDirectiondirectionThe elements of the
StreamarePairs:- 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- theArtifactAstto generate aStreamfor.direction- theAstTraversalDirectionused to navigate theartifact.ignoreParameterComplexValues- whether the returnedStreamwill contain any complex values in component parameters.- Returns:
- an enhanced
Streamwith hierarchy context.
- the first element is the same component that would be obtained by calling
-
hasPropertyPlaceholder
Determines if a value depends on a property, as defined by the${...}markers.- Parameters:
v- the value to evaluate.- Returns:
trueif the provided value contains a property placeholder,falseotherwise.- Since:
- 1.1
-
validatorBuilder
Provides a way to execute validations on anArtifactAst.- 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 aComponentParameterizationfrom aComponentAst.- Parameters:
componentAst- theComponentAstto be transformed.- Returns:
- a
ComponentParameterization. - Throws:
IllegalArgumentException- if theComponentAstmodel is not aParameterizedModel- Since:
- 1.1
-
validate
Deprecated.since 1.1, usevalidatorBuilder()instead.Runs all validations available from the currentThread.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, usevalidatorBuilder()instead.Runs all validations available from the currentThread.getContextClassLoader().All validations will be run even if failures are found in some. The result will contain all failures.
- Parameters:
artifact- the artifact to validatevalidationEnricher- a postprocessor to apply on every discoveredValidationsProvider.- Returns:
- the result of the validation
-
validate
@Deprecated public static ValidationResult validate(ArtifactAst artifact, Predicate<Validation> validationsFilter) Deprecated.since 1.1, usevalidatorBuilder()instead.Runs all validations available from the currentThread.getContextClassLoader().All validations will be run even if failures are found in some. The result will contain all failures.
- Parameters:
artifact- the artifact to validatevalidationsFilter- 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, usevalidatorBuilder()instead.Runs all validations available from the currentThread.getContextClassLoader().All validations will be run even if failures are found in some. The result will contain all failures.
- Parameters:
artifact- the artifact to validatevalidationEnricher- a postprocessor to apply on every discoveredValidationsProvider.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- fullArtifactAstto filter.componentFilter- aPredicateto filter theAST components.- Returns:
- an
ArtifactAstwith the components filtered by the givencomponentFilter. - Since:
- 1.4
-
areComponentsEquals
Compares the values of the givenComponentAsts for equality behavior-wise.`behavior-wise` comparison means that attributes of the
ComponentAstthat 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:
trueif the given components are equals behavior-wise,falseotherwise.- Since:
- 1.5
-
areParametersEquals
public static boolean areParametersEquals(ComponentParameterAst paramA, ComponentParameterAst paramB) Compares the values of the givenComponentParameterAsts for equality.- Parameters:
paramA- one parameter to compare, non-null.paramB- the other parameter to compare, non-null.- Returns:
trueif the values of the given params are equals,falseotherwise.- Since:
- 1.5
-
validatorBuilder()instead.