Search in sources :

Example 1 with StatementInterface

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);
    }
}
Also used : StatementInterface(org.evosuite.testcase.StatementInterface) VariableReference(org.evosuite.testcase.VariableReference) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) AssignmentStatement(org.evosuite.testcase.AssignmentStatement) PrimitiveExpression(org.evosuite.testcase.PrimitiveExpression)

Aggregations

HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 AssignmentStatement (org.evosuite.testcase.AssignmentStatement)1 PrimitiveExpression (org.evosuite.testcase.PrimitiveExpression)1 StatementInterface (org.evosuite.testcase.StatementInterface)1 VariableReference (org.evosuite.testcase.VariableReference)1