langtools/test/tools/javap/T4880672.java
author akulyakh
Thu, 21 May 2015 11:41:04 -0700
changeset 30730 d3ce7619db2c
parent 9078 096c39554639
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:
3544
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
     1
/*
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 9078
diff changeset
     2
 * Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
3544
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
     4
 *
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
     8
 *
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    13
 * accompanied this code).
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    14
 *
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    18
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3544
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3544
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3544
diff changeset
    21
 * questions.
3544
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    22
 */
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    23
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    24
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    25
/*
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    26
 * @test
9078
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 5520
diff changeset
    27
 * @bug 4880672 7031005
3544
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    28
 * @summary javap does not output inner interfaces of an interface
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 9078
diff changeset
    29
 * @modules jdk.compiler
3544
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    30
 */
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    31
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    32
import java.io.*;
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    33
import java.util.*;
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    34
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    35
public class T4880672
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    36
{
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    37
    public static void main(String... args) {
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    38
        new T4880672().run();
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    39
    }
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    40
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    41
    void run() {
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    42
        verify("java.util.Map", "public interface java.util.Map$Entry");
9078
096c39554639 7031005: javap prints "extends java.lang.Object"
jjg
parents: 5520
diff changeset
    43
        verify("T4880672", "class T4880672$A$B");
3544
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    44
        verify("C", ""); // must not give error if no InnerClasses attribute
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    45
        if (errors > 0)
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    46
            throw new Error(errors + " found.");
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    47
    }
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    48
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    49
    void verify(String className, String... expects) {
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    50
        String output = javap(className);
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    51
        for (String expect: expects) {
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    52
            if (output.indexOf(expect)< 0)
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    53
                error(expect + " not found");
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    54
        }
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    55
    }
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    56
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    57
    void error(String msg) {
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    58
        System.err.println(msg);
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    59
        errors++;
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    60
    }
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    61
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    62
    int errors;
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    63
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    64
    String javap(String className) {
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    65
        String testClasses = System.getProperty("test.classes", ".");
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    66
        StringWriter sw = new StringWriter();
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    67
        PrintWriter out = new PrintWriter(sw);
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    68
        String[] args = { "-XDinner", "-classpath", testClasses, className };
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    69
        int rc = com.sun.tools.javap.Main.run(args, out);
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    70
        out.close();
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    71
        String output = sw.toString();
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    72
        System.out.println("class " + className);
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    73
        System.out.println(output);
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    74
        if (rc != 0)
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    75
            throw new Error("javap failed. rc=" + rc);
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    76
        if (output.indexOf("Error:") != -1)
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    77
            throw new Error("javap reported error.");
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    78
        return output;
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    79
    }
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    80
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    81
    class A {
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    82
        class B { }
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    83
    }
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    84
}
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    85
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    86
class C { }
c6d0f086397f 4880672: javap does not output inner interfaces of an interface
jjg
parents:
diff changeset
    87