NameAndType.java 1.4 KB

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