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
24import static com.sun.tools.classfile.TypeAnnotation.TargetType.*;
25
26/*
27 * @test
28 * @bug 8042451
29 * @summary Test population of reference info for method exception clauses
30 * @modules jdk.jdeps/com.sun.tools.classfile
31 * @compile -g Driver.java ReferenceInfoUtil.java MethodThrows.java
32 * @run main Driver MethodThrows
33 */
34public class MethodThrows {
35
36    @TADescription(annotation = "TA", type = THROWS, typeIndex = 0)
37    @TADescription(annotation = "TB", type = THROWS, typeIndex = 2)
38    public String regularMethod() {
39        return "class %TEST_CLASS_NAME% { void test() throws @TA RuntimeException, IllegalArgumentException, @TB Exception { } }";
40    }
41
42    @TADescription(annotation = "TA", type = THROWS, typeIndex = 0)
43    @TADescription(annotation = "TB", type = THROWS, typeIndex = 2)
44    public String abstractMethod() {
45        return "abstract class %TEST_CLASS_NAME% { abstract void test() throws @TA RuntimeException, IllegalArgumentException, @TB Exception; }";
46    }
47
48    @TADescription(annotation = "TA", type = THROWS, typeIndex = 0)
49    @TADescription(annotation = "TB", type = THROWS, typeIndex = 2)
50    public String interfaceMethod() {
51        return "interface %TEST_CLASS_NAME% { void test() throws @TA RuntimeException, IllegalArgumentException, @TB Exception; }";
52    }
53
54    @TADescription(annotation = "TA", type = THROWS, typeIndex = 0,
55                   genericLocation = {})
56    @TADescription(annotation = "TB", type = THROWS, typeIndex = 0,
57                   genericLocation = {1, 0})
58    @TADescription(annotation = "TC", type = THROWS, typeIndex = 0,
59                   genericLocation = {1, 0, 1, 0})
60    @TADescription(annotation = "TD", type = THROWS, typeIndex = 1,
61                   genericLocation = {})
62    @TADescription(annotation = "TE", type = THROWS, typeIndex = 1,
63                   genericLocation = {1, 0})
64    @TADescription(annotation = "TF", type = THROWS, typeIndex = 1,
65                   genericLocation = {1, 0, 1, 0})
66    public String NestedTypes() {
67        return "class Outer { class Middle { class Inner1 extends Exception {}" +
68                "  class Inner2 extends Exception{} } }" +
69                "class %TEST_CLASS_NAME% { void test() throws @TA Outer.@TB Middle.@TC Inner1, @TD Outer.@TE Middle.@TF Inner2 { } }";
70    }
71}
72