Package org.openrewrite
Class Cursor
java.lang.Object
org.openrewrite.Cursor
A cursor is linked path of LST elements that can be used to traverse down the tree towards the root.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid<T> TcomputeMessageIfAbsent(String key, Function<String, ? extends T> mappingFunction) dropParentUntil(Predicate<Object> valuePredicate) dropParentWhile(Predicate<Object> valuePredicate) <T> TfirstEnclosing(Class<T> tClass) <T> TfirstEnclosingOrThrow(Class<T> tClass) 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.<T> TgetMessage(String key) Finds the closest message matching the provided key, leaving it in the message map for further access.<T> TgetMessage(String key, T defaultValue) <T> TgetNearestMessage(String key) Finds the closest message matching the provided key, leaving it in the message map for further access.<T> TgetNearestMessage(String key, T defaultValue) getParent(int levels) getParentOrThrow(int levels) 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.getPath()getPathAsCursors(Predicate<Cursor> filter) getPathAsStream(Predicate<Object> filter) getRoot()<T> TgetValue()booleanisScopeInPath(Tree scope) <T> TpollMessage(String key) Finds the message matching the provided key, removing it from the message map.<T> TpollNearestMessage(String key) Finds the closest message matching the provided key, removing it from the message map.voidputMessage(String key, Object value) voidputMessageOnFirstEnclosing(Class<?> enclosing, String key, Object value) toString()
-
Field Details
-
ROOT_VALUE
- See Also:
-
-
Constructor Details
-
Cursor
-
-
Method Details
-
getRoot
-
getPathAsCursors
-
getPathAsCursors
-
getPath
-
getPath
-
getPathAsStream
-
getPathAsStream
-
firstEnclosing
-
firstEnclosingOrThrow
-
toString
-
dropParentUntil
-
dropParentWhile
-
getParent
-
getParent
-
getParentOrThrow
-
getParentOrThrow
-
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
-
putMessageOnFirstEnclosing
-
putMessage
-
computeMessageIfAbsent
-
getNearestMessage
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
-
pollNearestMessage
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
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
-
pollMessage
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.
-
clearMessages
public void clearMessages() -
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.
-