test/tools/javac/annotations/typeAnnotations/classfile/SyntheticParameters.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
rev 2609 : 8065132: Parameter annotations not updated when synthetic parameters are prepended
Summary: Cause javac to add synthetic parameters to Runtime[In]VisibleParameterAnnotations attributes
Reviewed-by: jjg, jfranck


   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test SyntheticParameters
  26  * @summary Test generation of annotations on inner class parameters.
  27  * @build ClassfileInspector
  28  * @run main SyntheticParameters
  29  */
  30 


  31 import java.io.*;
  32 import java.lang.annotation.*;
  33 
  34 import com.sun.tools.classfile.*;
  35 
  36 public class SyntheticParameters extends ClassfileInspector {
  37 
  38     private static final String Inner_class = "SyntheticParameters$Inner.class";
  39     private static final String Foo_class = "SyntheticParameters$Foo.class";
  40     private static final Expected Inner_expected =
  41         new Expected("SyntheticParameters$Inner",
  42                      null,
  43                      new ExpectedMethodTypeAnnotation[] {
  44                          (ExpectedMethodTypeAnnotation)
  45                          // Assert there is no annotation on the
  46                          // this$0 parameter.
  47                          new ExpectedMethodTypeAnnotation.Builder(
  48                              "<init>",
  49                              "A",
  50                              TypeAnnotation.TargetType.METHOD_FORMAL_PARAMETER,


  94                          new ExpectedMethodTypeAnnotation.Builder(
  95                              "<init>",
  96                              "A",
  97                              TypeAnnotation.TargetType.METHOD_FORMAL_PARAMETER,
  98                              false,
  99                              0).setParameterIndex(1).build(),
 100                          (ExpectedMethodTypeAnnotation)
 101                          // Assert there is an annotation on the
 102                          // first parameter.
 103                          new ExpectedMethodTypeAnnotation.Builder(
 104                              "<init>",
 105                              "A",
 106                              TypeAnnotation.TargetType.METHOD_FORMAL_PARAMETER,
 107                              false,
 108                              1).setParameterIndex(2).build()
 109                      },
 110                      null);
 111 
 112     public static void main(String... args) throws Exception {
 113         new SyntheticParameters().run(
 114             new ClassFile[] { getClassFile(Inner_class), getClassFile(Foo_class) },

 115             new Expected[] { Inner_expected, Foo_expected });
 116     }
 117 
 118     public class Inner {
 119         public Inner(@A int a) {}
 120         public void foo(@A int a, int b) {}
 121     }
 122 
 123     public static enum Foo {
 124         ONE(null);
 125         Foo(@A Object a) {}
 126     }
 127 }
 128 
 129 @Target({ElementType.TYPE_USE})
 130 @interface A {}


   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test SyntheticParameters
  26  * @summary Test generation of annotations on inner class parameters.
  27  * @library /lib/annotations/
  28  * @run main SyntheticParameters
  29  */
  30 
  31 import annotations.classfile.ClassfileInspector;
  32 
  33 import java.io.*;
  34 import java.lang.annotation.*;
  35 
  36 import com.sun.tools.classfile.*;
  37 
  38 public class SyntheticParameters extends ClassfileInspector {
  39 
  40     private static final String Inner_class = "SyntheticParameters$Inner.class";
  41     private static final String Foo_class = "SyntheticParameters$Foo.class";
  42     private static final Expected Inner_expected =
  43         new Expected("SyntheticParameters$Inner",
  44                      null,
  45                      new ExpectedMethodTypeAnnotation[] {
  46                          (ExpectedMethodTypeAnnotation)
  47                          // Assert there is no annotation on the
  48                          // this$0 parameter.
  49                          new ExpectedMethodTypeAnnotation.Builder(
  50                              "<init>",
  51                              "A",
  52                              TypeAnnotation.TargetType.METHOD_FORMAL_PARAMETER,


  96                          new ExpectedMethodTypeAnnotation.Builder(
  97                              "<init>",
  98                              "A",
  99                              TypeAnnotation.TargetType.METHOD_FORMAL_PARAMETER,
 100                              false,
 101                              0).setParameterIndex(1).build(),
 102                          (ExpectedMethodTypeAnnotation)
 103                          // Assert there is an annotation on the
 104                          // first parameter.
 105                          new ExpectedMethodTypeAnnotation.Builder(
 106                              "<init>",
 107                              "A",
 108                              TypeAnnotation.TargetType.METHOD_FORMAL_PARAMETER,
 109                              false,
 110                              1).setParameterIndex(2).build()
 111                      },
 112                      null);
 113 
 114     public static void main(String... args) throws Exception {
 115         new SyntheticParameters().run(
 116             new ClassFile[] { getClassFile(Inner_class, Inner.class),
 117                               getClassFile(Foo_class, Foo.class) },
 118             new Expected[] { Inner_expected, Foo_expected });
 119     }
 120 
 121     public class Inner {
 122         public Inner(@A int a) {}
 123         public void foo(@A int a, int b) {}
 124     }
 125 
 126     public static enum Foo {
 127         ONE(null);
 128         Foo(@A Object a) {}
 129     }
 130 }
 131 
 132 @Target({ElementType.TYPE_USE})
 133 @interface A {}