Sat, 01 Dec 2007 00:00:00 +0000
Initial load
1 /*
2 * Copyright 2004-2007 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
25 /*
26 * @test
27 * @bug 5037165
28 * @summary Test the Declarations.overrides method
29 * @library ../../lib
30 */
33 import java.util.*;
34 import com.sun.mirror.declaration.*;
35 import com.sun.mirror.type.*;
36 import com.sun.mirror.util.*;
39 public class Overrides extends Tester {
41 public static void main(String[] args) {
42 (new Overrides()).run();
43 }
46 // Declarations used by tests
48 static class A {
49 void m1(int i) {}; // does not override itself
50 void m2(int i) {};
51 static void m3(int i) {};
52 }
54 static class B extends A {
55 void m1(int j) {}; // overrides A.m1
56 void m1(String i) {}; // does not override A.m1
57 void m4(int i) {}; // does not override A.m1
58 }
60 static class C extends B {
61 void m1(int i) {}; // overrides A.m1 and B.m1
62 void m2(int i) {}; // overrides A.m2
63 }
65 static class D extends A {
66 static void m3(int i) {}; // does not override A.m3
67 }
69 static class E {
70 void m1(int i) {}; // does not override A.m1
71 }
75 private Declarations decls;
77 private TypeDeclaration A;
78 private TypeDeclaration B;
79 private TypeDeclaration C;
80 private TypeDeclaration D;
81 private TypeDeclaration E;
82 private MethodDeclaration Am1;
83 private MethodDeclaration Am2;
84 private MethodDeclaration Am3;
85 private MethodDeclaration Bm1;
86 private MethodDeclaration Bm1b;
87 private MethodDeclaration Bm4;
88 private MethodDeclaration Cm1;
89 private MethodDeclaration Cm2;
90 private MethodDeclaration Dm3;
91 private MethodDeclaration Em1;
93 protected void init() {
94 decls = env.getDeclarationUtils();
96 A = env.getTypeDeclaration("Overrides.A");
97 B = env.getTypeDeclaration("Overrides.B");
98 C = env.getTypeDeclaration("Overrides.C");
99 D = env.getTypeDeclaration("Overrides.D");
100 E = env.getTypeDeclaration("Overrides.E");
102 Am1 = getMethod(A, "m1", "i");
103 Am2 = getMethod(A, "m2", "i");
104 Am3 = getMethod(A, "m3", "i");
105 Bm1 = getMethod(B, "m1", "j");
106 Bm1b = getMethod(B, "m1", "i");
107 Bm4 = getMethod(B, "m4", "i");
108 Cm1 = getMethod(C, "m1", "i");
109 Cm2 = getMethod(C, "m2", "i");
110 Dm3 = getMethod(D, "m3", "i");
111 Em1 = getMethod(E, "m1", "i");
112 }
114 private MethodDeclaration getMethod(TypeDeclaration t,
115 String methodName, String paramName) {
116 for (MethodDeclaration m : t.getMethods()) {
117 if (methodName.equals(m.getSimpleName()) &&
118 paramName.equals(m.getParameters().iterator().next()
119 .getSimpleName())) {
120 return m;
121 }
122 }
123 throw new AssertionError();
124 }
127 // Declarations methods
129 @Test(result={"false",
130 "true",
131 "false",
132 "false",
133 "true",
134 "true",
135 "true",
136 "false",
137 "false"},
138 ordered=true)
139 List<Boolean> overrides() {
140 return Arrays.asList(
141 decls.overrides(Am1, Am1),
142 decls.overrides(Bm1, Am1),
143 decls.overrides(Bm1b,Am1),
144 decls.overrides(Bm4, Am1),
145 decls.overrides(Cm1, Am1),
146 decls.overrides(Cm1, Bm1),
147 decls.overrides(Cm2, Am2),
148 decls.overrides(Dm3, Am3),
149 decls.overrides(Em1, Am1));
150 }
151 }