/*
* A method that doesn't touch any parameters is trivially inlinable (this
* covers the empty method case)
*/
if (orderVisitor.checkResults() == SideEffectCheck.NO_REFERENCES) {
JMultiExpression multi = createMultiExpressionIncludingArgs(x);
multi.exprs.add(targetExpr);
replaceWithMulti(ctx, multi);
return true;
}
/*
* We can still inline in the case where all of the actual arguments are
* "safe". They must have no side effects, and also have values which
* could not be affected by the execution of any code within the callee.
*/
if (orderVisitor.checkResults() == SideEffectCheck.FAILS) {
for (JExpression arg : x.getArgs()) {
ExpressionAnalyzer argAnalyzer = new ExpressionAnalyzer();
argAnalyzer.accept(arg);
if (argAnalyzer.hasAssignment() || argAnalyzer.accessesField()
|| argAnalyzer.createsObject() || argAnalyzer.canThrowException()) {
/*
* This argument evaluation could affect or be affected by the
* callee so we cannot inline here.
*/
return true;
}
}
}
// We're safe to inline.
JMultiExpression multi = createMultiExpressionForInstanceAndClinit(x);
// Replace all params in the target expression with the actual arguments.
new ParameterReplacer(x).accept(targetExpr);
multi.exprs.add(targetExpr);