1/*
2 * Copyright (c) 2009, 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
26 * @bug 8042451
27 * @summary Test population of reference info for method invocation type arguments
28 * @modules jdk.jdeps/com.sun.tools.classfile
29 * @compile -g Driver.java ReferenceInfoUtil.java MethodInvocationTypeArgument.java
30 * @run main Driver MethodInvocationTypeArgument
31 */
32
33import static com.sun.tools.classfile.TypeAnnotation.TargetType.METHOD_INVOCATION_TYPE_ARGUMENT;
34import static java.lang.System.lineSeparator;
35
36public class MethodInvocationTypeArgument {
37
38    @TADescription(annotation = "TA", type = METHOD_INVOCATION_TYPE_ARGUMENT,
39            typeIndex = 0, offset = 4)
40    @TADescription(annotation = "TB", type = METHOD_INVOCATION_TYPE_ARGUMENT,
41            typeIndex = 1, offset = 4)
42    @TADescription(annotation = "TC", type = METHOD_INVOCATION_TYPE_ARGUMENT,
43            typeIndex = 2, offset = 4)
44    @TADescription(annotation = "TD", type = METHOD_INVOCATION_TYPE_ARGUMENT,
45            typeIndex = 0, offset = 24)
46    @TADescription(annotation = "TE", type = METHOD_INVOCATION_TYPE_ARGUMENT,
47            typeIndex = 1, offset = 24)
48    @TADescription(annotation = "TF", type = METHOD_INVOCATION_TYPE_ARGUMENT,
49            typeIndex = 2, offset = 24)
50    public String genericMethod() {
51        return
52                "public <T1, T2, T3> void function(T1 t1, T2 t2, T3 t3) {}" + lineSeparator() +
53                        "{ new %TEST_CLASS_NAME%().<@TA Integer, @TB String, @TC Double>function(0, \"\", 0.0); " + lineSeparator() +
54                        "  this.<@TD Integer, @TE String, @TF Double>function(0, \"\", 0.0); }";
55    }
56
57    @TADescription(annotation = "TA", type = METHOD_INVOCATION_TYPE_ARGUMENT,
58            typeIndex = 0, offset = 0)
59    @TADescription(annotation = "TB", type = METHOD_INVOCATION_TYPE_ARGUMENT,
60            typeIndex = 1, offset = 0)
61    @TADescription(annotation = "TC", type = METHOD_INVOCATION_TYPE_ARGUMENT,
62            typeIndex = 2, offset = 0)
63    public String genericStaticMethod() {
64        return
65                "public static <T1, T2, T3> void staticFunction(T1 t1, T2 t2, T3 t3) {}" + lineSeparator() +
66                        "static { %TEST_CLASS_NAME%.<@TA Integer, @TB String, @TC Double>staticFunction(0, \"\", 0.0); }";
67    }
68
69    @TADescription(annotation = "RTAs", type = METHOD_INVOCATION_TYPE_ARGUMENT,
70            typeIndex = 0, offset = 4)
71    @TADescription(annotation = "RTBs", type = METHOD_INVOCATION_TYPE_ARGUMENT,
72            typeIndex = 1, offset = 4)
73    @TADescription(annotation = "RTCs", type = METHOD_INVOCATION_TYPE_ARGUMENT,
74            typeIndex = 0, offset = 20)
75    @TADescription(annotation = "RTDs", type = METHOD_INVOCATION_TYPE_ARGUMENT,
76            typeIndex = 1, offset = 20)
77    public String genericMethodRepeatableAnnotation() {
78        return
79                "public <T1, T2> void function(T1 t1, T2 t2) {}" + lineSeparator() +
80                        "{ new %TEST_CLASS_NAME%().<@RTA @RTA Integer, @RTB @RTB String>" +
81                        "function(0, \"\"); " + lineSeparator() +
82                        "  this.<@RTC @RTC Integer, @RTD @RTD String>function(0, \"\"); }";
83    }
84
85    @TADescription(annotation = "RTAs", type = METHOD_INVOCATION_TYPE_ARGUMENT,
86            typeIndex = 0, offset = 0)
87    @TADescription(annotation = "RTBs", type = METHOD_INVOCATION_TYPE_ARGUMENT,
88            typeIndex = 1, offset = 0)
89    @TADescription(annotation = "RTCs", type = METHOD_INVOCATION_TYPE_ARGUMENT,
90            typeIndex = 2, offset = 0)
91    public String genericStaticMethodRepeatableAnnotation() {
92        return
93                "public static <T1, T2, T3> void staticFunction(T1 t1, T2 t2, T3 t3) {}" + lineSeparator() +
94                        "static { %TEST_CLASS_NAME%.<@RTA @RTA Integer, @RTB @RTB String, @RTC @RTC Double>staticFunction(0, \"\", 0.0); }";
95    }
96
97}
98