FieldInfo.java 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /**********************************************************************/
  2. /* FieldInfo class for j2cps */
  3. /* */
  4. /* (c) copyright QUT, John Gough 2000-2012, John Gough, 2012-2017 */
  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. this.type = TypeDesc.GetType(this.signature,0);
  17. }
  18. public FieldInfo(ClassDesc cl,int acc,String nam,TypeDesc typ,Object cVal) {
  19. super(cl,acc,nam);
  20. this.type = typ;
  21. this.constVal = cVal;
  22. }
  23. // @Override
  24. // public void AddImport(ClassDesc thisClass) {
  25. // if (type instanceof ClassDesc) { thisClass.AddImport((ClassDesc)type); }
  26. // }
  27. public void GetConstValueAttribute (ConstantPool cp, DataInputStream stream)
  28. throws IOException {
  29. int attLen = stream.readInt();
  30. constVal = cp.Get(stream.readUnsignedShort());
  31. if (constVal instanceof StringRef) {
  32. constVal = ((StringRef)constVal).GetString();
  33. }
  34. }
  35. public Object GetConstVal() {
  36. return constVal;
  37. }
  38. public boolean isConstant() {
  39. return ((constVal != null) && ConstantPool.isFinal(accessFlags) &&
  40. ConstantPool.isStatic(accessFlags) &&
  41. (ConstantPool.isPublic(accessFlags) ||
  42. ConstantPool.isProtected(accessFlags)));
  43. }
  44. @Override
  45. public String toString() {
  46. if (constVal == null) {
  47. return ConstantPool.GetAccessString(accessFlags) + " " +
  48. signature + " " + name;
  49. } else {
  50. return ConstantPool.GetAccessString(accessFlags) + " " +
  51. signature + " " + name + " = " + constVal.toString();
  52. }
  53. }
  54. }