MethodThrows.java revision 1754:ddb4a2bfcd82
1251607Sdim/*
2251607Sdim * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
3251607Sdim * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4251607Sdim *
5251607Sdim * This code is free software; you can redistribute it and/or modify it
6251607Sdim * under the terms of the GNU General Public License version 2 only, as
7251607Sdim * published by the Free Software Foundation.
8251607Sdim *
9251607Sdim * This code is distributed in the hope that it will be useful, but WITHOUT
10251607Sdim * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11251607Sdim * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12251607Sdim * version 2 for more details (a copy is included in the LICENSE file that
13251607Sdim * accompanied this code).
14251607Sdim *
15251607Sdim * You should have received a copy of the GNU General Public License version
16251607Sdim * 2 along with this work; if not, write to the Free Software Foundation,
17251607Sdim * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18251607Sdim *
19251607Sdim * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20251607Sdim * or visit www.oracle.com if you need additional information or have any
21251607Sdim * questions.
22251607Sdim */
23251607Sdim
24263508Sdimimport static com.sun.tools.classfile.TypeAnnotation.TargetType.*;
25263508Sdim
26263508Sdim/*
27263508Sdim * @test
28263508Sdim * @summary Test population of reference info for method exception clauses
29263508Sdim * @compile -g Driver.java ReferenceInfoUtil.java MethodThrows.java
30251607Sdim * @run main Driver MethodThrows
31251607Sdim */
32251607Sdimpublic class MethodThrows {
33251607Sdim
34251607Sdim    @TADescriptions({
35251607Sdim        @TADescription(annotation = "TA", type = THROWS, typeIndex = 0),
36251607Sdim        @TADescription(annotation = "TB", type = THROWS, typeIndex = 2)
37251607Sdim    })
38251607Sdim    public String regularMethod() {
39251607Sdim        return "class Test { void test() throws @TA RuntimeException, IllegalArgumentException, @TB Exception { } }";
40251607Sdim    }
41251607Sdim
42251607Sdim    @TADescriptions({
43251607Sdim        @TADescription(annotation = "TA", type = THROWS, typeIndex = 0),
44251607Sdim        @TADescription(annotation = "TB", type = THROWS, typeIndex = 2)
45251607Sdim    })
46251607Sdim    public String abstractMethod() {
47251607Sdim        return "abstract class Test { abstract void test() throws @TA RuntimeException, IllegalArgumentException, @TB Exception; }";
48251607Sdim    }
49251607Sdim
50251607Sdim    @TADescriptions({
51251607Sdim        @TADescription(annotation = "TA", type = THROWS, typeIndex = 0),
52251607Sdim        @TADescription(annotation = "TB", type = THROWS, typeIndex = 2)
53251607Sdim    })
54251607Sdim    public String interfaceMethod() {
55251607Sdim        return "interface Test { void test() throws @TA RuntimeException, IllegalArgumentException, @TB Exception; }";
56251607Sdim    }
57251607Sdim
58251607Sdim    @TADescriptions({
59263508Sdim        @TADescription(annotation = "TA", type = THROWS, typeIndex = 0,
60263508Sdim                       genericLocation = {}),
61251607Sdim        @TADescription(annotation = "TB", type = THROWS, typeIndex = 0,
62263508Sdim                       genericLocation = {1, 0}),
63251607Sdim        @TADescription(annotation = "TC", type = THROWS, typeIndex = 0,
64251607Sdim                       genericLocation = {1, 0, 1, 0}),
65251607Sdim        @TADescription(annotation = "TD", type = THROWS, typeIndex = 1,
66263508Sdim                       genericLocation = {}),
67263508Sdim        @TADescription(annotation = "TE", type = THROWS, typeIndex = 1,
68251607Sdim                       genericLocation = {1, 0}),
69263508Sdim        @TADescription(annotation = "TF", type = THROWS, typeIndex = 1,
70251607Sdim                       genericLocation = {1, 0, 1, 0})
71251607Sdim    })
72251607Sdim    public String NestedTypes() {
73251607Sdim        return "class Outer { class Middle { class Inner1 extends Exception {}" +
74263508Sdim                "  class Inner2 extends Exception{} } }" +
75263508Sdim                "class Test { void test() throws @TA Outer.@TB Middle.@TC Inner1, @TD Outer.@TE Middle.@TF Inner2 { } }";
76263508Sdim    }
77263508Sdim}
78251607Sdim