< prev index next >

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

Print this page




 218 
 219     /** Derived visitor method: print list of expression trees, separated by given string.
 220      *  @param sep the separator string
 221      */
 222     public <T extends JCTree> void printExprs(List<T> trees, String sep) throws IOException {
 223         if (trees.nonEmpty()) {
 224             printExpr(trees.head);
 225             for (List<T> l = trees.tail; l.nonEmpty(); l = l.tail) {
 226                 print(sep);
 227                 printExpr(l.head);
 228             }
 229         }
 230     }
 231 
 232     /** Derived visitor method: print list of expression trees, separated by commas.
 233      */
 234     public <T extends JCTree> void printExprs(List<T> trees) throws IOException {
 235         printExprs(trees, ", ");
 236     }
 237 








 238     /** Derived visitor method: print list of statements, each on a separate line.
 239      */
 240     public void printStats(List<? extends JCTree> trees) throws IOException {
 241         for (List<? extends JCTree> l = trees; l.nonEmpty(); l = l.tail) {
 242             align();
 243             printStat(l.head);
 244             println();
 245         }
 246     }
 247 
 248     /** Print a set of modifiers.
 249      */
 250     public void printFlags(long flags) throws IOException {
 251         if ((flags & SYNTHETIC) != 0) print("/*synthetic*/ ");
 252         print(TreeInfo.flagNames(flags));
 253         if ((flags & ExtendedStandardFlags) != 0) print(" ");
 254         if ((flags & ANNOTATION) != 0) print("@");
 255     }
 256 
 257     public void printAnnotations(List<JCAnnotation> trees) throws IOException {


 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         }
 896     }
 897 
 898     public void visitTry(JCTry tree) {
 899         try {
 900             print("try ");


1267     }
1268 
1269     public void visitTypeCast(JCTypeCast tree) {
1270         try {
1271             open(prec, TreeInfo.prefixPrec);
1272             print("(");
1273             printExpr(tree.clazz);
1274             print(")");
1275             printExpr(tree.expr, TreeInfo.prefixPrec);
1276             close(prec, TreeInfo.prefixPrec);
1277         } catch (IOException e) {
1278             throw new UncheckedIOException(e);
1279         }
1280     }
1281 
1282     public void visitTypeTest(JCInstanceOf tree) {
1283         try {
1284             open(prec, TreeInfo.ordPrec);
1285             printExpr(tree.expr, TreeInfo.ordPrec);
1286             print(" instanceof ");
1287             printExpr(tree.clazz, TreeInfo.ordPrec + 1);




1288             close(prec, TreeInfo.ordPrec);
1289         } catch (IOException e) {
1290             throw new UncheckedIOException(e);
1291         }
1292     }
1293 
1294     public void visitIndexed(JCArrayAccess tree) {
1295         try {
1296             printExpr(tree.indexed, TreeInfo.postfixPrec);
1297             print("[");
1298             printExpr(tree.index);
1299             print("]");
1300         } catch (IOException e) {
1301             throw new UncheckedIOException(e);
1302         }
1303     }
1304 
1305     public void visitSelect(JCFieldAccess tree) {
1306         try {
1307             printExpr(tree.selected, TreeInfo.postfixPrec);




 218 
 219     /** Derived visitor method: print list of expression trees, separated by given string.
 220      *  @param sep the separator string
 221      */
 222     public <T extends JCTree> void printExprs(List<T> trees, String sep) throws IOException {
 223         if (trees.nonEmpty()) {
 224             printExpr(trees.head);
 225             for (List<T> l = trees.tail; l.nonEmpty(); l = l.tail) {
 226                 print(sep);
 227                 printExpr(l.head);
 228             }
 229         }
 230     }
 231 
 232     /** Derived visitor method: print list of expression trees, separated by commas.
 233      */
 234     public <T extends JCTree> void printExprs(List<T> trees) throws IOException {
 235         printExprs(trees, ", ");
 236     }
 237 
 238 
 239     /** Derived visitor method: print pattern.
 240      */
 241 
 242     public void printPattern(JCTree tree) throws IOException {
 243         printExpr(tree);
 244     }
 245 
 246     /** Derived visitor method: print list of statements, each on a separate line.
 247      */
 248     public void printStats(List<? extends JCTree> trees) throws IOException {
 249         for (List<? extends JCTree> l = trees; l.nonEmpty(); l = l.tail) {
 250             align();
 251             printStat(l.head);
 252             println();
 253         }
 254     }
 255 
 256     /** Print a set of modifiers.
 257      */
 258     public void printFlags(long flags) throws IOException {
 259         if ((flags & SYNTHETIC) != 0) print("/*synthetic*/ ");
 260         print(TreeInfo.flagNames(flags));
 261         if ((flags & ExtendedStandardFlags) != 0) print(" ");
 262         if ((flags & ANNOTATION) != 0) print("@");
 263     }
 264 
 265     public void printAnnotations(List<JCAnnotation> trees) throws IOException {


 869     public void visitSwitchExpression(JCSwitchExpression tree) {
 870         try {
 871             print("switch ");
 872             if (tree.selector.hasTag(PARENS)) {
 873                 printExpr(tree.selector);
 874             } else {
 875                 print("(");
 876                 printExpr(tree.selector);
 877                 print(")");
 878             }
 879             print(" {");
 880             println();
 881             printStats(tree.cases);
 882             align();
 883             print("}");
 884         } catch (IOException e) {
 885             throw new UncheckedIOException(e);
 886         }
 887     }
 888 
 889     public void visitBindingPattern(JCBindingPattern patt) {
 890         try {
 891             if (patt.vartype == null) {
 892                 print("var ");
 893                 print(patt.name);
 894             } else {
 895                 printExpr(patt.vartype);
 896                 print(" ");
 897                 print(patt.name);
 898             }
 899         } catch (IOException e) {
 900             throw new UncheckedIOException(e);
 901         }
 902     }
 903 
 904     public void visitSynchronized(JCSynchronized tree) {
 905         try {
 906             print("synchronized ");
 907             if (tree.lock.hasTag(PARENS)) {
 908                 printExpr(tree.lock);
 909             } else {
 910                 print("(");
 911                 printExpr(tree.lock);
 912                 print(")");
 913             }
 914             print(" ");
 915             printStat(tree.body);
 916         } catch (IOException e) {
 917             throw new UncheckedIOException(e);
 918         }
 919     }
 920 
 921     public void visitTry(JCTry tree) {
 922         try {
 923             print("try ");


1290     }
1291 
1292     public void visitTypeCast(JCTypeCast tree) {
1293         try {
1294             open(prec, TreeInfo.prefixPrec);
1295             print("(");
1296             printExpr(tree.clazz);
1297             print(")");
1298             printExpr(tree.expr, TreeInfo.prefixPrec);
1299             close(prec, TreeInfo.prefixPrec);
1300         } catch (IOException e) {
1301             throw new UncheckedIOException(e);
1302         }
1303     }
1304 
1305     public void visitTypeTest(JCInstanceOf tree) {
1306         try {
1307             open(prec, TreeInfo.ordPrec);
1308             printExpr(tree.expr, TreeInfo.ordPrec);
1309             print(" instanceof ");
1310             if (tree.pattern instanceof JCPattern) {
1311                 printPattern(tree.pattern);
1312             } else {
1313                 printExpr(tree.getType(), TreeInfo.ordPrec + 1);
1314             }
1315             close(prec, TreeInfo.ordPrec);
1316         } catch (IOException e) {
1317             throw new UncheckedIOException(e);
1318         }
1319     }
1320 
1321     public void visitIndexed(JCArrayAccess tree) {
1322         try {
1323             printExpr(tree.indexed, TreeInfo.postfixPrec);
1324             print("[");
1325             printExpr(tree.index);
1326             print("]");
1327         } catch (IOException e) {
1328             throw new UncheckedIOException(e);
1329         }
1330     }
1331 
1332     public void visitSelect(JCFieldAccess tree) {
1333         try {
1334             printExpr(tree.selected, TreeInfo.postfixPrec);


< prev index next >