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

changeset 1570
f91144b7da75
parent 1521
71f35e4b93a5
child 1755
ddb4a2bfcd82
     1.1 --- a/src/share/classes/com/sun/tools/javac/tree/Pretty.java	Mon Jan 21 01:27:42 2013 -0500
     1.2 +++ b/src/share/classes/com/sun/tools/javac/tree/Pretty.java	Mon Feb 04 18:08:53 2013 -0500
     1.3 @@ -29,7 +29,6 @@
     1.4  
     1.5  import com.sun.source.tree.MemberReferenceTree.ReferenceMode;
     1.6  import com.sun.tools.javac.code.*;
     1.7 -import com.sun.tools.javac.code.Symbol.*;
     1.8  import com.sun.tools.javac.tree.JCTree.*;
     1.9  import com.sun.tools.javac.util.*;
    1.10  import com.sun.tools.javac.util.List;
    1.11 @@ -261,6 +260,15 @@
    1.12          }
    1.13      }
    1.14  
    1.15 +    public void printTypeAnnotations(List<JCAnnotation> trees) throws IOException {
    1.16 +        if (trees.nonEmpty())
    1.17 +            print(" ");
    1.18 +        for (List<JCAnnotation> l = trees; l.nonEmpty(); l = l.tail) {
    1.19 +            printExpr(l.head);
    1.20 +            print(" ");
    1.21 +        }
    1.22 +    }
    1.23 +
    1.24      /** Print documentation comment, if it exists
    1.25       *  @param tree    The tree for which a documentation comment should be printed.
    1.26       */
    1.27 @@ -491,6 +499,12 @@
    1.28                  print(" " + tree.name);
    1.29              }
    1.30              print("(");
    1.31 +            if (tree.recvparam!=null) {
    1.32 +                printExpr(tree.recvparam);
    1.33 +                if (tree.params.size() > 0) {
    1.34 +                    print(", ");
    1.35 +                }
    1.36 +            }
    1.37              printExprs(tree.params);
    1.38              print(")");
    1.39              if (tree.thrown.nonEmpty()) {
    1.40 @@ -543,7 +557,15 @@
    1.41              } else {
    1.42                  printExpr(tree.mods);
    1.43                  if ((tree.mods.flags & VARARGS) != 0) {
    1.44 -                    printExpr(((JCArrayTypeTree) tree.vartype).elemtype);
    1.45 +                    JCTree vartype = tree.vartype;
    1.46 +                    List<JCAnnotation> tas = null;
    1.47 +                    if (vartype instanceof JCAnnotatedType) {
    1.48 +                        tas = ((JCAnnotatedType)vartype).annotations;
    1.49 +                        vartype = ((JCAnnotatedType)vartype).underlyingType;
    1.50 +                    }
    1.51 +                    printExpr(((JCArrayTypeTree) vartype).elemtype);
    1.52 +                    if (tas != null)
    1.53 +                        printTypeAnnotations(tas);
    1.54                      print("... " + tree.name);
    1.55                  } else {
    1.56                      printExpr(tree.vartype);
    1.57 @@ -919,16 +941,29 @@
    1.58          try {
    1.59              if (tree.elemtype != null) {
    1.60                  print("new ");
    1.61 +                printTypeAnnotations(tree.annotations);
    1.62                  JCTree elem = tree.elemtype;
    1.63 -                if (elem.hasTag(TYPEARRAY))
    1.64 -                    printBaseElementType((JCArrayTypeTree) elem);
    1.65 -                else
    1.66 -                    printExpr(elem);
    1.67 +                printBaseElementType(elem);
    1.68 +                boolean isElemAnnoType = elem instanceof JCAnnotatedType;
    1.69 +                int i = 0;
    1.70 +                List<List<JCAnnotation>> da = tree.dimAnnotations;
    1.71                  for (List<JCExpression> l = tree.dims; l.nonEmpty(); l = l.tail) {
    1.72 +                    if (da.size() > i) {
    1.73 +                        printTypeAnnotations(da.get(i));
    1.74 +                    }
    1.75                      print("[");
    1.76 +                    i++;
    1.77                      printExpr(l.head);
    1.78                      print("]");
    1.79                  }
    1.80 +                if (tree.elems != null) {
    1.81 +                    if (isElemAnnoType) {
    1.82 +                        printTypeAnnotations(((JCAnnotatedType)tree.elemtype).annotations);
    1.83 +                    }
    1.84 +                    print("[]");
    1.85 +                }
    1.86 +                if (isElemAnnoType)
    1.87 +                    elem = ((JCAnnotatedType)elem).underlyingType;
    1.88                  if (elem instanceof JCArrayTypeTree)
    1.89                      printBrackets((JCArrayTypeTree) elem);
    1.90              }
    1.91 @@ -946,7 +981,7 @@
    1.92      public void visitLambda(JCLambda tree) {
    1.93          try {
    1.94              print("(");
    1.95 -            if (TreeInfo.isExplicitLambda(tree)) {
    1.96 +            if (tree.paramKind == JCLambda.ParameterKind.EXPLICIT) {
    1.97                  printExprs(tree.params);
    1.98              } else {
    1.99                  String sep = "";
   1.100 @@ -1225,6 +1260,12 @@
   1.101          JCTree elem;
   1.102          while (true) {
   1.103              elem = tree.elemtype;
   1.104 +            if (elem.hasTag(ANNOTATED_TYPE)) {
   1.105 +                JCAnnotatedType atype = (JCAnnotatedType) elem;
   1.106 +                elem = atype.underlyingType;
   1.107 +                if (!elem.hasTag(TYPEARRAY)) break;
   1.108 +                printTypeAnnotations(atype.annotations);
   1.109 +            }
   1.110              print("[]");
   1.111              if (!elem.hasTag(TYPEARRAY)) break;
   1.112              tree = (JCArrayTypeTree) elem;
   1.113 @@ -1327,6 +1368,32 @@
   1.114          }
   1.115      }
   1.116  
   1.117 +    public void visitAnnotatedType(JCAnnotatedType tree) {
   1.118 +        try {
   1.119 +            if (tree.underlyingType.getKind() == JCTree.Kind.MEMBER_SELECT) {
   1.120 +                JCFieldAccess access = (JCFieldAccess) tree.underlyingType;
   1.121 +                printExpr(access.selected, TreeInfo.postfixPrec);
   1.122 +                print(".");
   1.123 +                printTypeAnnotations(tree.annotations);
   1.124 +                print(access.name);
   1.125 +            } else if (tree.underlyingType.getKind() == JCTree.Kind.ARRAY_TYPE) {
   1.126 +                JCArrayTypeTree array = (JCArrayTypeTree) tree.underlyingType;
   1.127 +                printBaseElementType(tree);
   1.128 +                printTypeAnnotations(tree.annotations);
   1.129 +                print("[]");
   1.130 +                JCExpression elem = array.elemtype;
   1.131 +                if (elem.hasTag(TYPEARRAY)) {
   1.132 +                    printBrackets((JCArrayTypeTree) elem);
   1.133 +                }
   1.134 +            } else {
   1.135 +                printTypeAnnotations(tree.annotations);
   1.136 +                printExpr(tree.underlyingType);
   1.137 +            }
   1.138 +        } catch (IOException e) {
   1.139 +            throw new UncheckedIOException(e);
   1.140 +        }
   1.141 +    }
   1.142 +
   1.143      public void visitTree(JCTree tree) {
   1.144          try {
   1.145              print("(UNKNOWN: " + tree + ")");

mercurial