Class ValueToConfigurationProperties

  • All Implemented Interfaces:
    org.openrewrite.java.JavaSourceVisitor<org.openrewrite.java.tree.J>, org.openrewrite.RefactorVisitor<org.openrewrite.java.tree.J>, org.openrewrite.SourceVisitor<org.openrewrite.java.tree.J>

    public class ValueToConfigurationProperties
    extends org.openrewrite.java.JavaRefactorVisitor
    Notes on ValueToConfigurationProperties

    1. Scanning phase: Visit class fields, constructors for @Value annotations create a tree of @Value annotation contents. Given @Values containing these property paths: app.config.bar, app.config.foo, screen.resolution.horizontal, screen.resolution.vertical, screen.refresh-rate The resulting tree should be:

                    root
                /         \
              app         screen
            /           /       \
        config     resolution    refreshRate
        /        /          \
     bar     horizontal     vertical
     
    Store list of classes where every field is @Value annotated as it can be reused instead of generating a new class Store a list of any existing @ConfigurationProperties classes Record list of fields whose names don't match the last piece of their @Value annotations. Leaf nodes of tree have links back to their original appearance(s)

    1.b.: Config Class Generation: For each subtree where there is not an existing ConfigurationProperties class, create a new (empty) ConfigurationProperties class Any new classes should be placed adjacent in the source tree to the Spring Application class

    2. Config Class Update Phase: Go through the config classes and create fields, getters, setters, corresponding to each node of the tree

    3. Reference Update phase: Go through ALL classes and anywhere anything @Value annotated appears, replace it with the corresponding @ConfigurationProperties type. May involve collapsing multiple arguments into a single argument, updating references to those arguments

    • Field Summary

      • Fields inherited from class org.openrewrite.java.JavaRefactorVisitor

        formatter, treeBuilder
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.Collection<org.openrewrite.SourceFile> generate()  
      org.openrewrite.java.tree.J visitClassDecl​(org.openrewrite.java.tree.J.ClassDecl classDecl)  
      org.openrewrite.java.tree.J visitCompilationUnit​(org.openrewrite.java.tree.J.CompilationUnit cu)  
      • Methods inherited from class org.openrewrite.java.JavaRefactorVisitor

        addImport, maybeAddImport, maybeAddImport, maybeRemoveImport, maybeRemoveImport, maybeUnwrapParentheses, visitAnnotatedType, visitAnnotation, visitArrayAccess, visitArrayType, visitAssert, visitAssign, visitAssignOp, visitBinary, visitBlock, visitBreak, visitCase, visitCatch, visitContinue, visitDoWhileLoop, visitElse, visitEmpty, visitEnumValue, visitEnumValueSet, visitFieldAccess, visitFinally, visitForEachLoop, visitForLoop, visitIdentifier, visitIf, visitImport, visitInstanceOf, visitLabel, visitLambda, visitLiteral, visitMemberReference, visitMethod, visitMethodInvocation, visitMultiCatch, visitMultiVariable, visitNewArray, visitNewClass, visitPackage, visitParameterizedType, visitParentheses, visitPrimitive, visitReturn, visitStatement, visitSwitch, visitSynchronized, visitTernary, visitThrow, visitTry, visitTypeCast, visitTypeName, visitTypeParameter, visitTypeParameters, visitUnary, visitUnparsedSource, visitVariable, visitWhileLoop, visitWildcard
      • Methods inherited from class org.openrewrite.AbstractRefactorVisitor

        andThen, andThen, next, refactor, refactor, refactor
      • Methods inherited from class org.openrewrite.AbstractSourceVisitor

        getCursor, setCursoringOn, visit, visitAfter, visitAfter
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface org.openrewrite.java.JavaSourceVisitor

        enclosingBlock, enclosingClass, enclosingCompilationUnit, enclosingMethod, isInSameNameScope, isInSameNameScope, visitExpression
      • Methods inherited from interface org.openrewrite.RefactorVisitor

        defaultTo, isIdempotent, nextCycle
      • Methods inherited from interface org.openrewrite.SourceVisitor

        getCursor, getName, getTags, reduce, validate, visit, visit, visitTree
    • Constructor Detail

      • ValueToConfigurationProperties

        public ValueToConfigurationProperties()
    • Method Detail

      • visitCompilationUnit

        public org.openrewrite.java.tree.J visitCompilationUnit​(org.openrewrite.java.tree.J.CompilationUnit cu)
        Specified by:
        visitCompilationUnit in interface org.openrewrite.java.JavaSourceVisitor<org.openrewrite.java.tree.J>
        Overrides:
        visitCompilationUnit in class org.openrewrite.java.JavaRefactorVisitor
      • visitClassDecl

        public org.openrewrite.java.tree.J visitClassDecl​(org.openrewrite.java.tree.J.ClassDecl classDecl)
        Specified by:
        visitClassDecl in interface org.openrewrite.java.JavaSourceVisitor<org.openrewrite.java.tree.J>
        Overrides:
        visitClassDecl in class org.openrewrite.java.JavaRefactorVisitor
      • generate

        public java.util.Collection<org.openrewrite.SourceFile> generate()