@SuppressWarnings("unchecked") @Override public <T, U> U getValue(T element) { return ((U) ((Object) (castTarget(element).getCondition()))); }
/** * calls function once for each expression/then block and at the end calls function for last else block. * * @param ifElement * @param consumer * @return true if all function calls returns true or if there is no function call */ private void forEachIfCase(CtIf ifElement, BiConsumer<CtExpression<Boolean>, CtStatement> consumer) { consumer.accept(ifElement.getCondition(), ifElement.getThenStatement()); CtStatement elseStmt = getElseIfStatement(ifElement.getElseStatement()); if (elseStmt instanceof CtIf) { //another else if case forEachIfCase((CtIf) elseStmt, consumer); } else if (elseStmt != null) { //last else consumer.accept(null, elseStmt); } }
public void visitCtIf(final spoon.reflect.code.CtIf ifElement) { spoon.reflect.code.CtIf other = ((spoon.reflect.code.CtIf) (this.stack.peek())); enter(ifElement); biScan(spoon.reflect.path.CtRole.ANNOTATION, ifElement.getAnnotations(), other.getAnnotations()); biScan(spoon.reflect.path.CtRole.CONDITION, ifElement.getCondition(), other.getCondition()); biScan(spoon.reflect.path.CtRole.THEN, ((spoon.reflect.code.CtStatement) (ifElement.getThenStatement())), other.getThenStatement()); biScan(spoon.reflect.path.CtRole.ELSE, ((spoon.reflect.code.CtStatement) (ifElement.getElseStatement())), other.getElseStatement()); biScan(spoon.reflect.path.CtRole.COMMENT, ifElement.getComments(), other.getComments()); exit(ifElement); }
private CtExpression getExpressionFromElement(CtElement element) { if (element instanceof CtExpression) return (CtExpression) element; if (element instanceof CtIf) { return ((CtIf) element).getCondition(); } // TODO: to continue return null; }
public void visitCtIf(final CtIf ifElement) { enter(ifElement); scan(CtRole.ANNOTATION, ifElement.getAnnotations()); scan(CtRole.CONDITION, ifElement.getCondition()); scan(CtRole.THEN, ((CtStatement) (ifElement.getThenStatement()))); scan(CtRole.ELSE, ((CtStatement) (ifElement.getElseStatement()))); scan(CtRole.COMMENT, ifElement.getComments()); exit(ifElement); }
@java.lang.Override public void visitCtIf(final spoon.reflect.code.CtIf ifElement) { replaceInListIfExist(ifElement.getAnnotations(), new spoon.support.visitor.replace.ReplacementVisitor.CtElementAnnotationsReplaceListener(ifElement)); replaceElementIfExist(ifElement.getCondition(), new spoon.support.visitor.replace.ReplacementVisitor.CtIfConditionReplaceListener(ifElement)); replaceElementIfExist(((spoon.reflect.code.CtStatement) (ifElement.getThenStatement())), new spoon.support.visitor.replace.ReplacementVisitor.CtIfThenStatementReplaceListener(ifElement)); replaceElementIfExist(((spoon.reflect.code.CtStatement) (ifElement.getElseStatement())), new spoon.support.visitor.replace.ReplacementVisitor.CtIfElseStatementReplaceListener(ifElement)); replaceInListIfExist(ifElement.getComments(), new spoon.support.visitor.replace.ReplacementVisitor.CtElementCommentsReplaceListener(ifElement)); }
@Override public void visitCtIf(CtIf ifElement) { if (ifElement.getCondition() == null && child instanceof CtExpression) { ifElement.setCondition((CtExpression<Boolean>) child); return; } else if (child instanceof CtStatement) { CtStatement child = (CtStatement) this.child; // we create implicit blocks everywhere for facilitating transformation if (!(this.child instanceof CtBlock)) { child = jdtTreeBuilder.getFactory().Code().createCtBlock(child); child.setImplicit(true); child.setPosition(this.child.getPosition()); } IfStatement ifJDT = (IfStatement) this.parentJDT; if (ifJDT.thenStatement == this.childJDT) { //we are visiting `then` of `if` ifElement.setThenStatement(child); return; } else if (ifJDT.elseStatement == this.childJDT) { //we are visiting `else` of `if` ifElement.setElseStatement(child); return; } else { throw new SpoonException("Unexpected call of ParentExiter on CtIf"); } } super.visitCtIf(ifElement); }
public void visitCtIf(final spoon.reflect.code.CtIf ifElement) { spoon.reflect.code.CtIf aCtIf = ifElement.getFactory().Core().createIf(); this.builder.copy(ifElement, aCtIf); aCtIf.setAnnotations(this.cloneHelper.clone(ifElement.getAnnotations())); aCtIf.setCondition(this.cloneHelper.clone(ifElement.getCondition())); aCtIf.setThenStatement(this.cloneHelper.clone(((spoon.reflect.code.CtStatement) (ifElement.getThenStatement())))); aCtIf.setElseStatement(this.cloneHelper.clone(((spoon.reflect.code.CtStatement) (ifElement.getElseStatement())))); aCtIf.setComments(this.cloneHelper.clone(ifElement.getComments())); this.cloneHelper.tailor(ifElement, aCtIf); this.other = aCtIf; }
@Override public void process(CtIf ctIf) { l.add(ctIf.getCondition().getPosition()); } });
/** Return the list of CtElements Mutanted */ private List<MutantCtElement> getMutants(CtIf targetIF) { List<MutantCtElement> mutations = null; mutations = this.mutatorBinary.execute(targetIF.getCondition()); return mutations; }
public SymbolicConditionalReplacer(CtStatement target) { super(target, RepairType.CONDITIONAL); setDefaultValue(((CtIf) target).getCondition().toString()); super.setType(Boolean.class); }
protected void findFromIf(CtIf ifStatement) { findFromStatement(ifStatement); addCollectableSubconditions(ifStatement.getCondition()); }
@Override public void process(CtIf element) { List<CtExpression<Boolean>> ctExp = ExpressionRevolver.getExpressions(element.getCondition()); for (CtExpression ctExpression : ctExp) { super.add(ctExpression); } }
enterCtStatement(ifElement); printer.writeKeyword("if").writeSpace().writeSeparator("("); scan(ifElement.getCondition()); printer.writeSeparator(")"); CtStatement thenStmt = ifElement.getThenStatement();
@Override public void visitCtIf(CtIf ifElement) { CtExpression<Boolean> r = evaluate(ifElement.getCondition()); if (r instanceof CtLiteral) { CtLiteral<Boolean> l = (CtLiteral<Boolean>) r;
public static List<CtVariableAccess> collectVariableReadIgnoringBlocks(CtElement element) { if (element instanceof CtIf) { return collectVariableRead(((CtIf) element).getCondition()); } if (element instanceof CtWhile) { return collectVariableRead(((CtWhile) element).getLoopingExpression()); } if (element instanceof CtFor) { return collectVariableRead(((CtFor) element).getExpression()); } return collectVariableRead(element); }
public static List<CtVariableAccess> collectVariableAccessIgnoringBlocks(CtElement element) { if (element instanceof CtIf) { return collectVariableAccess(((CtIf) element).getCondition()); } if (element instanceof CtWhile) { return collectVariableAccess(((CtWhile) element).getLoopingExpression()); } if (element instanceof CtFor) { return collectVariableAccess(((CtFor) element).getExpression()); } return collectVariableAccess(element); }
protected OperatorInstance createModificationInstance(ModificationPoint point, MutantCtElement fix) throws IllegalAccessException { CtIf targetIF = (CtIf) point.getCodeElement(); OperatorInstance operation = new OperatorInstance(); operation.setOriginal(targetIF.getCondition()); operation.setOperationApplied(this); operation.setModificationPoint(point); operation.setModified(fix.getElement()); return operation; }
public void visitCtIf(CtIf ifElement) { write("if ("); scan(ifElement.getCondition()); write(") then "); scan((CtStatement) ifElement.getThenStatement()); write(" else "); scan((CtStatement) ifElement.getElseStatement()); }
public void visitCtIf(CtIf ifElement) { enter(ifElement); scan(ifElement.getAnnotations()); scan(ifElement.getCondition()); scan((CtStatement) ifElement.getThenStatement()); scan((CtStatement) ifElement.getElseStatement()); exit(ifElement); }