jdk/test/java/lang/reflect/Generics/Probe.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 1934 94b646161f34
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2004-2006 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @bug 5003916
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Testing parsing of signatures attributes of nested classes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @author Joseph D. Darcy
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * @compile -source 1.5 Probe.java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * @run main Probe
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.lang.reflect.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.lang.annotation.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
@Classes({
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
        "java.util.concurrent.FutureTask",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
        "java.util.concurrent.ConcurrentHashMap$EntryIterator",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
        "java.util.concurrent.ConcurrentHashMap$KeyIterator",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
        "java.util.concurrent.ConcurrentHashMap$ValueIterator",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
        "java.util.AbstractList$ListItr",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
        "java.util.EnumMap$EntryIterator",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
        "java.util.EnumMap$KeyIterator",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
        "java.util.EnumMap$ValueIterator",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        "java.util.IdentityHashMap$EntryIterator",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        "java.util.IdentityHashMap$KeyIterator",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        "java.util.IdentityHashMap$ValueIterator",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        "java.util.WeakHashMap$EntryIterator",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        "java.util.WeakHashMap$KeyIterator",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        "java.util.WeakHashMap$ValueIterator",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        "java.util.TreeMap$EntryIterator",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        "java.util.TreeMap$KeyIterator",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        "java.util.TreeMap$ValueIterator",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        "java.util.HashMap$EntryIterator",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        "java.util.HashMap$KeyIterator",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        "java.util.HashMap$ValueIterator",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        "java.util.LinkedHashMap$EntryIterator",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        "java.util.LinkedHashMap$KeyIterator",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        "java.util.LinkedHashMap$ValueIterator",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        "javax.crypto.SunJCE_c",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        "javax.crypto.SunJCE_e",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        "javax.crypto.SunJCE_f",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        "javax.crypto.SunJCE_j",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        "javax.crypto.SunJCE_k",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        "javax.crypto.SunJCE_l"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        })
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
public class Probe {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    public static void main (String[] args) throws Throwable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        String [] names = (Probe.class).getAnnotation(Classes.class).value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        int errs = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        for(String name: names) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            System.out.println("\nCLASS " + name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            Class c = Class.forName(name, false, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            errs += probe(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            System.out.println(errs == 0 ? "  ok" : "  ERRORS:" + errs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        if (errs > 0 )
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            throw new RuntimeException("Errors during probing.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    static int probe (Class c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        int errs = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            c.getTypeParameters();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            c.getGenericSuperclass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            c.getGenericInterfaces();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        } catch (Throwable t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            errs++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            System.err.println(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        Field[] fields = c.getDeclaredFields();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        if (fields != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            for(Field field: fields) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                    field.getGenericType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                } catch (Throwable t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                    errs++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                    System.err.println("FIELD " + field);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                    System.err.println(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        Method[] methods = c.getDeclaredMethods();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        if (methods != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            for(Method method: methods) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                    method.getTypeParameters();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                    method.getGenericReturnType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                    method.getGenericParameterTypes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                    method.getGenericExceptionTypes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                } catch (Throwable t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                    errs++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                    System.err.println("METHOD " + method);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                    System.err.println(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        Constructor[] ctors = c.getDeclaredConstructors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        if (ctors != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            for(Constructor ctor: ctors) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                    ctor.getTypeParameters();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                    ctor.getGenericParameterTypes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                    ctor.getGenericExceptionTypes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                } catch (Throwable t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                    errs++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                    System.err.println("CONSTRUCTOR " + ctor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                    System.err.println(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        return errs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
@Retention(RetentionPolicy.RUNTIME)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
@interface Classes {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    String [] value(); // list of classes to probe
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
}