001package serp.bytecode.lowlevel; 002 003import java.io.DataInput; 004import java.io.DataOutput; 005import java.io.IOException; 006 007import serp.bytecode.visitor.BCVisitor; 008 009/** 010 * InvokeDynamic 011 * u1 tag 012 * u2 bootstrap_method_attr_index // References entry in Bootstrap Methods table 013 * u2 name_and_type_index // References NameAndTypeEntry representing method name and descriptor 014 * 015 */ 016public class InvokeDynamicEntry extends Entry { 017 private int _bootstrap_method_attr_index; 018 private int _name_and_type_index; 019 020 public InvokeDynamicEntry() { 021 022 } 023 024 public InvokeDynamicEntry(int bootstrap_method_attr_index, int nameAndTypeIndex) { 025 _bootstrap_method_attr_index = bootstrap_method_attr_index; 026 _name_and_type_index = nameAndTypeIndex; 027 } 028 029 public void acceptVisit(BCVisitor visitor) { 030 visitor.enterInvokeDynamicEntry(this); 031 visitor.exitInvokeDynamicEntry(this); 032 } 033 034 public int getType() { 035 return Entry.INVOKEDYNAMIC; 036 } 037 038 void readData(DataInput in) throws IOException { 039 _bootstrap_method_attr_index = in.readUnsignedShort(); 040 _name_and_type_index = in.readUnsignedShort(); 041 } 042 043 void writeData(DataOutput out) throws IOException { 044 out.writeShort(_bootstrap_method_attr_index); 045 out.writeShort(_name_and_type_index); 046 } 047 048 public int getBootstrapMethodAttrIndex() { 049 return _bootstrap_method_attr_index; 050 } 051 052 /** 053 * Return the constant pool index of the {@link NameAndTypeEntry} 054 * describing this entity. 055 */ 056 public int getNameAndTypeIndex() { 057 return _name_and_type_index; 058 } 059 /** 060 * Return the referenced {@link NameAndTypeEntry}. This method can only 061 * be run for entries that have been added to a constant pool. 062 */ 063 public NameAndTypeEntry getNameAndTypeEntry() { 064 return (NameAndTypeEntry) getPool().getEntry(_name_and_type_index); 065 } 066}