langtools/src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java
changeset 22702 1297fbaf34fa
parent 22699 3b17c61ad5a1
child 24396 3c36c6afcbca
equal deleted inserted replaced
22701:67811024e8b4 22702:1297fbaf34fa
   661 
   661 
   662         /* This is the beginning of the second part of organizing
   662         /* This is the beginning of the second part of organizing
   663          * type annotations: determine the type annotation positions.
   663          * type annotations: determine the type annotation positions.
   664          */
   664          */
   665 
   665 
   666         private void resolveFrame(JCTree tree, JCTree frame,
   666         // This method is considered deprecated, and will be removed
   667                 List<JCTree> path, TypeAnnotationPosition p) {
   667         // in the near future.  Don't use it for anything new.
       
   668         private TypeAnnotationPosition
       
   669             resolveFrame(JCTree tree,
       
   670                          JCTree frame,
       
   671                          List<JCTree> path,
       
   672                          JCLambda currentLambda,
       
   673                          int outer_type_index,
       
   674                          ListBuffer<TypePathEntry> location) {
   668             /*
   675             /*
   669             System.out.println("Resolving tree: " + tree + " kind: " + tree.getKind());
   676             System.out.println("Resolving tree: " + tree + " kind: " + tree.getKind());
   670             System.out.println("    Framing tree: " + frame + " kind: " + frame.getKind());
   677             System.out.println("    Framing tree: " + frame + " kind: " + frame.getKind());
   671             */
   678             */
   672 
   679 
   673             // Note that p.offset is set in
   680             // Note that p.offset is set in
   674             // com.sun.tools.javac.jvm.Gen.setTypeAnnotationPositions(int)
   681             // com.sun.tools.javac.jvm.Gen.setTypeAnnotationPositions(int)
   675 
   682 
   676             switch (frame.getKind()) {
   683             switch (frame.getKind()) {
   677                 case TYPE_CAST:
   684                 case TYPE_CAST:
   678                     JCTypeCast frameTC = (JCTypeCast) frame;
   685                     return TypeAnnotationPosition.typeCast(location.toList(),
   679                     p.type = TargetType.CAST;
   686                                                            currentLambda,
   680                     if (frameTC.clazz.hasTag(Tag.TYPEINTERSECTION)) {
   687                                                            outer_type_index,
   681                         // This case was already handled by INTERSECTION_TYPE
   688                                                            frame.pos);
   682                     } else {
       
   683                         p.type_index = 0;
       
   684                     }
       
   685                     p.pos = frame.pos;
       
   686                     return;
       
   687 
   689 
   688                 case INSTANCE_OF:
   690                 case INSTANCE_OF:
   689                     p.type = TargetType.INSTANCEOF;
   691                     return TypeAnnotationPosition.instanceOf(location.toList(),
   690                     p.pos = frame.pos;
   692                                                              currentLambda,
   691                     return;
   693                                                              frame.pos);
   692 
   694 
   693                 case NEW_CLASS:
   695                 case NEW_CLASS:
   694                     JCNewClass frameNewClass = (JCNewClass) frame;
   696                     final JCNewClass frameNewClass = (JCNewClass) frame;
   695                     if (frameNewClass.def != null) {
   697                     if (frameNewClass.def != null) {
   696                         // Special handling for anonymous class instantiations
   698                         // Special handling for anonymous class instantiations
   697                         JCClassDecl frameClassDecl = frameNewClass.def;
   699                         final JCClassDecl frameClassDecl = frameNewClass.def;
   698                         if (frameClassDecl.extending == tree) {
   700                         if (frameClassDecl.extending == tree) {
   699                             p.type = TargetType.CLASS_EXTENDS;
   701                             return TypeAnnotationPosition
   700                             p.type_index = -1;
   702                                 .classExtends(location.toList(), currentLambda,
       
   703                                               frame.pos);
   701                         } else if (frameClassDecl.implementing.contains(tree)) {
   704                         } else if (frameClassDecl.implementing.contains(tree)) {
   702                             p.type = TargetType.CLASS_EXTENDS;
   705                             final int type_index =
   703                             p.type_index = frameClassDecl.implementing.indexOf(tree);
   706                                 frameClassDecl.implementing.indexOf(tree);
       
   707                             return TypeAnnotationPosition
       
   708                                 .classExtends(location.toList(), currentLambda,
       
   709                                               type_index, frame.pos);
   704                         } else {
   710                         } else {
   705                             // In contrast to CLASS below, typarams cannot occur here.
   711                             // In contrast to CLASS below, typarams cannot occur here.
   706                             Assert.error("Could not determine position of tree " + tree +
   712                             throw new AssertionError("Could not determine position of tree " + tree +
   707                                     " within frame " + frame);
   713                                                      " within frame " + frame);
   708                         }
   714                         }
   709                     } else if (frameNewClass.typeargs.contains(tree)) {
   715                     } else if (frameNewClass.typeargs.contains(tree)) {
   710                         p.type = TargetType.CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT;
   716                         final int type_index =
   711                         p.type_index = frameNewClass.typeargs.indexOf(tree);
   717                             frameNewClass.typeargs.indexOf(tree);
       
   718                         return TypeAnnotationPosition
       
   719                             .constructorInvocationTypeArg(location.toList(),
       
   720                                                           currentLambda,
       
   721                                                           type_index,
       
   722                                                           frame.pos);
   712                     } else {
   723                     } else {
   713                         p.type = TargetType.NEW;
   724                         return TypeAnnotationPosition
   714                     }
   725                             .newObj(location.toList(), currentLambda,
   715                     p.pos = frame.pos;
   726                                     frame.pos);
   716                     return;
   727                     }
   717 
   728 
   718                 case NEW_ARRAY:
   729                 case NEW_ARRAY:
   719                     p.type = TargetType.NEW;
   730                     return TypeAnnotationPosition
   720                     p.pos = frame.pos;
   731                         .newObj(location.toList(), currentLambda, frame.pos);
   721                     return;
       
   722 
   732 
   723                 case ANNOTATION_TYPE:
   733                 case ANNOTATION_TYPE:
   724                 case CLASS:
   734                 case CLASS:
   725                 case ENUM:
   735                 case ENUM:
   726                 case INTERFACE:
   736                 case INTERFACE:
   727                     p.pos = frame.pos;
       
   728                     if (((JCClassDecl)frame).extending == tree) {
   737                     if (((JCClassDecl)frame).extending == tree) {
   729                         p.type = TargetType.CLASS_EXTENDS;
   738                         return TypeAnnotationPosition
   730                         p.type_index = -1;
   739                             .classExtends(location.toList(), currentLambda,
       
   740                                           frame.pos);
   731                     } else if (((JCClassDecl)frame).implementing.contains(tree)) {
   741                     } else if (((JCClassDecl)frame).implementing.contains(tree)) {
   732                         p.type = TargetType.CLASS_EXTENDS;
   742                         final int type_index =
   733                         p.type_index = ((JCClassDecl)frame).implementing.indexOf(tree);
   743                             ((JCClassDecl)frame).implementing.indexOf(tree);
       
   744                         return TypeAnnotationPosition
       
   745                             .classExtends(location.toList(), currentLambda,
       
   746                                           type_index, frame.pos);
   734                     } else if (((JCClassDecl)frame).typarams.contains(tree)) {
   747                     } else if (((JCClassDecl)frame).typarams.contains(tree)) {
   735                         p.type = TargetType.CLASS_TYPE_PARAMETER;
   748                         final int parameter_index =
   736                         p.parameter_index = ((JCClassDecl)frame).typarams.indexOf(tree);
   749                             ((JCClassDecl)frame).typarams.indexOf(tree);
       
   750                         return TypeAnnotationPosition
       
   751                             .typeParameter(location.toList(), currentLambda,
       
   752                                            parameter_index, frame.pos);
   737                     } else {
   753                     } else {
   738                         Assert.error("Could not determine position of tree " + tree +
   754                         throw new AssertionError("Could not determine position of tree " +
   739                                 " within frame " + frame);
   755                                                  tree + " within frame " + frame);
   740                     }
   756                     }
   741                     return;
       
   742 
   757 
   743                 case METHOD: {
   758                 case METHOD: {
   744                     JCMethodDecl frameMethod = (JCMethodDecl) frame;
   759                     final JCMethodDecl frameMethod = (JCMethodDecl) frame;
   745                     p.pos = frame.pos;
       
   746                     if (frameMethod.thrown.contains(tree)) {
   760                     if (frameMethod.thrown.contains(tree)) {
   747                         p.type = TargetType.THROWS;
   761                         final int type_index = frameMethod.thrown.indexOf(tree);
   748                         p.type_index = frameMethod.thrown.indexOf(tree);
   762                         return TypeAnnotationPosition
       
   763                             .methodThrows(location.toList(), currentLambda,
       
   764                                           type_index, frame.pos);
   749                     } else if (frameMethod.restype == tree) {
   765                     } else if (frameMethod.restype == tree) {
   750                         p.type = TargetType.METHOD_RETURN;
   766                         return TypeAnnotationPosition
       
   767                             .methodReturn(location.toList(), currentLambda,
       
   768                                           frame.pos);
   751                     } else if (frameMethod.typarams.contains(tree)) {
   769                     } else if (frameMethod.typarams.contains(tree)) {
   752                         p.type = TargetType.METHOD_TYPE_PARAMETER;
   770                         final int parameter_index =
   753                         p.parameter_index = frameMethod.typarams.indexOf(tree);
   771                             frameMethod.typarams.indexOf(tree);
       
   772                         return TypeAnnotationPosition
       
   773                             .methodTypeParameter(location.toList(),
       
   774                                                  currentLambda,
       
   775                                                  parameter_index, frame.pos);
   754                     } else {
   776                     } else {
   755                         Assert.error("Could not determine position of tree " + tree +
   777                         throw new AssertionError("Could not determine position of tree " + tree +
   756                                 " within frame " + frame);
   778                                                  " within frame " + frame);
   757                     }
   779                     }
   758                     return;
       
   759                 }
   780                 }
   760 
   781 
   761                 case PARAMETERIZED_TYPE: {
   782                 case PARAMETERIZED_TYPE: {
   762                     List<JCTree> newPath = path.tail;
   783                     List<JCTree> newPath = path.tail;
   763 
   784 
   764                     if (((JCTypeApply)frame).clazz == tree) {
   785                     if (((JCTypeApply)frame).clazz == tree) {
   765                         // generic: RAW; noop
   786                         // generic: RAW; noop
   766                     } else if (((JCTypeApply)frame).arguments.contains(tree)) {
   787                     } else if (((JCTypeApply)frame).arguments.contains(tree)) {
   767                         JCTypeApply taframe = (JCTypeApply) frame;
   788                         JCTypeApply taframe = (JCTypeApply) frame;
   768                         int arg = taframe.arguments.indexOf(tree);
   789                         int arg = taframe.arguments.indexOf(tree);
   769                         p.location = p.location.prepend(new TypePathEntry(TypePathEntryKind.TYPE_ARGUMENT, arg));
   790                         location = location.prepend(
       
   791                             new TypePathEntry(TypePathEntryKind.TYPE_ARGUMENT,
       
   792                                               arg));
   770 
   793 
   771                         Type typeToUse;
   794                         Type typeToUse;
   772                         if (newPath.tail != null && newPath.tail.head.hasTag(Tag.NEWCLASS)) {
   795                         if (newPath.tail != null &&
   773                             // If we are within an anonymous class instantiation, use its type,
   796                             newPath.tail.head.hasTag(Tag.NEWCLASS)) {
   774                             // because it contains a correctly nested type.
   797                             // If we are within an anonymous class
       
   798                             // instantiation, use its type, because it
       
   799                             // contains a correctly nested type.
   775                             typeToUse = newPath.tail.head.type;
   800                             typeToUse = newPath.tail.head.type;
   776                         } else {
   801                         } else {
   777                             typeToUse = taframe.type;
   802                             typeToUse = taframe.type;
   778                         }
   803                         }
   779 
   804 
   780                         locateNestedTypes(typeToUse, p);
   805                         location = locateNestedTypes(typeToUse, location);
   781                     } else {
   806                     } else {
   782                         Assert.error("Could not determine type argument position of tree " + tree +
   807                         throw new AssertionError("Could not determine type argument position of tree " + tree +
   783                                 " within frame " + frame);
   808                                                  " within frame " + frame);
   784                     }
   809                     }
   785 
   810 
   786                     resolveFrame(newPath.head, newPath.tail.head, newPath, p);
   811                     return resolveFrame(newPath.head, newPath.tail.head,
   787                     return;
   812                                         newPath, currentLambda,
       
   813                                         outer_type_index, location);
   788                 }
   814                 }
   789 
   815 
   790                 case MEMBER_REFERENCE: {
   816                 case MEMBER_REFERENCE: {
   791                     JCMemberReference mrframe = (JCMemberReference) frame;
   817                     JCMemberReference mrframe = (JCMemberReference) frame;
   792 
   818 
   793                     if (mrframe.expr == tree) {
   819                     if (mrframe.expr == tree) {
   794                         switch (mrframe.mode) {
   820                         switch (mrframe.mode) {
   795                         case INVOKE:
   821                         case INVOKE:
   796                             p.type = TargetType.METHOD_REFERENCE;
   822                             return TypeAnnotationPosition
   797                             break;
   823                                 .methodRef(location.toList(), currentLambda,
       
   824                                            frame.pos);
   798                         case NEW:
   825                         case NEW:
   799                             p.type = TargetType.CONSTRUCTOR_REFERENCE;
   826                             return TypeAnnotationPosition
   800                             break;
   827                                 .constructorRef(location.toList(),
       
   828                                                 currentLambda,
       
   829                                                 frame.pos);
   801                         default:
   830                         default:
   802                             Assert.error("Unknown method reference mode " + mrframe.mode +
   831                             throw new AssertionError("Unknown method reference mode " + mrframe.mode +
   803                                     " for tree " + tree + " within frame " + frame);
   832                                                      " for tree " + tree + " within frame " + frame);
   804                         }
   833                         }
   805                         p.pos = frame.pos;
       
   806                     } else if (mrframe.typeargs != null &&
   834                     } else if (mrframe.typeargs != null &&
   807                             mrframe.typeargs.contains(tree)) {
   835                             mrframe.typeargs.contains(tree)) {
   808                         int arg = mrframe.typeargs.indexOf(tree);
   836                         final int type_index = mrframe.typeargs.indexOf(tree);
   809                         p.type_index = arg;
       
   810                         switch (mrframe.mode) {
   837                         switch (mrframe.mode) {
   811                         case INVOKE:
   838                         case INVOKE:
   812                             p.type = TargetType.METHOD_REFERENCE_TYPE_ARGUMENT;
   839                             return TypeAnnotationPosition
   813                             break;
   840                                 .methodRefTypeArg(location.toList(),
       
   841                                                   currentLambda,
       
   842                                                   type_index, frame.pos);
   814                         case NEW:
   843                         case NEW:
   815                             p.type = TargetType.CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT;
   844                             return TypeAnnotationPosition
   816                             break;
   845                                 .constructorRefTypeArg(location.toList(),
       
   846                                                        currentLambda,
       
   847                                                        type_index, frame.pos);
   817                         default:
   848                         default:
   818                             Assert.error("Unknown method reference mode " + mrframe.mode +
   849                             throw new AssertionError("Unknown method reference mode " + mrframe.mode +
   819                                     " for tree " + tree + " within frame " + frame);
   850                                                    " for tree " + tree + " within frame " + frame);
   820                         }
   851                         }
   821                         p.pos = frame.pos;
       
   822                     } else {
   852                     } else {
   823                         Assert.error("Could not determine type argument position of tree " + tree +
   853                         throw new AssertionError("Could not determine type argument position of tree " + tree +
   824                                 " within frame " + frame);
   854                                                " within frame " + frame);
   825                     }
   855                     }
   826                     return;
       
   827                 }
   856                 }
   828 
   857 
   829                 case ARRAY_TYPE: {
   858                 case ARRAY_TYPE: {
   830                     ListBuffer<TypePathEntry> index = new ListBuffer<>();
   859                     location = location.prepend(TypePathEntry.ARRAY);
   831                     index = index.append(TypePathEntry.ARRAY);
       
   832                     List<JCTree> newPath = path.tail;
   860                     List<JCTree> newPath = path.tail;
   833                     while (true) {
   861                     while (true) {
   834                         JCTree npHead = newPath.tail.head;
   862                         JCTree npHead = newPath.tail.head;
   835                         if (npHead.hasTag(JCTree.Tag.TYPEARRAY)) {
   863                         if (npHead.hasTag(JCTree.Tag.TYPEARRAY)) {
   836                             newPath = newPath.tail;
   864                             newPath = newPath.tail;
   837                             index = index.append(TypePathEntry.ARRAY);
   865                             location = location.prepend(TypePathEntry.ARRAY);
   838                         } else if (npHead.hasTag(JCTree.Tag.ANNOTATED_TYPE)) {
   866                         } else if (npHead.hasTag(JCTree.Tag.ANNOTATED_TYPE)) {
   839                             newPath = newPath.tail;
   867                             newPath = newPath.tail;
   840                         } else {
   868                         } else {
   841                             break;
   869                             break;
   842                         }
   870                         }
   843                     }
   871                     }
   844                     p.location = p.location.prependList(index.toList());
   872                     return resolveFrame(newPath.head, newPath.tail.head,
   845                     resolveFrame(newPath.head, newPath.tail.head, newPath, p);
   873                                         newPath, currentLambda,
   846                     return;
   874                                         outer_type_index, location);
   847                 }
   875                 }
   848 
   876 
   849                 case TYPE_PARAMETER:
   877                 case TYPE_PARAMETER:
   850                     if (path.tail.tail.head.hasTag(JCTree.Tag.CLASSDEF)) {
   878                     if (path.tail.tail.head.hasTag(JCTree.Tag.CLASSDEF)) {
   851                         JCClassDecl clazz = (JCClassDecl)path.tail.tail.head;
   879                         final JCClassDecl clazz =
   852                         p.type = TargetType.CLASS_TYPE_PARAMETER_BOUND;
   880                             (JCClassDecl)path.tail.tail.head;
   853                         p.parameter_index = clazz.typarams.indexOf(path.tail.head);
   881                         final int parameter_index =
   854                         p.bound_index = ((JCTypeParameter)frame).bounds.indexOf(tree);
   882                             clazz.typarams.indexOf(path.tail.head);
   855                         if (((JCTypeParameter)frame).bounds.get(0).type.isInterface()) {
   883                         final int bound_index =
   856                             // Account for an implicit Object as bound 0
   884                             ((JCTypeParameter)frame).bounds.get(0)
   857                             p.bound_index += 1;
   885                             .type.isInterface() ?
   858                         }
   886                             ((JCTypeParameter)frame).bounds.indexOf(tree) + 1:
       
   887                             ((JCTypeParameter)frame).bounds.indexOf(tree);
       
   888                         return TypeAnnotationPosition
       
   889                             .typeParameterBound(location.toList(),
       
   890                                                 currentLambda,
       
   891                                                 parameter_index, bound_index,
       
   892                                                 frame.pos);
   859                     } else if (path.tail.tail.head.hasTag(JCTree.Tag.METHODDEF)) {
   893                     } else if (path.tail.tail.head.hasTag(JCTree.Tag.METHODDEF)) {
   860                         JCMethodDecl method = (JCMethodDecl)path.tail.tail.head;
   894                         final JCMethodDecl method =
   861                         p.type = TargetType.METHOD_TYPE_PARAMETER_BOUND;
   895                             (JCMethodDecl)path.tail.tail.head;
   862                         p.parameter_index = method.typarams.indexOf(path.tail.head);
   896                         final int parameter_index =
   863                         p.bound_index = ((JCTypeParameter)frame).bounds.indexOf(tree);
   897                             method.typarams.indexOf(path.tail.head);
   864                         if (((JCTypeParameter)frame).bounds.get(0).type.isInterface()) {
   898                         final int bound_index =
   865                             // Account for an implicit Object as bound 0
   899                             ((JCTypeParameter)frame).bounds.get(0)
   866                             p.bound_index += 1;
   900                             .type.isInterface() ?
   867                         }
   901                             ((JCTypeParameter)frame).bounds.indexOf(tree) + 1:
       
   902                             ((JCTypeParameter)frame).bounds.indexOf(tree);
       
   903                         return TypeAnnotationPosition
       
   904                             .methodTypeParameterBound(location.toList(),
       
   905                                                       currentLambda,
       
   906                                                       parameter_index,
       
   907                                                       bound_index,
       
   908                                                       frame.pos);
   868                     } else {
   909                     } else {
   869                         Assert.error("Could not determine position of tree " + tree +
   910                         throw new AssertionError("Could not determine position of tree " + tree +
   870                                 " within frame " + frame);
   911                                                  " within frame " + frame);
   871                     }
   912                     }
   872                     p.pos = frame.pos;
       
   873                     return;
       
   874 
   913 
   875                 case VARIABLE:
   914                 case VARIABLE:
   876                     VarSymbol v = ((JCVariableDecl)frame).sym;
   915                     VarSymbol v = ((JCVariableDecl)frame).sym;
   877                     p.pos = frame.pos;
   916                     if (v.getKind() != ElementKind.FIELD) {
       
   917                         v.owner.appendUniqueTypeAttributes(v.getRawTypeAttributes());
       
   918                     }
   878                     switch (v.getKind()) {
   919                     switch (v.getKind()) {
   879                         case LOCAL_VARIABLE:
   920                         case LOCAL_VARIABLE:
   880                             p.type = TargetType.LOCAL_VARIABLE;
   921                             return TypeAnnotationPosition
   881                             break;
   922                                 .localVariable(location.toList(), currentLambda,
       
   923                                                frame.pos);
   882                         case FIELD:
   924                         case FIELD:
   883                             p.type = TargetType.FIELD;
   925                             return TypeAnnotationPosition.field(location.toList(),
   884                             break;
   926                                                                 currentLambda,
       
   927                                                                 frame.pos);
   885                         case PARAMETER:
   928                         case PARAMETER:
   886                             if (v.getQualifiedName().equals(names._this)) {
   929                             if (v.getQualifiedName().equals(names._this)) {
   887                                 // TODO: Intro a separate ElementKind?
   930                                 return TypeAnnotationPosition
   888                                 p.type = TargetType.METHOD_RECEIVER;
   931                                     .methodReceiver(location.toList(),
       
   932                                                     currentLambda,
       
   933                                                     frame.pos);
   889                             } else {
   934                             } else {
   890                                 p.type = TargetType.METHOD_FORMAL_PARAMETER;
   935                                 final int parameter_index =
   891                                 p.parameter_index = methodParamIndex(path, frame);
   936                                     methodParamIndex(path, frame);
       
   937                                 return TypeAnnotationPosition
       
   938                                     .methodParameter(location.toList(),
       
   939                                                      currentLambda,
       
   940                                                      parameter_index,
       
   941                                                      frame.pos);
   892                             }
   942                             }
   893                             break;
       
   894                         case EXCEPTION_PARAMETER:
   943                         case EXCEPTION_PARAMETER:
   895                             p.type = TargetType.EXCEPTION_PARAMETER;
   944                             return TypeAnnotationPosition
   896                             break;
   945                                 .exceptionParameter(location.toList(),
       
   946                                                     currentLambda,
       
   947                                                     frame.pos);
   897                         case RESOURCE_VARIABLE:
   948                         case RESOURCE_VARIABLE:
   898                             p.type = TargetType.RESOURCE_VARIABLE;
   949                             return TypeAnnotationPosition
   899                             break;
   950                                 .resourceVariable(location.toList(),
       
   951                                                   currentLambda,
       
   952                                                   frame.pos);
   900                         default:
   953                         default:
   901                             Assert.error("Found unexpected type annotation for variable: " + v + " with kind: " + v.getKind());
   954                             throw new AssertionError("Found unexpected type annotation for variable: " + v + " with kind: " + v.getKind());
   902                     }
   955                     }
   903                     if (v.getKind() != ElementKind.FIELD) {
       
   904                         v.owner.appendUniqueTypeAttributes(v.getRawTypeAttributes());
       
   905                     }
       
   906                     return;
       
   907 
   956 
   908                 case ANNOTATED_TYPE: {
   957                 case ANNOTATED_TYPE: {
   909                     if (frame == tree) {
   958                     if (frame == tree) {
   910                         // This is only true for the first annotated type we see.
   959                         // This is only true for the first annotated type we see.
   911                         // For any other annotated types along the path, we do
   960                         // For any other annotated types along the path, we do
   919                                 utype.getKind().equals(TypeKind.ARRAY)) {
   968                                 utype.getKind().equals(TypeKind.ARRAY)) {
   920                             // Type parameters, wildcards, and arrays have the declaring
   969                             // Type parameters, wildcards, and arrays have the declaring
   921                             // class/method as enclosing elements.
   970                             // class/method as enclosing elements.
   922                             // There is actually nothing to do for them.
   971                             // There is actually nothing to do for them.
   923                         } else {
   972                         } else {
   924                             locateNestedTypes(utype, p);
   973                             location = locateNestedTypes(utype, location);
   925                         }
   974                         }
   926                     }
   975                     }
   927                     List<JCTree> newPath = path.tail;
   976                     List<JCTree> newPath = path.tail;
   928                     resolveFrame(newPath.head, newPath.tail.head, newPath, p);
   977                     return resolveFrame(newPath.head, newPath.tail.head,
   929                     return;
   978                                         newPath, currentLambda,
       
   979                                         outer_type_index, location);
   930                 }
   980                 }
   931 
   981 
   932                 case UNION_TYPE: {
   982                 case UNION_TYPE: {
   933                     List<JCTree> newPath = path.tail;
   983                     List<JCTree> newPath = path.tail;
   934                     resolveFrame(newPath.head, newPath.tail.head, newPath, p);
   984                     return resolveFrame(newPath.head, newPath.tail.head,
   935                     return;
   985                                         newPath, currentLambda,
       
   986                                         outer_type_index, location);
   936                 }
   987                 }
   937 
   988 
   938                 case INTERSECTION_TYPE: {
   989                 case INTERSECTION_TYPE: {
   939                     JCTypeIntersection isect = (JCTypeIntersection)frame;
   990                     JCTypeIntersection isect = (JCTypeIntersection)frame;
   940                     p.type_index = isect.bounds.indexOf(tree);
   991                     final List<JCTree> newPath = path.tail;
   941                     List<JCTree> newPath = path.tail;
   992                     return resolveFrame(newPath.head, newPath.tail.head,
   942                     resolveFrame(newPath.head, newPath.tail.head, newPath, p);
   993                                         newPath, currentLambda,
   943                     return;
   994                                         isect.bounds.indexOf(tree), location);
   944                 }
   995                 }
   945 
   996 
   946                 case METHOD_INVOCATION: {
   997                 case METHOD_INVOCATION: {
   947                     JCMethodInvocation invocation = (JCMethodInvocation)frame;
   998                     JCMethodInvocation invocation = (JCMethodInvocation)frame;
   948                     if (!invocation.typeargs.contains(tree)) {
   999                     if (!invocation.typeargs.contains(tree)) {
   949                         Assert.error("{" + tree + "} is not an argument in the invocation: " + invocation);
  1000                         throw new AssertionError("{" + tree + "} is not an argument in the invocation: " + invocation);
   950                     }
  1001                     }
   951                     MethodSymbol exsym = (MethodSymbol) TreeInfo.symbol(invocation.getMethodSelect());
  1002                     MethodSymbol exsym = (MethodSymbol) TreeInfo.symbol(invocation.getMethodSelect());
       
  1003                     final int type_index = invocation.typeargs.indexOf(tree);
   952                     if (exsym == null) {
  1004                     if (exsym == null) {
   953                         Assert.error("could not determine symbol for {" + invocation + "}");
  1005                         throw new AssertionError("could not determine symbol for {" + invocation + "}");
   954                     } else if (exsym.isConstructor()) {
  1006                     } else if (exsym.isConstructor()) {
   955                         p.type = TargetType.CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT;
  1007                         return TypeAnnotationPosition
       
  1008                             .constructorInvocationTypeArg(location.toList(),
       
  1009                                                           currentLambda,
       
  1010                                                           type_index,
       
  1011                                                           invocation.pos);
   956                     } else {
  1012                     } else {
   957                         p.type = TargetType.METHOD_INVOCATION_TYPE_ARGUMENT;
  1013                         return TypeAnnotationPosition
   958                     }
  1014                             .methodInvocationTypeArg(location.toList(),
   959                     p.pos = invocation.pos;
  1015                                                      currentLambda,
   960                     p.type_index = invocation.typeargs.indexOf(tree);
  1016                                                      type_index,
   961                     return;
  1017                                                      invocation.pos);
       
  1018                     }
   962                 }
  1019                 }
   963 
  1020 
   964                 case EXTENDS_WILDCARD:
  1021                 case EXTENDS_WILDCARD:
   965                 case SUPER_WILDCARD: {
  1022                 case SUPER_WILDCARD: {
   966                     // Annotations in wildcard bounds
  1023                     // Annotations in wildcard bounds
   967                     p.location = p.location.prepend(TypePathEntry.WILDCARD);
  1024                     final List<JCTree> newPath = path.tail;
   968                     List<JCTree> newPath = path.tail;
  1025                     return resolveFrame(newPath.head, newPath.tail.head,
   969                     resolveFrame(newPath.head, newPath.tail.head, newPath, p);
  1026                                         newPath, currentLambda,
   970                     return;
  1027                                         outer_type_index,
       
  1028                                         location.prepend(TypePathEntry.WILDCARD));
   971                 }
  1029                 }
   972 
  1030 
   973                 case MEMBER_SELECT: {
  1031                 case MEMBER_SELECT: {
   974                     List<JCTree> newPath = path.tail;
  1032                     final List<JCTree> newPath = path.tail;
   975                     resolveFrame(newPath.head, newPath.tail.head, newPath, p);
  1033                     return resolveFrame(newPath.head, newPath.tail.head,
   976                     return;
  1034                                         newPath, currentLambda,
       
  1035                                         outer_type_index, location);
   977                 }
  1036                 }
   978 
  1037 
   979                 default:
  1038                 default:
   980                     Assert.error("Unresolved frame: " + frame + " of kind: " + frame.getKind() +
  1039                     throw new AssertionError("Unresolved frame: " + frame +
   981                             "\n    Looking for tree: " + tree);
  1040                                              " of kind: " + frame.getKind() +
   982                     return;
  1041                                              "\n    Looking for tree: " + tree);
   983             }
  1042             }
   984         }
  1043         }
   985 
  1044 
   986         private void locateNestedTypes(Type type, TypeAnnotationPosition p) {
  1045         private ListBuffer<TypePathEntry>
   987             // The number of "steps" to get from the full type to the
  1046             locateNestedTypes(Type type,
   988             // left-most outer type.
  1047                               ListBuffer<TypePathEntry> depth) {
   989             ListBuffer<TypePathEntry> depth = new ListBuffer<>();
       
   990 
       
   991             Type encl = type.getEnclosingType();
  1048             Type encl = type.getEnclosingType();
   992             while (encl != null &&
  1049             while (encl != null &&
   993                     encl.getKind() != TypeKind.NONE &&
  1050                     encl.getKind() != TypeKind.NONE &&
   994                     encl.getKind() != TypeKind.ERROR) {
  1051                     encl.getKind() != TypeKind.ERROR) {
   995                 depth = depth.append(TypePathEntry.INNER_TYPE);
  1052                 depth = depth.prepend(TypePathEntry.INNER_TYPE);
   996                 encl = encl.getEnclosingType();
  1053                 encl = encl.getEnclosingType();
   997             }
  1054             }
   998             if (depth.nonEmpty()) {
  1055             return depth;
   999                 p.location = p.location.prependList(depth.toList());
       
  1000             }
       
  1001         }
  1056         }
  1002 
  1057 
  1003         private int methodParamIndex(List<JCTree> path, JCTree param) {
  1058         private int methodParamIndex(List<JCTree> path, JCTree param) {
  1004             List<JCTree> curr = path;
  1059             List<JCTree> curr = path;
  1005             while (curr.head.getTag() != Tag.METHODDEF &&
  1060             while (curr.head.getTag() != Tag.METHODDEF &&
  1046             if (tree.sym == null) {
  1101             if (tree.sym == null) {
  1047                 Assert.error("Visiting tree node before memberEnter");
  1102                 Assert.error("Visiting tree node before memberEnter");
  1048             }
  1103             }
  1049             if (sigOnly) {
  1104             if (sigOnly) {
  1050                 if (!tree.mods.annotations.isEmpty()) {
  1105                 if (!tree.mods.annotations.isEmpty()) {
  1051                     // Nothing to do for separateAnnotationsKinds if
       
  1052                     // there are no annotations of either kind.
       
  1053                     TypeAnnotationPosition pos = new TypeAnnotationPosition();
       
  1054                     pos.type = TargetType.METHOD_RETURN;
       
  1055                     if (tree.sym.isConstructor()) {
  1106                     if (tree.sym.isConstructor()) {
  1056                         pos.pos = tree.pos;
  1107                         final TypeAnnotationPosition pos =
  1057                         // Use null to mark that the annotations go with the symbol.
  1108                             TypeAnnotationPosition.methodReturn(tree.pos);
       
  1109                         // Use null to mark that the annotations go
       
  1110                         // with the symbol.
  1058                         separateAnnotationsKinds(tree, null, tree.sym, pos);
  1111                         separateAnnotationsKinds(tree, null, tree.sym, pos);
  1059                     } else {
  1112                     } else {
  1060                         pos.pos = tree.restype.pos;
  1113                         final TypeAnnotationPosition pos =
  1061                         separateAnnotationsKinds(tree.restype, tree.sym.type.getReturnType(),
  1114                             TypeAnnotationPosition.methodReturn(tree.restype.pos);
  1062                                 tree.sym, pos);
  1115                         separateAnnotationsKinds(tree.restype,
       
  1116                                                  tree.sym.type.getReturnType(),
       
  1117                                                  tree.sym, pos);
  1063                     }
  1118                     }
  1064                 }
  1119                 }
  1065                 if (tree.recvparam != null && tree.recvparam.sym != null &&
  1120                 if (tree.recvparam != null && tree.recvparam.sym != null &&
  1066                         !tree.recvparam.mods.annotations.isEmpty()) {
  1121                         !tree.recvparam.mods.annotations.isEmpty()) {
  1067                     // Nothing to do for separateAnnotationsKinds if
  1122                     // Nothing to do for separateAnnotationsKinds if
  1068                     // there are no annotations of either kind.
  1123                     // there are no annotations of either kind.
  1069                     // TODO: make sure there are no declaration annotations.
  1124                     // TODO: make sure there are no declaration annotations.
  1070                     TypeAnnotationPosition pos = new TypeAnnotationPosition();
  1125                     final TypeAnnotationPosition pos =
  1071                     pos.type = TargetType.METHOD_RECEIVER;
  1126                         TypeAnnotationPosition.methodReceiver(tree.recvparam.vartype.pos);
  1072                     pos.pos = tree.recvparam.vartype.pos;
  1127                     separateAnnotationsKinds(tree.recvparam.vartype,
  1073                     separateAnnotationsKinds(tree.recvparam.vartype, tree.recvparam.sym.type,
  1128                                              tree.recvparam.sym.type,
  1074                             tree.recvparam.sym, pos);
  1129                                              tree.recvparam.sym, pos);
  1075                 }
  1130                 }
  1076                 int i = 0;
  1131                 int i = 0;
  1077                 for (JCVariableDecl param : tree.params) {
  1132                 for (JCVariableDecl param : tree.params) {
  1078                     if (!param.mods.annotations.isEmpty()) {
  1133                     if (!param.mods.annotations.isEmpty()) {
  1079                         // Nothing to do for separateAnnotationsKinds if
  1134                         // Nothing to do for separateAnnotationsKinds if
  1080                         // there are no annotations of either kind.
  1135                         // there are no annotations of either kind.
  1081                         TypeAnnotationPosition pos = new TypeAnnotationPosition();
  1136                         final TypeAnnotationPosition pos =
  1082                         pos.type = TargetType.METHOD_FORMAL_PARAMETER;
  1137                             TypeAnnotationPosition.methodParameter(i, param.vartype.pos);
  1083                         pos.parameter_index = i;
  1138                         separateAnnotationsKinds(param.vartype,
  1084                         pos.pos = param.vartype.pos;
  1139                                                  param.sym.type,
  1085                         separateAnnotationsKinds(param.vartype, param.sym.type, param.sym, pos);
  1140                                                  param.sym, pos);
  1086                     }
  1141                     }
  1087                     ++i;
  1142                     ++i;
  1088                 }
  1143                 }
  1089             }
  1144             }
  1090 
  1145 
  1117                 int i = 0;
  1172                 int i = 0;
  1118                 for (JCVariableDecl param : tree.params) {
  1173                 for (JCVariableDecl param : tree.params) {
  1119                     if (!param.mods.annotations.isEmpty()) {
  1174                     if (!param.mods.annotations.isEmpty()) {
  1120                         // Nothing to do for separateAnnotationsKinds if
  1175                         // Nothing to do for separateAnnotationsKinds if
  1121                         // there are no annotations of either kind.
  1176                         // there are no annotations of either kind.
  1122                         TypeAnnotationPosition pos = new TypeAnnotationPosition();
  1177                         final TypeAnnotationPosition pos =
  1123                         pos.type = TargetType.METHOD_FORMAL_PARAMETER;
  1178                             TypeAnnotationPosition.methodParameter(tree, i,
  1124                         pos.parameter_index = i;
  1179                                                                    param.vartype.pos);
  1125                         pos.pos = param.vartype.pos;
       
  1126                         pos.onLambda = tree;
       
  1127                         separateAnnotationsKinds(param.vartype, param.sym.type, param.sym, pos);
  1180                         separateAnnotationsKinds(param.vartype, param.sym.type, param.sym, pos);
  1128                     }
  1181                     }
  1129                     ++i;
  1182                     ++i;
  1130                 }
  1183                 }
  1131 
  1184 
  1151                 Assert.error("Visiting tree node before memberEnter");
  1204                 Assert.error("Visiting tree node before memberEnter");
  1152             } else if (tree.sym.getKind() == ElementKind.PARAMETER) {
  1205             } else if (tree.sym.getKind() == ElementKind.PARAMETER) {
  1153                 // Parameters are handled in visitMethodDef or visitLambda.
  1206                 // Parameters are handled in visitMethodDef or visitLambda.
  1154             } else if (tree.sym.getKind() == ElementKind.FIELD) {
  1207             } else if (tree.sym.getKind() == ElementKind.FIELD) {
  1155                 if (sigOnly) {
  1208                 if (sigOnly) {
  1156                     TypeAnnotationPosition pos = new TypeAnnotationPosition();
  1209                     TypeAnnotationPosition pos =
  1157                     pos.type = TargetType.FIELD;
  1210                         TypeAnnotationPosition.field(tree.pos);
  1158                     pos.pos = tree.pos;
       
  1159                     separateAnnotationsKinds(tree.vartype, tree.sym.type, tree.sym, pos);
  1211                     separateAnnotationsKinds(tree.vartype, tree.sym.type, tree.sym, pos);
  1160                 }
  1212                 }
  1161             } else if (tree.sym.getKind() == ElementKind.LOCAL_VARIABLE) {
  1213             } else if (tree.sym.getKind() == ElementKind.LOCAL_VARIABLE) {
  1162                 TypeAnnotationPosition pos = new TypeAnnotationPosition();
  1214                 final TypeAnnotationPosition pos =
  1163                 pos.type = TargetType.LOCAL_VARIABLE;
  1215                     TypeAnnotationPosition.localVariable(currentLambda,
  1164                 pos.pos = tree.pos;
  1216                                                          tree.pos);
  1165                 pos.onLambda = currentLambda;
       
  1166                 separateAnnotationsKinds(tree.vartype, tree.sym.type, tree.sym, pos);
  1217                 separateAnnotationsKinds(tree.vartype, tree.sym.type, tree.sym, pos);
  1167             } else if (tree.sym.getKind() == ElementKind.EXCEPTION_PARAMETER) {
  1218             } else if (tree.sym.getKind() == ElementKind.EXCEPTION_PARAMETER) {
  1168                 TypeAnnotationPosition pos = new TypeAnnotationPosition();
  1219                 final TypeAnnotationPosition pos =
  1169                 pos.type = TargetType.EXCEPTION_PARAMETER;
  1220                     TypeAnnotationPosition.exceptionParameter(currentLambda,
  1170                 pos.pos = tree.pos;
  1221                                                               tree.pos);
  1171                 pos.onLambda = currentLambda;
       
  1172                 separateAnnotationsKinds(tree.vartype, tree.sym.type, tree.sym, pos);
  1222                 separateAnnotationsKinds(tree.vartype, tree.sym.type, tree.sym, pos);
  1173             } else if (tree.sym.getKind() == ElementKind.RESOURCE_VARIABLE) {
  1223             } else if (tree.sym.getKind() == ElementKind.RESOURCE_VARIABLE) {
  1174                 TypeAnnotationPosition pos = new TypeAnnotationPosition();
  1224                 final TypeAnnotationPosition pos =
  1175                 pos.type = TargetType.RESOURCE_VARIABLE;
  1225                     TypeAnnotationPosition.resourceVariable(currentLambda,
  1176                 pos.pos = tree.pos;
  1226                                                             tree.pos);
  1177                 pos.onLambda = currentLambda;
       
  1178                 separateAnnotationsKinds(tree.vartype, tree.sym.type, tree.sym, pos);
  1227                 separateAnnotationsKinds(tree.vartype, tree.sym.type, tree.sym, pos);
  1179             } else if (tree.sym.getKind() == ElementKind.ENUM_CONSTANT) {
  1228             } else if (tree.sym.getKind() == ElementKind.ENUM_CONSTANT) {
  1180                 // No type annotations can occur here.
  1229                 // No type annotations can occur here.
  1181             } else {
  1230             } else {
  1182                 // There is nothing else in a variable declaration that needs separation.
  1231                 // There is nothing else in a variable declaration that needs separation.
  1216             super.visitTypeParameter(tree);
  1265             super.visitTypeParameter(tree);
  1217         }
  1266         }
  1218 
  1267 
  1219         private void copyNewClassAnnotationsToOwner(JCNewClass tree) {
  1268         private void copyNewClassAnnotationsToOwner(JCNewClass tree) {
  1220             Symbol sym = tree.def.sym;
  1269             Symbol sym = tree.def.sym;
  1221             TypeAnnotationPosition pos = new TypeAnnotationPosition();
  1270             final TypeAnnotationPosition pos =
       
  1271                 TypeAnnotationPosition.newObj(tree.pos);
  1222             ListBuffer<Attribute.TypeCompound> newattrs = new ListBuffer<>();
  1272             ListBuffer<Attribute.TypeCompound> newattrs = new ListBuffer<>();
  1223 
  1273 
  1224             for (Attribute.TypeCompound old : sym.getRawTypeAttributes()) {
  1274             for (Attribute.TypeCompound old : sym.getRawTypeAttributes()) {
  1225                 newattrs.append(new Attribute.TypeCompound(old.type, old.values,
  1275                 newattrs.append(new Attribute.TypeCompound(old.type, old.values,
  1226                                                            pos));
  1276                                                            pos));
  1227             }
  1277             }
  1228 
  1278 
  1229             pos.type = TargetType.NEW;
       
  1230             pos.pos = tree.pos;
       
  1231             sym.owner.appendUniqueTypeAttributes(newattrs.toList());
  1279             sym.owner.appendUniqueTypeAttributes(newattrs.toList());
  1232         }
  1280         }
  1233 
  1281 
  1234         @Override
  1282         @Override
  1235         public void visitNewClass(JCNewClass tree) {
  1283         public void visitNewClass(JCNewClass tree) {
  1236             if (tree.def != null &&
  1284             if (tree.def != null &&
  1237                     !tree.def.mods.annotations.isEmpty()) {
  1285                     !tree.def.mods.annotations.isEmpty()) {
  1238                 JCClassDecl classdecl = tree.def;
  1286                 JCClassDecl classdecl = tree.def;
  1239                 TypeAnnotationPosition pos = new TypeAnnotationPosition();
  1287                 TypeAnnotationPosition pos;
  1240                 pos.type = TargetType.CLASS_EXTENDS;
  1288 
  1241                 pos.pos = tree.pos;
       
  1242                 if (classdecl.extending == tree.clazz) {
  1289                 if (classdecl.extending == tree.clazz) {
  1243                     pos.type_index = -1;
  1290                     pos = TypeAnnotationPosition.classExtends(tree.pos);
  1244                 } else if (classdecl.implementing.contains(tree.clazz)) {
  1291                 } else if (classdecl.implementing.contains(tree.clazz)) {
  1245                     pos.type_index = classdecl.implementing.indexOf(tree.clazz);
  1292                     final int index = classdecl.implementing.indexOf(tree.clazz);
       
  1293                     pos = TypeAnnotationPosition.classExtends(index, tree.pos);
  1246                 } else {
  1294                 } else {
  1247                     // In contrast to CLASS elsewhere, typarams cannot occur here.
  1295                     // In contrast to CLASS elsewhere, typarams cannot occur here.
  1248                     Assert.error("Could not determine position of tree " + tree);
  1296                     throw new AssertionError("Could not determine position of tree " + tree);
  1249                 }
  1297                 }
  1250                 Type before = classdecl.sym.type;
  1298                 Type before = classdecl.sym.type;
  1251                 separateAnnotationsKinds(classdecl, tree.clazz.type, classdecl.sym, pos);
  1299                 separateAnnotationsKinds(classdecl, tree.clazz.type, classdecl.sym, pos);
  1252                 copyNewClassAnnotationsToOwner(tree);
  1300                 copyNewClassAnnotationsToOwner(tree);
  1253                 // classdecl.sym.type now contains an annotated type, which
  1301                 // classdecl.sym.type now contains an annotated type, which
  1271             int dimAnnosCount = tree.dimAnnotations.size();
  1319             int dimAnnosCount = tree.dimAnnotations.size();
  1272             ListBuffer<TypePathEntry> depth = new ListBuffer<>();
  1320             ListBuffer<TypePathEntry> depth = new ListBuffer<>();
  1273 
  1321 
  1274             // handle annotations associated with dimensions
  1322             // handle annotations associated with dimensions
  1275             for (int i = 0; i < dimAnnosCount; ++i) {
  1323             for (int i = 0; i < dimAnnosCount; ++i) {
  1276                 TypeAnnotationPosition p = new TypeAnnotationPosition();
  1324                 ListBuffer<TypePathEntry> location =
  1277                 p.pos = tree.pos;
  1325                     new ListBuffer<TypePathEntry>();
  1278                 p.onLambda = currentLambda;
       
  1279                 p.type = TargetType.NEW;
       
  1280                 if (i != 0) {
  1326                 if (i != 0) {
  1281                     depth = depth.append(TypePathEntry.ARRAY);
  1327                     depth = depth.append(TypePathEntry.ARRAY);
  1282                     p.location = p.location.appendList(depth.toList());
  1328                     location = location.appendList(depth.toList());
  1283                 }
  1329                 }
       
  1330                 final TypeAnnotationPosition p =
       
  1331                     TypeAnnotationPosition.newObj(location.toList(),
       
  1332                                                   currentLambda,
       
  1333                                                   tree.pos);
  1284 
  1334 
  1285                 setTypeAnnotationPos(tree.dimAnnotations.get(i), p);
  1335                 setTypeAnnotationPos(tree.dimAnnotations.get(i), p);
  1286             }
  1336             }
  1287 
  1337 
  1288             // handle "free" annotations
  1338             // handle "free" annotations
  1291             JCExpression elemType = tree.elemtype;
  1341             JCExpression elemType = tree.elemtype;
  1292             depth = depth.append(TypePathEntry.ARRAY);
  1342             depth = depth.append(TypePathEntry.ARRAY);
  1293             while (elemType != null) {
  1343             while (elemType != null) {
  1294                 if (elemType.hasTag(JCTree.Tag.ANNOTATED_TYPE)) {
  1344                 if (elemType.hasTag(JCTree.Tag.ANNOTATED_TYPE)) {
  1295                     JCAnnotatedType at = (JCAnnotatedType)elemType;
  1345                     JCAnnotatedType at = (JCAnnotatedType)elemType;
  1296                     TypeAnnotationPosition p = new TypeAnnotationPosition();
  1346                     final ListBuffer<TypePathEntry> locationbuf =
  1297                     p.type = TargetType.NEW;
  1347                         locateNestedTypes(elemType.type,
  1298                     p.pos = tree.pos;
  1348                                           new ListBuffer<TypePathEntry>());
  1299                     p.onLambda = currentLambda;
  1349                     final List<TypePathEntry> location =
  1300                     locateNestedTypes(elemType.type, p);
  1350                         locationbuf.toList().prependList(depth.toList());
  1301                     p.location = p.location.prependList(depth.toList());
  1351                     final TypeAnnotationPosition p =
       
  1352                         TypeAnnotationPosition.newObj(location, currentLambda,
       
  1353                                                       tree.pos);
  1302                     setTypeAnnotationPos(at.annotations, p);
  1354                     setTypeAnnotationPos(at.annotations, p);
  1303                     elemType = at.underlyingType;
  1355                     elemType = at.underlyingType;
  1304                 } else if (elemType.hasTag(JCTree.Tag.TYPEARRAY)) {
  1356                 } else if (elemType.hasTag(JCTree.Tag.TYPEARRAY)) {
  1305                     depth = depth.append(TypePathEntry.ARRAY);
  1357                     depth = depth.append(TypePathEntry.ARRAY);
  1306                     elemType = ((JCArrayTypeTree)elemType).elemtype;
  1358                     elemType = ((JCArrayTypeTree)elemType).elemtype;
  1318                 /*
  1370                 /*
  1319                 System.err.println("Finding pos for: " + annotations);
  1371                 System.err.println("Finding pos for: " + annotations);
  1320                 System.err.println("    tree: " + tree + " kind: " + tree.getKind());
  1372                 System.err.println("    tree: " + tree + " kind: " + tree.getKind());
  1321                 System.err.println("    frame: " + frame + " kind: " + frame.getKind());
  1373                 System.err.println("    frame: " + frame + " kind: " + frame.getKind());
  1322                 */
  1374                 */
  1323                 TypeAnnotationPosition p = new TypeAnnotationPosition();
  1375                 final TypeAnnotationPosition p =
  1324                 p.onLambda = currentLambda;
  1376                     resolveFrame(tree, frame, frames.toList(), currentLambda, 0,
  1325                 resolveFrame(tree, frame, frames.toList(), p);
  1377                                  new ListBuffer<TypePathEntry>());
  1326                 setTypeAnnotationPos(annotations, p);
  1378                 setTypeAnnotationPos(annotations, p);
  1327             }
  1379             }
  1328         }
  1380         }
  1329 
  1381 
  1330         private void setTypeAnnotationPos(List<JCAnnotation> annotations,
  1382         private void setTypeAnnotationPos(List<JCAnnotation> annotations,