@SuppressWarnings("unchecked") @Override public <T, U> U getValue(T element) { return ((U) ((Object) (castTarget(element).getThenStatement()))); }
/** * 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); } }
return element.equals(anIf.getThenStatement()) || element.equals(anIf.getElseStatement());
@Override public void visitCtIf(CtIf e) { super.visitCtIf(e); boolean inThen = true; CtStatement stat = e.getThenStatement(); if (stat != target) { stat = e.getElseStatement(); inThen = false; } if (stat != target) { throw new IllegalArgumentException("should not happen"); } if (stat instanceof CtBlock) { insertType.insert((CtBlock<?>) stat, statementsToBeInserted); } else { CtBlock<?> block = insertNewBlock(stat); if (inThen) { e.setThenStatement(block); } else { e.setElseStatement(block); } } }
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); }
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)); }
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; }
CtLiteral<Boolean> l = (CtLiteral<Boolean>) r; if (l.getValue()) { setResult(evaluate(ifElement.getThenStatement())); } else { if (ifElement.getElseStatement() != null) { boolean thenEnded = false; boolean elseEnded = false; ifRes.setThenStatement((CtStatement) evaluate(ifElement.getThenStatement())); if (flowEnded) { thenEnded = true;
@Override public void visitCtIf(CtIf e) { super.visitCtIf(e); switch (role) { case THEN: if (e.getThenStatement() != null) { matchs.add(e.getThenStatement()); } case ELSE: if (e.getElseStatement() != null) { matchs.add(e.getElseStatement()); } } } }
@Override public void visitCtIf(CtIf e) { CtStatement thenStatement = e.getThenStatement(); if (thenStatement != null) { if (!(thenStatement instanceof CtBlock)) {
scan(ifElement.getCondition()); printer.writeSeparator(")"); CtStatement thenStmt = ifElement.getThenStatement(); CtStatement elseStmt = ifElement.getElseStatement(); elementPrinterHelper.writeIfOrLoopBlock(thenStmt);
@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; }
private static CtIf originalLoopReplacement(Factory factory, LoopMonitor monitor, While loop) { CtExpression<Boolean> monitoredCondition = newExpressionFromSnippet(factory, conditionName(monitor), Boolean.class); CtIf newIf = newIf(factory, monitoredCondition, loop.loopBody(), newBreak(factory)); CtStatement increment = newStatementFromSnippet(factory, format("%s += 1", counterName(monitor))); insertBeforeUnderSameParent(increment, newIf.getThenStatement()); if (loop.isUnbreakable()) { newIf.setElseStatement(null); } return newIf; }
@Override public void visitCtIf(CtIf ifElement) { if (ifElement.getCondition() == null && child instanceof CtExpression) { ifElement.setCondition((CtExpression<Boolean>) child); return; } else if (child instanceof CtStatement) { if (ifElement.getThenStatement() == null) { ifElement.setThenStatement((CtStatement) child); return; } else if (ifElement.getElseStatement() == null) { ifElement.setElseStatement((CtStatement) child); return; } } super.visitCtIf(ifElement); }
@Override public void visitCtIf(CtIf element) { super.visitCtIf(element); if(!(element.getThenStatement() instanceof CtBlock)){ CtStatement c = element.getThenStatement() ; CtBlock nBlock = MutationSupporter.getFactory().Core().createBlock(); nBlock.addStatement(c); element.setThenStatement(nBlock); } if( element.getElseStatement() != null && !(element.getElseStatement() instanceof CtBlock)){ CtStatement c = element.getElseStatement() ; CtBlock nBlock = MutationSupporter.getFactory().Core().createBlock(); nBlock.addStatement(c); element.setElseStatement(nBlock); } }
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); }
CtLiteral<Boolean> l = (CtLiteral<Boolean>) r; if (l.getValue()) { setResult(evaluate(null, ifElement.getThenStatement())); } else { setResult(evaluate(null, ifElement.getElseStatement())); ifRes.setCondition(r); boolean thenEnded = false, elseEnded = false; ifRes.setThenStatement((CtStatement) evaluate(ifRes, ifElement.getThenStatement())); if (flowEnded) { thenEnded = true;
scan(ifElement.getCondition()); write(")"); if (ifElement.getThenStatement() instanceof CtBlock) { write(" "); scan((CtStatement) ifElement.getThenStatement()); write(" "); } else { incTab().writeln().writeTabs(); writeStatement(ifElement.getThenStatement()); if (env.isPreserveLineNumbers()) { decTab();