test/tools/apt/mirror/declaration/PackageDecl.java

Tue, 25 May 2010 15:54:51 -0700

author
ohair
date
Tue, 25 May 2010 15:54:51 -0700
changeset 554
9d9f26857129
parent 174
fdfed22db054
permissions
-rw-r--r--

6943119: Rebrand source copyright notices
Reviewed-by: darcy

     1 /*
     2  * Copyright (c) 2004, 2008, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  */
    25 /*
    26  * @test
    27  * @bug 4853450 5031168
    28  * @summary PackageDeclaration tests
    29  * @library ../../lib
    30  * @compile -source 1.5 PackageDecl.java
    31  * @run main/othervm PackageDecl
    32  */
    35 import java.io.File;
    36 import java.util.*;
    37 import com.sun.mirror.declaration.*;
    38 import com.sun.mirror.type.*;
    39 import com.sun.mirror.util.*;
    41 import pkg1.pkg2.*;
    44 /**
    45  * Sed Quis custodiet ipsos custodes?
    46  */
    47 public class PackageDecl extends Tester {
    49     public PackageDecl() {
    50         super(System.getProperty("test.src", ".") + File.separator +
    51               "pkg1" + File.separator + "package-info.java");
    52     }
    54     public static void main(String[] args) {
    55         (new PackageDecl()).run();
    56     }
    59     private PackageDeclaration pkg1 = null;             // a package
    60     private PackageDeclaration pkg2 = null;             // a subpackage
    62     protected void init() {
    63         pkg1 = env.getPackage("pkg1");
    64         pkg2 = env.getPackage("pkg1.pkg2");
    65     }
    68     // Declaration methods
    70     @Test(result="package")
    71     Collection<String> accept() {
    72         final Collection<String> res = new ArrayList<String>();
    74         pkg1.accept(new SimpleDeclarationVisitor() {
    75             public void visitTypeDeclaration(TypeDeclaration t) {
    76                 res.add("type");
    77             }
    78             public void visitPackageDeclaration(PackageDeclaration p) {
    79                 res.add("package");
    80             }
    81         });
    82         return res;
    83     }
    85     @Test(result={"@pkg1.AnAnnoType"})
    86     Collection<AnnotationMirror> getAnnotationMirrors() {
    87         return pkg1.getAnnotationMirrors();
    88     }
    90     @Test(result=" Herein lieth the package comment.\n" +
    91                  " A doc comment it be, and wonderous to behold.\n")
    92     String getDocCommentFromPackageInfoFile() {
    93         return pkg1.getDocComment();
    94     }
    96     @Test(result="\nHerein lieth the package comment.\n" +
    97                  "An HTML file it be, and wonderous to behold.\n\n")
    98     @Ignore("Not yet supported")
    99     String getDocCommentFromHtmlFile() {
   100         return pkg2.getDocComment();
   101     }
   103     @Test(result={})
   104     Collection<Modifier> getModifiers() {
   105         return pkg1.getModifiers();
   106     }
   108     @Test(result="null")
   109     SourcePosition getPosition() {
   110         return thisClassDecl.getPackage().getPosition();
   111     }
   113     @Test(result="package-info.java")
   114     String getPositionFromPackageInfoFile() {
   115         return pkg1.getPosition().file().getName();
   116     }
   118     @Test(result="pkg1/pkg2/package.html")
   119     @Ignore("Not yet supported")
   120     String getPositionFromHtmlFile() {
   121         return pkg2.getPosition().file().getName()
   122                                             .replace(File.separatorChar, '/');
   123     }
   125     @Test(result="pkg1")
   126     String getSimpleName1() {
   127         return pkg1.getSimpleName();
   128     }
   130     @Test(result="pkg2")
   131     String getSimpleName2() {
   132         return pkg2.getSimpleName();
   133     }
   136     // PackageDeclaration methods
   138     @Test(result="pkg1.AnAnnoType")
   139     Collection<AnnotationTypeDeclaration> getAnnotationTypes() {
   140         return pkg1.getAnnotationTypes();
   141     }
   143     @Test(result={"pkg1.AClass", "pkg1.AnEnum"})
   144     Collection<ClassDeclaration> getClasses() {
   145         return pkg1.getClasses();
   146     }
   148     @Test(result="pkg1.AnEnum")
   149     Collection<EnumDeclaration> getEnums() {
   150         return pkg1.getEnums();
   151     }
   153     @Test(result={"pkg1.AnInterface", "pkg1.AnAnnoType"})
   154     Collection<InterfaceDeclaration> getInterfaces() {
   155         return pkg1.getInterfaces();
   156     }
   158     @Test(result="pkg1")
   159     String getQualifiedName1() {
   160         return pkg1.getQualifiedName();
   161     }
   163     @Test(result="pkg1.pkg2")
   164     String getQualifiedName2() {
   165         return pkg2.getQualifiedName();
   166     }
   167 }

mercurial