public class FunctionSplitter extends Object implements CodeRewriter
This rewriter only deals with functions without return values. Functions with return values
should have been converted by ReturnValueRewriter.
For functions with
return statements, this rewriter will add a check for early returns with the help of
AddBoolBeforeReturnRewriter.
Before
public class Example {
public void myFun(int a, int b) {
a += b;
b += a;
if (a > 0) {
return;
}
a *= 2;
b *= 2;
System.out.println(a);
System.out.println(b);
}
}
After
public class Example {
boolean myFunHasReturned$0;
public void myFun(int a, int b) {
myFunHasReturned$0 = false;
myFun_split1(a, b);
myFun_split2(a, b);
if (myFunHasReturned$0) {
return;
}
myFun_split3(a, b);
}
void myFun_split1(int a, int b) {
a += b;
b += a;
}
void myFun_split2(int a, int b) {
if (a > 0) {
{
myFunHasReturned$0 = true;
return;
}
}
}
void myFun_split3(int a, int b) {
a *= 2;
b *= 2;
System.out.println(a);
System.out.println(b);
}
}
| Constructor and Description |
|---|
FunctionSplitter(String code,
int maxMethodLength) |
public FunctionSplitter(String code, int maxMethodLength)
public String rewrite()
rewrite in interface CodeRewriterCopyright © 2023–2024 The Apache Software Foundation. All rights reserved.