StringRef.java 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. /**********************************************************************/
  2. /* String Reference class for J2CPS */
  3. /* */
  4. /* (c) copyright QUT */
  5. /**********************************************************************/
  6. package J2CPS;
  7. import java.io.*;
  8. public class StringRef {
  9. ConstantPool cp; /* the constant pool containing this string ref */
  10. String str; /* the string this ref refers to */
  11. int strIndex; /* the CP index for this string */
  12. public StringRef(ConstantPool thisCp, int strIx) {
  13. this.cp = thisCp;
  14. this.strIndex = strIx;
  15. }
  16. public String GetString() {
  17. if (this.str == null) { this.str = (String) cp.Get(strIndex); }
  18. return str;
  19. }
  20. public void Resolve() {
  21. this.str = (String) this.cp.Get(strIndex);
  22. }
  23. public String toString() {
  24. this.Resolve();
  25. return ("<StringRef> " + this.strIndex + " " + str);
  26. }
  27. }