使用 OpenRewrite 进行自动代码转换

  • Code Maintenance/Refactoring Challenges: Aim to minimize cost and maximize benefit over time. Costs and benefits for software maintenance revolve around old and new code quantity and quality.

    • Quantity: SonarQube suggests maintaining at least 80 million lines of code.
    • Quality: In fast-paced environments, code changes often come from copying or using quick knowledge. Automated refactoring has benefits and costs.
  • Benefits and Costs of Automated Refactoring:

    • Benefits: Zero human cost if a recipe exists and works; easy migration to newer libraries; educational for programmers.
    • Costs: Cost of creating a recipe if no recipe exists; rewards for using common programming languages; possible loss of "design evolution".
  • What We’ve Been Using: Butterfly: A two-part system with an open-source CLI and a hosted transformation tool. Focus is on replacing the CLI with OpenRewrite.
  • Where We Are Going: OpenRewrite: Adopted by open source projects; maintained by Moderne; uses Lossless Semantic Trees and the Visitor pattern; tracking AI for code transformation.
  • What About Artificial Intelligence?: Should be investigated as it could be useful in code transformation; organization is starting to incorporate AI.
  • How We’ve Used OpenRewrite: Manually running recipes against a single software project, such as JUnit 4 to JUnit 5 JAX-RS refactoring, GitHub release notes refactoring, and running multiple recipes on a large project with significant savings.
  • Caveat: It’s Only Easy When It’s Easy: If a recipe doesn't exist or is difficult to create, it's not always the answer. Manual intervention is often needed for complicated transformations.
  • Manual Intervention: Most complicated transformations require human cleanup, especially in test cases.
  • Triaging Problems: OpenRewrite lacks application logging and may not produce errors as expected. A recommendations page is available in internal documentation.
  • Conclusion: Exciting new tools to maximize value.
  • Resource: OpenRewrite documentation
阅读 9
0 条评论