1/*
2 * Copyright (c) 2004, 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 * @test
26 * @bug 5015676 4987888 4997464
27 * @summary Testing upper bounds and availability of toString methods
28 * @author Joseph D. Darcy
29 */
30
31import java.lang.reflect.*;
32import java.util.List;
33import java.util.Collection;
34
35class A<T> {
36    class B<U> {}
37}
38
39class Test<T> {
40    static class Inner1<U> {
41        void bar(U[] array1) { return;}
42    }
43
44    class Inner2<V> {
45        List<?> foo2(List<? extends V> t) {
46            return null;
47        }
48    }
49
50    static <S extends Object & Comparable<? super S> > S max(Collection<? extends S> coll) {
51        return null;
52    }
53
54    List<? extends T> foo(List<? super T> t) {
55        return null;
56    }
57}
58
59public class StringsAndBounds {
60    public void f(A<String>.B<Integer> x) {
61    }
62
63    public <T>  void g(T a) {return ;}
64
65    static void scanner(Class clazz) {
66        System.out.println("\n\nScanning " + clazz.getName());
67
68        for(Class c: clazz.getDeclaredClasses()) {
69            scanner(c);
70        }
71
72        for(Method m: clazz.getDeclaredMethods()) {
73            System.out.println("\nMethod:\t" + m.toString()); // Need toGenericString?
74            System.out.println("\tReturn Type: " + m.getGenericReturnType().toString() );
75            for(Type p: m.getGenericParameterTypes()) {
76                if (p instanceof WildcardType) { // Check upper bounds
77                    Type[] upperBounds = ((WildcardType)p).getUpperBounds();
78                    if (upperBounds.length < 1 ||
79                        upperBounds[0] == null)
80                        throw new RuntimeException("Malformed upper bounds: " + p);
81
82                }
83
84                System.out.println("\tParameter: " + p.toString());
85            }
86        }
87    }
88
89    public static void main(String[] argv) throws Exception {
90        scanner(StringsAndBounds.class);
91        scanner(A.B.class);
92        scanner(Test.class);
93    }
94}
95