Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/test/tools/javap/DescriptorTest.java
32285 views
/*1* Copyright (c) 2013, 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 800705226* @summary javap should include the descriptor for a method in verbose mode27*/2829import java.io.File;30import java.io.FileWriter;31import java.io.IOException;32import java.io.PrintWriter;33import java.io.StringWriter;34import java.util.regex.Pattern;3536public class DescriptorTest {37public static void main(String... args) throws Exception {38new DescriptorTest().run();39}4041void run() throws Exception {42File srcDir = new File("src");43srcDir.mkdirs();44File classesDir = new File("classes");45classesDir.mkdirs();4647File f = writeFile(new File(srcDir, "E.java"), "enum E { A, B }");48javac("-d", classesDir.getPath(), f.getPath());49String out = javap("-p", "-v", new File(classesDir, "E.class").getPath());50Pattern expect = Pattern.compile("\\Qprivate E();\\E\\s+\\Qdescriptor: (Ljava/lang/String;I)V\\E");51checkContains(out, expect);52}5354File writeFile(File f, String body) throws IOException {55try (FileWriter out = new FileWriter(f)) {56out.write(body);57}58return f;59}6061void javac(String... args) throws Exception {62StringWriter sw = new StringWriter();63PrintWriter pw = new PrintWriter(sw);64int rc = com.sun.tools.javac.Main.compile(args, pw);65pw.flush();66String out = sw.toString();67if (!out.isEmpty())68System.err.println(out);69if (rc != 0)70throw new Exception("compilation failed");71}7273String javap(String... args) throws Exception {74StringWriter sw = new StringWriter();75PrintWriter pw = new PrintWriter(sw);76int rc = com.sun.tools.javap.Main.run(args, pw);77pw.flush();78String out = sw.toString();79if (!out.isEmpty())80System.err.println(out);81if (rc != 0)82throw new Exception("javap failed");83return out;84}8586void checkContains(String s, Pattern p) throws Exception {87if (!p.matcher(s).find())88throw new Exception("expected pattern not found: " + p);89}90}919293