test/tools/javac/annotations/typeAnnotations/referenceinfos/Constructors.java

Print this page
rev 2608 : 8029012: parameter_index for type annotation not updated after outer.this added
Summary: Fix javac's handling of type annotations when synthetic parameters are added
Reviewed-by: jjg, mcimadamore


  29  * @run main Driver Constructors
  30  */
  31 
  32 import static com.sun.tools.classfile.TypeAnnotation.TargetType.*;
  33 
  34 public class Constructors {
  35 
  36     @TADescriptions({
  37         @TADescription(annotation = "TA", type = METHOD_RETURN),
  38         @TADescription(annotation = "TB", type = METHOD_RETURN),
  39         @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER, paramIndex = 0)
  40     })
  41     public String regularClass() {
  42         return "class Test { @TA Test() {}" +
  43                            " @TB Test(@TC int b) {} }";
  44     }
  45 
  46     @TADescriptions({
  47         @TADescription(annotation = "TA", type = METHOD_RETURN, genericLocation = {1, 0}),
  48         @TADescription(annotation = "TB", type = METHOD_RETURN, genericLocation = {1, 0}),
  49         @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER, paramIndex = 0)
  50     })
  51     @TestClass("Test$Inner")
  52     public String innerClass() {
  53         return "class Test { class Inner {" +
  54                " @TA Inner() {}" +
  55                " @TB Inner(@TC int b) {}" +
  56                " } }";
  57     }
  58 
  59     @TADescriptions({
  60         @TADescription(annotation = "TA", type = METHOD_RECEIVER),
  61         @TADescription(annotation = "TB", type = METHOD_RETURN, genericLocation = {1, 0}),
  62         @TADescription(annotation = "TC", type = METHOD_RECEIVER),
  63         @TADescription(annotation = "TD", type = METHOD_RETURN, genericLocation = {1, 0}),
  64         @TADescription(annotation = "TE", type = METHOD_FORMAL_PARAMETER, paramIndex = 0)
  65     })
  66     @TestClass("Test$Inner")
  67     public String innerClass2() {
  68         return "class Test { class Inner {" +
  69                " @TB Inner(@TA Test Test.this) {}" +
  70                " @TD Inner(@TC Test Test.this, @TE int b) {}" +
  71                " } }";
  72     }
  73 
  74     @TADescriptions({
  75         @TADescription(annotation = "TA", type = METHOD_RECEIVER),
  76         @TADescription(annotation = "TB", type = METHOD_RECEIVER, genericLocation = {1, 0}),
  77         @TADescription(annotation = "TC", type = METHOD_RETURN, genericLocation = {1, 0, 1, 0}),
  78         @TADescription(annotation = "TD", type = METHOD_RECEIVER, genericLocation = {1, 0}),
  79         @TADescription(annotation = "TE", type = METHOD_RETURN, genericLocation = {1, 0, 1, 0}),
  80         @TADescription(annotation = "TF", type = METHOD_FORMAL_PARAMETER, paramIndex = 0)
  81     })
  82     @TestClass("Outer$Middle$Inner")
  83     public String innerClass3() {
  84         return "class Outer { class Middle { class Inner {" +
  85                " @TC Inner(@TA Outer. @TB Middle Middle.this) {}" +
  86                " @TE Inner(@TD Middle Outer.Middle.this, @TF int b) {}" +
  87                " } } }";
  88     }
  89 
  90     @TADescriptions({
  91         @TADescription(annotation = "TA", type = CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT,
  92                 typeIndex = 0, offset = 4),
  93         @TADescription(annotation = "TB", type = CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT,
  94                 typeIndex = 0, offset = 0)
  95     })
  96     public String generic1() {
  97         return "class Test { <T> Test(int i) { new <@TA T>Test(); }" +
  98                            " <T> Test() { <@TB String>this(0); } }";
  99     }
 100 


  29  * @run main Driver Constructors
  30  */
  31 
  32 import static com.sun.tools.classfile.TypeAnnotation.TargetType.*;
  33 
  34 public class Constructors {
  35 
  36     @TADescriptions({
  37         @TADescription(annotation = "TA", type = METHOD_RETURN),
  38         @TADescription(annotation = "TB", type = METHOD_RETURN),
  39         @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER, paramIndex = 0)
  40     })
  41     public String regularClass() {
  42         return "class Test { @TA Test() {}" +
  43                            " @TB Test(@TC int b) {} }";
  44     }
  45 
  46     @TADescriptions({
  47         @TADescription(annotation = "TA", type = METHOD_RETURN, genericLocation = {1, 0}),
  48         @TADescription(annotation = "TB", type = METHOD_RETURN, genericLocation = {1, 0}),
  49         @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER, paramIndex = 1)
  50     })
  51     @TestClass("Test$Inner")
  52     public String innerClass() {
  53         return "class Test { class Inner {" +
  54                " @TA Inner() {}" +
  55                " @TB Inner(@TC int b) {}" +
  56                " } }";
  57     }
  58 
  59     @TADescriptions({
  60         @TADescription(annotation = "TA", type = METHOD_RECEIVER),
  61         @TADescription(annotation = "TB", type = METHOD_RETURN, genericLocation = {1, 0}),
  62         @TADescription(annotation = "TC", type = METHOD_RECEIVER),
  63         @TADescription(annotation = "TD", type = METHOD_RETURN, genericLocation = {1, 0}),
  64         @TADescription(annotation = "TE", type = METHOD_FORMAL_PARAMETER, paramIndex = 1)
  65     })
  66     @TestClass("Test$Inner")
  67     public String innerClass2() {
  68         return "class Test { class Inner {" +
  69                " @TB Inner(@TA Test Test.this) {}" +
  70                " @TD Inner(@TC Test Test.this, @TE int b) {}" +
  71                " } }";
  72     }
  73 
  74     @TADescriptions({
  75         @TADescription(annotation = "TA", type = METHOD_RECEIVER),
  76         @TADescription(annotation = "TB", type = METHOD_RECEIVER, genericLocation = {1, 0}),
  77         @TADescription(annotation = "TC", type = METHOD_RETURN, genericLocation = {1, 0, 1, 0}),
  78         @TADescription(annotation = "TD", type = METHOD_RECEIVER, genericLocation = {1, 0}),
  79         @TADescription(annotation = "TE", type = METHOD_RETURN, genericLocation = {1, 0, 1, 0}),
  80         @TADescription(annotation = "TF", type = METHOD_FORMAL_PARAMETER, paramIndex = 1)
  81     })
  82     @TestClass("Outer$Middle$Inner")
  83     public String innerClass3() {
  84         return "class Outer { class Middle { class Inner {" +
  85                " @TC Inner(@TA Outer. @TB Middle Middle.this) {}" +
  86                " @TE Inner(@TD Middle Outer.Middle.this, @TF int b) {}" +
  87                " } } }";
  88     }
  89 
  90     @TADescriptions({
  91         @TADescription(annotation = "TA", type = CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT,
  92                 typeIndex = 0, offset = 4),
  93         @TADescription(annotation = "TB", type = CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT,
  94                 typeIndex = 0, offset = 0)
  95     })
  96     public String generic1() {
  97         return "class Test { <T> Test(int i) { new <@TA T>Test(); }" +
  98                            " <T> Test() { <@TB String>this(0); } }";
  99     }
 100