Package org.openrewrite.trait
Class SimpleTraitMatcher<U extends Trait<?>>
java.lang.Object
org.openrewrite.trait.SimpleTraitMatcher<U>
- All Implemented Interfaces:
TraitMatcher<U>
@Incubating(since="8.30.0")
public abstract class SimpleTraitMatcher<U extends Trait<?>>
extends Object
implements TraitMatcher<U>
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<P> TreeVisitor<? extends Tree,P> asVisitor(VisitFunction2<U, P> visitor) This method is called on every tree.Tests whether a tree at the cursor matches the trait, and if so, returns a trait instance containing the semantic information represented by the tree.Looks up the cursor stack (ancestors) for trees that match the trait.Looks down the syntax tree starting at the cursor stack (descendents) for trees that match the trait.protected abstract U
-
Constructor Details
-
SimpleTraitMatcher
public SimpleTraitMatcher()
-
-
Method Details
-
get
Description copied from interface:TraitMatcherTests whether a tree at the cursor matches the trait, and if so, returns a trait instance containing the semantic information represented by the tree.- Specified by:
getin interfaceTraitMatcher<U extends Trait<?>>- Parameters:
cursor- The starting point of the search.- Returns:
- Optionally a trait instance if the tree pointed at by the cursor matches the trait criteria.
-
higher
Description copied from interface:TraitMatcherLooks up the cursor stack (ancestors) for trees that match the trait.- Specified by:
higherin interfaceTraitMatcher<U extends Trait<?>>- Parameters:
cursor- The starting point of the search.- Returns:
- A stream of trees that are ancestors of the cursor that match the trait.
-
lower
Description copied from interface:TraitMatcherLooks down the syntax tree starting at the cursor stack (descendents) for trees that match the trait.- Specified by:
lowerin interfaceTraitMatcher<U extends Trait<?>>- Parameters:
cursor- The starting point of the search.- Returns:
- A stream of trees that are descendents of the cursor that match the trait.
-
asVisitor
This method is called on every tree. For more performant matching, traits should override and provide a narrower visitor that only callstest(Cursor)against tree types that could potentially match.- Specified by:
asVisitorin interfaceTraitMatcher<U extends Trait<?>>- Type Parameters:
P- The type of the context object.- Parameters:
visitor- Called for each match of the trait. The function is passed the trait, the cursor at which the trait was found, and a context object.- Returns:
- A visitor that can be used to locate trees matching the trait.
-
test
-