Package org.openrewrite.java
Class JavaVisitor<P>
java.lang.Object
org.openrewrite.TreeVisitor<J,P>
org.openrewrite.java.JavaVisitor<P>
- Direct Known Subclasses:
CountLinesVisitor
,ExtractField
,InvertCondition
,JavaIsoVisitor
,JavaPrinter
,NoMissingTypes
,UnwrapParentheses
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<J2 extends J>
J2autoFormat
(J2 j, @Nullable J stopAfter, P p, org.openrewrite.Cursor cursor) <J2 extends J>
J2autoFormat
(J2 j, P p) <J2 extends J>
J2autoFormat
(J2 j, P p, org.openrewrite.Cursor cursor) protected @Nullable String
describeLocation
(org.openrewrite.Cursor cursor) protected JavadocVisitor<P>
This method returns a new instance of a Javadoc visitor that will be used by this JavaVisitor.boolean
isAcceptable
(org.openrewrite.SourceFile sourceFile, P p) 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
(String fullyQualifiedName) This method will add an import to the compilation unit if there is a reference to the type.void
maybeAddImport
(String fullyQualifiedName, boolean onlyIfReferenced) void
maybeAddImport
(String fullyQualifiedName, @Nullable String statik, boolean onlyIfReferenced) void
maybeAddImport
(String fullyQualifiedName, String statik) This method will add a static import to the compilation unit if there is a reference to the type/method.void
This method will add an import to the compilation unit if there is a reference to the type.<J2 extends J>
J2maybeAutoFormat
(J2 before, J2 after, @Nullable J stopAfter, P p, org.openrewrite.Cursor cursor) <J2 extends J>
J2maybeAutoFormat
(J2 before, J2 after, P p) <J2 extends J>
J2maybeAutoFormat
(J2 before, J2 after, P p, org.openrewrite.Cursor cursor) void
maybeRemoveImport
(String fullyQualifiedName) void
visitAnnotatedType
(J.AnnotatedType annotatedType, P p) visitAnnotation
(J.Annotation annotation, P p) visitArrayAccess
(J.ArrayAccess arrayAccess, P p) visitArrayDimension
(J.ArrayDimension arrayDimension, P p) visitArrayType
(J.ArrayType arrayType, P p) visitAssert
(J.Assert azzert, P p) visitAssignment
(J.Assignment assignment, P p) visitAssignmentOperation
(J.AssignmentOperation assignOp, P p) visitBinary
(J.Binary binary, P p) visitBlock
(J.Block block, P p) visitBreak
(J.Break breakStatement, P p) visitCatch
(J.Try.Catch catzh, P p) visitClassDeclaration
(J.ClassDeclaration classDecl, P p) <J2 extends J>
JContainer<J2>visitContainer
(@Nullable JContainer<J2> container, JContainer.Location loc, P p) visitContinue
(J.Continue continueStatement, P p) visitControlParentheses
(J.ControlParentheses<T> controlParens, P p) visitDoWhileLoop
(J.DoWhileLoop doWhileLoop, P p) visitEmpty
(J.Empty empty, P p) visitEnumValue
(J.EnumValue enoom, P p) visitEnumValueSet
(J.EnumValueSet enums, P p) visitExpression
(Expression expression, P p) visitFieldAccess
(J.FieldAccess fieldAccess, P p) visitForControl
(J.ForLoop.Control control, P p) visitForEachControl
(J.ForEachLoop.Control control, P p) visitForEachLoop
(J.ForEachLoop forLoop, P p) visitForLoop
(J.ForLoop forLoop, P p) visitIdentifier
(J.Identifier ident, P p) visitImport
(J.Import impoort, P p) visitInstanceOf
(J.InstanceOf instanceOf, P p) visitLabel
(J.Label label, P p) visitLambda
(J.Lambda lambda, P p) <T> JLeftPadded<T>
visitLeftPadded
(@Nullable JLeftPadded<T> left, JLeftPadded.Location loc, P p) visitLiteral
(J.Literal literal, P p) visitMemberReference
(J.MemberReference memberRef, P p) visitMethodDeclaration
(J.MethodDeclaration method, P p) visitMethodInvocation
(J.MethodInvocation method, P p) visitMultiCatch
(J.MultiCatch multiCatch, P p) visitNewArray
(J.NewArray newArray, P p) visitNewClass
(J.NewClass newClass, P p) visitPackage
(J.Package pkg, P p) visitParameterizedType
(J.ParameterizedType type, P p) visitParentheses
(J.Parentheses<T> parens, P p) visitPrimitive
(J.Primitive primitive, P p) visitReturn
(J.Return retrn, P p) <T> JRightPadded<T>
visitRightPadded
(@Nullable JRightPadded<T> right, JRightPadded.Location loc, P p) visitSpace
(Space space, Space.Location loc, P p) visitStatement
(Statement statement, P p) visitSwitch
(J.Switch switzh, P p) visitSwitchExpression
(J.SwitchExpression switzh, P p) visitSynchronized
(J.Synchronized synch, P p) visitTernary
(J.Ternary ternary, P p) visitThrow
(J.Throw thrown, P p) visitTryResource
(J.Try.Resource tryResource, P p) @Nullable JavaType
visitTypeCast
(J.TypeCast typeCast, P p) <N extends NameTree>
NvisitTypeName
(N nameTree, P p) visitTypeParameter
(J.TypeParameter typeParam, P p) visitUnary
(J.Unary unary, P p) visitVariable
(J.VariableDeclarations.NamedVariable variable, P p) visitVariableDeclarations
(J.VariableDeclarations multiVariable, P p) visitWhileLoop
(J.WhileLoop whileLoop, P p) visitWildcard
(J.Wildcard wildcard, P p) visitYield
(J.Yield yield, P p) Methods inherited from class org.openrewrite.TreeVisitor
adapt, collect, collect, defaultValue, doAfterVisit, getAfterVisit, getCursor, isAdaptableTo, noop, postVisit, preVisit, reduce, reduce, reduce, setCursor, stopAfterPreVisit, updateCursor, visit, visit, visit, visitAndCast, visitAndCast, visitMarker, visitMarkers, visitNonNull, visitNonNull
-
Field Details
-
javadocVisitor
-
-
Constructor Details
-
JavaVisitor
public JavaVisitor()
-
-
Method Details
-
isAcceptable
-
getLanguage
-
getJavadocVisitor
This method returns a new instance of a Javadoc visitor that will be used by this JavaVisitor.- Returns:
- The JavadocVisitor associated with the JavaVisitor.
-
maybeAddImport
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.
-
maybeAutoFormat
-
maybeAutoFormat
-
maybeAutoFormat
-
autoFormat
-
autoFormat
-
autoFormat
-
maybeAddImport
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
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.
-
maybeAddImport
-
maybeAddImport
-
maybeRemoveImport
-
maybeRemoveImport
-
visitExpression
-
visitStatement
-
visitSpace
-
visitType
-
visitTypeName
-
visitAnnotatedType
-
visitAnnotation
-
visitArrayAccess
-
visitArrayDimension
-
visitArrayType
-
visitAssert
-
visitAssignment
-
visitAssignmentOperation
-
visitBinary
-
visitBlock
-
visitBreak
-
visitCase
-
visitCatch
-
visitClassDeclaration
-
visitCompilationUnit
-
visitContinue
-
visitControlParentheses
-
visitDoWhileLoop
-
visitEmpty
-
visitEnumValue
-
visitEnumValueSet
-
visitFieldAccess
-
visitForEachLoop
-
visitForEachControl
-
visitForLoop
-
visitForControl
-
visitIdentifier
-
visitElse
-
visitIf
-
visitImport
-
visitInstanceOf
-
visitLabel
-
visitLambda
-
visitLiteral
-
visitMemberReference
-
visitMethodDeclaration
-
visitMethodInvocation
-
visitMultiCatch
-
visitVariableDeclarations
-
visitNewArray
-
visitNewClass
-
visitPackage
-
visitParameterizedType
-
visitParentheses
-
visitPrimitive
-
visitReturn
-
visitSwitch
-
visitSwitchExpression
-
visitSynchronized
-
visitTernary
-
visitThrow
-
visitTry
-
visitTryResource
-
visitTypeCast
-
visitTypeParameter
-
visitUnary
-
visitVariable
-
visitWhileLoop
-
visitWildcard
-
visitYield
-
visitRightPadded
public <T> JRightPadded<T> visitRightPadded(@Nullable @Nullable JRightPadded<T> right, JRightPadded.Location loc, P p) -
visitLeftPadded
public <T> JLeftPadded<T> visitLeftPadded(@Nullable @Nullable JLeftPadded<T> left, JLeftPadded.Location loc, P p) -
visitContainer
public <J2 extends J> JContainer<J2> visitContainer(@Nullable @Nullable 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
-
describeLocation
-