langtools/test/tools/javap/4111861/T4111861.java
author akulyakh
Thu, 21 May 2015 11:41:04 -0700
changeset 30730 d3ce7619db2c
parent 5520 86e4b9a9da40
child 30846 2b3f379840f0
permissions -rw-r--r--
8076543: Add @modules as needed to the langtools tests Reviewed-by: jjg, shurailine
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1038
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
     1
/*
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 5520
diff changeset
     2
 * Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
1038
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
     4
 *
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
     8
 *
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    13
 * accompanied this code).
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    14
 *
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    18
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3547
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3547
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3547
diff changeset
    21
 * questions.
1038
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    22
 */
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    23
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    24
import java.io.*;
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    25
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    26
/*
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    27
 * @test
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    28
 * @bug 4111861
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    29
 * @summary static final field contents are not displayed
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 5520
diff changeset
    30
 * @modules jdk.compiler
1038
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    31
 */
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    32
public class T4111861 {
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    33
    public static void main(String... args) throws Exception {
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    34
        new T4111861().run();
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    35
    }
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    36
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    37
    void run() throws Exception {
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    38
        File testSrc = new File(System.getProperty("test.src", "."));
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    39
        File a_java = new File(testSrc, "A.java");
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    40
        javac("-d", ".", a_java.getPath());
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    41
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    42
        String out = javap("-classpath", ".", "-constants", "A");
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    43
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    44
        String a = read(a_java);
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    45
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    46
        if (!filter(out).equals(filter(read(a_java)))) {
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    47
            System.out.println(out);
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    48
            throw new Exception("unexpected output");
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    49
        }
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    50
    }
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    51
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    52
    String javac(String... args) throws Exception {
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    53
        StringWriter sw = new StringWriter();
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    54
        PrintWriter pw = new PrintWriter(sw);
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    55
        int rc = com.sun.tools.javac.Main.compile(args, pw);
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    56
        if (rc != 0)
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    57
            throw new Exception("javac failed, rc=" + rc);
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    58
        return sw.toString();
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    59
    }
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    60
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    61
    String javap(String... args) throws Exception {
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    62
        StringWriter sw = new StringWriter();
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    63
        PrintWriter pw = new PrintWriter(sw);
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    64
        int rc = com.sun.tools.javap.Main.run(args, pw);
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    65
        if (rc != 0)
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    66
            throw new Exception("javap failed, rc=" + rc);
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    67
        return sw.toString();
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    68
    }
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    69
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    70
    String read(File f) throws IOException {
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    71
        StringBuilder sb = new StringBuilder();
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    72
        BufferedReader in = new BufferedReader(new FileReader(f));
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    73
        try {
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    74
            String line;
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    75
            while ((line = in.readLine()) != null) {
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    76
                sb.append(line);
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    77
                sb.append('\n');
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    78
            }
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    79
        } finally {
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    80
            in.close();
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    81
        }
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    82
        return sb.toString();
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    83
    }
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    84
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    85
    // return those lines beginning "public static final"
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    86
    String filter(String s) throws IOException {
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    87
        StringBuilder sb = new StringBuilder();
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    88
        BufferedReader in = new BufferedReader(new StringReader(s));
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    89
        try {
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    90
            String line;
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    91
            while ((line = in.readLine()) != null) {
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    92
                if (line.indexOf("public static final") > 0) {
3547
4471bb5983d1 6868553: 6867671 breaks some tests
jjg
parents: 1038
diff changeset
    93
                    sb.append(line.trim());
1038
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    94
                    sb.append('\n');
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    95
                }
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    96
            }
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    97
        } finally {
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    98
            in.close();
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
    99
        }
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
   100
        return sb.toString();
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
   101
    }
fbe81cf1123d 4111861: static final field contents are not displayed
jjg
parents:
diff changeset
   102
}