Tue, 19 May 2009 11:33:13 -0700
6841420: classfile: add new methods to ConstantClassInfo
Reviewed-by: mcimadamore
Contributed-by: kevin.t.looney@sun.com
jjg@46 | 1 | /* |
xdono@229 | 2 | * Copyright 2007-2009 Sun Microsystems, Inc. All Rights Reserved. |
jjg@46 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
jjg@46 | 4 | * |
jjg@46 | 5 | * This code is free software; you can redistribute it and/or modify it |
jjg@46 | 6 | * under the terms of the GNU General Public License version 2 only, as |
jjg@46 | 7 | * published by the Free Software Foundation. Sun designates this |
jjg@46 | 8 | * particular file as subject to the "Classpath" exception as provided |
jjg@46 | 9 | * by Sun in the LICENSE file that accompanied this code. |
jjg@46 | 10 | * |
jjg@46 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
jjg@46 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
jjg@46 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
jjg@46 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
jjg@46 | 15 | * accompanied this code). |
jjg@46 | 16 | * |
jjg@46 | 17 | * You should have received a copy of the GNU General Public License version |
jjg@46 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
jjg@46 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
jjg@46 | 20 | * |
jjg@46 | 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
jjg@46 | 22 | * CA 95054 USA or visit www.sun.com if you need additional information or |
jjg@46 | 23 | * have any questions. |
jjg@46 | 24 | */ |
jjg@46 | 25 | |
jjg@46 | 26 | package com.sun.tools.classfile; |
jjg@46 | 27 | |
jjg@46 | 28 | import java.io.IOException; |
jjg@46 | 29 | |
jjg@46 | 30 | /** |
jjg@46 | 31 | * See JVMS3, section 4.5. |
jjg@46 | 32 | * |
jjg@46 | 33 | * <p><b>This is NOT part of any API supported by Sun Microsystems. If |
jjg@46 | 34 | * you write code that depends on this, you do so at your own risk. |
jjg@46 | 35 | * This code and its internal interfaces are subject to change or |
jjg@46 | 36 | * deletion without notice.</b> |
jjg@46 | 37 | */ |
jjg@46 | 38 | public class ConstantPool { |
jjg@46 | 39 | |
jjg@46 | 40 | public class InvalidIndex extends ConstantPoolException { |
jjg@198 | 41 | private static final long serialVersionUID = -4350294289300939730L; |
jjg@46 | 42 | InvalidIndex(int index) { |
jjg@46 | 43 | super(index); |
jjg@46 | 44 | } |
jjg@46 | 45 | |
jjg@46 | 46 | @Override |
jjg@46 | 47 | public String getMessage() { |
jjg@46 | 48 | // i18n |
jjg@46 | 49 | return "invalid index #" + index; |
jjg@46 | 50 | } |
jjg@46 | 51 | } |
jjg@46 | 52 | |
jjg@46 | 53 | public class UnexpectedEntry extends ConstantPoolException { |
jjg@198 | 54 | private static final long serialVersionUID = 6986335935377933211L; |
jjg@46 | 55 | UnexpectedEntry(int index, int expected_tag, int found_tag) { |
jjg@46 | 56 | super(index); |
jjg@46 | 57 | this.expected_tag = expected_tag; |
jjg@46 | 58 | this.found_tag = found_tag; |
jjg@46 | 59 | } |
jjg@46 | 60 | |
jjg@46 | 61 | @Override |
jjg@46 | 62 | public String getMessage() { |
jjg@46 | 63 | // i18n? |
jjg@46 | 64 | return "unexpected entry at #" + index + " -- expected tag " + expected_tag + ", found " + found_tag; |
jjg@46 | 65 | } |
jjg@46 | 66 | |
jjg@46 | 67 | public final int expected_tag; |
jjg@46 | 68 | public final int found_tag; |
jjg@46 | 69 | } |
jjg@46 | 70 | |
jjg@46 | 71 | public class InvalidEntry extends ConstantPoolException { |
jjg@198 | 72 | private static final long serialVersionUID = 1000087545585204447L; |
jjg@46 | 73 | InvalidEntry(int index, int tag) { |
jjg@46 | 74 | super(index); |
jjg@46 | 75 | this.tag = tag; |
jjg@46 | 76 | } |
jjg@46 | 77 | |
jjg@46 | 78 | @Override |
jjg@46 | 79 | public String getMessage() { |
jjg@46 | 80 | // i18n? |
jjg@46 | 81 | return "unexpected tag at #" + index + ": " + tag; |
jjg@46 | 82 | } |
jjg@46 | 83 | |
jjg@46 | 84 | public final int tag; |
jjg@46 | 85 | } |
jjg@46 | 86 | |
jjg@46 | 87 | public class EntryNotFound extends ConstantPoolException { |
jjg@198 | 88 | private static final long serialVersionUID = 2885537606468581850L; |
jjg@46 | 89 | EntryNotFound(Object value) { |
jjg@46 | 90 | super(-1); |
jjg@46 | 91 | this.value = value; |
jjg@46 | 92 | } |
jjg@46 | 93 | |
jjg@46 | 94 | @Override |
jjg@46 | 95 | public String getMessage() { |
jjg@46 | 96 | // i18n? |
jjg@46 | 97 | return "value not found: " + value; |
jjg@46 | 98 | } |
jjg@46 | 99 | |
jjg@46 | 100 | public final Object value; |
jjg@46 | 101 | } |
jjg@46 | 102 | |
jjg@46 | 103 | public static final int CONSTANT_Utf8 = 1; |
jjg@46 | 104 | public static final int CONSTANT_Integer = 3; |
jjg@46 | 105 | public static final int CONSTANT_Float = 4; |
jjg@46 | 106 | public static final int CONSTANT_Long = 5; |
jjg@46 | 107 | public static final int CONSTANT_Double = 6; |
jjg@46 | 108 | public static final int CONSTANT_Class = 7; |
jjg@46 | 109 | public static final int CONSTANT_String = 8; |
jjg@46 | 110 | public static final int CONSTANT_Fieldref = 9; |
jjg@46 | 111 | public static final int CONSTANT_Methodref = 10; |
jjg@46 | 112 | public static final int CONSTANT_InterfaceMethodref = 11; |
jjg@46 | 113 | public static final int CONSTANT_NameAndType = 12; |
jjg@46 | 114 | |
jjg@46 | 115 | ConstantPool(ClassReader cr) throws IOException, InvalidEntry { |
jjg@46 | 116 | int count = cr.readUnsignedShort(); |
jjg@46 | 117 | pool = new CPInfo[count]; |
jjg@46 | 118 | for (int i = 1; i < count; i++) { |
jjg@46 | 119 | int tag = cr.readUnsignedByte(); |
jjg@46 | 120 | switch (tag) { |
jjg@46 | 121 | case CONSTANT_Class: |
jjg@46 | 122 | pool[i] = new CONSTANT_Class_info(this, cr); |
jjg@46 | 123 | break; |
jjg@46 | 124 | |
jjg@46 | 125 | case CONSTANT_Double: |
jjg@46 | 126 | pool[i] = new CONSTANT_Double_info(cr); |
jjg@46 | 127 | i++; |
jjg@46 | 128 | break; |
jjg@46 | 129 | |
jjg@46 | 130 | case CONSTANT_Fieldref: |
jjg@46 | 131 | pool[i] = new CONSTANT_Fieldref_info(this, cr); |
jjg@46 | 132 | break; |
jjg@46 | 133 | |
jjg@46 | 134 | case CONSTANT_Float: |
jjg@46 | 135 | pool[i] = new CONSTANT_Float_info(cr); |
jjg@46 | 136 | break; |
jjg@46 | 137 | |
jjg@46 | 138 | case CONSTANT_Integer: |
jjg@46 | 139 | pool[i] = new CONSTANT_Integer_info(cr); |
jjg@46 | 140 | break; |
jjg@46 | 141 | |
jjg@46 | 142 | case CONSTANT_InterfaceMethodref: |
jjg@46 | 143 | pool[i] = new CONSTANT_InterfaceMethodref_info(this, cr); |
jjg@46 | 144 | break; |
jjg@46 | 145 | |
jjg@46 | 146 | case CONSTANT_Long: |
jjg@46 | 147 | pool[i] = new CONSTANT_Long_info(cr); |
jjg@46 | 148 | i++; |
jjg@46 | 149 | break; |
jjg@46 | 150 | |
jjg@46 | 151 | case CONSTANT_Methodref: |
jjg@46 | 152 | pool[i] = new CONSTANT_Methodref_info(this, cr); |
jjg@46 | 153 | break; |
jjg@46 | 154 | |
jjg@46 | 155 | case CONSTANT_NameAndType: |
jjg@46 | 156 | pool[i] = new CONSTANT_NameAndType_info(this, cr); |
jjg@46 | 157 | break; |
jjg@46 | 158 | |
jjg@46 | 159 | case CONSTANT_String: |
jjg@52 | 160 | pool[i] = new CONSTANT_String_info(this, cr); |
jjg@46 | 161 | break; |
jjg@46 | 162 | |
jjg@46 | 163 | case CONSTANT_Utf8: |
jjg@46 | 164 | pool[i] = new CONSTANT_Utf8_info(cr); |
jjg@46 | 165 | break; |
jjg@46 | 166 | |
jjg@46 | 167 | default: |
jjg@46 | 168 | throw new InvalidEntry(i, tag); |
jjg@46 | 169 | } |
jjg@46 | 170 | } |
jjg@46 | 171 | } |
jjg@46 | 172 | |
jjg@46 | 173 | public ConstantPool(CPInfo[] pool) { |
jjg@46 | 174 | this.pool = pool; |
jjg@46 | 175 | } |
jjg@46 | 176 | |
jjg@46 | 177 | public int size() { |
jjg@46 | 178 | return pool.length; |
jjg@46 | 179 | } |
jjg@46 | 180 | |
jjg@46 | 181 | public CPInfo get(int index) throws InvalidIndex { |
jjg@46 | 182 | if (index <= 0 || index >= pool.length) |
jjg@46 | 183 | throw new InvalidIndex(index); |
jjg@46 | 184 | CPInfo info = pool[index]; |
jjg@46 | 185 | if (info == null) { |
jjg@46 | 186 | // this occurs for indices referencing the "second half" of an |
jjg@46 | 187 | // 8 byte constant, such as CONSTANT_Double or CONSTANT_Long |
jjg@46 | 188 | throw new InvalidIndex(index); |
jjg@46 | 189 | } |
jjg@46 | 190 | return pool[index]; |
jjg@46 | 191 | } |
jjg@46 | 192 | |
jjg@46 | 193 | private CPInfo get(int index, int expected_type) throws InvalidIndex, UnexpectedEntry { |
jjg@46 | 194 | CPInfo info = get(index); |
jjg@46 | 195 | if (info.getTag() != expected_type) |
jjg@46 | 196 | throw new UnexpectedEntry(index, expected_type, info.getTag()); |
jjg@46 | 197 | return info; |
jjg@46 | 198 | } |
jjg@46 | 199 | |
jjg@46 | 200 | public CONSTANT_Utf8_info getUTF8Info(int index) throws InvalidIndex, UnexpectedEntry { |
jjg@46 | 201 | return ((CONSTANT_Utf8_info) get(index, CONSTANT_Utf8)); |
jjg@46 | 202 | } |
jjg@46 | 203 | |
jjg@46 | 204 | public CONSTANT_Class_info getClassInfo(int index) throws InvalidIndex, UnexpectedEntry { |
jjg@46 | 205 | return ((CONSTANT_Class_info) get(index, CONSTANT_Class)); |
jjg@46 | 206 | } |
jjg@46 | 207 | |
jjg@46 | 208 | public CONSTANT_NameAndType_info getNameAndTypeInfo(int index) throws InvalidIndex, UnexpectedEntry { |
jjg@46 | 209 | return ((CONSTANT_NameAndType_info) get(index, CONSTANT_NameAndType)); |
jjg@46 | 210 | } |
jjg@46 | 211 | |
jjg@46 | 212 | public String getUTF8Value(int index) throws InvalidIndex, UnexpectedEntry { |
jjg@46 | 213 | return getUTF8Info(index).value; |
jjg@46 | 214 | } |
jjg@46 | 215 | |
jjg@46 | 216 | public int getUTF8Index(String value) throws EntryNotFound { |
jjg@46 | 217 | for (int i = 1; i < pool.length; i++) { |
jjg@46 | 218 | CPInfo info = pool[i]; |
jjg@46 | 219 | if (info instanceof CONSTANT_Utf8_info && |
jjg@46 | 220 | ((CONSTANT_Utf8_info) info).value.equals(value)) |
jjg@46 | 221 | return i; |
jjg@46 | 222 | } |
jjg@46 | 223 | throw new EntryNotFound(value); |
jjg@46 | 224 | } |
jjg@46 | 225 | |
jjg@46 | 226 | private CPInfo[] pool; |
jjg@46 | 227 | |
jjg@46 | 228 | public interface Visitor<R,P> { |
jjg@46 | 229 | R visitClass(CONSTANT_Class_info info, P p); |
jjg@46 | 230 | R visitDouble(CONSTANT_Double_info info, P p); |
jjg@46 | 231 | R visitFieldref(CONSTANT_Fieldref_info info, P p); |
jjg@46 | 232 | R visitFloat(CONSTANT_Float_info info, P p); |
jjg@46 | 233 | R visitInteger(CONSTANT_Integer_info info, P p); |
jjg@46 | 234 | R visitInterfaceMethodref(CONSTANT_InterfaceMethodref_info info, P p); |
jjg@46 | 235 | R visitLong(CONSTANT_Long_info info, P p); |
jjg@46 | 236 | R visitNameAndType(CONSTANT_NameAndType_info info, P p); |
jjg@46 | 237 | R visitMethodref(CONSTANT_Methodref_info info, P p); |
jjg@46 | 238 | R visitString(CONSTANT_String_info info, P p); |
jjg@46 | 239 | R visitUtf8(CONSTANT_Utf8_info info, P p); |
jjg@46 | 240 | } |
jjg@46 | 241 | |
jjg@46 | 242 | public static abstract class CPInfo { |
jjg@46 | 243 | CPInfo() { |
jjg@46 | 244 | this.cp = null; |
jjg@46 | 245 | } |
jjg@46 | 246 | |
jjg@46 | 247 | CPInfo(ConstantPool cp) { |
jjg@46 | 248 | this.cp = cp; |
jjg@46 | 249 | } |
jjg@46 | 250 | |
jjg@46 | 251 | public abstract int getTag(); |
jjg@46 | 252 | |
jjg@46 | 253 | public abstract <R,D> R accept(Visitor<R,D> visitor, D data); |
jjg@46 | 254 | |
jjg@46 | 255 | protected final ConstantPool cp; |
jjg@46 | 256 | } |
jjg@46 | 257 | |
jjg@46 | 258 | public static abstract class CPRefInfo extends CPInfo { |
jjg@46 | 259 | protected CPRefInfo(ConstantPool cp, ClassReader cr, int tag) throws IOException { |
jjg@46 | 260 | super(cp); |
jjg@46 | 261 | this.tag = tag; |
jjg@46 | 262 | class_index = cr.readUnsignedShort(); |
jjg@46 | 263 | name_and_type_index = cr.readUnsignedShort(); |
jjg@46 | 264 | } |
jjg@46 | 265 | |
jjg@46 | 266 | protected CPRefInfo(ConstantPool cp, int tag, int class_index, int name_and_type_index) { |
jjg@46 | 267 | super(cp); |
jjg@46 | 268 | this.tag = tag; |
jjg@46 | 269 | this.class_index = class_index; |
jjg@46 | 270 | this.name_and_type_index = name_and_type_index; |
jjg@46 | 271 | } |
jjg@46 | 272 | |
jjg@46 | 273 | public int getTag() { |
jjg@46 | 274 | return tag; |
jjg@46 | 275 | } |
jjg@46 | 276 | |
jjg@46 | 277 | public CONSTANT_Class_info getClassInfo() throws ConstantPoolException { |
jjg@46 | 278 | return cp.getClassInfo(class_index); |
jjg@46 | 279 | } |
jjg@46 | 280 | |
jjg@46 | 281 | public String getClassName() throws ConstantPoolException { |
jjg@46 | 282 | return cp.getClassInfo(class_index).getName(); |
jjg@46 | 283 | } |
jjg@46 | 284 | |
jjg@46 | 285 | public CONSTANT_NameAndType_info getNameAndTypeInfo() throws ConstantPoolException { |
jjg@46 | 286 | return cp.getNameAndTypeInfo(name_and_type_index); |
jjg@46 | 287 | } |
jjg@46 | 288 | |
jjg@46 | 289 | public final int tag; |
jjg@46 | 290 | public final int class_index; |
jjg@46 | 291 | public final int name_and_type_index; |
jjg@46 | 292 | } |
jjg@46 | 293 | |
jjg@46 | 294 | public static class CONSTANT_Class_info extends CPInfo { |
jjg@46 | 295 | CONSTANT_Class_info(ConstantPool cp, ClassReader cr) throws IOException { |
jjg@46 | 296 | super(cp); |
jjg@46 | 297 | name_index = cr.readUnsignedShort(); |
jjg@46 | 298 | } |
jjg@46 | 299 | |
jjg@46 | 300 | public CONSTANT_Class_info(ConstantPool cp, int name_index) { |
jjg@46 | 301 | super(cp); |
jjg@46 | 302 | this.name_index = name_index; |
jjg@46 | 303 | } |
jjg@46 | 304 | |
jjg@46 | 305 | public int getTag() { |
jjg@46 | 306 | return CONSTANT_Class; |
jjg@46 | 307 | } |
jjg@46 | 308 | |
jjg@46 | 309 | public String getName() throws ConstantPoolException { |
jjg@46 | 310 | return cp.getUTF8Value(name_index); |
jjg@46 | 311 | } |
jjg@46 | 312 | |
jjg@281 | 313 | public String getBaseName() throws ConstantPoolException { |
jjg@281 | 314 | String name = getName(); |
jjg@281 | 315 | int index = name.indexOf("[L") + 1; |
jjg@281 | 316 | return name.substring(index); |
jjg@281 | 317 | } |
jjg@281 | 318 | |
jjg@281 | 319 | public int getDimensionCount() throws ConstantPoolException { |
jjg@281 | 320 | String name = getName(); |
jjg@281 | 321 | int count = 0; |
jjg@281 | 322 | while (name.charAt(count) == '[') |
jjg@281 | 323 | count++; |
jjg@281 | 324 | return count; |
jjg@281 | 325 | } |
jjg@281 | 326 | |
jjg@46 | 327 | @Override |
jjg@46 | 328 | public String toString() { |
jjg@46 | 329 | return "CONSTANT_Class_info[name_index: " + name_index + "]"; |
jjg@46 | 330 | } |
jjg@46 | 331 | |
jjg@46 | 332 | public <R, D> R accept(Visitor<R, D> visitor, D data) { |
jjg@46 | 333 | return visitor.visitClass(this, data); |
jjg@46 | 334 | } |
jjg@46 | 335 | |
jjg@46 | 336 | public final int name_index; |
jjg@46 | 337 | } |
jjg@46 | 338 | |
jjg@46 | 339 | public static class CONSTANT_Double_info extends CPInfo { |
jjg@46 | 340 | CONSTANT_Double_info(ClassReader cr) throws IOException { |
jjg@46 | 341 | value = cr.readDouble(); |
jjg@46 | 342 | } |
jjg@46 | 343 | |
jjg@46 | 344 | public CONSTANT_Double_info(double value) { |
jjg@46 | 345 | this.value = value; |
jjg@46 | 346 | } |
jjg@46 | 347 | |
jjg@46 | 348 | public int getTag() { |
jjg@46 | 349 | return CONSTANT_Double; |
jjg@46 | 350 | } |
jjg@46 | 351 | |
jjg@46 | 352 | @Override |
jjg@46 | 353 | public String toString() { |
jjg@46 | 354 | return "CONSTANT_Double_info[value: " + value + "]"; |
jjg@46 | 355 | } |
jjg@46 | 356 | |
jjg@46 | 357 | public <R, D> R accept(Visitor<R, D> visitor, D data) { |
jjg@46 | 358 | return visitor.visitDouble(this, data); |
jjg@46 | 359 | } |
jjg@46 | 360 | |
jjg@46 | 361 | public final double value; |
jjg@46 | 362 | } |
jjg@46 | 363 | |
jjg@46 | 364 | public static class CONSTANT_Fieldref_info extends CPRefInfo { |
jjg@46 | 365 | CONSTANT_Fieldref_info(ConstantPool cp, ClassReader cr) throws IOException { |
jjg@46 | 366 | super(cp, cr, CONSTANT_Fieldref); |
jjg@46 | 367 | } |
jjg@46 | 368 | |
jjg@46 | 369 | public CONSTANT_Fieldref_info(ConstantPool cp, int class_index, int name_and_type_index) { |
jjg@46 | 370 | super(cp, CONSTANT_Fieldref, class_index, name_and_type_index); |
jjg@46 | 371 | } |
jjg@46 | 372 | |
jjg@46 | 373 | @Override |
jjg@46 | 374 | public String toString() { |
jjg@46 | 375 | return "CONSTANT_Fieldref_info[class_index: " + class_index + ", name_and_type_index: " + name_and_type_index + "]"; |
jjg@46 | 376 | } |
jjg@46 | 377 | |
jjg@46 | 378 | public <R, D> R accept(Visitor<R, D> visitor, D data) { |
jjg@46 | 379 | return visitor.visitFieldref(this, data); |
jjg@46 | 380 | } |
jjg@46 | 381 | } |
jjg@46 | 382 | |
jjg@46 | 383 | public static class CONSTANT_Float_info extends CPInfo { |
jjg@46 | 384 | CONSTANT_Float_info(ClassReader cr) throws IOException { |
jjg@46 | 385 | value = cr.readFloat(); |
jjg@46 | 386 | } |
jjg@46 | 387 | |
jjg@46 | 388 | public CONSTANT_Float_info(float value) { |
jjg@46 | 389 | this.value = value; |
jjg@46 | 390 | } |
jjg@46 | 391 | |
jjg@46 | 392 | public int getTag() { |
jjg@46 | 393 | return CONSTANT_Float; |
jjg@46 | 394 | } |
jjg@46 | 395 | |
jjg@46 | 396 | @Override |
jjg@46 | 397 | public String toString() { |
jjg@46 | 398 | return "CONSTANT_Float_info[value: " + value + "]"; |
jjg@46 | 399 | } |
jjg@46 | 400 | |
jjg@46 | 401 | public <R, D> R accept(Visitor<R, D> visitor, D data) { |
jjg@46 | 402 | return visitor.visitFloat(this, data); |
jjg@46 | 403 | } |
jjg@46 | 404 | |
jjg@46 | 405 | public final float value; |
jjg@46 | 406 | } |
jjg@46 | 407 | |
jjg@46 | 408 | public static class CONSTANT_Integer_info extends CPInfo { |
jjg@46 | 409 | CONSTANT_Integer_info(ClassReader cr) throws IOException { |
jjg@46 | 410 | value = cr.readInt(); |
jjg@46 | 411 | } |
jjg@46 | 412 | |
jjg@46 | 413 | public CONSTANT_Integer_info(int value) { |
jjg@46 | 414 | this.value = value; |
jjg@46 | 415 | } |
jjg@46 | 416 | |
jjg@46 | 417 | public int getTag() { |
jjg@46 | 418 | return CONSTANT_Integer; |
jjg@46 | 419 | } |
jjg@46 | 420 | |
jjg@46 | 421 | @Override |
jjg@46 | 422 | public String toString() { |
jjg@46 | 423 | return "CONSTANT_Integer_info[value: " + value + "]"; |
jjg@46 | 424 | } |
jjg@46 | 425 | |
jjg@46 | 426 | public <R, D> R accept(Visitor<R, D> visitor, D data) { |
jjg@46 | 427 | return visitor.visitInteger(this, data); |
jjg@46 | 428 | } |
jjg@46 | 429 | |
jjg@46 | 430 | public final int value; |
jjg@46 | 431 | } |
jjg@46 | 432 | |
jjg@46 | 433 | public static class CONSTANT_InterfaceMethodref_info extends CPRefInfo { |
jjg@46 | 434 | CONSTANT_InterfaceMethodref_info(ConstantPool cp, ClassReader cr) throws IOException { |
jjg@46 | 435 | super(cp, cr, CONSTANT_InterfaceMethodref); |
jjg@46 | 436 | } |
jjg@46 | 437 | |
jjg@46 | 438 | public CONSTANT_InterfaceMethodref_info(ConstantPool cp, int class_index, int name_and_type_index) { |
jjg@46 | 439 | super(cp, CONSTANT_InterfaceMethodref, class_index, name_and_type_index); |
jjg@46 | 440 | } |
jjg@46 | 441 | |
jjg@46 | 442 | @Override |
jjg@46 | 443 | public String toString() { |
jjg@46 | 444 | return "CONSTANT_InterfaceMethodref_info[class_index: " + class_index + ", name_and_type_index: " + name_and_type_index + "]"; |
jjg@46 | 445 | } |
jjg@46 | 446 | |
jjg@46 | 447 | public <R, D> R accept(Visitor<R, D> visitor, D data) { |
jjg@46 | 448 | return visitor.visitInterfaceMethodref(this, data); |
jjg@46 | 449 | } |
jjg@46 | 450 | } |
jjg@46 | 451 | |
jjg@46 | 452 | public static class CONSTANT_Long_info extends CPInfo { |
jjg@46 | 453 | CONSTANT_Long_info(ClassReader cr) throws IOException { |
jjg@46 | 454 | value = cr.readLong(); |
jjg@46 | 455 | } |
jjg@46 | 456 | |
jjg@46 | 457 | public CONSTANT_Long_info(long value) { |
jjg@46 | 458 | this.value = value; |
jjg@46 | 459 | } |
jjg@46 | 460 | |
jjg@46 | 461 | public int getTag() { |
jjg@46 | 462 | return CONSTANT_Long; |
jjg@46 | 463 | } |
jjg@46 | 464 | |
jjg@46 | 465 | @Override |
jjg@46 | 466 | public String toString() { |
jjg@46 | 467 | return "CONSTANT_Long_info[value: " + value + "]"; |
jjg@46 | 468 | } |
jjg@46 | 469 | |
jjg@46 | 470 | public <R, D> R accept(Visitor<R, D> visitor, D data) { |
jjg@46 | 471 | return visitor.visitLong(this, data); |
jjg@46 | 472 | } |
jjg@46 | 473 | |
jjg@46 | 474 | public final long value; |
jjg@46 | 475 | } |
jjg@46 | 476 | |
jjg@46 | 477 | public static class CONSTANT_Methodref_info extends CPRefInfo { |
jjg@46 | 478 | CONSTANT_Methodref_info(ConstantPool cp, ClassReader cr) throws IOException { |
jjg@46 | 479 | super(cp, cr, CONSTANT_Methodref); |
jjg@46 | 480 | } |
jjg@46 | 481 | |
jjg@46 | 482 | public CONSTANT_Methodref_info(ConstantPool cp, int class_index, int name_and_type_index) { |
jjg@46 | 483 | super(cp, CONSTANT_Methodref, class_index, name_and_type_index); |
jjg@46 | 484 | } |
jjg@46 | 485 | |
jjg@46 | 486 | @Override |
jjg@46 | 487 | public String toString() { |
jjg@46 | 488 | return "CONSTANT_Methodref_info[class_index: " + class_index + ", name_and_type_index: " + name_and_type_index + "]"; |
jjg@46 | 489 | } |
jjg@46 | 490 | |
jjg@46 | 491 | public <R, D> R accept(Visitor<R, D> visitor, D data) { |
jjg@46 | 492 | return visitor.visitMethodref(this, data); |
jjg@46 | 493 | } |
jjg@46 | 494 | } |
jjg@46 | 495 | |
jjg@46 | 496 | public static class CONSTANT_NameAndType_info extends CPInfo { |
jjg@46 | 497 | CONSTANT_NameAndType_info(ConstantPool cp, ClassReader cr) throws IOException { |
jjg@46 | 498 | super(cp); |
jjg@46 | 499 | name_index = cr.readUnsignedShort(); |
jjg@46 | 500 | type_index = cr.readUnsignedShort(); |
jjg@46 | 501 | } |
jjg@46 | 502 | |
jjg@46 | 503 | public CONSTANT_NameAndType_info(ConstantPool cp, int name_index, int type_index) { |
jjg@46 | 504 | super(cp); |
jjg@46 | 505 | this.name_index = name_index; |
jjg@46 | 506 | this.type_index = type_index; |
jjg@46 | 507 | } |
jjg@46 | 508 | |
jjg@46 | 509 | public int getTag() { |
jjg@46 | 510 | return CONSTANT_NameAndType; |
jjg@46 | 511 | } |
jjg@46 | 512 | |
jjg@46 | 513 | public String getName() throws ConstantPoolException { |
jjg@46 | 514 | return cp.getUTF8Value(name_index); |
jjg@46 | 515 | } |
jjg@46 | 516 | |
jjg@46 | 517 | public String getType() throws ConstantPoolException { |
jjg@46 | 518 | return cp.getUTF8Value(type_index); |
jjg@46 | 519 | } |
jjg@46 | 520 | |
jjg@46 | 521 | public <R, D> R accept(Visitor<R, D> visitor, D data) { |
jjg@46 | 522 | return visitor.visitNameAndType(this, data); |
jjg@46 | 523 | } |
jjg@46 | 524 | |
jjg@46 | 525 | public final int name_index; |
jjg@46 | 526 | public final int type_index; |
jjg@46 | 527 | } |
jjg@46 | 528 | |
jjg@46 | 529 | public static class CONSTANT_String_info extends CPInfo { |
jjg@52 | 530 | CONSTANT_String_info(ConstantPool cp, ClassReader cr) throws IOException { |
jjg@52 | 531 | super(cp); |
jjg@46 | 532 | string_index = cr.readUnsignedShort(); |
jjg@46 | 533 | } |
jjg@46 | 534 | |
jjg@46 | 535 | public CONSTANT_String_info(ConstantPool cp, int string_index) { |
jjg@46 | 536 | super(cp); |
jjg@46 | 537 | this.string_index = string_index; |
jjg@46 | 538 | } |
jjg@46 | 539 | |
jjg@46 | 540 | public int getTag() { |
jjg@46 | 541 | return CONSTANT_String; |
jjg@46 | 542 | } |
jjg@46 | 543 | |
jjg@46 | 544 | public String getString() throws ConstantPoolException { |
jjg@46 | 545 | return cp.getUTF8Value(string_index); |
jjg@46 | 546 | } |
jjg@46 | 547 | |
jjg@46 | 548 | public <R, D> R accept(Visitor<R, D> visitor, D data) { |
jjg@46 | 549 | return visitor.visitString(this, data); |
jjg@46 | 550 | } |
jjg@46 | 551 | |
jjg@46 | 552 | public final int string_index; |
jjg@46 | 553 | } |
jjg@46 | 554 | |
jjg@46 | 555 | public static class CONSTANT_Utf8_info extends CPInfo { |
jjg@46 | 556 | CONSTANT_Utf8_info(ClassReader cr) throws IOException { |
jjg@46 | 557 | value = cr.readUTF(); |
jjg@46 | 558 | } |
jjg@46 | 559 | |
jjg@46 | 560 | public CONSTANT_Utf8_info(String value) { |
jjg@46 | 561 | this.value = value; |
jjg@46 | 562 | } |
jjg@46 | 563 | |
jjg@46 | 564 | public int getTag() { |
jjg@46 | 565 | return CONSTANT_Utf8; |
jjg@46 | 566 | } |
jjg@46 | 567 | |
jjg@46 | 568 | @Override |
jjg@46 | 569 | public String toString() { |
jjg@46 | 570 | return "CONSTANT_Utf8_info[value: " + value + "]"; |
jjg@46 | 571 | } |
jjg@46 | 572 | |
jjg@46 | 573 | public <R, D> R accept(Visitor<R, D> visitor, D data) { |
jjg@46 | 574 | return visitor.visitUtf8(this, data); |
jjg@46 | 575 | } |
jjg@46 | 576 | |
jjg@46 | 577 | public final String value; |
jjg@46 | 578 | } |
jjg@46 | 579 | |
jjg@46 | 580 | |
jjg@46 | 581 | } |