Reference.java 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /**********************************************************************/
  2. /* Reference class for j2cps */
  3. /* */
  4. /* (c) copyright QUT, John Gough 2000-2012, John Gough, 2012-2017 */
  5. /**********************************************************************/
  6. package j2cps;
  7. public class Reference {
  8. ConstantPool cp; /* The constant pool containing this ref */
  9. int classIndex; /* CP index for this reference's class */
  10. int nameAndTypeIndex; /* CP index for this ref's name and type */
  11. ClassRef classRef;
  12. NameAndType nAndt;
  13. String name;
  14. String type;
  15. public Reference(ConstantPool thisCp, int classIndex, int ntIndex) {
  16. this.cp = thisCp;
  17. this.classIndex = classIndex;
  18. this.nameAndTypeIndex = ntIndex;
  19. }
  20. public String GetClassName() {
  21. if (this.classRef == null) {
  22. this.classRef = (ClassRef) this.cp.Get(classIndex);
  23. }
  24. return classRef.GetName();
  25. }
  26. public void Resolve() {
  27. this.classRef = (ClassRef) this.cp.Get(classIndex);
  28. this.nAndt = (NameAndType) this.cp.Get(nameAndTypeIndex);
  29. this.name = nAndt.GetName();
  30. this.type = nAndt.GetType();
  31. }
  32. @Override
  33. public String toString() {
  34. this.Resolve();
  35. return ("Class " + classIndex + " NameAndType " + nameAndTypeIndex);
  36. }
  37. }