1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/tools/apt/mirror/declaration/PackageDecl.java Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,167 @@ 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 5031168 1.31 + * @summary PackageDeclaration tests 1.32 + * @library ../../lib 1.33 + * @compile -source 1.5 PackageDecl.java 1.34 + * @run main PackageDecl 1.35 + */ 1.36 + 1.37 + 1.38 +import java.io.File; 1.39 +import java.util.*; 1.40 +import com.sun.mirror.declaration.*; 1.41 +import com.sun.mirror.type.*; 1.42 +import com.sun.mirror.util.*; 1.43 + 1.44 +import pkg1.pkg2.*; 1.45 + 1.46 + 1.47 +/** 1.48 + * Sed Quis custodiet ipsos custodes? 1.49 + */ 1.50 +public class PackageDecl extends Tester { 1.51 + 1.52 + public PackageDecl() { 1.53 + super(System.getProperty("test.src", ".") + File.separator + 1.54 + "pkg1" + File.separator + "package-info.java"); 1.55 + } 1.56 + 1.57 + public static void main(String[] args) { 1.58 + (new PackageDecl()).run(); 1.59 + } 1.60 + 1.61 + 1.62 + private PackageDeclaration pkg1 = null; // a package 1.63 + private PackageDeclaration pkg2 = null; // a subpackage 1.64 + 1.65 + protected void init() { 1.66 + pkg1 = env.getPackage("pkg1"); 1.67 + pkg2 = env.getPackage("pkg1.pkg2"); 1.68 + } 1.69 + 1.70 + 1.71 + // Declaration methods 1.72 + 1.73 + @Test(result="package") 1.74 + Collection<String> accept() { 1.75 + final Collection<String> res = new ArrayList<String>(); 1.76 + 1.77 + pkg1.accept(new SimpleDeclarationVisitor() { 1.78 + public void visitTypeDeclaration(TypeDeclaration t) { 1.79 + res.add("type"); 1.80 + } 1.81 + public void visitPackageDeclaration(PackageDeclaration p) { 1.82 + res.add("package"); 1.83 + } 1.84 + }); 1.85 + return res; 1.86 + } 1.87 + 1.88 + @Test(result={"@pkg1.AnAnnoType"}) 1.89 + Collection<AnnotationMirror> getAnnotationMirrors() { 1.90 + return pkg1.getAnnotationMirrors(); 1.91 + } 1.92 + 1.93 + @Test(result=" Herein lieth the package comment.\n" + 1.94 + " A doc comment it be, and wonderous to behold.\n") 1.95 + String getDocCommentFromPackageInfoFile() { 1.96 + return pkg1.getDocComment(); 1.97 + } 1.98 + 1.99 + @Test(result="\nHerein lieth the package comment.\n" + 1.100 + "An HTML file it be, and wonderous to behold.\n\n") 1.101 + @Ignore("Not yet supported") 1.102 + String getDocCommentFromHtmlFile() { 1.103 + return pkg2.getDocComment(); 1.104 + } 1.105 + 1.106 + @Test(result={}) 1.107 + Collection<Modifier> getModifiers() { 1.108 + return pkg1.getModifiers(); 1.109 + } 1.110 + 1.111 + @Test(result="null") 1.112 + SourcePosition getPosition() { 1.113 + return thisClassDecl.getPackage().getPosition(); 1.114 + } 1.115 + 1.116 + @Test(result="package-info.java") 1.117 + String getPositionFromPackageInfoFile() { 1.118 + return pkg1.getPosition().file().getName(); 1.119 + } 1.120 + 1.121 + @Test(result="pkg1/pkg2/package.html") 1.122 + @Ignore("Not yet supported") 1.123 + String getPositionFromHtmlFile() { 1.124 + return pkg2.getPosition().file().getName() 1.125 + .replace(File.separatorChar, '/'); 1.126 + } 1.127 + 1.128 + @Test(result="pkg1") 1.129 + String getSimpleName1() { 1.130 + return pkg1.getSimpleName(); 1.131 + } 1.132 + 1.133 + @Test(result="pkg2") 1.134 + String getSimpleName2() { 1.135 + return pkg2.getSimpleName(); 1.136 + } 1.137 + 1.138 + 1.139 + // PackageDeclaration methods 1.140 + 1.141 + @Test(result="pkg1.AnAnnoType") 1.142 + Collection<AnnotationTypeDeclaration> getAnnotationTypes() { 1.143 + return pkg1.getAnnotationTypes(); 1.144 + } 1.145 + 1.146 + @Test(result={"pkg1.AClass", "pkg1.AnEnum"}) 1.147 + Collection<ClassDeclaration> getClasses() { 1.148 + return pkg1.getClasses(); 1.149 + } 1.150 + 1.151 + @Test(result="pkg1.AnEnum") 1.152 + Collection<EnumDeclaration> getEnums() { 1.153 + return pkg1.getEnums(); 1.154 + } 1.155 + 1.156 + @Test(result={"pkg1.AnInterface", "pkg1.AnAnnoType"}) 1.157 + Collection<InterfaceDeclaration> getInterfaces() { 1.158 + return pkg1.getInterfaces(); 1.159 + } 1.160 + 1.161 + @Test(result="pkg1") 1.162 + String getQualifiedName1() { 1.163 + return pkg1.getQualifiedName(); 1.164 + } 1.165 + 1.166 + @Test(result="pkg1.pkg2") 1.167 + String getQualifiedName2() { 1.168 + return pkg2.getQualifiedName(); 1.169 + } 1.170 +}