Package org.apache.flink.table.codesplit
Class BlockStatementGrouper
- java.lang.Object
-
- org.apache.flink.table.codesplit.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); }
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
BlockStatementGrouper.RewriteGroupedCode
This object represents a rewritten code block.
-
Constructor Summary
Constructors Constructor Description BlockStatementGrouper(String code, long maxMethodLength, String parameters)
Initialize new BlockStatementGrouper.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description BlockStatementGrouper.RewriteGroupedCode
rewrite(String context)
Rewrite code block used for initialization of this object.
-
-
-
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.
-
-
Method Detail
-
rewrite
public BlockStatementGrouper.RewriteGroupedCode rewrite(String context)
Rewrite code block used for initialization of this object. The code block is grouped into new methods.- Parameters:
context
- prefix used for extracted group names.- Returns:
BlockStatementGrouper.RewriteGroupedCode
representing rewritten code block and containing extracted groups with their names and content.
-
-