author | akulyakh |
Thu, 21 May 2015 11:41:04 -0700 | |
changeset 30730 | d3ce7619db2c |
parent 26389 | b389165f2c78 |
child 30846 | 2b3f379840f0 |
permissions | -rw-r--r-- |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
1 |
/* |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
26389
diff
changeset
|
2 |
* Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved. |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
4 |
* |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
8 |
* |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
13 |
* accompanied this code). |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
14 |
* |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
18 |
* |
5520 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
22 |
*/ |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
23 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
24 |
/* |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
25 |
* @test |
26389
b389165f2c78
8034861: Incorrect format and indentation of InnerClasses section
jjg
parents:
23797
diff
changeset
|
26 |
* @bug 4975569 6622215 8034861 |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
27 |
* @summary javap doesn't print new flag bits |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
26389
diff
changeset
|
28 |
* @modules jdk.compiler |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
29 |
*/ |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
30 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
31 |
import java.io.*; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
32 |
import java.util.*; |
26389
b389165f2c78
8034861: Incorrect format and indentation of InnerClasses section
jjg
parents:
23797
diff
changeset
|
33 |
import java.util.regex.Matcher; |
b389165f2c78
8034861: Incorrect format and indentation of InnerClasses section
jjg
parents:
23797
diff
changeset
|
34 |
import java.util.regex.Pattern; |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
35 |
|
26389
b389165f2c78
8034861: Incorrect format and indentation of InnerClasses section
jjg
parents:
23797
diff
changeset
|
36 |
public class T4975569 { |
b389165f2c78
8034861: Incorrect format and indentation of InnerClasses section
jjg
parents:
23797
diff
changeset
|
37 |
private static final String NEW_LINE = System.getProperty("line.separator"); |
b389165f2c78
8034861: Incorrect format and indentation of InnerClasses section
jjg
parents:
23797
diff
changeset
|
38 |
private static final String TEST_CLASSES = System.getProperty("test.classes", "."); |
b389165f2c78
8034861: Incorrect format and indentation of InnerClasses section
jjg
parents:
23797
diff
changeset
|
39 |
|
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
40 |
public static void main(String... args) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
41 |
new T4975569().run(); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
42 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
43 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
44 |
void run() { |
26389
b389165f2c78
8034861: Incorrect format and indentation of InnerClasses section
jjg
parents:
23797
diff
changeset
|
45 |
verify(Anno.class.getName(), "flags: ACC_INTERFACE, ACC_ABSTRACT, ACC_ANNOTATION"); |
b389165f2c78
8034861: Incorrect format and indentation of InnerClasses section
jjg
parents:
23797
diff
changeset
|
46 |
verify(E.class.getName(), "flags: ACC_FINAL, ACC_SUPER, ACC_ENUM"); |
b389165f2c78
8034861: Incorrect format and indentation of InnerClasses section
jjg
parents:
23797
diff
changeset
|
47 |
verify(S.class.getName(), "flags: ACC_BRIDGE, ACC_SYNTHETIC", |
b389165f2c78
8034861: Incorrect format and indentation of InnerClasses section
jjg
parents:
23797
diff
changeset
|
48 |
"InnerClasses:\n static [# =\\w]+; +// "); |
b389165f2c78
8034861: Incorrect format and indentation of InnerClasses section
jjg
parents:
23797
diff
changeset
|
49 |
verify(V.class.getName(), "void m\\(java.lang.String...\\)", |
b389165f2c78
8034861: Incorrect format and indentation of InnerClasses section
jjg
parents:
23797
diff
changeset
|
50 |
"flags: ACC_VARARGS"); |
b389165f2c78
8034861: Incorrect format and indentation of InnerClasses section
jjg
parents:
23797
diff
changeset
|
51 |
verify(Prot.class.getName(), "InnerClasses:\n protected [# =\\w]+; +// "); |
b389165f2c78
8034861: Incorrect format and indentation of InnerClasses section
jjg
parents:
23797
diff
changeset
|
52 |
verify(Priv.class.getName(), new String[]{"-p"}, |
b389165f2c78
8034861: Incorrect format and indentation of InnerClasses section
jjg
parents:
23797
diff
changeset
|
53 |
"InnerClasses:\n private [# =\\w]+; +// "); |
b389165f2c78
8034861: Incorrect format and indentation of InnerClasses section
jjg
parents:
23797
diff
changeset
|
54 |
|
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
55 |
if (errors > 0) |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
56 |
throw new Error(errors + " found."); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
57 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
58 |
|
26389
b389165f2c78
8034861: Incorrect format and indentation of InnerClasses section
jjg
parents:
23797
diff
changeset
|
59 |
void verify(String className, String[] flags, String... expects) { |
b389165f2c78
8034861: Incorrect format and indentation of InnerClasses section
jjg
parents:
23797
diff
changeset
|
60 |
String output = javap(className, Arrays.asList(flags)); |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
61 |
for (String expect: expects) { |
26389
b389165f2c78
8034861: Incorrect format and indentation of InnerClasses section
jjg
parents:
23797
diff
changeset
|
62 |
Pattern expectPattern = Pattern.compile(expect); |
b389165f2c78
8034861: Incorrect format and indentation of InnerClasses section
jjg
parents:
23797
diff
changeset
|
63 |
Matcher matcher = expectPattern.matcher(output); |
b389165f2c78
8034861: Incorrect format and indentation of InnerClasses section
jjg
parents:
23797
diff
changeset
|
64 |
if (!matcher.find()) { |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
65 |
error(expect + " not found"); |
26389
b389165f2c78
8034861: Incorrect format and indentation of InnerClasses section
jjg
parents:
23797
diff
changeset
|
66 |
} |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
67 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
68 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
69 |
|
26389
b389165f2c78
8034861: Incorrect format and indentation of InnerClasses section
jjg
parents:
23797
diff
changeset
|
70 |
void verify(String className, String... expects) { |
b389165f2c78
8034861: Incorrect format and indentation of InnerClasses section
jjg
parents:
23797
diff
changeset
|
71 |
verify(className, new String[0], expects); |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
72 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
73 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
74 |
int errors; |
26389
b389165f2c78
8034861: Incorrect format and indentation of InnerClasses section
jjg
parents:
23797
diff
changeset
|
75 |
void error(String msg) { |
b389165f2c78
8034861: Incorrect format and indentation of InnerClasses section
jjg
parents:
23797
diff
changeset
|
76 |
System.err.println(msg.replace("\n", NEW_LINE)); |
b389165f2c78
8034861: Incorrect format and indentation of InnerClasses section
jjg
parents:
23797
diff
changeset
|
77 |
errors++; |
b389165f2c78
8034861: Incorrect format and indentation of InnerClasses section
jjg
parents:
23797
diff
changeset
|
78 |
} |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
79 |
|
26389
b389165f2c78
8034861: Incorrect format and indentation of InnerClasses section
jjg
parents:
23797
diff
changeset
|
80 |
String javap(String className, List<String> flags) { |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
81 |
StringWriter sw = new StringWriter(); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
82 |
PrintWriter out = new PrintWriter(sw); |
26389
b389165f2c78
8034861: Incorrect format and indentation of InnerClasses section
jjg
parents:
23797
diff
changeset
|
83 |
List<String> args = new ArrayList<>(flags); |
b389165f2c78
8034861: Incorrect format and indentation of InnerClasses section
jjg
parents:
23797
diff
changeset
|
84 |
args.addAll(Arrays.asList("-v", "-classpath", TEST_CLASSES, className)); |
b389165f2c78
8034861: Incorrect format and indentation of InnerClasses section
jjg
parents:
23797
diff
changeset
|
85 |
int rc = com.sun.tools.javap.Main.run(args.toArray(new String[args.size()]), out); |
b389165f2c78
8034861: Incorrect format and indentation of InnerClasses section
jjg
parents:
23797
diff
changeset
|
86 |
out.close(); |
b389165f2c78
8034861: Incorrect format and indentation of InnerClasses section
jjg
parents:
23797
diff
changeset
|
87 |
String output = sw.toString(); |
b389165f2c78
8034861: Incorrect format and indentation of InnerClasses section
jjg
parents:
23797
diff
changeset
|
88 |
System.err.println("class " + className); |
b389165f2c78
8034861: Incorrect format and indentation of InnerClasses section
jjg
parents:
23797
diff
changeset
|
89 |
System.err.println(output); |
b389165f2c78
8034861: Incorrect format and indentation of InnerClasses section
jjg
parents:
23797
diff
changeset
|
90 |
|
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
91 |
if (rc != 0) |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
92 |
throw new Error("javap failed. rc=" + rc); |
26389
b389165f2c78
8034861: Incorrect format and indentation of InnerClasses section
jjg
parents:
23797
diff
changeset
|
93 |
return output.replaceAll(NEW_LINE, "\n"); |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
94 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
95 |
|
26389
b389165f2c78
8034861: Incorrect format and indentation of InnerClasses section
jjg
parents:
23797
diff
changeset
|
96 |
List x() { return null; } |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
97 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
98 |
class V { void m(String... args) { } } |
26389
b389165f2c78
8034861: Incorrect format and indentation of InnerClasses section
jjg
parents:
23797
diff
changeset
|
99 |
enum E { e } |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
100 |
@interface Anno { } |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
101 |
static class S extends T4975569 { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
102 |
ArrayList x() { return null; } |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
103 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
104 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
105 |
protected class Prot { } |
26389
b389165f2c78
8034861: Incorrect format and indentation of InnerClasses section
jjg
parents:
23797
diff
changeset
|
106 |
private class Priv { int i; } |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
107 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
108 |