1. /*
  2. * Copyright 2000-2004 The Apache Software Foundation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. *
  16. */
  17. package org.apache.tools.ant.taskdefs.optional.depend.constantpool;
  18. import java.io.DataInputStream;
  19. import java.io.IOException;
  20. /**
  21. * A InterfaceMethodRef CP Info
  22. *
  23. */
  24. public class InterfaceMethodRefCPInfo extends ConstantPoolEntry {
  25. /** the class name of the class defining the interface method */
  26. private String interfaceMethodClassName;
  27. /** the name of the interface nmethod */
  28. private String interfaceMethodName;
  29. /** the method signature of the interface method */
  30. private String interfaceMethodType;
  31. /**
  32. * the index into the constant pool of the class entry for the interface
  33. * class
  34. */
  35. private int classIndex;
  36. /**
  37. * the index into the constant pool of the name and type entry
  38. * describing the method
  39. */
  40. private int nameAndTypeIndex;
  41. /** Constructor. */
  42. public InterfaceMethodRefCPInfo() {
  43. super(CONSTANT_INTERFACEMETHODREF, 1);
  44. }
  45. /**
  46. * read a constant pool entry from a class stream.
  47. *
  48. * @param cpStream the DataInputStream which contains the constant pool
  49. * entry to be read.
  50. * @exception IOException if there is a problem reading the entry from
  51. * the stream.
  52. */
  53. public void read(DataInputStream cpStream) throws IOException {
  54. classIndex = cpStream.readUnsignedShort();
  55. nameAndTypeIndex = cpStream.readUnsignedShort();
  56. }
  57. /**
  58. * Resolve this constant pool entry with respect to its dependents in
  59. * the constant pool.
  60. *
  61. * @param constantPool the constant pool of which this entry is a member
  62. * and against which this entry is to be resolved.
  63. */
  64. public void resolve(ConstantPool constantPool) {
  65. ClassCPInfo interfaceMethodClass
  66. = (ClassCPInfo) constantPool.getEntry(classIndex);
  67. interfaceMethodClass.resolve(constantPool);
  68. interfaceMethodClassName = interfaceMethodClass.getClassName();
  69. NameAndTypeCPInfo nt
  70. = (NameAndTypeCPInfo) constantPool.getEntry(nameAndTypeIndex);
  71. nt.resolve(constantPool);
  72. interfaceMethodName = nt.getName();
  73. interfaceMethodType = nt.getType();
  74. super.resolve(constantPool);
  75. }
  76. /**
  77. * Print a readable version of the constant pool entry.
  78. *
  79. * @return the string representation of this constant pool entry.
  80. */
  81. public String toString() {
  82. String value;
  83. if (isResolved()) {
  84. value = "InterfaceMethod : Class = " + interfaceMethodClassName
  85. + ", name = " + interfaceMethodName + ", type = "
  86. + interfaceMethodType;
  87. } else {
  88. value = "InterfaceMethod : Class index = " + classIndex
  89. + ", name and type index = " + nameAndTypeIndex;
  90. }
  91. return value;
  92. }
  93. /**
  94. * Gets the name of the class defining the interface method
  95. *
  96. * @return the name of the class defining the interface method
  97. */
  98. public String getInterfaceMethodClassName() {
  99. return interfaceMethodClassName;
  100. }
  101. /**
  102. * Get the name of the interface method
  103. *
  104. * @return the name of the interface method
  105. */
  106. public String getInterfaceMethodName() {
  107. return interfaceMethodName;
  108. }
  109. /**
  110. * Gets the type of the interface method
  111. *
  112. * @return the interface method's type signature
  113. */
  114. public String getInterfaceMethodType() {
  115. return interfaceMethodType;
  116. }
  117. }