com.sun.tools.javac.tree.Pretty Java Examples
The following examples show how to use
com.sun.tools.javac.tree.Pretty.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JavaCompiler.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** 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(), Errors.SourceCantOverwriteInputFile(outFile)); return null; } else { try (BufferedWriter out = new BufferedWriter(outFile.openWriter())) { new Pretty(out, true).printUnit(env.toplevel, cdef); if (verbose) log.printVerbose("wrote.file", outFile); } return outFile; } }
Example #2
Source File: JavaCompiler.java From javaide with GNU General Public License v3.0 | 6 votes |
/** * 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; } }
Example #3
Source File: Trees.java From javaide with GNU General Public License v3.0 | 6 votes |
/** * Returns the string name of an operator, including assignment and compound assignment. */ static String operatorName(ExpressionTree expression) { // JCTree.Tag tag = ((JCTree) expression).getTag(); // if (tag == JCTree.Tag.ASSIGN) { // return "="; // } // boolean assignOp = expression instanceof CompoundAssignmentTree; // if (assignOp) { // tag = tag.noAssignOp(); // } int tag = ((JCTree) expression).getTag(); if (tag == JCTree.ASSIGN) { return "="; } boolean assignOp = expression instanceof CompoundAssignmentTree; if (assignOp) { // tag = tag.noAssignOp(); // TODO: 22-Jul-17 ????? } String name = new Pretty(/*writer*/ null, /*sourceOutput*/ true).operatorName(tag); return assignOp ? name + "=" : name; }
Example #4
Source File: JavaCompiler.java From java-n-IDE-for-Android with Apache License 2.0 | 6 votes |
/** * 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; } }
Example #5
Source File: Trees.java From java-n-IDE-for-Android with Apache License 2.0 | 6 votes |
/** * Returns the string name of an operator, including assignment and compound assignment. */ static String operatorName(ExpressionTree expression) { // JCTree.Tag tag = ((JCTree) expression).getTag(); // if (tag == JCTree.Tag.ASSIGN) { // return "="; // } // boolean assignOp = expression instanceof CompoundAssignmentTree; // if (assignOp) { // tag = tag.noAssignOp(); // } int tag = ((JCTree) expression).getTag(); if (tag == JCTree.ASSIGN) { return "="; } boolean assignOp = expression instanceof CompoundAssignmentTree; if (assignOp) { // tag = tag.noAssignOp(); // TODO: 22-Jul-17 ????? } String name = new Pretty(/*writer*/ null, /*sourceOutput*/ true).operatorName(tag); return assignOp ? name + "=" : name; }
Example #6
Source File: DPrinter.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
protected void printTree(String label, JCTree tree) { if (tree == null) { printNull(label); } else { indent(); String ext; try { ext = tree.getKind().name(); } catch (Throwable t) { ext = "n/a"; } out.print(label + ": " + info(tree.getClass(), tree.getTag(), ext)); if (showPositions) { // We can always get start position, but to get end position // and/or line+offset, we would need a JCCompilationUnit out.print(" pos:" + tree.pos); } if (showTreeTypes && tree.type != null) out.print(" type:" + toString(tree.type)); Symbol sym; if (showTreeSymbols && (sym = TreeInfo.symbolFor(tree)) != null) out.print(" sym:" + toString(sym)); out.println(); indent(+1); if (showSrc) { indent(); out.println("src: " + Pretty.toSimpleString(tree, maxSrcLength)); } tree.accept(treeVisitor); indent(-1); } }
Example #7
Source File: Trees.java From google-java-format with Apache License 2.0 | 5 votes |
/** Returns the string name of an operator, including assignment and compound assignment. */ static String operatorName(ExpressionTree expression) { JCTree.Tag tag = ((JCTree) expression).getTag(); if (tag == JCTree.Tag.ASSIGN) { return "="; } boolean assignOp = expression instanceof CompoundAssignmentTree; if (assignOp) { tag = tag.noAssignOp(); } String name = new Pretty(/*writer*/ null, /*sourceOutput*/ true).operatorName(tag); return assignOp ? name + "=" : name; }
Example #8
Source File: GenStubs.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
void makeStub(StandardJavaFileManager fm, CompilationUnitTree tree) throws IOException { CompilationUnitTree tree2 = new StubMaker().translate(tree); CompilationUnitTree tree3 = new ImportCleaner(fm).removeRedundantImports(tree2); String className = fm.inferBinaryName(StandardLocation.SOURCE_PATH, tree.getSourceFile()); JavaFileObject fo = fm.getJavaFileForOutput(StandardLocation.SOURCE_OUTPUT, className, JavaFileObject.Kind.SOURCE, null); // System.err.println("Writing " + className + " to " + fo.getName()); Writer out = fo.openWriter(); try { new Pretty(out, true).printExpr((JCTree) tree3); } finally { out.close(); } }
Example #9
Source File: DPrinter.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
protected void printTree(String label, JCTree tree) { if (tree == null) { printNull(label); } else { indent(); String ext; try { ext = tree.getKind().name(); } catch (Throwable t) { ext = "n/a"; } out.print(label + ": " + info(tree.getClass(), tree.getTag(), ext)); if (showPositions) { // We can always get start position, but to get end position // and/or line+offset, we would need a JCCompilationUnit out.print(" pos:" + tree.pos); } if (showTreeTypes && tree.type != null) out.print(" type:" + toString(tree.type)); Symbol sym; if (showTreeSymbols && (sym = TreeInfo.symbolFor(tree)) != null) out.print(" sym:" + toString(sym)); out.println(); indent(+1); if (showSrc) { indent(); out.println("src: " + Pretty.toSimpleString(tree, maxSrcLength)); } tree.accept(treeVisitor); indent(-1); } }
Example #10
Source File: GenStubs.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
void makeStub(StandardJavaFileManager fm, CompilationUnitTree tree) throws IOException { CompilationUnitTree tree2 = new StubMaker().translate(tree); CompilationUnitTree tree3 = new ImportCleaner(fm).removeRedundantImports(tree2); String className = fm.inferBinaryName(StandardLocation.SOURCE_PATH, tree.getSourceFile()); JavaFileObject fo = fm.getJavaFileForOutput(StandardLocation.SOURCE_OUTPUT, className, JavaFileObject.Kind.SOURCE, null); // System.err.println("Writing " + className + " to " + fo.getName()); Writer out = fo.openWriter(); try { new Pretty(out, true).printExpr((JCTree) tree3); } finally { out.close(); } }
Example #11
Source File: AbstractDiagnosticFormatter.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
private String expr2String(JCExpression tree) { switch(tree.getTag()) { case PARENS: return expr2String(((JCParens)tree).expr); case LAMBDA: case REFERENCE: case CONDEXPR: return Pretty.toSimpleString(tree); default: Assert.error("unexpected tree kind " + tree.getKind()); return null; } }
Example #12
Source File: Test.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
void checkEndPos(CompilationUnitTree unit, Tree tree) { long sp = srcPosns.getStartPosition(unit, tree); long ep = srcPosns.getEndPosition(unit, tree); if (sp >= 0 && ep == Position.NOPOS) { error("endpos not set for " + tree.getKind() + " " + Pretty.toSimpleString(((JCTree) tree)) +", start:" + sp); } }
Example #13
Source File: DPrinter.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
protected void printTree(String label, JCTree tree) { if (tree == null) { printNull(label); } else { indent(); String ext; try { ext = tree.getKind().name(); } catch (Throwable t) { ext = "n/a"; } out.print(label + ": " + info(tree.getClass(), tree.getTag(), ext)); if (showPositions) { // We can always get start position, but to get end position // and/or line+offset, we would need a JCCompilationUnit out.print(" pos:" + tree.pos); } if (showTreeTypes && tree.type != null) out.print(" type:" + toString(tree.type)); Symbol sym; if (showTreeSymbols && (sym = TreeInfo.symbolFor(tree)) != null) out.print(" sym:" + toString(sym)); out.println(); indent(+1); if (showSrc) { indent(); out.println("src: " + Pretty.toSimpleString(tree, maxSrcLength)); } tree.accept(treeVisitor); indent(-1); } }
Example #14
Source File: GenStubs.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
void makeStub(StandardJavaFileManager fm, CompilationUnitTree tree) throws IOException { CompilationUnitTree tree2 = new StubMaker().translate(tree); CompilationUnitTree tree3 = new ImportCleaner(fm).removeRedundantImports(tree2); String className = fm.inferBinaryName(StandardLocation.SOURCE_PATH, tree.getSourceFile()); JavaFileObject fo = fm.getJavaFileForOutput(StandardLocation.SOURCE_OUTPUT, className, JavaFileObject.Kind.SOURCE, null); // System.err.println("Writing " + className + " to " + fo.getName()); Writer out = fo.openWriter(); try { new Pretty(out, true).printExpr((JCTree) tree3); } finally { out.close(); } }
Example #15
Source File: AbstractDiagnosticFormatter.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private String expr2String(JCExpression tree) { switch(tree.getTag()) { case PARENS: return expr2String(((JCParens)tree).expr); case LAMBDA: case REFERENCE: case CONDEXPR: return Pretty.toSimpleString(tree); default: Assert.error("unexpected tree kind " + tree.getKind()); return null; } }
Example #16
Source File: Test.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
void checkEndPos(CompilationUnitTree unit, Tree tree) { long sp = srcPosns.getStartPosition(unit, tree); long ep = srcPosns.getEndPosition(unit, tree); if (sp >= 0 && ep == Position.NOPOS) { error("endpos not set for " + tree.getKind() + " " + Pretty.toSimpleString(((JCTree) tree)) +", start:" + sp); } }
Example #17
Source File: DPrinter.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
protected void printTree(String label, JCTree tree) { if (tree == null) { printNull(label); } else { indent(); String ext; try { ext = tree.getKind().name(); } catch (Throwable t) { ext = "n/a"; } out.print(label + ": " + info(tree.getClass(), tree.getTag(), ext)); if (showPositions) { // We can always get start position, but to get end position // and/or line+offset, we would need a JCCompilationUnit out.print(" pos:" + tree.pos); } if (showTreeTypes && tree.type != null) out.print(" type:" + toString(tree.type)); Symbol sym; if (showTreeSymbols && (sym = TreeInfo.symbolFor(tree)) != null) out.print(" sym:" + toString(sym)); out.println(); indent(+1); if (showSrc) { indent(); out.println("src: " + Pretty.toSimpleString(tree, maxSrcLength)); } tree.accept(treeVisitor); indent(-1); } }
Example #18
Source File: GenStubs.java From hottub with GNU General Public License v2.0 | 5 votes |
void makeStub(StandardJavaFileManager fm, CompilationUnitTree tree) throws IOException { CompilationUnitTree tree2 = new StubMaker().translate(tree); CompilationUnitTree tree3 = new ImportCleaner(fm).removeRedundantImports(tree2); String className = fm.inferBinaryName(StandardLocation.SOURCE_PATH, tree.getSourceFile()); JavaFileObject fo = fm.getJavaFileForOutput(StandardLocation.SOURCE_OUTPUT, className, JavaFileObject.Kind.SOURCE, null); // System.err.println("Writing " + className + " to " + fo.getName()); Writer out = fo.openWriter(); try { new Pretty(out, true).printExpr((JCTree) tree3); } finally { out.close(); } }
Example #19
Source File: AbstractDiagnosticFormatter.java From hottub with GNU General Public License v2.0 | 5 votes |
private String expr2String(JCExpression tree) { switch(tree.getTag()) { case PARENS: return expr2String(((JCParens)tree).expr); case LAMBDA: case REFERENCE: case CONDEXPR: return Pretty.toSimpleString(tree); default: Assert.error("unexpected tree kind " + tree.getKind()); return null; } }
Example #20
Source File: Test.java From hottub with GNU General Public License v2.0 | 5 votes |
void checkEndPos(CompilationUnitTree unit, Tree tree) { long sp = srcPosns.getStartPosition(unit, tree); long ep = srcPosns.getEndPosition(unit, tree); if (sp >= 0 && ep == Position.NOPOS) { error("endpos not set for " + tree.getKind() + " " + Pretty.toSimpleString(((JCTree) tree)) +", start:" + sp); } }
Example #21
Source File: DPrinter.java From hottub with GNU General Public License v2.0 | 5 votes |
protected void printTree(String label, JCTree tree) { if (tree == null) { printNull(label); } else { indent(); String ext; try { ext = tree.getKind().name(); } catch (Throwable t) { ext = "n/a"; } out.print(label + ": " + info(tree.getClass(), tree.getTag(), ext)); if (showPositions) { // We can always get start position, but to get end position // and/or line+offset, we would need a JCCompilationUnit out.print(" pos:" + tree.pos); } if (showTreeTypes && tree.type != null) out.print(" type:" + toString(tree.type)); Symbol sym; if (showTreeSymbols && (sym = TreeInfo.symbolFor(tree)) != null) out.print(" sym:" + toString(sym)); out.println(); indent(+1); if (showSrc) { indent(); out.println("src: " + Pretty.toSimpleString(tree, maxSrcLength)); } tree.accept(treeVisitor); indent(-1); } }
Example #22
Source File: GenStubs.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
void makeStub(StandardJavaFileManager fm, CompilationUnitTree tree) throws IOException { CompilationUnitTree tree2 = new StubMaker().translate(tree); CompilationUnitTree tree3 = new ImportCleaner(fm).removeRedundantImports(tree2); String className = fm.inferBinaryName(StandardLocation.SOURCE_PATH, tree.getSourceFile()); JavaFileObject fo = fm.getJavaFileForOutput(StandardLocation.SOURCE_OUTPUT, className, JavaFileObject.Kind.SOURCE, null); // System.err.println("Writing " + className + " to " + fo.getName()); Writer out = fo.openWriter(); try { new Pretty(out, true).printExpr((JCTree) tree3); } finally { out.close(); } }
Example #23
Source File: AbstractDiagnosticFormatter.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
private String expr2String(JCExpression tree) { switch(tree.getTag()) { case PARENS: return expr2String(((JCParens)tree).expr); case LAMBDA: case REFERENCE: case CONDEXPR: return Pretty.toSimpleString(tree); default: Assert.error("unexpected tree kind " + tree.getKind()); return null; } }
Example #24
Source File: Test.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
void checkEndPos(CompilationUnitTree unit, Tree tree) { long sp = srcPosns.getStartPosition(unit, tree); long ep = srcPosns.getEndPosition(unit, tree); if (sp >= 0 && ep == Position.NOPOS) { error("endpos not set for " + tree.getKind() + " " + Pretty.toSimpleString(((JCTree) tree)) +", start:" + sp); } }
Example #25
Source File: DPrinter.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
protected void printTree(String label, JCTree tree) { if (tree == null) { printNull(label); } else { indent(); String ext; try { ext = tree.getKind().name(); } catch (Throwable t) { ext = "n/a"; } out.print(label + ": " + info(tree.getClass(), tree.getTag(), ext)); if (showPositions) { // We can always get start position, but to get end position // and/or line+offset, we would need a JCCompilationUnit out.print(" pos:" + tree.pos); } if (showTreeTypes && tree.type != null) out.print(" type:" + toString(tree.type)); Symbol sym; if (showTreeSymbols && (sym = TreeInfo.symbolFor(tree)) != null) out.print(" sym:" + toString(sym)); out.println(); indent(+1); if (showSrc) { indent(); out.println("src: " + Pretty.toSimpleString(tree, maxSrcLength)); } tree.accept(treeVisitor); indent(-1); } }
Example #26
Source File: GenStubs.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
void makeStub(StandardJavaFileManager fm, CompilationUnitTree tree) throws IOException { CompilationUnitTree tree2 = new StubMaker().translate(tree); CompilationUnitTree tree3 = new ImportCleaner(fm).removeRedundantImports(tree2); String className = fm.inferBinaryName(StandardLocation.SOURCE_PATH, tree.getSourceFile()); JavaFileObject fo = fm.getJavaFileForOutput(StandardLocation.SOURCE_OUTPUT, className, JavaFileObject.Kind.SOURCE, null); // System.err.println("Writing " + className + " to " + fo.getName()); Writer out = fo.openWriter(); try { new Pretty(out, true).printExpr((JCTree) tree3); } finally { out.close(); } }
Example #27
Source File: AbstractDiagnosticFormatter.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
private String expr2String(JCExpression tree) { switch(tree.getTag()) { case PARENS: return expr2String(((JCParens)tree).expr); case LAMBDA: case REFERENCE: case CONDEXPR: return Pretty.toSimpleString(tree); default: Assert.error("unexpected tree kind " + tree.getKind()); return null; } }
Example #28
Source File: Test.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
void checkEndPos(CompilationUnitTree unit, Tree tree) { long sp = srcPosns.getStartPosition(unit, tree); long ep = srcPosns.getEndPosition(unit, tree); if (sp >= 0 && ep == Position.NOPOS) { error("endpos not set for " + tree.getKind() + " " + Pretty.toSimpleString(((JCTree) tree)) +", start:" + sp); } }
Example #29
Source File: DPrinter.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
protected void printTree(String label, JCTree tree) { if (tree == null) { printNull(label); } else { indent(); String ext; try { ext = tree.getKind().name(); } catch (Throwable t) { ext = "n/a"; } out.print(label + ": " + info(tree.getClass(), tree.getTag(), ext)); if (showPositions) { // We can always get start position, but to get end position // and/or line+offset, we would need a JCCompilationUnit out.print(" pos:" + tree.pos); } if (showTreeTypes && tree.type != null) out.print(" type:" + toString(tree.type)); Symbol sym; if (showTreeSymbols && (sym = TreeInfo.symbolFor(tree)) != null) out.print(" sym:" + toString(sym)); out.println(); indent(+1); if (showSrc) { indent(); out.println("src: " + Pretty.toSimpleString(tree, maxSrcLength)); } tree.accept(treeVisitor); indent(-1); } }
Example #30
Source File: GenStubs.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
void makeStub(StandardJavaFileManager fm, CompilationUnitTree tree) throws IOException { CompilationUnitTree tree2 = new StubMaker().translate(tree); CompilationUnitTree tree3 = new ImportCleaner(fm).removeRedundantImports(tree2); String className = fm.inferBinaryName(StandardLocation.SOURCE_PATH, tree.getSourceFile()); JavaFileObject fo = fm.getJavaFileForOutput(StandardLocation.SOURCE_OUTPUT, className, JavaFileObject.Kind.SOURCE, null); // System.err.println("Writing " + className + " to " + fo.getName()); Writer out = fo.openWriter(); try { new Pretty(out, true).printExpr((JCTree) tree3); } finally { out.close(); } }