jaroslav@1646
|
1 |
/*
|
jaroslav@1646
|
2 |
* Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
|
jaroslav@1646
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
jaroslav@1646
|
4 |
*
|
jaroslav@1646
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
jaroslav@1646
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
jaroslav@1646
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
jaroslav@1646
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
jaroslav@1646
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
jaroslav@1646
|
10 |
*
|
jaroslav@1646
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
jaroslav@1646
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
jaroslav@1646
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
jaroslav@1646
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
jaroslav@1646
|
15 |
* accompanied this code).
|
jaroslav@1646
|
16 |
*
|
jaroslav@1646
|
17 |
* You should have received a copy of the GNU General Public License version
|
jaroslav@1646
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
jaroslav@1646
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
jaroslav@1646
|
20 |
*
|
jaroslav@1646
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
jaroslav@1646
|
22 |
* or visit www.oracle.com if you need additional information or have any
|
jaroslav@1646
|
23 |
* questions.
|
jaroslav@1646
|
24 |
*/
|
jaroslav@1646
|
25 |
|
jaroslav@1646
|
26 |
package sun.invoke.anon;
|
jaroslav@1646
|
27 |
|
jaroslav@1646
|
28 |
/**
|
jaroslav@1646
|
29 |
* A visitor called by {@link ConstantPoolParser#parse(ConstantPoolVisitor)}
|
jaroslav@1646
|
30 |
* when a constant pool entry is parsed.
|
jaroslav@1646
|
31 |
* <p>
|
jaroslav@1646
|
32 |
* A visit* method is called when a constant pool entry is parsed.
|
jaroslav@1646
|
33 |
* The first argument is always the constant pool index.
|
jaroslav@1646
|
34 |
* The second argument is always the constant pool tag,
|
jaroslav@1646
|
35 |
* even for methods like {@link #visitUTF8(int, byte, String)} which only apply to one tag.
|
jaroslav@1646
|
36 |
* String arguments refer to Utf8 or NameAndType entries declared elsewhere,
|
jaroslav@1646
|
37 |
* and are always accompanied by the indexes of those entries.
|
jaroslav@1646
|
38 |
* <p>
|
jaroslav@1646
|
39 |
* The order of the calls to the visit* methods is not necessarily related
|
jaroslav@1646
|
40 |
* to the order of the entries in the constant pool.
|
jaroslav@1646
|
41 |
* If one entry has a reference to another entry, the latter (lower-level)
|
jaroslav@1646
|
42 |
* entry will be visited first.
|
jaroslav@1646
|
43 |
* <p>
|
jaroslav@1646
|
44 |
* The following table shows the relation between constant pool entry
|
jaroslav@1646
|
45 |
* types and the corresponding visit* methods:
|
jaroslav@1646
|
46 |
*
|
jaroslav@1646
|
47 |
* <table border=1 cellpadding=5 summary="constant pool visitor methods">
|
jaroslav@1646
|
48 |
* <tr><th>Tag(s)</th><th>Method</th></tr>
|
jaroslav@1646
|
49 |
* <tr>
|
jaroslav@1646
|
50 |
* <td>{@link #CONSTANT_Utf8}</td>
|
jaroslav@1646
|
51 |
* <td>{@link #visitUTF8(int, byte, String)}</td>
|
jaroslav@1646
|
52 |
* </tr><tr>
|
jaroslav@1646
|
53 |
* <td>{@link #CONSTANT_Integer}, {@link #CONSTANT_Float},
|
jaroslav@1646
|
54 |
* {@link #CONSTANT_Long}, {@link #CONSTANT_Double}</td>
|
jaroslav@1646
|
55 |
* <td>{@link #visitConstantValue(int, byte, Object)}</td>
|
jaroslav@1646
|
56 |
* </tr><tr>
|
jaroslav@1646
|
57 |
* <td>{@link #CONSTANT_String}, {@link #CONSTANT_Class}</td>
|
jaroslav@1646
|
58 |
* <td>{@link #visitConstantString(int, byte, String, int)}</td>
|
jaroslav@1646
|
59 |
* </tr><tr>
|
jaroslav@1646
|
60 |
* <td>{@link #CONSTANT_NameAndType}</td>
|
jaroslav@1646
|
61 |
* <td>{@link #visitDescriptor(int, byte, String, String, int, int)}</td>
|
jaroslav@1646
|
62 |
* </tr><tr>
|
jaroslav@1646
|
63 |
* <td>{@link #CONSTANT_Fieldref},
|
jaroslav@1646
|
64 |
* {@link #CONSTANT_Methodref},
|
jaroslav@1646
|
65 |
* {@link #CONSTANT_InterfaceMethodref}</td>
|
jaroslav@1646
|
66 |
* <td>{@link #visitMemberRef(int, byte, String, String, String, int, int)}</td>
|
jaroslav@1646
|
67 |
* </tr>
|
jaroslav@1646
|
68 |
* </table>
|
jaroslav@1646
|
69 |
*
|
jaroslav@1646
|
70 |
* @see ConstantPoolPatch
|
jaroslav@1646
|
71 |
* @author Remi Forax
|
jaroslav@1646
|
72 |
* @author jrose
|
jaroslav@1646
|
73 |
*/
|
jaroslav@1646
|
74 |
public class ConstantPoolVisitor {
|
jaroslav@1646
|
75 |
/** Called each time an UTF8 constant pool entry is found.
|
jaroslav@1646
|
76 |
* @param index the constant pool index
|
jaroslav@1646
|
77 |
* @param tag always {@link #CONSTANT_Utf8}
|
jaroslav@1646
|
78 |
* @param utf8 string encoded in modified UTF-8 format passed as a {@code String}
|
jaroslav@1646
|
79 |
*
|
jaroslav@1646
|
80 |
* @see ConstantPoolPatch#putUTF8(int, String)
|
jaroslav@1646
|
81 |
*/
|
jaroslav@1646
|
82 |
public void visitUTF8(int index, byte tag, String utf8) {
|
jaroslav@1646
|
83 |
// do nothing
|
jaroslav@1646
|
84 |
}
|
jaroslav@1646
|
85 |
|
jaroslav@1646
|
86 |
/** Called for each constant pool entry that encodes an integer,
|
jaroslav@1646
|
87 |
* a float, a long, or a double.
|
jaroslav@1646
|
88 |
* Constant strings and classes are not managed by this method but
|
jaroslav@1646
|
89 |
* by {@link #visitConstantString(int, byte, String, int)}.
|
jaroslav@1646
|
90 |
*
|
jaroslav@1646
|
91 |
* @param index the constant pool index
|
jaroslav@1646
|
92 |
* @param tag one of {@link #CONSTANT_Integer},
|
jaroslav@1646
|
93 |
* {@link #CONSTANT_Float},
|
jaroslav@1646
|
94 |
* {@link #CONSTANT_Long},
|
jaroslav@1646
|
95 |
* or {@link #CONSTANT_Double}
|
jaroslav@1646
|
96 |
* @param value encoded value
|
jaroslav@1646
|
97 |
*
|
jaroslav@1646
|
98 |
* @see ConstantPoolPatch#putConstantValue(int, Object)
|
jaroslav@1646
|
99 |
*/
|
jaroslav@1646
|
100 |
public void visitConstantValue(int index, byte tag, Object value) {
|
jaroslav@1646
|
101 |
// do nothing
|
jaroslav@1646
|
102 |
}
|
jaroslav@1646
|
103 |
|
jaroslav@1646
|
104 |
/** Called for each constant pool entry that encodes a string or a class.
|
jaroslav@1646
|
105 |
* @param index the constant pool index
|
jaroslav@1646
|
106 |
* @param tag one of {@link #CONSTANT_String},
|
jaroslav@1646
|
107 |
* {@link #CONSTANT_Class},
|
jaroslav@1646
|
108 |
* @param name string body or class name (using dot separator)
|
jaroslav@1646
|
109 |
* @param nameIndex the index of the Utf8 string for the name
|
jaroslav@1646
|
110 |
*
|
jaroslav@1646
|
111 |
* @see ConstantPoolPatch#putConstantValue(int, byte, Object)
|
jaroslav@1646
|
112 |
*/
|
jaroslav@1646
|
113 |
public void visitConstantString(int index, byte tag,
|
jaroslav@1646
|
114 |
String name, int nameIndex) {
|
jaroslav@1646
|
115 |
// do nothing
|
jaroslav@1646
|
116 |
}
|
jaroslav@1646
|
117 |
|
jaroslav@1646
|
118 |
/** Called for each constant pool entry that encodes a name and type.
|
jaroslav@1646
|
119 |
* @param index the constant pool index
|
jaroslav@1646
|
120 |
* @param tag always {@link #CONSTANT_NameAndType}
|
jaroslav@1646
|
121 |
* @param memberName a field or method name
|
jaroslav@1646
|
122 |
* @param signature the member signature
|
jaroslav@1646
|
123 |
* @param memberNameIndex index of the Utf8 string for the member name
|
jaroslav@1646
|
124 |
* @param signatureIndex index of the Utf8 string for the signature
|
jaroslav@1646
|
125 |
*
|
jaroslav@1646
|
126 |
* @see ConstantPoolPatch#putDescriptor(int, String, String)
|
jaroslav@1646
|
127 |
*/
|
jaroslav@1646
|
128 |
public void visitDescriptor(int index, byte tag,
|
jaroslav@1646
|
129 |
String memberName, String signature,
|
jaroslav@1646
|
130 |
int memberNameIndex, int signatureIndex) {
|
jaroslav@1646
|
131 |
// do nothing
|
jaroslav@1646
|
132 |
}
|
jaroslav@1646
|
133 |
|
jaroslav@1646
|
134 |
/** Called for each constant pool entry that encodes a field or method.
|
jaroslav@1646
|
135 |
* @param index the constant pool index
|
jaroslav@1646
|
136 |
* @param tag one of {@link #CONSTANT_Fieldref},
|
jaroslav@1646
|
137 |
* or {@link #CONSTANT_Methodref},
|
jaroslav@1646
|
138 |
* or {@link #CONSTANT_InterfaceMethodref}
|
jaroslav@1646
|
139 |
* @param className the class name (using dot separator)
|
jaroslav@1646
|
140 |
* @param memberName name of the field or method
|
jaroslav@1646
|
141 |
* @param signature the field or method signature
|
jaroslav@1646
|
142 |
* @param classNameIndex index of the Utf8 string for the class name
|
jaroslav@1646
|
143 |
* @param descriptorIndex index of the NameAndType descriptor constant
|
jaroslav@1646
|
144 |
*
|
jaroslav@1646
|
145 |
* @see ConstantPoolPatch#putMemberRef(int, byte, String, String, String)
|
jaroslav@1646
|
146 |
*/
|
jaroslav@1646
|
147 |
public void visitMemberRef(int index, byte tag,
|
jaroslav@1646
|
148 |
String className, String memberName, String signature,
|
jaroslav@1646
|
149 |
int classNameIndex, int descriptorIndex) {
|
jaroslav@1646
|
150 |
// do nothing
|
jaroslav@1646
|
151 |
}
|
jaroslav@1646
|
152 |
|
jaroslav@1646
|
153 |
public static final byte
|
jaroslav@1646
|
154 |
CONSTANT_None = 0,
|
jaroslav@1646
|
155 |
CONSTANT_Utf8 = 1,
|
jaroslav@1646
|
156 |
//CONSTANT_Unicode = 2, /* unused */
|
jaroslav@1646
|
157 |
CONSTANT_Integer = 3,
|
jaroslav@1646
|
158 |
CONSTANT_Float = 4,
|
jaroslav@1646
|
159 |
CONSTANT_Long = 5,
|
jaroslav@1646
|
160 |
CONSTANT_Double = 6,
|
jaroslav@1646
|
161 |
CONSTANT_Class = 7,
|
jaroslav@1646
|
162 |
CONSTANT_String = 8,
|
jaroslav@1646
|
163 |
CONSTANT_Fieldref = 9,
|
jaroslav@1646
|
164 |
CONSTANT_Methodref = 10,
|
jaroslav@1646
|
165 |
CONSTANT_InterfaceMethodref = 11,
|
jaroslav@1646
|
166 |
CONSTANT_NameAndType = 12;
|
jaroslav@1646
|
167 |
|
jaroslav@1646
|
168 |
private static String[] TAG_NAMES = {
|
jaroslav@1646
|
169 |
"Empty",
|
jaroslav@1646
|
170 |
"Utf8",
|
jaroslav@1646
|
171 |
null, //"Unicode",
|
jaroslav@1646
|
172 |
"Integer",
|
jaroslav@1646
|
173 |
"Float",
|
jaroslav@1646
|
174 |
"Long",
|
jaroslav@1646
|
175 |
"Double",
|
jaroslav@1646
|
176 |
"Class",
|
jaroslav@1646
|
177 |
"String",
|
jaroslav@1646
|
178 |
"Fieldref",
|
jaroslav@1646
|
179 |
"Methodref",
|
jaroslav@1646
|
180 |
"InterfaceMethodref",
|
jaroslav@1646
|
181 |
"NameAndType"
|
jaroslav@1646
|
182 |
};
|
jaroslav@1646
|
183 |
|
jaroslav@1646
|
184 |
public static String tagName(byte tag) {
|
jaroslav@1646
|
185 |
String name = null;
|
jaroslav@1646
|
186 |
if ((tag & 0xFF) < TAG_NAMES.length)
|
jaroslav@1646
|
187 |
name = TAG_NAMES[tag];
|
jaroslav@1646
|
188 |
if (name == null)
|
jaroslav@1646
|
189 |
name = "Unknown#"+(tag&0xFF);
|
jaroslav@1646
|
190 |
return name;
|
jaroslav@1646
|
191 |
}
|
jaroslav@1646
|
192 |
}
|