FieldInfo.java 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /**********************************************************************/
  2. /* FieldInfo class for J2CPS */
  3. /* */
  4. /* (c) copyright QUT */
  5. /**********************************************************************/
  6. package J2CPS;
  7. import java.io.*;
  8. import java.util.*;
  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. if (type instanceof ClassDesc) { thisClass.AddImport((ClassDesc)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. 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. public String toString() {
  45. if (constVal == null) {
  46. return ConstantPool.GetAccessString(accessFlags) + " " +
  47. signature + " " + name;
  48. } else {
  49. return ConstantPool.GetAccessString(accessFlags) + " " +
  50. signature + " " + name + " = " + constVal.toString();
  51. }
  52. }
  53. }