test/tools/apt/mirror/type/ClassTyp.java

Wed, 15 Oct 2008 17:23:55 +0100

author
mcimadamore
date
Wed, 15 Oct 2008 17:23:55 +0100
changeset 141
83ffdd1a6294
parent 132
a54ef8459576
child 174
fdfed22db054
permissions
-rw-r--r--

6759682: APT: compiler message file broken after refactoring of com.sun.tools.javac.util.Message
Summary: JavacMessages should refresh its own bundle cache when a new resource bundle is added by APT
Reviewed-by: jjg

     1 /*
     2  * Copyright 2004-2007 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 5009360 5055963
    28  * @summary ClassType tests
    29  * @library ../../lib
    30  * @run main/othervm ClassTyp
    31  */
    34 import java.util.*;
    35 import com.sun.mirror.declaration.*;
    36 import com.sun.mirror.type.*;
    37 import com.sun.mirror.util.*;
    40 public class ClassTyp<T1,T2> extends Tester {
    42     public static void main(String[] args) {
    43         (new ClassTyp()).run();
    44     }
    47     // Declarations used by tests
    49     static class C1<S> extends AbstractSet<S> implements Set<S> {
    50         class C2<R> {
    51         }
    53         static class C3<R> {
    54             class C4<Q> {
    55             }
    56         }
    58         public Iterator<S> iterator() {
    59             return null;
    60         }
    62         public int size() {
    63             return 0;
    64         }
    65     }
    68     // Generate some class types to test.
    69     private C1<T1> f0;
    70     private C1<String> f1;
    71     private C1 f2;
    72     private C1.C3<T2> f3;
    73     private C1<T1>.C2<T2> f4;
    74     private C1.C2 f5;
    75     private C1<T1> f6;
    76     private C1.C3<T2>.C4<T1> f7;
    77     private static final int NUMTYPES = 8;
    79     // Type mirrors corresponding to the types of the above fields
    80     private ClassType[] t = new ClassType[NUMTYPES];
    82     // One more type:  our own.
    83     private ClassTyp<T1,T2> me = this;
    86     protected void init() {
    87         for (int i = 0; i < t.length; i++) {
    88             t[i] = (ClassType) getField("f"+i).getType();
    89         }
    90     }
    93     // TypeMirror methods
    95     @Test(result="class")
    96     Collection<String> accept() {
    97         final Collection<String> res = new ArrayList<String>();
    99         t[0].accept(new SimpleTypeVisitor() {
   100             public void visitReferenceType(ReferenceType t) {
   101                 res.add("ref type");
   102             }
   103             public void visitClassType(ClassType t) {
   104                 res.add("class");
   105             }
   106             public void visitInterfaceType(InterfaceType t) {
   107                 res.add("interface");
   108             }
   109         });
   110         return res;
   111     }
   113     @Test(result="true")
   114     boolean equals1() {
   115         return t[0].equals(t[0]);
   116     }
   118     @Test(result="false")
   119     boolean equals2() {
   120         return t[0].equals(t[1]);
   121     }
   123     // Raw type is not same as type instantiated with unbounded type var.
   124     @Test(result="false")
   125     boolean equals3() {
   126         return t[0].equals(t[2]);
   127     }
   129     // C1<T1> is same type as C1<T1>
   130     @Test(result="true")
   131     boolean equals4() {
   132         return t[0].equals(t[6]);
   133     }
   135     @Test(result={
   136               "ClassTyp.C1<T1>",
   137               "ClassTyp.C1<java.lang.String>",
   138               "ClassTyp.C1",
   139               "ClassTyp.C1.C3<T2>",
   140               "ClassTyp.C1<T1>.C2<T2>",
   141               "ClassTyp.C1.C2",
   142               "ClassTyp.C1<T1>",
   143               "ClassTyp.C1.C3<T2>.C4<T1>"
   144           },
   145           ordered=true)
   146     Collection<String> toStringTests() {
   147         Collection<String> res = new ArrayList<String>();
   148         for (ClassType c : t) {
   149             res.add(c.toString());
   150         }
   151         return res;
   152     }
   155     // DeclaredType methods
   157     @Test(result={"T1"})
   158     Collection<TypeMirror> getActualTypeArguments1() {
   159         return t[0].getActualTypeArguments();
   160     }
   162     @Test(result={})
   163     Collection<TypeMirror> getActualTypeArguments2() {
   164         return t[2].getActualTypeArguments();
   165     }
   167     @Test(result={"T2"})
   168     Collection<TypeMirror> getActualTypeArguments3() {
   169         return t[3].getActualTypeArguments();
   170     }
   172     @Test(result="null")
   173     DeclaredType getContainingType1() {
   174         ClassType thisType = (ClassType) getField("me").getType();
   175         return thisType.getContainingType();
   176     }
   178     @Test(result="ClassTyp")
   179     DeclaredType getContainingType2() {
   180         return t[0].getContainingType();
   181     }
   183     @Test(result="ClassTyp.C1")
   184     DeclaredType getContainingType3() {
   185         return t[3].getContainingType();
   186     }
   188     @Test(result="ClassTyp.C1<T1>")
   189     DeclaredType getContainingType4() {
   190         return t[4].getContainingType();
   191     }
   193     @Test(result={"java.util.Set<T1>"})
   194     Collection<InterfaceType> getSuperinterfaces() {
   195         return t[0].getSuperinterfaces();
   196     }
   199     // ClassType methods
   201     @Test(result="ClassTyp.C1<S>")
   202     ClassDeclaration getDeclaration1() {
   203         return t[0].getDeclaration();
   204     }
   206     @Test(result="ClassTyp.C1.C3<R>")
   207     ClassDeclaration getDeclaration2() {
   208         return t[3].getDeclaration();
   209     }
   211     @Test(result="ClassTyp.C1<S>.C2<R>")
   212     ClassDeclaration getDeclaration3a() {
   213         return t[4].getDeclaration();
   214     }
   216     @Test(result="ClassTyp.C1<S>.C2<R>")
   217     ClassDeclaration getDeclaration3b() {
   218         return t[5].getDeclaration();
   219     }
   221     @Test(result="true")
   222     boolean getDeclarationEq() {
   223         return t[0].getDeclaration() == t[6].getDeclaration();
   224     }
   226     @Test(result="java.util.AbstractSet<T1>")
   227     ClassType getSuperclass1() {
   228         return t[0].getSuperclass();
   229     }
   231     @Test(result="java.lang.Object")
   232     ClassType getSuperclass2() {
   233         return t[4].getSuperclass();
   234     }
   236     @Test(result="null")
   237     ClassType getSuperclassOfObject() {
   238         return t[4].getSuperclass().getSuperclass();
   239     }
   240 }

mercurial