Class BlockStatementRewriter

java.lang.Object
org.apache.flink.table.codesplit.BlockStatementRewriter
All Implemented Interfaces:
CodeRewriter

@Internal public class BlockStatementRewriter extends Object implements CodeRewriter
Extract branch of IFs, ELSEs statements and WHILEs code blocks into smaller methods. Single line statement blocks, with more than one statement, like field or local variable operations will be extracted also to separate methods.

This rewriter only deals with functions without return values. Functions with return values should have been converted by ReturnValueRewriter. Also, this rewriter will not extract blocks containing return statements for correctness.

Before


 public class Example {

     int b;
     int c;

     public void myFun(int a) {

         int counter = 10;
         while (counter > 0) {
             int localA = a + 1000;
             System.out.println(localA);
             if (a > 0) {
                 b = a * 2;
                 c = b * 2;
                 System.out.println(b);
             } else {
                 b = a * 3;
                 System.out.println(b);
             }
             counter--;
         }
     }
 }
 

After


 public class Example {

     int b;
     int c;

     public void myFun(int a) {

         int counter = 10;

         while (counter > 0) {
             myFun_rewriteGroup1(a);
             counter--;
         }
     }

     void myFun_rewriteGroup1(int a) {
         myFun_whileBody0_0(a);
         if (a > 0) {
             myFun_whileBody0_0_ifBody0(a);
         } else {
             myFun_whileBody0_0_ifBody1(a);
         }
     }

     void myFun_whileBody0_0(int a) {
         int localA = a + 1000;
         System.out.println(localA);
     }

     void myFun_whileBody0_0_ifBody1(int a) {
         b = a * 3;
         System.out.println(b);
     }

     void myFun_whileBody0_0_ifBody0(int a) {
         b = a * 2;
         c = b * 2;
         System.out.println(b);
     }
 }
 
  • Constructor Details

    • BlockStatementRewriter

      public BlockStatementRewriter(String code, long maxMethodLength)
  • Method Details