StringRef.java 1.0 KB

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