ClassRef.java 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*************************************************************************/
  2. /* Class Reference class for J2CPS */
  3. /* Represents the class references in the constant pool of a class file */
  4. /* (c) copyright QUT */
  5. /*************************************************************************/
  6. package J2CPS;
  7. public class ClassRef {
  8. ConstantPool cp; /* the constant pool containing this class ref */
  9. String name; /* the name of this class */
  10. int nameIndex; /* the index into the constant pool */
  11. /* for the name of this class */
  12. ClassDesc info; /* this class info for this class ref */
  13. public ClassRef(ConstantPool thisCp, int nameIndex) {
  14. this.cp = thisCp;
  15. this.nameIndex = nameIndex;
  16. }
  17. public String GetName() {
  18. if (name == null) { name = (String) cp.Get(nameIndex); }
  19. return name;
  20. }
  21. public ClassDesc GetClassDesc() {
  22. if (info == null) {
  23. if (name == null) { name = (String) this.cp.Get(nameIndex); }
  24. info = ClassDesc.GetClassDesc(name,null);
  25. }
  26. return info;
  27. }
  28. public boolean equals(ClassRef anotherClass) {
  29. return this.GetName().equals(anotherClass.GetName());
  30. }
  31. public void Resolve() {
  32. if (name == null) { this.name = (String) this.cp.Get(nameIndex); }
  33. }
  34. @Override
  35. public String toString() {
  36. this.Resolve();
  37. return ("<ClassReference> " + nameIndex + " " + name);
  38. }
  39. }