1 28 29 package com.caucho.bytecode; 30 31 import com.caucho.log.Log; 32 33 import java.io.IOException ; 34 import java.util.logging.Logger ; 35 36 39 public class FieldRefConstant extends ConstantPoolEntry { 40 static private final Logger log = Log.open(FieldRefConstant.class); 41 42 private int _classIndex; 43 private int _nameAndTypeIndex; 44 45 48 FieldRefConstant(ConstantPool pool, int index, 49 int classIndex, int nameAndTypeIndex) 50 { 51 super(pool, index); 52 53 _classIndex = classIndex; 54 _nameAndTypeIndex = nameAndTypeIndex; 55 } 56 57 60 public int getClassIndex() 61 { 62 return _classIndex; 63 } 64 65 68 public void setClassIndex(int index) 69 { 70 _classIndex = index; 71 } 72 73 76 public String getClassName() 77 { 78 return getConstantPool().getClass(_classIndex).getName(); 79 } 80 81 84 public String getName() 85 { 86 return getConstantPool().getNameAndType(_nameAndTypeIndex).getName(); 87 } 88 89 92 public String getType() 93 { 94 return getConstantPool().getNameAndType(_nameAndTypeIndex).getType(); 95 } 96 97 100 void write(ByteCodeWriter out) 101 throws IOException 102 { 103 out.write(ConstantPool.CP_FIELD_REF); 104 out.writeShort(_classIndex); 105 out.writeShort(_nameAndTypeIndex); 106 } 107 108 111 public void setNameAndType(String name, String type) 112 { 113 _nameAndTypeIndex = getConstantPool().addNameAndType(name, type).getIndex(); 114 } 115 116 119 public int export(ConstantPool target) 120 { 121 return target.addFieldRef(getClassName(), getName(), getType()).getIndex(); 122 } 123 124 public String toString() 125 { 126 return "FieldRefConstant[" + getClassName() + "." + getName() + "(" + getType() + ")]"; 127 } 128 } 129 | Popular Tags |