@Override protected void exit(CtElement e) { CtElement simplified = eval.evaluate(e); if (simplified != null) { e.replace(simplified); } } }
toReplace.replace(elements2after.get(ctPath.getKey()));
@Override public boolean undoChangesInModel(OperatorInstance opInstance, ProgramVariant p) { // We update the spoon Model opInstance.getModified().replace(opInstance.getOriginal()); // Finally, we update the modification point (i.e., Astor // Representation) return true; }
/** * This method replace the given original element by the amplified one, by producing a clone of the given test method. * The amplified element would be marked as amplified, with the METADATA_KEY, * <i>i.e.</i> calling {@link #hasBeenAmplified(CtElement)} returns true. * * @param originalElement element to be replaced * @param amplifiedElement new element to be used * @param testMethod test method to be cloned * @return a clone of the given test method with an amplified element that replaces the original element */ protected CtMethod<?> replace(T originalElement, T amplifiedElement, CtMethod<?> testMethod) { originalElement.replace(amplifiedElement); amplifiedElement.putMetadata(this.METADATA_KEY, true); CtMethod<?> clone = CloneHelper.cloneTestMethodForAmp(testMethod, getSuffix()); amplifiedElement.replace(originalElement); Counter.updateInputOf(clone, 1); return clone; }
@Override public boolean applyChangesInModel(OperatorInstance opInstance, ProgramVariant p) { CtExpression elementToModify = (CtExpression) opInstance.getOriginal(); CtExpression elementOriginalCloned = (CtExpression) MutationSupporter.clone(elementToModify); CtElement elFixIngredient = opInstance.getModified(); // we transform the Spoon model try { opInstance.getModificationPoint().getCodeElement().replace(elFixIngredient); } catch (Exception e) { log.error("error to modify " + elementOriginalCloned + " to " + elFixIngredient); log.equals(e); opInstance.setExceptionAtApplied(e); return false; } // I save the original instance opInstance.setOriginal(elementOriginalCloned); // Finally, we update the modification point (i.e., Astor // Representation) opInstance.getModificationPoint().setCodeElement(elFixIngredient); boolean change = !opInstance.getModificationPoint().getCodeElement().toString() .equals(elementOriginalCloned.toString()); if (!change) log.error("Replacement does not work for modify " + elementOriginalCloned + " to " + elFixIngredient); return true; }
@Override public boolean undoChangesInModel(OperatorInstance opInstance, ProgramVariant p) { // We update the spoon Model opInstance.getModificationPoint().getCodeElement().replace(opInstance.getOriginal()); // Finally, we update the modification point (i.e., Astor // Representation) opInstance.getModificationPoint().setCodeElement(opInstance.getOriginal()); return true; }
if (Util.isPrimitiveArray.test(Logger.observations.get(index))) {//TODO only primitive are supported String snippet = createSnippetFromObservations(Logger.observations.get(index)); valueToReplace.replace(factory.createCodeSnippetExpression(snippet)); Counter.incNumberOfArrayFixed(); replaced = true; valueToReplace.replace( factory.createCodeSnippetExpression( Util.fieldOfObjectToString.apply(Logger.observations.get(index)) fieldNegativeInfinity.setVariable(negative_infinity.getReference()); fieldNegativeInfinity.setFactory(factory); valueToReplace.replace(fieldNegativeInfinity); } else if (Logger.observations.get(index).equals(Double.POSITIVE_INFINITY)) { final CtFieldRead<Double> fieldPositiveInfinity = factory.createFieldRead(); fieldPositiveInfinity.setVariable(positive_infinity.getReference()); fieldPositiveInfinity.setFactory(factory); valueToReplace.replace(fieldPositiveInfinity); } else { valueToReplace.replace( factory.createLiteral( Logger.observations.get(index)
toReplace.replace(newLiteral); Counter.updateInputOf(cloned_method, 1); DSpotUtils.addComment(toReplace, "TestDataMutator on numbers", CtComment.CommentType.INLINE);