private void addVariable(Statement statement) { VariableReference retVal = statement.getReturnValue(); variableMap.put(retVal, new LinkedHashSet<Type>()); }
/** {@inheritDoc} */ @Override public VariableReference getReturnValue(int position) { return getStatement(position).getReturnValue(); }
/** {@inheritDoc} */ @Override public boolean hasCastableObject(Type type) { for (Statement st : statements) { if (st.getReturnValue().isAssignableFrom(type)) { return true; } } return false; }
/** * Get the statement that defines this variable * * @param test * @param name * @return */ private static PrimitiveStatement<?> getStatement(TestCase test, String name) { for (Statement statement : test) { if (statement instanceof PrimitiveStatement<?>) { if (statement.getReturnValue().getName().equals(name)) return (PrimitiveStatement<?>) statement; } } return null; }
/** {@inheritDoc} */ @Override public boolean hasObject(Type type, int position) { for (int i = 0; i < position && i < size(); i++) { Statement st = statements.get(i); if (st.getReturnValue() == null) continue; // Nop if (st.getReturnValue().isAssignableTo(type)) { return true; } } return false; }
/** {@inheritDoc} */ @Override public VariableReference setStatement(Statement statement, int position) { statements.set(position, statement); assert (isValid()); return statement.getReturnValue(); // TODO: // -1? }
/** * {@inheritDoc} * * Create a copy of the current variable */ @Override public VariableReference clone(TestCase newTestCase) { return newTestCase.getStatement(getStPosition()).getReturnValue(); }
/** {@inheritDoc} */ @Override public VariableReference copy(TestCase newTestCase, int offset) { return newTestCase.getStatement(getStPosition() + offset).getReturnValue(); }
/** {@inheritDoc} */ @Override public VariableReference addStatement(Statement statement, int position) { statements.add(position, statement); assert (isValid()); return statement.getReturnValue(); }
/** {@inheritDoc} */ @Override public VariableReference copy(TestCase newTest, int offset) { return newTest.getStatement(getStPosition() + offset).getReturnValue(); }
private void addUnchangedMapping(TestCase test, VariableReference var) { VariableReference copy = test.getStatement(var.getStPosition()).getReturnValue(); if (!variableMapping.containsKey(var.getStPosition())) { variableMapping.put(var.getStPosition(), new HashSet<VariableReference>()); variableMapping.get(var.getStPosition()).add(var); } variableMapping.get(var.getStPosition()).add(copy); }
/** {@inheritDoc} */ @Override public Assertion copy(TestCase newTestCase, int offset) { PrimitiveFieldAssertion s = new PrimitiveFieldAssertion(); s.source = newTestCase.getStatement(source.getStPosition() + offset).getReturnValue(); s.value = value; s.field = field; s.comment = comment; s.killedMutants.addAll(killedMutants); return s; }
/** {@inheritDoc} */ @Override public Assertion copy(TestCase newTestCase, int offset) { InspectorAssertion s = new InspectorAssertion(); s.source = newTestCase.getStatement(source.getStPosition() + offset).getReturnValue(); s.inspector = inspector; s.value = value; s.comment = comment; s.killedMutants.addAll(killedMutants); return s; }
/** * {@inheritDoc} * * Create a copy of the compare assertion */ @Override public Assertion copy(TestCase newTestCase, int offset) { CompareAssertion s = new CompareAssertion(); s.source = newTestCase.getStatement(source.getStPosition() + offset).getReturnValue(); s.dest = newTestCase.getStatement(dest.getStPosition() + offset).getReturnValue(); s.value = value; s.comment = comment; s.killedMutants.addAll(killedMutants); return s; }
/** {@inheritDoc} */ @Override public Assertion copy(TestCase newTestCase, int offset) { NullAssertion s = new NullAssertion(); s.source = newTestCase.getStatement(source.getStPosition() + offset).getReturnValue(); s.value = value; s.comment = comment; s.killedMutants.addAll(killedMutants); assert (s.isValid()); return s; }
/** * {@inheritDoc} * * Create a copy of the current variable */ @Override public VariableReference copy(TestCase newTestCase, int offset) { ArrayReference otherArray = (ArrayReference) newTestCase.getStatement(array.getStPosition() + offset).getReturnValue(); //must be set as we only use this to clone whole testcases return new ArrayIndex(newTestCase, otherArray, indices); }
/** {@inheritDoc} */ @Override public Statement copy(TestCase newTestCase, int offset) { VariableReference newRetVal = new VariableReferenceImpl(newTestCase, retval.getType()); VariableReference newLeftOperand = newTestCase.getStatement(leftOperand.getStPosition()).getReturnValue(); VariableReference newRightOperand = newTestCase.getStatement(rightOperand.getStPosition()).getReturnValue(); return new PrimitiveExpression(newTestCase, newRetVal, newLeftOperand, operator, newRightOperand); // return new PrimitiveExpression(newTestCase, retval, leftOperand, operator, rightOperand); }
@Override public VariableReference getLastObject(Type type, int position) throws ConstructionFailedException { for (int i = statements.size() - 1; i >= position; i--) { Statement statement = statements.get(i); VariableReference var = statement.getReturnValue(); if (var.isAssignableTo(type)) return var; } throw new ConstructionFailedException("Found no variables of type " + type); }
/** {@inheritDoc} */ @Override public Statement clone(TestCase newTestCase) { Statement result = copy(newTestCase, 0); result.getReturnValue().setOriginalCode(retval.getOriginalCode()); result.addComment(getComment()); return result; }
/** * Add a method call on the return value of the object at position statement * * @param test * @param statement */ private boolean addCall(TestChromosome test, int statement) { logger.debug("Adding call"); TestFactory factory = TestFactory.getInstance(); Statement theStatement = test.getTestCase().getStatement(statement); VariableReference var = theStatement.getReturnValue(); int oldLength = test.size(); factory.insertRandomCallOnObjectAt(test.getTestCase(), var, statement + 1); test.setChanged(test.size() != oldLength); return false; }