SyntheticParameters.java revision 2735:f9f38be75c84
1184578Sdelphij/*
2184578Sdelphij * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
365294Sdes * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4184578Sdelphij *
565294Sdes * This code is free software; you can redistribute it and/or modify it
6184578Sdelphij * under the terms of the GNU General Public License version 2 only, as
7184578Sdelphij * published by the Free Software Foundation.
8184578Sdelphij *
965294Sdes * This code is distributed in the hope that it will be useful, but WITHOUT
10184578Sdelphij * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11184578Sdelphij * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12184578Sdelphij * version 2 for more details (a copy is included in the LICENSE file that
13184578Sdelphij * accompanied this code).
14184578Sdelphij *
15184578Sdelphij * You should have received a copy of the GNU General Public License version
16184578Sdelphij * 2 along with this work; if not, write to the Free Software Foundation,
1765294Sdes * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1865294Sdes *
1990016Sbde * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2089999Sobrien * or visit www.oracle.com if you need additional information or have any
2165294Sdes * questions.
2265294Sdes */
2365294Sdes
24108419Smarcel/*
2565294Sdes * @test SyntheticParameters
2665294Sdes * @bug 8065132
2765294Sdes * @summary Test generation of annotations on inner class parameters.
2865294Sdes * @library /lib/annotations/
29184578Sdelphij * @run main SyntheticParameters
3065294Sdes */
31184578Sdelphij
32184578Sdelphijimport annotations.classfile.ClassfileInspector;
3390041Sobrien
3465294Sdesimport java.io.*;
35184578Sdelphijimport java.lang.annotation.*;
36184578Sdelphij
37184578Sdelphijimport com.sun.tools.classfile.*;
38108152Sbbraun
39108152Sbbraunpublic class SyntheticParameters extends ClassfileInspector {
40108152Sbbraun
4165294Sdes    private static final String Inner_class = "SyntheticParameters$Inner.class";
4265294Sdes    private static final String Foo_class = "SyntheticParameters$Foo.class";
43184578Sdelphij    private static final Expected Inner_expected =
44184578Sdelphij        new Expected("SyntheticParameters$Inner",
45184578Sdelphij                     null,
4665294Sdes                     null,
4765294Sdes                     new ExpectedParameterAnnotation[] {
48184578Sdelphij                         (ExpectedParameterAnnotation)
4965294Sdes                         // Assert there is no annotation on the
5065294Sdes                         // this$0 parameter.
5165294Sdes                         new ExpectedParameterAnnotation(
5265294Sdes                             "<init>",
5365294Sdes                             0,
5465294Sdes                             "A",
5565294Sdes                             true,
5665294Sdes                             0),
5765294Sdes                         (ExpectedParameterAnnotation)
5865294Sdes                         // Assert there is an annotation on the
59184578Sdelphij                         // first parameter.
60184578Sdelphij                         new ExpectedParameterAnnotation(
61184578Sdelphij                             "<init>",
6265294Sdes                             1,
63184578Sdelphij                             "A",
6465294Sdes                             true,
6565294Sdes                             1),
6665294Sdes                         (ExpectedParameterAnnotation)
6765294Sdes                         new ExpectedParameterAnnotation(
6865294Sdes                             "foo",
69184578Sdelphij                             0,
70184578Sdelphij                             "A",
7165294Sdes                             true,
72184578Sdelphij                             1),
7365294Sdes                         (ExpectedParameterAnnotation)
74184578Sdelphij                         new ExpectedParameterAnnotation(
75184578Sdelphij                             "foo",
76184578Sdelphij                             1,
7765294Sdes                             "A",
78                             true,
79                             0),
80                         (ExpectedParameterAnnotation)
81                         // Assert there is no annotation on the
82                         // this$0 parameter.
83                         new ExpectedParameterAnnotation(
84                             "<init>",
85                             0,
86                             "B",
87                             false,
88                             0),
89                         (ExpectedParameterAnnotation)
90                         // Assert there is an annotation on the
91                         // first parameter.
92                         new ExpectedParameterAnnotation(
93                             "<init>",
94                             1,
95                             "B",
96                             false,
97                             1),
98                         (ExpectedParameterAnnotation)
99                         new ExpectedParameterAnnotation(
100                             "foo",
101                             0,
102                             "B",
103                             false,
104                             1),
105                         (ExpectedParameterAnnotation)
106                         new ExpectedParameterAnnotation(
107                             "foo",
108                             1,
109                             "B",
110                             false,
111                             0)
112                     },
113                     null);
114    private static final Expected Foo_expected =
115        new Expected("SyntheticParameters$Foo",
116                     null,
117                     null,
118                     new ExpectedParameterAnnotation[] {
119                         (ExpectedParameterAnnotation)
120                         // Assert there is no annotation on the
121                         // $enum$name parameter.
122                         new ExpectedParameterAnnotation(
123                             "<init>",
124                             0,
125                             "A",
126                             true,
127                             0),
128                         (ExpectedParameterAnnotation)
129                         // Assert there is no annotation on the
130                         // $enum$ordinal parameter.
131                         new ExpectedParameterAnnotation(
132                             "<init>",
133                             1,
134                             "A",
135                             true,
136                             0),
137                         (ExpectedParameterAnnotation)
138                         // Assert there is an annotation on the
139                         // first parameter.
140                         new ExpectedParameterAnnotation(
141                             "<init>",
142                             2,
143                             "A",
144                             true,
145                             1),
146                         (ExpectedParameterAnnotation)
147                         // Assert there is no annotation on the
148                         // $enum$name parameter.
149                         new ExpectedParameterAnnotation(
150                             "<init>",
151                             0,
152                             "B",
153                             false,
154                             0),
155                         (ExpectedParameterAnnotation)
156                         // Assert there is no annotation on the
157                         // $enum$ordinal parameter.
158                         new ExpectedParameterAnnotation(
159                             "<init>",
160                             1,
161                             "B",
162                             false,
163                             0),
164                         (ExpectedParameterAnnotation)
165                         // Assert there is an annotation on the
166                         // first parameter.
167                         new ExpectedParameterAnnotation(
168                             "<init>",
169                             2,
170                             "B",
171                             false,
172                             1)
173                     },
174                     null);
175
176    public static void main(String... args) throws Exception {
177        new SyntheticParameters().run(
178            new ClassFile[] { getClassFile(Inner_class, Inner.class),
179                              getClassFile(Foo_class, Foo.class) },
180            new Expected[] { Inner_expected, Foo_expected });
181    }
182
183    public class Inner {
184        public Inner(@A @B int a) {}
185        public void foo(@A @B int a, int b) {}
186    }
187
188    public static enum Foo {
189        ONE(null);
190        Foo(@A @B Object a) {}
191    }
192}
193
194@Retention(RetentionPolicy.RUNTIME)
195@interface A {}
196
197@Retention(RetentionPolicy.CLASS)
198@interface B {}
199