SyntheticParameters.java revision 2942:08092deced3f
1/*
2 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
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 * @bug 8065132
27 * @summary Test generation of annotations on inner class parameters.
28 * @library /lib/annotations/
29 * @modules jdk.jdeps/com.sun.tools.classfile
30 * @run main SyntheticParameters
31 */
32
33import annotations.classfile.ClassfileInspector;
34
35import java.io.*;
36import java.lang.annotation.*;
37
38import com.sun.tools.classfile.*;
39
40public class SyntheticParameters extends ClassfileInspector {
41
42    private static final String Inner_class = "SyntheticParameters$Inner.class";
43    private static final String Foo_class = "SyntheticParameters$Foo.class";
44    private static final Expected Inner_expected =
45        new Expected("SyntheticParameters$Inner",
46                     null,
47                     null,
48                     new ExpectedParameterAnnotation[] {
49                         (ExpectedParameterAnnotation)
50                         // Assert there is an annotation on the
51                         // first parameter.
52                         new ExpectedParameterAnnotation(
53                             "<init>",
54                             0,
55                             "A",
56                             true,
57                             1),
58                         (ExpectedParameterAnnotation)
59                         new ExpectedParameterAnnotation(
60                             "foo",
61                             0,
62                             "A",
63                             true,
64                             1),
65                         (ExpectedParameterAnnotation)
66                         // Assert there is an annotation on the
67                         // first parameter.
68                         new ExpectedParameterAnnotation(
69                             "<init>",
70                             0,
71                             "B",
72                             false,
73                             1),
74                         (ExpectedParameterAnnotation)
75                         new ExpectedParameterAnnotation(
76                             "foo",
77                             0,
78                             "B",
79                             false,
80                             1),
81                         (ExpectedParameterAnnotation)
82                         new ExpectedParameterAnnotation(
83                             "foo",
84                             1,
85                             "B",
86                             false,
87                             0)
88                     },
89                     null);
90    private static final Expected Foo_expected =
91        new Expected("SyntheticParameters$Foo",
92                     null,
93                     null,
94                     new ExpectedParameterAnnotation[] {
95                         (ExpectedParameterAnnotation)
96                         // Assert there is an annotation on the
97                         // first parameter.
98                         new ExpectedParameterAnnotation(
99                             "<init>",
100                             0,
101                             "A",
102                             true,
103                             1),
104                         (ExpectedParameterAnnotation)
105                         // Assert there is an annotation on the
106                         // first parameter.
107                         new ExpectedParameterAnnotation(
108                             "<init>",
109                             0,
110                             "B",
111                             false,
112                             1)
113                     },
114                     null);
115
116    public static void main(String... args) throws Exception {
117        new SyntheticParameters().run(
118            new ClassFile[] { getClassFile(Inner_class, Inner.class),
119                              getClassFile(Foo_class, Foo.class) },
120            new Expected[] { Inner_expected, Foo_expected });
121    }
122
123    public class Inner {
124        public Inner(@A @B int a) {}
125        public void foo(@A @B int a, int b) {}
126    }
127
128    public static enum Foo {
129        ONE(null);
130        Foo(@A @B Object a) {}
131    }
132}
133
134@Retention(RetentionPolicy.RUNTIME)
135@interface A {}
136
137@Retention(RetentionPolicy.CLASS)
138@interface B {}
139