author | katleman |
Thu, 21 Aug 2014 14:16:14 -0700 | |
changeset 25878 | 6d561031123e |
parent 20618 | 313dc106ebca |
child 30730 | d3ce7619db2c |
permissions | -rw-r--r-- |
20618
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
1 |
/* |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
2 |
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
4 |
* |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
8 |
* |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
13 |
* accompanied this code). |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
14 |
* |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
18 |
* |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
21 |
* questions. |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
22 |
*/ |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
23 |
|
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
24 |
/** |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
25 |
* @test |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
26 |
* @bug 8003537 |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
27 |
* @summary javap should not use / in Bounds Type Variables |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
28 |
*/ |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
29 |
|
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
30 |
import java.io.File; |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
31 |
import java.io.IOException; |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
32 |
import java.io.PrintWriter; |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
33 |
import java.io.StringWriter; |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
34 |
import java.nio.charset.Charset; |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
35 |
import java.nio.file.Files; |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
36 |
import java.util.ArrayList; |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
37 |
import java.util.List; |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
38 |
import java.util.regex.Pattern; |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
39 |
import static java.nio.file.StandardOpenOption.*; |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
40 |
|
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
41 |
public class BoundsTypeVariableTest { |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
42 |
public static void main(String... args) throws Exception { |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
43 |
new BoundsTypeVariableTest().run(); |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
44 |
} |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
45 |
|
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
46 |
void run() throws Exception { |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
47 |
File srcDir = new File("src"); |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
48 |
srcDir.mkdirs(); |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
49 |
File classesDir = new File("classes"); |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
50 |
classesDir.mkdirs(); |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
51 |
final String expect = "public abstract <U extends java.lang.Object> U doit();"; |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
52 |
List<String> contents = new ArrayList<>(); |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
53 |
contents.add("abstract class X {"); |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
54 |
contents.add(expect); |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
55 |
contents.add("}"); |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
56 |
|
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
57 |
File f = writeFile(new File(srcDir, "X.java"), contents); |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
58 |
javac("-d", classesDir.getPath(), f.getPath()); |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
59 |
String out = javap("-p", "-v", new File(classesDir, "X.class").getPath()); |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
60 |
if (!out.contains(expect)) { |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
61 |
throw new Exception("expected pattern not found: " + expect); |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
62 |
} |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
63 |
} |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
64 |
|
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
65 |
File writeFile(File f, List<String> body) throws IOException { |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
66 |
Files.write(f.toPath(), body, Charset.defaultCharset(), |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
67 |
CREATE, TRUNCATE_EXISTING); |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
68 |
return f; |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
69 |
} |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
70 |
|
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
71 |
void javac(String... args) throws Exception { |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
72 |
StringWriter sw = new StringWriter(); |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
73 |
PrintWriter pw = new PrintWriter(sw); |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
74 |
int rc = com.sun.tools.javac.Main.compile(args, pw); |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
75 |
pw.flush(); |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
76 |
String out = sw.toString(); |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
77 |
if (!out.isEmpty()) |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
78 |
System.err.println(out); |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
79 |
if (rc != 0) |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
80 |
throw new Exception("compilation failed"); |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
81 |
} |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
82 |
|
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
83 |
String javap(String... args) throws Exception { |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
84 |
StringWriter sw = new StringWriter(); |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
85 |
PrintWriter pw = new PrintWriter(sw); |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
86 |
int rc = com.sun.tools.javap.Main.run(args, pw); |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
87 |
pw.flush(); |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
88 |
String out = sw.toString(); |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
89 |
if (!out.isEmpty()) |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
90 |
System.err.println(out); |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
91 |
if (rc != 0) |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
92 |
throw new Exception("javap failed"); |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
93 |
return out; |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
94 |
} |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
diff
changeset
|
95 |
} |