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

Sat, 01 Dec 2007 00:00:00 +0000

author
duke
date
Sat, 01 Dec 2007 00:00:00 +0000
changeset 1
9a66ca7c79fa
child 132
a54ef8459576
permissions
-rw-r--r--

Initial load

     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
    28  * @summary TypeVariable tests
    29  * @library ../../lib
    30  * @compile -source 1.5 TypeVar.java
    31  * @run main TypeVar
    32  */
    35 import java.util.*;
    36 import com.sun.mirror.declaration.*;
    37 import com.sun.mirror.type.*;
    38 import com.sun.mirror.util.*;
    41 public class TypeVar<T, S extends Number & Runnable> extends Tester {
    43     public static void main(String[] args) {
    44         (new TypeVar()).run();
    45     }
    48     // Declarations used by tests
    50     private T t;
    51     private S s;
    54     private TypeVariable tvT;   // type variable T
    55     private TypeVariable tvS;   // type variable S
    57     protected void init() {
    58         tvT = (TypeVariable) getField("t").getType();
    59         tvS = (TypeVariable) getField("s").getType();
    60     }
    63     // TypeMirror methods
    65     @Test(result="type var")
    66     Collection<String> accept() {
    67         final Collection<String> res = new ArrayList<String>();
    69         tvT.accept(new SimpleTypeVisitor() {
    70             public void visitTypeMirror(TypeMirror t) {
    71                 res.add("type");
    72             }
    73             public void visitReferenceType(ReferenceType t) {
    74                 res.add("ref type");
    75             }
    76             public void visitTypeVariable(TypeVariable t) {
    77                 res.add("type var");
    78             }
    79         });
    80         return res;
    81     }
    83     @Test(result="T")
    84     String toStringTest1() {
    85         return tvT.toString();
    86     }
    88     @Test(result="S")
    89     String toStringTest2() {
    90         return tvS.toString();
    91     }
    94     // TypeVariable method
    96     @Test(result="S extends java.lang.Number & java.lang.Runnable")
    97     TypeParameterDeclaration getDeclaration() {
    98         return tvS.getDeclaration();
    99     }
   100 }

mercurial