Package org.apache.flink.table.codesplit
Class BlockStatementGrouper
java.lang.Object
org.apache.flink.table.codesplit.BlockStatementGrouper
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 ClassesModifier and TypeClassDescriptionstatic classThis object represents a rewritten code block. -
Constructor Summary
ConstructorsConstructorDescriptionBlockStatementGrouper(String code, long maxMethodLength, String parameters) Initialize new BlockStatementGrouper. -
Method Summary
Modifier and TypeMethodDescriptionRewrite code block used for initialization of this object.
-
Constructor Details
-
BlockStatementGrouper
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 Details
-
rewrite
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.RewriteGroupedCoderepresenting rewritten code block and containing extracted groups with their names and content.
-