Class BlockStatementGrouper


  • @Internal
    public class BlockStatementGrouper
    extends Object
    Groups end extract single line statements such as operations on fields/local variables, IF and WHILE statements and extract new method for each group making them smaller.

    BlockStatementGrouper does not recognize if statement operates on local of class member variable. Because of that, code must be preprocessed by DeclarationRewriter which converts all local variables extracted as to member variables.

    Before

    
     {
         a[0] += b[1];
         b[1] += a[1];
         while (counter > 0) {
             myFun_whileBody0_0(a, b);
             if (a[0] > 0) {
                 myFun_whileBody0_0_ifBody0(a, b);
             } else {
                 myFun_whileBody0_0_ifBody1(a, b);
             }
             counter--;
         }
    
         a[2] += b[2];
         b[3] += a[3];
     }
    
     

    After

    
     {
         myFun_rewriteGroup4(a, b);
         myFun_rewriteGroup5(a, b);
     }
     

    Where bodies of extracted "methods" are:

    
         myFun_rewriteGroup4 ->
             a[0] += b[1];
             b[1] += a[1];
             while (counter > 0) {
                 myFun_rewriteGroup0_1_rewriteGroup3(a, b);
                 counter--;
             }
     
    
         myFun_rewriteGroup5 ->
             a[2] += b[2];
             b[3] += a[3];
     
    
         myFun_rewriteGroup0_1_rewriteGroup3 ->
             myFun_whileBody0_0(a, b);
             if (a[0] > 0) {
                 myFun_whileBody0_0_ifBody0(a, b);
             } else {
                 myFun_whileBody0_0_ifBody1(a, b);
             }
     
    • Constructor Detail

      • BlockStatementGrouper

        public BlockStatementGrouper​(String code,
                                     long maxMethodLength,
                                     String parameters)
        Initialize new BlockStatementGrouper.
        Parameters:
        code - code block that should be rewritten for statement grouping.
        maxMethodLength - maximal length of the extracted code block.
        parameters - parameters definition that should be used for extracted methods.