1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/tools/apt/mirror/declaration/ConstructorDecl.java Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,199 @@ 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 4993299 1.31 + * @summary ConstructorDeclaration tests 1.32 + * @library ../../lib 1.33 + * @compile -source 1.5 ConstructorDecl.java 1.34 + * @run main ConstructorDecl 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 +public class ConstructorDecl extends Tester { 1.45 + 1.46 + /** 1.47 + * Sed Quis custodiet ipsos custodes? 1.48 + */ 1.49 + @AT1 1.50 + public ConstructorDecl() { 1.51 + } 1.52 + 1.53 + 1.54 + public static void main(String[] args) { 1.55 + (new ConstructorDecl()).run(); 1.56 + } 1.57 + 1.58 + 1.59 + private ConstructorDeclaration ctor = null; // a constructor 1.60 + private ConstructorDeclaration ctorDef = null; // a default c'tor 1.61 + private ConstructorDeclaration ctorInner = null; // an inner class c'tor 1.62 + 1.63 + protected void init() { 1.64 + ctor = getAConstructor(thisClassDecl); 1.65 + ctorDef = getAConstructor((ClassDeclaration) 1.66 + env.getTypeDeclaration("C1")); 1.67 + ctorInner = getAConstructor((ClassDeclaration) 1.68 + env.getTypeDeclaration("C1.C2")); 1.69 + } 1.70 + 1.71 + // Return a constructor of a class. 1.72 + private ConstructorDeclaration getAConstructor(ClassDeclaration c) { 1.73 + return c.getConstructors().iterator().next(); 1.74 + } 1.75 + 1.76 + 1.77 + // Declaration methods 1.78 + 1.79 + @Test(result="constructor") 1.80 + Collection<String> accept() { 1.81 + final Collection<String> res = new ArrayList<String>(); 1.82 + 1.83 + ctor.accept(new SimpleDeclarationVisitor() { 1.84 + public void visitTypeDeclaration(TypeDeclaration t) { 1.85 + res.add("type"); 1.86 + } 1.87 + public void visitExecutableDeclaration(ExecutableDeclaration e) { 1.88 + res.add("executable"); 1.89 + } 1.90 + public void visitConstructorDeclaration(ConstructorDeclaration c) { 1.91 + res.add("constructor"); 1.92 + } 1.93 + }); 1.94 + return res; 1.95 + } 1.96 + 1.97 + @Test(result={"@AT1"}) 1.98 + Collection<AnnotationMirror> getAnnotationMirrors() { 1.99 + return ctor.getAnnotationMirrors(); 1.100 + } 1.101 + 1.102 + @Test(result=" Sed Quis custodiet ipsos custodes?\n") 1.103 + String getDocComment() { 1.104 + return ctor.getDocComment(); 1.105 + } 1.106 + 1.107 + @Test(result={"public"}) 1.108 + Collection<Modifier> getModifiers() { 1.109 + return ctor.getModifiers(); 1.110 + } 1.111 + 1.112 + @Test(result="ConstructorDecl.java") 1.113 + String getPosition() { 1.114 + return ctor.getPosition().file().getName(); 1.115 + } 1.116 + 1.117 + @Test(result="ConstructorDecl.java") 1.118 + String getPositionDefault() { 1.119 + return ctorDef.getPosition().file().getName(); 1.120 + } 1.121 + 1.122 + @Test(result="ConstructorDecl") 1.123 + String getSimpleName() { 1.124 + return ctor.getSimpleName(); 1.125 + } 1.126 + 1.127 + @Test(result="C2") 1.128 + String getSimpleNameInner() { 1.129 + return ctorInner.getSimpleName(); 1.130 + } 1.131 + 1.132 + 1.133 + // MemberDeclaration method 1.134 + 1.135 + @Test(result="ConstructorDecl") 1.136 + TypeDeclaration getDeclaringType() { 1.137 + return ctor.getDeclaringType(); 1.138 + } 1.139 + 1.140 + 1.141 + // ExecutableDeclaration methods 1.142 + 1.143 + @Test(result={}) 1.144 + Collection<TypeParameterDeclaration> getFormalTypeParameters1() { 1.145 + return ctor.getFormalTypeParameters(); 1.146 + } 1.147 + 1.148 + @Test(result={"N extends java.lang.Number"}) 1.149 + Collection<TypeParameterDeclaration> getFormalTypeParameters2() { 1.150 + return ctorInner.getFormalTypeParameters(); 1.151 + } 1.152 + 1.153 + @Test(result={}) 1.154 + Collection<ParameterDeclaration> getParameters1() { 1.155 + return ctor.getParameters(); 1.156 + } 1.157 + 1.158 + // 4993299: verify synthetic parameters to inner class constructors 1.159 + // aren't visible 1.160 + @Test(result={"N n1", "N n2", "java.lang.String[] ss"}, 1.161 + ordered=true) 1.162 + Collection<ParameterDeclaration> getParameters2() { 1.163 + return ctorInner.getParameters(); 1.164 + } 1.165 + 1.166 + @Test(result={"java.lang.Throwable"}) 1.167 + Collection<ReferenceType> getThrownTypes() { 1.168 + return ctorInner.getThrownTypes(); 1.169 + } 1.170 + 1.171 + @Test(result="false") 1.172 + Boolean isVarArgs1() { 1.173 + return ctor.isVarArgs(); 1.174 + } 1.175 + 1.176 + @Test(result="true") 1.177 + Boolean isVarArgs2() { 1.178 + return ctorInner.isVarArgs(); 1.179 + } 1.180 + 1.181 + 1.182 + // toString 1.183 + 1.184 + @Test(result="<N extends java.lang.Number> C2(N, N, String...)") 1.185 + @Ignore("This is what it would be nice to see.") 1.186 + String toStringTest() { 1.187 + return ctorInner.toString(); 1.188 + } 1.189 +} 1.190 + 1.191 + 1.192 +// Classes and interfaces used for testing. 1.193 + 1.194 +class C1 { 1.195 + class C2 { 1.196 + <N extends Number> C2(N n1, N n2, String... ss) throws Throwable { 1.197 + } 1.198 + } 1.199 +} 1.200 + 1.201 +@interface AT1 { 1.202 +}