Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-9324

Implement `AstStringCompiler` in Java

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.0.0-rc-2
    • Component/s: None
    • Labels:
      None

      Description

      We can use AstStringCompiler to construct AST in Java code, it will be especially useful when we want to implement AST transformations in groovy core and generate complicated bytecode. For example,

      AsmClassGenerator acg = controller.getAcg();
      
      // Using text block in Java 13(preview)
      new AstStringCompiler().compile("""
           if ('a' == x) {
                ...
           } else {
                ...
           }
      """).get(0).visit(acg);
      

      So we do not have to contruct AST with util methods of GeneralUtils any more.

        Attachments

          Activity

            People

            • Assignee:
              daniel_sun Daniel Sun
              Reporter:
              daniel_sun Daniel Sun
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: