Fri, 15 Feb 2013 08:28:42 -0800
8007052: javap should include the descriptor for a method in verbose mode
Reviewed-by: mcimadamore
1.1 --- a/src/share/classes/com/sun/tools/javap/ClassWriter.java Thu Feb 14 09:43:00 2013 -0800 1.2 +++ b/src/share/classes/com/sun/tools/javap/ClassWriter.java Fri Feb 15 08:28:42 2013 -0800 1.3 @@ -379,8 +379,8 @@ 1.4 1.5 indent(+1); 1.6 1.7 - if (options.showInternalSignatures) 1.8 - println("Signature: " + getValue(f.descriptor)); 1.9 + if (options.showDescriptors) 1.10 + println("descriptor: " + getValue(f.descriptor)); 1.11 1.12 if (options.verbose && !options.compat) 1.13 writeList("flags: ", flags.getFieldFlags(), "\n"); 1.14 @@ -475,8 +475,8 @@ 1.15 1.16 indent(+1); 1.17 1.18 - if (options.showInternalSignatures) { 1.19 - println("Signature: " + getValue(m.descriptor)); 1.20 + if (options.showDescriptors) { 1.21 + println("descriptor: " + getValue(m.descriptor)); 1.22 } 1.23 1.24 if (options.verbose && !options.compat) { 1.25 @@ -520,7 +520,7 @@ 1.26 setPendingNewline( 1.27 options.showDisassembled || 1.28 options.showAllAttrs || 1.29 - options.showInternalSignatures || 1.30 + options.showDescriptors || 1.31 options.showLineAndLocalVariableTables || 1.32 options.verbose); 1.33 }
2.1 --- a/src/share/classes/com/sun/tools/javap/JavapTask.java Thu Feb 14 09:43:00 2013 -0800 2.2 +++ b/src/share/classes/com/sun/tools/javap/JavapTask.java Fri Feb 15 08:28:42 2013 -0800 2.3 @@ -140,6 +140,7 @@ 2.4 new Option(false, "-v", "-verbose", "-all") { 2.5 void process(JavapTask task, String opt, String arg) { 2.6 task.options.verbose = true; 2.7 + task.options.showDescriptors = true; 2.8 task.options.showFlags = true; 2.9 task.options.showAllAttrs = true; 2.10 } 2.11 @@ -190,7 +191,7 @@ 2.12 2.13 new Option(false, "-s") { 2.14 void process(JavapTask task, String opt, String arg) { 2.15 - task.options.showInternalSignatures = true; 2.16 + task.options.showDescriptors = true; 2.17 } 2.18 }, 2.19
3.1 --- a/src/share/classes/com/sun/tools/javap/Options.java Thu Feb 14 09:43:00 2013 -0800 3.2 +++ b/src/share/classes/com/sun/tools/javap/Options.java Fri Feb 15 08:28:42 2013 -0800 3.3 @@ -1,5 +1,5 @@ 3.4 /* 3.5 - * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved. 3.6 + * Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved. 3.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3.8 * 3.9 * This code is free software; you can redistribute it and/or modify it 3.10 @@ -81,7 +81,7 @@ 3.11 public Set<String> accessOptions = new HashSet<String>(); 3.12 public Set<InstructionDetailWriter.Kind> details = EnumSet.noneOf(InstructionDetailWriter.Kind.class); 3.13 public boolean showDisassembled; 3.14 - public boolean showInternalSignatures; 3.15 + public boolean showDescriptors; 3.16 public boolean showAllAttrs; 3.17 public boolean showConstants; 3.18 public boolean sysInfo;
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/test/tools/javap/DescriptorTest.java Fri Feb 15 08:28:42 2013 -0800 4.3 @@ -0,0 +1,91 @@ 4.4 +/* 4.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 4.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4.7 + * 4.8 + * This code is free software; you can redistribute it and/or modify it 4.9 + * under the terms of the GNU General Public License version 2 only, as 4.10 + * published by the Free Software Foundation. 4.11 + * 4.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 4.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 4.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 4.15 + * version 2 for more details (a copy is included in the LICENSE file that 4.16 + * accompanied this code). 4.17 + * 4.18 + * You should have received a copy of the GNU General Public License version 4.19 + * 2 along with this work; if not, write to the Free Software Foundation, 4.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 4.21 + * 4.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 4.23 + * or visit www.oracle.com if you need additional information or have any 4.24 + * questions. 4.25 + */ 4.26 + 4.27 +/** 4.28 + * @test 4.29 + * @bug 8007052 4.30 + * @summary javap should include the descriptor for a method in verbose mode 4.31 + */ 4.32 + 4.33 +import java.io.File; 4.34 +import java.io.FileWriter; 4.35 +import java.io.IOException; 4.36 +import java.io.PrintWriter; 4.37 +import java.io.StringWriter; 4.38 +import java.util.regex.Pattern; 4.39 + 4.40 +public class DescriptorTest { 4.41 + public static void main(String... args) throws Exception { 4.42 + new DescriptorTest().run(); 4.43 + } 4.44 + 4.45 + void run() throws Exception { 4.46 + File srcDir = new File("src"); 4.47 + srcDir.mkdirs(); 4.48 + File classesDir = new File("classes"); 4.49 + classesDir.mkdirs(); 4.50 + 4.51 + File f = writeFile(new File(srcDir, "E.java"), "enum E { A, B }"); 4.52 + javac("-d", classesDir.getPath(), f.getPath()); 4.53 + String out = javap("-p", "-v", new File(classesDir, "E.class").getPath()); 4.54 + Pattern expect = Pattern.compile("\\Qprivate E();\\E\\s+\\Qdescriptor: (Ljava/lang/String;I)V\\E"); 4.55 + checkContains(out, expect); 4.56 + } 4.57 + 4.58 + File writeFile(File f, String body) throws IOException { 4.59 + try (FileWriter out = new FileWriter(f)) { 4.60 + out.write(body); 4.61 + } 4.62 + return f; 4.63 + } 4.64 + 4.65 + void javac(String... args) throws Exception { 4.66 + StringWriter sw = new StringWriter(); 4.67 + PrintWriter pw = new PrintWriter(sw); 4.68 + int rc = com.sun.tools.javac.Main.compile(args, pw); 4.69 + pw.flush(); 4.70 + String out = sw.toString(); 4.71 + if (!out.isEmpty()) 4.72 + System.err.println(out); 4.73 + if (rc != 0) 4.74 + throw new Exception("compilation failed"); 4.75 + } 4.76 + 4.77 + String javap(String... args) throws Exception { 4.78 + StringWriter sw = new StringWriter(); 4.79 + PrintWriter pw = new PrintWriter(sw); 4.80 + int rc = com.sun.tools.javap.Main.run(args, pw); 4.81 + pw.flush(); 4.82 + String out = sw.toString(); 4.83 + if (!out.isEmpty()) 4.84 + System.err.println(out); 4.85 + if (rc != 0) 4.86 + throw new Exception("javap failed"); 4.87 + return out; 4.88 + } 4.89 + 4.90 + void checkContains(String s, Pattern p) throws Exception { 4.91 + if (!p.matcher(s).find()) 4.92 + throw new Exception("expected pattern not found: " + p); 4.93 + } 4.94 +}