Package org.openrewrite.java
Class JavaVisitor<P>
- java.lang.Object
-
- org.openrewrite.TreeVisitor<J,P>
-
- org.openrewrite.java.JavaVisitor<P>
-
- Direct Known Subclasses:
AutoFormatVisitor
,JavaIsoVisitor
,JavaListMarkersVisitor
,JavaPrinter
,UnwrapParentheses
public class JavaVisitor<P> extends org.openrewrite.TreeVisitor<J,P>
-
-
Constructor Summary
Constructors Constructor Description JavaVisitor()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
isInSameNameScope(org.openrewrite.Cursor child)
Check if a child AST element is in the same lexical scope as that of the AST element associated with the current cursor.protected boolean
isInSameNameScope(org.openrewrite.Cursor base, org.openrewrite.Cursor child)
Check if a child AST element is in the same lexical scope as that of the AST element associated with the base cursor.void
maybeAddImport(java.lang.String fullyQualifiedName)
This method will add an import to the compilation unit if there is a reference to the type.void
maybeAddImport(java.lang.String fullyQualifiedName, java.lang.String statik)
This method will add a static import to the compilation unit if there is a reference to the type/method.void
maybeAddImport(JavaType.FullyQualified clazz)
This method will add an import to the compilation unit if there is a reference to the type.void
maybeRemoveImport(java.lang.String fullyQualifiedName)
void
maybeRemoveImport(JavaType.FullyQualified clazz)
J
visitAnnotatedType(J.AnnotatedType annotatedType, P p)
J
visitAnnotation(J.Annotation annotation, P p)
J
visitArrayAccess(J.ArrayAccess arrayAccess, P p)
J
visitArrayDimension(J.ArrayDimension arrayDimension, P p)
J
visitArrayType(J.ArrayType arrayType, P p)
J
visitAssert(J.Assert azzert, P p)
J
visitAssign(J.Assign assign, P p)
J
visitAssignOp(J.AssignOp assignOp, P p)
J
visitBinary(J.Binary binary, P p)
J
visitBlock(J.Block block, P p)
J
visitBreak(J.Break breakStatement, P p)
J
visitCase(J.Case caze, P p)
J
visitCatch(J.Try.Catch catzh, P p)
J
visitClassDecl(J.ClassDecl classDecl, P p)
J
visitCompilationUnit(J.CompilationUnit cu, P p)
<J2 extends J>
JContainer<J2>visitContainer(JContainer<J2> container, JContainer.Location loc, P p)
J
visitContinue(J.Continue continueStatement, P p)
<T extends J>
JvisitControlParentheses(J.ControlParentheses<T> controlParens, P p)
J
visitDoWhileLoop(J.DoWhileLoop doWhileLoop, P p)
J
visitElse(J.If.Else elze, P p)
J
visitEmpty(J.Empty empty, P p)
J
visitEnumValue(J.EnumValue enoom, P p)
J
visitEnumValueSet(J.EnumValueSet enums, P p)
J
visitExpression(Expression expression, P p)
J
visitFieldAccess(J.FieldAccess fieldAccess, P p)
J
visitForControl(J.ForLoop.Control control, P p)
J
visitForEachControl(J.ForEachLoop.Control control, P p)
J
visitForEachLoop(J.ForEachLoop forLoop, P p)
J
visitForLoop(J.ForLoop forLoop, P p)
J
visitIdentifier(J.Ident ident, P p)
J
visitIf(J.If iff, P p)
J
visitImport(J.Import impoort, P p)
J
visitInstanceOf(J.InstanceOf instanceOf, P p)
J
visitLabel(J.Label label, P p)
J
visitLambda(J.Lambda lambda, P p)
<T> JLeftPadded<T>
visitLeftPadded(JLeftPadded<T> left, JLeftPadded.Location loc, P p)
J
visitLiteral(J.Literal literal, P p)
J
visitMemberReference(J.MemberReference memberRef, P p)
J
visitMethod(J.MethodDecl method, P p)
J
visitMethodInvocation(J.MethodInvocation method, P p)
J
visitMultiCatch(J.MultiCatch multiCatch, P p)
J
visitMultiVariable(J.VariableDecls multiVariable, P p)
J
visitNewArray(J.NewArray newArray, P p)
J
visitNewClass(J.NewClass newClass, P p)
J
visitPackage(J.Package pkg, P p)
J
visitParameterizedType(J.ParameterizedType type, P p)
<T extends J>
JvisitParentheses(J.Parentheses<T> parens, P p)
J
visitPrimitive(J.Primitive primitive, P p)
J
visitReturn(J.Return retrn, P p)
<J2 extends J>
JRightPadded<J2>visitRightPadded(JRightPadded<J2> right, JRightPadded.Location type, P p)
Space
visitSpace(Space space, P p)
J
visitStatement(Statement statement, P p)
J
visitSwitch(J.Switch switzh, P p)
J
visitSynchronized(J.Synchronized synch, P p)
J
visitTernary(J.Ternary ternary, P p)
J
visitThrow(J.Throw thrown, P p)
J
visitTry(J.Try tryable, P p)
J
visitTypeCast(J.TypeCast typeCast, P p)
<N extends NameTree>
NvisitTypeName(N nameTree, P p)
J
visitTypeParameter(J.TypeParameter typeParam, P p)
J
visitUnary(J.Unary unary, P p)
J
visitVariable(J.VariableDecls.NamedVar variable, P p)
J
visitWhileLoop(J.WhileLoop whileLoop, P p)
J
visitWildcard(J.Wildcard wildcard, P p)
-
-
-
Method Detail
-
maybeAddImport
public void maybeAddImport(@Nullable JavaType.FullyQualified clazz)
This method will add an import to the compilation unit if there is a reference to the type. It adds an additional visitor which means the "add import" is deferred and does not complete immediately. This operation is idempotent and calling this method multiple times with the same arguments will only add an import once.- Parameters:
clazz
- The class that will be imported into the compilation unit.
-
maybeAddImport
public void maybeAddImport(java.lang.String fullyQualifiedName)
This method will add an import to the compilation unit if there is a reference to the type. It adds an additional visitor which means the "add import" is deferred and does not complete immediately. This operation is idempotent and calling this method multiple times with the same arguments will only add an import once.- Parameters:
fullyQualifiedName
- Fully-qualified name of the class.
-
maybeAddImport
public void maybeAddImport(java.lang.String fullyQualifiedName, java.lang.String statik)
This method will add a static import to the compilation unit if there is a reference to the type/method. It adds an additional visitor which means the "add import" is deferred and does not complete immediately. This operation is idempotent and calling this method multiple times with the same arguments will only add an import once.- Parameters:
fullyQualifiedName
- Fully-qualified name of the class.statik
- The static method or field to be imported. A wildcard "*" may also be used to statically import all methods/fields.
-
maybeRemoveImport
public void maybeRemoveImport(@Nullable JavaType.FullyQualified clazz)
-
maybeRemoveImport
public void maybeRemoveImport(java.lang.String fullyQualifiedName)
-
visitExpression
public J visitExpression(Expression expression, P p)
-
visitAnnotatedType
public J visitAnnotatedType(J.AnnotatedType annotatedType, P p)
-
visitAnnotation
public J visitAnnotation(J.Annotation annotation, P p)
-
visitArrayAccess
public J visitArrayAccess(J.ArrayAccess arrayAccess, P p)
-
visitArrayDimension
public J visitArrayDimension(J.ArrayDimension arrayDimension, P p)
-
visitArrayType
public J visitArrayType(J.ArrayType arrayType, P p)
-
visitAssignOp
public J visitAssignOp(J.AssignOp assignOp, P p)
-
visitCatch
public J visitCatch(J.Try.Catch catzh, P p)
-
visitClassDecl
public J visitClassDecl(J.ClassDecl classDecl, P p)
-
visitCompilationUnit
public J visitCompilationUnit(J.CompilationUnit cu, P p)
-
visitContinue
public J visitContinue(J.Continue continueStatement, P p)
-
visitControlParentheses
public <T extends J> J visitControlParentheses(J.ControlParentheses<T> controlParens, P p)
-
visitDoWhileLoop
public J visitDoWhileLoop(J.DoWhileLoop doWhileLoop, P p)
-
visitEnumValue
public J visitEnumValue(J.EnumValue enoom, P p)
-
visitEnumValueSet
public J visitEnumValueSet(J.EnumValueSet enums, P p)
-
visitFieldAccess
public J visitFieldAccess(J.FieldAccess fieldAccess, P p)
-
visitForEachLoop
public J visitForEachLoop(J.ForEachLoop forLoop, P p)
-
visitForEachControl
public J visitForEachControl(J.ForEachLoop.Control control, P p)
-
visitForControl
public J visitForControl(J.ForLoop.Control control, P p)
-
visitInstanceOf
public J visitInstanceOf(J.InstanceOf instanceOf, P p)
-
visitMemberReference
public J visitMemberReference(J.MemberReference memberRef, P p)
-
visitMethod
public J visitMethod(J.MethodDecl method, P p)
-
visitMethodInvocation
public J visitMethodInvocation(J.MethodInvocation method, P p)
-
visitMultiCatch
public J visitMultiCatch(J.MultiCatch multiCatch, P p)
-
visitMultiVariable
public J visitMultiVariable(J.VariableDecls multiVariable, P p)
-
visitNewArray
public J visitNewArray(J.NewArray newArray, P p)
-
visitNewClass
public J visitNewClass(J.NewClass newClass, P p)
-
visitParameterizedType
public J visitParameterizedType(J.ParameterizedType type, P p)
-
visitParentheses
public <T extends J> J visitParentheses(J.Parentheses<T> parens, P p)
-
visitPrimitive
public J visitPrimitive(J.Primitive primitive, P p)
-
visitSynchronized
public J visitSynchronized(J.Synchronized synch, P p)
-
visitTypeCast
public J visitTypeCast(J.TypeCast typeCast, P p)
-
visitTypeParameter
public J visitTypeParameter(J.TypeParameter typeParam, P p)
-
visitVariable
public J visitVariable(J.VariableDecls.NamedVar variable, P p)
-
visitWhileLoop
public J visitWhileLoop(J.WhileLoop whileLoop, P p)
-
visitWildcard
public J visitWildcard(J.Wildcard wildcard, P p)
-
visitRightPadded
public <J2 extends J> JRightPadded<J2> visitRightPadded(JRightPadded<J2> right, JRightPadded.Location type, P p)
-
visitLeftPadded
public <T> JLeftPadded<T> visitLeftPadded(JLeftPadded<T> left, JLeftPadded.Location loc, P p)
-
visitContainer
public <J2 extends J> JContainer<J2> visitContainer(JContainer<J2> container, JContainer.Location loc, P p)
-
isInSameNameScope
protected boolean isInSameNameScope(org.openrewrite.Cursor base, org.openrewrite.Cursor child)
Check if a child AST element is in the same lexical scope as that of the AST element associated with the base cursor. (i.e.: Are the variables and declarations visible in the base scope also visible to the child AST element?)The base lexical scope is first established by walking up the path of the base cursor to find its first enclosing element. The child path is traversed by walking up the child path elements until either the base scope has been found, a "terminating" element is encountered, or there are no more elements in the path.
A terminating element is one of the following:
- A static class declaration
- An enumeration declaration
- An interface declaration
- An annotation declaration
- Parameters:
base
- A pointer within the AST that is used to establish the "base lexical scope".child
- A pointer within the AST that will be traversed (up the tree) looking for an intersection with the base lexical scope.- Returns:
- true if the child is in within the lexical scope of the base
-
isInSameNameScope
protected boolean isInSameNameScope(org.openrewrite.Cursor child)
Check if a child AST element is in the same lexical scope as that of the AST element associated with the current cursor.See
isInSameNameScope(org.openrewrite.Cursor, org.openrewrite.Cursor)
- Parameters:
child
- A pointer to an element within the abstract syntax tree- Returns:
- true if the child is in within the lexical scope of the current cursor
-
-