author | katleman |
Thu, 21 Aug 2014 14:16:14 -0700 | |
changeset 25878 | 6d561031123e |
parent 23797 | 756821688d0a |
child 26389 | b389165f2c78 |
permissions | -rw-r--r-- |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
1 |
/* |
23797
756821688d0a
8035104: reorder class file attributes in javap listing
jjg
parents:
5520
diff
changeset
|
2 |
* Copyright (c) 2008, 2014, 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 |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
26 |
* @bug 4975569 6622215 |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
27 |
* @summary javap doesn't print new flag bits |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
28 |
*/ |
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 |
import java.io.*; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
31 |
import java.util.*; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
32 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
33 |
public class T4975569 |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
34 |
{ |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
35 |
public static void main(String... args) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
36 |
new T4975569().run(); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
37 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
38 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
39 |
void run() { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
40 |
verify("T4975569$Anno", "flags: ACC_INTERFACE, ACC_ABSTRACT, ACC_ANNOTATION"); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
41 |
verify("T4975569$E", "flags: ACC_FINAL, ACC_SUPER, ACC_ENUM"); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
42 |
verify("T4975569$S", "flags: ACC_BRIDGE, ACC_SYNTHETIC", |
23797
756821688d0a
8035104: reorder class file attributes in javap listing
jjg
parents:
5520
diff
changeset
|
43 |
"InnerClasses:\n static"); |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
44 |
verify("T4975569$V", "void m(java.lang.String...)", |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
45 |
"flags: ACC_VARARGS"); |
23797
756821688d0a
8035104: reorder class file attributes in javap listing
jjg
parents:
5520
diff
changeset
|
46 |
verify("T4975569$Prot", "InnerClasses:\n protected"); |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
47 |
//verify("T4975569$Priv", "InnerClasses"); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
48 |
if (errors > 0) |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
49 |
throw new Error(errors + " found."); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
50 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
51 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
52 |
void verify(String className, String... expects) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
53 |
String output = javap(className); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
54 |
for (String expect: expects) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
55 |
if (output.indexOf(expect)< 0) |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
56 |
error(expect + " not 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 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
59 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
60 |
void error(String msg) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
61 |
System.err.println(msg); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
62 |
errors++; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
63 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
64 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
65 |
int errors; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
66 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
67 |
String javap(String className) { |
3768 | 68 |
String newline = System.getProperty("line.separator"); |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
69 |
String testClasses = System.getProperty("test.classes", "."); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
70 |
StringWriter sw = new StringWriter(); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
71 |
PrintWriter out = new PrintWriter(sw); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
72 |
String[] args = { "-v", "-classpath", testClasses, className }; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
73 |
int rc = com.sun.tools.javap.Main.run(args, out); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
74 |
if (rc != 0) |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
75 |
throw new Error("javap failed. rc=" + rc); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
76 |
out.close(); |
3768 | 77 |
String output = sw.toString().replaceAll(newline, "\n"); |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
78 |
System.out.println("class " + className); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
79 |
System.out.println(output); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
80 |
return output; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
81 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
82 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
83 |
List x() { return null; }; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
84 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
85 |
class V { void m(String... args) { } } |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
86 |
enum E { e; } |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
87 |
@interface Anno { } |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
88 |
static class S extends T4975569 { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
89 |
ArrayList x() { return null; } |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
90 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
91 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
92 |
protected class Prot { } |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
93 |
//private class Priv { int i; } |
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 |