PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-3-pre5/org/objectweb/asm/Item.java

#
Java | 256 lines | 98 code | 41 blank | 117 comment | 8 complexity | cc9193f7b5f1f3c2bb3d9cc02aa6efab MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  1. /***
  2. * ASM: a very small and fast Java bytecode manipulation framework
  3. * Copyright (C) 2000 INRIA, France Telecom
  4. * Copyright (C) 2002 France Telecom
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. *
  20. * Contact: Eric.Bruneton@rd.francetelecom.com
  21. *
  22. * Author: Eric Bruneton
  23. */
  24. package org.objectweb.asm;
  25. /**
  26. * A constant pool item. Constant pool items can be created with the 'newXXX'
  27. * methods in the {@link ClassWriter} class.
  28. */
  29. final class Item {
  30. /**
  31. * Index of this item in the constant pool.
  32. */
  33. short index;
  34. /**
  35. * Type of this constant pool item. A single class is used to represent all
  36. * constant pool item types, in order to minimize the bytecode size of this
  37. * package. The value of this field is one of the constants defined in the
  38. * {@link ClassWriter ClassWriter} class.
  39. */
  40. int type;
  41. /**
  42. * Value of this item, for a {@link ClassWriter#INT INT} item.
  43. */
  44. int intVal;
  45. /**
  46. * Value of this item, for a {@link ClassWriter#LONG LONG} item.
  47. */
  48. long longVal;
  49. /**
  50. * Value of this item, for a {@link ClassWriter#FLOAT FLOAT} item.
  51. */
  52. float floatVal;
  53. /**
  54. * Value of this item, for a {@link ClassWriter#DOUBLE DOUBLE} item.
  55. */
  56. double doubleVal;
  57. /**
  58. * First part of the value of this item, for items that do not hold a
  59. * primitive value.
  60. */
  61. String strVal1;
  62. /**
  63. * Second part of the value of this item, for items that do not hold a
  64. * primitive value.
  65. */
  66. String strVal2;
  67. /**
  68. * Third part of the value of this item, for items that do not hold a
  69. * primitive value.
  70. */
  71. String strVal3;
  72. /**
  73. * The hash code value of this constant pool item.
  74. */
  75. int hashCode;
  76. /**
  77. * Link to another constant pool item, used for collision lists in the
  78. * constant pool's hash table.
  79. */
  80. Item next;
  81. /**
  82. * Constructs an uninitialized {@link Item Item} object.
  83. */
  84. Item () {
  85. }
  86. /**
  87. * Constructs a copy of the given item.
  88. *
  89. * @param index index of the item to be constructed.
  90. * @param i the item that must be copied into the item to be constructed.
  91. */
  92. Item (final short index, final Item i) {
  93. this.index = index;
  94. type = i.type;
  95. intVal = i.intVal;
  96. longVal = i.longVal;
  97. floatVal = i.floatVal;
  98. doubleVal = i.doubleVal;
  99. strVal1 = i.strVal1;
  100. strVal2 = i.strVal2;
  101. strVal3 = i.strVal3;
  102. hashCode = i.hashCode;
  103. }
  104. /**
  105. * Sets this item to an {@link ClassWriter#INT INT} item.
  106. *
  107. * @param intVal the value of this item.
  108. */
  109. void set (final int intVal) {
  110. this.type = ClassWriter.INT;
  111. this.intVal = intVal;
  112. this.hashCode = type + intVal;
  113. }
  114. /**
  115. * Sets this item to a {@link ClassWriter#LONG LONG} item.
  116. *
  117. * @param longVal the value of this item.
  118. */
  119. void set (final long longVal) {
  120. this.type = ClassWriter.LONG;
  121. this.longVal = longVal;
  122. this.hashCode = type + (int)longVal;
  123. }
  124. /**
  125. * Sets this item to a {@link ClassWriter#FLOAT FLOAT} item.
  126. *
  127. * @param floatVal the value of this item.
  128. */
  129. void set (final float floatVal) {
  130. this.type = ClassWriter.FLOAT;
  131. this.floatVal = floatVal;
  132. this.hashCode = type + (int)floatVal;
  133. }
  134. /**
  135. * Sets this item to a {@link ClassWriter#DOUBLE DOUBLE} item.
  136. *
  137. * @param doubleVal the value of this item.
  138. */
  139. void set (final double doubleVal) {
  140. this.type = ClassWriter.DOUBLE;
  141. this.doubleVal = doubleVal;
  142. this.hashCode = type + (int)doubleVal;
  143. }
  144. /**
  145. * Sets this item to an item that do not hold a primitive value.
  146. *
  147. * @param type the type of this item.
  148. * @param strVal1 first part of the value of this item.
  149. * @param strVal2 second part of the value of this item.
  150. * @param strVal3 third part of the value of this item.
  151. */
  152. void set (
  153. final int type,
  154. final String strVal1,
  155. final String strVal2,
  156. final String strVal3)
  157. {
  158. this.type = type;
  159. this.strVal1 = strVal1;
  160. this.strVal2 = strVal2;
  161. this.strVal3 = strVal3;
  162. switch (type) {
  163. case ClassWriter.UTF8:
  164. case ClassWriter.STR:
  165. case ClassWriter.CLASS:
  166. hashCode = type + strVal1.hashCode();
  167. return;
  168. case ClassWriter.NAME_TYPE:
  169. hashCode = type + strVal1.hashCode()*strVal2.hashCode();
  170. return;
  171. //case ClassWriter.FIELD:
  172. //case ClassWriter.METH:
  173. //case ClassWriter.IMETH:
  174. default:
  175. hashCode = type + strVal1.hashCode()*strVal2.hashCode()*strVal3.hashCode();
  176. return;
  177. }
  178. }
  179. /**
  180. * Indicates if the given item is equal to this one.
  181. *
  182. * @param i the item to be compared to this one.
  183. * @return <tt>true</tt> if the given item if equal to this one,
  184. * <tt>false</tt> otherwise.
  185. */
  186. boolean isEqualTo (final Item i) {
  187. if (i.type == type) {
  188. switch (type) {
  189. case ClassWriter.INT:
  190. return i.intVal == intVal;
  191. case ClassWriter.LONG:
  192. return i.longVal == longVal;
  193. case ClassWriter.FLOAT:
  194. return i.floatVal == floatVal;
  195. case ClassWriter.DOUBLE:
  196. return i.doubleVal == doubleVal;
  197. case ClassWriter.UTF8:
  198. case ClassWriter.STR:
  199. case ClassWriter.CLASS:
  200. return i.strVal1.equals(strVal1);
  201. case ClassWriter.NAME_TYPE:
  202. return i.strVal1.equals(strVal1) &&
  203. i.strVal2.equals(strVal2);
  204. //case ClassWriter.FIELD:
  205. //case ClassWriter.METH:
  206. //case ClassWriter.IMETH:
  207. default:
  208. return i.strVal1.equals(strVal1) &&
  209. i.strVal2.equals(strVal2) &&
  210. i.strVal3.equals(strVal3);
  211. }
  212. }
  213. return false;
  214. }
  215. }