langtools/test/tools/javap/T6868539.java
author ohair
Tue, 28 Dec 2010 15:54:52 -0800
changeset 7681 1f0819a3341f
parent 6601 90c4a1a64217
child 23120 6e12870d6652
permissions -rw-r--r--
6962318: Update copyright year Reviewed-by: xdono
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3553
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
     1
/*
7681
1f0819a3341f 6962318: Update copyright year
ohair
parents: 6601
diff changeset
     2
 * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
3553
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
     4
 *
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
     8
 *
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    13
 * accompanied this code).
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    14
 *
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    18
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3553
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3553
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3553
diff changeset
    21
 * questions.
3553
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    22
 */
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    23
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    24
/*
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    25
 * @test
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    26
 * @bug 6868539 6868548
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    27
 * @summary javap should use current names for constant pool entries,
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    28
 *              remove spurious ';' from constant pool entries
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    29
 */
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    30
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    31
import java.io.*;
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    32
import java.util.*;
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    33
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    34
public class T6868539
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    35
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    36
{
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    37
    public static void main(String... args) {
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    38
        new T6868539().run();
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    39
    }
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    40
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    41
    void run() {
6601
90c4a1a64217 6985115: tests create too much output
jjg
parents: 5520
diff changeset
    42
        String output = javap("T6868539");
90c4a1a64217 6985115: tests create too much output
jjg
parents: 5520
diff changeset
    43
        verify(output, "Utf8 +java/lang/String");                                   // 1: Utf8
3553
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    44
                                                                                        // 2: currently unused
6601
90c4a1a64217 6985115: tests create too much output
jjg
parents: 5520
diff changeset
    45
        verify(output, "Integer +123456");                                          // 3: Integer
90c4a1a64217 6985115: tests create too much output
jjg
parents: 5520
diff changeset
    46
        verify(output, "Float +123456.0f");                                         // 4: Float
90c4a1a64217 6985115: tests create too much output
jjg
parents: 5520
diff changeset
    47
        verify(output, "Long +123456l");                                            // 5: Long
90c4a1a64217 6985115: tests create too much output
jjg
parents: 5520
diff changeset
    48
        verify(output, "Double +123456.0d");                                        // 6: Double
90c4a1a64217 6985115: tests create too much output
jjg
parents: 5520
diff changeset
    49
        verify(output, "Class +#[0-9]+ +// + T6868539");                            // 7: Class
90c4a1a64217 6985115: tests create too much output
jjg
parents: 5520
diff changeset
    50
        verify(output, "String +#[0-9]+ +// + not found");                          // 8: String
90c4a1a64217 6985115: tests create too much output
jjg
parents: 5520
diff changeset
    51
        verify(output, "Fieldref +#[0-9]+\\.#[0-9]+ +// +T6868539.errors:I");       // 9: Fieldref
90c4a1a64217 6985115: tests create too much output
jjg
parents: 5520
diff changeset
    52
        verify(output, "Methodref +#[0-9]+\\.#[0-9]+ +// +T6868539.run:\\(\\)V");   // 10: Methodref
90c4a1a64217 6985115: tests create too much output
jjg
parents: 5520
diff changeset
    53
        verify(output, "InterfaceMethodref +#[0-9]+\\.#[0-9]+ +// +java/lang/Runnable\\.run:\\(\\)V");
3553
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    54
                                                                                        // 11: InterfaceMethodref
6601
90c4a1a64217 6985115: tests create too much output
jjg
parents: 5520
diff changeset
    55
        verify(output, "NameAndType +#[0-9]+:#[0-9]+ +// +run:\\(\\)V");            // 12: NameAndType
3553
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    56
        if (errors > 0)
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    57
            throw new Error(errors + " found.");
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    58
    }
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    59
6601
90c4a1a64217 6985115: tests create too much output
jjg
parents: 5520
diff changeset
    60
    void verify(String output, String... expects) {
3553
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    61
        for (String expect: expects) {
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    62
            if (!output.matches("(?s).*" + expect + ".*"))
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    63
                error(expect + " not found");
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    64
        }
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    65
    }
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    66
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    67
    void error(String msg) {
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    68
        System.err.println(msg);
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    69
        errors++;
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    70
    }
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    71
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    72
    int errors;
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    73
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    74
    String javap(String className) {
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    75
        String testClasses = System.getProperty("test.classes", ".");
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    76
        StringWriter sw = new StringWriter();
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    77
        PrintWriter out = new PrintWriter(sw);
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    78
        String[] args = { "-v", "-classpath", testClasses, className };
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    79
        int rc = com.sun.tools.javap.Main.run(args, out);
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    80
        if (rc != 0)
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    81
            throw new Error("javap failed. rc=" + rc);
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    82
        out.close();
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    83
        String output = sw.toString();
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    84
        System.out.println("class " + className);
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    85
        System.out.println(output);
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    86
        return output;
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    87
    }
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    88
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    89
    int i = 123456;
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    90
    float f = 123456.f;
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    91
    double d = 123456.;
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    92
    long l = 123456L;
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    93
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    94
    void m(Runnable r) { r.run(); }
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    95
}
5daeeb71ee78 6868539: javap should use current names for constant pool tags
jjg
parents:
diff changeset
    96