Class JavaVisitor<P>

    • Field Detail

      • javadocVisitor

        @Nullable
        protected @Nullable JavadocVisitor<P> javadocVisitor
    • Constructor Detail

      • JavaVisitor

        public JavaVisitor()
    • Method Detail

      • isAcceptable

        public boolean isAcceptable​(org.openrewrite.SourceFile sourceFile,
                                    P p)
        Overrides:
        isAcceptable in class org.openrewrite.TreeVisitor<J,​P>
      • getLanguage

        public java.lang.String getLanguage()
        Overrides:
        getLanguage in class org.openrewrite.TreeVisitor<J,​P>
      • getJavadocVisitor

        protected JavadocVisitor<P> 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.
      • dataflow

        @Incubating(since="7.24.0")
        public Dataflow dataflow()
      • 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.
      • maybeAutoFormat

        public <J2 extends J> J2 maybeAutoFormat​(J2 before,
                                                 J2 after,
                                                 P p)
      • maybeAutoFormat

        public <J2 extends J> J2 maybeAutoFormat​(J2 before,
                                                 J2 after,
                                                 P p,
                                                 org.openrewrite.Cursor cursor)
      • maybeAutoFormat

        public <J2 extends J> J2 maybeAutoFormat​(J2 before,
                                                 J2 after,
                                                 @Nullable
                                                 @Nullable J stopAfter,
                                                 P p,
                                                 org.openrewrite.Cursor cursor)
      • autoFormat

        public <J2 extends J> J2 autoFormat​(J2 j,
                                            P p)
      • autoFormat

        public <J2 extends J> J2 autoFormat​(J2 j,
                                            P p,
                                            org.openrewrite.Cursor cursor)
      • autoFormat

        public <J2 extends J> J2 autoFormat​(J2 j,
                                            @Nullable
                                            @Nullable J stopAfter,
                                            P p,
                                            org.openrewrite.Cursor cursor)
      • 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​(java.lang.String fullyQualifiedName)
      • visitExpression

        public J visitExpression​(Expression expression,
                                 P p)
      • visitStatement

        public J visitStatement​(Statement statement,
                                P p)
      • visitType

        @Nullable
        public @Nullable JavaType visitType​(@Nullable
                                            @Nullable JavaType javaType,
                                            P p)
      • visitTypeName

        public <N extends NameTree> N visitTypeName​(N nameTree,
                                                    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)
      • visitAssert

        public J visitAssert​(J.Assert azzert,
                             P p)
      • visitAssignment

        public J visitAssignment​(J.Assignment assignment,
                                 P p)
      • visitBinary

        public J visitBinary​(J.Binary binary,
                             P p)
      • visitBlock

        public J visitBlock​(J.Block block,
                            P p)
      • visitBreak

        public J visitBreak​(J.Break breakStatement,
                            P p)
      • visitCase

        public J visitCase​(J.Case caze,
                           P p)
      • visitJavaSourceFile

        public J visitJavaSourceFile​(JavaSourceFile cu,
                                     P p)
      • visitContinue

        public J visitContinue​(J.Continue continueStatement,
                               P p)
      • visitControlParentheses

        public <T extends JJ visitControlParentheses​(J.ControlParentheses<T> controlParens,
                                                       P p)
      • visitDoWhileLoop

        public J visitDoWhileLoop​(J.DoWhileLoop doWhileLoop,
                                  P p)
      • visitEmpty

        public J visitEmpty​(J.Empty empty,
                            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)
      • visitForLoop

        public J visitForLoop​(J.ForLoop forLoop,
                              P p)
      • visitIdentifier

        public J visitIdentifier​(J.Identifier ident,
                                 P p)
      • visitElse

        public J visitElse​(J.If.Else elze,
                           P p)
      • visitIf

        public J visitIf​(J.If iff,
                         P p)
      • visitImport

        public J visitImport​(J.Import impoort,
                             P p)
      • visitInstanceOf

        public J visitInstanceOf​(J.InstanceOf instanceOf,
                                 P p)
      • visitLabel

        public J visitLabel​(J.Label label,
                            P p)
      • visitLambda

        public J visitLambda​(J.Lambda lambda,
                             P p)
      • visitLiteral

        public J visitLiteral​(J.Literal literal,
                              P p)
      • visitMultiCatch

        public J visitMultiCatch​(J.MultiCatch multiCatch,
                                 P p)
      • visitNewArray

        public J visitNewArray​(J.NewArray newArray,
                               P p)
      • visitNewClass

        public J visitNewClass​(J.NewClass newClass,
                               P p)
      • visitPackage

        public J visitPackage​(J.Package pkg,
                              P p)
      • visitParentheses

        public <T extends JJ visitParentheses​(J.Parentheses<T> parens,
                                                P p)
      • visitPrimitive

        public J visitPrimitive​(J.Primitive primitive,
                                P p)
      • visitReturn

        public J visitReturn​(J.Return retrn,
                             P p)
      • visitSwitch

        public J visitSwitch​(J.Switch switzh,
                             P p)
      • visitSynchronized

        public J visitSynchronized​(J.Synchronized synch,
                                   P p)
      • visitTernary

        public J visitTernary​(J.Ternary ternary,
                              P p)
      • visitThrow

        public J visitThrow​(J.Throw thrown,
                            P p)
      • visitTry

        public J visitTry​(J.Try tryable,
                          P p)
      • visitTryResource

        public J visitTryResource​(J.Try.Resource tryResource,
                                  P p)
      • visitTypeCast

        public J visitTypeCast​(J.TypeCast typeCast,
                               P p)
      • visitTypeParameter

        public J visitTypeParameter​(J.TypeParameter typeParam,
                                    P p)
      • visitUnary

        public J visitUnary​(J.Unary unary,
                            P p)
      • visitWhileLoop

        public J visitWhileLoop​(J.WhileLoop whileLoop,
                                P p)
      • visitWildcard

        public J visitWildcard​(J.Wildcard wildcard,
                               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