/** * The generic scan method for an element. */ public DefaultJavaPrettyPrinter scan(CtElement e) { if (e != null) { enter(e); context.elementStack.push(e); if (env.isPreserveLineNumbers()) { if (!(e instanceof CtNamedElement)) { getPrinterHelper().adjustStartPosition(e); } } try { e.accept(this); } catch (SpoonException ex) { throw ex; } catch (Exception ex) { String elementInfo = e.getClass().getName(); elementInfo += " on path " + getPath(e) + "\n"; if (e.getPosition().isValidPosition()) { elementInfo += "at position " + e.getPosition().toString() + " "; } throw new SpoonException("Printing of " + elementInfo + "failed", ex); } context.elementStack.pop(); exit(e); } return this; }
@Override public void visitCtModule(CtModule module) { enter(module); if (module.isOpenModule()) { printer.writeKeyword("open").writeSpace(); } printer.writeKeyword("module").writeSpace().writeIdentifier(module.getSimpleName()); printer.writeSpace().writeSeparator("{").incTab().writeln(); for (CtModuleDirective moduleDirective : module.getModuleDirectives()) { scan(moduleDirective); } printer.decTab().writeSeparator("}"); exit(module); }