langtools/src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java
changeset 20249 93f8eae31092
parent 19651 b1aa46cc2198
child 20258 bdaa691b4da4
equal deleted inserted replaced
20248:0c72984b7a4d 20249:93f8eae31092
   231 
   231 
   232         /*
   232         /*
   233          * When traversing the AST we keep the "frames" of visited
   233          * When traversing the AST we keep the "frames" of visited
   234          * trees in order to determine the position of annotations.
   234          * trees in order to determine the position of annotations.
   235          */
   235          */
   236         private ListBuffer<JCTree> frames = ListBuffer.lb();
   236         private ListBuffer<JCTree> frames = new ListBuffer<>();
   237 
   237 
   238         protected void push(JCTree t) { frames = frames.prepend(t); }
   238         protected void push(JCTree t) { frames = frames.prepend(t); }
   239         protected JCTree pop() { return frames.next(); }
   239         protected JCTree pop() { return frames.next(); }
   240         // could this be frames.elems.tail.head?
   240         // could this be frames.elems.tail.head?
   241         private JCTree peek2() { return frames.toList().tail.head; }
   241         private JCTree peek2() { return frames.toList().tail.head; }
   379                         toreturn = tomodify;
   379                         toreturn = tomodify;
   380                     }
   380                     }
   381                 }
   381                 }
   382                 JCArrayTypeTree arTree = arrayTypeTree(typetree);
   382                 JCArrayTypeTree arTree = arrayTypeTree(typetree);
   383 
   383 
   384                 ListBuffer<TypePathEntry> depth = ListBuffer.lb();
   384                 ListBuffer<TypePathEntry> depth = new ListBuffer<>();
   385                 depth = depth.append(TypePathEntry.ARRAY);
   385                 depth = depth.append(TypePathEntry.ARRAY);
   386                 while (arType.elemtype.hasTag(TypeTag.ARRAY)) {
   386                 while (arType.elemtype.hasTag(TypeTag.ARRAY)) {
   387                     if (arType.elemtype.isAnnotated()) {
   387                     if (arType.elemtype.isAnnotated()) {
   388                         Type.AnnotatedType aelemtype = (Type.AnnotatedType) arType.elemtype;
   388                         Type.AnnotatedType aelemtype = (Type.AnnotatedType) arType.elemtype;
   389                         Type.AnnotatedType newAT = new Type.AnnotatedType(aelemtype.underlyingType);
   389                         Type.AnnotatedType newAT = new Type.AnnotatedType(aelemtype.underlyingType);
   471                 // type that is written in the source code.
   471                 // type that is written in the source code.
   472                 // Now count from here to the actual top-level class to determine
   472                 // Now count from here to the actual top-level class to determine
   473                 // the correct nesting.
   473                 // the correct nesting.
   474 
   474 
   475                 // The genericLocation for the annotation.
   475                 // The genericLocation for the annotation.
   476                 ListBuffer<TypePathEntry> depth = ListBuffer.lb();
   476                 ListBuffer<TypePathEntry> depth = new ListBuffer<>();
   477 
   477 
   478                 Type topTy = enclTy;
   478                 Type topTy = enclTy;
   479                 while (enclEl != null &&
   479                 while (enclEl != null &&
   480                         enclEl.getKind() != ElementKind.PACKAGE &&
   480                         enclEl.getKind() != ElementKind.PACKAGE &&
   481                         topTy != null &&
   481                         topTy != null &&
   791                     }
   791                     }
   792                     return;
   792                     return;
   793                 }
   793                 }
   794 
   794 
   795                 case ARRAY_TYPE: {
   795                 case ARRAY_TYPE: {
   796                     ListBuffer<TypePathEntry> index = ListBuffer.lb();
   796                     ListBuffer<TypePathEntry> index = new ListBuffer<>();
   797                     index = index.append(TypePathEntry.ARRAY);
   797                     index = index.append(TypePathEntry.ARRAY);
   798                     List<JCTree> newPath = path.tail;
   798                     List<JCTree> newPath = path.tail;
   799                     while (true) {
   799                     while (true) {
   800                         JCTree npHead = newPath.tail.head;
   800                         JCTree npHead = newPath.tail.head;
   801                         if (npHead.hasTag(JCTree.Tag.TYPEARRAY)) {
   801                         if (npHead.hasTag(JCTree.Tag.TYPEARRAY)) {
   954         }
   954         }
   955 
   955 
   956         private static void locateNestedTypes(Type type, TypeAnnotationPosition p) {
   956         private static void locateNestedTypes(Type type, TypeAnnotationPosition p) {
   957             // The number of "steps" to get from the full type to the
   957             // The number of "steps" to get from the full type to the
   958             // left-most outer type.
   958             // left-most outer type.
   959             ListBuffer<TypePathEntry> depth = ListBuffer.lb();
   959             ListBuffer<TypePathEntry> depth = new ListBuffer<>();
   960 
   960 
   961             Type encl = type.getEnclosingType();
   961             Type encl = type.getEnclosingType();
   962             while (encl != null &&
   962             while (encl != null &&
   963                     encl.getKind() != TypeKind.NONE &&
   963                     encl.getKind() != TypeKind.NONE &&
   964                     encl.getKind() != TypeKind.ERROR) {
   964                     encl.getKind() != TypeKind.ERROR) {
  1224 
  1224 
  1225         @Override
  1225         @Override
  1226         public void visitNewArray(JCNewArray tree) {
  1226         public void visitNewArray(JCNewArray tree) {
  1227             findPosition(tree, tree, tree.annotations);
  1227             findPosition(tree, tree, tree.annotations);
  1228             int dimAnnosCount = tree.dimAnnotations.size();
  1228             int dimAnnosCount = tree.dimAnnotations.size();
  1229             ListBuffer<TypePathEntry> depth = ListBuffer.lb();
  1229             ListBuffer<TypePathEntry> depth = new ListBuffer<>();
  1230 
  1230 
  1231             // handle annotations associated with dimensions
  1231             // handle annotations associated with dimensions
  1232             for (int i = 0; i < dimAnnosCount; ++i) {
  1232             for (int i = 0; i < dimAnnosCount; ++i) {
  1233                 TypeAnnotationPosition p = new TypeAnnotationPosition();
  1233                 TypeAnnotationPosition p = new TypeAnnotationPosition();
  1234                 p.pos = tree.pos;
  1234                 p.pos = tree.pos;