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 Details

    • SimpleTraitMatcher

      public SimpleTraitMatcher()
  • Method Details

    • get

      public Optional<U> get(Cursor cursor)
      Description copied from interface: TraitMatcher
      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.
      Specified by:
      get in interface TraitMatcher<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

      public Stream<U> higher(Cursor cursor)
      Description copied from interface: TraitMatcher
      Looks up the cursor stack (ancestors) for trees that match the trait.
      Specified by:
      higher in interface TraitMatcher<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

      public Stream<U> lower(Cursor cursor)
      Description copied from interface: TraitMatcher
      Looks down the syntax tree starting at the cursor stack (descendents) for trees that match the trait.
      Specified by:
      lower in interface TraitMatcher<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

      public <P> TreeVisitor<? extends Tree,P> asVisitor(VisitFunction2<U,P> visitor)
      This method is called on every tree. For more performant matching, traits should override and provide a narrower visitor that only calls test(Cursor) against tree types that could potentially match.
      Specified by:
      asVisitor in interface TraitMatcher<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

      @Nullable protected abstract U test(Cursor cursor)