use of org.evosuite.testcase.StatementInterface in project evosuite by EvoSuite.
the class CompoundTestCase method convertMethod.
/**
* <p>
* convertMethod
* </p>
*
* @param methodDef
* a {@link org.evosuite.junit.CompoundTestCase.MethodDef}
* object.
* @param params
* a {@link java.util.List} object.
* @param retVal
* a {@link org.evosuite.testcase.VariableReference} object.
*/
public void convertMethod(MethodDef methodDef, List<VariableReference> params, VariableReference retVal) {
assert methodDef.getParams().size() == params.size();
Map<VariableReference, VariableReference> methodVarsMap = new HashMap<VariableReference, VariableReference>();
for (StatementInterface statement : methodDef.getCode()) {
for (int idx = 0; idx < params.size(); idx++) {
statement.replace(methodDef.getParams().get(idx), params.get(idx));
}
if (statement instanceof ReturnStatementPlaceholder) {
VariableReference resultVal = methodVarsMap.get(statement.getReturnValue());
if (resultVal == null) {
throw new IllegalStateException();
}
AssignmentStatement assignmentStatement = new AssignmentStatement(delegate, retVal, resultVal);
addStatement(assignmentStatement);
return;
}
StatementInterface newStmt = statement;
if (!(statement instanceof PrimitiveExpression)) {
// Since the delegate code is not yet finished,
// cloning of PrimitiveExpressions does not work.
newStmt = statement.clone(delegate);
}
addReplacementVariable(statement.getReturnValue(), newStmt.getReturnValue());
methodVarsMap.put(statement.getReturnValue(), newStmt.getReturnValue());
addStatement(newStmt);
}
}
Aggregations