langtools/test/tools/apt/mirror/declaration/PackageDecl.java
changeset 11914 d1311b0c757f
parent 11913 be61e1597cc6
parent 11872 c51754cddc03
child 11915 33f703959597
child 11986 6f383069eb6d
equal deleted inserted replaced
11913:be61e1597cc6 11914:d1311b0c757f
     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  */
       
    23 
       
    24 
       
    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  */
       
    33 
       
    34 
       
    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.*;
       
    40 
       
    41 import pkg1.pkg2.*;
       
    42 
       
    43 
       
    44 /**
       
    45  * Sed Quis custodiet ipsos custodes?
       
    46  */
       
    47 public class PackageDecl extends Tester {
       
    48 
       
    49     public PackageDecl() {
       
    50         super(System.getProperty("test.src", ".") + File.separator +
       
    51               "pkg1" + File.separator + "package-info.java");
       
    52     }
       
    53 
       
    54     public static void main(String[] args) {
       
    55         (new PackageDecl()).run();
       
    56     }
       
    57 
       
    58 
       
    59     private PackageDeclaration pkg1 = null;             // a package
       
    60     private PackageDeclaration pkg2 = null;             // a subpackage
       
    61 
       
    62     protected void init() {
       
    63         pkg1 = env.getPackage("pkg1");
       
    64         pkg2 = env.getPackage("pkg1.pkg2");
       
    65     }
       
    66 
       
    67 
       
    68     // Declaration methods
       
    69 
       
    70     @Test(result="package")
       
    71     Collection<String> accept() {
       
    72         final Collection<String> res = new ArrayList<String>();
       
    73 
       
    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     }
       
    84 
       
    85     @Test(result={"@pkg1.AnAnnoType"})
       
    86     Collection<AnnotationMirror> getAnnotationMirrors() {
       
    87         return pkg1.getAnnotationMirrors();
       
    88     }
       
    89 
       
    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     }
       
    95 
       
    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     }
       
   102 
       
   103     @Test(result={})
       
   104     Collection<Modifier> getModifiers() {
       
   105         return pkg1.getModifiers();
       
   106     }
       
   107 
       
   108     @Test(result="null")
       
   109     SourcePosition getPosition() {
       
   110         return thisClassDecl.getPackage().getPosition();
       
   111     }
       
   112 
       
   113     @Test(result="package-info.java")
       
   114     String getPositionFromPackageInfoFile() {
       
   115         return pkg1.getPosition().file().getName();
       
   116     }
       
   117 
       
   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     }
       
   124 
       
   125     @Test(result="pkg1")
       
   126     String getSimpleName1() {
       
   127         return pkg1.getSimpleName();
       
   128     }
       
   129 
       
   130     @Test(result="pkg2")
       
   131     String getSimpleName2() {
       
   132         return pkg2.getSimpleName();
       
   133     }
       
   134 
       
   135 
       
   136     // PackageDeclaration methods
       
   137 
       
   138     @Test(result="pkg1.AnAnnoType")
       
   139     Collection<AnnotationTypeDeclaration> getAnnotationTypes() {
       
   140         return pkg1.getAnnotationTypes();
       
   141     }
       
   142 
       
   143     @Test(result={"pkg1.AClass", "pkg1.AnEnum"})
       
   144     Collection<ClassDeclaration> getClasses() {
       
   145         return pkg1.getClasses();
       
   146     }
       
   147 
       
   148     @Test(result="pkg1.AnEnum")
       
   149     Collection<EnumDeclaration> getEnums() {
       
   150         return pkg1.getEnums();
       
   151     }
       
   152 
       
   153     @Test(result={"pkg1.AnInterface", "pkg1.AnAnnoType"})
       
   154     Collection<InterfaceDeclaration> getInterfaces() {
       
   155         return pkg1.getInterfaces();
       
   156     }
       
   157 
       
   158     @Test(result="pkg1")
       
   159     String getQualifiedName1() {
       
   160         return pkg1.getQualifiedName();
       
   161     }
       
   162 
       
   163     @Test(result="pkg1.pkg2")
       
   164     String getQualifiedName2() {
       
   165         return pkg2.getQualifiedName();
       
   166     }
       
   167 }