Package org.openrewrite
Class TreeVisitor<T extends Tree,P>
- java.lang.Object
-
- org.openrewrite.TreeVisitor<T,P>
-
- Type Parameters:
T
- The type of tree.P
- An input object that is passed to every visit method.
- Direct Known Subclasses:
HasSourcePath
,PlainTextVisitor
,PolyglotVisitor
public abstract class TreeVisitor<T extends Tree,P> extends java.lang.Object
AbstractTreeVisitor
for processingelements
Always returns input type T provides Parameterizable P input which is mutable allowing context to be shared
postProcessing via afterVisit for conditionally chaining other operations with the expectation is that after TreeVisitors are invoked immediately after visiting SourceFile
-
-
Constructor Summary
Constructors Constructor Description TreeVisitor()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
debugOnChange(@Nullable Tree before, @Nullable Tree after)
A debugging probe that is only called if a tree changes and either the org.openrewrite.debug system property is set or the process is running in debug mode.T
defaultValue(@Nullable Tree tree, P p)
protected void
doAfterVisit(Recipe recipe)
Execute the recipe's main visitor once after the whole source file has been visited.protected void
doAfterVisit(TreeVisitor<T,P> visitor)
Execute the visitor once after the whole source file has been visited.protected java.util.List<TreeVisitor<T,P>>
getAfterVisit()
Cursor
getCursor()
@Nullable java.lang.String
getLanguage()
boolean
isAcceptable(SourceFile sourceFile, ExecutionContext ctx)
static <T extends Tree,P>
TreeVisitor<T,P>noop()
T
postVisit(T tree, P p)
T
preVisit(T tree, P p)
protected void
setCursor(@Nullable Cursor cursor)
void
visit(@Nullable java.util.List<? extends T> nodes, P p)
T
visit(@Nullable Tree tree, P p)
T
visit(@Nullable Tree tree, P p, Cursor parent)
protected <T2 extends T>
T2visitAndCast(@Nullable Tree tree, P p)
protected <T2 extends Tree>
T2visitAndCast(T2 t, P p, java.util.function.BiFunction<T2,P,Tree> callSuper)
<M extends Marker>
MvisitMarker(Marker marker, P p)
Markers
visitMarkers(Markers markers, P p)
T
visitNonNull(Tree tree, P p)
By calling this method, you are asserting that you know that the outcome will be non-null when the compiler couldn't otherwise prove this to be the case.T
visitNonNull(Tree tree, P p, Cursor parent)
-
-
-
Method Detail
-
noop
public static <T extends Tree,P> TreeVisitor<T,P> noop()
-
isAcceptable
public boolean isAcceptable(SourceFile sourceFile, ExecutionContext ctx)
-
getLanguage
@Nullable public @Nullable java.lang.String getLanguage()
- Returns:
- Describes the language type that this visitor applies to, e.g. java, xml, properties.
-
doAfterVisit
protected void doAfterVisit(TreeVisitor<T,P> visitor)
Execute the visitor once after the whole source file has been visited. The visitor is executed against the whole source file. This operation only happens once immediately after the containing visitor visits the whole source file. A subsequentRecipe
cycle will not run it.This method is ideal for one-off operations like auto-formatting, adding/removing imports, etc.
- Parameters:
visitor
- The visitor to run.
-
doAfterVisit
@Incubating(since="7.0.0") protected void doAfterVisit(Recipe recipe)
Execute the recipe's main visitor once after the whole source file has been visited. The visitor is executed against the whole source file. This operation only happens once immediately after the containing visitor visits the whole source file. A subsequentRecipe
cycle will not run it.This method is ideal for one-off operations like auto-formatting, adding/removing imports, etc.
- Parameters:
recipe
- The recipe whose visitor to run.
-
getAfterVisit
protected java.util.List<TreeVisitor<T,P>> getAfterVisit()
-
getCursor
public final Cursor getCursor()
-
visitNonNull
public T visitNonNull(Tree tree, P p)
By calling this method, you are asserting that you know that the outcome will be non-null when the compiler couldn't otherwise prove this to be the case. This method is a shortcut for having to assert the non-nullability of the returned tree.- Parameters:
tree
- A non-null tree.p
- A state object that passes through the visitor.- Returns:
- A non-null tree.
-
debugOnChange
@Incubating(since="7.3.0") protected void debugOnChange(@Nullable @Nullable Tree before, @Nullable @Nullable Tree after)
A debugging probe that is only called if a tree changes and either the org.openrewrite.debug system property is set or the process is running in debug mode.
-
visitAndCast
@Incubating(since="7.0.0") protected final <T2 extends Tree> T2 visitAndCast(T2 t, P p, java.util.function.BiFunction<T2,P,Tree> callSuper)
-
visitAndCast
@Incubating(since="7.0.0") @Nullable protected final <T2 extends T> T2 visitAndCast(@Nullable @Nullable Tree tree, P p)
-
visitMarkers
@Incubating(since="7.2.0") public Markers visitMarkers(Markers markers, P p)
-
visitMarker
@Incubating(since="7.2.0") public <M extends Marker> M visitMarker(Marker marker, P p)
-
-