duke@1: /* ohair@554: * Copyright (c) 2004, 2008, Oracle and/or its affiliates. All rights reserved. duke@1: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@1: * duke@1: * This code is free software; you can redistribute it and/or modify it duke@1: * under the terms of the GNU General Public License version 2 only, as duke@1: * published by the Free Software Foundation. duke@1: * duke@1: * This code is distributed in the hope that it will be useful, but WITHOUT duke@1: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@1: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@1: * version 2 for more details (a copy is included in the LICENSE file that duke@1: * accompanied this code). duke@1: * duke@1: * You should have received a copy of the GNU General Public License version duke@1: * 2 along with this work; if not, write to the Free Software Foundation, duke@1: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@1: * ohair@554: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@554: * or visit www.oracle.com if you need additional information or have any ohair@554: * questions. duke@1: */ duke@1: duke@1: duke@1: /* duke@1: * @test duke@1: * @bug 4853450 5031168 duke@1: * @summary PackageDeclaration tests duke@1: * @library ../../lib duke@1: * @compile -source 1.5 PackageDecl.java jjg@132: * @run main/othervm PackageDecl duke@1: */ duke@1: duke@1: duke@1: import java.io.File; duke@1: import java.util.*; duke@1: import com.sun.mirror.declaration.*; duke@1: import com.sun.mirror.type.*; duke@1: import com.sun.mirror.util.*; duke@1: duke@1: import pkg1.pkg2.*; duke@1: duke@1: duke@1: /** duke@1: * Sed Quis custodiet ipsos custodes? duke@1: */ duke@1: public class PackageDecl extends Tester { duke@1: duke@1: public PackageDecl() { duke@1: super(System.getProperty("test.src", ".") + File.separator + duke@1: "pkg1" + File.separator + "package-info.java"); duke@1: } duke@1: duke@1: public static void main(String[] args) { duke@1: (new PackageDecl()).run(); duke@1: } duke@1: duke@1: duke@1: private PackageDeclaration pkg1 = null; // a package duke@1: private PackageDeclaration pkg2 = null; // a subpackage duke@1: duke@1: protected void init() { duke@1: pkg1 = env.getPackage("pkg1"); duke@1: pkg2 = env.getPackage("pkg1.pkg2"); duke@1: } duke@1: duke@1: duke@1: // Declaration methods duke@1: duke@1: @Test(result="package") duke@1: Collection accept() { duke@1: final Collection res = new ArrayList(); duke@1: duke@1: pkg1.accept(new SimpleDeclarationVisitor() { duke@1: public void visitTypeDeclaration(TypeDeclaration t) { duke@1: res.add("type"); duke@1: } duke@1: public void visitPackageDeclaration(PackageDeclaration p) { duke@1: res.add("package"); duke@1: } duke@1: }); duke@1: return res; duke@1: } duke@1: duke@1: @Test(result={"@pkg1.AnAnnoType"}) duke@1: Collection getAnnotationMirrors() { duke@1: return pkg1.getAnnotationMirrors(); duke@1: } duke@1: duke@1: @Test(result=" Herein lieth the package comment.\n" + duke@1: " A doc comment it be, and wonderous to behold.\n") duke@1: String getDocCommentFromPackageInfoFile() { duke@1: return pkg1.getDocComment(); duke@1: } duke@1: duke@1: @Test(result="\nHerein lieth the package comment.\n" + duke@1: "An HTML file it be, and wonderous to behold.\n\n") duke@1: @Ignore("Not yet supported") duke@1: String getDocCommentFromHtmlFile() { duke@1: return pkg2.getDocComment(); duke@1: } duke@1: duke@1: @Test(result={}) duke@1: Collection getModifiers() { duke@1: return pkg1.getModifiers(); duke@1: } duke@1: duke@1: @Test(result="null") duke@1: SourcePosition getPosition() { duke@1: return thisClassDecl.getPackage().getPosition(); duke@1: } duke@1: duke@1: @Test(result="package-info.java") duke@1: String getPositionFromPackageInfoFile() { duke@1: return pkg1.getPosition().file().getName(); duke@1: } duke@1: duke@1: @Test(result="pkg1/pkg2/package.html") duke@1: @Ignore("Not yet supported") duke@1: String getPositionFromHtmlFile() { duke@1: return pkg2.getPosition().file().getName() duke@1: .replace(File.separatorChar, '/'); duke@1: } duke@1: duke@1: @Test(result="pkg1") duke@1: String getSimpleName1() { duke@1: return pkg1.getSimpleName(); duke@1: } duke@1: duke@1: @Test(result="pkg2") duke@1: String getSimpleName2() { duke@1: return pkg2.getSimpleName(); duke@1: } duke@1: duke@1: duke@1: // PackageDeclaration methods duke@1: duke@1: @Test(result="pkg1.AnAnnoType") duke@1: Collection getAnnotationTypes() { duke@1: return pkg1.getAnnotationTypes(); duke@1: } duke@1: duke@1: @Test(result={"pkg1.AClass", "pkg1.AnEnum"}) duke@1: Collection getClasses() { duke@1: return pkg1.getClasses(); duke@1: } duke@1: duke@1: @Test(result="pkg1.AnEnum") duke@1: Collection getEnums() { duke@1: return pkg1.getEnums(); duke@1: } duke@1: duke@1: @Test(result={"pkg1.AnInterface", "pkg1.AnAnnoType"}) duke@1: Collection getInterfaces() { duke@1: return pkg1.getInterfaces(); duke@1: } duke@1: duke@1: @Test(result="pkg1") duke@1: String getQualifiedName1() { duke@1: return pkg1.getQualifiedName(); duke@1: } duke@1: duke@1: @Test(result="pkg1.pkg2") duke@1: String getQualifiedName2() { duke@1: return pkg2.getQualifiedName(); duke@1: } duke@1: }