Package org.openrewrite
Class Cursor
java.lang.Object
org.openrewrite.Cursor
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
<T> T
computeMessageIfAbsent
(String key, Function<String, ? extends T> mappingFunction) dropParentUntil
(Predicate<Object> valuePredicate) dropParentWhile
(Predicate<Object> valuePredicate) <T> T
firstEnclosing
(Class<T> tClass) <T> T
firstEnclosingOrThrow
(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> T
getMessage
(String key) Finds the closest message matching the provided key, leaving it in the message map for further access.<T> T
getMessage
(String key, T defaultValue) <T> T
getNearestMessage
(String key) Finds the closest message matching the provided key, leaving it in the message map for further access.<T> T
getNearestMessage
(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> T
getValue()
boolean
isScopeInPath
(Tree scope) <T> T
pollMessage
(String key) Finds the message matching the provided key, removing it from the message map.<T> T
pollNearestMessage
(String key) Finds the closest message matching the provided key, removing it from the message map.void
putMessage
(String key, Object value) void
putMessageOnFirstEnclosing
(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
null
if 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
null
if 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
null
if 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
null
if 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.
-