Fri, 04 Oct 2013 16:08:18 -0700
8003537: javap use internal class name when printing bound of type variable
Reviewed-by: jjg
src/share/classes/com/sun/tools/javap/ClassWriter.java | file | annotate | diff | comparison | revisions | |
test/tools/javap/BoundsTypeVariableTest.java | file | annotate | diff | comparison | revisions |
1.1 --- a/src/share/classes/com/sun/tools/javap/ClassWriter.java Fri Oct 04 15:24:42 2013 -0700 1.2 +++ b/src/share/classes/com/sun/tools/javap/ClassWriter.java Fri Oct 04 16:08:18 2013 -0700 1.3 @@ -232,6 +232,12 @@ 1.4 return t.accept(this, new StringBuilder()).toString(); 1.5 } 1.6 1.7 + String printTypeArgs(List<? extends TypeParamType> typeParamTypes) { 1.8 + StringBuilder builder = new StringBuilder(); 1.9 + appendIfNotEmpty(builder, "<", typeParamTypes, "> "); 1.10 + return builder.toString(); 1.11 + } 1.12 + 1.13 public StringBuilder visitSimpleType(SimpleType type, StringBuilder sb) { 1.14 sb.append(getJavaName(type.name)); 1.15 return sb; 1.16 @@ -438,7 +444,7 @@ 1.17 1.18 writeModifiers(flags.getMethodModifiers()); 1.19 if (methodType != null) { 1.20 - writeListIfNotEmpty("<", methodType.typeParamTypes, "> "); 1.21 + print(new JavaTypePrinter(false).printTypeArgs(methodType.typeParamTypes)); 1.22 } 1.23 if (getName(m).equals("<init>")) { 1.24 print(getJavaName(classFile));
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/tools/javap/BoundsTypeVariableTest.java Fri Oct 04 16:08:18 2013 -0700 2.3 @@ -0,0 +1,95 @@ 2.4 +/* 2.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.7 + * 2.8 + * This code is free software; you can redistribute it and/or modify it 2.9 + * under the terms of the GNU General Public License version 2 only, as 2.10 + * published by the Free Software Foundation. 2.11 + * 2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 2.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 2.15 + * version 2 for more details (a copy is included in the LICENSE file that 2.16 + * accompanied this code). 2.17 + * 2.18 + * You should have received a copy of the GNU General Public License version 2.19 + * 2 along with this work; if not, write to the Free Software Foundation, 2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2.21 + * 2.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2.23 + * or visit www.oracle.com if you need additional information or have any 2.24 + * questions. 2.25 + */ 2.26 + 2.27 +/** 2.28 + * @test 2.29 + * @bug 8003537 2.30 + * @summary javap should not use / in Bounds Type Variables 2.31 + */ 2.32 + 2.33 +import java.io.File; 2.34 +import java.io.IOException; 2.35 +import java.io.PrintWriter; 2.36 +import java.io.StringWriter; 2.37 +import java.nio.charset.Charset; 2.38 +import java.nio.file.Files; 2.39 +import java.util.ArrayList; 2.40 +import java.util.List; 2.41 +import java.util.regex.Pattern; 2.42 +import static java.nio.file.StandardOpenOption.*; 2.43 + 2.44 +public class BoundsTypeVariableTest { 2.45 + public static void main(String... args) throws Exception { 2.46 + new BoundsTypeVariableTest().run(); 2.47 + } 2.48 + 2.49 + void run() throws Exception { 2.50 + File srcDir = new File("src"); 2.51 + srcDir.mkdirs(); 2.52 + File classesDir = new File("classes"); 2.53 + classesDir.mkdirs(); 2.54 + final String expect = "public abstract <U extends java.lang.Object> U doit();"; 2.55 + List<String> contents = new ArrayList<>(); 2.56 + contents.add("abstract class X {"); 2.57 + contents.add(expect); 2.58 + contents.add("}"); 2.59 + 2.60 + File f = writeFile(new File(srcDir, "X.java"), contents); 2.61 + javac("-d", classesDir.getPath(), f.getPath()); 2.62 + String out = javap("-p", "-v", new File(classesDir, "X.class").getPath()); 2.63 + if (!out.contains(expect)) { 2.64 + throw new Exception("expected pattern not found: " + expect); 2.65 + } 2.66 + } 2.67 + 2.68 + File writeFile(File f, List<String> body) throws IOException { 2.69 + Files.write(f.toPath(), body, Charset.defaultCharset(), 2.70 + CREATE, TRUNCATE_EXISTING); 2.71 + return f; 2.72 + } 2.73 + 2.74 + void javac(String... args) throws Exception { 2.75 + StringWriter sw = new StringWriter(); 2.76 + PrintWriter pw = new PrintWriter(sw); 2.77 + int rc = com.sun.tools.javac.Main.compile(args, pw); 2.78 + pw.flush(); 2.79 + String out = sw.toString(); 2.80 + if (!out.isEmpty()) 2.81 + System.err.println(out); 2.82 + if (rc != 0) 2.83 + throw new Exception("compilation failed"); 2.84 + } 2.85 + 2.86 + String javap(String... args) throws Exception { 2.87 + StringWriter sw = new StringWriter(); 2.88 + PrintWriter pw = new PrintWriter(sw); 2.89 + int rc = com.sun.tools.javap.Main.run(args, pw); 2.90 + pw.flush(); 2.91 + String out = sw.toString(); 2.92 + if (!out.isEmpty()) 2.93 + System.err.println(out); 2.94 + if (rc != 0) 2.95 + throw new Exception("javap failed"); 2.96 + return out; 2.97 + } 2.98 +}