/** * Creates a new statement list from an existing block. */ public <R> CtStatementList createStatementList(CtBlock<R> block) { CtStatementList l = factory.Core().createStatementList(); for (CtStatement s : block.getStatements()) { l.addStatement(s.clone()); } return l; }
@Override public <R> void visitCtBlock(CtBlock<R> block) { CtBlock<?> b = block.getFactory().Core().createBlock(); for (CtStatement s : block.getStatements()) { CtElement res = evaluate(s); if (res != null) { if (res instanceof CtStatement) { b.addStatement((CtStatement) res); } else { //the context expects statement. We cannot simplify in this case b.addStatement(s.clone()); } } // do not copy unreachable statements if (flowEnded) { break; } } setResult(b); }
@Override public List<OperatorInstance> createOperatorInstances(ModificationPoint modificationPoint) { log.debug("Unwrap If:"); CtIf ifToRemove = (CtIf) modificationPoint.getCodeElement(); CtStatement stmtinsideThen = ifToRemove.getThenStatement().clone(); stmtinsideThen.setParent(null); MutationSupporter.clearPosition(stmtinsideThen); List<OperatorInstance> opInstances = new ArrayList<>(); OperatorInstance opInstace = new StatementOperatorInstance(modificationPoint, this, ifToRemove, stmtinsideThen); opInstances.add(opInstace); return opInstances; }
@Override public List<OperatorInstance> createOperatorInstances(ModificationPoint modificationPoint) { List<OperatorInstance> opInstances = new ArrayList<>(); CtStatement statementPointed = (CtStatement) modificationPoint.getCodeElement(); CtTry tryNew = MutationSupporter.getFactory().createTry(); List<CtCatch> catchers = new ArrayList<>(); CtCatch catchEx1 = MutationSupporter.getFactory().createCtCatch("e", Exception.class, new CtBlockImpl()); catchers.add(catchEx1); tryNew.setCatchers(catchers); CtBlock tryBoddy = new CtBlockImpl(); tryNew.setBody(tryBoddy); CtStatement stmtC = statementPointed.clone(); MutationSupporter.clearPosition(stmtC); tryBoddy.addStatement(stmtC); OperatorInstance opInstace = new StatementOperatorInstance(modificationPoint, this, statementPointed, tryNew); opInstances.add(opInstace); return opInstances; }
@Override public OperatorInstance getConcreteOperatorInstance(MetaOperatorInstance operatorInstance, int metaIdentifier) { // We retrieve the information from the operator instance Ingredient ingredient = operatorInstance.getAllIngredients().get(metaIdentifier); ModificationPoint modificationPoint = operatorInstance.getModificationPoint(); // We create the new operator CtIf ifNew = MutationSupporter.getFactory().createIf(); CtStatement statementPointed = (CtStatement) modificationPoint.getCodeElement(); CtStatement statementPointedCloned = statementPointed.clone(); MutationSupporter.clearPosition(statementPointedCloned); ifNew.setThenStatement(statementPointedCloned); // as difference with the meta, here we put the ingredient evaluated in the // meta. ifNew.setCondition((CtExpression<Boolean>) ingredient.getCode()); // Let's create the operations List<OperatorInstance> opsOfVariant = new ArrayList(); OperatorInstance opInstace = new StatementOperatorInstance(modificationPoint, this, statementPointed, ifNew); opsOfVariant.add(opInstace); return opInstace; }
@Override public OperatorInstance getConcreteOperatorInstance(MetaOperatorInstance operatorInstance, int metaIdentifier) { // We retrieve the information from the operator instance Ingredient ingredient = operatorInstance.getAllIngredients().get(metaIdentifier); ModificationPoint modificationPoint = operatorInstance.getModificationPoint(); // We create the new operator CtIf ifNew = MutationSupporter.getFactory().createIf(); CtStatement statementPointed = (CtStatement) modificationPoint.getCodeElement(); CtStatement statementPointedCloned = statementPointed.clone(); MutationSupporter.clearPosition(statementPointedCloned); ifNew.setThenStatement(statementPointedCloned); // as difference with the meta, here we put the ingredient evaluated in the // meta. ifNew.setCondition((CtExpression<Boolean>) ingredient.getCode()); // Let's create the operations List<OperatorInstance> opsOfVariant = new ArrayList(); OperatorInstance opInstace = new StatementOperatorInstance(modificationPoint, this/* new ReplaceOp() */, statementPointed, ifNew); opsOfVariant.add(opInstace); return opInstace; }
!AssertGeneratorHelper.isVoidReturn((CtInvocation) statementToBeAsserted) && statementToBeAsserted.getParent() instanceof CtBlock) { CtInvocation invocationToBeReplaced = (CtInvocation) statementToBeAsserted.clone(); final CtLocalVariable localVariable = factory.createLocalVariable( invocationToBeReplaced.getType(), "o_" + id.split("___")[0], invocationToBeReplaced
CtStatement statementPointedCloned = statementPointed.clone(); statementPointedCloned.setPosition(new NoSourcePosition()); MutationSupporter.clearPosition(statementPointedCloned);
CtStatement statementPointedCloned = statementPointed.clone(); statementPointedCloned.setPosition(new NoSourcePosition()); MutationSupporter.clearPosition(statementPointedCloned);