Class Cursor

java.lang.Object
org.openrewrite.Cursor

public class Cursor extends Object
  • Field Details

  • Constructor Details

  • Method Details

    • getRoot

      public Cursor getRoot()
    • getPathAsCursors

      public Iterator<Cursor> getPathAsCursors()
    • getPathAsCursors

      public Iterator<Cursor> getPathAsCursors(Predicate<Cursor> filter)
    • getPath

      public Iterator<Object> getPath()
    • getPath

      public Iterator<Object> getPath(Predicate<Object> filter)
    • getPathAsStream

      public Stream<Object> getPathAsStream()
    • getPathAsStream

      public Stream<Object> getPathAsStream(Predicate<Object> filter)
    • firstEnclosing

      @Nullable public <T> T firstEnclosing(Class<T> tClass)
    • firstEnclosingOrThrow

      public <T> T firstEnclosingOrThrow(Class<T> tClass)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • dropParentUntil

      public Cursor dropParentUntil(Predicate<Object> valuePredicate)
    • dropParentWhile

      public Cursor dropParentWhile(Predicate<Object> valuePredicate)
    • getParent

      @Nullable public @Nullable Cursor getParent(int levels)
    • getParent

      @Nullable public @Nullable Cursor getParent()
    • getParentOrThrow

      public Cursor getParentOrThrow(int levels)
    • getParentOrThrow

      public Cursor getParentOrThrow()
    • getParentTreeCursor

      public Cursor getParentTreeCursor()
      Return the first parent of the current cursor which points to an AST element, or the root cursor if the current cursor already points to the root AST element. This skips over non-tree Padding elements.
      If you do want to access Padding elements, use getParent() or getParentOrThrow(), which do not skip over these elements.
      Returns:
      a cursor which either points at the first non-padding parent of the current element
    • getValue

      public <T> T getValue()
    • isScopeInPath

      public boolean isScopeInPath(Tree scope)
    • putMessageOnFirstEnclosing

      public void putMessageOnFirstEnclosing(Class<?> enclosing, String key, Object value)
    • putMessage

      public void putMessage(String key, Object value)
    • computeMessageIfAbsent

      public <T> T computeMessageIfAbsent(String key, Function<String,? extends T> mappingFunction)
    • getNearestMessage

      @Nullable public <T> T getNearestMessage(String key)
      Finds the closest message matching the provided key, leaving it in the message map for further access.
      Type Parameters:
      T - The expected value of the message.
      Parameters:
      key - The message key to find.
      Returns:
      The closest message matching the provided key in the cursor stack, or null if none.
    • getNearestMessage

      public <T> T getNearestMessage(String key, T defaultValue)
    • pollNearestMessage

      @Nullable public <T> T pollNearestMessage(String key)
      Finds the closest message matching the provided key, removing it from the message map.
      Type Parameters:
      T - The expected value of the message.
      Parameters:
      key - The message key to find.
      Returns:
      The closest message matching the provided key in the cursor stack, or null if none.
    • getMessage

      @Nullable public <T> T getMessage(String key)
      Finds the closest message matching the provided key, leaving it in the message map for further access.
      Type Parameters:
      T - The expected value of the message.
      Parameters:
      key - The message key to find.
      Returns:
      The message matching the provided key, or null if none.
    • getMessage

      public <T> T getMessage(String key, T defaultValue)
    • pollMessage

      @Nullable public <T> T pollMessage(String key)
      Finds the message matching the provided key, removing it from the message map.
      Type Parameters:
      T - The expected value of the message.
      Parameters:
      key - The message key to find.
      Returns:
      The message matching the provided key, or null if none.
    • clearMessages

      public void clearMessages()
    • fork

      public Cursor fork()
      Creates a cursor at the same position, but with its own messages that can't influence the messages of the cursor that was forked.
      Returns:
      A new cursor with the same position but an initially clear set of messages.