Package org.openrewrite.trait
Interface TraitMatcher<U extends Trait<?>>
- Type Parameters:
U- The type ofTraitthat this matcher builds.
- All Known Implementing Classes:
SimpleTraitMatcher
A trait matcher builds
Trait instances when they match the criteria for that trait.
Required constructor arguments in implementing classes represent the minimum information
needed to meaningfully search for this trait. Optional further filtering criteria should
be expressed as setter methods in the builder style (lacking a 'set' prefix and returning
the matcher instance).-
Method Summary
Modifier and TypeMethodDescriptiondefault <P> TreeVisitor<? extends Tree,P> asVisitor(VisitFunction<U> visitor) <P> TreeVisitor<? extends Tree,P> asVisitor(VisitFunction2<U, P> visitor) 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.lower(SourceFile sourceFile) Looks down the syntax tree starting at the source file (root LST) for trees that match the trait.default Udefault U
-
Method Details
-
require
-
require
-
get
-
get
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.- 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
Looks up the cursor stack (ancestors) for trees that match the 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
Looks down the syntax tree starting at the cursor stack (descendents) for trees that match the trait.- Parameters:
cursor- The starting point of the search.- Returns:
- A stream of trees that are descendents of the cursor that match the trait.
-
lower
Looks down the syntax tree starting at the source file (root LST) for trees that match the trait.- Parameters:
sourceFile- A whole source file.- Returns:
- A stream of all trees in a source file that match the trait.
-
asVisitor
- Type Parameters:
P- The type of context object passed to the visitor.- Parameters:
visitor- Called for each match of the trait. The function is passed the trait.- Returns:
- A visitor that can be used to inspect or modify trees matching the trait.
-
asVisitor
- Type Parameters:
P- The type of context object passed to the visitor.- Parameters:
visitor- Called for each match of the trait. The function is passed the trait and a context object.- Returns:
- A visitor that can be used to inspect or modify trees matching the trait.
-