// Supply code snippet
// The consumer's identify
personal String identify = "Java";
// LST illustration
J.VariableDeclarations | "// The consumer'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 various file varieties together with XML or YAML to change issues like Maven POMs or different configuration information. Additionally they can create new information when wanted as a part of migrations. However recipes don’t even have to change code in any respect. A robust characteristic and advantage of the wealthy knowledge from the LST is that they might simply collect knowledge and insights, analyzing code bases to generate knowledge tables for use for reviews, metrics, or visualizations that assist groups perceive their code earlier than making adjustments.
Testing recipes: Deterministic and dependable
OpenRewrite’s deterministic nature makes recipes straightforward to check. Right here’s how easy it’s to visualise the adjustments a recipe ought to make, and to confirm it really works appropriately:
@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 take a look at 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.
