8303078: Reduce allocations when pretty printing JCTree during compilation

Reviewed-by: jjg, vromero
This commit is contained in:
Christoph Dreis 2023-02-23 15:25:05 +00:00 committed by Jonathan Gibbons
parent 2cf8b8607d
commit 58ca711a97
2 changed files with 240 additions and 197 deletions

View File

@ -76,6 +76,12 @@ public class DocPretty implements DocTreeVisitor<Void,Void> {
out.write(Convert.escapeUnicode(s.toString())); out.write(Convert.escapeUnicode(s.toString()));
} }
/** Print character. Should be only used internally for known ASCII characters.
*/
private void print(char c) throws IOException {
out.write(c);
}
/** /**
* Print list. * Print list.
*/ */
@ -88,7 +94,7 @@ public class DocPretty implements DocTreeVisitor<Void,Void> {
/** /**
* Print list with separators. * Print list with separators.
*/ */
protected void print(List<? extends DocTree> list, String sep) throws IOException { private void print(List<? extends DocTree> list, char sep) throws IOException {
if (list.isEmpty()) if (list.isEmpty())
return; return;
boolean first = true; boolean first = true;
@ -107,7 +113,7 @@ public class DocPretty implements DocTreeVisitor<Void,Void> {
} }
protected void printTagName(DocTree node) throws IOException { protected void printTagName(DocTree node) throws IOException {
out.write("@"); out.write('@');
out.write(node.getKind().tagName); out.write(node.getKind().tagName);
} }
@ -128,7 +134,8 @@ public class DocPretty implements DocTreeVisitor<Void,Void> {
case DOUBLE -> "\""; case DOUBLE -> "\"";
}; };
if (quote != null) { if (quote != null) {
print("=" + quote); print('=');
print(quote);
print(node.getValue()); print(node.getValue());
print(quote); print(quote);
} }
@ -142,7 +149,7 @@ public class DocPretty implements DocTreeVisitor<Void,Void> {
public Void visitAuthor(AuthorTree node, Void p) { public Void visitAuthor(AuthorTree node, Void p) {
try { try {
printTagName(node); printTagName(node);
print(" "); print(' ');
print(node.getName()); print(node.getName());
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
@ -165,7 +172,7 @@ public class DocPretty implements DocTreeVisitor<Void,Void> {
try { try {
printTagName(node); printTagName(node);
if (!node.getBody().isEmpty()) { if (!node.getBody().isEmpty()) {
print(" "); print(' ');
print(node.getBody()); print(node.getBody());
} }
} catch (IOException e) { } catch (IOException e) {
@ -181,8 +188,8 @@ public class DocPretty implements DocTreeVisitor<Void,Void> {
List<? extends DocTree> t = node.getBlockTags(); List<? extends DocTree> t = node.getBlockTags();
print(b); print(b);
if (!b.isEmpty() && !t.isEmpty()) if (!b.isEmpty() && !t.isEmpty())
print("\n"); print('\n');
print(t, "\n"); print(t, '\n');
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
} }
@ -192,9 +199,9 @@ public class DocPretty implements DocTreeVisitor<Void,Void> {
@Override @DefinedBy(Api.COMPILER_TREE) @Override @DefinedBy(Api.COMPILER_TREE)
public Void visitDocRoot(DocRootTree node, Void p) { public Void visitDocRoot(DocRootTree node, Void p) {
try { try {
print("{"); print('{');
printTagName(node); printTagName(node);
print("}"); print('}');
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
} }
@ -216,7 +223,7 @@ public class DocPretty implements DocTreeVisitor<Void,Void> {
try { try {
print("</"); print("</");
print(node.getName()); print(node.getName());
print(">"); print('>');
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
} }
@ -226,9 +233,9 @@ public class DocPretty implements DocTreeVisitor<Void,Void> {
@Override @DefinedBy(Api.COMPILER_TREE) @Override @DefinedBy(Api.COMPILER_TREE)
public Void visitEntity(EntityTree node, Void p) { public Void visitEntity(EntityTree node, Void p) {
try { try {
print("&"); print('&');
print(node.getName()); print(node.getName());
print(";"); print(';');
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
} }
@ -248,7 +255,7 @@ public class DocPretty implements DocTreeVisitor<Void,Void> {
@Override @DefinedBy(Api.COMPILER_TREE) @Override @DefinedBy(Api.COMPILER_TREE)
public Void visitEscape(EscapeTree node, Void p) { public Void visitEscape(EscapeTree node, Void p) {
try { try {
out.write("@"); out.write('@');
print(node.getBody()); print(node.getBody());
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
@ -261,7 +268,7 @@ public class DocPretty implements DocTreeVisitor<Void,Void> {
try { try {
printTagName(node); printTagName(node);
if (!node.getBody().isEmpty()) { if (!node.getBody().isEmpty()) {
print(" "); print(' ');
print(node.getBody()); print(node.getBody());
} }
} catch (IOException e) { } catch (IOException e) {
@ -283,15 +290,15 @@ public class DocPretty implements DocTreeVisitor<Void,Void> {
@Override @DefinedBy(Api.COMPILER_TREE) @Override @DefinedBy(Api.COMPILER_TREE)
public Void visitIndex(IndexTree node, Void p) { public Void visitIndex(IndexTree node, Void p) {
try { try {
print("{"); print('{');
printTagName(node); printTagName(node);
print(" "); print(' ');
print(node.getSearchTerm()); print(node.getSearchTerm());
if (!node.getDescription().isEmpty()) { if (!node.getDescription().isEmpty()) {
print(" "); print(' ');
print(node.getDescription()); print(node.getDescription());
} }
print("}"); print('}');
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
} }
@ -301,9 +308,9 @@ public class DocPretty implements DocTreeVisitor<Void,Void> {
@Override @DefinedBy(Api.COMPILER_TREE) @Override @DefinedBy(Api.COMPILER_TREE)
public Void visitInheritDoc(InheritDocTree node, Void p) { public Void visitInheritDoc(InheritDocTree node, Void p) {
try { try {
print("{"); print('{');
printTagName(node); printTagName(node);
print("}"); print('}');
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
} }
@ -313,15 +320,15 @@ public class DocPretty implements DocTreeVisitor<Void,Void> {
@Override @DefinedBy(Api.COMPILER_TREE) @Override @DefinedBy(Api.COMPILER_TREE)
public Void visitLink(LinkTree node, Void p) { public Void visitLink(LinkTree node, Void p) {
try { try {
print("{"); print('{');
printTagName(node); printTagName(node);
print(" "); print(' ');
print(node.getReference()); print(node.getReference());
if (!node.getLabel().isEmpty()) { if (!node.getLabel().isEmpty()) {
print(" "); print(' ');
print(node.getLabel()); print(node.getLabel());
} }
print("}"); print('}');
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
} }
@ -331,14 +338,14 @@ public class DocPretty implements DocTreeVisitor<Void,Void> {
@Override @DefinedBy(Api.COMPILER_TREE) @Override @DefinedBy(Api.COMPILER_TREE)
public Void visitLiteral(LiteralTree node, Void p) { public Void visitLiteral(LiteralTree node, Void p) {
try { try {
print("{"); print('{');
printTagName(node); printTagName(node);
String body = node.getBody().getBody(); String body = node.getBody().getBody();
if (!body.isEmpty() && !Character.isWhitespace(body.charAt(0))) { if (!body.isEmpty() && !Character.isWhitespace(body.charAt(0))) {
print(" "); print(' ');
} }
print(node.getBody()); print(node.getBody());
print("}"); print('}');
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
} }
@ -349,12 +356,12 @@ public class DocPretty implements DocTreeVisitor<Void,Void> {
public Void visitParam(ParamTree node, Void p) { public Void visitParam(ParamTree node, Void p) {
try { try {
printTagName(node); printTagName(node);
print(" "); print(' ');
if (node.isTypeParameter()) print("<"); if (node.isTypeParameter()) print('<');
print(node.getName()); print(node.getName());
if (node.isTypeParameter()) print(">"); if (node.isTypeParameter()) print('>');
if (!node.getDescription().isEmpty()) { if (!node.getDescription().isEmpty()) {
print(" "); print(' ');
print(node.getDescription()); print(node.getDescription());
} }
} catch (IOException e) { } catch (IOException e) {
@ -367,10 +374,10 @@ public class DocPretty implements DocTreeVisitor<Void,Void> {
public Void visitProvides(ProvidesTree node, Void p) { public Void visitProvides(ProvidesTree node, Void p) {
try { try {
printTagName(node); printTagName(node);
print(" "); print(' ');
print(node.getServiceType()); print(node.getServiceType());
if (!node.getDescription().isEmpty()) { if (!node.getDescription().isEmpty()) {
print(" "); print(' ');
print(node.getDescription()); print(node.getDescription());
} }
} catch (IOException e) { } catch (IOException e) {
@ -393,13 +400,13 @@ public class DocPretty implements DocTreeVisitor<Void,Void> {
public Void visitReturn(ReturnTree node, Void p) { public Void visitReturn(ReturnTree node, Void p) {
try { try {
if (node.isInline()) { if (node.isInline()) {
print("{"); print('{');
} }
printTagName(node); printTagName(node);
print(" "); print(' ');
print(node.getDescription()); print(node.getDescription());
if (node.isInline()) { if (node.isInline()) {
print("}"); print('}');
} }
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
@ -414,7 +421,7 @@ public class DocPretty implements DocTreeVisitor<Void,Void> {
boolean first = true; boolean first = true;
boolean needSep = true; boolean needSep = true;
for (DocTree t: node.getReference()) { for (DocTree t: node.getReference()) {
if (needSep) print(" "); if (needSep) print(' ');
needSep = (first && (t instanceof ReferenceTree)); needSep = (first && (t instanceof ReferenceTree));
first = false; first = false;
print(t); print(t);
@ -430,7 +437,7 @@ public class DocPretty implements DocTreeVisitor<Void,Void> {
try { try {
printTagName(node); printTagName(node);
if (!node.getDescription().isEmpty()) { if (!node.getDescription().isEmpty()) {
print(" "); print(' ');
print(node.getDescription()); print(node.getDescription());
} }
} catch (IOException e) { } catch (IOException e) {
@ -444,7 +451,7 @@ public class DocPretty implements DocTreeVisitor<Void,Void> {
try { try {
printTagName(node); printTagName(node);
if (!node.getDescription().isEmpty()) { if (!node.getDescription().isEmpty()) {
print(" "); print(' ');
print(node.getDescription()); print(node.getDescription());
} }
} catch (IOException e) { } catch (IOException e) {
@ -457,12 +464,12 @@ public class DocPretty implements DocTreeVisitor<Void,Void> {
public Void visitSerialField(SerialFieldTree node, Void p) { public Void visitSerialField(SerialFieldTree node, Void p) {
try { try {
printTagName(node); printTagName(node);
print(" "); print(' ');
print(node.getName()); print(node.getName());
print(" "); print(' ');
print(node.getType()); print(node.getType());
if (!node.getDescription().isEmpty()) { if (!node.getDescription().isEmpty()) {
print(" "); print(' ');
print(node.getDescription()); print(node.getDescription());
} }
} catch (IOException e) { } catch (IOException e) {
@ -475,7 +482,7 @@ public class DocPretty implements DocTreeVisitor<Void,Void> {
public Void visitSince(SinceTree node, Void p) { public Void visitSince(SinceTree node, Void p) {
try { try {
printTagName(node); printTagName(node);
print(" "); print(' ');
print(node.getBody()); print(node.getBody());
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
@ -486,18 +493,18 @@ public class DocPretty implements DocTreeVisitor<Void,Void> {
@Override @DefinedBy(Api.COMPILER_TREE) @Override @DefinedBy(Api.COMPILER_TREE)
public Void visitSnippet(SnippetTree node, Void p) { public Void visitSnippet(SnippetTree node, Void p) {
try { try {
print("{"); print('{');
printTagName(node); printTagName(node);
List<? extends DocTree> attrs = node.getAttributes(); List<? extends DocTree> attrs = node.getAttributes();
if (!attrs.isEmpty()) { if (!attrs.isEmpty()) {
print(" "); print(' ');
print(attrs, " "); print(attrs, ' ');
} }
if (node.getBody() != null) { if (node.getBody() != null) {
print(" :\n"); print(" :\n");
print(node.getBody()); print(node.getBody());
} }
print("}"); print('}');
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
} }
@ -508,9 +515,9 @@ public class DocPretty implements DocTreeVisitor<Void,Void> {
public Void visitSpec(SpecTree node, Void p) { public Void visitSpec(SpecTree node, Void p) {
try { try {
printTagName(node); printTagName(node);
print(" "); print(' ');
print(node.getURL()); print(node.getURL());
print(" "); print(' ');
print(node.getTitle()); print(node.getTitle());
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
@ -521,20 +528,20 @@ public class DocPretty implements DocTreeVisitor<Void,Void> {
@Override @DefinedBy(Api.COMPILER_TREE) @Override @DefinedBy(Api.COMPILER_TREE)
public Void visitStartElement(StartElementTree node, Void p) { public Void visitStartElement(StartElementTree node, Void p) {
try { try {
print("<"); print('<');
print(node.getName()); print(node.getName());
List<? extends DocTree> attrs = node.getAttributes(); List<? extends DocTree> attrs = node.getAttributes();
if (!attrs.isEmpty()) { if (!attrs.isEmpty()) {
print(" "); print(' ');
print(attrs, " "); print(attrs, ' ');
DocTree last = node.getAttributes().get(attrs.size() - 1); DocTree last = node.getAttributes().get(attrs.size() - 1);
if (node.isSelfClosing() && last instanceof AttributeTree attributeTree if (node.isSelfClosing() && last instanceof AttributeTree attributeTree
&& attributeTree.getValueKind() == ValueKind.UNQUOTED) && attributeTree.getValueKind() == ValueKind.UNQUOTED)
print(" "); print(' ');
} }
if (node.isSelfClosing()) if (node.isSelfClosing())
print("/"); print('/');
print(">"); print('>');
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
} }
@ -544,13 +551,13 @@ public class DocPretty implements DocTreeVisitor<Void,Void> {
@Override @DefinedBy(Api.COMPILER_TREE) @Override @DefinedBy(Api.COMPILER_TREE)
public Void visitSummary(SummaryTree node, Void p) { public Void visitSummary(SummaryTree node, Void p) {
try { try {
print("{"); print('{');
printTagName(node); printTagName(node);
if (!node.getSummary().isEmpty()) { if (!node.getSummary().isEmpty()) {
print(" "); print(' ');
print(node.getSummary()); print(node.getSummary());
} }
print("}"); print('}');
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
} }
@ -560,11 +567,11 @@ public class DocPretty implements DocTreeVisitor<Void,Void> {
@Override @DefinedBy(Api.COMPILER_TREE) @Override @DefinedBy(Api.COMPILER_TREE)
public Void visitSystemProperty(SystemPropertyTree node, Void p) { public Void visitSystemProperty(SystemPropertyTree node, Void p) {
try { try {
print("{"); print('{');
printTagName(node); printTagName(node);
print(" "); print(' ');
print(node.getPropertyName()); print(node.getPropertyName());
print("}"); print('}');
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
} }
@ -585,10 +592,10 @@ public class DocPretty implements DocTreeVisitor<Void,Void> {
public Void visitThrows(ThrowsTree node, Void p) { public Void visitThrows(ThrowsTree node, Void p) {
try { try {
printTagName(node); printTagName(node);
print(" "); print(' ');
print(node.getExceptionName()); print(node.getExceptionName());
if (!node.getDescription().isEmpty()) { if (!node.getDescription().isEmpty()) {
print(" "); print(' ');
print(node.getDescription()); print(node.getDescription());
} }
} catch (IOException e) { } catch (IOException e) {
@ -600,9 +607,9 @@ public class DocPretty implements DocTreeVisitor<Void,Void> {
@Override @DefinedBy(Api.COMPILER_TREE) @Override @DefinedBy(Api.COMPILER_TREE)
public Void visitUnknownBlockTag(UnknownBlockTagTree node, Void p) { public Void visitUnknownBlockTag(UnknownBlockTagTree node, Void p) {
try { try {
print("@"); print('@');
print(node.getTagName()); print(node.getTagName());
print(" "); print(' ');
print(node.getContent()); print(node.getContent());
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
@ -613,12 +620,12 @@ public class DocPretty implements DocTreeVisitor<Void,Void> {
@Override @DefinedBy(Api.COMPILER_TREE) @Override @DefinedBy(Api.COMPILER_TREE)
public Void visitUnknownInlineTag(UnknownInlineTagTree node, Void p) { public Void visitUnknownInlineTag(UnknownInlineTagTree node, Void p) {
try { try {
print("{"); print('{');
print("@"); print('@');
print(node.getTagName()); print(node.getTagName());
print(" "); print(' ');
print(node.getContent()); print(node.getContent());
print("}"); print('}');
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
} }
@ -629,10 +636,10 @@ public class DocPretty implements DocTreeVisitor<Void,Void> {
public Void visitUses(UsesTree node, Void p) { public Void visitUses(UsesTree node, Void p) {
try { try {
printTagName(node); printTagName(node);
print(" "); print(' ');
print(node.getServiceType()); print(node.getServiceType());
if (!node.getDescription().isEmpty()) { if (!node.getDescription().isEmpty()) {
print(" "); print(' ');
print(node.getDescription()); print(node.getDescription());
} }
} catch (IOException e) { } catch (IOException e) {
@ -644,17 +651,17 @@ public class DocPretty implements DocTreeVisitor<Void,Void> {
@Override @DefinedBy(Api.COMPILER_TREE) @Override @DefinedBy(Api.COMPILER_TREE)
public Void visitValue(ValueTree node, Void p) { public Void visitValue(ValueTree node, Void p) {
try { try {
print("{"); print('{');
printTagName(node); printTagName(node);
if (node.getFormat() != null) { if (node.getFormat() != null) {
print(" "); print(' ');
print(node.getFormat()); print(node.getFormat());
} }
if (node.getReference() != null) { if (node.getReference() != null) {
print(" "); print(' ');
print(node.getReference()); print(node.getReference());
} }
print("}"); print('}');
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
} }
@ -665,7 +672,7 @@ public class DocPretty implements DocTreeVisitor<Void,Void> {
public Void visitVersion(VersionTree node, Void p) { public Void visitVersion(VersionTree node, Void p) {
try { try {
printTagName(node); printTagName(node);
print(" "); print(' ');
print(node.getBody()); print(node.getBody());
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
@ -676,7 +683,9 @@ public class DocPretty implements DocTreeVisitor<Void,Void> {
@Override @DefinedBy(Api.COMPILER_TREE) @Override @DefinedBy(Api.COMPILER_TREE)
public Void visitOther(DocTree node, Void p) { public Void visitOther(DocTree node, Void p) {
try { try {
print("(UNKNOWN: " + node + ")"); print("(UNKNOWN: ");
print(node);
print(')');
println(); println();
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);

View File

@ -132,6 +132,12 @@ public class Pretty extends JCTree.Visitor {
out.write(Convert.escapeUnicode(s.toString())); out.write(Convert.escapeUnicode(s.toString()));
} }
/** Print character. Should be only used internally for known ASCII characters.
*/
private void print(char c) throws IOException {
out.write(c);
}
/** Print new line. /** Print new line.
*/ */
public void println() throws IOException { public void println() throws IOException {
@ -247,8 +253,8 @@ public class Pretty extends JCTree.Visitor {
public void printFlags(long flags) throws IOException { public void printFlags(long flags) throws IOException {
if ((flags & SYNTHETIC) != 0) print("/*synthetic*/ "); if ((flags & SYNTHETIC) != 0) print("/*synthetic*/ ");
print(TreeInfo.flagNames(flags)); print(TreeInfo.flagNames(flags));
if ((flags & ExtendedStandardFlags) != 0) print(" "); if ((flags & ExtendedStandardFlags) != 0) print(' ');
if ((flags & ANNOTATION) != 0) print("@"); if ((flags & ANNOTATION) != 0) print('@');
} }
public void printAnnotations(List<JCAnnotation> trees) throws IOException { public void printAnnotations(List<JCAnnotation> trees) throws IOException {
@ -262,7 +268,7 @@ public class Pretty extends JCTree.Visitor {
public void printTypeAnnotations(List<JCAnnotation> trees) throws IOException { public void printTypeAnnotations(List<JCAnnotation> trees) throws IOException {
for (List<JCAnnotation> l = trees; l.nonEmpty(); l = l.tail) { for (List<JCAnnotation> l = trees; l.nonEmpty(); l = l.tail) {
printExpr(l.head); printExpr(l.head);
print(" "); print(' ');
} }
} }
@ -279,7 +285,7 @@ public class Pretty extends JCTree.Visitor {
while (pos < dc.length()) { while (pos < dc.length()) {
align(); align();
print(" *"); print(" *");
if (pos < dc.length() && dc.charAt(pos) > ' ') print(" "); if (pos < dc.length() && dc.charAt(pos) > ' ') print(' ');
print(dc.substring(pos, endpos)); println(); print(dc.substring(pos, endpos)); println();
pos = endpos + 1; pos = endpos + 1;
endpos = lineEndPos(dc, pos); endpos = lineEndPos(dc, pos);
@ -301,35 +307,35 @@ public class Pretty extends JCTree.Visitor {
*/ */
public void printTypeParameters(List<JCTypeParameter> trees) throws IOException { public void printTypeParameters(List<JCTypeParameter> trees) throws IOException {
if (trees.nonEmpty()) { if (trees.nonEmpty()) {
print("<"); print('<');
printExprs(trees); printExprs(trees);
print(">"); print('>');
} }
} }
/** Print a block. /** Print a block.
*/ */
public void printBlock(List<? extends JCTree> stats) throws IOException { public void printBlock(List<? extends JCTree> stats) throws IOException {
print("{"); print('{');
println(); println();
indent(); indent();
printStats(stats); printStats(stats);
undent(); undent();
align(); align();
print("}"); print('}');
} }
/** Print a block. /** Print a block.
*/ */
public void printEnumBody(List<JCTree> stats) throws IOException { public void printEnumBody(List<JCTree> stats) throws IOException {
print("{"); print('{');
println(); println();
indent(); indent();
boolean first = true; boolean first = true;
for (List<JCTree> l = stats; l.nonEmpty(); l = l.tail) { for (List<JCTree> l = stats; l.nonEmpty(); l = l.tail) {
if (isEnumerator(l.head)) { if (isEnumerator(l.head)) {
if (!first) { if (!first) {
print(","); print(',');
println(); println();
} }
align(); align();
@ -337,7 +343,7 @@ public class Pretty extends JCTree.Visitor {
first = false; first = false;
} }
} }
print(";"); print(';');
println(); println();
for (List<JCTree> l = stats; l.nonEmpty(); l = l.tail) { for (List<JCTree> l = stats; l.nonEmpty(); l = l.tail) {
if (!isEnumerator(l.head)) { if (!isEnumerator(l.head)) {
@ -348,7 +354,7 @@ public class Pretty extends JCTree.Visitor {
} }
undent(); undent();
align(); align();
print("}"); print('}');
} }
/** Is the given tree an enumerator definition? */ /** Is the given tree an enumerator definition? */
@ -429,7 +435,7 @@ public class Pretty extends JCTree.Visitor {
if (tree.pid != null) { if (tree.pid != null) {
print("package "); print("package ");
printExpr(tree.pid); printExpr(tree.pid);
print(";"); print(';');
println(); println();
} }
} catch (IOException e) { } catch (IOException e) {
@ -448,9 +454,9 @@ public class Pretty extends JCTree.Visitor {
print("module "); print("module ");
printExpr(tree.qualId); printExpr(tree.qualId);
if (tree.directives == null) { if (tree.directives == null) {
print(";"); print(';');
} else { } else {
print(" "); print(' ');
printBlock(tree.directives); printBlock(tree.directives);
} }
println(); println();
@ -468,7 +474,7 @@ public class Pretty extends JCTree.Visitor {
print(" to "); print(" to ");
printExprs(tree.moduleNames); printExprs(tree.moduleNames);
} }
print(";"); print(';');
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
} }
@ -483,7 +489,7 @@ public class Pretty extends JCTree.Visitor {
print(" to "); print(" to ");
printExprs(tree.moduleNames); printExprs(tree.moduleNames);
} }
print(";"); print(';');
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
} }
@ -496,7 +502,7 @@ public class Pretty extends JCTree.Visitor {
printExpr(tree.serviceName); printExpr(tree.serviceName);
print(" with "); print(" with ");
printExprs(tree.implNames); printExprs(tree.implNames);
print(";"); print(';');
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
} }
@ -511,7 +517,7 @@ public class Pretty extends JCTree.Visitor {
if (tree.isTransitive) if (tree.isTransitive)
print("transitive "); print("transitive ");
printExpr(tree.moduleName); printExpr(tree.moduleName);
print(";"); print(';');
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
} }
@ -522,7 +528,7 @@ public class Pretty extends JCTree.Visitor {
try { try {
print("uses "); print("uses ");
printExpr(tree.qualid); printExpr(tree.qualid);
print(";"); print(';');
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
} }
@ -533,7 +539,7 @@ public class Pretty extends JCTree.Visitor {
print("import "); print("import ");
if (tree.staticImport) print("static "); if (tree.staticImport) print("static ");
printExpr(tree.qualid); printExpr(tree.qualid);
print(";"); print(';');
println(); println();
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
@ -549,7 +555,8 @@ public class Pretty extends JCTree.Visitor {
Name enclClassNamePrev = enclClassName; Name enclClassNamePrev = enclClassName;
enclClassName = tree.name; enclClassName = tree.name;
if ((tree.mods.flags & INTERFACE) != 0) { if ((tree.mods.flags & INTERFACE) != 0) {
print("interface " + tree.name); print("interface ");
print(tree.name);
printTypeParameters(tree.typarams); printTypeParameters(tree.typarams);
if (tree.implementing.nonEmpty()) { if (tree.implementing.nonEmpty()) {
print(" extends "); print(" extends ");
@ -561,9 +568,10 @@ public class Pretty extends JCTree.Visitor {
} }
} else { } else {
if ((tree.mods.flags & ENUM) != 0) if ((tree.mods.flags & ENUM) != 0)
print("enum " + tree.name); print("enum ");
else else
print("class " + tree.name); print("class ");
print(tree.name);
printTypeParameters(tree.typarams); printTypeParameters(tree.typarams);
if (tree.extending != null) { if (tree.extending != null) {
print(" extends "); print(" extends ");
@ -578,7 +586,7 @@ public class Pretty extends JCTree.Visitor {
printExprs(tree.permitting); printExprs(tree.permitting);
} }
} }
print(" "); print(' ');
if ((tree.mods.flags & ENUM) != 0) { if ((tree.mods.flags & ENUM) != 0) {
printEnumBody(tree.defs); printEnumBody(tree.defs);
} else { } else {
@ -604,9 +612,10 @@ public class Pretty extends JCTree.Visitor {
print(enclClassName != null ? enclClassName : tree.name); print(enclClassName != null ? enclClassName : tree.name);
} else { } else {
printExpr(tree.restype); printExpr(tree.restype);
print(" " + tree.name); print(' ');
print(tree.name);
} }
print("("); print('(');
if (tree.recvparam!=null) { if (tree.recvparam!=null) {
printExpr(tree.recvparam); printExpr(tree.recvparam);
if (tree.params.size() > 0) { if (tree.params.size() > 0) {
@ -614,7 +623,7 @@ public class Pretty extends JCTree.Visitor {
} }
} }
printExprs(tree.params); printExprs(tree.params);
print(")"); print(')');
if (tree.thrown.nonEmpty()) { if (tree.thrown.nonEmpty()) {
print(" throws "); print(" throws ");
printExprs(tree.thrown); printExprs(tree.thrown);
@ -624,10 +633,10 @@ public class Pretty extends JCTree.Visitor {
printExpr(tree.defaultValue); printExpr(tree.defaultValue);
} }
if (tree.body != null) { if (tree.body != null) {
print(" "); print(' ');
printStat(tree.body); printStat(tree.body);
} else { } else {
print(";"); print(';');
} }
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
@ -649,12 +658,12 @@ public class Pretty extends JCTree.Visitor {
if (sourceOutput) { if (sourceOutput) {
print(" /*enum*/ "); print(" /*enum*/ ");
if (init.args != null && init.args.nonEmpty()) { if (init.args != null && init.args.nonEmpty()) {
print("("); print('(');
print(init.args); print(init.args);
print(")"); print(')');
} }
if (init.def != null && init.def.defs != null) { if (init.def != null && init.def.defs != null) {
print(" "); print(' ');
printBlock(init.def.defs); printBlock(init.def.defs);
} }
return; return;
@ -665,18 +674,18 @@ public class Pretty extends JCTree.Visitor {
printTypeAnnotations(init.def.mods.annotations); printTypeAnnotations(init.def.mods.annotations);
} }
printExpr(init.clazz); printExpr(init.clazz);
print("("); print('(');
printExprs(init.args); printExprs(init.args);
print(")"); print(')');
print(" */"); print(" */");
print(" /*enum*/ "); print(" /*enum*/ ");
if (init.args != null && init.args.nonEmpty()) { if (init.args != null && init.args.nonEmpty()) {
print("("); print('(');
printExprs(init.args); printExprs(init.args);
print(")"); print(')');
} }
if (init.def != null && init.def.defs != null) { if (init.def != null && init.def.defs != null) {
print(" "); print(' ');
printBlock(init.def.defs); printBlock(init.def.defs);
} }
return; return;
@ -700,16 +709,18 @@ public class Pretty extends JCTree.Visitor {
print(' '); print(' ');
printTypeAnnotations(tas); printTypeAnnotations(tas);
} }
print("... " + tree.name); print("... ");
print(tree.name);
} else { } else {
printExpr(tree.vartype); printExpr(tree.vartype);
print(" " + tree.name); print(' ');
print(tree.name);
} }
if (tree.init != null) { if (tree.init != null) {
print(" = "); print(" = ");
printExpr(tree.init); printExpr(tree.init);
} }
if (prec == TreeInfo.notExpression) print(";"); if (prec == TreeInfo.notExpression) print(';');
} }
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
@ -718,7 +729,7 @@ public class Pretty extends JCTree.Visitor {
public void visitSkip(JCSkip tree) { public void visitSkip(JCSkip tree) {
try { try {
print(";"); print(';');
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
} }
@ -742,11 +753,11 @@ public class Pretty extends JCTree.Visitor {
if (tree.cond.hasTag(PARENS)) { if (tree.cond.hasTag(PARENS)) {
printExpr(tree.cond); printExpr(tree.cond);
} else { } else {
print("("); print('(');
printExpr(tree.cond); printExpr(tree.cond);
print(")"); print(')');
} }
print(";"); print(';');
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
} }
@ -758,11 +769,11 @@ public class Pretty extends JCTree.Visitor {
if (tree.cond.hasTag(PARENS)) { if (tree.cond.hasTag(PARENS)) {
printExpr(tree.cond); printExpr(tree.cond);
} else { } else {
print("("); print('(');
printExpr(tree.cond); printExpr(tree.cond);
print(")"); print(')');
} }
print(" "); print(' ');
printStat(tree.body); printStat(tree.body);
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
@ -777,7 +788,8 @@ public class Pretty extends JCTree.Visitor {
printExpr(tree.init.head); printExpr(tree.init.head);
for (List<JCStatement> l = tree.init.tail; l.nonEmpty(); l = l.tail) { for (List<JCStatement> l = tree.init.tail; l.nonEmpty(); l = l.tail) {
JCVariableDecl vdef = (JCVariableDecl)l.head; JCVariableDecl vdef = (JCVariableDecl)l.head;
print(", " + vdef.name); print(", ");
print(vdef.name);
if (vdef.init != null) { if (vdef.init != null) {
print(" = "); print(" = ");
printExpr(vdef.init); printExpr(vdef.init);
@ -813,7 +825,8 @@ public class Pretty extends JCTree.Visitor {
public void visitLabelled(JCLabeledStatement tree) { public void visitLabelled(JCLabeledStatement tree) {
try { try {
print(tree.label + ": "); print(tree.label);
print(": ");
printStat(tree.body); printStat(tree.body);
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
@ -826,15 +839,15 @@ public class Pretty extends JCTree.Visitor {
if (tree.selector.hasTag(PARENS)) { if (tree.selector.hasTag(PARENS)) {
printExpr(tree.selector); printExpr(tree.selector);
} else { } else {
print("("); print('(');
printExpr(tree.selector); printExpr(tree.selector);
print(")"); print(')');
} }
print(" {"); print(" {");
println(); println();
printStats(tree.cases); printStats(tree.cases);
align(); align();
print("}"); print('}');
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
} }
@ -849,7 +862,7 @@ public class Pretty extends JCTree.Visitor {
printExprs(tree.labels); printExprs(tree.labels);
} }
if (tree.caseKind == JCCase.STATEMENT) { if (tree.caseKind == JCCase.STATEMENT) {
print(":"); print(':');
println(); println();
indent(); indent();
printStats(tree.stats); printStats(tree.stats);
@ -905,15 +918,15 @@ public class Pretty extends JCTree.Visitor {
if (tree.selector.hasTag(PARENS)) { if (tree.selector.hasTag(PARENS)) {
printExpr(tree.selector); printExpr(tree.selector);
} else { } else {
print("("); print('(');
printExpr(tree.selector); printExpr(tree.selector);
print(")"); print(')');
} }
print(" {"); print(" {");
println(); println();
printStats(tree.cases); printStats(tree.cases);
align(); align();
print("}"); print('}');
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
} }
@ -930,9 +943,9 @@ public class Pretty extends JCTree.Visitor {
@Override @Override
public void visitParenthesizedPattern(JCParenthesizedPattern patt) { public void visitParenthesizedPattern(JCParenthesizedPattern patt) {
try { try {
print("("); print('(');
printExpr(patt.pattern); printExpr(patt.pattern);
print(")"); print(')');
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
} }
@ -942,9 +955,9 @@ public class Pretty extends JCTree.Visitor {
public void visitRecordPattern(JCRecordPattern tree) { public void visitRecordPattern(JCRecordPattern tree) {
try { try {
printExpr(tree.deconstructor); printExpr(tree.deconstructor);
print("("); print('(');
printExprs(tree.nested); printExprs(tree.nested);
print(")"); print(')');
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
} }
@ -956,11 +969,11 @@ public class Pretty extends JCTree.Visitor {
if (tree.lock.hasTag(PARENS)) { if (tree.lock.hasTag(PARENS)) {
printExpr(tree.lock); printExpr(tree.lock);
} else { } else {
print("("); print('(');
printExpr(tree.lock); printExpr(tree.lock);
print(")"); print(')');
} }
print(" "); print(' ');
printStat(tree.body); printStat(tree.body);
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
@ -971,7 +984,7 @@ public class Pretty extends JCTree.Visitor {
try { try {
print("try "); print("try ");
if (tree.resources.nonEmpty()) { if (tree.resources.nonEmpty()) {
print("("); print('(');
boolean first = true; boolean first = true;
for (JCTree var : tree.resources) { for (JCTree var : tree.resources) {
if (!first) { if (!first) {
@ -1027,11 +1040,11 @@ public class Pretty extends JCTree.Visitor {
if (tree.cond.hasTag(PARENS)) { if (tree.cond.hasTag(PARENS)) {
printExpr(tree.cond); printExpr(tree.cond);
} else { } else {
print("("); print('(');
printExpr(tree.cond); printExpr(tree.cond);
print(")"); print(')');
} }
print(" "); print(' ');
printStat(tree.thenpart); printStat(tree.thenpart);
if (tree.elsepart != null) { if (tree.elsepart != null) {
print(" else "); print(" else ");
@ -1045,7 +1058,7 @@ public class Pretty extends JCTree.Visitor {
public void visitExec(JCExpressionStatement tree) { public void visitExec(JCExpressionStatement tree) {
try { try {
printExpr(tree.expr); printExpr(tree.expr);
if (prec == TreeInfo.notExpression) print(";"); if (prec == TreeInfo.notExpression) print(';');
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
} }
@ -1054,8 +1067,11 @@ public class Pretty extends JCTree.Visitor {
public void visitBreak(JCBreak tree) { public void visitBreak(JCBreak tree) {
try { try {
print("break"); print("break");
if (tree.label != null) print(" " + tree.label); if (tree.label != null) {
print(";"); print(' ');
print(tree.label);
}
print(';');
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
} }
@ -1064,9 +1080,9 @@ public class Pretty extends JCTree.Visitor {
public void visitYield(JCYield tree) { public void visitYield(JCYield tree) {
try { try {
print("yield"); print("yield");
print(" "); print(' ');
printExpr(tree.value); printExpr(tree.value);
print(";"); print(';');
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
} }
@ -1075,8 +1091,11 @@ public class Pretty extends JCTree.Visitor {
public void visitContinue(JCContinue tree) { public void visitContinue(JCContinue tree) {
try { try {
print("continue"); print("continue");
if (tree.label != null) print(" " + tree.label); if (tree.label != null) {
print(";"); print(' ');
print(tree.label);
}
print(';');
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
} }
@ -1086,10 +1105,10 @@ public class Pretty extends JCTree.Visitor {
try { try {
print("return"); print("return");
if (tree.expr != null) { if (tree.expr != null) {
print(" "); print(' ');
printExpr(tree.expr); printExpr(tree.expr);
} }
print(";"); print(';');
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
} }
@ -1099,7 +1118,7 @@ public class Pretty extends JCTree.Visitor {
try { try {
print("throw "); print("throw ");
printExpr(tree.expr); printExpr(tree.expr);
print(";"); print(';');
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
} }
@ -1113,7 +1132,7 @@ public class Pretty extends JCTree.Visitor {
print(" : "); print(" : ");
printExpr(tree.detail); printExpr(tree.detail);
} }
print(";"); print(';');
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
} }
@ -1127,19 +1146,20 @@ public class Pretty extends JCTree.Visitor {
printExpr(left.selected); printExpr(left.selected);
print(".<"); print(".<");
printExprs(tree.typeargs); printExprs(tree.typeargs);
print(">" + left.name); print('>');
print(left.name);
} else { } else {
print("<"); print('<');
printExprs(tree.typeargs); printExprs(tree.typeargs);
print(">"); print('>');
printExpr(tree.meth); printExpr(tree.meth);
} }
} else { } else {
printExpr(tree.meth); printExpr(tree.meth);
} }
print("("); print('(');
printExprs(tree.args); printExprs(tree.args);
print(")"); print(')');
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
} }
@ -1149,21 +1169,21 @@ public class Pretty extends JCTree.Visitor {
try { try {
if (tree.encl != null) { if (tree.encl != null) {
printExpr(tree.encl); printExpr(tree.encl);
print("."); print('.');
} }
print("new "); print("new ");
if (!tree.typeargs.isEmpty()) { if (!tree.typeargs.isEmpty()) {
print("<"); print('<');
printExprs(tree.typeargs); printExprs(tree.typeargs);
print(">"); print('>');
} }
if (tree.def != null && tree.def.mods.annotations.nonEmpty()) { if (tree.def != null && tree.def.mods.annotations.nonEmpty()) {
printTypeAnnotations(tree.def.mods.annotations); printTypeAnnotations(tree.def.mods.annotations);
} }
printExpr(tree.clazz); printExpr(tree.clazz);
print("("); print('(');
printExprs(tree.args); printExprs(tree.args);
print(")"); print(')');
if (tree.def != null) { if (tree.def != null) {
Name enclClassNamePrev = enclClassName; Name enclClassNamePrev = enclClassName;
enclClassName = enclClassName =
@ -1201,17 +1221,17 @@ public class Pretty extends JCTree.Visitor {
print(' '); print(' ');
printTypeAnnotations(da.get(i)); printTypeAnnotations(da.get(i));
} }
print("["); print('[');
i++; i++;
printExpr(l.head); printExpr(l.head);
print("]"); print(']');
} }
printBrackets(elem); printBrackets(elem);
} }
if (tree.elems != null) { if (tree.elems != null) {
print("{"); print('{');
printExprs(tree.elems); printExprs(tree.elems);
print("}"); print('}');
} }
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
@ -1220,7 +1240,7 @@ public class Pretty extends JCTree.Visitor {
public void visitLambda(JCLambda tree) { public void visitLambda(JCLambda tree) {
try { try {
print("("); print('(');
if (tree.paramKind == JCLambda.ParameterKind.EXPLICIT) { if (tree.paramKind == JCLambda.ParameterKind.EXPLICIT) {
printExprs(tree.params); printExprs(tree.params);
} else { } else {
@ -1240,9 +1260,9 @@ public class Pretty extends JCTree.Visitor {
public void visitParens(JCParens tree) { public void visitParens(JCParens tree) {
try { try {
print("("); print('(');
printExpr(tree.expr); printExpr(tree.expr);
print(")"); print(')');
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
} }
@ -1298,7 +1318,9 @@ public class Pretty extends JCTree.Visitor {
try { try {
open(prec, TreeInfo.assignopPrec); open(prec, TreeInfo.assignopPrec);
printExpr(tree.lhs, TreeInfo.assignopPrec + 1); printExpr(tree.lhs, TreeInfo.assignopPrec + 1);
print(" " + operatorName(tree.getTag().noAssignOp()) + "= "); print(' ');
print(operatorName(tree.getTag().noAssignOp()));
print("= ");
printExpr(tree.rhs, TreeInfo.assignopPrec); printExpr(tree.rhs, TreeInfo.assignopPrec);
close(prec, TreeInfo.assignopPrec); close(prec, TreeInfo.assignopPrec);
} catch (IOException e) { } catch (IOException e) {
@ -1330,7 +1352,9 @@ public class Pretty extends JCTree.Visitor {
String opname = operatorName(tree.getTag()); String opname = operatorName(tree.getTag());
open(prec, ownprec); open(prec, ownprec);
printExpr(tree.lhs, ownprec); printExpr(tree.lhs, ownprec);
print(" " + opname + " "); print(' ');
print(opname);
print(' ');
printExpr(tree.rhs, ownprec + 1); printExpr(tree.rhs, ownprec + 1);
close(prec, ownprec); close(prec, ownprec);
} catch (IOException e) { } catch (IOException e) {
@ -1341,9 +1365,9 @@ public class Pretty extends JCTree.Visitor {
public void visitTypeCast(JCTypeCast tree) { public void visitTypeCast(JCTypeCast tree) {
try { try {
open(prec, TreeInfo.prefixPrec); open(prec, TreeInfo.prefixPrec);
print("("); print('(');
printExpr(tree.clazz); printExpr(tree.clazz);
print(")"); print(')');
printExpr(tree.expr, TreeInfo.prefixPrec); printExpr(tree.expr, TreeInfo.prefixPrec);
close(prec, TreeInfo.prefixPrec); close(prec, TreeInfo.prefixPrec);
} catch (IOException e) { } catch (IOException e) {
@ -1370,9 +1394,9 @@ public class Pretty extends JCTree.Visitor {
public void visitIndexed(JCArrayAccess tree) { public void visitIndexed(JCArrayAccess tree) {
try { try {
printExpr(tree.indexed, TreeInfo.postfixPrec); printExpr(tree.indexed, TreeInfo.postfixPrec);
print("["); print('[');
printExpr(tree.index); printExpr(tree.index);
print("]"); print(']');
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
} }
@ -1381,7 +1405,8 @@ public class Pretty extends JCTree.Visitor {
public void visitSelect(JCFieldAccess tree) { public void visitSelect(JCFieldAccess tree) {
try { try {
printExpr(tree.selected, TreeInfo.postfixPrec); printExpr(tree.selected, TreeInfo.postfixPrec);
print("." + tree.name); print('.');
print(tree.name);
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
} }
@ -1392,9 +1417,9 @@ public class Pretty extends JCTree.Visitor {
printExpr(tree.expr); printExpr(tree.expr);
print("::"); print("::");
if (tree.typeargs != null) { if (tree.typeargs != null) {
print("<"); print('<');
printExprs(tree.typeargs); printExprs(tree.typeargs);
print(">"); print('>');
} }
print(tree.getMode() == ReferenceMode.INVOKE ? tree.name : "new"); print(tree.getMode() == ReferenceMode.INVOKE ? tree.name : "new");
} catch (IOException e) { } catch (IOException e) {
@ -1417,19 +1442,20 @@ public class Pretty extends JCTree.Visitor {
print(tree.value.toString()); print(tree.value.toString());
break; break;
case LONG: case LONG:
print(tree.value + "L"); print(tree.value);
print('L');
break; break;
case FLOAT: case FLOAT:
print(tree.value + "F"); print(tree.value);
print('F');
break; break;
case DOUBLE: case DOUBLE:
print(tree.value.toString()); print(tree.value.toString());
break; break;
case CHAR: case CHAR:
print("\'" + print('\'');
Convert.quote( print(Convert.quote(String.valueOf((char)((Number)tree.value).intValue())));
String.valueOf((char)((Number)tree.value).intValue())) + print('\'');
"\'");
break; break;
case BOOLEAN: case BOOLEAN:
print(((Number)tree.value).intValue() == 1 ? "true" : "false"); print(((Number)tree.value).intValue() == 1 ? "true" : "false");
@ -1438,7 +1464,9 @@ public class Pretty extends JCTree.Visitor {
print("null"); print("null");
break; break;
default: default:
print("\"" + Convert.quote(tree.value.toString()) + "\""); print('"');
print(Convert.quote(tree.value.toString()));
print('"');
break; break;
} }
} catch (IOException e) { } catch (IOException e) {
@ -1524,9 +1552,9 @@ public class Pretty extends JCTree.Visitor {
public void visitTypeApply(JCTypeApply tree) { public void visitTypeApply(JCTypeApply tree) {
try { try {
printExpr(tree.clazz); printExpr(tree.clazz);
print("<"); print('<');
printExprs(tree.arguments); printExprs(tree.arguments);
print(">"); print('>');
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
} }
@ -1593,7 +1621,11 @@ public class Pretty extends JCTree.Visitor {
public void visitLetExpr(LetExpr tree) { public void visitLetExpr(LetExpr tree) {
try { try {
print("(let " + tree.defs + " in " + tree.expr + ")"); print("(let ");
print(tree.defs);
print(" in ");
print(tree.expr);
print(')');
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
} }
@ -1610,12 +1642,12 @@ public class Pretty extends JCTree.Visitor {
public void visitAnnotation(JCAnnotation tree) { public void visitAnnotation(JCAnnotation tree) {
try { try {
print("@"); print('@');
printExpr(tree.annotationType); printExpr(tree.annotationType);
if (!tree.args.isEmpty()) { if (!tree.args.isEmpty()) {
print("("); print('(');
printExprs(tree.args); printExprs(tree.args);
print(")"); print(')');
} }
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
@ -1627,7 +1659,7 @@ public class Pretty extends JCTree.Visitor {
if (tree.underlyingType.hasTag(SELECT)) { if (tree.underlyingType.hasTag(SELECT)) {
JCFieldAccess access = (JCFieldAccess) tree.underlyingType; JCFieldAccess access = (JCFieldAccess) tree.underlyingType;
printExpr(access.selected, TreeInfo.postfixPrec); printExpr(access.selected, TreeInfo.postfixPrec);
print("."); print('.');
printTypeAnnotations(tree.annotations); printTypeAnnotations(tree.annotations);
print(access.name); print(access.name);
} else if (tree.underlyingType.hasTag(TYPEARRAY)) { } else if (tree.underlyingType.hasTag(TYPEARRAY)) {
@ -1644,7 +1676,9 @@ public class Pretty extends JCTree.Visitor {
public void visitTree(JCTree tree) { public void visitTree(JCTree tree) {
try { try {
print("(UNKNOWN: " + tree.getTag() + ")"); print("(UNKNOWN: ");
print(tree.getTag());
print(')');
println(); println();
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);