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

changeset 1
9a66ca7c79fa
child 132
a54ef8459576
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/tools/apt/mirror/type/TypeVar.java	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,100 @@
     1.4 +/*
     1.5 + * Copyright 2004-2007 Sun Microsystems, Inc.  All Rights Reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.24 + * have any questions.
    1.25 + */
    1.26 +
    1.27 +
    1.28 +/*
    1.29 + * @test
    1.30 + * @bug 4853450
    1.31 + * @summary TypeVariable tests
    1.32 + * @library ../../lib
    1.33 + * @compile -source 1.5 TypeVar.java
    1.34 + * @run main TypeVar
    1.35 + */
    1.36 +
    1.37 +
    1.38 +import java.util.*;
    1.39 +import com.sun.mirror.declaration.*;
    1.40 +import com.sun.mirror.type.*;
    1.41 +import com.sun.mirror.util.*;
    1.42 +
    1.43 +
    1.44 +public class TypeVar<T, S extends Number & Runnable> extends Tester {
    1.45 +
    1.46 +    public static void main(String[] args) {
    1.47 +        (new TypeVar()).run();
    1.48 +    }
    1.49 +
    1.50 +
    1.51 +    // Declarations used by tests
    1.52 +
    1.53 +    private T t;
    1.54 +    private S s;
    1.55 +
    1.56 +
    1.57 +    private TypeVariable tvT;   // type variable T
    1.58 +    private TypeVariable tvS;   // type variable S
    1.59 +
    1.60 +    protected void init() {
    1.61 +        tvT = (TypeVariable) getField("t").getType();
    1.62 +        tvS = (TypeVariable) getField("s").getType();
    1.63 +    }
    1.64 +
    1.65 +
    1.66 +    // TypeMirror methods
    1.67 +
    1.68 +    @Test(result="type var")
    1.69 +    Collection<String> accept() {
    1.70 +        final Collection<String> res = new ArrayList<String>();
    1.71 +
    1.72 +        tvT.accept(new SimpleTypeVisitor() {
    1.73 +            public void visitTypeMirror(TypeMirror t) {
    1.74 +                res.add("type");
    1.75 +            }
    1.76 +            public void visitReferenceType(ReferenceType t) {
    1.77 +                res.add("ref type");
    1.78 +            }
    1.79 +            public void visitTypeVariable(TypeVariable t) {
    1.80 +                res.add("type var");
    1.81 +            }
    1.82 +        });
    1.83 +        return res;
    1.84 +    }
    1.85 +
    1.86 +    @Test(result="T")
    1.87 +    String toStringTest1() {
    1.88 +        return tvT.toString();
    1.89 +    }
    1.90 +
    1.91 +    @Test(result="S")
    1.92 +    String toStringTest2() {
    1.93 +        return tvS.toString();
    1.94 +    }
    1.95 +
    1.96 +
    1.97 +    // TypeVariable method
    1.98 +
    1.99 +    @Test(result="S extends java.lang.Number & java.lang.Runnable")
   1.100 +    TypeParameterDeclaration getDeclaration() {
   1.101 +        return tvS.getDeclaration();
   1.102 +    }
   1.103 +}

mercurial