ClassRef.java 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. import java.io.*;
  8. public class ClassRef {
  9. ConstantPool cp; /* the constant pool containing this class ref */
  10. String name; /* the name of this class */
  11. int nameIndex; /* the index into the constant pool */
  12. /* for the name of this class */
  13. ClassDesc info; /* this class info for this class ref */
  14. public ClassRef(ConstantPool thisCp, int nameIndex) {
  15. this.cp = thisCp;
  16. this.nameIndex = nameIndex;
  17. }
  18. public String GetName() {
  19. if (name == null) { name = (String) cp.Get(nameIndex); }
  20. return name;
  21. }
  22. public ClassDesc GetClassDesc() {
  23. if (info == null) {
  24. if (name == null) { name = (String) this.cp.Get(nameIndex); }
  25. info = ClassDesc.GetClassDesc(name,null);
  26. }
  27. return info;
  28. }
  29. public boolean equals(ClassRef anotherClass) {
  30. return this.GetName().equals(anotherClass.GetName());
  31. }
  32. public void Resolve() {
  33. if (name == null) { this.name = (String) this.cp.Get(nameIndex); }
  34. }
  35. public String toString() {
  36. this.Resolve();
  37. return ("<ClassReference> " + nameIndex + " " + name);
  38. }
  39. }