use of org.evosuite.testcase.PrimitiveExpression 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);
}
}
use of org.evosuite.testcase.PrimitiveExpression in project evosuite by EvoSuite.
the class TestExtractingVisitor method retrieveVariableReference.
private VariableReference retrieveVariableReference(InfixExpression infixExpr, Class<?> exprType) {
if (exprType == null) {
exprType = retrieveTypeClass(infixExpr);
}
VariableReference ref = new VariableReferenceImpl(testCase.getReference(), exprType);
VariableReference leftOperand = retrieveVariableReference(infixExpr.getLeftOperand(), null);
leftOperand.setOriginalCode(infixExpr.getLeftOperand().toString());
Operator operator = Operator.toOperator(infixExpr.getOperator().toString());
VariableReference rightOperand = retrieveVariableReference(infixExpr.getRightOperand(), null);
rightOperand.setOriginalCode(infixExpr.getRightOperand().toString());
PrimitiveExpression expr = new PrimitiveExpression(testCase.getReference(), ref, leftOperand, operator, rightOperand);
testCase.addStatement(expr);
return ref;
}
Aggregations