jdk/test/com/sun/jdi/GenericsTest.java
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 3432 8acd97c69118
child 24973 8c4bc3fa4c4e
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3432
diff changeset
     2
 * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
2
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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3432
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3432
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3432
diff changeset
    21
 * questions.
2
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 4421040
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 *  @summary  JPDA: Add support for JSR-014 Generics
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *  @author jjh
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 *  @run build TestScaffold VMConnection TargetListener TargetAdapter
3432
8acd97c69118 6868533: 3/4 JDI: remove '-source 1.5' and '-target 1.5' options from com.sun.jdi tests
dcubed
parents: 2
diff changeset
    32
 *  @run compile -g GenericsTest.java
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 *  @run main GenericsTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import com.sun.jdi.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import com.sun.jdi.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import com.sun.jdi.request.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    /********** target program **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
class GenericsTarg {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    static Gen1<String> genField = new Gen1<String>();;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    static Sub1 sub1Field = new Sub1();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    String[] strArray = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    int intField = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    Object objField;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    public static void main(String[] args){
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        //genField.print();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        System.out.println("Goodbye from GenericsTarg!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
class Gen1<tt> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    tt field1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    Gen1() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        System.out.println("Gen1<tt> ctor called");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    tt method1(tt p1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        Gen1<String> xxx = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        System.out.println("method1: param is " + p1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        return p1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    String method2() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        String str = "This local variable is not generic";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        return str;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
class Sub1 extends Gen1<String> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    String method1(String p1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        System.out.println("method1 has been overridden: param is " + p1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        return "hi";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    /********** test program **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
public class GenericsTest extends TestScaffold {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    ReferenceType targetClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    ThreadReference mainThread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    static boolean useOld;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    GenericsTest (String args[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        super(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
         * The 1.5 FE must be able to talk to a 1.4 BE, ie, JDWP version <= 1.4.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
         * This is hard to test since this test file must be compiled with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
         * -source 1.5 which will cause its class file to be version 49 which
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
         * won't run on a pre 1.5 JDK.   We can simulate this though
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
         * by passing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
         *      -xjdk <pathname>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
         * to this test which causes the debuggee to be run on that JDK.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
         * This should be a version of 1.5 that accepts classfile version 49,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
         * but which still contains the 1.4 version of JDWP.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
         * This trick verifies that the calls to genericSignature() methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
         * in the test do not cause the generic JDWP commands to be issued.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
         * The value to use for this is currently:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
         * /java/re/jdk/1.5/promoted/all/b17/binaries/solaris-sparc
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        if (args.length > 1 && args[0].equals("-xjdk")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            System.setProperty("java.home", args[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            useOld = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            // Delete this arg
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            String[] args1 = new String[args.length - 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            for (int ii = 0; ii < args.length -2; ii++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                args1[ii] = args[ii + 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            args = args1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        new GenericsTest(args).startTests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    /********** test core **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    protected void runTests() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
         * Get to the top of main()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
         * to determine targetClass and mainThread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        BreakpointEvent bpe = startToMain("GenericsTarg");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        targetClass = bpe.location().declaringType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
             * Prove that arrays aren't broken and that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
             * null is returned if there is no generic signature
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            Field strArray = targetClass.fieldByName("strArray");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            ReferenceType fieldType = (ReferenceType)(strArray.type());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            String genSig = fieldType.genericSignature();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            System.out.println("strArray name = " + strArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            System.out.println("         type = " + fieldType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            System.out.println("          sig = " + fieldType.signature());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            System.out.println("       genSig = " + genSig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            if (!useOld && genSig != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                failure("FAILED: Expected generic signature = null for "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                        + fieldType.name() + ", received: " + genSig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            // prove that primitives aren't broken.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            Field intField = targetClass.fieldByName("intField");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            Type fieldType = (Type)(intField.type());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            System.out.println("intField name = " + intField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            System.out.println("         type = " + fieldType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            System.out.println("          sig = " + fieldType.signature());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        Field genField = targetClass.fieldByName("genField");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        ReferenceType gen1Class = (ReferenceType)(genField.type());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        String genSig;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        String expected;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            // Verify genericSignature for a class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            expected = "<tt:Ljava/lang/Object;>Ljava/lang/Object;";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            genSig = gen1Class.genericSignature();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            System.out.println("genField name = " + genField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            System.out.println("         type = " + gen1Class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            System.out.println("          sig = " + gen1Class.signature());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            System.out.println("       genSig = " + genSig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            if (!useOld && !expected.equals(genSig)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                failure("FAILED: Expected generic signature for gen1: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                        expected + ", received: " + genSig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            // Verify genericSignature() for a field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            List genFields = gen1Class.fields();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            Field field1 = (Field)genFields.get(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            // there is only one field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            expected = "Ttt;";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            genSig = field1.genericSignature();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            System.out.println("field1 name = " + field1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            System.out.println("       type = " + gen1Class.signature());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            System.out.println("        sig = " + field1.signature());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            System.out.println("    gen sig = " + genSig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            if (!useOld && !expected.equals(genSig)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                failure("FAILED: Expected generic signature for field1: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                        expected + ", received: " + genSig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            // Verify genericSignature() for a method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            List genMethods = gen1Class.methodsByName("method1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            // There is only uno
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            Method method1 = (Method)genMethods.get(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            expected = "(Ttt;)Ttt;";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            genSig = method1.genericSignature();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            System.out.println("method1 name = " + method1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            System.out.println("        type = " + gen1Class.signature());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            System.out.println("         sig = " + method1.signature());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            System.out.println("     gen sig = " + genSig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            System.out.println("     bridge  = " + method1.isBridge());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            if (!useOld && !expected.equals(genSig)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                failure("FAILED: Expected generic signature for method1: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                        expected + ", received: " + genSig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            // Verify this is not a bridge method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            if (method1.isBridge()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                failure("FAILED: Expected gen1.method1 to not be a bridge"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                         + " method but it is");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            // Verify genericSignature for a local var
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            List localVars = method1.variables();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            String[] expectedGenSigs = { "Ttt", "Gen1<String>" };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            for ( int ii = 0 ; ii < localVars.size(); ii++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                expected = expectedGenSigs[ii];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                LocalVariable pp = (LocalVariable)localVars.get(ii);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                genSig = pp.genericSignature();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                System.out.println("   local var " + ii + " = " + pp.name());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                System.out.println("      sig      = " + pp.signature());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                System.out.println("      gen sig  = " + genSig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                //jjh Uncomment when generics for local vars are available from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                //jjh javac and hotspot.  See:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                //jjh   4914602 LVT entries for classfile version > 49 must be converted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                //jjh if (!useOld && !expected.equals(genSig)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                //jjh    failure("FAILED: Expected generic signature for local var: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                //jjh            expected + ", received: " + genSig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                //jjh }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            // Verify genericSignature() for a method2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            List genMethods = gen1Class.methodsByName("method2");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            // There is only uno
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            Method method2 = (Method)genMethods.get(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            expected = "null";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            genSig = method2.genericSignature();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            genSig = (genSig == null) ? "null" : genSig;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            System.out.println("method2 name = " + method2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            System.out.println("        type = " + gen1Class.signature());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            System.out.println("         sig = " + method2.signature());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            System.out.println("     gen sig = " + genSig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            System.out.println("     bridge  = " + method2.isBridge());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            if (!useOld && !expected.equals(genSig)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                failure("FAILED: Expected generic signature for method2: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                        expected + ", received: " + genSig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            // Verify this is not a bridge method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            if (method2.isBridge()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                failure("FAILED: Expected gen1.method2 to not be a bridge"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                         + " method but it is");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            // Verify genericSignature for a local var
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            List localVars = method2.variables();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            expected = "null";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            for ( int ii = 0 ; ii < localVars.size(); ii++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                LocalVariable pp = (LocalVariable)localVars.get(ii);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                genSig = pp.genericSignature();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                genSig = (genSig == null) ? "null" : genSig;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                System.out.println("   local var " + ii + " = " + pp.name());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                System.out.println("      sig      = " + pp.signature());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                System.out.println("      gen sig  = " + genSig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                if (!useOld && !expected.equals(genSig)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                   failure("FAILED: Expected generic signature for local var: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                           expected + ", received: " + genSig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            Field sub1Field = targetClass.fieldByName("sub1Field");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            ReferenceType sub1Class = (ReferenceType)(sub1Field.type());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            List<Method> sub1Methods = sub1Class.methodsByName("method1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            for (Method mm: sub1Methods) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                System.out.println("method is: " + mm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
             * There should be two methods - the first is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
             * method1 defined in Sub1, and the 2nd is a javac generated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
             * bridge method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            Method method1 = (Method)sub1Methods.get(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            System.out.println("\nmethod1 name = " + method1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            System.out.println("         sig = " + method1.signature());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            System.out.println("      bridge = " + method1.isBridge());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            if (!useOld && !method1.isBridge()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                failure("FAILED: Expected Sub1.method1 to be a bridge method"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                         + " but it isn't");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            // Verify genericSignature for a non generic class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            genSig = targetClass.genericSignature();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            if (genSig != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                failure("FAILED: Expected generic signature = null for "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                        + targetClass.name() + ", received: " + genSig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            // Verify genericSignature for a non generic field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            Field objField = targetClass.fieldByName("objField");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            genSig = objField.genericSignature();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            if (genSig != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                failure("FAILED: Expected generic signature = null for "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                        + objField.name() + ", received: " + genSig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            // Verify genericSignature for a non generic method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            List methods = targetClass.methodsByName("main");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            Method main = (Method)methods.get(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            genSig = main.genericSignature();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            if (genSig != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                failure("FAILED: Expected generic signature = null for "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                        + main.name() + ", received: " + genSig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        if (0 == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            mainThread = bpe.thread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            EventRequestManager erm = vm().eventRequestManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            StepRequest request = erm.createStepRequest(mainThread,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                                                    StepRequest.STEP_LINE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                                                    StepRequest.STEP_INTO);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            request.enable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
         * resume the target listening for events
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        listenUntilVMDisconnect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
         * deal with results of test
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
         * if anything has called failure("foo") testFailed will be true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        if (!testFailed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            println("GenericsTest: passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            throw new Exception("GenericsTest: failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
}