public String getCode() { if (astElement != null) { try { if (printer == null) return astElement.toString(); printer.reset(); printer.scan(astElement); return printer.toString(); } catch (NullPointerException ex) { throw new NullPointerException( "Unable to get the code. Code field was empty and astElement.toString() throw null"); } } return code; }
/** * 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; }