1 11 package org.eclipse.jdi.internal; 12 13 14 import java.io.DataInputStream ; 15 import java.io.DataOutputStream ; 16 import java.io.IOException ; 17 18 import org.eclipse.jdi.internal.jdwp.JdwpFieldID; 19 20 import com.sun.jdi.ClassNotLoadedException; 21 import com.sun.jdi.Field; 22 import com.sun.jdi.Type; 23 24 30 public class FieldImpl extends TypeComponentImpl implements Field { 31 32 private JdwpFieldID fFieldID; 33 private Type fType; 34 private String fTypeName; 35 36 39 public FieldImpl(VirtualMachineImpl vmImpl, ReferenceTypeImpl declaringType, JdwpFieldID ID, String name, String signature, String genericSignature, int modifierBits) { 40 super("Field", vmImpl, declaringType, name, signature, genericSignature, modifierBits); fFieldID = ID; 42 } 43 44 47 public void flushStoredJdwpResults() { 48 } 50 51 54 public JdwpFieldID getFieldID() { 55 return fFieldID; 56 } 57 58 62 public boolean equals(Object object) { 63 return object != null 64 && object.getClass().equals(this.getClass()) 65 && fFieldID.equals(((FieldImpl)object).fFieldID) 66 && referenceTypeImpl().equals(((FieldImpl)object).referenceTypeImpl()); 67 } 68 69 72 public int compareTo(Object object) { 73 if (object == null || !object.getClass().equals(this.getClass())) 74 throw new ClassCastException (JDIMessages.FieldImpl_Can__t_compare_field_to_given_object_1); 75 76 Field type2 = (Field)object; 78 if (!declaringType().equals(type2.declaringType())) 79 return declaringType().compareTo(type2.declaringType()); 80 81 int index1 = declaringType().fields().indexOf(this); 83 int index2 = type2.declaringType().fields().indexOf(type2); 84 if (index1 < index2) 85 return -1; 86 else if (index1 > index2) 87 return 1; 88 else return 0; 89 } 90 91 94 public int hashCode() { 95 return fFieldID.hashCode(); 96 } 97 98 101 public String typeName() { 102 if (fTypeName == null) { 103 fTypeName = TypeImpl.signatureToName(signature()); 104 } 105 return fTypeName; 106 } 107 108 111 public Type type() throws ClassNotLoadedException { 112 if (fType == null) { 113 fType = TypeImpl.create(virtualMachineImpl(), signature(), declaringType().classLoader()); 114 } 115 return fType; 116 } 117 118 121 public boolean isTransient() { 122 return (fModifierBits & MODIFIER_ACC_TRANSIENT) != 0; 123 } 124 125 128 public boolean isVolatile() { 129 return (fModifierBits & MODIFIER_ACC_VOLITILE) != 0; 130 } 131 132 135 public void write(MirrorImpl target, DataOutputStream out) throws IOException { 136 fFieldID.write(out); 137 if (target.fVerboseWriter != null) 138 target.fVerboseWriter.println("field", fFieldID.value()); } 140 141 144 public void writeWithReferenceType(MirrorImpl target, DataOutputStream out) throws IOException { 145 referenceTypeImpl().write(target, out); 147 write(target, out); 148 } 149 150 153 public static FieldImpl readWithReferenceTypeWithTag(MirrorImpl target, DataInputStream in) throws IOException { 154 VirtualMachineImpl vmImpl = target.virtualMachineImpl(); 155 ReferenceTypeImpl referenceType = ReferenceTypeImpl.readWithTypeTag(target, in); 157 if (referenceType == null) 158 return null; 159 160 JdwpFieldID ID = new JdwpFieldID(vmImpl); 161 ID.read(in); 162 if (target.fVerboseWriter != null) 163 target.fVerboseWriter.println("field", ID.value()); 165 if (ID.isNull()) 166 return null; 167 FieldImpl field = referenceType.findField(ID); 168 if (field == null) 169 throw new InternalError (JDIMessages.FieldImpl_Got_FieldID_of_ReferenceType_that_is_not_a_member_of_the_ReferenceType_2); 170 return field; 171 } 172 173 176 public static FieldImpl readWithNameSignatureModifiers(ReferenceTypeImpl target, ReferenceTypeImpl referenceType, boolean withGenericSignature, DataInputStream in) throws IOException { 177 VirtualMachineImpl vmImpl = target.virtualMachineImpl(); 178 JdwpFieldID ID = new JdwpFieldID(vmImpl); 179 ID.read(in); 180 if (target.fVerboseWriter != null) 181 target.fVerboseWriter.println("field", ID.value()); 183 if (ID.isNull()) 184 return null; 185 String name = target.readString("name", in); String signature = target.readString("signature", in); String genericSignature= null; 188 if (withGenericSignature) { 189 genericSignature = target.readString("generic signature", in); if ("".equals(genericSignature)) { genericSignature= null; 192 } 193 } 194 int modifierBits = target.readInt("modifiers", AccessibleImpl.getModifierStrings(), in); 196 FieldImpl mirror = new FieldImpl(vmImpl, referenceType, ID, name, signature, genericSignature, modifierBits); 197 return mirror; 198 } 199 200 public boolean isEnumConstant() { 201 return (fModifierBits & MODIFIER_ACC_ENUM) != 0; 202 } 203 } 204 | Popular Tags |