langtools/src/share/classes/com/sun/tools/javac/tree/Pretty.java
changeset 19651 b1aa46cc2198
parent 19246 4c6990756cd3
child 21004 dc81ffd21bd3
equal deleted inserted replaced
19512:07dcf1232608 19651:b1aa46cc2198
   942 
   942 
   943     public void visitNewArray(JCNewArray tree) {
   943     public void visitNewArray(JCNewArray tree) {
   944         try {
   944         try {
   945             if (tree.elemtype != null) {
   945             if (tree.elemtype != null) {
   946                 print("new ");
   946                 print("new ");
   947                 printTypeAnnotations(tree.annotations);
       
   948                 JCTree elem = tree.elemtype;
   947                 JCTree elem = tree.elemtype;
   949                 printBaseElementType(elem);
   948                 printBaseElementType(elem);
   950                 boolean isElemAnnoType = elem instanceof JCAnnotatedType;
   949 
       
   950                 if (!tree.annotations.isEmpty()) {
       
   951                     print(' ');
       
   952                     printTypeAnnotations(tree.annotations);
       
   953                 }
       
   954                 if (tree.elems != null) {
       
   955                     print("[]");
       
   956                 }
       
   957 
   951                 int i = 0;
   958                 int i = 0;
   952                 List<List<JCAnnotation>> da = tree.dimAnnotations;
   959                 List<List<JCAnnotation>> da = tree.dimAnnotations;
   953                 for (List<JCExpression> l = tree.dims; l.nonEmpty(); l = l.tail) {
   960                 for (List<JCExpression> l = tree.dims; l.nonEmpty(); l = l.tail) {
   954                     if (da.size() > i && !da.get(i).isEmpty()) {
   961                     if (da.size() > i && !da.get(i).isEmpty()) {
   955                         print(' ');
   962                         print(' ');
   958                     print("[");
   965                     print("[");
   959                     i++;
   966                     i++;
   960                     printExpr(l.head);
   967                     printExpr(l.head);
   961                     print("]");
   968                     print("]");
   962                 }
   969                 }
   963                 if (tree.elems != null) {
   970                 printBrackets(elem);
   964                     if (isElemAnnoType) {
       
   965                         print(' ');
       
   966                         printTypeAnnotations(((JCAnnotatedType)tree.elemtype).annotations);
       
   967                     }
       
   968                     print("[]");
       
   969                 }
       
   970                 if (isElemAnnoType)
       
   971                     elem = ((JCAnnotatedType)elem).underlyingType;
       
   972                 if (elem instanceof JCArrayTypeTree)
       
   973                     printBrackets((JCArrayTypeTree) elem);
       
   974             }
   971             }
   975             if (tree.elems != null) {
   972             if (tree.elems != null) {
   976                 print("{");
   973                 print("{");
   977                 printExprs(tree.elems);
   974                 printExprs(tree.elems);
   978                 print("}");
   975                 print("}");
  1258     private void printBaseElementType(JCTree tree) throws IOException {
  1255     private void printBaseElementType(JCTree tree) throws IOException {
  1259         printExpr(TreeInfo.innermostType(tree));
  1256         printExpr(TreeInfo.innermostType(tree));
  1260     }
  1257     }
  1261 
  1258 
  1262     // prints the brackets of a nested array in reverse order
  1259     // prints the brackets of a nested array in reverse order
  1263     private void printBrackets(JCArrayTypeTree tree) throws IOException {
  1260     // tree is either JCArrayTypeTree or JCAnnotatedTypeTree
  1264         JCTree elem;
  1261     private void printBrackets(JCTree tree) throws IOException {
       
  1262         JCTree elem = tree;
  1265         while (true) {
  1263         while (true) {
  1266             elem = tree.elemtype;
       
  1267             if (elem.hasTag(ANNOTATED_TYPE)) {
  1264             if (elem.hasTag(ANNOTATED_TYPE)) {
  1268                 JCAnnotatedType atype = (JCAnnotatedType) elem;
  1265                 JCAnnotatedType atype = (JCAnnotatedType) elem;
  1269                 elem = atype.underlyingType;
  1266                 elem = atype.underlyingType;
  1270                 if (!elem.hasTag(TYPEARRAY)) break;
  1267                 if (elem.hasTag(TYPEARRAY)) {
  1271                 print(' ');
  1268                     print(' ');
  1272                 printTypeAnnotations(atype.annotations);
  1269                     printTypeAnnotations(atype.annotations);
  1273             }
  1270                 }
  1274             print("[]");
  1271             }
  1275             if (!elem.hasTag(TYPEARRAY)) break;
  1272             if (elem.hasTag(TYPEARRAY)) {
  1276             tree = (JCArrayTypeTree) elem;
  1273                 print("[]");
       
  1274                 elem = ((JCArrayTypeTree)elem).elemtype;
       
  1275             } else {
       
  1276                 break;
       
  1277             }
  1277         }
  1278         }
  1278     }
  1279     }
  1279 
  1280 
  1280     public void visitTypeApply(JCTypeApply tree) {
  1281     public void visitTypeApply(JCTypeApply tree) {
  1281         try {
  1282         try {
  1376         }
  1377         }
  1377     }
  1378     }
  1378 
  1379 
  1379     public void visitAnnotatedType(JCAnnotatedType tree) {
  1380     public void visitAnnotatedType(JCAnnotatedType tree) {
  1380         try {
  1381         try {
  1381             if (tree.underlyingType.getKind() == JCTree.Kind.MEMBER_SELECT) {
  1382             if (tree.underlyingType.hasTag(SELECT)) {
  1382                 JCFieldAccess access = (JCFieldAccess) tree.underlyingType;
  1383                 JCFieldAccess access = (JCFieldAccess) tree.underlyingType;
  1383                 printExpr(access.selected, TreeInfo.postfixPrec);
  1384                 printExpr(access.selected, TreeInfo.postfixPrec);
  1384                 print(".");
  1385                 print(".");
  1385                 printTypeAnnotations(tree.annotations);
  1386                 printTypeAnnotations(tree.annotations);
  1386                 print(access.name);
  1387                 print(access.name);
  1387             } else if (tree.underlyingType.getKind() == JCTree.Kind.ARRAY_TYPE) {
  1388             } else if (tree.underlyingType.hasTag(TYPEARRAY)) {
  1388                 JCArrayTypeTree array = (JCArrayTypeTree) tree.underlyingType;
       
  1389                 printBaseElementType(tree);
  1389                 printBaseElementType(tree);
  1390                 print(' ');
  1390                 printBrackets(tree);
  1391                 printTypeAnnotations(tree.annotations);
       
  1392                 print("[]");
       
  1393                 JCExpression elem = array.elemtype;
       
  1394                 if (elem.hasTag(TYPEARRAY)) {
       
  1395                     printBrackets((JCArrayTypeTree) elem);
       
  1396                 }
       
  1397             } else {
  1391             } else {
  1398                 printTypeAnnotations(tree.annotations);
  1392                 printTypeAnnotations(tree.annotations);
  1399                 printExpr(tree.underlyingType);
  1393                 printExpr(tree.underlyingType);
  1400             }
  1394             }
  1401         } catch (IOException e) {
  1395         } catch (IOException e) {