FieldInfo.java 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**********************************************************************/
  2. /* FieldInfo class for J2CPS */
  3. /* */
  4. /* (c) copyright QUT */
  5. /**********************************************************************/
  6. package J2CPS;
  7. import java.io.DataInputStream;
  8. import java.io.IOException;
  9. public class FieldInfo extends MemberInfo {
  10. Object constVal;
  11. public TypeDesc type;
  12. public int typeFixUp = 0;
  13. public FieldInfo(ConstantPool cp, DataInputStream stream,
  14. ClassDesc thisClass) throws IOException {
  15. super(cp,stream,thisClass);
  16. type = TypeDesc.GetType(signature,0);
  17. thisClass.TryImport(type);
  18. }
  19. public FieldInfo(ClassDesc cl,int acc,String nam,TypeDesc typ,Object cVal) {
  20. super(cl,acc,nam);
  21. type = typ;
  22. constVal = cVal;
  23. }
  24. // @Override
  25. // public void AddImport(ClassDesc thisClass) {
  26. // if (type instanceof ClassDesc) { thisClass.AddImport((ClassDesc)type); }
  27. // }
  28. public void GetConstValueAttribute (ConstantPool cp, DataInputStream stream)
  29. throws IOException {
  30. int attLen = stream.readInt();
  31. constVal = cp.Get(stream.readUnsignedShort());
  32. if (constVal instanceof StringRef) {
  33. constVal = ((StringRef)constVal).GetString();
  34. }
  35. }
  36. public Object GetConstVal() {
  37. return constVal;
  38. }
  39. public boolean isConstant() {
  40. return ((constVal != null) && ConstantPool.isFinal(accessFlags) &&
  41. ConstantPool.isStatic(accessFlags) &&
  42. (ConstantPool.isPublic(accessFlags) ||
  43. ConstantPool.isProtected(accessFlags)));
  44. }
  45. @Override
  46. public String toString() {
  47. if (constVal == null) {
  48. return ConstantPool.GetAccessString(accessFlags) + " " +
  49. signature + " " + name;
  50. } else {
  51. return ConstantPool.GetAccessString(accessFlags) + " " +
  52. signature + " " + name + " = " + constVal.toString();
  53. }
  54. }
  55. }