< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/tree/Pretty.java

Print this page
rev 51258 : imported patch switch.diff


  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 import com.sun.tools.javac.util.List;
  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) {


 818             print("switch ");
 819             if (tree.selector.hasTag(PARENS)) {
 820                 printExpr(tree.selector);
 821             } else {
 822                 print("(");
 823                 printExpr(tree.selector);
 824                 print(")");
 825             }
 826             print(" {");
 827             println();
 828             printStats(tree.cases);
 829             align();
 830             print("}");
 831         } catch (IOException e) {
 832             throw new UncheckedIOException(e);
 833         }
 834     }
 835 
 836     public void visitCase(JCCase tree) {
 837         try {
 838             if (tree.pat == null) {
 839                 print("default");
 840             } else {
 841                 print("case ");
 842                 printExpr(tree.pat);
 843             }
 844             print(": ");

 845             println();
 846             indent();
 847             printStats(tree.stats);
 848             undent();
 849             align();
























 850         } catch (IOException e) {
 851             throw new UncheckedIOException(e);
 852         }
 853     }
 854 
 855     public void visitSynchronized(JCSynchronized tree) {
 856         try {
 857             print("synchronized ");
 858             if (tree.lock.hasTag(PARENS)) {
 859                 printExpr(tree.lock);
 860             } else {
 861                 print("(");
 862                 printExpr(tree.lock);
 863                 print(")");
 864             }
 865             print(" ");
 866             printStat(tree.body);
 867         } catch (IOException e) {
 868             throw new UncheckedIOException(e);
 869         }


 939                 print(" else ");
 940                 printStat(tree.elsepart);
 941             }
 942         } catch (IOException e) {
 943             throw new UncheckedIOException(e);
 944         }
 945     }
 946 
 947     public void visitExec(JCExpressionStatement tree) {
 948         try {
 949             printExpr(tree.expr);
 950             if (prec == TreeInfo.notExpression) print(";");
 951         } catch (IOException e) {
 952             throw new UncheckedIOException(e);
 953         }
 954     }
 955 
 956     public void visitBreak(JCBreak tree) {
 957         try {
 958             print("break");
 959             if (tree.label != null) print(" " + tree.label);
 960             print(";");
 961         } catch (IOException e) {
 962             throw new UncheckedIOException(e);
 963         }
 964     }
 965 
 966     public void visitContinue(JCContinue tree) {
 967         try {
 968             print("continue");
 969             if (tree.label != null) print(" " + tree.label);
 970             print(";");
 971         } catch (IOException e) {
 972             throw new UncheckedIOException(e);
 973         }
 974     }
 975 
 976     public void visitReturn(JCReturn tree) {
 977         try {
 978             print("return");
 979             if (tree.expr != null) {




  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.CaseTree.CaseKind;
  31 import com.sun.source.tree.MemberReferenceTree.ReferenceMode;
  32 import com.sun.source.tree.ModuleTree.ModuleKind;
  33 import com.sun.tools.javac.code.*;
  34 import com.sun.tools.javac.tree.JCTree.*;
  35 import com.sun.tools.javac.util.*;
  36 import com.sun.tools.javac.util.List;
  37 import static com.sun.tools.javac.code.Flags.*;
  38 import static com.sun.tools.javac.code.Flags.ANNOTATION;
  39 import static com.sun.tools.javac.tree.JCTree.Tag.*;
  40 
  41 /** Prints out a tree as an indented Java source program.
  42  *
  43  *  <p><b>This is NOT part of any supported API.
  44  *  If you write code that depends on this, you do so at your own risk.
  45  *  This code and its internal interfaces are subject to change or
  46  *  deletion without notice.</b>
  47  */
  48 public class Pretty extends JCTree.Visitor {
  49 
  50     public Pretty(Writer out, boolean sourceOutput) {


 819             print("switch ");
 820             if (tree.selector.hasTag(PARENS)) {
 821                 printExpr(tree.selector);
 822             } else {
 823                 print("(");
 824                 printExpr(tree.selector);
 825                 print(")");
 826             }
 827             print(" {");
 828             println();
 829             printStats(tree.cases);
 830             align();
 831             print("}");
 832         } catch (IOException e) {
 833             throw new UncheckedIOException(e);
 834         }
 835     }
 836 
 837     public void visitCase(JCCase tree) {
 838         try {
 839             if (tree.pats.isEmpty()) {
 840                 print("default");
 841             } else {
 842                 print("case ");
 843                 printExprs(tree.pats);
 844             }
 845             if (tree.caseKind == JCCase.STATEMENT) {
 846                 print(":");
 847                 println();
 848                 indent();
 849                 printStats(tree.stats);
 850                 undent();
 851                 align();
 852             } else {
 853                 print(" -> ");
 854                 printStat(tree.stats.head);
 855             }
 856         } catch (IOException e) {
 857             throw new UncheckedIOException(e);
 858         }
 859     }
 860 
 861     public void visitSwitchExpression(JCSwitchExpression tree) {
 862         try {
 863             print("switch ");
 864             if (tree.selector.hasTag(PARENS)) {
 865                 printExpr(tree.selector);
 866             } else {
 867                 print("(");
 868                 printExpr(tree.selector);
 869                 print(")");
 870             }
 871             print(" {");
 872             println();
 873             printStats(tree.cases);
 874             align();
 875             print("}");
 876         } catch (IOException e) {
 877             throw new UncheckedIOException(e);
 878         }
 879     }
 880 
 881     public void visitSynchronized(JCSynchronized tree) {
 882         try {
 883             print("synchronized ");
 884             if (tree.lock.hasTag(PARENS)) {
 885                 printExpr(tree.lock);
 886             } else {
 887                 print("(");
 888                 printExpr(tree.lock);
 889                 print(")");
 890             }
 891             print(" ");
 892             printStat(tree.body);
 893         } catch (IOException e) {
 894             throw new UncheckedIOException(e);
 895         }


 965                 print(" else ");
 966                 printStat(tree.elsepart);
 967             }
 968         } catch (IOException e) {
 969             throw new UncheckedIOException(e);
 970         }
 971     }
 972 
 973     public void visitExec(JCExpressionStatement tree) {
 974         try {
 975             printExpr(tree.expr);
 976             if (prec == TreeInfo.notExpression) print(";");
 977         } catch (IOException e) {
 978             throw new UncheckedIOException(e);
 979         }
 980     }
 981 
 982     public void visitBreak(JCBreak tree) {
 983         try {
 984             print("break");
 985             if (tree.value != null) print(" " + tree.value);
 986             print(";");
 987         } catch (IOException e) {
 988             throw new UncheckedIOException(e);
 989         }
 990     }
 991 
 992     public void visitContinue(JCContinue tree) {
 993         try {
 994             print("continue");
 995             if (tree.label != null) print(" " + tree.label);
 996             print(";");
 997         } catch (IOException e) {
 998             throw new UncheckedIOException(e);
 999         }
1000     }
1001 
1002     public void visitReturn(JCReturn tree) {
1003         try {
1004             print("return");
1005             if (tree.expr != null) {


< prev index next >