jaroslav@1646: /* jaroslav@1646: * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved. jaroslav@1646: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jaroslav@1646: * jaroslav@1646: * This code is free software; you can redistribute it and/or modify it jaroslav@1646: * under the terms of the GNU General Public License version 2 only, as jaroslav@1646: * published by the Free Software Foundation. Oracle designates this jaroslav@1646: * particular file as subject to the "Classpath" exception as provided jaroslav@1646: * by Oracle in the LICENSE file that accompanied this code. jaroslav@1646: * jaroslav@1646: * This code is distributed in the hope that it will be useful, but WITHOUT jaroslav@1646: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jaroslav@1646: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jaroslav@1646: * version 2 for more details (a copy is included in the LICENSE file that jaroslav@1646: * accompanied this code). jaroslav@1646: * jaroslav@1646: * You should have received a copy of the GNU General Public License version jaroslav@1646: * 2 along with this work; if not, write to the Free Software Foundation, jaroslav@1646: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jaroslav@1646: * jaroslav@1646: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA jaroslav@1646: * or visit www.oracle.com if you need additional information or have any jaroslav@1646: * questions. jaroslav@1646: */ jaroslav@1646: jaroslav@1646: package sun.invoke.anon; jaroslav@1646: jaroslav@1646: /** jaroslav@1646: * A visitor called by {@link ConstantPoolParser#parse(ConstantPoolVisitor)} jaroslav@1646: * when a constant pool entry is parsed. jaroslav@1646: *

jaroslav@1646: * A visit* method is called when a constant pool entry is parsed. jaroslav@1646: * The first argument is always the constant pool index. jaroslav@1646: * The second argument is always the constant pool tag, jaroslav@1646: * even for methods like {@link #visitUTF8(int, byte, String)} which only apply to one tag. jaroslav@1646: * String arguments refer to Utf8 or NameAndType entries declared elsewhere, jaroslav@1646: * and are always accompanied by the indexes of those entries. jaroslav@1646: *

jaroslav@1646: * The order of the calls to the visit* methods is not necessarily related jaroslav@1646: * to the order of the entries in the constant pool. jaroslav@1646: * If one entry has a reference to another entry, the latter (lower-level) jaroslav@1646: * entry will be visited first. jaroslav@1646: *

jaroslav@1646: * The following table shows the relation between constant pool entry jaroslav@1646: * types and the corresponding visit* methods: jaroslav@1646: * jaroslav@1646: * jaroslav@1646: * jaroslav@1646: * jaroslav@1646: * jaroslav@1646: * jaroslav@1646: * jaroslav@1646: * jaroslav@1646: * jaroslav@1646: * jaroslav@1646: * jaroslav@1646: * jaroslav@1646: * jaroslav@1646: * jaroslav@1646: * jaroslav@1646: * jaroslav@1646: * jaroslav@1646: * jaroslav@1646: * jaroslav@1646: *
Tag(s)Method
{@link #CONSTANT_Utf8}{@link #visitUTF8(int, byte, String)}
{@link #CONSTANT_Integer}, {@link #CONSTANT_Float}, jaroslav@1646: * {@link #CONSTANT_Long}, {@link #CONSTANT_Double}{@link #visitConstantValue(int, byte, Object)}
{@link #CONSTANT_String}, {@link #CONSTANT_Class}{@link #visitConstantString(int, byte, String, int)}
{@link #CONSTANT_NameAndType}{@link #visitDescriptor(int, byte, String, String, int, int)}
{@link #CONSTANT_Fieldref}, jaroslav@1646: * {@link #CONSTANT_Methodref}, jaroslav@1646: * {@link #CONSTANT_InterfaceMethodref}{@link #visitMemberRef(int, byte, String, String, String, int, int)}
jaroslav@1646: * jaroslav@1646: * @see ConstantPoolPatch jaroslav@1646: * @author Remi Forax jaroslav@1646: * @author jrose jaroslav@1646: */ jaroslav@1646: public class ConstantPoolVisitor { jaroslav@1646: /** Called each time an UTF8 constant pool entry is found. jaroslav@1646: * @param index the constant pool index jaroslav@1646: * @param tag always {@link #CONSTANT_Utf8} jaroslav@1646: * @param utf8 string encoded in modified UTF-8 format passed as a {@code String} jaroslav@1646: * jaroslav@1646: * @see ConstantPoolPatch#putUTF8(int, String) jaroslav@1646: */ jaroslav@1646: public void visitUTF8(int index, byte tag, String utf8) { jaroslav@1646: // do nothing jaroslav@1646: } jaroslav@1646: jaroslav@1646: /** Called for each constant pool entry that encodes an integer, jaroslav@1646: * a float, a long, or a double. jaroslav@1646: * Constant strings and classes are not managed by this method but jaroslav@1646: * by {@link #visitConstantString(int, byte, String, int)}. jaroslav@1646: * jaroslav@1646: * @param index the constant pool index jaroslav@1646: * @param tag one of {@link #CONSTANT_Integer}, jaroslav@1646: * {@link #CONSTANT_Float}, jaroslav@1646: * {@link #CONSTANT_Long}, jaroslav@1646: * or {@link #CONSTANT_Double} jaroslav@1646: * @param value encoded value jaroslav@1646: * jaroslav@1646: * @see ConstantPoolPatch#putConstantValue(int, Object) jaroslav@1646: */ jaroslav@1646: public void visitConstantValue(int index, byte tag, Object value) { jaroslav@1646: // do nothing jaroslav@1646: } jaroslav@1646: jaroslav@1646: /** Called for each constant pool entry that encodes a string or a class. jaroslav@1646: * @param index the constant pool index jaroslav@1646: * @param tag one of {@link #CONSTANT_String}, jaroslav@1646: * {@link #CONSTANT_Class}, jaroslav@1646: * @param name string body or class name (using dot separator) jaroslav@1646: * @param nameIndex the index of the Utf8 string for the name jaroslav@1646: * jaroslav@1646: * @see ConstantPoolPatch#putConstantValue(int, byte, Object) jaroslav@1646: */ jaroslav@1646: public void visitConstantString(int index, byte tag, jaroslav@1646: String name, int nameIndex) { jaroslav@1646: // do nothing jaroslav@1646: } jaroslav@1646: jaroslav@1646: /** Called for each constant pool entry that encodes a name and type. jaroslav@1646: * @param index the constant pool index jaroslav@1646: * @param tag always {@link #CONSTANT_NameAndType} jaroslav@1646: * @param memberName a field or method name jaroslav@1646: * @param signature the member signature jaroslav@1646: * @param memberNameIndex index of the Utf8 string for the member name jaroslav@1646: * @param signatureIndex index of the Utf8 string for the signature jaroslav@1646: * jaroslav@1646: * @see ConstantPoolPatch#putDescriptor(int, String, String) jaroslav@1646: */ jaroslav@1646: public void visitDescriptor(int index, byte tag, jaroslav@1646: String memberName, String signature, jaroslav@1646: int memberNameIndex, int signatureIndex) { jaroslav@1646: // do nothing jaroslav@1646: } jaroslav@1646: jaroslav@1646: /** Called for each constant pool entry that encodes a field or method. jaroslav@1646: * @param index the constant pool index jaroslav@1646: * @param tag one of {@link #CONSTANT_Fieldref}, jaroslav@1646: * or {@link #CONSTANT_Methodref}, jaroslav@1646: * or {@link #CONSTANT_InterfaceMethodref} jaroslav@1646: * @param className the class name (using dot separator) jaroslav@1646: * @param memberName name of the field or method jaroslav@1646: * @param signature the field or method signature jaroslav@1646: * @param classNameIndex index of the Utf8 string for the class name jaroslav@1646: * @param descriptorIndex index of the NameAndType descriptor constant jaroslav@1646: * jaroslav@1646: * @see ConstantPoolPatch#putMemberRef(int, byte, String, String, String) jaroslav@1646: */ jaroslav@1646: public void visitMemberRef(int index, byte tag, jaroslav@1646: String className, String memberName, String signature, jaroslav@1646: int classNameIndex, int descriptorIndex) { jaroslav@1646: // do nothing jaroslav@1646: } jaroslav@1646: jaroslav@1646: public static final byte jaroslav@1646: CONSTANT_None = 0, jaroslav@1646: CONSTANT_Utf8 = 1, jaroslav@1646: //CONSTANT_Unicode = 2, /* unused */ jaroslav@1646: CONSTANT_Integer = 3, jaroslav@1646: CONSTANT_Float = 4, jaroslav@1646: CONSTANT_Long = 5, jaroslav@1646: CONSTANT_Double = 6, jaroslav@1646: CONSTANT_Class = 7, jaroslav@1646: CONSTANT_String = 8, jaroslav@1646: CONSTANT_Fieldref = 9, jaroslav@1646: CONSTANT_Methodref = 10, jaroslav@1646: CONSTANT_InterfaceMethodref = 11, jaroslav@1646: CONSTANT_NameAndType = 12; jaroslav@1646: jaroslav@1646: private static String[] TAG_NAMES = { jaroslav@1646: "Empty", jaroslav@1646: "Utf8", jaroslav@1646: null, //"Unicode", jaroslav@1646: "Integer", jaroslav@1646: "Float", jaroslav@1646: "Long", jaroslav@1646: "Double", jaroslav@1646: "Class", jaroslav@1646: "String", jaroslav@1646: "Fieldref", jaroslav@1646: "Methodref", jaroslav@1646: "InterfaceMethodref", jaroslav@1646: "NameAndType" jaroslav@1646: }; jaroslav@1646: jaroslav@1646: public static String tagName(byte tag) { jaroslav@1646: String name = null; jaroslav@1646: if ((tag & 0xFF) < TAG_NAMES.length) jaroslav@1646: name = TAG_NAMES[tag]; jaroslav@1646: if (name == null) jaroslav@1646: name = "Unknown#"+(tag&0xFF); jaroslav@1646: return name; jaroslav@1646: } jaroslav@1646: }