MethodThrows.java revision 2454:f434ca8aface
1284345Ssjg/*
2284345Ssjg * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
3284345Ssjg * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4284345Ssjg *
5284345Ssjg * This code is free software; you can redistribute it and/or modify it
6284345Ssjg * under the terms of the GNU General Public License version 2 only, as
7284345Ssjg * published by the Free Software Foundation.
8284345Ssjg *
9284345Ssjg * This code is distributed in the hope that it will be useful, but WITHOUT
10284345Ssjg * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11284345Ssjg * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12284345Ssjg * version 2 for more details (a copy is included in the LICENSE file that
13284345Ssjg * accompanied this code).
14284345Ssjg *
15284345Ssjg * You should have received a copy of the GNU General Public License version
16284345Ssjg * 2 along with this work; if not, write to the Free Software Foundation,
17284345Ssjg * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18284345Ssjg *
19284345Ssjg * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20284345Ssjg * or visit www.oracle.com if you need additional information or have any
21284345Ssjg * 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 * @compile -g Driver.java ReferenceInfoUtil.java MethodThrows.java
31 * @run main Driver MethodThrows
32 */
33public class MethodThrows {
34
35    @TADescription(annotation = "TA", type = THROWS, typeIndex = 0)
36    @TADescription(annotation = "TB", type = THROWS, typeIndex = 2)
37    public String regularMethod() {
38        return "class %TEST_CLASS_NAME% { void test() throws @TA RuntimeException, IllegalArgumentException, @TB Exception { } }";
39    }
40
41    @TADescription(annotation = "TA", type = THROWS, typeIndex = 0)
42    @TADescription(annotation = "TB", type = THROWS, typeIndex = 2)
43    public String abstractMethod() {
44        return "abstract class %TEST_CLASS_NAME% { abstract void test() throws @TA RuntimeException, IllegalArgumentException, @TB Exception; }";
45    }
46
47    @TADescription(annotation = "TA", type = THROWS, typeIndex = 0)
48    @TADescription(annotation = "TB", type = THROWS, typeIndex = 2)
49    public String interfaceMethod() {
50        return "interface %TEST_CLASS_NAME% { void test() throws @TA RuntimeException, IllegalArgumentException, @TB Exception; }";
51    }
52
53    @TADescription(annotation = "TA", type = THROWS, typeIndex = 0,
54                   genericLocation = {})
55    @TADescription(annotation = "TB", type = THROWS, typeIndex = 0,
56                   genericLocation = {1, 0})
57    @TADescription(annotation = "TC", type = THROWS, typeIndex = 0,
58                   genericLocation = {1, 0, 1, 0})
59    @TADescription(annotation = "TD", type = THROWS, typeIndex = 1,
60                   genericLocation = {})
61    @TADescription(annotation = "TE", type = THROWS, typeIndex = 1,
62                   genericLocation = {1, 0})
63    @TADescription(annotation = "TF", type = THROWS, typeIndex = 1,
64                   genericLocation = {1, 0, 1, 0})
65    public String NestedTypes() {
66        return "class Outer { class Middle { class Inner1 extends Exception {}" +
67                "  class Inner2 extends Exception{} } }" +
68                "class %TEST_CLASS_NAME% { void test() throws @TA Outer.@TB Middle.@TC Inner1, @TD Outer.@TE Middle.@TF Inner2 { } }";
69    }
70}
71