use of org.evosuite.testcase.VariableReference 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.VariableReference in project evosuite by EvoSuite.
the class TestExtractingVisitor method retrieveVariableReference.
private VariableReference retrieveVariableReference(IVariableBinding varBinding, Class<?> varClass) {
if (varClass == null) {
varClass = retrieveTypeClass(varBinding.getType());
}
VariableReference localVar = testCase.getVariableReference(varBinding);
if (localVar != null) {
return localVar;
}
if (!iterations.isEmpty()) {
return getLoopVariable(varBinding, varClass);
}
logger.warn("No variable reference found for variable binding {}, creating new one.", varBinding);
return new BoundVariableReferenceImpl(testCase, varClass, varBinding.getName());
}
use of org.evosuite.testcase.VariableReference in project evosuite by EvoSuite.
the class TestExtractingVisitor method retrieveVariableReference.
private VariableReference retrieveVariableReference(VariableDeclaration varDecl) {
IVariableBinding variableBinding = varDecl.resolveBinding();
Class<?> clazz = retrieveTypeClass(variableBinding.getType());
VariableReference result = new BoundVariableReferenceImpl(testCase, clazz, variableBinding.getName());
testCase.addVariable(variableBinding, result);
return result;
}
use of org.evosuite.testcase.VariableReference in project evosuite by EvoSuite.
the class TestExtractingVisitor method visit.
/**
* {@inheritDoc}
*/
@Override
public boolean visit(SingleVariableDeclaration variableDeclaration) {
VariableReference varRef = retrieveVariableReference(variableDeclaration);
varRef.setOriginalCode(variableDeclaration.toString());
testCase.addParameter(varRef);
return true;
}
use of org.evosuite.testcase.VariableReference in project evosuite by EvoSuite.
the class TestExtractingVisitor method retrieveResultReference.
private VariableReference retrieveResultReference(SuperMethodInvocation superMethodInvocation) {
// TODO Duplicate code from retrieveResultReference(MethodInvocation)
// too bad they don't have a common matching interface
VariableReference result = calleeResultMap.get(superMethodInvocation.toString());
if (result != null) {
return result;
}
ASTNode parent = superMethodInvocation.getParent();
if (parent instanceof VariableDeclarationFragment) {
return retrieveVariableReference(parent, null);
}
if (parent instanceof Assignment) {
Assignment assignment = (Assignment) parent;
return retrieveVariableReference(assignment.getLeftHandSide(), null);
}
IMethodBinding methodBinding = superMethodInvocation.resolveMethodBinding();
result = retrieveVariableReference(methodBinding.getReturnType(), null);
calleeResultMap.put(superMethodInvocation.toString(), result);
return result;
}
Aggregations