--- old/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/CPInstruction.java 2017-08-08 16:04:50.176245886 -0700 +++ new/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/CPInstruction.java 2017-08-08 16:04:50.092241680 -0700 @@ -18,116 +18,127 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.sun.org.apache.bcel.internal.generic; +import java.io.DataOutputStream; +import java.io.IOException; -import java.io.*; +import com.sun.org.apache.bcel.internal.classfile.Constant; +import com.sun.org.apache.bcel.internal.classfile.ConstantClass; +import com.sun.org.apache.bcel.internal.classfile.ConstantPool; import com.sun.org.apache.bcel.internal.util.ByteSequence; -import com.sun.org.apache.bcel.internal.Constants; -import com.sun.org.apache.bcel.internal.classfile.*; /** - * Abstract super class for instructions that use an index into the - * constant pool such as LDC, INVOKEVIRTUAL, etc. + * Abstract super class for instructions that use an index into the constant + * pool such as LDC, INVOKEVIRTUAL, etc. * * @see ConstantPoolGen * @see LDC * @see INVOKEVIRTUAL * - * @author M. Dahm + * @version $Id: CPInstruction.java 1749603 2016-06-21 20:50:19Z ggregory $ */ -public abstract class CPInstruction extends Instruction - implements TypedInstruction, IndexedInstruction -{ - protected int index; // index to constant pool - - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - CPInstruction() {} - - /** - * @param index to constant pool - */ - protected CPInstruction(short opcode, int index) { - super(opcode, (short)3); - setIndex(index); - } - - /** - * Dump instruction as byte code to stream out. - * @param out Output stream - */ - public void dump(DataOutputStream out) throws IOException { - out.writeByte(opcode); - out.writeShort(index); - } - - /** - * Long output format: - * - * <name of opcode> "["<opcode number>"]" - * "("<length of instruction>")" "<"< constant pool index>">" - * - * @param verbose long/short format switch - * @return mnemonic for instruction - */ - public String toString(boolean verbose) { - return super.toString(verbose) + " " + index; - } - - /** - * @return mnemonic for instruction with symbolic references resolved - */ - public String toString(ConstantPool cp) { - Constant c = cp.getConstant(index); - String str = cp.constantToString(c); - - if(c instanceof ConstantClass) - str = str.replace('.', '/'); - - return com.sun.org.apache.bcel.internal.Constants.OPCODE_NAMES[opcode] + " " + str; - } - - /** - * Read needed data (i.e., index) from file. - * @param bytes input stream - * @param wide wide prefix? - */ - protected void initFromFile(ByteSequence bytes, boolean wide) - throws IOException - { - setIndex(bytes.readUnsignedShort()); - length = 3; - } - - /** - * @return index in constant pool referred by this instruction. - */ - public final int getIndex() { return index; } - - /** - * Set the index to constant pool. - * @param index in constant pool. - */ - public void setIndex(int index) { - if(index < 0) - throw new ClassGenException("Negative index value: " + index); - - this.index = index; - } - - /** @return type related with this instruction. - */ - public Type getType(ConstantPoolGen cpg) { - ConstantPool cp = cpg.getConstantPool(); - String name = cp.getConstantString(index, com.sun.org.apache.bcel.internal.Constants.CONSTANT_Class); +public abstract class CPInstruction extends Instruction implements TypedInstruction, + IndexedInstruction { - if(!name.startsWith("[")) - name = "L" + name + ";"; + private int index; // index to constant pool - return Type.getType(name); - } + /** + * Empty constructor needed for the Class.newInstance() statement in + * Instruction.readInstruction(). Not to be used otherwise. + */ + CPInstruction() { + } + + /** + * @param index to constant pool + */ + protected CPInstruction(final short opcode, final int index) { + super(opcode, (short) 3); + setIndex(index); + } + + /** + * Dump instruction as byte code to stream out. + * + * @param out Output stream + */ + @Override + public void dump(final DataOutputStream out) throws IOException { + out.writeByte(super.getOpcode()); + out.writeShort(index); + } + + /** + * Long output format: + * + * <name of opcode> "["<opcode number>"]" "("<length of + * instruction>")" "<"< constant pool index>">" + * + * @param verbose long/short format switch + * @return mnemonic for instruction + */ + @Override + public String toString(final boolean verbose) { + return super.toString(verbose) + " " + index; + } + + /** + * @return mnemonic for instruction with symbolic references resolved + */ + @Override + public String toString(final ConstantPool cp) { + final Constant c = cp.getConstant(index); + String str = cp.constantToString(c); + if (c instanceof ConstantClass) { + str = str.replace('.', '/'); + } + return com.sun.org.apache.bcel.internal.Const.getOpcodeName(super.getOpcode()) + " " + str; + } + + /** + * Read needed data (i.e., index) from file. + * + * @param bytes input stream + * @param wide wide prefix? + */ + @Override + protected void initFromFile(final ByteSequence bytes, final boolean wide) throws IOException { + setIndex(bytes.readUnsignedShort()); + super.setLength(3); + } + + /** + * @return index in constant pool referred by this instruction. + */ + @Override + public final int getIndex() { + return index; + } + + /** + * Set the index to constant pool. + * + * @param index in constant pool. + */ + @Override + public void setIndex(final int index) { // TODO could be package-protected? + if (index < 0) { + throw new ClassGenException("Negative index value: " + index); + } + this.index = index; + } + + /** + * @return type related with this instruction. + */ + @Override + public Type getType(final ConstantPoolGen cpg) { + final ConstantPool cp = cpg.getConstantPool(); + String name = cp.getConstantString(index, com.sun.org.apache.bcel.internal.Const.CONSTANT_Class); + if (!name.startsWith("[")) { + name = "L" + name + ";"; + } + return Type.getType(name); + } }