A practitioner’s primer on deterministic software modernization

Learn extra at:

// Supply code snippet
// The person's identify
personal String identify = "Java";

// LST illustration
J.VariableDeclarations | "// The person's namenprivate String identify = "Java""
|---J.Modifier | "personal"
|---J.Identifier | "String"
---J.VariableDeclarations.NamedVariable | "identify = "Java""
    |---J.Identifier | "identify"
    ---J.Literal | ""Java""

Recipes work with many alternative file sorts together with XML or YAML to change issues like Maven POMs or different configuration recordsdata. Additionally they can create new recordsdata when wanted as a part of migrations. However recipes don’t even have to change code in any respect. A robust characteristic and good thing about the wealthy information from the LST is that they might simply collect information and insights, analyzing code bases to generate information tables for use for studies, metrics, or visualizations that assist groups perceive their code earlier than making adjustments.

Testing recipes: Deterministic and dependable

OpenRewrite’s deterministic nature makes recipes easy to test. Right here’s how easy it’s to visualise the adjustments a recipe ought to make, and to confirm it really works accurately:

@Check
void migrateJUnitTest() {
    rewriteRun(
        // The recipe to check
        new MigrateToJUnit5(),
        
        // Earlier than: JUnit 4 code
        java("""
            import org.junit.Check;
            
            public class MyTest {
                @Check
                public void testSomething() {}
            }
            """),
            
        // After: Anticipated JUnit 5 end result
        java("""
            import org.junit.jupiter.api.Check;
            
            public class MyTest {
                @Check
                public void testSomething() {}
            }
            """)
    );
}

This check framework validates that the recipe produces precisely the anticipated output—no extra, no much less. As a result of recipes are deterministic, the identical enter all the time produces the identical end result, making them dependable and testable at scale.

Turn leads into sales with free email marketing tools (en)

Leave a reply

Please enter your comment!
Please enter your name here