langtools/test/tools/javap/T7004698.java
author akulyakh
Thu, 21 May 2015 11:41:04 -0700
changeset 30730 d3ce7619db2c
parent 7625 f7374a9d9cc9
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:
7625
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
     1
/*
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 7625
diff changeset
     2
 * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
7625
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
     4
 *
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
     8
 *
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    13
 * accompanied this code).
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    14
 *
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    18
 *
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    21
 * questions.
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    22
 */
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    23
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    24
/*
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    25
 * @test
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    26
 * @bug 7004698
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    27
 * @summary javap does not output CharacterRangeTable attributes correctly
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 7625
diff changeset
    28
 * @modules jdk.compiler
7625
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    29
 */
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    30
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    31
import java.io.*;
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    32
import java.util.*;
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    33
import java.util.regex.*;
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    34
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    35
public class T7004698 {
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    36
    public static void main(String... args) throws Exception {
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    37
        new T7004698().run();
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    38
    }
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    39
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    40
    void run() throws Exception {
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    41
        File srcDir = new File(System.getProperty("test.src"));
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    42
        File srcFile = new File(srcDir, T7004698.class.getSimpleName() + ".java");
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    43
        File classesDir = new File(".");
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    44
        compile("-Xjcov", "-d", classesDir.getPath(), srcFile.getPath());
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    45
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    46
        File classFile = new File(classesDir, T7004698.class.getSimpleName() + ".class");
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    47
        String out = javap("-v", classFile.getPath());
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    48
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    49
        Pattern attrBody = Pattern.compile("[0-9a-f, ]+//[-0-9a-z:, ]+");
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    50
        Pattern endOfAttr = Pattern.compile("(^$|[A-Z][A-Za-z0-9_]+:.*|})");
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    51
        boolean inAttr = false;
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    52
        int count = 0;
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    53
        int errors = 0;
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    54
        for (String line: out.split(System.getProperty("line.separator"))) {
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    55
            line = line.trim();
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    56
            if (line.equals("CharacterRangeTable:")) {
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    57
                inAttr = true;
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    58
                count++;
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    59
            } else if (inAttr) {
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    60
                if (endOfAttr.matcher(line).matches()) {
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    61
                    inAttr = false;
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    62
                } else if (!attrBody.matcher(line).matches()) {
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    63
                    System.err.println("unexpected line found: " + line);
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    64
                    errors++;
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    65
                }
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    66
            }
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    67
        }
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    68
        if (count == 0)
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    69
            throw new Exception("no attribute instances found");
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    70
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    71
        if (errors > 0)
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    72
            throw new Exception(errors + " errors found");
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    73
    }
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    74
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    75
    void compile(String... args) throws Exception {
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    76
        StringWriter sw = new StringWriter();
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    77
        PrintWriter pw = new PrintWriter(sw);
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    78
        int rc = com.sun.tools.javac.Main.compile(args, pw);
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    79
        pw.close();
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    80
        String out = sw.toString();
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    81
        if (!out.isEmpty())
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    82
            System.err.println(out);
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    83
        if (rc != 0)
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    84
            throw new Exception("javac failed unexpectedly; rc=" + rc);
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    85
    }
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    86
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    87
    String javap(String... args) throws Exception {
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    88
        StringWriter sw = new StringWriter();
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    89
        PrintWriter pw = new PrintWriter(sw);
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    90
        int rc = com.sun.tools.javap.Main.run(args, pw);
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    91
        pw.close();
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    92
        String out = sw.toString();
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    93
        if (!out.isEmpty())
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    94
            System.err.println(out);
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    95
        if (rc != 0)
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    96
            throw new Exception("javap failed unexpectedly; rc=" + rc);
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    97
        return out;
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    98
    }
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    99
}