27 |
27 |
28 import java.io.*; |
28 import java.io.*; |
29 |
29 |
30 import com.sun.source.tree.MemberReferenceTree.ReferenceMode; |
30 import com.sun.source.tree.MemberReferenceTree.ReferenceMode; |
31 import com.sun.tools.javac.code.*; |
31 import com.sun.tools.javac.code.*; |
32 import com.sun.tools.javac.code.Symbol.*; |
|
33 import com.sun.tools.javac.tree.JCTree.*; |
32 import com.sun.tools.javac.tree.JCTree.*; |
34 import com.sun.tools.javac.util.*; |
33 import com.sun.tools.javac.util.*; |
35 import com.sun.tools.javac.util.List; |
34 import com.sun.tools.javac.util.List; |
36 import static com.sun.tools.javac.code.Flags.*; |
35 import static com.sun.tools.javac.code.Flags.*; |
37 import static com.sun.tools.javac.code.Flags.ANNOTATION; |
36 import static com.sun.tools.javac.code.Flags.ANNOTATION; |
256 public void printAnnotations(List<JCAnnotation> trees) throws IOException { |
255 public void printAnnotations(List<JCAnnotation> trees) throws IOException { |
257 for (List<JCAnnotation> l = trees; l.nonEmpty(); l = l.tail) { |
256 for (List<JCAnnotation> l = trees; l.nonEmpty(); l = l.tail) { |
258 printStat(l.head); |
257 printStat(l.head); |
259 println(); |
258 println(); |
260 align(); |
259 align(); |
|
260 } |
|
261 } |
|
262 |
|
263 public void printTypeAnnotations(List<JCAnnotation> trees) throws IOException { |
|
264 if (trees.nonEmpty()) |
|
265 print(" "); |
|
266 for (List<JCAnnotation> l = trees; l.nonEmpty(); l = l.tail) { |
|
267 printExpr(l.head); |
|
268 print(" "); |
261 } |
269 } |
262 } |
270 } |
263 |
271 |
264 /** Print documentation comment, if it exists |
272 /** Print documentation comment, if it exists |
265 * @param tree The tree for which a documentation comment should be printed. |
273 * @param tree The tree for which a documentation comment should be printed. |
489 } else { |
497 } else { |
490 printExpr(tree.restype); |
498 printExpr(tree.restype); |
491 print(" " + tree.name); |
499 print(" " + tree.name); |
492 } |
500 } |
493 print("("); |
501 print("("); |
|
502 if (tree.recvparam!=null) { |
|
503 printExpr(tree.recvparam); |
|
504 if (tree.params.size() > 0) { |
|
505 print(", "); |
|
506 } |
|
507 } |
494 printExprs(tree.params); |
508 printExprs(tree.params); |
495 print(")"); |
509 print(")"); |
496 if (tree.thrown.nonEmpty()) { |
510 if (tree.thrown.nonEmpty()) { |
497 print(" throws "); |
511 print(" throws "); |
498 printExprs(tree.thrown); |
512 printExprs(tree.thrown); |
541 print(" */"); |
555 print(" */"); |
542 } |
556 } |
543 } else { |
557 } else { |
544 printExpr(tree.mods); |
558 printExpr(tree.mods); |
545 if ((tree.mods.flags & VARARGS) != 0) { |
559 if ((tree.mods.flags & VARARGS) != 0) { |
546 printExpr(((JCArrayTypeTree) tree.vartype).elemtype); |
560 JCTree vartype = tree.vartype; |
|
561 List<JCAnnotation> tas = null; |
|
562 if (vartype instanceof JCAnnotatedType) { |
|
563 tas = ((JCAnnotatedType)vartype).annotations; |
|
564 vartype = ((JCAnnotatedType)vartype).underlyingType; |
|
565 } |
|
566 printExpr(((JCArrayTypeTree) vartype).elemtype); |
|
567 if (tas != null) |
|
568 printTypeAnnotations(tas); |
547 print("... " + tree.name); |
569 print("... " + tree.name); |
548 } else { |
570 } else { |
549 printExpr(tree.vartype); |
571 printExpr(tree.vartype); |
550 print(" " + tree.name); |
572 print(" " + tree.name); |
551 } |
573 } |
917 |
939 |
918 public void visitNewArray(JCNewArray tree) { |
940 public void visitNewArray(JCNewArray tree) { |
919 try { |
941 try { |
920 if (tree.elemtype != null) { |
942 if (tree.elemtype != null) { |
921 print("new "); |
943 print("new "); |
|
944 printTypeAnnotations(tree.annotations); |
922 JCTree elem = tree.elemtype; |
945 JCTree elem = tree.elemtype; |
923 if (elem.hasTag(TYPEARRAY)) |
946 printBaseElementType(elem); |
924 printBaseElementType((JCArrayTypeTree) elem); |
947 boolean isElemAnnoType = elem instanceof JCAnnotatedType; |
925 else |
948 int i = 0; |
926 printExpr(elem); |
949 List<List<JCAnnotation>> da = tree.dimAnnotations; |
927 for (List<JCExpression> l = tree.dims; l.nonEmpty(); l = l.tail) { |
950 for (List<JCExpression> l = tree.dims; l.nonEmpty(); l = l.tail) { |
|
951 if (da.size() > i) { |
|
952 printTypeAnnotations(da.get(i)); |
|
953 } |
928 print("["); |
954 print("["); |
|
955 i++; |
929 printExpr(l.head); |
956 printExpr(l.head); |
930 print("]"); |
957 print("]"); |
931 } |
958 } |
|
959 if (tree.elems != null) { |
|
960 if (isElemAnnoType) { |
|
961 printTypeAnnotations(((JCAnnotatedType)tree.elemtype).annotations); |
|
962 } |
|
963 print("[]"); |
|
964 } |
|
965 if (isElemAnnoType) |
|
966 elem = ((JCAnnotatedType)elem).underlyingType; |
932 if (elem instanceof JCArrayTypeTree) |
967 if (elem instanceof JCArrayTypeTree) |
933 printBrackets((JCArrayTypeTree) elem); |
968 printBrackets((JCArrayTypeTree) elem); |
934 } |
969 } |
935 if (tree.elems != null) { |
970 if (tree.elems != null) { |
936 if (tree.elemtype != null) print("[]"); |
971 if (tree.elemtype != null) print("[]"); |
1223 // prints the brackets of a nested array in reverse order |
1258 // prints the brackets of a nested array in reverse order |
1224 private void printBrackets(JCArrayTypeTree tree) throws IOException { |
1259 private void printBrackets(JCArrayTypeTree tree) throws IOException { |
1225 JCTree elem; |
1260 JCTree elem; |
1226 while (true) { |
1261 while (true) { |
1227 elem = tree.elemtype; |
1262 elem = tree.elemtype; |
|
1263 if (elem.hasTag(ANNOTATED_TYPE)) { |
|
1264 JCAnnotatedType atype = (JCAnnotatedType) elem; |
|
1265 elem = atype.underlyingType; |
|
1266 if (!elem.hasTag(TYPEARRAY)) break; |
|
1267 printTypeAnnotations(atype.annotations); |
|
1268 } |
1228 print("[]"); |
1269 print("[]"); |
1229 if (!elem.hasTag(TYPEARRAY)) break; |
1270 if (!elem.hasTag(TYPEARRAY)) break; |
1230 tree = (JCArrayTypeTree) elem; |
1271 tree = (JCArrayTypeTree) elem; |
1231 } |
1272 } |
1232 } |
1273 } |
1325 } catch (IOException e) { |
1366 } catch (IOException e) { |
1326 throw new UncheckedIOException(e); |
1367 throw new UncheckedIOException(e); |
1327 } |
1368 } |
1328 } |
1369 } |
1329 |
1370 |
|
1371 public void visitAnnotatedType(JCAnnotatedType tree) { |
|
1372 try { |
|
1373 if (tree.underlyingType.getKind() == JCTree.Kind.MEMBER_SELECT) { |
|
1374 JCFieldAccess access = (JCFieldAccess) tree.underlyingType; |
|
1375 printExpr(access.selected, TreeInfo.postfixPrec); |
|
1376 print("."); |
|
1377 printTypeAnnotations(tree.annotations); |
|
1378 print(access.name); |
|
1379 } else if (tree.underlyingType.getKind() == JCTree.Kind.ARRAY_TYPE) { |
|
1380 JCArrayTypeTree array = (JCArrayTypeTree) tree.underlyingType; |
|
1381 printBaseElementType(tree); |
|
1382 printTypeAnnotations(tree.annotations); |
|
1383 print("[]"); |
|
1384 JCExpression elem = array.elemtype; |
|
1385 if (elem.hasTag(TYPEARRAY)) { |
|
1386 printBrackets((JCArrayTypeTree) elem); |
|
1387 } |
|
1388 } else { |
|
1389 printTypeAnnotations(tree.annotations); |
|
1390 printExpr(tree.underlyingType); |
|
1391 } |
|
1392 } catch (IOException e) { |
|
1393 throw new UncheckedIOException(e); |
|
1394 } |
|
1395 } |
|
1396 |
1330 public void visitTree(JCTree tree) { |
1397 public void visitTree(JCTree tree) { |
1331 try { |
1398 try { |
1332 print("(UNKNOWN: " + tree + ")"); |
1399 print("(UNKNOWN: " + tree + ")"); |
1333 println(); |
1400 println(); |
1334 } catch (IOException e) { |
1401 } catch (IOException e) { |