printer.calculate(cu, toBePrinted); stream.print(printer.getResult()); for (CtType<?> t : toBePrinted) { lineNumberMappings.put(t.getQualifiedName(), printer.getLineNumberMapping());
private void createModuleFile(CtModule module) { if (getEnvironment().getComplianceLevel() > 8 && module != getFactory().getModel().getUnnamedModule()) { File moduleFile = getElementPath(module).toFile(); if (!printedFiles.contains(moduleFile)) { printedFiles.add(moduleFile); } try (PrintStream stream = new PrintStream(moduleFile)) { stream.println(getPrinter().printModuleInfo(module)); } catch (FileNotFoundException e) { Launcher.LOGGER.error(e.getMessage(), e); } } }
private void createPackageFile(CtPackage pack) { // Create package annotation file File packageAnnot = getElementPath(pack).toFile(); if (!printedFiles.contains(packageAnnot)) { printedFiles.add(packageAnnot); } try (PrintStream stream = new PrintStream(packageAnnot)) { stream.println(getPrinter().printPackageInfo(pack)); } catch (FileNotFoundException e) { Launcher.LOGGER.error(e.getMessage(), e); } }
protected InputStream getCompilationUnitInputStream(String path) { Environment env = factory.getEnvironment(); spoon.reflect.cu.CompilationUnit cu = factory.CompilationUnit().getMap().get(path); List<CtType<?>> toBePrinted = cu.getDeclaredTypes(); PrettyPrinter printer = env.createPrettyPrinter(); printer.calculate(cu, toBePrinted); return new ByteArrayInputStream(printer.getResult().getBytes(env.getEncoding())); }
toBePrinted.add(element); printer.calculate(cu, toBePrinted); stream.println(printer.getPackageDeclaration()); stream.close(); } catch (FileNotFoundException e) { stream.print(printer.getResult()); for (CtType<?> t : toBePrinted) { lineNumberMappings.put(t.getQualifiedName(), printer.getLineNumberMapping());
/** * Creates a source file for each processed top-level type and pretty prints * its contents. */ public void process(CtType<?> type) { if (type.isTopLevel()) { createJavaFile(type); } printer.reset(); }
protected InputStream getCompilationUnitInputStream(String path) { Environment env = factory.getEnvironment(); spoon.reflect.cu.CompilationUnit cu = factory.CompilationUnit().getMap().get(path); List<CtType<?>> toBePrinted = cu.getDeclaredTypes(); PrettyPrinter printer = null; if (printer == null) { printer = new DefaultJavaPrettyPrinter(env); } printer.calculate(cu, toBePrinted); return new ByteArrayInputStream(printer.getResult().toString().getBytes()); }