Interface TraitMatcher<U extends Trait<?>>

Type Parameters:
U - The type of Trait that this matcher builds.
All Known Implementing Classes:
SimpleTraitMatcher

@Incubating(since="8.30.0") public interface TraitMatcher<U extends Trait<?>>
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 Details

    • require

      default U require(Tree tree, Cursor parent)
    • require

      default U require(Cursor cursor)
    • get

      default Optional<U> get(Tree tree, Cursor parent)
    • get

      Optional<U> get(Cursor cursor)
      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

      Stream<U> higher(Cursor cursor)
      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

      Stream<U> lower(Cursor cursor)
      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

      default Stream<U> lower(SourceFile sourceFile)
      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

      default <P> TreeVisitor<? extends Tree,P> asVisitor(VisitFunction<U> visitor)
      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

      <P> TreeVisitor<? extends Tree,P> asVisitor(VisitFunction2<U,P> visitor)
      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.