public class BlockStatementGrouper extends Object
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);
}
Modifier and Type | Class and Description |
---|---|
static class |
BlockStatementGrouper.RewriteGroupedCode
This object represents a rewritten code block.
|
Constructor and Description |
---|
BlockStatementGrouper(String code,
long maxMethodLength,
String parameters)
Initialize new BlockStatementGrouper.
|
Modifier and Type | Method and Description |
---|---|
BlockStatementGrouper.RewriteGroupedCode |
rewrite(String context)
Rewrite code block used for initialization of this object.
|
public BlockStatementGrouper(String code, long maxMethodLength, String 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.public BlockStatementGrouper.RewriteGroupedCode rewrite(String context)
context
- prefix used for extracted group names.BlockStatementGrouper.RewriteGroupedCode
representing rewritten code block and containing extracted
groups with their names and content.Copyright © 2023–2024 The Apache Software Foundation. All rights reserved.