@Internal public class BlockStatementSplitter extends Object
BlockStatementSplitter 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
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
while (counter > 0) {
myFun_0_1(a, b, c);
if (a > 0) {
myFun_0_1_2(a, b, c);
} else {
myFun_0_1_3(a, b, c);
}
counter--;
}
Where bodies of extracted "methods" are:
myFun_0_1(int a, int b, int c) ->
int localA = a + 1000;
System.out.println(localA);
myFun_0_1_3(int a, int b, int c) ->
b = a * 2;
c = b * 2;
System.out.println(b);
myFun_whileBody0_0_ifBody1(int a) ->
b = a * 3;
System.out.println(b);
Constructor and Description |
---|
BlockStatementSplitter(String code,
String parameters)
Initialize new BlockStatementSplitter.
|
Modifier and Type | Method and Description |
---|---|
Map<String,List<String>> |
extractBlocks()
This method extracts statements from IFs, ELSE's and WHILE blocks from block code used during
initialization of this object.
|
String |
rewriteBlock(String context)
Rewrite code block that was used for this object initialization.
|
public String rewriteBlock(String context)
context
- prefix for extracted blocks.public Map<String,List<String>> extractBlocks()
Copyright © 2014–2024 The Apache Software Foundation. All rights reserved.