Tue, 07 Oct 2008 15:39:19 -0700
6749967: regression tests for apt should be same-vm friendly
Reviewed-by: darcy
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 4853450 4993303 5004618 5010746
28 * @summary InterfaceDeclaration tests
29 * @library ../../lib
30 * @compile -source 1.5 InterfaceDecl.java
31 * @run main/othervm InterfaceDecl
32 */
35 import java.util.*;
36 import com.sun.mirror.declaration.*;
37 import com.sun.mirror.type.*;
38 import com.sun.mirror.util.*;
41 /**
42 * Sed Quis custodiet ipsos custodes?
43 */
44 @AT1
45 @AT2
46 public class InterfaceDecl extends Tester {
48 public static void main(String[] args) {
49 (new InterfaceDecl()).run();
50 }
53 private InterfaceDeclaration iDecl = null; // an interface
54 private InterfaceDeclaration nested = null; // a nested interface
56 protected void init() {
57 iDecl = (InterfaceDeclaration) env.getTypeDeclaration("I");
58 nested = (InterfaceDeclaration)
59 iDecl.getNestedTypes().iterator().next();
60 }
63 // Declaration methods
65 @Test(result="interface")
66 Collection<String> accept() {
67 final Collection<String> res = new ArrayList<String>();
69 iDecl.accept(new SimpleDeclarationVisitor() {
70 public void visitTypeDeclaration(TypeDeclaration t) {
71 res.add("type");
72 }
73 public void visitClassDeclaration(ClassDeclaration c) {
74 res.add("class");
75 }
76 public void visitInterfaceDeclaration(InterfaceDeclaration e) {
77 res.add("interface");
78 }
79 public void visitAnnotationTypeDeclaration(
80 AnnotationTypeDeclaration e) {
81 res.add("annotation type");
82 }
83 });
84 return res;
85 }
87 @Test(result="true")
88 boolean equals1() {
89 return iDecl.equals(iDecl);
90 }
92 @Test(result="false")
93 boolean equals2() {
94 return iDecl.equals(nested);
95 }
97 @Test(result="true")
98 boolean equals3() {
99 return iDecl.equals(env.getTypeDeclaration("I"));
100 }
103 @Test(result={"@AT1", "@AT2"})
104 Collection<AnnotationMirror> getAnnotationMirrors() {
105 return iDecl.getAnnotationMirrors();
106 }
108 @Test(result=" Sed Quis custodiet ipsos custodes?\n")
109 String getDocComment() {
110 return iDecl.getDocComment();
111 }
113 // Check that interface has "abstract" modifier, even though it's implict
114 // in the source code.
115 @Test(result={"abstract"})
116 Collection<Modifier> getModifiers1() {
117 return iDecl.getModifiers();
118 }
120 // Check that nested interface has "static" modifier, even though
121 // it's implicit in the source code and the VM doesn't set that bit.
122 @Test(result={"public", "abstract", "static"})
123 Collection<Modifier> getModifiers2() {
124 return nested.getModifiers();
125 }
127 @Test(result="InterfaceDecl.java")
128 String getPosition() {
129 return iDecl.getPosition().file().getName();
130 }
132 @Test(result="I")
133 String getSimpleName1() {
134 return iDecl.getSimpleName();
135 }
137 @Test(result="Nested")
138 String getSimpleName2() {
139 return nested.getSimpleName();
140 }
143 // MemberDeclaration method
145 @Test(result="null")
146 TypeDeclaration getDeclaringType1() {
147 return iDecl.getDeclaringType();
148 }
150 @Test(result="I<T extends java.lang.Number>")
151 TypeDeclaration getDeclaringType2() {
152 return nested.getDeclaringType();
153 }
156 // TypeDeclaration methods
158 @Test(result={"i"})
159 Collection<FieldDeclaration> getFields() {
160 return iDecl.getFields();
161 }
163 @Test(result={"T extends java.lang.Number"})
164 Collection<TypeParameterDeclaration> getFormalTypeParameters1() {
165 return iDecl.getFormalTypeParameters();
166 }
168 @Test(result={})
169 Collection<TypeParameterDeclaration> getFormalTypeParameters2() {
170 return nested.getFormalTypeParameters();
171 }
173 // 4993303: verify policy on Object methods being visible
174 @Test(result={"m()", "toString()"})
175 Collection<? extends MethodDeclaration> getMethods() {
176 return nested.getMethods();
177 }
179 @Test(result="I.Nested")
180 Collection<TypeDeclaration> getNestedTypes() {
181 return iDecl.getNestedTypes();
182 }
184 @Test(result="")
185 PackageDeclaration getPackage1() {
186 return iDecl.getPackage();
187 }
189 @Test(result="java.util")
190 PackageDeclaration getPackage2() {
191 InterfaceDeclaration set =
192 (InterfaceDeclaration) env.getTypeDeclaration("java.util.Set");
193 return set.getPackage();
194 }
196 @Test(result="I")
197 String getQualifiedName1() {
198 return iDecl.getQualifiedName();
199 }
201 @Test(result="I.Nested")
202 String getQualifiedName2() {
203 return nested.getQualifiedName();
204 }
206 @Test(result="java.util.Set")
207 String getQualifiedName3() {
208 InterfaceDeclaration set =
209 (InterfaceDeclaration) env.getTypeDeclaration("java.util.Set");
210 return set.getQualifiedName();
211 }
213 @Test(result="java.lang.Runnable")
214 Collection<InterfaceType> getSuperinterfaces() {
215 return iDecl.getSuperinterfaces();
216 }
217 }
220 // Interfaces used for testing.
222 /**
223 * Sed Quis custodiet ipsos custodes?
224 */
225 @AT1
226 @AT2
227 interface I<T extends Number> extends Runnable {
228 int i = 6;
229 void m1();
230 void m2();
231 void m2(int j);
233 interface Nested {
234 void m();
235 String toString();
236 }
237 }
239 @interface AT1 {
240 }
242 @interface AT2 {
243 }