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

Mon, 15 Dec 2008 16:55:33 -0800

author
xdono
date
Mon, 15 Dec 2008 16:55:33 -0800
changeset 174
fdfed22db054
parent 132
a54ef8459576
child 554
9d9f26857129
permissions
-rw-r--r--

6785258: Update copyright year
Summary: Update copyright for files that have been modified starting July 2008 to Dec 2008
Reviewed-by: katleman, ohair, tbell

     1 /*
     2  * Copyright 2004-2008 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    20  * CA 95054 USA or visit www.sun.com if you need additional information or
    21  * have any questions.
    22  */
    25 /*
    26  * @test
    27  * @bug 4853450 4997614
    28  * @summary ClassDeclaration tests
    29  * @library ../../lib
    30  * @compile -source 1.5 ClassDecl.java
    31  * @run main/othervm ClassDecl
    32  */
    35 import java.io.Serializable;
    36 import java.util.*;
    37 import com.sun.mirror.declaration.*;
    38 import com.sun.mirror.type.*;
    39 import com.sun.mirror.util.*;
    42 /**
    43  * Sed Quis custodiet ipsos custodes?
    44  */
    45 @AT1
    46 @AT2
    47 public class ClassDecl extends Tester {
    49     public static void main(String[] args) {
    50         (new ClassDecl()).run();
    51     }
    54     private ClassDeclaration nested = null;     // a nested type
    55     private ClassDeclaration object = null;     // java.lang.object
    57     // A constructor to be found
    58     private ClassDecl() {
    59     }
    61     // Another constructor to be found
    62     private ClassDecl(int i) {
    63         this();
    64     }
    66     // An extra field to be found
    67     static int i;
    69     // Static initializer isn't among this class's methods.
    70     static {
    71         i = 7;
    72     }
    74     // A nested class with some accoutrements
    75     private static strictfp class NestedClass<T> implements Serializable {
    76         void m1() {}
    77         void m2() {}
    78         void m2(int i) {}
    79     }
    81     protected void init() {
    82         nested = (ClassDeclaration)
    83             thisClassDecl.getNestedTypes().iterator().next();
    84         object = (ClassDeclaration)
    85             env.getTypeDeclaration("java.lang.Object");
    86     }
    89     // Declaration methods
    91     @Test(result="class")
    92     Collection<String> accept() {
    93         final Collection<String> res = new ArrayList<String>();
    95         thisClassDecl.accept(new SimpleDeclarationVisitor() {
    96             public void visitTypeDeclaration(TypeDeclaration t) {
    97                 res.add("type");
    98             }
    99             public void visitClassDeclaration(ClassDeclaration c) {
   100                 res.add("class");
   101             }
   102             public void visitEnumDeclaration(EnumDeclaration e) {
   103                 res.add("enum");
   104             }
   105         });
   106         return res;
   107     }
   109     @Test(result={"@AT1", "@AT2"})
   110     Collection<AnnotationMirror> getAnnotationMirrors() {
   111         return thisClassDecl.getAnnotationMirrors();
   112     }
   114     @Test(result=" Sed Quis custodiet ipsos custodes?\n")
   115     String getDocComment() {
   116         return thisClassDecl.getDocComment();
   117     }
   119     @Test(result={"public"})
   120     Collection<Modifier> getModifiers1() {
   121         return thisClassDecl.getModifiers();
   122     }
   124     // Check that static nested class has "static" modifier, even though
   125     // the VM doesn't set that bit.
   126     @Test(result={"private", "static", "strictfp"})
   127     Collection<Modifier> getModifiers2() {
   128         return nested.getModifiers();
   129     }
   131     @Test(result="ClassDecl.java")
   132     String getPosition() {
   133         return thisClassDecl.getPosition().file().getName();
   134     }
   136     @Test(result="ClassDecl")
   137     String getSimpleName1() {
   138         return thisClassDecl.getSimpleName();
   139     }
   141     @Test(result="NestedClass")
   142     String getSimpleName2() {
   143         return nested.getSimpleName();
   144     }
   147     // MemberDeclaration method
   149     @Test(result="null")
   150     TypeDeclaration getDeclaringType1() {
   151         return thisClassDecl.getDeclaringType();
   152     }
   154     @Test(result="ClassDecl")
   155     TypeDeclaration getDeclaringType2() {
   156         return nested.getDeclaringType();
   157     }
   160     // TypeDeclaration methods
   162     @Test(result={"nested", "object", "i"})
   163     Collection<FieldDeclaration> getFields() {
   164         return thisClassDecl.getFields();
   165     }
   167     @Test(result={})
   168     Collection<TypeParameterDeclaration> getFormalTypeParameters1() {
   169         return thisClassDecl.getFormalTypeParameters();
   170     }
   172     @Test(result="T")
   173     Collection<TypeParameterDeclaration> getFormalTypeParameters2() {
   174         return nested.getFormalTypeParameters();
   175     }
   177     @Test(result="ClassDecl.NestedClass<T>")
   178     Collection<TypeDeclaration> getNestedTypes() {
   179         return thisClassDecl.getNestedTypes();
   180     }
   182     @Test(result="")
   183     PackageDeclaration getPackage1() {
   184         return thisClassDecl.getPackage();
   185     }
   187     @Test(result="java.lang")
   188     PackageDeclaration getPackage2() {
   189         return object.getPackage();
   190     }
   192     @Test(result="ClassDecl")
   193     String getQualifiedName1() {
   194         return thisClassDecl.getQualifiedName();
   195     }
   197     @Test(result="ClassDecl.NestedClass")
   198     String getQualifiedName2() {
   199         return nested.getQualifiedName();
   200     }
   202     @Test(result="java.lang.Object")
   203     String getQualifiedName3() {
   204         return object.getQualifiedName();
   205     }
   207     @Test(result="java.io.Serializable")
   208     Collection<InterfaceType> getSuperinterfaces() {
   209         return nested.getSuperinterfaces();
   210     }
   213     // ClassDeclaration methods
   215     @Test(result={"ClassDecl()", "ClassDecl(int)"})
   216     Collection<ConstructorDeclaration> getConstructors1() {
   217         return thisClassDecl.getConstructors();
   218     }
   220     // Check for default constructor.
   221     // 4997614: visitConstructionDeclaration reports info when there is no ctor
   222     @Test(result={"NestedClass()"})
   223     Collection<ConstructorDeclaration> getConstructors2() {
   224         return nested.getConstructors();
   225     }
   227     @Test(result={"m1()", "m2()", "m2(int)"})
   228     Collection<MethodDeclaration> getMethods() {
   229         return nested.getMethods();
   230     }
   232     @Test(result={"Tester"})
   233     ClassType getSuperclass() {
   234         return thisClassDecl.getSuperclass();
   235     }
   237     @Test(result={"null"})
   238     ClassType objectHasNoSuperclass() {
   239         return object.getSuperclass();
   240     }
   241 }
   244 // Annotations used for testing.
   246 @interface AT1 {
   247 }
   249 @interface AT2 {
   250 }

mercurial