1. /*
  2. * Copyright 2000-2002,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 MethodRef CP Info
  22. *
  23. */
  24. public class MethodRefCPInfo extends ConstantPoolEntry {
  25. /** the name of the class defining this method */
  26. private String methodClassName;
  27. /** the name of the method */
  28. private String methodName;
  29. /** the method's type descriptor */
  30. private String methodType;
  31. /** The index into the constant pool which defines the class of this method. */
  32. private int classIndex;
  33. /**
  34. * the index into the constant pool which defined the name and type
  35. * signature of the method
  36. */
  37. private int nameAndTypeIndex;
  38. /** Constructor. */
  39. public MethodRefCPInfo() {
  40. super(CONSTANT_METHODREF, 1);
  41. }
  42. /**
  43. * read a constant pool entry from a class stream.
  44. *
  45. * @param cpStream the DataInputStream which contains the constant pool
  46. * entry to be read.
  47. * @exception IOException if there is a problem reading the entry from
  48. * the stream.
  49. */
  50. public void read(DataInputStream cpStream) throws IOException {
  51. classIndex = cpStream.readUnsignedShort();
  52. nameAndTypeIndex = cpStream.readUnsignedShort();
  53. }
  54. /**
  55. * Print a readable version of the constant pool entry.
  56. *
  57. * @return the string representation of this constant pool entry.
  58. */
  59. public String toString() {
  60. String value;
  61. if (isResolved()) {
  62. value = "Method : Class = " + methodClassName + ", name = "
  63. + methodName + ", type = " + methodType;
  64. } else {
  65. value = "Method : Class index = " + classIndex
  66. + ", name and type index = " + nameAndTypeIndex;
  67. }
  68. return value;
  69. }
  70. /**
  71. * Resolve this constant pool entry with respect to its dependents in
  72. * the constant pool.
  73. *
  74. * @param constantPool the constant pool of which this entry is a member
  75. * and against which this entry is to be resolved.
  76. */
  77. public void resolve(ConstantPool constantPool) {
  78. ClassCPInfo methodClass
  79. = (ClassCPInfo) constantPool.getEntry(classIndex);
  80. methodClass.resolve(constantPool);
  81. methodClassName = methodClass.getClassName();
  82. NameAndTypeCPInfo nt
  83. = (NameAndTypeCPInfo) constantPool.getEntry(nameAndTypeIndex);
  84. nt.resolve(constantPool);
  85. methodName = nt.getName();
  86. methodType = nt.getType();
  87. super.resolve(constantPool);
  88. }
  89. /**
  90. * Get the name of the class defining the method
  91. *
  92. * @return the name of the class defining this method
  93. */
  94. public String getMethodClassName() {
  95. return methodClassName;
  96. }
  97. /**
  98. * Get the name of the method.
  99. *
  100. * @return the name of the method.
  101. */
  102. public String getMethodName() {
  103. return methodName;
  104. }
  105. /**
  106. * Get the type signature of the method.
  107. *
  108. * @return the type signature of the method.
  109. */
  110. public String getMethodType() {
  111. return methodType;
  112. }
  113. }