SyntheticParameters.java revision 3294:9adfb22ff08f
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 * @build annotations.classfile.ClassfileInspector SyntheticParameters
31 * @run main SyntheticParameters
32 */
33
34import annotations.classfile.ClassfileInspector;
35
36import java.io.*;
37import java.lang.annotation.*;
38
39import com.sun.tools.classfile.*;
40
41public class SyntheticParameters extends ClassfileInspector {
42
43    private static final String Inner_class = "SyntheticParameters$Inner.class";
44    private static final String Foo_class = "SyntheticParameters$Foo.class";
45    private static final Expected Inner_expected =
46        new Expected("SyntheticParameters$Inner",
47                     null,
48                     null,
49                     new ExpectedParameterAnnotation[] {
50                         (ExpectedParameterAnnotation)
51                         // Assert there is an annotation on the
52                         // first parameter.
53                         new ExpectedParameterAnnotation(
54                             "<init>",
55                             0,
56                             "A",
57                             true,
58                             1),
59                         (ExpectedParameterAnnotation)
60                         new ExpectedParameterAnnotation(
61                             "foo",
62                             0,
63                             "A",
64                             true,
65                             1),
66                         (ExpectedParameterAnnotation)
67                         // Assert there is an annotation on the
68                         // first parameter.
69                         new ExpectedParameterAnnotation(
70                             "<init>",
71                             0,
72                             "B",
73                             false,
74                             1),
75                         (ExpectedParameterAnnotation)
76                         new ExpectedParameterAnnotation(
77                             "foo",
78                             0,
79                             "B",
80                             false,
81                             1),
82                         (ExpectedParameterAnnotation)
83                         new ExpectedParameterAnnotation(
84                             "foo",
85                             1,
86                             "B",
87                             false,
88                             0)
89                     },
90                     null);
91    private static final Expected Foo_expected =
92        new Expected("SyntheticParameters$Foo",
93                     null,
94                     null,
95                     new ExpectedParameterAnnotation[] {
96                         (ExpectedParameterAnnotation)
97                         // Assert there is an annotation on the
98                         // first parameter.
99                         new ExpectedParameterAnnotation(
100                             "<init>",
101                             0,
102                             "A",
103                             true,
104                             1),
105                         (ExpectedParameterAnnotation)
106                         // Assert there is an annotation on the
107                         // first parameter.
108                         new ExpectedParameterAnnotation(
109                             "<init>",
110                             0,
111                             "B",
112                             false,
113                             1)
114                     },
115                     null);
116
117    public static void main(String... args) throws Exception {
118        new SyntheticParameters().run(
119            new ClassFile[] { getClassFile(Inner_class, Inner.class),
120                              getClassFile(Foo_class, Foo.class) },
121            new Expected[] { Inner_expected, Foo_expected });
122    }
123
124    public class Inner {
125        public Inner(@A @B int a) {}
126        public void foo(@A @B int a, int b) {}
127    }
128
129    public static enum Foo {
130        ONE(null);
131        Foo(@A @B Object a) {}
132    }
133}
134
135@Retention(RetentionPolicy.RUNTIME)
136@interface A {}
137
138@Retention(RetentionPolicy.CLASS)
139@interface B {}
140