Package org.openrewrite
Class Cursor
- java.lang.Object
-
- org.openrewrite.Cursor
-
public class Cursor extends java.lang.Object
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> TcomputeMessageIfAbsent(java.lang.String key, java.util.function.Function<java.lang.String,? extends T> mappingFunction)CursordropParentUntil(java.util.function.Predicate<java.lang.Object> valuePredicate)CursordropParentWhile(java.util.function.Predicate<java.lang.Object> valuePredicate)<T> TfirstEnclosing(java.lang.Class<T> tClass)<T> TfirstEnclosingOrThrow(java.lang.Class<T> tClass)Cursorfork()Creates a cursor at the same position, but with its own messages that can't influence the messages of the cursor that was forked.<T> TgetMessage(java.lang.String key)Finds the closest message matching the provided key, leaving it in the message map for further access.<T> TgetMessage(java.lang.String key, T defaultValue)<T> TgetNearestMessage(java.lang.String key)Finds the closest message matching the provided key, leaving it in the message map for further access.<T> TgetNearestMessage(java.lang.String key, T defaultValue)@Nullable CursorgetParent()@Nullable CursorgetParent(int levels)CursorgetParentOrThrow()CursorgetParentOrThrow(int levels)java.util.Iterator<java.lang.Object>getPath()java.util.Iterator<java.lang.Object>getPath(java.util.function.Predicate<java.lang.Object> filter)java.util.stream.Stream<java.lang.Object>getPathAsStream()java.util.stream.Stream<java.lang.Object>getPathAsStream(java.util.function.Predicate<java.lang.Object> filter)CursorgetRoot()<T> TgetValue()booleanisScopeInPath(Tree scope)<T> TpollMessage(java.lang.String key)Finds the message matching the provided key, removing it from the message map.<T> TpollNearestMessage(java.lang.String key)Finds the closest message matching the provided key, removing it from the message map.voidputMessage(java.lang.String key, java.lang.Object value)voidputMessageOnFirstEnclosing(java.lang.Class<?> enclosing, java.lang.String key, java.lang.Object value)java.lang.StringtoString()
-
-
-
Method Detail
-
getRoot
public Cursor getRoot()
-
getPath
public java.util.Iterator<java.lang.Object> getPath()
-
getPath
public java.util.Iterator<java.lang.Object> getPath(java.util.function.Predicate<java.lang.Object> filter)
-
getPathAsStream
public java.util.stream.Stream<java.lang.Object> getPathAsStream()
-
getPathAsStream
public java.util.stream.Stream<java.lang.Object> getPathAsStream(java.util.function.Predicate<java.lang.Object> filter)
-
firstEnclosing
@Nullable public <T> T firstEnclosing(java.lang.Class<T> tClass)
-
firstEnclosingOrThrow
public <T> T firstEnclosingOrThrow(java.lang.Class<T> tClass)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
dropParentUntil
public Cursor dropParentUntil(java.util.function.Predicate<java.lang.Object> valuePredicate)
-
dropParentWhile
public Cursor dropParentWhile(java.util.function.Predicate<java.lang.Object> valuePredicate)
-
getParent
@Incubating(since="7.0.0") @Nullable public @Nullable Cursor getParent(int levels)
-
getParentOrThrow
@Incubating(since="7.0.0") public Cursor getParentOrThrow(int levels)
-
getParentOrThrow
public Cursor getParentOrThrow()
-
getValue
public <T> T getValue()
-
isScopeInPath
public boolean isScopeInPath(Tree scope)
-
putMessageOnFirstEnclosing
public void putMessageOnFirstEnclosing(java.lang.Class<?> enclosing, java.lang.String key, java.lang.Object value)
-
putMessage
public void putMessage(java.lang.String key, java.lang.Object value)
-
computeMessageIfAbsent
public <T> T computeMessageIfAbsent(java.lang.String key, java.util.function.Function<java.lang.String,? extends T> mappingFunction)
-
getNearestMessage
@Nullable public <T> T getNearestMessage(java.lang.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
nullif none.
-
getNearestMessage
public <T> T getNearestMessage(java.lang.String key, T defaultValue)
-
pollNearestMessage
@Nullable public <T> T pollNearestMessage(java.lang.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
nullif none.
-
getMessage
@Nullable public <T> T getMessage(java.lang.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
nullif none.
-
getMessage
public <T> T getMessage(java.lang.String key, T defaultValue)
-
pollMessage
@Nullable public <T> T pollMessage(java.lang.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
nullif none.
-
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.
-
-