1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/tools/apt/mirror/declaration/InterfaceDecl.java Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,243 @@ 1.4 +/* 1.5 + * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + */ 1.26 + 1.27 + 1.28 +/* 1.29 + * @test 1.30 + * @bug 4853450 4993303 5004618 5010746 1.31 + * @summary InterfaceDeclaration tests 1.32 + * @library ../../lib 1.33 + * @compile -source 1.5 InterfaceDecl.java 1.34 + * @run main InterfaceDecl 1.35 + */ 1.36 + 1.37 + 1.38 +import java.util.*; 1.39 +import com.sun.mirror.declaration.*; 1.40 +import com.sun.mirror.type.*; 1.41 +import com.sun.mirror.util.*; 1.42 + 1.43 + 1.44 +/** 1.45 + * Sed Quis custodiet ipsos custodes? 1.46 + */ 1.47 +@AT1 1.48 +@AT2 1.49 +public class InterfaceDecl extends Tester { 1.50 + 1.51 + public static void main(String[] args) { 1.52 + (new InterfaceDecl()).run(); 1.53 + } 1.54 + 1.55 + 1.56 + private InterfaceDeclaration iDecl = null; // an interface 1.57 + private InterfaceDeclaration nested = null; // a nested interface 1.58 + 1.59 + protected void init() { 1.60 + iDecl = (InterfaceDeclaration) env.getTypeDeclaration("I"); 1.61 + nested = (InterfaceDeclaration) 1.62 + iDecl.getNestedTypes().iterator().next(); 1.63 + } 1.64 + 1.65 + 1.66 + // Declaration methods 1.67 + 1.68 + @Test(result="interface") 1.69 + Collection<String> accept() { 1.70 + final Collection<String> res = new ArrayList<String>(); 1.71 + 1.72 + iDecl.accept(new SimpleDeclarationVisitor() { 1.73 + public void visitTypeDeclaration(TypeDeclaration t) { 1.74 + res.add("type"); 1.75 + } 1.76 + public void visitClassDeclaration(ClassDeclaration c) { 1.77 + res.add("class"); 1.78 + } 1.79 + public void visitInterfaceDeclaration(InterfaceDeclaration e) { 1.80 + res.add("interface"); 1.81 + } 1.82 + public void visitAnnotationTypeDeclaration( 1.83 + AnnotationTypeDeclaration e) { 1.84 + res.add("annotation type"); 1.85 + } 1.86 + }); 1.87 + return res; 1.88 + } 1.89 + 1.90 + @Test(result="true") 1.91 + boolean equals1() { 1.92 + return iDecl.equals(iDecl); 1.93 + } 1.94 + 1.95 + @Test(result="false") 1.96 + boolean equals2() { 1.97 + return iDecl.equals(nested); 1.98 + } 1.99 + 1.100 + @Test(result="true") 1.101 + boolean equals3() { 1.102 + return iDecl.equals(env.getTypeDeclaration("I")); 1.103 + } 1.104 + 1.105 + 1.106 + @Test(result={"@AT1", "@AT2"}) 1.107 + Collection<AnnotationMirror> getAnnotationMirrors() { 1.108 + return iDecl.getAnnotationMirrors(); 1.109 + } 1.110 + 1.111 + @Test(result=" Sed Quis custodiet ipsos custodes?\n") 1.112 + String getDocComment() { 1.113 + return iDecl.getDocComment(); 1.114 + } 1.115 + 1.116 + // Check that interface has "abstract" modifier, even though it's implict 1.117 + // in the source code. 1.118 + @Test(result={"abstract"}) 1.119 + Collection<Modifier> getModifiers1() { 1.120 + return iDecl.getModifiers(); 1.121 + } 1.122 + 1.123 + // Check that nested interface has "static" modifier, even though 1.124 + // it's implicit in the source code and the VM doesn't set that bit. 1.125 + @Test(result={"public", "abstract", "static"}) 1.126 + Collection<Modifier> getModifiers2() { 1.127 + return nested.getModifiers(); 1.128 + } 1.129 + 1.130 + @Test(result="InterfaceDecl.java") 1.131 + String getPosition() { 1.132 + return iDecl.getPosition().file().getName(); 1.133 + } 1.134 + 1.135 + @Test(result="I") 1.136 + String getSimpleName1() { 1.137 + return iDecl.getSimpleName(); 1.138 + } 1.139 + 1.140 + @Test(result="Nested") 1.141 + String getSimpleName2() { 1.142 + return nested.getSimpleName(); 1.143 + } 1.144 + 1.145 + 1.146 + // MemberDeclaration method 1.147 + 1.148 + @Test(result="null") 1.149 + TypeDeclaration getDeclaringType1() { 1.150 + return iDecl.getDeclaringType(); 1.151 + } 1.152 + 1.153 + @Test(result="I<T extends java.lang.Number>") 1.154 + TypeDeclaration getDeclaringType2() { 1.155 + return nested.getDeclaringType(); 1.156 + } 1.157 + 1.158 + 1.159 + // TypeDeclaration methods 1.160 + 1.161 + @Test(result={"i"}) 1.162 + Collection<FieldDeclaration> getFields() { 1.163 + return iDecl.getFields(); 1.164 + } 1.165 + 1.166 + @Test(result={"T extends java.lang.Number"}) 1.167 + Collection<TypeParameterDeclaration> getFormalTypeParameters1() { 1.168 + return iDecl.getFormalTypeParameters(); 1.169 + } 1.170 + 1.171 + @Test(result={}) 1.172 + Collection<TypeParameterDeclaration> getFormalTypeParameters2() { 1.173 + return nested.getFormalTypeParameters(); 1.174 + } 1.175 + 1.176 + // 4993303: verify policy on Object methods being visible 1.177 + @Test(result={"m()", "toString()"}) 1.178 + Collection<? extends MethodDeclaration> getMethods() { 1.179 + return nested.getMethods(); 1.180 + } 1.181 + 1.182 + @Test(result="I.Nested") 1.183 + Collection<TypeDeclaration> getNestedTypes() { 1.184 + return iDecl.getNestedTypes(); 1.185 + } 1.186 + 1.187 + @Test(result="") 1.188 + PackageDeclaration getPackage1() { 1.189 + return iDecl.getPackage(); 1.190 + } 1.191 + 1.192 + @Test(result="java.util") 1.193 + PackageDeclaration getPackage2() { 1.194 + InterfaceDeclaration set = 1.195 + (InterfaceDeclaration) env.getTypeDeclaration("java.util.Set"); 1.196 + return set.getPackage(); 1.197 + } 1.198 + 1.199 + @Test(result="I") 1.200 + String getQualifiedName1() { 1.201 + return iDecl.getQualifiedName(); 1.202 + } 1.203 + 1.204 + @Test(result="I.Nested") 1.205 + String getQualifiedName2() { 1.206 + return nested.getQualifiedName(); 1.207 + } 1.208 + 1.209 + @Test(result="java.util.Set") 1.210 + String getQualifiedName3() { 1.211 + InterfaceDeclaration set = 1.212 + (InterfaceDeclaration) env.getTypeDeclaration("java.util.Set"); 1.213 + return set.getQualifiedName(); 1.214 + } 1.215 + 1.216 + @Test(result="java.lang.Runnable") 1.217 + Collection<InterfaceType> getSuperinterfaces() { 1.218 + return iDecl.getSuperinterfaces(); 1.219 + } 1.220 +} 1.221 + 1.222 + 1.223 +// Interfaces used for testing. 1.224 + 1.225 +/** 1.226 + * Sed Quis custodiet ipsos custodes? 1.227 + */ 1.228 +@AT1 1.229 +@AT2 1.230 +interface I<T extends Number> extends Runnable { 1.231 + int i = 6; 1.232 + void m1(); 1.233 + void m2(); 1.234 + void m2(int j); 1.235 + 1.236 + interface Nested { 1.237 + void m(); 1.238 + String toString(); 1.239 + } 1.240 +} 1.241 + 1.242 +@interface AT1 { 1.243 +} 1.244 + 1.245 +@interface AT2 { 1.246 +}