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 && |