1 /*
   2  * Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.tools.javac.tree;
  27 
  28 import java.io.*;
  29 
  30 import com.sun.source.tree.MemberReferenceTree.ReferenceMode;
  31 import com.sun.source.tree.ModuleTree.ModuleKind;
  32 import com.sun.tools.javac.code.*;
  33 import com.sun.tools.javac.tree.JCTree.*;
  34 import com.sun.tools.javac.util.*;
  35 
  36 import static com.sun.tools.javac.code.Flags.*;
  37 import static com.sun.tools.javac.code.Flags.ANNOTATION;
  38 import static com.sun.tools.javac.tree.JCTree.Tag.*;
  39 
  40 /** Prints out a tree as an indented Java source program.
  41  *
  42  *  <p><b>This is NOT part of any supported API.
  43  *  If you write code that depends on this, you do so at your own risk.
  44  *  This code and its internal interfaces are subject to change or
  45  *  deletion without notice.</b>
  46  */
  47 public class Pretty extends JCTree.Visitor {
  48 
  49     public Pretty(Writer out, boolean sourceOutput) {
  50         this.out = out;
  51         this.sourceOutput = sourceOutput;
  52     }
  53 
  54     /** Set when we are producing source output.  If we're not
  55      *  producing source output, we can sometimes give more detail in
  56      *  the output even though that detail would not be valid java
  57      *  source.
  58      */
  59     private final boolean sourceOutput;
  60 
  61     /** The output stream on which trees are printed.
  62      */
  63     Writer out;
  64 
  65     /** Indentation width (can be reassigned from outside).
  66      */
  67     public int width = 4;
  68 
  69     /** The current left margin.
  70      */
  71     int lmargin = 0;
  72 
  73     /** The enclosing class name.
  74      */
  75     Name enclClassName;
  76 
  77     /** A table mapping trees to their documentation comments
  78      *  (can be null)
  79      */
  80     DocCommentTable docComments = null;
  81 
  82     /**
  83      * A string sequence to be used when Pretty output should be constrained
  84      * to fit into a given size
  85      */
  86     private static final String trimSequence = "[...]";
  87 
  88     /**
  89      * Max number of chars to be generated when output should fit into a single line
  90      */
  91     private static final int PREFERRED_LENGTH = 20;
  92 
  93     /** Align code to be indented to left margin.
  94      */
  95     void align() throws IOException {
  96         for (int i = 0; i < lmargin; i++) out.write(" ");
  97     }
  98 
  99     /** Increase left margin by indentation width.
 100      */
 101     void indent() {
 102         lmargin = lmargin + width;
 103     }
 104 
 105     /** Decrease left margin by indentation width.
 106      */
 107     void undent() {
 108         lmargin = lmargin - width;
 109     }
 110 
 111     /** Enter a new precedence level. Emit a `(' if new precedence level
 112      *  is less than precedence level so far.
 113      *  @param contextPrec    The precedence level in force so far.
 114      *  @param ownPrec        The new precedence level.
 115      */
 116     void open(int contextPrec, int ownPrec) throws IOException {
 117         if (ownPrec < contextPrec) out.write("(");
 118     }
 119 
 120     /** Leave precedence level. Emit a `(' if inner precedence level
 121      *  is less than precedence level we revert to.
 122      *  @param contextPrec    The precedence level we revert to.
 123      *  @param ownPrec        The inner precedence level.
 124      */
 125     void close(int contextPrec, int ownPrec) throws IOException {
 126         if (ownPrec < contextPrec) out.write(")");
 127     }
 128 
 129     /** Print string, replacing all non-ascii character with unicode escapes.
 130      */
 131     public void print(Object s) throws IOException {
 132         out.write(Convert.escapeUnicode(s.toString()));
 133     }
 134 
 135     /** Print new line.
 136      */
 137     public void println() throws IOException {
 138         out.write(lineSep);
 139     }
 140 
 141     public static String toSimpleString(JCTree tree) {
 142         return toSimpleString(tree, PREFERRED_LENGTH);
 143     }
 144 
 145     public static String toSimpleString(JCTree tree, int maxLength) {
 146         StringWriter s = new StringWriter();
 147         try {
 148             new Pretty(s, false).printExpr(tree);
 149         }
 150         catch (IOException e) {
 151             // should never happen, because StringWriter is defined
 152             // never to throw any IOExceptions
 153             throw new AssertionError(e);
 154         }
 155         //we need to (i) replace all line terminators with a space and (ii) remove
 156         //occurrences of 'missing' in the Pretty output (generated when types are missing)
 157         String res = s.toString().trim().replaceAll("\\s+", " ").replaceAll("/\\*missing\\*/", "");
 158         if (res.length() < maxLength) {
 159             return res;
 160         } else {
 161             int head = (maxLength - trimSequence.length()) * 2 / 3;
 162             int tail = maxLength - trimSequence.length() - head;
 163             return res.substring(0, head) + trimSequence + res.substring(res.length() - tail);
 164         }
 165     }
 166 
 167     String lineSep = System.getProperty("line.separator");
 168 
 169     /* ************************************************************************
 170      * Traversal methods
 171      *************************************************************************/
 172 
 173     /** Exception to propagate IOException through visitXYZ methods */
 174     private static class UncheckedIOException extends Error {
 175         static final long serialVersionUID = -4032692679158424751L;
 176         UncheckedIOException(IOException e) {
 177             super(e.getMessage(), e);
 178         }
 179     }
 180 
 181     /** Visitor argument: the current precedence level.
 182      */
 183     int prec;
 184 
 185     /** Visitor method: print expression tree.
 186      *  @param prec  The current precedence level.
 187      */
 188     public void printExpr(JCTree tree, int prec) throws IOException {
 189         int prevPrec = this.prec;
 190         try {
 191             this.prec = prec;
 192             if (tree == null) print("/*missing*/");
 193             else {
 194                 tree.accept(this);
 195             }
 196         } catch (UncheckedIOException ex) {
 197             IOException e = new IOException(ex.getMessage());
 198             e.initCause(ex);
 199             throw e;
 200         } finally {
 201             this.prec = prevPrec;
 202         }
 203     }
 204 
 205     /** Derived visitor method: print expression tree at minimum precedence level
 206      *  for expression.
 207      */
 208     public void printExpr(JCTree tree) throws IOException {
 209         printExpr(tree, TreeInfo.noPrec);
 210     }
 211 
 212     /** Derived visitor method: print statement tree.
 213      */
 214     public void printStat(JCTree tree) throws IOException {
 215         printExpr(tree, TreeInfo.notExpression);
 216     }
 217 
 218     /** Derived visitor method: print list of expression trees, separated by given string.
 219      *  @param sep the separator string
 220      */
 221     public <T extends JCTree> void printExprs(List<T> trees, String sep) throws IOException {
 222         if (trees.nonEmpty()) {
 223             printExpr(trees.head);
 224             for (List<T> l = trees.tail; l.nonEmpty(); l = l.tail) {
 225                 print(sep);
 226                 printExpr(l.head);
 227             }
 228         }
 229     }
 230 
 231     /** Derived visitor method: print list of expression trees, separated by commas.
 232      */
 233     public <T extends JCTree> void printExprs(List<T> trees) throws IOException {
 234         printExprs(trees, ", ");
 235     }
 236 
 237 
 238     /** Derived visitor method: print pattern.
 239      */
 240 
 241     public void printPattern(JCTree tree) throws IOException {
 242         printExpr(tree);
 243     }
 244 
 245     /** Derived visitor method: print list of statements, each on a separate line.
 246      */
 247     public void printStats(List<? extends JCTree> trees) throws IOException {
 248         for (List<? extends JCTree> l = trees; l.nonEmpty(); l = l.tail) {
 249             align();
 250             printStat(l.head);
 251             println();
 252         }
 253     }
 254 
 255     /** Print a set of modifiers.
 256      */
 257     public void printFlags(long flags) throws IOException {
 258         if ((flags & SYNTHETIC) != 0) print("/*synthetic*/ ");
 259         print(TreeInfo.flagNames(flags));
 260         if ((flags & ExtendedStandardFlags) != 0) print(" ");
 261         if ((flags & ANNOTATION) != 0) print("@");
 262     }
 263 
 264     public void printAnnotations(List<JCAnnotation> trees) throws IOException {
 265         for (List<JCAnnotation> l = trees; l.nonEmpty(); l = l.tail) {
 266             printStat(l.head);
 267             println();
 268             align();
 269         }
 270     }
 271 
 272     public void printTypeAnnotations(List<JCAnnotation> trees) throws IOException {
 273         for (List<JCAnnotation> l = trees; l.nonEmpty(); l = l.tail) {
 274             printExpr(l.head);
 275             print(" ");
 276         }
 277     }
 278 
 279     /** Print documentation comment, if it exists
 280      *  @param tree    The tree for which a documentation comment should be printed.
 281      */
 282     public void printDocComment(JCTree tree) throws IOException {
 283         if (docComments != null) {
 284             String dc = docComments.getCommentText(tree);
 285             if (dc != null) {
 286                 print("/**"); println();
 287                 int pos = 0;
 288                 int endpos = lineEndPos(dc, pos);
 289                 while (pos < dc.length()) {
 290                     align();
 291                     print(" *");
 292                     if (pos < dc.length() && dc.charAt(pos) > ' ') print(" ");
 293                     print(dc.substring(pos, endpos)); println();
 294                     pos = endpos + 1;
 295                     endpos = lineEndPos(dc, pos);
 296                 }
 297                 align(); print(" */"); println();
 298                 align();
 299             }
 300         }
 301     }
 302 //where
 303     static int lineEndPos(String s, int start) {
 304         int pos = s.indexOf('\n', start);
 305         if (pos < 0) pos = s.length();
 306         return pos;
 307     }
 308 
 309     /** If type parameter list is non-empty, print it enclosed in
 310      *  {@literal "<...>"} brackets.
 311      */
 312     public void printTypeParameters(List<JCTypeParameter> trees) throws IOException {
 313         if (trees.nonEmpty()) {
 314             print("<");
 315             printExprs(trees);
 316             print(">");
 317         }
 318     }
 319 
 320     /** Print a block.
 321      */
 322     public void printBlock(List<? extends JCTree> stats) throws IOException {
 323         print("{");
 324         println();
 325         indent();
 326         printStats(stats);
 327         undent();
 328         align();
 329         print("}");
 330     }
 331 
 332     /** Print a block.
 333      */
 334     public void printEnumBody(List<JCTree> stats) throws IOException {
 335         print("{");
 336         println();
 337         indent();
 338         boolean first = true;
 339         for (List<JCTree> l = stats; l.nonEmpty(); l = l.tail) {
 340             if (isEnumerator(l.head)) {
 341                 if (!first) {
 342                     print(",");
 343                     println();
 344                 }
 345                 align();
 346                 printStat(l.head);
 347                 first = false;
 348             }
 349         }
 350         print(";");
 351         println();
 352         for (List<JCTree> l = stats; l.nonEmpty(); l = l.tail) {
 353             if (!isEnumerator(l.head)) {
 354                 align();
 355                 printStat(l.head);
 356                 println();
 357             }
 358         }
 359         undent();
 360         align();
 361         print("}");
 362     }
 363 
 364     /** Is the given tree an enumerator definition? */
 365     boolean isEnumerator(JCTree t) {
 366         return t.hasTag(VARDEF) && (((JCVariableDecl) t).mods.flags & ENUM) != 0;
 367     }
 368 
 369     /** Print unit consisting of package clause and import statements in toplevel,
 370      *  followed by class definition. if class definition == null,
 371      *  print all definitions in toplevel.
 372      *  @param tree     The toplevel tree
 373      *  @param cdef     The class definition, which is assumed to be part of the
 374      *                  toplevel tree.
 375      */
 376     public void printUnit(JCCompilationUnit tree, JCClassDecl cdef) throws IOException {
 377         docComments = tree.docComments;
 378         printDocComment(tree);
 379 
 380         boolean firstImport = true;
 381         for (List<JCTree> l = tree.defs;
 382              l.nonEmpty() &&
 383                  (cdef == null ||
 384                   l.head.hasTag(IMPORT) || l.head.hasTag(PACKAGEDEF));
 385              l = l.tail) {
 386             if (l.head.hasTag(IMPORT)) {
 387                 JCImport imp = (JCImport)l.head;
 388                 Name name = TreeInfo.name(imp.qualid);
 389                 if (name == name.table.names.asterisk ||
 390                         cdef == null ||
 391                         isUsed(TreeInfo.symbol(imp.qualid), cdef)) {
 392                     if (firstImport) {
 393                         firstImport = false;
 394                         println();
 395                     }
 396                     printStat(imp);
 397                 }
 398             } else {
 399                 printStat(l.head);
 400             }
 401         }
 402         if (cdef != null) {
 403             printStat(cdef);
 404             println();
 405         }
 406     }
 407     // where
 408     boolean isUsed(final Symbol t, JCTree cdef) {
 409         class UsedVisitor extends TreeScanner {
 410             public void scan(JCTree tree) {
 411                 if (tree!=null && !result) tree.accept(this);
 412             }
 413             boolean result = false;
 414             public void visitIdent(JCIdent tree) {
 415                 if (tree.sym == t) result = true;
 416             }
 417         }
 418         UsedVisitor v = new UsedVisitor();
 419         v.scan(cdef);
 420         return v.result;
 421     }
 422 
 423     /**************************************************************************
 424      * Visitor methods
 425      *************************************************************************/
 426 
 427     public void visitTopLevel(JCCompilationUnit tree) {
 428         try {
 429             printUnit(tree, null);
 430         } catch (IOException e) {
 431             throw new UncheckedIOException(e);
 432         }
 433     }
 434 
 435     public void visitPackageDef(JCPackageDecl tree) {
 436         try {
 437             printDocComment(tree);
 438             printAnnotations(tree.annotations);
 439             if (tree.pid != null) {
 440                 print("package ");
 441                 printExpr(tree.pid);
 442                 print(";");
 443                 println();
 444             }
 445         } catch (IOException e) {
 446             throw new UncheckedIOException(e);
 447         }
 448     }
 449 
 450     @Override
 451     public void visitModuleDef(JCModuleDecl tree) {
 452         try {
 453             printDocComment(tree);
 454             printAnnotations(tree.mods.annotations);
 455             if (tree.getModuleType() == ModuleKind.OPEN) {
 456                 print("open ");
 457             }
 458             print("module ");
 459             printExpr(tree.qualId);
 460             if (tree.directives == null) {
 461                 print(";");
 462             } else {
 463                 print(" ");
 464                 printBlock(tree.directives);
 465             }
 466             println();
 467         } catch (IOException e) {
 468             throw new UncheckedIOException(e);
 469         }
 470     }
 471 
 472     @Override
 473     public void visitExports(JCExports tree) {
 474         try {
 475             print("exports ");
 476             printExpr(tree.qualid);
 477             if (tree.moduleNames != null) {
 478                 print(" to ");
 479                 printExprs(tree.moduleNames);
 480             }
 481             print(";");
 482         } catch (IOException e) {
 483             throw new UncheckedIOException(e);
 484         }
 485     }
 486 
 487     @Override
 488     public void visitOpens(JCOpens tree) {
 489         try {
 490             print("opens ");
 491             printExpr(tree.qualid);
 492             if (tree.moduleNames != null) {
 493                 print(" to ");
 494                 printExprs(tree.moduleNames);
 495             }
 496             print(";");
 497         } catch (IOException e) {
 498             throw new UncheckedIOException(e);
 499         }
 500     }
 501 
 502     @Override
 503     public void visitProvides(JCProvides tree) {
 504         try {
 505             print("provides ");
 506             printExpr(tree.serviceName);
 507             print(" with ");
 508             printExprs(tree.implNames);
 509             print(";");
 510         } catch (IOException e) {
 511             throw new UncheckedIOException(e);
 512         }
 513     }
 514 
 515     @Override
 516     public void visitRequires(JCRequires tree) {
 517         try {
 518             print("requires ");
 519             if (tree.isStaticPhase)
 520                 print("static ");
 521             if (tree.isTransitive)
 522                 print("transitive ");
 523             printExpr(tree.moduleName);
 524             print(";");
 525         } catch (IOException e) {
 526             throw new UncheckedIOException(e);
 527         }
 528     }
 529 
 530     @Override
 531     public void visitUses(JCUses tree) {
 532         try {
 533             print("uses ");
 534             printExpr(tree.qualid);
 535             print(";");
 536         } catch (IOException e) {
 537             throw new UncheckedIOException(e);
 538         }
 539     }
 540 
 541     public void visitImport(JCImport tree) {
 542         try {
 543             print("import ");
 544             if (tree.staticImport) print("static ");
 545             printExpr(tree.qualid);
 546             print(";");
 547             println();
 548         } catch (IOException e) {
 549             throw new UncheckedIOException(e);
 550         }
 551     }
 552 
 553     public void visitClassDef(JCClassDecl tree) {
 554         try {
 555             println(); align();
 556             printDocComment(tree);
 557             printAnnotations(tree.mods.annotations);
 558             printFlags(tree.mods.flags & ~INTERFACE);
 559             Name enclClassNamePrev = enclClassName;
 560             enclClassName = tree.name;
 561             if ((tree.mods.flags & INTERFACE) != 0) {
 562                 print("interface " + tree.name);
 563                 printTypeParameters(tree.typarams);
 564                 if (tree.implementing.nonEmpty()) {
 565                     print(" extends ");
 566                     printExprs(tree.implementing);
 567                 }
 568                 if (tree.permitting.nonEmpty()) {
 569                     print(" permits ");
 570                     printExprs(tree.permitting);
 571                 }
 572             } else {
 573                 if ((tree.mods.flags & ENUM) != 0)
 574                     print("enum " + tree.name);
 575                 else
 576                     print("class " + tree.name);
 577                 printTypeParameters(tree.typarams);
 578                 if (tree.extending != null) {
 579                     print(" extends ");
 580                     printExpr(tree.extending);
 581                 }
 582                 if (tree.implementing.nonEmpty()) {
 583                     print(" implements ");
 584                     printExprs(tree.implementing);
 585                 }
 586                 if (tree.permitting.nonEmpty()) {
 587                     print(" permits ");
 588                     printExprs(tree.permitting);
 589                 }
 590             }
 591             print(" ");
 592             if ((tree.mods.flags & ENUM) != 0) {
 593                 printEnumBody(tree.defs);
 594             } else {
 595                 printBlock(tree.defs);
 596             }
 597             enclClassName = enclClassNamePrev;
 598         } catch (IOException e) {
 599             throw new UncheckedIOException(e);
 600         }
 601     }
 602 
 603     public void visitMethodDef(JCMethodDecl tree) {
 604         try {
 605             // when producing source output, omit anonymous constructors
 606             if (tree.name == tree.name.table.names.init &&
 607                     enclClassName == null &&
 608                     sourceOutput) return;
 609             println(); align();
 610             printDocComment(tree);
 611             printExpr(tree.mods);
 612             printTypeParameters(tree.typarams);
 613             if (tree.name == tree.name.table.names.init) {
 614                 print(enclClassName != null ? enclClassName : tree.name);
 615             } else {
 616                 printExpr(tree.restype);
 617                 print(" " + tree.name);
 618             }
 619             print("(");
 620             if (tree.recvparam!=null) {
 621                 printExpr(tree.recvparam);
 622                 if (tree.params.size() > 0) {
 623                     print(", ");
 624                 }
 625             }
 626             printExprs(tree.params);
 627             print(")");
 628             if (tree.thrown.nonEmpty()) {
 629                 print(" throws ");
 630                 printExprs(tree.thrown);
 631             }
 632             if (tree.defaultValue != null) {
 633                 print(" default ");
 634                 printExpr(tree.defaultValue);
 635             }
 636             if (tree.body != null) {
 637                 print(" ");
 638                 printStat(tree.body);
 639             } else {
 640                 print(";");
 641             }
 642         } catch (IOException e) {
 643             throw new UncheckedIOException(e);
 644         }
 645     }
 646 
 647     public void visitVarDef(JCVariableDecl tree) {
 648         try {
 649             if (docComments != null && docComments.hasComment(tree)) {
 650                 println(); align();
 651             }
 652             printDocComment(tree);
 653             if ((tree.mods.flags & ENUM) != 0) {
 654                 print("/*public static final*/ ");
 655                 print(tree.name);
 656                 if (tree.init != null) {
 657                     if (tree.init.hasTag(NEWCLASS)) {
 658                         JCNewClass init = (JCNewClass) tree.init;
 659                         if (sourceOutput) {
 660                             print(" /*enum*/ ");
 661                             if (init.args != null && init.args.nonEmpty()) {
 662                                 print("(");
 663                                 print(init.args);
 664                                 print(")");
 665                             }
 666                             if (init.def != null && init.def.defs != null) {
 667                                 print(" ");
 668                                 printBlock(init.def.defs);
 669                             }
 670                             return;
 671                         }else {
 672                             print(" /* = ");
 673                             print("new ");
 674                             if (init.def != null && init.def.mods.annotations.nonEmpty()) {
 675                                 printTypeAnnotations(init.def.mods.annotations);
 676                             }
 677                             printExpr(init.clazz);
 678                             print("(");
 679                             printExprs(init.args);
 680                             print(")");
 681                             print(" */");
 682                             print(" /*enum*/ ");
 683                             if (init.args != null && init.args.nonEmpty()) {
 684                                 print("(");
 685                                 printExprs(init.args);
 686                                 print(")");
 687                             }
 688                             if (init.def != null && init.def.defs != null) {
 689                                 print(" ");
 690                                 printBlock(init.def.defs);
 691                             }
 692                             return;
 693                         }
 694                     }
 695                     print(" /* = ");
 696                     printExpr(tree.init);
 697                     print(" */");
 698                 }
 699             } else {
 700                 printExpr(tree.mods);
 701                 if ((tree.mods.flags & VARARGS) != 0) {
 702                     JCTree vartype = tree.vartype;
 703                     List<JCAnnotation> tas = null;
 704                     if (vartype instanceof JCAnnotatedType annotatedType) {
 705                         tas = annotatedType.annotations;
 706                         vartype = annotatedType.underlyingType;
 707                     }
 708                     printExpr(((JCArrayTypeTree) vartype).elemtype);
 709                     if (tas != null) {
 710                         print(' ');
 711                         printTypeAnnotations(tas);
 712                     }
 713                     print("... " + tree.name);
 714                 } else {
 715                     printExpr(tree.vartype);
 716                     print(" " + tree.name);
 717                 }
 718                 if (tree.init != null) {
 719                     print(" = ");
 720                     printExpr(tree.init);
 721                 }
 722                 if (prec == TreeInfo.notExpression) print(";");
 723             }
 724         } catch (IOException e) {
 725             throw new UncheckedIOException(e);
 726         }
 727     }
 728 
 729     public void visitSkip(JCSkip tree) {
 730         try {
 731             print(";");
 732         } catch (IOException e) {
 733             throw new UncheckedIOException(e);
 734         }
 735     }
 736 
 737     public void visitBlock(JCBlock tree) {
 738         try {
 739             printFlags(tree.flags);
 740             printBlock(tree.stats);
 741         } catch (IOException e) {
 742             throw new UncheckedIOException(e);
 743         }
 744     }
 745 
 746     public void visitDoLoop(JCDoWhileLoop tree) {
 747         try {
 748             print("do ");
 749             printStat(tree.body);
 750             align();
 751             print(" while ");
 752             if (tree.cond.hasTag(PARENS)) {
 753                 printExpr(tree.cond);
 754             } else {
 755                 print("(");
 756                 printExpr(tree.cond);
 757                 print(")");
 758             }
 759             print(";");
 760         } catch (IOException e) {
 761             throw new UncheckedIOException(e);
 762         }
 763     }
 764 
 765     public void visitWhileLoop(JCWhileLoop tree) {
 766         try {
 767             print("while ");
 768             if (tree.cond.hasTag(PARENS)) {
 769                 printExpr(tree.cond);
 770             } else {
 771                 print("(");
 772                 printExpr(tree.cond);
 773                 print(")");
 774             }
 775             print(" ");
 776             printStat(tree.body);
 777         } catch (IOException e) {
 778             throw new UncheckedIOException(e);
 779         }
 780     }
 781 
 782     public void visitForLoop(JCForLoop tree) {
 783         try {
 784             print("for (");
 785             if (tree.init.nonEmpty()) {
 786                 if (tree.init.head.hasTag(VARDEF)) {
 787                     printExpr(tree.init.head);
 788                     for (List<JCStatement> l = tree.init.tail; l.nonEmpty(); l = l.tail) {
 789                         JCVariableDecl vdef = (JCVariableDecl)l.head;
 790                         print(", " + vdef.name);
 791                         if (vdef.init != null) {
 792                             print(" = ");
 793                             printExpr(vdef.init);
 794                         }
 795                     }
 796                 } else {
 797                     printExprs(tree.init);
 798                 }
 799             }
 800             print("; ");
 801             if (tree.cond != null) printExpr(tree.cond);
 802             print("; ");
 803             printExprs(tree.step);
 804             print(") ");
 805             printStat(tree.body);
 806         } catch (IOException e) {
 807             throw new UncheckedIOException(e);
 808         }
 809     }
 810 
 811     public void visitForeachLoop(JCEnhancedForLoop tree) {
 812         try {
 813             print("for (");
 814             printExpr(tree.var);
 815             print(" : ");
 816             printExpr(tree.expr);
 817             print(") ");
 818             printStat(tree.body);
 819         } catch (IOException e) {
 820             throw new UncheckedIOException(e);
 821         }
 822     }
 823 
 824     public void visitLabelled(JCLabeledStatement tree) {
 825         try {
 826             print(tree.label + ": ");
 827             printStat(tree.body);
 828         } catch (IOException e) {
 829             throw new UncheckedIOException(e);
 830         }
 831     }
 832 
 833     public void visitSwitch(JCSwitch tree) {
 834         try {
 835             print("switch ");
 836             if (tree.selector.hasTag(PARENS)) {
 837                 printExpr(tree.selector);
 838             } else {
 839                 print("(");
 840                 printExpr(tree.selector);
 841                 print(")");
 842             }
 843             print(" {");
 844             println();
 845             printStats(tree.cases);
 846             align();
 847             print("}");
 848         } catch (IOException e) {
 849             throw new UncheckedIOException(e);
 850         }
 851     }
 852 
 853     public void visitCase(JCCase tree) {
 854         try {
 855             if (tree.labels.size() == 1 && tree.labels.get(0).hasTag(DEFAULTCASELABEL)) {
 856                 print("default");
 857             } else {
 858                 print("case ");
 859                 printExprs(tree.labels);
 860             }
 861             if (tree.caseKind == JCCase.STATEMENT) {
 862                 print(":");
 863                 println();
 864                 indent();
 865                 printStats(tree.stats);
 866                 undent();
 867                 align();
 868             } else {
 869                 print(" -> ");
 870                 if (tree.stats.size() == 1) {
 871                     printStat(tree.stats.head);
 872                 } else {
 873                     printBlock(tree.stats);
 874                 }
 875             }
 876         } catch (IOException e) {
 877             throw new UncheckedIOException(e);
 878         }
 879     }
 880 
 881     @Override
 882     public void visitDefaultCaseLabel(JCTree.JCDefaultCaseLabel that) {
 883         try {
 884             print("default");
 885         } catch (IOException e) {
 886             throw new UncheckedIOException(e);
 887         }
 888     }
 889 
 890     public void visitSwitchExpression(JCSwitchExpression tree) {
 891         try {
 892             print("switch ");
 893             if (tree.selector.hasTag(PARENS)) {
 894                 printExpr(tree.selector);
 895             } else {
 896                 print("(");
 897                 printExpr(tree.selector);
 898                 print(")");
 899             }
 900             print(" {");
 901             println();
 902             printStats(tree.cases);
 903             align();
 904             print("}");
 905         } catch (IOException e) {
 906             throw new UncheckedIOException(e);
 907         }
 908     }
 909 
 910     public void visitBindingPattern(JCBindingPattern patt) {
 911         try {
 912             printExpr(patt.var);
 913         } catch (IOException e) {
 914             throw new UncheckedIOException(e);
 915         }
 916     }
 917 
 918     @Override
 919     public void visitParenthesizedPattern(JCParenthesizedPattern patt) {
 920         try {
 921             print("(");
 922             printExpr(patt.pattern);
 923             print(")");
 924         } catch (IOException e) {
 925             throw new UncheckedIOException(e);
 926         }
 927     }
 928 
 929     @Override
 930     public void visitGuardPattern(JCGuardPattern patt) {
 931         try {
 932             printExpr(patt.patt);
 933             print(" && ");
 934             printExpr(patt.expr);
 935         } catch (IOException e) {
 936             throw new UncheckedIOException(e);
 937         }
 938     }
 939 
 940     public void visitSynchronized(JCSynchronized tree) {
 941         try {
 942             print("synchronized ");
 943             if (tree.lock.hasTag(PARENS)) {
 944                 printExpr(tree.lock);
 945             } else {
 946                 print("(");
 947                 printExpr(tree.lock);
 948                 print(")");
 949             }
 950             print(" ");
 951             printStat(tree.body);
 952         } catch (IOException e) {
 953             throw new UncheckedIOException(e);
 954         }
 955     }
 956 
 957     public void visitTry(JCTry tree) {
 958         try {
 959             print("try ");
 960             if (tree.resources.nonEmpty()) {
 961                 print("(");
 962                 boolean first = true;
 963                 for (JCTree var : tree.resources) {
 964                     if (!first) {
 965                         println();
 966                         indent();
 967                     }
 968                     printStat(var);
 969                     first = false;
 970                 }
 971                 print(") ");
 972             }
 973             printStat(tree.body);
 974             for (List<JCCatch> l = tree.catchers; l.nonEmpty(); l = l.tail) {
 975                 printStat(l.head);
 976             }
 977             if (tree.finalizer != null) {
 978                 print(" finally ");
 979                 printStat(tree.finalizer);
 980             }
 981         } catch (IOException e) {
 982             throw new UncheckedIOException(e);
 983         }
 984     }
 985 
 986     public void visitCatch(JCCatch tree) {
 987         try {
 988             print(" catch (");
 989             printExpr(tree.param);
 990             print(") ");
 991             printStat(tree.body);
 992         } catch (IOException e) {
 993             throw new UncheckedIOException(e);
 994         }
 995     }
 996 
 997     public void visitConditional(JCConditional tree) {
 998         try {
 999             open(prec, TreeInfo.condPrec);
1000             printExpr(tree.cond, TreeInfo.condPrec + 1);
1001             print(" ? ");
1002             printExpr(tree.truepart);
1003             print(" : ");
1004             printExpr(tree.falsepart, TreeInfo.condPrec);
1005             close(prec, TreeInfo.condPrec);
1006         } catch (IOException e) {
1007             throw new UncheckedIOException(e);
1008         }
1009     }
1010 
1011     public void visitIf(JCIf tree) {
1012         try {
1013             print("if ");
1014             if (tree.cond.hasTag(PARENS)) {
1015                 printExpr(tree.cond);
1016             } else {
1017                 print("(");
1018                 printExpr(tree.cond);
1019                 print(")");
1020             }
1021             print(" ");
1022             printStat(tree.thenpart);
1023             if (tree.elsepart != null) {
1024                 print(" else ");
1025                 printStat(tree.elsepart);
1026             }
1027         } catch (IOException e) {
1028             throw new UncheckedIOException(e);
1029         }
1030     }
1031 
1032     public void visitExec(JCExpressionStatement tree) {
1033         try {
1034             printExpr(tree.expr);
1035             if (prec == TreeInfo.notExpression) print(";");
1036         } catch (IOException e) {
1037             throw new UncheckedIOException(e);
1038         }
1039     }
1040 
1041     public void visitBreak(JCBreak tree) {
1042         try {
1043             print("break");
1044             if (tree.label != null) print(" " + tree.label);
1045             print(";");
1046         } catch (IOException e) {
1047             throw new UncheckedIOException(e);
1048         }
1049     }
1050 
1051     public void visitYield(JCYield tree) {
1052         try {
1053             print("yield");
1054             print(" ");
1055             printExpr(tree.value);
1056             print(";");
1057         } catch (IOException e) {
1058             throw new UncheckedIOException(e);
1059         }
1060     }
1061 
1062     public void visitContinue(JCContinue tree) {
1063         try {
1064             print("continue");
1065             if (tree.label != null) print(" " + tree.label);
1066             print(";");
1067         } catch (IOException e) {
1068             throw new UncheckedIOException(e);
1069         }
1070     }
1071 
1072     public void visitReturn(JCReturn tree) {
1073         try {
1074             print("return");
1075             if (tree.expr != null) {
1076                 print(" ");
1077                 printExpr(tree.expr);
1078             }
1079             print(";");
1080         } catch (IOException e) {
1081             throw new UncheckedIOException(e);
1082         }
1083     }
1084 
1085     public void visitThrow(JCThrow tree) {
1086         try {
1087             print("throw ");
1088             printExpr(tree.expr);
1089             print(";");
1090         } catch (IOException e) {
1091             throw new UncheckedIOException(e);
1092         }
1093     }
1094 
1095     public void visitAssert(JCAssert tree) {
1096         try {
1097             print("assert ");
1098             printExpr(tree.cond);
1099             if (tree.detail != null) {
1100                 print(" : ");
1101                 printExpr(tree.detail);
1102             }
1103             print(";");
1104         } catch (IOException e) {
1105             throw new UncheckedIOException(e);
1106         }
1107     }
1108 
1109     public void visitApply(JCMethodInvocation tree) {
1110         try {
1111             if (!tree.typeargs.isEmpty()) {
1112                 if (tree.meth.hasTag(SELECT)) {
1113                     JCFieldAccess left = (JCFieldAccess)tree.meth;
1114                     printExpr(left.selected);
1115                     print(".<");
1116                     printExprs(tree.typeargs);
1117                     print(">" + left.name);
1118                 } else {
1119                     print("<");
1120                     printExprs(tree.typeargs);
1121                     print(">");
1122                     printExpr(tree.meth);
1123                 }
1124             } else {
1125                 printExpr(tree.meth);
1126             }
1127             print("(");
1128             printExprs(tree.args);
1129             print(")");
1130         } catch (IOException e) {
1131             throw new UncheckedIOException(e);
1132         }
1133     }
1134 
1135     public void visitNewClass(JCNewClass tree) {
1136         try {
1137             if (tree.encl != null) {
1138                 printExpr(tree.encl);
1139                 print(".");
1140             }
1141             print("new ");
1142             if (!tree.typeargs.isEmpty()) {
1143                 print("<");
1144                 printExprs(tree.typeargs);
1145                 print(">");
1146             }
1147             if (tree.def != null && tree.def.mods.annotations.nonEmpty()) {
1148                 printTypeAnnotations(tree.def.mods.annotations);
1149             }
1150             printExpr(tree.clazz);
1151             print("(");
1152             printExprs(tree.args);
1153             print(")");
1154             if (tree.def != null) {
1155                 Name enclClassNamePrev = enclClassName;
1156                 enclClassName =
1157                         tree.def.name != null ? tree.def.name :
1158                             tree.type != null && tree.type.tsym.name != tree.type.tsym.name.table.names.empty
1159                                 ? tree.type.tsym.name : null;
1160                 if ((tree.def.mods.flags & Flags.ENUM) != 0) print("/*enum*/");
1161                 printBlock(tree.def.defs);
1162                 enclClassName = enclClassNamePrev;
1163             }
1164         } catch (IOException e) {
1165             throw new UncheckedIOException(e);
1166         }
1167     }
1168 
1169     public void visitNewArray(JCNewArray tree) {
1170         try {
1171             if (tree.elemtype != null) {
1172                 print("new ");
1173                 JCTree elem = tree.elemtype;
1174                 printBaseElementType(elem);
1175 
1176                 if (!tree.annotations.isEmpty()) {
1177                     print(' ');
1178                     printTypeAnnotations(tree.annotations);
1179                 }
1180                 if (tree.elems != null) {
1181                     print("[]");
1182                 }
1183 
1184                 int i = 0;
1185                 List<List<JCAnnotation>> da = tree.dimAnnotations;
1186                 for (List<JCExpression> l = tree.dims; l.nonEmpty(); l = l.tail) {
1187                     if (da.size() > i && !da.get(i).isEmpty()) {
1188                         print(' ');
1189                         printTypeAnnotations(da.get(i));
1190                     }
1191                     print("[");
1192                     i++;
1193                     printExpr(l.head);
1194                     print("]");
1195                 }
1196                 printBrackets(elem);
1197             }
1198             if (tree.elems != null) {
1199                 print("{");
1200                 printExprs(tree.elems);
1201                 print("}");
1202             }
1203         } catch (IOException e) {
1204             throw new UncheckedIOException(e);
1205         }
1206     }
1207 
1208     public void visitLambda(JCLambda tree) {
1209         try {
1210             print("(");
1211             if (tree.paramKind == JCLambda.ParameterKind.EXPLICIT) {
1212                 printExprs(tree.params);
1213             } else {
1214                 String sep = "";
1215                 for (JCVariableDecl param : tree.params) {
1216                     print(sep);
1217                     print(param.name);
1218                     sep = ",";
1219                 }
1220             }
1221             print(")->");
1222             printExpr(tree.body);
1223         } catch (IOException e) {
1224             throw new UncheckedIOException(e);
1225         }
1226     }
1227 
1228     public void visitParens(JCParens tree) {
1229         try {
1230             print("(");
1231             printExpr(tree.expr);
1232             print(")");
1233         } catch (IOException e) {
1234             throw new UncheckedIOException(e);
1235         }
1236     }
1237 
1238     public void visitAssign(JCAssign tree) {
1239         try {
1240             open(prec, TreeInfo.assignPrec);
1241             printExpr(tree.lhs, TreeInfo.assignPrec + 1);
1242             print(" = ");
1243             printExpr(tree.rhs, TreeInfo.assignPrec);
1244             close(prec, TreeInfo.assignPrec);
1245         } catch (IOException e) {
1246             throw new UncheckedIOException(e);
1247         }
1248     }
1249 
1250     public String operatorName(JCTree.Tag tag) {
1251         switch(tag) {
1252             case POS:     return "+";
1253             case NEG:     return "-";
1254             case NOT:     return "!";
1255             case COMPL:   return "~";
1256             case PREINC:  return "++";
1257             case PREDEC:  return "--";
1258             case POSTINC: return "++";
1259             case POSTDEC: return "--";
1260             case NULLCHK: return "<*nullchk*>";
1261             case OR:      return "||";
1262             case AND:     return "&&";
1263             case EQ:      return "==";
1264             case NE:      return "!=";
1265             case LT:      return "<";
1266             case GT:      return ">";
1267             case LE:      return "<=";
1268             case GE:      return ">=";
1269             case BITOR:   return "|";
1270             case BITXOR:  return "^";
1271             case BITAND:  return "&";
1272             case SL:      return "<<";
1273             case SR:      return ">>";
1274             case USR:     return ">>>";
1275             case PLUS:    return "+";
1276             case MINUS:   return "-";
1277             case MUL:     return "*";
1278             case DIV:     return "/";
1279             case MOD:     return "%";
1280             default: throw new Error();
1281         }
1282     }
1283 
1284     public void visitAssignop(JCAssignOp tree) {
1285         try {
1286             open(prec, TreeInfo.assignopPrec);
1287             printExpr(tree.lhs, TreeInfo.assignopPrec + 1);
1288             print(" " + operatorName(tree.getTag().noAssignOp()) + "= ");
1289             printExpr(tree.rhs, TreeInfo.assignopPrec);
1290             close(prec, TreeInfo.assignopPrec);
1291         } catch (IOException e) {
1292             throw new UncheckedIOException(e);
1293         }
1294     }
1295 
1296     public void visitUnary(JCUnary tree) {
1297         try {
1298             int ownprec = TreeInfo.opPrec(tree.getTag());
1299             String opname = operatorName(tree.getTag());
1300             open(prec, ownprec);
1301             if (!tree.getTag().isPostUnaryOp()) {
1302                 print(opname);
1303                 printExpr(tree.arg, ownprec);
1304             } else {
1305                 printExpr(tree.arg, ownprec);
1306                 print(opname);
1307             }
1308             close(prec, ownprec);
1309         } catch (IOException e) {
1310             throw new UncheckedIOException(e);
1311         }
1312     }
1313 
1314     public void visitBinary(JCBinary tree) {
1315         try {
1316             int ownprec = TreeInfo.opPrec(tree.getTag());
1317             String opname = operatorName(tree.getTag());
1318             open(prec, ownprec);
1319             printExpr(tree.lhs, ownprec);
1320             print(" " + opname + " ");
1321             printExpr(tree.rhs, ownprec + 1);
1322             close(prec, ownprec);
1323         } catch (IOException e) {
1324             throw new UncheckedIOException(e);
1325         }
1326     }
1327 
1328     public void visitTypeCast(JCTypeCast tree) {
1329         try {
1330             open(prec, TreeInfo.prefixPrec);
1331             print("(");
1332             printExpr(tree.clazz);
1333             print(")");
1334             printExpr(tree.expr, TreeInfo.prefixPrec);
1335             close(prec, TreeInfo.prefixPrec);
1336         } catch (IOException e) {
1337             throw new UncheckedIOException(e);
1338         }
1339     }
1340 
1341     public void visitTypeTest(JCInstanceOf tree) {
1342         try {
1343             open(prec, TreeInfo.ordPrec);
1344             printExpr(tree.expr, TreeInfo.ordPrec);
1345             print(" instanceof ");
1346             if (tree.pattern instanceof JCPattern) {
1347                 printPattern(tree.pattern);
1348             } else {
1349                 printExpr(tree.getType(), TreeInfo.ordPrec + 1);
1350             }
1351             close(prec, TreeInfo.ordPrec);
1352         } catch (IOException e) {
1353             throw new UncheckedIOException(e);
1354         }
1355     }
1356 
1357     public void visitIndexed(JCArrayAccess tree) {
1358         try {
1359             printExpr(tree.indexed, TreeInfo.postfixPrec);
1360             print("[");
1361             printExpr(tree.index);
1362             print("]");
1363         } catch (IOException e) {
1364             throw new UncheckedIOException(e);
1365         }
1366     }
1367 
1368     public void visitSelect(JCFieldAccess tree) {
1369         try {
1370             printExpr(tree.selected, TreeInfo.postfixPrec);
1371             print("." + tree.name);
1372         } catch (IOException e) {
1373             throw new UncheckedIOException(e);
1374         }
1375     }
1376 
1377     public void visitReference(JCMemberReference tree) {
1378         try {
1379             printExpr(tree.expr);
1380             print("::");
1381             if (tree.typeargs != null) {
1382                 print("<");
1383                 printExprs(tree.typeargs);
1384                 print(">");
1385             }
1386             print(tree.getMode() == ReferenceMode.INVOKE ? tree.name : "new");
1387         } catch (IOException e) {
1388             throw new UncheckedIOException(e);
1389         }
1390     }
1391 
1392     public void visitIdent(JCIdent tree) {
1393         try {
1394             print(tree.name);
1395         } catch (IOException e) {
1396             throw new UncheckedIOException(e);
1397         }
1398     }
1399 
1400     public void visitLiteral(JCLiteral tree) {
1401         try {
1402             switch (tree.typetag) {
1403                 case INT:
1404                     print(tree.value.toString());
1405                     break;
1406                 case LONG:
1407                     print(tree.value + "L");
1408                     break;
1409                 case FLOAT:
1410                     print(tree.value + "F");
1411                     break;
1412                 case DOUBLE:
1413                     print(tree.value.toString());
1414                     break;
1415                 case CHAR:
1416                     print("\'" +
1417                             Convert.quote(
1418                             String.valueOf((char)((Number)tree.value).intValue())) +
1419                             "\'");
1420                     break;
1421                 case BOOLEAN:
1422                     print(((Number)tree.value).intValue() == 1 ? "true" : "false");
1423                     break;
1424                 case BOT:
1425                     print("null");
1426                     break;
1427                 default:
1428                     print("\"" + Convert.quote(tree.value.toString()) + "\"");
1429                     break;
1430             }
1431         } catch (IOException e) {
1432             throw new UncheckedIOException(e);
1433         }
1434     }
1435 
1436     public void visitTypeIdent(JCPrimitiveTypeTree tree) {
1437         try {
1438             switch(tree.typetag) {
1439                 case BYTE:
1440                     print("byte");
1441                     break;
1442                 case CHAR:
1443                     print("char");
1444                     break;
1445                 case SHORT:
1446                     print("short");
1447                     break;
1448                 case INT:
1449                     print("int");
1450                     break;
1451                 case LONG:
1452                     print("long");
1453                     break;
1454                 case FLOAT:
1455                     print("float");
1456                     break;
1457                 case DOUBLE:
1458                     print("double");
1459                     break;
1460                 case BOOLEAN:
1461                     print("boolean");
1462                     break;
1463                 case VOID:
1464                     print("void");
1465                     break;
1466                 default:
1467                     print("error");
1468                     break;
1469             }
1470         } catch (IOException e) {
1471             throw new UncheckedIOException(e);
1472         }
1473     }
1474 
1475     public void visitTypeArray(JCArrayTypeTree tree) {
1476         try {
1477             printBaseElementType(tree);
1478             printBrackets(tree);
1479         } catch (IOException e) {
1480             throw new UncheckedIOException(e);
1481         }
1482     }
1483 
1484     // Prints the inner element type of a nested array
1485     private void printBaseElementType(JCTree tree) throws IOException {
1486         printExpr(TreeInfo.innermostType(tree, false));
1487     }
1488 
1489     // prints the brackets of a nested array in reverse order
1490     // tree is either JCArrayTypeTree or JCAnnotatedTypeTree
1491     private void printBrackets(JCTree tree) throws IOException {
1492         JCTree elem = tree;
1493         while (true) {
1494             if (elem.hasTag(ANNOTATED_TYPE)) {
1495                 JCAnnotatedType atype = (JCAnnotatedType) elem;
1496                 elem = atype.underlyingType;
1497                 if (elem.hasTag(TYPEARRAY)) {
1498                     print(' ');
1499                     printTypeAnnotations(atype.annotations);
1500                 }
1501             }
1502             if (elem.hasTag(TYPEARRAY)) {
1503                 print("[]");
1504                 elem = ((JCArrayTypeTree)elem).elemtype;
1505             } else {
1506                 break;
1507             }
1508         }
1509     }
1510 
1511     public void visitTypeApply(JCTypeApply tree) {
1512         try {
1513             printExpr(tree.clazz);
1514             print("<");
1515             printExprs(tree.arguments);
1516             print(">");
1517         } catch (IOException e) {
1518             throw new UncheckedIOException(e);
1519         }
1520     }
1521 
1522     public void visitTypeUnion(JCTypeUnion tree) {
1523         try {
1524             printExprs(tree.alternatives, " | ");
1525         } catch (IOException e) {
1526             throw new UncheckedIOException(e);
1527         }
1528     }
1529 
1530     public void visitTypeIntersection(JCTypeIntersection tree) {
1531         try {
1532             printExprs(tree.bounds, " & ");
1533         } catch (IOException e) {
1534             throw new UncheckedIOException(e);
1535         }
1536     }
1537 
1538     public void visitTypeParameter(JCTypeParameter tree) {
1539         try {
1540             if (tree.annotations.nonEmpty()) {
1541                 this.printTypeAnnotations(tree.annotations);
1542             }
1543             print(tree.name);
1544             if (tree.bounds.nonEmpty()) {
1545                 print(" extends ");
1546                 printExprs(tree.bounds, " & ");
1547             }
1548         } catch (IOException e) {
1549             throw new UncheckedIOException(e);
1550         }
1551     }
1552 
1553     @Override
1554     public void visitWildcard(JCWildcard tree) {
1555         try {
1556             print(tree.kind);
1557             if (tree.kind.kind != BoundKind.UNBOUND)
1558                 printExpr(tree.inner);
1559         } catch (IOException e) {
1560             throw new UncheckedIOException(e);
1561         }
1562     }
1563 
1564     @Override
1565     public void visitTypeBoundKind(TypeBoundKind tree) {
1566         try {
1567             print(String.valueOf(tree.kind));
1568         } catch (IOException e) {
1569             throw new UncheckedIOException(e);
1570         }
1571     }
1572 
1573     public void visitErroneous(JCErroneous tree) {
1574         try {
1575             print("(ERROR)");
1576         } catch (IOException e) {
1577             throw new UncheckedIOException(e);
1578         }
1579     }
1580 
1581     public void visitLetExpr(LetExpr tree) {
1582         try {
1583             print("(let " + tree.defs + " in " + tree.expr + ")");
1584         } catch (IOException e) {
1585             throw new UncheckedIOException(e);
1586         }
1587     }
1588 
1589     public void visitModifiers(JCModifiers mods) {
1590         try {
1591             printAnnotations(mods.annotations);
1592             printFlags(mods.flags);
1593         } catch (IOException e) {
1594             throw new UncheckedIOException(e);
1595         }
1596     }
1597 
1598     public void visitAnnotation(JCAnnotation tree) {
1599         try {
1600             print("@");
1601             printExpr(tree.annotationType);
1602             if (!tree.args.isEmpty()) {
1603                 print("(");
1604                 printExprs(tree.args);
1605                 print(")");
1606             }
1607         } catch (IOException e) {
1608             throw new UncheckedIOException(e);
1609         }
1610     }
1611 
1612     public void visitAnnotatedType(JCAnnotatedType tree) {
1613         try {
1614             if (tree.underlyingType.hasTag(SELECT)) {
1615                 JCFieldAccess access = (JCFieldAccess) tree.underlyingType;
1616                 printExpr(access.selected, TreeInfo.postfixPrec);
1617                 print(".");
1618                 printTypeAnnotations(tree.annotations);
1619                 print(access.name);
1620             } else if (tree.underlyingType.hasTag(TYPEARRAY)) {
1621                 printBaseElementType(tree);
1622                 printBrackets(tree);
1623             } else {
1624                 printTypeAnnotations(tree.annotations);
1625                 printExpr(tree.underlyingType);
1626             }
1627         } catch (IOException e) {
1628             throw new UncheckedIOException(e);
1629         }
1630     }
1631 
1632     public void visitTree(JCTree tree) {
1633         try {
1634             print("(UNKNOWN: " + tree.getTag() + ")");
1635             println();
1636         } catch (IOException e) {
1637             throw new UncheckedIOException(e);
1638         }
1639     }
1640 
1641 }