author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 42822 | langtools/src/jdk.jdeps/share/classes/com/sun/tools/javap/ClassWriter.java@a84956e7ee4d |
child 55242 | 77b54b2822cc |
permissions | -rw-r--r-- |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
1 |
/* |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
2 |
* Copyright (c) 2007, 2016, 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 |
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
10 |
* |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
11 |
* 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
|
12 |
* 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
|
13 |
* 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
|
14 |
* 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
|
15 |
* accompanied this code). |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
16 |
* |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
17 |
* 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
|
18 |
* 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
|
19 |
* 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
|
20 |
* |
5520 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
727
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 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
26 |
package com.sun.tools.javap; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
27 |
|
1039 | 28 |
import java.net.URI; |
2979
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
1039
diff
changeset
|
29 |
import java.text.DateFormat; |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
30 |
import java.util.Collection; |
2979
ea39317acd3d
6824493: experimental support for additional info for instructions
jjg
parents:
1039
diff
changeset
|
31 |
import java.util.Date; |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
32 |
import java.util.List; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
33 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
34 |
import com.sun.tools.classfile.AccessFlags; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
35 |
import com.sun.tools.classfile.Attribute; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
36 |
import com.sun.tools.classfile.Attributes; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
37 |
import com.sun.tools.classfile.ClassFile; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
38 |
import com.sun.tools.classfile.Code_attribute; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
39 |
import com.sun.tools.classfile.ConstantPool; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
40 |
import com.sun.tools.classfile.ConstantPoolException; |
1038 | 41 |
import com.sun.tools.classfile.ConstantValue_attribute; |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
42 |
import com.sun.tools.classfile.Descriptor; |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
43 |
import com.sun.tools.classfile.Descriptor.InvalidDescriptor; |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
44 |
import com.sun.tools.classfile.Exceptions_attribute; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
45 |
import com.sun.tools.classfile.Field; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
46 |
import com.sun.tools.classfile.Method; |
36526 | 47 |
import com.sun.tools.classfile.Module_attribute; |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
48 |
import com.sun.tools.classfile.Signature; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
49 |
import com.sun.tools.classfile.Signature_attribute; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
50 |
import com.sun.tools.classfile.SourceFile_attribute; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
51 |
import com.sun.tools.classfile.Type; |
9078 | 52 |
import com.sun.tools.classfile.Type.ArrayType; |
53 |
import com.sun.tools.classfile.Type.ClassSigType; |
|
54 |
import com.sun.tools.classfile.Type.ClassType; |
|
55 |
import com.sun.tools.classfile.Type.MethodType; |
|
56 |
import com.sun.tools.classfile.Type.SimpleType; |
|
57 |
import com.sun.tools.classfile.Type.TypeParamType; |
|
58 |
import com.sun.tools.classfile.Type.WildcardType; |
|
727
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 |
import static com.sun.tools.classfile.AccessFlags.*; |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
61 |
import static com.sun.tools.classfile.ConstantPool.CONSTANT_Module; |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
62 |
import static com.sun.tools.classfile.ConstantPool.CONSTANT_Package; |
727
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 |
* The main javap class to write the contents of a class file as text. |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
66 |
* |
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
67 |
* <p><b>This is NOT part of any supported API. |
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
68 |
* If you write code that depends on this, you do so at your own risk. |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
69 |
* This code and its internal interfaces are subject to change or |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
70 |
* deletion without notice.</b> |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
71 |
*/ |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
72 |
public class ClassWriter extends BasicWriter { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
73 |
static ClassWriter instance(Context context) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
74 |
ClassWriter instance = context.get(ClassWriter.class); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
75 |
if (instance == null) |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
76 |
instance = new ClassWriter(context); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
77 |
return instance; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
78 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
79 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
80 |
protected ClassWriter(Context context) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
81 |
super(context); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
82 |
context.put(ClassWriter.class, this); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
83 |
options = Options.instance(context); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
84 |
attrWriter = AttributeWriter.instance(context); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
85 |
codeWriter = CodeWriter.instance(context); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
86 |
constantWriter = ConstantWriter.instance(context); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
87 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
88 |
|
1039 | 89 |
void setDigest(String name, byte[] digest) { |
90 |
this.digestName = name; |
|
91 |
this.digest = digest; |
|
92 |
} |
|
93 |
||
94 |
void setFile(URI uri) { |
|
95 |
this.uri = uri; |
|
96 |
} |
|
97 |
||
98 |
void setFileSize(int size) { |
|
99 |
this.size = size; |
|
100 |
} |
|
101 |
||
102 |
void setLastModified(long lastModified) { |
|
103 |
this.lastModified = lastModified; |
|
104 |
} |
|
105 |
||
3141
79c119fae7fb
6852856: javap changes to facilitate subclassing javap for variants
jjg
parents:
2979
diff
changeset
|
106 |
protected ClassFile getClassFile() { |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
107 |
return classFile; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
108 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
109 |
|
3141
79c119fae7fb
6852856: javap changes to facilitate subclassing javap for variants
jjg
parents:
2979
diff
changeset
|
110 |
protected void setClassFile(ClassFile cf) { |
79c119fae7fb
6852856: javap changes to facilitate subclassing javap for variants
jjg
parents:
2979
diff
changeset
|
111 |
classFile = cf; |
79c119fae7fb
6852856: javap changes to facilitate subclassing javap for variants
jjg
parents:
2979
diff
changeset
|
112 |
constant_pool = classFile.constant_pool; |
79c119fae7fb
6852856: javap changes to facilitate subclassing javap for variants
jjg
parents:
2979
diff
changeset
|
113 |
} |
79c119fae7fb
6852856: javap changes to facilitate subclassing javap for variants
jjg
parents:
2979
diff
changeset
|
114 |
|
79c119fae7fb
6852856: javap changes to facilitate subclassing javap for variants
jjg
parents:
2979
diff
changeset
|
115 |
protected Method getMethod() { |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
116 |
return method; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
117 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
118 |
|
3141
79c119fae7fb
6852856: javap changes to facilitate subclassing javap for variants
jjg
parents:
2979
diff
changeset
|
119 |
protected void setMethod(Method m) { |
79c119fae7fb
6852856: javap changes to facilitate subclassing javap for variants
jjg
parents:
2979
diff
changeset
|
120 |
method = m; |
79c119fae7fb
6852856: javap changes to facilitate subclassing javap for variants
jjg
parents:
2979
diff
changeset
|
121 |
} |
79c119fae7fb
6852856: javap changes to facilitate subclassing javap for variants
jjg
parents:
2979
diff
changeset
|
122 |
|
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
123 |
public void write(ClassFile cf) { |
3141
79c119fae7fb
6852856: javap changes to facilitate subclassing javap for variants
jjg
parents:
2979
diff
changeset
|
124 |
setClassFile(cf); |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
125 |
|
22698 | 126 |
if (options.sysInfo || options.verbose) { |
1039 | 127 |
if (uri != null) { |
128 |
if (uri.getScheme().equals("file")) |
|
129 |
println("Classfile " + uri.getPath()); |
|
130 |
else |
|
131 |
println("Classfile " + uri); |
|
132 |
} |
|
3546 | 133 |
indent(+1); |
1039 | 134 |
if (lastModified != -1) { |
135 |
Date lm = new Date(lastModified); |
|
136 |
DateFormat df = DateFormat.getDateInstance(); |
|
137 |
if (size > 0) { |
|
138 |
println("Last modified " + df.format(lm) + "; size " + size + " bytes"); |
|
139 |
} else { |
|
140 |
println("Last modified " + df.format(lm)); |
|
141 |
} |
|
142 |
} else if (size > 0) { |
|
143 |
println("Size " + size + " bytes"); |
|
144 |
} |
|
145 |
if (digestName != null && digest != null) { |
|
146 |
StringBuilder sb = new StringBuilder(); |
|
147 |
for (byte b: digest) |
|
148 |
sb.append(String.format("%02x", b)); |
|
149 |
println(digestName + " checksum " + sb); |
|
150 |
} |
|
151 |
} |
|
152 |
||
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
153 |
Attribute sfa = cf.getAttribute(Attribute.SourceFile); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
154 |
if (sfa instanceof SourceFile_attribute) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
155 |
println("Compiled from \"" + getSourceFile((SourceFile_attribute) sfa) + "\""); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
156 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
157 |
|
22698 | 158 |
if (options.sysInfo || options.verbose) { |
3546 | 159 |
indent(-1); |
160 |
} |
|
161 |
||
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
162 |
AccessFlags flags = cf.access_flags; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
163 |
writeModifiers(flags.getClassModifiers()); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
164 |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
165 |
if (classFile.access_flags.is(AccessFlags.ACC_MODULE)) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
166 |
Attribute attr = classFile.attributes.get(Attribute.Module); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
167 |
if (attr instanceof Module_attribute) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
168 |
Module_attribute modAttr = (Module_attribute) attr; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
169 |
String name; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
170 |
try { |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
171 |
// FIXME: compatibility code |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
172 |
if (constant_pool.get(modAttr.module_name).getTag() == CONSTANT_Module) { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
173 |
name = getJavaName(constant_pool.getModuleInfo(modAttr.module_name).getName()); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
174 |
} else { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
175 |
name = getJavaName(constant_pool.getUTF8Value(modAttr.module_name)); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
176 |
} |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
177 |
} catch (ConstantPoolException e) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
178 |
name = report(e); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
179 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
180 |
if ((modAttr.module_flags & Module_attribute.ACC_OPEN) != 0) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
181 |
print("open "); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
182 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
183 |
print("module "); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
184 |
print(name); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
185 |
if (modAttr.module_version_index != 0) { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
186 |
print("@"); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
187 |
print(getUTF8Value(modAttr.module_version_index)); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
188 |
} |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
189 |
} else { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
190 |
// fallback for malformed class files |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
191 |
print("class "); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
192 |
print(getJavaName(classFile)); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
193 |
} |
36526 | 194 |
} else { |
195 |
if (classFile.isClass()) |
|
196 |
print("class "); |
|
197 |
else if (classFile.isInterface()) |
|
198 |
print("interface "); |
|
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
199 |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
200 |
print(getJavaName(classFile)); |
36526 | 201 |
} |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
202 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
203 |
Signature_attribute sigAttr = getSignature(cf.attributes); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
204 |
if (sigAttr == null) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
205 |
// use info from class file header |
859
16b1ea00598f
6715757: javap does not print "extends java.lang.Object"
jjg
parents:
735
diff
changeset
|
206 |
if (classFile.isClass() && classFile.super_class != 0 ) { |
16b1ea00598f
6715757: javap does not print "extends java.lang.Object"
jjg
parents:
735
diff
changeset
|
207 |
String sn = getJavaSuperclassName(cf); |
9078 | 208 |
if (!sn.equals("java.lang.Object")) { |
209 |
print(" extends "); |
|
210 |
print(sn); |
|
211 |
} |
|
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
212 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
213 |
for (int i = 0; i < classFile.interfaces.length; i++) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
214 |
print(i == 0 ? (classFile.isClass() ? " implements " : " extends ") : ","); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
215 |
print(getJavaInterfaceName(classFile, i)); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
216 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
217 |
} else { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
218 |
try { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
219 |
Type t = sigAttr.getParsedSignature().getType(constant_pool); |
9078 | 220 |
JavaTypePrinter p = new JavaTypePrinter(classFile.isInterface()); |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
221 |
// The signature parser cannot disambiguate between a |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
222 |
// FieldType and a ClassSignatureType that only contains a superclass type. |
9078 | 223 |
if (t instanceof Type.ClassSigType) { |
224 |
print(p.print(t)); |
|
225 |
} else if (options.verbose || !t.isObject()) { |
|
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
226 |
print(" extends "); |
9078 | 227 |
print(p.print(t)); |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
228 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
229 |
} catch (ConstantPoolException e) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
230 |
print(report(e)); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
231 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
232 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
233 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
234 |
if (options.verbose) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
235 |
println(); |
3546 | 236 |
indent(+1); |
237 |
println("minor version: " + cf.minor_version); |
|
238 |
println("major version: " + cf.major_version); |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
239 |
writeList(String.format("flags: (0x%04x) ", flags.flags), flags.getClassFlags(), "\n"); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
240 |
print("this_class: #" + cf.this_class); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
241 |
if (cf.this_class != 0) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
242 |
tab(); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
243 |
print("// " + constantWriter.stringValue(cf.this_class)); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
244 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
245 |
println(); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
246 |
print("super_class: #" + cf.super_class); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
247 |
if (cf.super_class != 0) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
248 |
tab(); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
249 |
print("// " + constantWriter.stringValue(cf.super_class)); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
250 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
251 |
println(); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
252 |
print("interfaces: " + cf.interfaces.length); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
253 |
print(", fields: " + cf.fields.length); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
254 |
print(", methods: " + cf.methods.length); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
255 |
println(", attributes: " + cf.attributes.attrs.length); |
3546 | 256 |
indent(-1); |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
257 |
constantWriter.writeConstantPool(); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
258 |
} else { |
3546 | 259 |
print(" "); |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
260 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
261 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
262 |
println("{"); |
3546 | 263 |
indent(+1); |
36526 | 264 |
if (flags.is(AccessFlags.ACC_MODULE) && !options.verbose) { |
265 |
writeDirectives(); |
|
266 |
} |
|
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
267 |
writeFields(); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
268 |
writeMethods(); |
3546 | 269 |
indent(-1); |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
270 |
println("}"); |
23797
756821688d0a
8035104: reorder class file attributes in javap listing
jjg
parents:
22698
diff
changeset
|
271 |
|
756821688d0a
8035104: reorder class file attributes in javap listing
jjg
parents:
22698
diff
changeset
|
272 |
if (options.verbose) { |
756821688d0a
8035104: reorder class file attributes in javap listing
jjg
parents:
22698
diff
changeset
|
273 |
attrWriter.write(cf, cf.attributes, constant_pool); |
756821688d0a
8035104: reorder class file attributes in javap listing
jjg
parents:
22698
diff
changeset
|
274 |
} |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
275 |
} |
9078 | 276 |
// where |
277 |
class JavaTypePrinter implements Type.Visitor<StringBuilder,StringBuilder> { |
|
278 |
boolean isInterface; |
|
279 |
||
280 |
JavaTypePrinter(boolean isInterface) { |
|
281 |
this.isInterface = isInterface; |
|
282 |
} |
|
283 |
||
284 |
String print(Type t) { |
|
285 |
return t.accept(this, new StringBuilder()).toString(); |
|
286 |
} |
|
287 |
||
20618
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
16291
diff
changeset
|
288 |
String printTypeArgs(List<? extends TypeParamType> typeParamTypes) { |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
16291
diff
changeset
|
289 |
StringBuilder builder = new StringBuilder(); |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
16291
diff
changeset
|
290 |
appendIfNotEmpty(builder, "<", typeParamTypes, "> "); |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
16291
diff
changeset
|
291 |
return builder.toString(); |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
16291
diff
changeset
|
292 |
} |
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
16291
diff
changeset
|
293 |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
294 |
@Override |
9078 | 295 |
public StringBuilder visitSimpleType(SimpleType type, StringBuilder sb) { |
296 |
sb.append(getJavaName(type.name)); |
|
297 |
return sb; |
|
298 |
} |
|
299 |
||
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
300 |
@Override |
9078 | 301 |
public StringBuilder visitArrayType(ArrayType type, StringBuilder sb) { |
302 |
append(sb, type.elemType); |
|
303 |
sb.append("[]"); |
|
304 |
return sb; |
|
305 |
} |
|
306 |
||
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
307 |
@Override |
9078 | 308 |
public StringBuilder visitMethodType(MethodType type, StringBuilder sb) { |
309 |
appendIfNotEmpty(sb, "<", type.typeParamTypes, "> "); |
|
310 |
append(sb, type.returnType); |
|
311 |
append(sb, " (", type.paramTypes, ")"); |
|
312 |
appendIfNotEmpty(sb, " throws ", type.throwsTypes, ""); |
|
313 |
return sb; |
|
314 |
} |
|
315 |
||
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
316 |
@Override |
9078 | 317 |
public StringBuilder visitClassSigType(ClassSigType type, StringBuilder sb) { |
318 |
appendIfNotEmpty(sb, "<", type.typeParamTypes, ">"); |
|
319 |
if (isInterface) { |
|
320 |
appendIfNotEmpty(sb, " extends ", type.superinterfaceTypes, ""); |
|
321 |
} else { |
|
322 |
if (type.superclassType != null |
|
323 |
&& (options.verbose || !type.superclassType.isObject())) { |
|
324 |
sb.append(" extends "); |
|
325 |
append(sb, type.superclassType); |
|
326 |
} |
|
327 |
appendIfNotEmpty(sb, " implements ", type.superinterfaceTypes, ""); |
|
328 |
} |
|
329 |
return sb; |
|
330 |
} |
|
331 |
||
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
332 |
@Override |
9078 | 333 |
public StringBuilder visitClassType(ClassType type, StringBuilder sb) { |
334 |
if (type.outerType != null) { |
|
335 |
append(sb, type.outerType); |
|
336 |
sb.append("."); |
|
337 |
} |
|
338 |
sb.append(getJavaName(type.name)); |
|
339 |
appendIfNotEmpty(sb, "<", type.typeArgs, ">"); |
|
340 |
return sb; |
|
341 |
} |
|
342 |
||
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
343 |
@Override |
9078 | 344 |
public StringBuilder visitTypeParamType(TypeParamType type, StringBuilder sb) { |
345 |
sb.append(type.name); |
|
346 |
String sep = " extends "; |
|
347 |
if (type.classBound != null |
|
348 |
&& (options.verbose || !type.classBound.isObject())) { |
|
349 |
sb.append(sep); |
|
350 |
append(sb, type.classBound); |
|
351 |
sep = " & "; |
|
352 |
} |
|
353 |
if (type.interfaceBounds != null) { |
|
354 |
for (Type bound: type.interfaceBounds) { |
|
355 |
sb.append(sep); |
|
356 |
append(sb, bound); |
|
357 |
sep = " & "; |
|
358 |
} |
|
359 |
} |
|
360 |
return sb; |
|
361 |
} |
|
362 |
||
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
363 |
@Override |
9078 | 364 |
public StringBuilder visitWildcardType(WildcardType type, StringBuilder sb) { |
365 |
switch (type.kind) { |
|
366 |
case UNBOUNDED: |
|
367 |
sb.append("?"); |
|
368 |
break; |
|
369 |
case EXTENDS: |
|
370 |
sb.append("? extends "); |
|
371 |
append(sb, type.boundType); |
|
372 |
break; |
|
373 |
case SUPER: |
|
374 |
sb.append("? super "); |
|
375 |
append(sb, type.boundType); |
|
376 |
break; |
|
377 |
default: |
|
378 |
throw new AssertionError(); |
|
379 |
} |
|
380 |
return sb; |
|
381 |
} |
|
382 |
||
383 |
private void append(StringBuilder sb, Type t) { |
|
384 |
t.accept(this, sb); |
|
385 |
} |
|
386 |
||
387 |
private void append(StringBuilder sb, String prefix, List<? extends Type> list, String suffix) { |
|
388 |
sb.append(prefix); |
|
389 |
String sep = ""; |
|
390 |
for (Type t: list) { |
|
391 |
sb.append(sep); |
|
392 |
append(sb, t); |
|
393 |
sep = ", "; |
|
394 |
} |
|
395 |
sb.append(suffix); |
|
396 |
} |
|
397 |
||
398 |
private void appendIfNotEmpty(StringBuilder sb, String prefix, List<? extends Type> list, String suffix) { |
|
399 |
if (!isEmpty(list)) |
|
400 |
append(sb, prefix, list, suffix); |
|
401 |
} |
|
402 |
||
403 |
private boolean isEmpty(List<? extends Type> list) { |
|
404 |
return (list == null || list.isEmpty()); |
|
405 |
} |
|
406 |
} |
|
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
407 |
|
3141
79c119fae7fb
6852856: javap changes to facilitate subclassing javap for variants
jjg
parents:
2979
diff
changeset
|
408 |
protected void writeFields() { |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
409 |
for (Field f: classFile.fields) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
410 |
writeField(f); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
411 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
412 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
413 |
|
3141
79c119fae7fb
6852856: javap changes to facilitate subclassing javap for variants
jjg
parents:
2979
diff
changeset
|
414 |
protected void writeField(Field f) { |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
415 |
if (!options.checkAccess(f.access_flags)) |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
416 |
return; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
417 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
418 |
AccessFlags flags = f.access_flags; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
419 |
writeModifiers(flags.getFieldModifiers()); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
420 |
Signature_attribute sigAttr = getSignature(f.attributes); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
421 |
if (sigAttr == null) |
5216
b7f7018fa96a
6937244: sqe ws7 tools javap/javap_t10a fail jdk7 b80 used output of javap is changed
jjg
parents:
4076
diff
changeset
|
422 |
print(getJavaFieldType(f.descriptor)); |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
423 |
else { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
424 |
try { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
425 |
Type t = sigAttr.getParsedSignature().getType(constant_pool); |
5216
b7f7018fa96a
6937244: sqe ws7 tools javap/javap_t10a fail jdk7 b80 used output of javap is changed
jjg
parents:
4076
diff
changeset
|
426 |
print(getJavaName(t.toString())); |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
427 |
} catch (ConstantPoolException e) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
428 |
// report error? |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
429 |
// fall back on non-generic descriptor |
5216
b7f7018fa96a
6937244: sqe ws7 tools javap/javap_t10a fail jdk7 b80 used output of javap is changed
jjg
parents:
4076
diff
changeset
|
430 |
print(getJavaFieldType(f.descriptor)); |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
431 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
432 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
433 |
print(" "); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
434 |
print(getFieldName(f)); |
22698 | 435 |
if (options.showConstants) { |
1038 | 436 |
Attribute a = f.attributes.get(Attribute.ConstantValue); |
437 |
if (a instanceof ConstantValue_attribute) { |
|
438 |
print(" = "); |
|
439 |
ConstantValue_attribute cv = (ConstantValue_attribute) a; |
|
440 |
print(getConstantValue(f.descriptor, cv.constantvalue_index)); |
|
441 |
} |
|
442 |
} |
|
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
443 |
print(";"); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
444 |
println(); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
445 |
|
3546 | 446 |
indent(+1); |
447 |
||
22695
a290c74925d7
8032819: Extra empty line between field declarations for the "-v -c" and "-v -l" combination of options
jjg
parents:
22693
diff
changeset
|
448 |
boolean showBlank = false; |
a290c74925d7
8032819: Extra empty line between field declarations for the "-v -c" and "-v -l" combination of options
jjg
parents:
22693
diff
changeset
|
449 |
|
16291
d4249734ecd8
8007052: javap should include the descriptor for a method in verbose mode
jjg
parents:
15036
diff
changeset
|
450 |
if (options.showDescriptors) |
d4249734ecd8
8007052: javap should include the descriptor for a method in verbose mode
jjg
parents:
15036
diff
changeset
|
451 |
println("descriptor: " + getValue(f.descriptor)); |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
452 |
|
22698 | 453 |
if (options.verbose) |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
454 |
writeList(String.format("flags: (0x%04x) ", flags.flags), flags.getFieldFlags(), "\n"); |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
455 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
456 |
if (options.showAllAttrs) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
457 |
for (Attribute attr: f.attributes) |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
458 |
attrWriter.write(f, attr, constant_pool); |
22695
a290c74925d7
8032819: Extra empty line between field declarations for the "-v -c" and "-v -l" combination of options
jjg
parents:
22693
diff
changeset
|
459 |
showBlank = true; |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
460 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
461 |
|
3546 | 462 |
indent(-1); |
463 |
||
22695
a290c74925d7
8032819: Extra empty line between field declarations for the "-v -c" and "-v -l" combination of options
jjg
parents:
22693
diff
changeset
|
464 |
if (showBlank || options.showDisassembled || options.showLineAndLocalVariableTables) |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
465 |
println(); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
466 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
467 |
|
3141
79c119fae7fb
6852856: javap changes to facilitate subclassing javap for variants
jjg
parents:
2979
diff
changeset
|
468 |
protected void writeMethods() { |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
469 |
for (Method m: classFile.methods) |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
470 |
writeMethod(m); |
3546 | 471 |
setPendingNewline(false); |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
472 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
473 |
|
3141
79c119fae7fb
6852856: javap changes to facilitate subclassing javap for variants
jjg
parents:
2979
diff
changeset
|
474 |
protected void writeMethod(Method m) { |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
475 |
if (!options.checkAccess(m.access_flags)) |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
476 |
return; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
477 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
478 |
method = m; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
479 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
480 |
AccessFlags flags = m.access_flags; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
481 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
482 |
Descriptor d; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
483 |
Type.MethodType methodType; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
484 |
List<? extends Type> methodExceptions; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
485 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
486 |
Signature_attribute sigAttr = getSignature(m.attributes); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
487 |
if (sigAttr == null) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
488 |
d = m.descriptor; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
489 |
methodType = null; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
490 |
methodExceptions = null; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
491 |
} else { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
492 |
Signature methodSig = sigAttr.getParsedSignature(); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
493 |
d = methodSig; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
494 |
try { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
495 |
methodType = (Type.MethodType) methodSig.getType(constant_pool); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
496 |
methodExceptions = methodType.throwsTypes; |
9078 | 497 |
if (methodExceptions != null && methodExceptions.isEmpty()) |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
498 |
methodExceptions = null; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
499 |
} catch (ConstantPoolException e) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
500 |
// report error? |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
501 |
// fall back on standard descriptor |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
502 |
methodType = null; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
503 |
methodExceptions = null; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
504 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
505 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
506 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
507 |
writeModifiers(flags.getMethodModifiers()); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
508 |
if (methodType != null) { |
20618
313dc106ebca
8003537: javap use internal class name when printing bound of type variable
ksrini
parents:
16291
diff
changeset
|
509 |
print(new JavaTypePrinter(false).printTypeArgs(methodType.typeParamTypes)); |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
510 |
} |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
511 |
switch (getName(m)) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
512 |
case "<init>": |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
513 |
print(getJavaName(classFile)); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
514 |
print(getJavaParameterTypes(d, flags)); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
515 |
break; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
516 |
case "<clinit>": |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
517 |
print("{}"); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
518 |
break; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
519 |
default: |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
520 |
print(getJavaReturnType(d)); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
521 |
print(" "); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
522 |
print(getName(m)); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
523 |
print(getJavaParameterTypes(d, flags)); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
524 |
break; |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
525 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
526 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
527 |
Attribute e_attr = m.attributes.get(Attribute.Exceptions); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
528 |
if (e_attr != null) { // if there are generic exceptions, there must be erased exceptions |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
529 |
if (e_attr instanceof Exceptions_attribute) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
530 |
Exceptions_attribute exceptions = (Exceptions_attribute) e_attr; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
531 |
print(" throws "); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
532 |
if (methodExceptions != null) { // use generic list if available |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
533 |
writeList("", methodExceptions, ""); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
534 |
} else { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
535 |
for (int i = 0; i < exceptions.number_of_exceptions; i++) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
536 |
if (i > 0) |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
537 |
print(", "); |
733 | 538 |
print(getJavaException(exceptions, i)); |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
539 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
540 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
541 |
} else { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
542 |
report("Unexpected or invalid value for Exceptions attribute"); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
543 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
544 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
545 |
|
3546 | 546 |
println(";"); |
547 |
||
548 |
indent(+1); |
|
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
549 |
|
16291
d4249734ecd8
8007052: javap should include the descriptor for a method in verbose mode
jjg
parents:
15036
diff
changeset
|
550 |
if (options.showDescriptors) { |
d4249734ecd8
8007052: javap should include the descriptor for a method in verbose mode
jjg
parents:
15036
diff
changeset
|
551 |
println("descriptor: " + getValue(m.descriptor)); |
3546 | 552 |
} |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
553 |
|
22698 | 554 |
if (options.verbose) { |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
555 |
writeList(String.format("flags: (0x%04x) ", flags.flags), flags.getMethodFlags(), "\n"); |
3546 | 556 |
} |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
557 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
558 |
Code_attribute code = null; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
559 |
Attribute c_attr = m.attributes.get(Attribute.Code); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
560 |
if (c_attr != null) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
561 |
if (c_attr instanceof Code_attribute) |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
562 |
code = (Code_attribute) c_attr; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
563 |
else |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
564 |
report("Unexpected or invalid value for Code attribute"); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
565 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
566 |
|
22693
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
20618
diff
changeset
|
567 |
if (options.showAllAttrs) { |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
20618
diff
changeset
|
568 |
Attribute[] attrs = m.attributes.attrs; |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
20618
diff
changeset
|
569 |
for (Attribute attr: attrs) |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
20618
diff
changeset
|
570 |
attrWriter.write(m, attr, constant_pool); |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
20618
diff
changeset
|
571 |
} else if (code != null) { |
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
20618
diff
changeset
|
572 |
if (options.showDisassembled) { |
3546 | 573 |
println("Code:"); |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
574 |
codeWriter.writeInstrs(code); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
575 |
codeWriter.writeExceptionTable(code); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
576 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
577 |
|
22693
d9f55dfc5f3b
8032814: LineNumberTable/LocalVariableTable tables duplication for the "-v -l" combination of options
jjg
parents:
20618
diff
changeset
|
578 |
if (options.showLineAndLocalVariableTables) { |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
579 |
attrWriter.write(code, code.attributes.get(Attribute.LineNumberTable), constant_pool); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
580 |
attrWriter.write(code, code.attributes.get(Attribute.LocalVariableTable), constant_pool); |
3546 | 581 |
} |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
582 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
583 |
|
3546 | 584 |
indent(-1); |
585 |
||
586 |
// set pendingNewline to write a newline before the next method (if any) |
|
587 |
// if a separator is desired |
|
588 |
setPendingNewline( |
|
589 |
options.showDisassembled || |
|
590 |
options.showAllAttrs || |
|
16291
d4249734ecd8
8007052: javap should include the descriptor for a method in verbose mode
jjg
parents:
15036
diff
changeset
|
591 |
options.showDescriptors || |
3546 | 592 |
options.showLineAndLocalVariableTables || |
593 |
options.verbose); |
|
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
594 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
595 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
596 |
void writeModifiers(Collection<String> items) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
597 |
for (Object item: items) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
598 |
print(item); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
599 |
print(" "); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
600 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
601 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
602 |
|
36526 | 603 |
void writeDirectives() { |
604 |
Attribute attr = classFile.attributes.get(Attribute.Module); |
|
605 |
if (!(attr instanceof Module_attribute)) |
|
606 |
return; |
|
607 |
||
608 |
Module_attribute m = (Module_attribute) attr; |
|
609 |
for (Module_attribute.RequiresEntry entry: m.requires) { |
|
610 |
print("requires"); |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
611 |
if ((entry.requires_flags & Module_attribute.ACC_STATIC_PHASE) != 0) |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
612 |
print(" static"); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
613 |
if ((entry.requires_flags & Module_attribute.ACC_TRANSITIVE) != 0) |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
614 |
print(" transitive"); |
36526 | 615 |
print(" "); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
616 |
String mname; |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
617 |
try { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
618 |
mname = getModuleName(entry.requires_index); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
619 |
} catch (ConstantPoolException e) { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
620 |
mname = report(e); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
621 |
} |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
622 |
print(mname); |
36526 | 623 |
println(";"); |
624 |
} |
|
625 |
||
626 |
for (Module_attribute.ExportsEntry entry: m.exports) { |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
627 |
print("exports"); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
628 |
print(" "); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
629 |
String pname; |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
630 |
try { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
631 |
pname = getPackageName(entry.exports_index).replace('/', '.'); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
632 |
} catch (ConstantPoolException e) { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
633 |
pname = report(e); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
634 |
} |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
635 |
print(pname); |
36526 | 636 |
boolean first = true; |
637 |
for (int i: entry.exports_to_index) { |
|
638 |
String mname; |
|
639 |
try { |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
640 |
mname = getModuleName(i); |
36526 | 641 |
} catch (ConstantPoolException e) { |
642 |
mname = report(e); |
|
643 |
} |
|
644 |
if (first) { |
|
645 |
println(" to"); |
|
646 |
indent(+1); |
|
647 |
first = false; |
|
648 |
} else { |
|
649 |
println(","); |
|
650 |
} |
|
651 |
print(mname); |
|
652 |
} |
|
653 |
println(";"); |
|
654 |
if (!first) |
|
655 |
indent(-1); |
|
656 |
} |
|
657 |
||
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
658 |
for (Module_attribute.OpensEntry entry: m.opens) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
659 |
print("opens"); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
660 |
print(" "); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
661 |
String pname; |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
662 |
try { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
663 |
pname = getPackageName(entry.opens_index).replace('/', '.'); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
664 |
} catch (ConstantPoolException e) { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
665 |
pname = report(e); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
666 |
} |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
667 |
print(pname); |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
668 |
boolean first = true; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
669 |
for (int i: entry.opens_to_index) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
670 |
String mname; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
671 |
try { |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
672 |
mname = getModuleName(i); |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
673 |
} catch (ConstantPoolException e) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
674 |
mname = report(e); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
675 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
676 |
if (first) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
677 |
println(" to"); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
678 |
indent(+1); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
679 |
first = false; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
680 |
} else { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
681 |
println(","); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
682 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
683 |
print(mname); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
684 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
685 |
println(";"); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
686 |
if (!first) |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
687 |
indent(-1); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
688 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
689 |
|
36526 | 690 |
for (int entry: m.uses_index) { |
691 |
print("uses "); |
|
692 |
print(getClassName(entry).replace('/', '.')); |
|
693 |
println(";"); |
|
694 |
} |
|
695 |
||
696 |
for (Module_attribute.ProvidesEntry entry: m.provides) { |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
697 |
print("provides "); |
36526 | 698 |
print(getClassName(entry.provides_index).replace('/', '.')); |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
699 |
boolean first = true; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
700 |
for (int i: entry.with_index) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
701 |
if (first) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
702 |
println(" with"); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
703 |
indent(+1); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
704 |
first = false; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
705 |
} else { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
706 |
println(","); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
707 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
708 |
print(getClassName(i).replace('/', '.')); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
709 |
} |
36526 | 710 |
println(";"); |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
711 |
if (!first) |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
712 |
indent(-1); |
36526 | 713 |
} |
714 |
} |
|
715 |
||
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
716 |
String getModuleName(int index) throws ConstantPoolException { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
717 |
if (constant_pool.get(index).getTag() == CONSTANT_Module) { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
718 |
return constant_pool.getModuleInfo(index).getName(); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
719 |
} else { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
720 |
return constant_pool.getUTF8Value(index); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
721 |
} |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
722 |
} |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
723 |
|
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
724 |
String getPackageName(int index) throws ConstantPoolException { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
725 |
if (constant_pool.get(index).getTag() == CONSTANT_Package) { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
726 |
return constant_pool.getPackageInfo(index).getName(); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
727 |
} else { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
728 |
return constant_pool.getUTF8Value(index); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
729 |
} |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
730 |
} |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
731 |
|
36526 | 732 |
String getUTF8Value(int index) { |
733 |
try { |
|
734 |
return classFile.constant_pool.getUTF8Value(index); |
|
735 |
} catch (ConstantPoolException e) { |
|
736 |
return report(e); |
|
737 |
} |
|
738 |
} |
|
739 |
||
740 |
String getClassName(int index) { |
|
741 |
try { |
|
742 |
return classFile.constant_pool.getClassInfo(index).getName(); |
|
743 |
} catch (ConstantPoolException e) { |
|
744 |
return report(e); |
|
745 |
} |
|
746 |
} |
|
747 |
||
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
748 |
void writeList(String prefix, Collection<?> items, String suffix) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
749 |
print(prefix); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
750 |
String sep = ""; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
751 |
for (Object item: items) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
752 |
print(sep); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
753 |
print(item); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
754 |
sep = ", "; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
755 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
756 |
print(suffix); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
757 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
758 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
759 |
void writeListIfNotEmpty(String prefix, List<?> items, String suffix) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
760 |
if (items != null && items.size() > 0) |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
761 |
writeList(prefix, items, suffix); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
762 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
763 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
764 |
Signature_attribute getSignature(Attributes attributes) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
765 |
return (Signature_attribute) attributes.get(Attribute.Signature); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
766 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
767 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
768 |
String adjustVarargs(AccessFlags flags, String params) { |
22698 | 769 |
if (flags.is(ACC_VARARGS)) { |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
770 |
int i = params.lastIndexOf("[]"); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
771 |
if (i > 0) |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
772 |
return params.substring(0, i) + "..." + params.substring(i+2); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
773 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
774 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
775 |
return params; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
776 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
777 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
778 |
String getJavaName(ClassFile cf) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
779 |
try { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
780 |
return getJavaName(cf.getName()); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
781 |
} catch (ConstantPoolException e) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
782 |
return report(e); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
783 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
784 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
785 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
786 |
String getJavaSuperclassName(ClassFile cf) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
787 |
try { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
788 |
return getJavaName(cf.getSuperclassName()); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
789 |
} catch (ConstantPoolException e) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
790 |
return report(e); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
791 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
792 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
793 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
794 |
String getJavaInterfaceName(ClassFile cf, int index) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
795 |
try { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
796 |
return getJavaName(cf.getInterfaceName(index)); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
797 |
} catch (ConstantPoolException e) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
798 |
return report(e); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
799 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
800 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
801 |
|
5216
b7f7018fa96a
6937244: sqe ws7 tools javap/javap_t10a fail jdk7 b80 used output of javap is changed
jjg
parents:
4076
diff
changeset
|
802 |
String getJavaFieldType(Descriptor d) { |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
803 |
try { |
5216
b7f7018fa96a
6937244: sqe ws7 tools javap/javap_t10a fail jdk7 b80 used output of javap is changed
jjg
parents:
4076
diff
changeset
|
804 |
return getJavaName(d.getFieldType(constant_pool)); |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
805 |
} catch (ConstantPoolException e) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
806 |
return report(e); |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
807 |
} catch (InvalidDescriptor e) { |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
808 |
return report(e); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
809 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
810 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
811 |
|
5216
b7f7018fa96a
6937244: sqe ws7 tools javap/javap_t10a fail jdk7 b80 used output of javap is changed
jjg
parents:
4076
diff
changeset
|
812 |
String getJavaReturnType(Descriptor d) { |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
813 |
try { |
5216
b7f7018fa96a
6937244: sqe ws7 tools javap/javap_t10a fail jdk7 b80 used output of javap is changed
jjg
parents:
4076
diff
changeset
|
814 |
return getJavaName(d.getReturnType(constant_pool)); |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
815 |
} catch (ConstantPoolException e) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
816 |
return report(e); |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
817 |
} catch (InvalidDescriptor e) { |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
818 |
return report(e); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
819 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
820 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
821 |
|
5216
b7f7018fa96a
6937244: sqe ws7 tools javap/javap_t10a fail jdk7 b80 used output of javap is changed
jjg
parents:
4076
diff
changeset
|
822 |
String getJavaParameterTypes(Descriptor d, AccessFlags flags) { |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
823 |
try { |
5216
b7f7018fa96a
6937244: sqe ws7 tools javap/javap_t10a fail jdk7 b80 used output of javap is changed
jjg
parents:
4076
diff
changeset
|
824 |
return getJavaName(adjustVarargs(flags, d.getParameterTypes(constant_pool))); |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
825 |
} catch (ConstantPoolException e) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
826 |
return report(e); |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
827 |
} catch (InvalidDescriptor e) { |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
828 |
return report(e); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
829 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
830 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
831 |
|
733 | 832 |
String getJavaException(Exceptions_attribute attr, int index) { |
833 |
try { |
|
834 |
return getJavaName(attr.getException(index, constant_pool)); |
|
835 |
} catch (ConstantPoolException e) { |
|
836 |
return report(e); |
|
837 |
} |
|
838 |
} |
|
839 |
||
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
840 |
String getValue(Descriptor d) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
841 |
try { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
842 |
return d.getValue(constant_pool); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
843 |
} catch (ConstantPoolException e) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
844 |
return report(e); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
845 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
846 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
847 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
848 |
String getFieldName(Field f) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
849 |
try { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
850 |
return f.getName(constant_pool); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
851 |
} catch (ConstantPoolException e) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
852 |
return report(e); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
853 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
854 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
855 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
856 |
String getName(Method m) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
857 |
try { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
858 |
return m.getName(constant_pool); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
859 |
} catch (ConstantPoolException e) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
860 |
return report(e); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
861 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
862 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
863 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
864 |
static String getJavaName(String name) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
865 |
return name.replace('/', '.'); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
866 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
867 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
868 |
String getSourceFile(SourceFile_attribute attr) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
869 |
try { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
870 |
return attr.getSourceFile(constant_pool); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
871 |
} catch (ConstantPoolException e) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
872 |
return report(e); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
873 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
874 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
875 |
|
1038 | 876 |
/** |
877 |
* Get the value of an entry in the constant pool as a Java constant. |
|
878 |
* Characters and booleans are represented by CONSTANT_Intgere entries. |
|
879 |
* Character and string values are processed to escape characters outside |
|
880 |
* the basic printable ASCII set. |
|
881 |
* @param d the descriptor, giving the expected type of the constant |
|
882 |
* @param index the index of the value in the constant pool |
|
883 |
* @return a printable string containing the value of the constant. |
|
884 |
*/ |
|
885 |
String getConstantValue(Descriptor d, int index) { |
|
886 |
try { |
|
887 |
ConstantPool.CPInfo cpInfo = constant_pool.get(index); |
|
888 |
||
889 |
switch (cpInfo.getTag()) { |
|
890 |
case ConstantPool.CONSTANT_Integer: { |
|
891 |
ConstantPool.CONSTANT_Integer_info info = |
|
892 |
(ConstantPool.CONSTANT_Integer_info) cpInfo; |
|
893 |
String t = d.getValue(constant_pool); |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
894 |
switch (t) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
895 |
case "C": |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
896 |
// character |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
897 |
return getConstantCharValue((char) info.value); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
898 |
case "Z": |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
899 |
// boolean |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
900 |
return String.valueOf(info.value == 1); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
901 |
default: |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
902 |
// other: assume integer |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
903 |
return String.valueOf(info.value); |
1038 | 904 |
} |
905 |
} |
|
906 |
||
907 |
case ConstantPool.CONSTANT_String: { |
|
908 |
ConstantPool.CONSTANT_String_info info = |
|
909 |
(ConstantPool.CONSTANT_String_info) cpInfo; |
|
910 |
return getConstantStringValue(info.getString()); |
|
911 |
} |
|
912 |
||
913 |
default: |
|
914 |
return constantWriter.stringValue(cpInfo); |
|
915 |
} |
|
916 |
} catch (ConstantPoolException e) { |
|
917 |
return "#" + index; |
|
918 |
} |
|
919 |
} |
|
920 |
||
921 |
private String getConstantCharValue(char c) { |
|
922 |
StringBuilder sb = new StringBuilder(); |
|
923 |
sb.append('\''); |
|
924 |
sb.append(esc(c, '\'')); |
|
925 |
sb.append('\''); |
|
926 |
return sb.toString(); |
|
927 |
} |
|
928 |
||
929 |
private String getConstantStringValue(String s) { |
|
930 |
StringBuilder sb = new StringBuilder(); |
|
931 |
sb.append("\""); |
|
932 |
for (int i = 0; i < s.length(); i++) { |
|
933 |
sb.append(esc(s.charAt(i), '"')); |
|
934 |
} |
|
935 |
sb.append("\""); |
|
936 |
return sb.toString(); |
|
937 |
} |
|
938 |
||
939 |
private String esc(char c, char quote) { |
|
39919
3d3573afc062
8143366: Control characters in constant pool strings are not escaped properly
sdrach
parents:
36526
diff
changeset
|
940 |
if (32 <= c && c <= 126 && c != quote && c != '\\') |
1038 | 941 |
return String.valueOf(c); |
942 |
else switch (c) { |
|
943 |
case '\b': return "\\b"; |
|
944 |
case '\n': return "\\n"; |
|
945 |
case '\t': return "\\t"; |
|
946 |
case '\f': return "\\f"; |
|
947 |
case '\r': return "\\r"; |
|
948 |
case '\\': return "\\\\"; |
|
949 |
case '\'': return "\\'"; |
|
950 |
case '\"': return "\\\""; |
|
951 |
default: return String.format("\\u%04x", (int) c); |
|
952 |
} |
|
953 |
} |
|
954 |
||
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
955 |
private final Options options; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
956 |
private final AttributeWriter attrWriter; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
957 |
private final CodeWriter codeWriter; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39919
diff
changeset
|
958 |
private final ConstantWriter constantWriter; |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
959 |
private ClassFile classFile; |
1039 | 960 |
private URI uri; |
961 |
private long lastModified; |
|
962 |
private String digestName; |
|
963 |
private byte[] digest; |
|
964 |
private int size; |
|
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
965 |
private ConstantPool constant_pool; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
966 |
private Method method; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
967 |
} |