PageRenderTime 34ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/testing/apache-ant-1.8.2/src/main/org/apache/tools/ant/taskdefs/optional/depend/constantpool/ConstantPoolEntry.java

https://code.google.com/p/classroom-presenter/
Java | 221 lines | 82 code | 40 blank | 99 comment | 1 complexity | be5764b0afeedcd6480e929f7b726e97 MD5 | raw file
Possible License(s): Apache-2.0, IPL-1.0
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. package org.apache.tools.ant.taskdefs.optional.depend.constantpool;
  19. import java.io.DataInputStream;
  20. import java.io.IOException;
  21. /**
  22. * An entry in the constant pool. This class contains a representation of the
  23. * constant pool entries. It is an abstract base class for all the different
  24. * forms of constant pool entry.
  25. *
  26. * @see ConstantPool
  27. */
  28. public abstract class ConstantPoolEntry {
  29. /** Tag value for UTF8 entries. */
  30. public static final int CONSTANT_UTF8 = 1;
  31. /** Tag value for Integer entries. */
  32. public static final int CONSTANT_INTEGER = 3;
  33. /** Tag value for Float entries. */
  34. public static final int CONSTANT_FLOAT = 4;
  35. /** Tag value for Long entries. */
  36. public static final int CONSTANT_LONG = 5;
  37. /** Tag value for Double entries. */
  38. public static final int CONSTANT_DOUBLE = 6;
  39. /** Tag value for Class entries. */
  40. public static final int CONSTANT_CLASS = 7;
  41. /** Tag value for String entries. */
  42. public static final int CONSTANT_STRING = 8;
  43. /** Tag value for Field Reference entries. */
  44. public static final int CONSTANT_FIELDREF = 9;
  45. /** Tag value for Method Reference entries. */
  46. public static final int CONSTANT_METHODREF = 10;
  47. /** Tag value for Interface Method Reference entries. */
  48. public static final int CONSTANT_INTERFACEMETHODREF = 11;
  49. /** Tag value for Name and Type entries. */
  50. public static final int CONSTANT_NAMEANDTYPE = 12;
  51. /**
  52. * This entry's tag which identifies the type of this constant pool
  53. * entry.
  54. */
  55. private int tag;
  56. /**
  57. * The number of slots in the constant pool, occupied by this entry.
  58. */
  59. private int numEntries;
  60. /**
  61. * A flag which indicates if this entry has been resolved or not.
  62. */
  63. private boolean resolved;
  64. /**
  65. * Initialise the constant pool entry.
  66. *
  67. * @param tagValue the tag value which identifies which type of constant
  68. * pool entry this is.
  69. * @param entries the number of constant pool entry slots this entry
  70. * occupies.
  71. */
  72. public ConstantPoolEntry(int tagValue, int entries) {
  73. tag = tagValue;
  74. numEntries = entries;
  75. resolved = false;
  76. }
  77. /**
  78. * Read a constant pool entry from a stream. This is a factory method
  79. * which reads a constant pool entry form a stream and returns the
  80. * appropriate subclass for the entry.
  81. *
  82. * @param cpStream the stream from which the constant pool entry is to
  83. * be read.
  84. * @return the appropriate ConstantPoolEntry subclass representing the
  85. * constant pool entry from the stream.
  86. * @exception IOException if the constant pool entry cannot be read
  87. * from the stream
  88. */
  89. public static ConstantPoolEntry readEntry(DataInputStream cpStream)
  90. throws IOException {
  91. ConstantPoolEntry cpInfo = null;
  92. int cpTag = cpStream.readUnsignedByte();
  93. switch (cpTag) {
  94. case CONSTANT_UTF8:
  95. cpInfo = new Utf8CPInfo();
  96. break;
  97. case CONSTANT_INTEGER:
  98. cpInfo = new IntegerCPInfo();
  99. break;
  100. case CONSTANT_FLOAT:
  101. cpInfo = new FloatCPInfo();
  102. break;
  103. case CONSTANT_LONG:
  104. cpInfo = new LongCPInfo();
  105. break;
  106. case CONSTANT_DOUBLE:
  107. cpInfo = new DoubleCPInfo();
  108. break;
  109. case CONSTANT_CLASS:
  110. cpInfo = new ClassCPInfo();
  111. break;
  112. case CONSTANT_STRING:
  113. cpInfo = new StringCPInfo();
  114. break;
  115. case CONSTANT_FIELDREF:
  116. cpInfo = new FieldRefCPInfo();
  117. break;
  118. case CONSTANT_METHODREF:
  119. cpInfo = new MethodRefCPInfo();
  120. break;
  121. case CONSTANT_INTERFACEMETHODREF:
  122. cpInfo = new InterfaceMethodRefCPInfo();
  123. break;
  124. case CONSTANT_NAMEANDTYPE:
  125. cpInfo = new NameAndTypeCPInfo();
  126. break;
  127. default:
  128. throw new ClassFormatError("Invalid Constant Pool entry Type "
  129. + cpTag);
  130. }
  131. cpInfo.read(cpStream);
  132. return cpInfo;
  133. }
  134. /**
  135. * Indicates whether this entry has been resolved. In general a constant
  136. * pool entry can reference another constant pool entry by its index
  137. * value. Resolution involves replacing this index value with the
  138. * constant pool entry at that index.
  139. *
  140. * @return true if this entry has been resolved.
  141. */
  142. public boolean isResolved() {
  143. return resolved;
  144. }
  145. /**
  146. * Resolve this constant pool entry with respect to its dependents in
  147. * the constant pool.
  148. *
  149. * @param constantPool the constant pool of which this entry is a member
  150. * and against which this entry is to be resolved.
  151. */
  152. public void resolve(ConstantPool constantPool) {
  153. resolved = true;
  154. }
  155. /**
  156. * read a constant pool entry from a class stream.
  157. *
  158. * @param cpStream the DataInputStream which contains the constant pool
  159. * entry to be read.
  160. * @exception IOException if there is a problem reading the entry from
  161. * the stream.
  162. */
  163. public abstract void read(DataInputStream cpStream) throws IOException;
  164. /**
  165. * Get the Entry's type tag.
  166. *
  167. * @return The Tag value of this entry
  168. */
  169. public int getTag() {
  170. return tag;
  171. }
  172. /**
  173. * Get the number of Constant Pool Entry slots within the constant pool
  174. * occupied by this entry.
  175. *
  176. * @return the number of slots used.
  177. */
  178. public final int getNumEntries() {
  179. return numEntries;
  180. }
  181. }