use of org.evosuite.testcase.VariableReferenceImpl 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;
}
use of org.evosuite.testcase.VariableReferenceImpl in project evosuite by EvoSuite.
the class TestCaseCodeGenerator method createFieldReadAccessStmt.
private void createFieldReadAccessStmt(final int logRecNo, final TestCase testCase) {
// assumption: all necessary statements are created and there is one variable for reach referenced object
final int oid = this.log.objectIds.get(logRecNo);
final int captureId = this.log.captureIds.get(logRecNo);
final Object returnValue = this.log.returnValues.get(logRecNo);
if (// TODO necessary?
!CaptureLog.RETURN_TYPE_VOID.equals(returnValue)) {
Integer returnValueOID = (Integer) returnValue;
final String descriptor = this.log.descList.get(logRecNo);
final org.objectweb.asm.Type fieldTypeType = org.objectweb.asm.Type.getType(descriptor);
final String typeName = this.log.oidClassNames.get(this.log.oidRecMapping.get(oid));
final String fieldName = this.log.namesOfAccessedFields.get(captureId);
try {
// Class.forName(fieldTypeName, true, StaticTestCluster.classLoader);
final Class<?> fieldType = getClassFromType(fieldTypeType);
// Class.forName(typeName, true, StaticTestCluster.classLoader);
final Class<?> type = getClassForName(typeName);
final FieldReference valueRef = new FieldReference(testCase, new GenericField(type.getField(fieldName), type));
final VariableReference targetVar = new VariableReferenceImpl(testCase, fieldType);
final AssignmentStatement assignment = new AssignmentStatement(testCase, targetVar, valueRef);
VariableReference varRef = testCase.addStatement(assignment);
this.oidToVarRefMap.put(returnValueOID, varRef);
} catch (final Exception e) {
throw new RuntimeException(e);
}
}
}
Aggregations