/** Convert a tree to a pretty-printed string. */ public String toString() { StringWriter s = new StringWriter(); try { new Pretty(s, false).printExpr(this); } catch (IOException e) { // should never happen, because StringWriter is defined // never to throw any IOExceptions throw new AssertionError(e); } return s.toString(); }
private String operatorName(Tag tag) { // dummy instance, just to access a public method which should be static return new Pretty(null, false).operatorName(tag); }
/** Convert a tree to a pretty-printed string. */ public String toString() { StringWriter s = new StringWriter(); try { new Pretty(s, false).printExpr(this); } catch (IOException e) { // should never happen, because StringWriter is defined // never to throw any IOExceptions throw new AssertionError(e); } return s.toString(); }
/** Convert a tree to a pretty-printed string. */ @Override public String toString() { StringWriter s = new StringWriter(); try { new Pretty(s, false).printExpr(this); } catch (IOException e) { // should never happen, because StringWriter is defined // never to throw any IOExceptions throw new AssertionError(e); } return s.toString(); }
/** Convert a tree to a pretty-printed string. */ @Override public String toString() { StringWriter s = new StringWriter(); try { new Pretty(s, false).printExpr(this); } catch (IOException e) { // should never happen, because StringWriter is defined // never to throw any IOExceptions throw new AssertionError(e); } return s.toString(); }
/** Convert a expression-statement tree to a pretty-printed string. */ @Override public String toString() { StringWriter s = new StringWriter(); try { new Pretty(s, false).printStat(this); } catch (IOException e) { // should never happen, because StringWriter is defined // never to throw any IOExceptions throw new AssertionError(e); } return s.toString(); } }
/** Convert a expression-statement tree to a pretty-printed string. */ @Override public String toString() { StringWriter s = new StringWriter(); try { new Pretty(s, false).printStat(this); } catch (IOException e) { // should never happen, because StringWriter is defined // never to throw any IOExceptions throw new AssertionError(e); } return s.toString(); } }
public static String toSimpleString(JCTree tree, int maxLength) { StringWriter s = new StringWriter(); try { new Pretty(s, false).printExpr(tree); } catch (IOException e) { // should never happen, because StringWriter is defined // never to throw any IOExceptions throw new AssertionError(e); } //we need to (i) replace all line terminators with a space and (ii) remove //occurrences of 'missing' in the Pretty output (generated when types are missing) String res = s.toString().trim().replaceAll("\\s+", " ").replaceAll("/\\*missing\\*/", ""); if (res.length() < maxLength) { return res; } else { int head = (maxLength - trimSequence.length()) * 2 / 3; int tail = maxLength - trimSequence.length() - head; return res.substring(0, head) + trimSequence + res.substring(res.length() - tail); } }
public static String toSimpleString(JCTree tree, int maxLength) { StringWriter s = new StringWriter(); try { new Pretty(s, false).printExpr(tree); } catch (IOException e) { // should never happen, because StringWriter is defined // never to throw any IOExceptions throw new AssertionError(e); } //we need to (i) replace all line terminators with a space and (ii) remove //occurrences of 'missing' in the Pretty output (generated when types are missing) String res = s.toString().trim().replaceAll("\\s+", " ").replaceAll("/\\*missing\\*/", ""); if (res.length() < maxLength) { return res; } else { int head = (maxLength - trimSequence.length()) * 2 / 3; int tail = maxLength - trimSequence.length() - head; return res.substring(0, head) + trimSequence + res.substring(res.length() - tail); } }
/** Emit plain Java source for a class. * @param env The attribution environment of the outermost class * containing this class. * @param cdef The class definition to be printed. */ JavaFileObject printSource(Env<AttrContext> env, JCClassDecl cdef) throws IOException { JavaFileObject outFile = fileManager.getJavaFileForOutput(CLASS_OUTPUT, cdef.sym.flatname.toString(), JavaFileObject.Kind.SOURCE, null); if (inputFiles.contains(outFile)) { log.error(cdef.pos(), "source.cant.overwrite.input.file", outFile); return null; } else { BufferedWriter out = new BufferedWriter(outFile.openWriter()); try { new Pretty(out, true).printUnit(env.toplevel, cdef); if (verbose) printVerbose("wrote.file", outFile); } finally { out.close(); } return outFile; } }
/** Emit plain Java source for a class. * @param env The attribution environment of the outermost class * containing this class. * @param cdef The class definition to be printed. */ JavaFileObject printSource(Env<AttrContext> env, JCClassDecl cdef) throws IOException { JavaFileObject outFile = fileManager.getJavaFileForOutput(CLASS_OUTPUT, cdef.sym.flatname.toString(), JavaFileObject.Kind.SOURCE, null); if (inputFiles.contains(outFile)) { log.error(cdef.pos(), "source.cant.overwrite.input.file", outFile); return null; } else { BufferedWriter out = new BufferedWriter(outFile.openWriter()); try { new Pretty(out, true).printUnit(env.toplevel, cdef); if (verbose) log.printVerbose("wrote.file", outFile); } finally { out.close(); } return outFile; } }
/** Emit plain Java source for a class. * @param env The attribution environment of the outermost class * containing this class. * @param cdef The class definition to be printed. */ JavaFileObject printSource(Env<AttrContext> env, JCClassDecl cdef) throws IOException { JavaFileObject outFile = fileManager.getJavaFileForOutput(CLASS_OUTPUT, cdef.sym.flatname.toString(), JavaFileObject.Kind.SOURCE, null); if (inputFiles.contains(outFile)) { log.error(cdef.pos(), "source.cant.overwrite.input.file", outFile); return null; } else { BufferedWriter out = new BufferedWriter(outFile.openWriter()); try { new Pretty(out, true).printUnit(env.toplevel, cdef); if (verbose) printVerbose("wrote.file", outFile); } finally { out.close(); } return outFile; } }
/** Emit plain Java source for a class. * @param env The attribution environment of the outermost class * containing this class. * @param cdef The class definition to be printed. */ JavaFileObject printSource(Env<AttrContext> env, JCClassDecl cdef) throws IOException { JavaFileObject outFile = fileManager.getJavaFileForOutput(CLASS_OUTPUT, cdef.sym.flatname.toString(), JavaFileObject.Kind.SOURCE, null); if (inputFiles.contains(outFile)) { log.error(cdef.pos(), "source.cant.overwrite.input.file", outFile); return null; } else { BufferedWriter out = new BufferedWriter(outFile.openWriter()); try { new Pretty(out, true).printUnit(env.toplevel, cdef); if (verbose) log.printVerbose("wrote.file", outFile); } finally { out.close(); } return outFile; } }