@Override public <R> void visitCtBlock(CtBlock<R> block) { int i = 0; while (i < block.getStatements().size()) { int size = block.getStatements().size(); CtStatement s = block.getStatement(i); s.accept(this); if (block.getStatements().size() >= size) i++; } }
/** * Replaces the element by an statement list containing all unary operators in the element * * @param element */ private void replaceByUnaryBlock(CtElement element) { CtBlock<CtUnaryOperator> opBlock = new CtBlockImpl<CtUnaryOperator>(); for (CtUnaryOperator s : element.getElements(new TypeFilter<CtUnaryOperator>(CtUnaryOperator.class))) if (s.getKind().compareTo(UnaryOperatorKind.PREINC) >= 0) { s.setParent(null); opBlock.addStatement(s); s.setParent(opBlock); } element.replace(opBlock); }
/** * Pretty print for the resulting degraded block * * @param clonedBody * @return */ public String prettyPrintBody(CtStatement clonedBody) { String result = ""; if (clonedBody instanceof CtBlock) { CtBlock block = (CtBlock) clonedBody; try { for (int i = 0; i < block.getStatements().size(); i++) { if (block.getStatement(i) instanceof CtBlock) result += prettyPrintBody(block.getStatement(i)); else if (block.getStatement(i) != null) result += block.getStatement(i).toString() + ";\n"; } } catch (NullPointerException ex) { log.error("Unable to print the degraded loop!"); } } else result = clonedBody.toString(); return result; }