< prev index next >

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

Print this page




 746         }
 747     }
 748 
 749     public void visitWhileLoop(JCWhileLoop tree) {
 750         try {
 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             printStat(tree.body);
 761         } catch (IOException e) {
 762             throw new UncheckedIOException(e);
 763         }
 764     }
 765 












 766     public void visitForLoop(JCForLoop tree) {
 767         try {
 768             print("for (");
 769             if (tree.init.nonEmpty()) {
 770                 if (tree.init.head.hasTag(VARDEF)) {
 771                     printExpr(tree.init.head);
 772                     for (List<JCStatement> l = tree.init.tail; l.nonEmpty(); l = l.tail) {
 773                         JCVariableDecl vdef = (JCVariableDecl)l.head;
 774                         print(", " + vdef.name);
 775                         if (vdef.init != null) {
 776                             print(" = ");
 777                             printExpr(vdef.init);
 778                         }
 779                     }
 780                 } else {
 781                     printExprs(tree.init);
 782                 }
 783             }
 784             print("; ");
 785             if (tree.cond != null) printExpr(tree.cond);


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);
1308             print("." + tree.name);


1309         } catch (IOException e) {
1310             throw new UncheckedIOException(e);
1311         }
1312     }
1313 
1314     public void visitReference(JCMemberReference tree) {
1315         try {
1316             printExpr(tree.expr);
1317             print("::");
1318             if (tree.typeargs != null) {
1319                 print("<");
1320                 printExprs(tree.typeargs);
1321                 print(">");
1322             }
1323             print(tree.getMode() == ReferenceMode.INVOKE ? tree.name : "new");
1324         } catch (IOException e) {
1325             throw new UncheckedIOException(e);
1326         }
1327     }
1328 
1329     public void visitIdent(JCIdent tree) {
1330         try {
1331             print(tree.name);


1332         } catch (IOException e) {
1333             throw new UncheckedIOException(e);
1334         }
1335     }
1336 
1337     public void visitLiteral(JCLiteral tree) {
1338         try {
1339             switch (tree.typetag) {
1340                 case INT:
1341                     print(tree.value.toString());
1342                     break;
1343                 case LONG:
1344                     print(tree.value + "L");
1345                     break;
1346                 case FLOAT:
1347                     print(tree.value + "F");
1348                     break;
1349                 case DOUBLE:
1350                     print(tree.value.toString());
1351                     break;


1434                 if (elem.hasTag(TYPEARRAY)) {
1435                     print(' ');
1436                     printTypeAnnotations(atype.annotations);
1437                 }
1438             }
1439             if (elem.hasTag(TYPEARRAY)) {
1440                 print("[]");
1441                 elem = ((JCArrayTypeTree)elem).elemtype;
1442             } else {
1443                 break;
1444             }
1445         }
1446     }
1447 
1448     public void visitTypeApply(JCTypeApply tree) {
1449         try {
1450             printExpr(tree.clazz);
1451             print("<");
1452             printExprs(tree.arguments);
1453             print(">");


1454         } catch (IOException e) {
1455             throw new UncheckedIOException(e);
1456         }
1457     }
1458 
1459     public void visitTypeUnion(JCTypeUnion tree) {
1460         try {
1461             printExprs(tree.alternatives, " | ");
1462         } catch (IOException e) {
1463             throw new UncheckedIOException(e);
1464         }
1465     }
1466 
1467     public void visitTypeIntersection(JCTypeIntersection tree) {
1468         try {
1469             printExprs(tree.bounds, " & ");
1470         } catch (IOException e) {
1471             throw new UncheckedIOException(e);
1472         }
1473     }




 746         }
 747     }
 748 
 749     public void visitWhileLoop(JCWhileLoop tree) {
 750         try {
 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             printStat(tree.body);
 761         } catch (IOException e) {
 762             throw new UncheckedIOException(e);
 763         }
 764     }
 765 
 766     public void visitWithField(JCWithField tree) {
 767         try {
 768             print("__WithField(");
 769             printExpr(tree.field);
 770             print(", ");
 771             printExpr(tree.value);
 772             print(")");
 773         } catch (IOException e) {
 774             throw new UncheckedIOException(e);
 775         }
 776     }
 777 
 778     public void visitForLoop(JCForLoop tree) {
 779         try {
 780             print("for (");
 781             if (tree.init.nonEmpty()) {
 782                 if (tree.init.head.hasTag(VARDEF)) {
 783                     printExpr(tree.init.head);
 784                     for (List<JCStatement> l = tree.init.tail; l.nonEmpty(); l = l.tail) {
 785                         JCVariableDecl vdef = (JCVariableDecl)l.head;
 786                         print(", " + vdef.name);
 787                         if (vdef.init != null) {
 788                             print(" = ");
 789                             printExpr(vdef.init);
 790                         }
 791                     }
 792                 } else {
 793                     printExprs(tree.init);
 794                 }
 795             }
 796             print("; ");
 797             if (tree.cond != null) printExpr(tree.cond);


1301         } catch (IOException e) {
1302             throw new UncheckedIOException(e);
1303         }
1304     }
1305 
1306     public void visitIndexed(JCArrayAccess tree) {
1307         try {
1308             printExpr(tree.indexed, TreeInfo.postfixPrec);
1309             print("[");
1310             printExpr(tree.index);
1311             print("]");
1312         } catch (IOException e) {
1313             throw new UncheckedIOException(e);
1314         }
1315     }
1316 
1317     public void visitSelect(JCFieldAccess tree) {
1318         try {
1319             printExpr(tree.selected, TreeInfo.postfixPrec);
1320             print("." + tree.name);
1321             if (tree.isQuestioned())
1322                 print('?');
1323         } catch (IOException e) {
1324             throw new UncheckedIOException(e);
1325         }
1326     }
1327 
1328     public void visitReference(JCMemberReference tree) {
1329         try {
1330             printExpr(tree.expr);
1331             print("::");
1332             if (tree.typeargs != null) {
1333                 print("<");
1334                 printExprs(tree.typeargs);
1335                 print(">");
1336             }
1337             print(tree.getMode() == ReferenceMode.INVOKE ? tree.name : "new");
1338         } catch (IOException e) {
1339             throw new UncheckedIOException(e);
1340         }
1341     }
1342 
1343     public void visitIdent(JCIdent tree) {
1344         try {
1345             print(tree.name);
1346             if (tree.isQuestioned())
1347                 print('?');
1348         } catch (IOException e) {
1349             throw new UncheckedIOException(e);
1350         }
1351     }
1352 
1353     public void visitLiteral(JCLiteral tree) {
1354         try {
1355             switch (tree.typetag) {
1356                 case INT:
1357                     print(tree.value.toString());
1358                     break;
1359                 case LONG:
1360                     print(tree.value + "L");
1361                     break;
1362                 case FLOAT:
1363                     print(tree.value + "F");
1364                     break;
1365                 case DOUBLE:
1366                     print(tree.value.toString());
1367                     break;


1450                 if (elem.hasTag(TYPEARRAY)) {
1451                     print(' ');
1452                     printTypeAnnotations(atype.annotations);
1453                 }
1454             }
1455             if (elem.hasTag(TYPEARRAY)) {
1456                 print("[]");
1457                 elem = ((JCArrayTypeTree)elem).elemtype;
1458             } else {
1459                 break;
1460             }
1461         }
1462     }
1463 
1464     public void visitTypeApply(JCTypeApply tree) {
1465         try {
1466             printExpr(tree.clazz);
1467             print("<");
1468             printExprs(tree.arguments);
1469             print(">");
1470             if (tree.isQuestioned())
1471                 print('?');
1472         } catch (IOException e) {
1473             throw new UncheckedIOException(e);
1474         }
1475     }
1476 
1477     public void visitTypeUnion(JCTypeUnion tree) {
1478         try {
1479             printExprs(tree.alternatives, " | ");
1480         } catch (IOException e) {
1481             throw new UncheckedIOException(e);
1482         }
1483     }
1484 
1485     public void visitTypeIntersection(JCTypeIntersection tree) {
1486         try {
1487             printExprs(tree.bounds, " & ");
1488         } catch (IOException e) {
1489             throw new UncheckedIOException(e);
1490         }
1491     }


< prev index next >