public static boolean undoReplaceStatement(OperatorInstance operation) { StatementOperatorInstance stmtoperator = (StatementOperatorInstance) operation; CtStatement ctst = (CtStatement) operation.getOriginal(); CtStatement fix = (CtStatement) operation.getModified(); CtBlock<?> parentBlock = stmtoperator.getParentBlock(); if (parentBlock != null) { fix.replace((CtStatement) ctst); return true; } return false; }
@Override public boolean undoChangesInModel(OperatorInstance operation, ProgramVariant p) { StatementOperatorInstance stmtoperator = (StatementOperatorInstance) operation; CtStatement ctst = (CtStatement) operation.getOriginal(); CtStatement fix = (CtStatement) operation.getModified(); CtBlock<?> parentBlock = stmtoperator.getParentBlock(); if (parentBlock != null) { fix.replace((CtStatement) ctst); return true; } return false; }
private void removeEnclosingStatement(CtElement e) { if (!(e.getParent() instanceof CtBlock)) { removeEnclosingStatement(e.getParent()); } else { ((CtStatement) e).replace(null); } }
@Override public boolean undoChangesInModel(OperatorInstance operation, ProgramVariant p) { StatementOperatorInstance stmtoperator = (StatementOperatorInstance) operation; CtStatement ctst = (CtStatement) operation.getOriginal(); CtStatement fix = (CtStatement) operation.getModified(); CtBlock<?> parentBlock = stmtoperator.getParentBlock(); if (parentBlock != null) { fix.replace((CtStatement) ctst); return true; } return false; }
@Override public boolean undoChangesInModel(OperatorInstance operation, ProgramVariant p) { StatementOperatorInstance stmtoperator = (StatementOperatorInstance) operation; CtStatement ctst = (CtStatement) operation.getOriginal(); CtStatement fix = (CtStatement) operation.getModified(); CtBlock<?> parentBlock = stmtoperator.getParentBlock(); if (parentBlock != null) { fix.replace((CtStatement) ctst); return true; } return false; }
private void replaceInvocationByLocalVariable(CtStatement invocationToBeReplaced, CtLocalVariable localVariable) { if (invocationToBeReplaced.getParent() instanceof CtBlock) { invocationToBeReplaced.replace(localVariable); } else { CtElement parent = invocationToBeReplaced.getParent(); while (!(parent.getParent() instanceof CtBlock)) { parent = invocationToBeReplaced.getParent(); } ((CtStatement) parent).insertBefore(localVariable); invocationToBeReplaced.replace(localVariable.getReference()); } }
@Override public boolean undoChangesInModel(OperatorInstance operation, ProgramVariant p) { StatementOperatorInstance stmtoperator = (StatementOperatorInstance) operation; CtStatement ctst = (CtStatement) operation.getOriginal(); CtStatement fix = (CtStatement) operation.getModified(); CtBlock<?> parentBlock = stmtoperator.getParentBlock(); if (parentBlock != null) { fix.replace((CtStatement) ctst); return true; } return false; }
@Override public boolean undoChangesInModel(OperatorInstance operation, ProgramVariant p) { StatementOperatorInstance stmtoperator = (StatementOperatorInstance) operation; CtStatement ctst = (CtStatement) operation.getOriginal(); CtStatement fix = (CtStatement) operation.getModified(); CtBlock<?> parentBlock = stmtoperator.getParentBlock(); if (parentBlock != null) { if (fix instanceof CtBlock) { CtBlock movedBlock = (CtBlock) fix; CtStatement firstFromBlock = movedBlock.getStatement(0); firstFromBlock.replace((CtStatement) ctst); for (CtStatement s : movedBlock.getStatements()) { parentBlock.removeStatement(s); } return true; } else { fix.replace((CtStatement) ctst); return true; } } return false; }
public boolean applyChangesInModel(OperatorInstance operation, ProgramVariant p) { StatementOperatorInstance stmtoperator = (StatementOperatorInstance) operation; boolean successful = false; CtStatement ctst = (CtStatement) operation.getOriginal(); CtStatement fix = (CtStatement) operation.getModified(); CtBlock parentBlock = stmtoperator.getParentBlock(); if (parentBlock != null) { try { ctst.replace((CtStatement) fix); fix.setParent(parentBlock); successful = true; operation.setSuccessfulyApplied(successful); } catch (Exception ex) { log.error("Error applying an operation, exception: " + ex.getMessage()); operation.setExceptionAtApplied(ex); operation.setSuccessfulyApplied(false); } } else { log.error("Operation not applied. Parent null "); } return successful; }
public boolean applyChangesInModel(OperatorInstance operation, ProgramVariant p) { StatementOperatorInstance stmtoperator = (StatementOperatorInstance) operation; boolean successful = false; CtStatement ctst = (CtStatement) operation.getOriginal(); CtStatement fix = (CtStatement) operation.getModified(); CtBlock parentBlock = stmtoperator.getParentBlock(); if (parentBlock != null) { try { ctst.replace((CtStatement) fix); fix.setParent(parentBlock); successful = true; operation.setSuccessfulyApplied(successful); } catch (Exception ex) { log.error("Error applying an operation, exception: " + ex.getMessage()); operation.setExceptionAtApplied(ex); operation.setSuccessfulyApplied(false); } } else { log.error("Operation not applied. Parent null "); } return successful; }
public boolean applyChangesInModel(OperatorInstance operation, ProgramVariant p) { StatementOperatorInstance stmtoperator = (StatementOperatorInstance) operation; boolean successful = false; CtStatement ctst = (CtStatement) operation.getOriginal(); CtStatement fix = (CtStatement) operation.getModified(); CtBlock parentBlock = stmtoperator.getParentBlock(); if (parentBlock != null) { try { ctst.replace((CtStatement) fix); fix.setParent(parentBlock); successful = true; operation.setSuccessfulyApplied(successful); } catch (Exception ex) { log.error("Error applying an operation, exception: " + ex.getMessage()); operation.setExceptionAtApplied(ex); operation.setSuccessfulyApplied(false); } } else { log.error("Operation not applied. Parent null "); } return successful; }
public static boolean doReplaceStatement(OperatorInstance operation) { StatementOperatorInstance stmtoperator = (StatementOperatorInstance) operation; boolean successful = false; CtStatement ctst = (CtStatement) operation.getOriginal(); CtStatement fix = (CtStatement) operation.getModified(); CtBlock parentBlock = stmtoperator.getParentBlock(); if (parentBlock != null) { try { ctst.replace((CtStatement) fix); fix.setParent(parentBlock); successful = true; operation.setSuccessfulyApplied(successful); } catch (Exception ex) { log.error("Error applying an operation, exception: " + ex.getMessage()); operation.setExceptionAtApplied(ex); operation.setSuccessfulyApplied(false); } } else { log.error("Operation not applied. Parent null "); } return successful; }
public boolean applyChangesInModel(OperatorInstance operation, ProgramVariant p) { StatementOperatorInstance stmtoperator = (StatementOperatorInstance) operation; boolean successful = false; CtStatement ctst = (CtStatement) operation.getOriginal(); CtStatement fix = (CtStatement) operation.getModified(); CtBlock parentBlock = stmtoperator.getParentBlock(); if (parentBlock != null) { try { ctst.replace((CtStatement) fix); fix.setParent(parentBlock); successful = true; operation.setSuccessfulyApplied(successful); } catch (Exception ex) { log.error("Error applying an operation, exception: " + ex.getMessage()); operation.setExceptionAtApplied(ex); operation.setSuccessfulyApplied(false); } } else { log.error("Operation not applied. Parent null "); } return successful; }
invocationToBeReplaced.getType(), "o_" + id.split("___")[0], invocationToBeReplaced ); statementToBeAsserted.replace(localVariable); DSpotUtils.addComment(localVariable, "AssertGenerator create local variable with return value of invocation", CtComment.CommentType.INLINE); localVariable.setParent(statementToBeAsserted.getParent());
".assert" + Logger.observations.get(index).toString().toUpperCase().substring(0, 1) + Logger.observations.get(index).toString().substring(1) + "(" + valueToReplace + ")"; testCaseToBeFix.getBody().getStatement(index).replace(factory.createCodeSnippetStatement(snippet)); } else if ("assertSame".equals(((CtInvocation) valueToReplace.getParent()).getExecutable().getSimpleName())) { ((CtInvocation) valueToReplace.getParent()).replace(factory.createCodeSnippetStatement(
element.replace(newIf);
@Override public CtIf processCondition(CtStatement element, String newCondition) { //logger.debug("##### {} ##### Before:\n{}", element, element.getParent()); // if the element is not a line if (!new LineFilter().matches(element)) { element = element.getParent(new LineFilter()); } CtElement parent = element.getParent(); CtIf newIf = element.getFactory().Core().createIf(); CtCodeSnippetExpression<Boolean> condition = element.getFactory().Core().createCodeSnippetExpression(); condition.setValue(newCondition); newIf.setCondition(condition); // Fix : warning: ignoring inconsistent parent for [CtElem1] ( [CtElem2] != [CtElem3] ) newIf.setParent(parent); element.replace(newIf); // this should be after the replace to avoid an StackOverflowException caused by the circular reference. newIf.setThenStatement(element); //logger.debug("##### {} ##### After:\n{}", element, element.getParent().getParent()); return newIf; } }
"o_" + id, invocation.clone()); try { stmt.replace(localVariable); } catch (ClassCastException e) { throw new RuntimeException(e);