Path: blob/master/test/langtools/tools/javap/T6729471.java
41144 views
/*1* Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 672947126* @summary javap does not output inner interfaces of an interface27* @library /tools/lib28* @modules jdk.compiler/com.sun.tools.javac.api29* jdk.compiler/com.sun.tools.javac.main30* jdk.jdeps/com.sun.tools.javap31* @build toolbox.ToolBox toolbox.JarTask32* @run main T672947133*/3435import java.io.*;36import java.net.*;37import java.util.*;38import javax.tools.*;3940import toolbox.JarTask;41import toolbox.ToolBox;4243public class T672947144{45public static void main(String... args) throws IOException {46new T6729471().run();47}4849void run() throws IOException {50File testClasses = new File(System.getProperty("test.classes"));5152// simple class53verify("java.util.Map",54"public abstract boolean containsKey(java.lang.Object)");5556// inner class57verify("java.util.Map.Entry",58"public abstract K getKey()");5960// file name61verify(new File(testClasses, "T6729471.class").getPath(),62"public static void main(java.lang.String...)");6364// file url65verify(new File(testClasses, "T6729471.class").toURI().toString(),66"public static void main(java.lang.String...)");6768// jar url69File testJar = createJar("test.jar", "java.util.*");70try {71verify("jar:" + testJar.toURL() + "!/java/util/Map.class",72"public abstract boolean containsKey(java.lang.Object)");73} catch (MalformedURLException e) {74error(e.toString());75}7677if (errors > 0)78throw new Error(errors + " found.");79}8081File createJar(String name, String... paths) throws IOException {82JavaCompiler comp = ToolProvider.getSystemJavaCompiler();83try (JavaFileManager fm = comp.getStandardFileManager(null, null, null)) {84File f = new File(name);85ToolBox tb = new ToolBox();86new JarTask(tb, f.getPath())87.files(fm, StandardLocation.PLATFORM_CLASS_PATH, paths)88.run();89return f;90}91}9293void verify(String className, String... expects) {94String output = javap(className);95for (String expect: expects) {96if (output.indexOf(expect)< 0)97error(expect + " not found");98}99}100101void error(String msg) {102System.err.println(msg);103errors++;104}105106int errors;107108String javap(String className) {109String testClasses = System.getProperty("test.classes", ".");110StringWriter sw = new StringWriter();111PrintWriter out = new PrintWriter(sw);112String[] args = { "-classpath", testClasses, className };113int rc = com.sun.tools.javap.Main.run(args, out);114out.close();115String output = sw.toString();116System.out.println("class " + className);117System.out.println(output);118if (rc != 0)119throw new Error("javap failed. rc=" + rc);120if (output.indexOf("Error:") != -1)121throw new Error("javap reported error.");122return output;123}124}125126127128