102 public String toString() { 103 return tag.toString() + 104 (tag == TypePathEntryKind.TYPE_ARGUMENT ? ("(" + arg + ")") : ""); 105 } 106 107 @Override 108 public boolean equals(Object other) { 109 if (! (other instanceof TypePathEntry)) { 110 return false; 111 } 112 TypePathEntry tpe = (TypePathEntry) other; 113 return this.tag == tpe.tag && this.arg == tpe.arg; 114 } 115 116 @Override 117 public int hashCode() { 118 return this.tag.hashCode() * 17 + this.arg; 119 } 120 } 121 122 public TargetType type = TargetType.UNKNOWN; 123 124 // For generic/array types. 125 public List<TypePathEntry> location = List.nil(); 126 127 // Tree position. 128 public int pos = -1; 129 130 // For type casts, type tests, new, locals (as start_pc), 131 // and method and constructor reference type arguments. 132 public boolean isValidOffset = false; 133 public int offset = -1; 134 135 // For locals. arrays same length 136 public int[] lvarOffset = null; 137 public int[] lvarLength = null; 138 public int[] lvarIndex = null; 139 140 // For type parameter bound 141 public int bound_index = Integer.MIN_VALUE; 142 143 // For type parameter and method parameter 144 public int parameter_index = Integer.MIN_VALUE; 145 146 // For class extends, implements, and throws clauses 147 public int type_index = Integer.MIN_VALUE; 148 149 // For exception parameters, index into exception table. 150 // In com.sun.tools.javac.jvm.Gen.genCatch we first set the type_index 151 // to the catch type index - that value is only temporary. 152 // Then in com.sun.tools.javac.jvm.Code.fillExceptionParameterPositions 153 // we use that value to determine the exception table index. 154 public int exception_index = Integer.MIN_VALUE; 155 156 // If this type annotation is within a lambda expression, 157 // store a pointer to the lambda expression tree in order 158 // to allow a later translation to the right method. 159 public JCLambda onLambda = null; 160 161 public TypeAnnotationPosition() {} 162 163 @Override 164 public String toString() { 165 StringBuilder sb = new StringBuilder(); 166 sb.append('['); 167 sb.append(type); 168 169 switch (type) { 170 // instanceof 171 case INSTANCEOF: 172 // new expression 173 case NEW: 174 // constructor/method reference receiver 175 case CONSTRUCTOR_REFERENCE: 176 case METHOD_REFERENCE: 177 sb.append(", offset = "); 178 sb.append(offset); 179 break; 180 // local variable 181 case LOCAL_VARIABLE: 306 public static List<TypePathEntry> getTypePathFromBinary(java.util.List<Integer> list) { 307 ListBuffer<TypePathEntry> loc = new ListBuffer<>(); 308 Iterator<Integer> iter = list.iterator(); 309 while (iter.hasNext()) { 310 Integer fst = iter.next(); 311 Assert.check(iter.hasNext(), "Could not decode type path: " + list); 312 Integer snd = iter.next(); 313 loc = loc.append(TypePathEntry.fromBinary(fst, snd)); 314 } 315 return loc.toList(); 316 } 317 318 public static List<Integer> getBinaryFromTypePath(java.util.List<TypePathEntry> locs) { 319 ListBuffer<Integer> loc = new ListBuffer<>(); 320 for (TypePathEntry tpe : locs) { 321 loc = loc.append(tpe.tag.tag); 322 loc = loc.append(tpe.arg); 323 } 324 return loc.toList(); 325 } 326 } | 102 public String toString() { 103 return tag.toString() + 104 (tag == TypePathEntryKind.TYPE_ARGUMENT ? ("(" + arg + ")") : ""); 105 } 106 107 @Override 108 public boolean equals(Object other) { 109 if (! (other instanceof TypePathEntry)) { 110 return false; 111 } 112 TypePathEntry tpe = (TypePathEntry) other; 113 return this.tag == tpe.tag && this.arg == tpe.arg; 114 } 115 116 @Override 117 public int hashCode() { 118 return this.tag.hashCode() * 17 + this.arg; 119 } 120 } 121 122 public static final List<TypePathEntry> emptyPath = List.nil(); 123 124 // NOTE: All of these will be converted to final fields eventually. 125 126 public final TargetType type; 127 128 // For generic/array types. 129 130 // This field is in the process of being made final. Do not 131 // introduce new mutations. 132 public List<TypePathEntry> location; 133 134 // Tree position. 135 public final int pos; 136 137 // For type casts, type tests, new, locals (as start_pc), 138 // and method and constructor reference type arguments. 139 public boolean isValidOffset = false; 140 public int offset = -1; 141 142 // For locals. arrays same length 143 public int[] lvarOffset = null; 144 public int[] lvarLength = null; 145 public int[] lvarIndex = null; 146 147 // For type parameter bound 148 public final int bound_index; 149 150 // For type parameter and method parameter 151 public final int parameter_index; 152 153 // For class extends, implements, and throws clauses 154 155 // This field is effectively final. However, it needs to be 156 // modified by Gen for the time being. Do not introduce new 157 // mutations. 158 public int type_index; 159 160 // For exception parameters, index into exception table. 161 // In com.sun.tools.javac.jvm.Gen.genCatch we first set the type_index 162 // to the catch type index - that value is only temporary. 163 // Then in com.sun.tools.javac.jvm.Code.fillExceptionParameterPositions 164 // we use that value to determine the exception table index. 165 public int exception_index = Integer.MIN_VALUE; 166 167 // If this type annotation is within a lambda expression, 168 // store a pointer to the lambda expression tree in order 169 // to allow a later translation to the right method. 170 public final JCLambda onLambda; 171 172 // NOTE: This constructor will eventually go away, and be replaced 173 // by static builder methods. 174 175 @Override 176 public String toString() { 177 StringBuilder sb = new StringBuilder(); 178 sb.append('['); 179 sb.append(type); 180 181 switch (type) { 182 // instanceof 183 case INSTANCEOF: 184 // new expression 185 case NEW: 186 // constructor/method reference receiver 187 case CONSTRUCTOR_REFERENCE: 188 case METHOD_REFERENCE: 189 sb.append(", offset = "); 190 sb.append(offset); 191 break; 192 // local variable 193 case LOCAL_VARIABLE: 318 public static List<TypePathEntry> getTypePathFromBinary(java.util.List<Integer> list) { 319 ListBuffer<TypePathEntry> loc = new ListBuffer<>(); 320 Iterator<Integer> iter = list.iterator(); 321 while (iter.hasNext()) { 322 Integer fst = iter.next(); 323 Assert.check(iter.hasNext(), "Could not decode type path: " + list); 324 Integer snd = iter.next(); 325 loc = loc.append(TypePathEntry.fromBinary(fst, snd)); 326 } 327 return loc.toList(); 328 } 329 330 public static List<Integer> getBinaryFromTypePath(java.util.List<TypePathEntry> locs) { 331 ListBuffer<Integer> loc = new ListBuffer<>(); 332 for (TypePathEntry tpe : locs) { 333 loc = loc.append(tpe.tag.tag); 334 loc = loc.append(tpe.arg); 335 } 336 return loc.toList(); 337 } 338 339 // These methods are the new preferred way to create 340 // TypeAnnotationPositions 341 342 // Never make this a public constructor without creating a builder. 343 private TypeAnnotationPosition(final TargetType ttype, 344 final int pos, 345 final int parameter_index, 346 final JCLambda onLambda, 347 final int type_index, 348 final int bound_index, 349 final List<TypePathEntry> location) { 350 Assert.checkNonNull(location); 351 this.type = ttype; 352 this.pos = pos; 353 this.parameter_index = parameter_index; 354 this.onLambda = onLambda; 355 this.type_index = type_index; 356 this.bound_index = bound_index; 357 this.location = location; 358 } 359 360 /** 361 * Create a {@code TypeAnnotationPosition} for a method return. 362 * 363 * @param location The type path. 364 * @param onLambda The lambda for this parameter. 365 * @param pos The position from the associated tree node. 366 */ 367 public static TypeAnnotationPosition 368 methodReturn(final List<TypePathEntry> location, 369 final JCLambda onLambda, 370 final int pos) { 371 return new TypeAnnotationPosition(TargetType.METHOD_RETURN, pos, 372 Integer.MIN_VALUE, onLambda, 373 Integer.MIN_VALUE, Integer.MIN_VALUE, 374 location); 375 } 376 377 /** 378 * Create a {@code TypeAnnotationPosition} for a method return. 379 * 380 * @param location The type path. 381 */ 382 public static TypeAnnotationPosition 383 methodReturn(final List<TypePathEntry> location) { 384 return methodReturn(location, null, -1); 385 } 386 387 /** 388 * Create a {@code TypeAnnotationPosition} for a method return. 389 * 390 * @param pos The position from the associated tree node. 391 */ 392 public static TypeAnnotationPosition methodReturn(final int pos) { 393 return methodReturn(emptyPath, null, pos); 394 } 395 396 /** 397 * Create a {@code TypeAnnotationPosition} for a method receiver. 398 * 399 * @param location The type path. 400 * @param onLambda The lambda for this parameter. 401 * @param pos The position from the associated tree node. 402 */ 403 public static TypeAnnotationPosition 404 methodReceiver(final List<TypePathEntry> location, 405 final JCLambda onLambda, 406 final int pos) { 407 return new TypeAnnotationPosition(TargetType.METHOD_RECEIVER, pos, 408 Integer.MIN_VALUE, onLambda, 409 Integer.MIN_VALUE, Integer.MIN_VALUE, 410 location); 411 } 412 413 /** 414 * Create a {@code TypeAnnotationPosition} for a method receiver. 415 * 416 * @param location The type path. 417 */ 418 public static TypeAnnotationPosition 419 methodReceiver(final List<TypePathEntry> location) { 420 return methodReceiver(location, null, -1); 421 } 422 423 /** 424 * Create a {@code TypeAnnotationPosition} for a method receiver. 425 * 426 * @param pos The position from the associated tree node. 427 */ 428 public static TypeAnnotationPosition methodReceiver(final int pos) { 429 return methodReceiver(emptyPath, null, pos); 430 } 431 432 /** 433 * Create a {@code TypeAnnotationPosition} for a method formal parameter. 434 * 435 * @param location The type path. 436 * @param onLambda The lambda for this parameter. 437 * @param index The index of the parameter. 438 * @param pos The position from the associated tree node. 439 */ 440 public static TypeAnnotationPosition 441 methodParameter(final List<TypePathEntry> location, 442 final JCLambda onLambda, 443 final int parameter_index, 444 final int pos) { 445 return new TypeAnnotationPosition(TargetType.METHOD_FORMAL_PARAMETER, 446 pos, parameter_index, onLambda, 447 Integer.MIN_VALUE, Integer.MIN_VALUE, 448 location); 449 } 450 451 /** 452 * Create a {@code TypeAnnotationPosition} for a method formal parameter. 453 * 454 * @param onLambda The lambda for this parameter. 455 * @param index The index of the parameter. 456 * @param pos The position from the associated tree node. 457 */ 458 public static TypeAnnotationPosition 459 methodParameter(final JCLambda onLambda, 460 final int parameter_index, 461 final int pos) { 462 return methodParameter(emptyPath, onLambda, 463 parameter_index, pos); 464 } 465 466 /** 467 * Create a {@code TypeAnnotationPosition} for a method formal parameter. 468 * 469 * @param index The index of the parameter. 470 * @param pos The position from the associated tree node. 471 */ 472 public static TypeAnnotationPosition 473 methodParameter(final int parameter_index, 474 final int pos) { 475 return methodParameter(null, parameter_index, pos); 476 } 477 478 /** 479 * Create a {@code TypeAnnotationPosition} for a method formal parameter. 480 * 481 * @param location The type path. 482 * @param index The index of the parameter. 483 */ 484 public static TypeAnnotationPosition 485 methodParameter(final List<TypePathEntry> location, 486 final int parameter_index) { 487 return methodParameter(location, null, parameter_index, -1); 488 } 489 490 /** 491 * Create a {@code TypeAnnotationPosition} for a method reference. 492 * 493 * @param location The type path. 494 * @param onLambda The lambda for this method reference. 495 * @param pos The position from the associated tree node. 496 */ 497 public static TypeAnnotationPosition 498 methodRef(final List<TypePathEntry> location, 499 final JCLambda onLambda, 500 final int pos) { 501 return new TypeAnnotationPosition(TargetType.METHOD_REFERENCE, pos, 502 Integer.MIN_VALUE, onLambda, 503 Integer.MIN_VALUE, Integer.MIN_VALUE, 504 location); 505 } 506 507 /** 508 * Create a {@code TypeAnnotationPosition} for a method reference. 509 * 510 * @param location The type path. 511 * @param onLambda The lambda for this method reference. 512 * @param pos The position from the associated tree node. 513 */ 514 public static TypeAnnotationPosition 515 methodRef(final List<TypePathEntry> location) { 516 return methodRef(location, null, -1); 517 } 518 519 /** 520 * Create a {@code TypeAnnotationPosition} for a constructor reference. 521 * 522 * @param location The type path. 523 * @param onLambda The lambda for this constructor reference. 524 * @param pos The position from the associated tree node. 525 */ 526 public static TypeAnnotationPosition 527 constructorRef(final List<TypePathEntry> location, 528 final JCLambda onLambda, 529 final int pos) { 530 return new TypeAnnotationPosition(TargetType.CONSTRUCTOR_REFERENCE, pos, 531 Integer.MIN_VALUE, onLambda, 532 Integer.MIN_VALUE, Integer.MIN_VALUE, 533 location); 534 } 535 536 /** 537 * Create a {@code TypeAnnotationPosition} for a constructor reference. 538 * 539 * @param location The type path. 540 * @param onLambda The lambda for this constructor reference. 541 * @param pos The position from the associated tree node. 542 */ 543 public static TypeAnnotationPosition 544 constructorRef(final List<TypePathEntry> location) { 545 return constructorRef(location, null, -1); 546 } 547 548 /** 549 * Create a {@code TypeAnnotationPosition} for a field. 550 * 551 * @param location The type path. 552 * @param onLambda The lambda for this variable. 553 * @param pos The position from the associated tree node. 554 */ 555 public static TypeAnnotationPosition 556 field(final List<TypePathEntry> location, 557 final JCLambda onLambda, 558 final int pos) { 559 return new TypeAnnotationPosition(TargetType.FIELD, pos, 560 Integer.MIN_VALUE, onLambda, 561 Integer.MIN_VALUE, Integer.MIN_VALUE, 562 location); 563 } 564 565 /** 566 * Create a {@code TypeAnnotationPosition} for a field. 567 * 568 * @param location The type path. 569 */ 570 public static TypeAnnotationPosition 571 field(final List<TypePathEntry> location) { 572 return field(location, null, -1); 573 } 574 575 /** 576 * Create a {@code TypeAnnotationPosition} for a field. 577 * 578 * @param pos The position from the associated tree node. 579 */ 580 public static TypeAnnotationPosition field(final int pos) { 581 return field(emptyPath, null, pos); 582 } 583 584 /** 585 * Create a {@code TypeAnnotationPosition} for a local variable. 586 * 587 * @param location The type path. 588 * @param onLambda The lambda for this variable. 589 * @param pos The position from the associated tree node. 590 */ 591 public static TypeAnnotationPosition 592 localVariable(final List<TypePathEntry> location, 593 final JCLambda onLambda, 594 final int pos) { 595 return new TypeAnnotationPosition(TargetType.LOCAL_VARIABLE, pos, 596 Integer.MIN_VALUE, onLambda, 597 Integer.MIN_VALUE, Integer.MIN_VALUE, 598 location); 599 } 600 601 /** 602 * Create a {@code TypeAnnotationPosition} for a local variable. 603 * 604 * @param onLambda The lambda for this variable. 605 * @param pos The position from the associated tree node. 606 */ 607 public static TypeAnnotationPosition 608 localVariable(final JCLambda onLambda, 609 final int pos) { 610 return localVariable(emptyPath, onLambda, pos); 611 } 612 613 /** 614 * Create a {@code TypeAnnotationPosition} for a local variable. 615 * 616 * @param location The type path. 617 */ 618 public static TypeAnnotationPosition 619 localVariable(final List<TypePathEntry> location) { 620 return localVariable(location, null, -1); 621 } 622 623 /** 624 * Create a {@code TypeAnnotationPosition} for an exception parameter. 625 * 626 * @param location The type path. 627 * @param onLambda The lambda for this parameter. 628 * @param pos The position from the associated tree node. 629 */ 630 public static TypeAnnotationPosition 631 exceptionParameter(final List<TypePathEntry> location, 632 final JCLambda onLambda, 633 final int pos) { 634 return new TypeAnnotationPosition(TargetType.EXCEPTION_PARAMETER, pos, 635 Integer.MIN_VALUE, onLambda, 636 Integer.MIN_VALUE, Integer.MIN_VALUE, 637 location); 638 } 639 640 /** 641 * Create a {@code TypeAnnotationPosition} for an exception parameter. 642 * 643 * @param onLambda The lambda for this parameter. 644 * @param pos The position from the associated tree node. 645 */ 646 public static TypeAnnotationPosition 647 exceptionParameter(final JCLambda onLambda, 648 final int pos) { 649 return exceptionParameter(emptyPath, onLambda, pos); 650 } 651 652 /** 653 * Create a {@code TypeAnnotationPosition} for an exception parameter. 654 * 655 * @param location The type path. 656 */ 657 public static TypeAnnotationPosition 658 exceptionParameter(final List<TypePathEntry> location) { 659 return exceptionParameter(location, null, -1); 660 } 661 662 663 /** 664 * Create a {@code TypeAnnotationPosition} for a resource variable. 665 * 666 * @param location The type path. 667 * @param onLambda The lambda for this variable. 668 * @param pos The position from the associated tree node. 669 */ 670 public static TypeAnnotationPosition 671 resourceVariable(final List<TypePathEntry> location, 672 final JCLambda onLambda, 673 final int pos) { 674 return new TypeAnnotationPosition(TargetType.RESOURCE_VARIABLE, pos, 675 Integer.MIN_VALUE, onLambda, 676 Integer.MIN_VALUE, Integer.MIN_VALUE, 677 location); 678 } 679 680 /** 681 * Create a {@code TypeAnnotationPosition} for a resource variable. 682 * 683 * @param onLambda The lambda for this variable. 684 * @param pos The position from the associated tree node. 685 */ 686 public static TypeAnnotationPosition 687 resourceVariable(final JCLambda onLambda, 688 final int pos) { 689 return resourceVariable(emptyPath, onLambda, pos); 690 } 691 692 /** 693 * Create a {@code TypeAnnotationPosition} for a resource variable. 694 * 695 * @param location The type path. 696 * @param onLambda The lambda for this variable. 697 * @param pos The position from the associated tree node. 698 */ 699 public static TypeAnnotationPosition 700 resourceVariable(final List<TypePathEntry> location) { 701 return resourceVariable(location, null, -1); 702 } 703 704 /** 705 * Create a {@code TypeAnnotationPosition} for a new. 706 * 707 * @param location The type path. 708 * @param onLambda The lambda for this variable. 709 * @param pos The position from the associated tree node. 710 */ 711 public static TypeAnnotationPosition 712 newObj(final List<TypePathEntry> location, 713 final JCLambda onLambda, 714 final int pos) { 715 return new TypeAnnotationPosition(TargetType.NEW, pos, 716 Integer.MIN_VALUE, onLambda, 717 Integer.MIN_VALUE, Integer.MIN_VALUE, 718 location); 719 } 720 721 /** 722 * Create a {@code TypeAnnotationPosition} for a new. 723 * 724 * @param location The type path. 725 * @param onLambda The lambda for this variable. 726 * @param pos The position from the associated tree node. 727 */ 728 public static TypeAnnotationPosition newObj(final int pos) { 729 return newObj(emptyPath, null, pos); 730 } 731 732 /** 733 * Create a {@code TypeAnnotationPosition} for a new. 734 * 735 * @param location The type path. 736 * @param onLambda The lambda for this variable. 737 * @param pos The position from the associated tree node. 738 */ 739 public static TypeAnnotationPosition 740 newObj(final List<TypePathEntry> location) { 741 return newObj(location, null, -1); 742 } 743 744 /** 745 * Create a {@code TypeAnnotationPosition} for a class extension. 746 * 747 * @param location The type path. 748 * @param onLambda The lambda for this variable. 749 * @param type_index The index of the interface. 750 * @param pos The position from the associated tree node. 751 */ 752 public static TypeAnnotationPosition 753 classExtends(final List<TypePathEntry> location, 754 final JCLambda onLambda, 755 final int type_index, 756 final int pos) { 757 return new TypeAnnotationPosition(TargetType.CLASS_EXTENDS, pos, 758 Integer.MIN_VALUE, onLambda, 759 type_index, Integer.MIN_VALUE, 760 location); 761 } 762 763 /** 764 * Create a {@code TypeAnnotationPosition} for a class extension. 765 * 766 * @param location The type path. 767 * @param onLambda The lambda for this variable. 768 * @param type_index The index of the interface. 769 * @param pos The position from the associated tree node. 770 */ 771 public static TypeAnnotationPosition 772 classExtends(final List<TypePathEntry> location, 773 final JCLambda onLambda, 774 final int pos) { 775 return classExtends(location, onLambda, -1, pos); 776 } 777 778 /** 779 * Create a {@code TypeAnnotationPosition} for a class extension. 780 * 781 * @param location The type path. 782 * @param type_index The index of the interface. 783 */ 784 public static TypeAnnotationPosition 785 classExtends(final List<TypePathEntry> location, 786 final int type_index) { 787 return classExtends(location, null, type_index, -1); 788 } 789 790 /** 791 * Create a {@code TypeAnnotationPosition} for a class extension. 792 * 793 * @param type_index The index of the interface. 794 * @param pos The position from the associated tree node. 795 */ 796 public static TypeAnnotationPosition classExtends(final int type_index, 797 final int pos) { 798 return classExtends(emptyPath, null, type_index, pos); 799 } 800 801 /** 802 * Create a {@code TypeAnnotationPosition} for a class extension. 803 * 804 * @param pos The position from the associated tree node. 805 */ 806 public static TypeAnnotationPosition classExtends(final int pos) { 807 return classExtends(-1, pos); 808 } 809 810 /** 811 * Create a {@code TypeAnnotationPosition} for an instanceof. 812 * 813 * @param location The type path. 814 * @param onLambda The lambda for this variable. 815 * @param pos The position from the associated tree node. 816 */ 817 public static TypeAnnotationPosition 818 instanceOf(final List<TypePathEntry> location, 819 final JCLambda onLambda, 820 final int pos) { 821 return new TypeAnnotationPosition(TargetType.INSTANCEOF, pos, 822 Integer.MIN_VALUE, onLambda, 823 Integer.MIN_VALUE, Integer.MIN_VALUE, 824 location); 825 } 826 /** 827 * Create a {@code TypeAnnotationPosition} for an instanceof. 828 * 829 * @param location The type path. 830 * @param onLambda The lambda for this variable. 831 * @param pos The position from the associated tree node. 832 */ 833 public static TypeAnnotationPosition 834 instanceOf(final List<TypePathEntry> location) { 835 return instanceOf(location, null, -1); 836 } 837 838 /** 839 * Create a {@code TypeAnnotationPosition} for a type cast. 840 * 841 * @param location The type path. 842 * @param onLambda The lambda for this variable. 843 * @param type_index The index into an intersection type. 844 * @param pos The position from the associated tree node. 845 */ 846 public static TypeAnnotationPosition 847 typeCast(final List<TypePathEntry> location, 848 final JCLambda onLambda, 849 final int type_index, 850 final int pos) { 851 return new TypeAnnotationPosition(TargetType.CAST, pos, 852 Integer.MIN_VALUE, onLambda, 853 type_index, Integer.MIN_VALUE, 854 location); 855 } 856 857 /** 858 * Create a {@code TypeAnnotationPosition} for a type cast. 859 * 860 * @param location The type path. 861 * @param onLambda The lambda for this variable. 862 * @param type_index The index into an intersection type. 863 * @param pos The position from the associated tree node. 864 */ 865 public static TypeAnnotationPosition 866 typeCast(final List<TypePathEntry> location, 867 final int type_index) { 868 return typeCast(location, null, type_index, -1); 869 } 870 871 /** 872 * Create a {@code TypeAnnotationPosition} for a method 873 * invocation type argument. 874 * 875 * @param location The type path. 876 * @param onLambda The lambda for this variable. 877 * @param type_index The index of the type argument. 878 * @param pos The position from the associated tree node. 879 */ 880 public static TypeAnnotationPosition 881 methodInvocationTypeArg(final List<TypePathEntry> location, 882 final JCLambda onLambda, 883 final int type_index, 884 final int pos) { 885 return new TypeAnnotationPosition(TargetType.METHOD_INVOCATION_TYPE_ARGUMENT, 886 pos, Integer.MIN_VALUE, onLambda, 887 type_index, Integer.MIN_VALUE, 888 location); 889 } 890 891 /** 892 * Create a {@code TypeAnnotationPosition} for a method 893 * invocation type argument. 894 * 895 * @param location The type path. 896 * @param type_index The index of the type argument. 897 */ 898 public static TypeAnnotationPosition 899 methodInvocationTypeArg(final List<TypePathEntry> location, 900 final int type_index) { 901 return methodInvocationTypeArg(location, null, type_index, -1); 902 } 903 904 /** 905 * Create a {@code TypeAnnotationPosition} for a constructor 906 * invocation type argument. 907 * 908 * @param location The type path. 909 * @param onLambda The lambda for this variable. 910 * @param type_index The index of the type argument. 911 * @param pos The position from the associated tree node. 912 */ 913 public static TypeAnnotationPosition 914 constructorInvocationTypeArg(final List<TypePathEntry> location, 915 final JCLambda onLambda, 916 final int type_index, 917 final int pos) { 918 return new TypeAnnotationPosition(TargetType.CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT, 919 pos, Integer.MIN_VALUE, onLambda, 920 type_index, Integer.MIN_VALUE, 921 location); 922 } 923 924 /** 925 * Create a {@code TypeAnnotationPosition} for a constructor 926 * invocation type argument. 927 * 928 * @param location The type path. 929 * @param type_index The index of the type argument. 930 */ 931 public static TypeAnnotationPosition 932 constructorInvocationTypeArg(final List<TypePathEntry> location, 933 final int type_index) { 934 return constructorInvocationTypeArg(location, null, type_index, -1); 935 } 936 937 /** 938 * Create a {@code TypeAnnotationPosition} for a type parameter. 939 * 940 * @param location The type path. 941 * @param onLambda The lambda for this variable. 942 * @param parameter_index The index of the type parameter. 943 * @param pos The position from the associated tree node. 944 */ 945 public static TypeAnnotationPosition 946 typeParameter(final List<TypePathEntry> location, 947 final JCLambda onLambda, 948 final int parameter_index, 949 final int pos) { 950 return new TypeAnnotationPosition(TargetType.CLASS_TYPE_PARAMETER, pos, 951 parameter_index, onLambda, 952 Integer.MIN_VALUE, Integer.MIN_VALUE, 953 location); 954 } 955 956 /** 957 * Create a {@code TypeAnnotationPosition} for a type parameter. 958 * 959 * @param location The type path. 960 * @param onLambda The lambda for this variable. 961 * @param parameter_index The index of the type parameter. 962 * @param pos The position from the associated tree node. 963 */ 964 public static TypeAnnotationPosition 965 typeParameter(final List<TypePathEntry> location, 966 final int parameter_index) { 967 return typeParameter(location, null, parameter_index, -1); 968 } 969 970 /** 971 * Create a {@code TypeAnnotationPosition} for a method type parameter. 972 * 973 * @param location The type path. 974 * @param onLambda The lambda for this variable. 975 * @param parameter_index The index of the type parameter. 976 * @param pos The position from the associated tree node. 977 */ 978 public static TypeAnnotationPosition 979 methodTypeParameter(final List<TypePathEntry> location, 980 final JCLambda onLambda, 981 final int parameter_index, 982 final int pos) { 983 return new TypeAnnotationPosition(TargetType.METHOD_TYPE_PARAMETER, 984 pos, parameter_index, onLambda, 985 Integer.MIN_VALUE, Integer.MIN_VALUE, 986 location); 987 } 988 989 /** 990 * Create a {@code TypeAnnotationPosition} for a method type parameter. 991 * 992 * @param location The type path. 993 * @param parameter_index The index of the type parameter. 994 */ 995 public static TypeAnnotationPosition 996 methodTypeParameter(final List<TypePathEntry> location, 997 final int parameter_index) { 998 return methodTypeParameter(location, null, parameter_index, -1); 999 } 1000 1001 /** 1002 * Create a {@code TypeAnnotationPosition} for a throws clause. 1003 * 1004 * @param location The type path. 1005 * @param onLambda The lambda for this variable. 1006 * @param type_index The index of the exception. 1007 * @param pos The position from the associated tree node. 1008 */ 1009 public static TypeAnnotationPosition 1010 methodThrows(final List<TypePathEntry> location, 1011 final JCLambda onLambda, 1012 final int type_index, 1013 final int pos) { 1014 return new TypeAnnotationPosition(TargetType.THROWS, pos, 1015 Integer.MIN_VALUE, onLambda, 1016 type_index, Integer.MIN_VALUE, 1017 location); 1018 } 1019 1020 /** 1021 * Create a {@code TypeAnnotationPosition} for a throws clause. 1022 * 1023 * @param location The type path. 1024 * @param type_index The index of the exception. 1025 */ 1026 public static TypeAnnotationPosition 1027 methodThrows(final List<TypePathEntry> location, 1028 final int type_index) { 1029 return methodThrows(location, null, type_index, -1); 1030 } 1031 1032 /** 1033 * Create a {@code TypeAnnotationPosition} for a method reference 1034 * type argument. 1035 * 1036 * @param location The type path. 1037 * @param onLambda The lambda for this variable. 1038 * @param parameter_index The index of the type argument. 1039 * @param pos The position from the associated tree node. 1040 */ 1041 public static TypeAnnotationPosition 1042 methodRefTypeArg(final List<TypePathEntry> location, 1043 final JCLambda onLambda, 1044 final int type_index, 1045 final int pos) { 1046 return new TypeAnnotationPosition(TargetType.METHOD_REFERENCE_TYPE_ARGUMENT, 1047 pos, Integer.MIN_VALUE, onLambda, 1048 type_index, Integer.MIN_VALUE, 1049 location); 1050 } 1051 1052 /** 1053 * Create a {@code TypeAnnotationPosition} for a method reference 1054 * type argument. 1055 * 1056 * @param location The type path. 1057 * @param onLambda The lambda for this variable. 1058 * @param parameter_index The index of the type argument. 1059 * @param pos The position from the associated tree node. 1060 */ 1061 public static TypeAnnotationPosition 1062 methodRefTypeArg(final List<TypePathEntry> location, 1063 final int type_index) { 1064 return methodRefTypeArg(location, null, type_index, -1); 1065 } 1066 1067 /** 1068 * Create a {@code TypeAnnotationPosition} for a constructor reference 1069 * type argument. 1070 * 1071 * @param location The type path. 1072 * @param onLambda The lambda for this variable. 1073 * @param parameter_index The index of the type argument. 1074 * @param pos The position from the associated tree node. 1075 */ 1076 public static TypeAnnotationPosition 1077 constructorRefTypeArg(final List<TypePathEntry> location, 1078 final JCLambda onLambda, 1079 final int type_index, 1080 final int pos) { 1081 return new TypeAnnotationPosition(TargetType.CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT, 1082 pos, Integer.MIN_VALUE, onLambda, 1083 type_index, Integer.MIN_VALUE, 1084 location); 1085 } 1086 1087 /** 1088 * Create a {@code TypeAnnotationPosition} for a constructor reference 1089 * type argument. 1090 * 1091 * @param location The type path. 1092 * @param parameter_index The index of the type argument. 1093 */ 1094 public static TypeAnnotationPosition 1095 constructorRefTypeArg(final List<TypePathEntry> location, 1096 final int type_index) { 1097 return constructorRefTypeArg(location, null, type_index, -1); 1098 } 1099 1100 /** 1101 * Create a {@code TypeAnnotationPosition} for a type parameter bound. 1102 * 1103 * @param location The type path. 1104 * @param onLambda The lambda for this variable. 1105 * @param parameter_index The index of the type parameter. 1106 * @param bound_index The index of the type parameter bound. 1107 * @param pos The position from the associated tree node. 1108 */ 1109 public static TypeAnnotationPosition 1110 typeParameterBound(final List<TypePathEntry> location, 1111 final JCLambda onLambda, 1112 final int parameter_index, 1113 final int bound_index, 1114 final int pos) { 1115 return new TypeAnnotationPosition(TargetType.CLASS_TYPE_PARAMETER_BOUND, 1116 pos, parameter_index, onLambda, 1117 Integer.MIN_VALUE, bound_index, 1118 location); 1119 } 1120 1121 /** 1122 * Create a {@code TypeAnnotationPosition} for a type parameter bound. 1123 * 1124 * @param location The type path. 1125 * @param parameter_index The index of the type parameter. 1126 * @param bound_index The index of the type parameter bound. 1127 */ 1128 public static TypeAnnotationPosition 1129 typeParameterBound(final List<TypePathEntry> location, 1130 final int parameter_index, 1131 final int bound_index) { 1132 return typeParameterBound(location, null, parameter_index, 1133 bound_index, -1); 1134 } 1135 1136 /** 1137 * Create a {@code TypeAnnotationPosition} for a method type 1138 * parameter bound. 1139 * 1140 * @param location The type path. 1141 * @param onLambda The lambda for this variable. 1142 * @param parameter_index The index of the type parameter. 1143 * @param bound_index The index of the type parameter bound. 1144 * @param pos The position from the associated tree node. 1145 */ 1146 public static TypeAnnotationPosition 1147 methodTypeParameterBound(final List<TypePathEntry> location, 1148 final JCLambda onLambda, 1149 final int parameter_index, 1150 final int bound_index, 1151 final int pos) { 1152 return new TypeAnnotationPosition(TargetType.METHOD_TYPE_PARAMETER_BOUND, 1153 pos, parameter_index, onLambda, 1154 Integer.MIN_VALUE, bound_index, 1155 location); 1156 } 1157 1158 /** 1159 * Create a {@code TypeAnnotationPosition} for a method type 1160 * parameter bound. 1161 * 1162 * @param location The type path. 1163 * @param parameter_index The index of the type parameter. 1164 * @param bound_index The index of the type parameter bound. 1165 */ 1166 public static TypeAnnotationPosition 1167 methodTypeParameterBound(final List<TypePathEntry> location, 1168 final int parameter_index, 1169 final int bound_index) { 1170 return methodTypeParameterBound(location, null, parameter_index, 1171 bound_index, -1); 1172 } 1173 1174 // Consider this deprecated on arrival. We eventually want to get 1175 // rid of this value altogether. Do not use it for anything new. 1176 public static final TypeAnnotationPosition unknown = 1177 new TypeAnnotationPosition(TargetType.UNKNOWN, -1, 1178 Integer.MIN_VALUE, null, 1179 Integer.MIN_VALUE, Integer.MIN_VALUE, 1180 emptyPath); 1181 } |