PageRenderTime 106ms CodeModel.GetById 93ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-5-pre1/org/gjt/sp/jedit/bsh/org/objectweb/asm/Item.java

#
Java | 256 lines | 98 code | 41 blank | 117 comment | 8 complexity | 5004aa512c1682caac8bce2b6e60787a MD5 | raw file
  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
 25package org.gjt.sp.jedit.bsh.org.objectweb.asm;
 26
 27/**
 28 * A constant pool item. Constant pool items can be created with the 'newXXX'
 29 * methods in the {@link ClassWriter} class.
 30 */
 31
 32final class Item {
 33
 34  /**
 35   * Index of this item in the constant pool.
 36   */
 37
 38  short index;
 39
 40  /**
 41   * Type of this constant pool item. A single class is used to represent all
 42   * constant pool item types, in order to minimize the bytecode size of this
 43   * package. The value of this field is one of the constants defined in the
 44   * {@link ClassWriter ClassWriter} class.
 45   */
 46
 47  int type;
 48
 49  /**
 50   * Value of this item, for a {@link ClassWriter#INT INT} item.
 51   */
 52
 53  int intVal;
 54
 55  /**
 56   * Value of this item, for a {@link ClassWriter#LONG LONG} item.
 57   */
 58
 59  long longVal;
 60
 61  /**
 62   * Value of this item, for a {@link ClassWriter#FLOAT FLOAT} item.
 63   */
 64
 65  float floatVal;
 66
 67  /**
 68   * Value of this item, for a {@link ClassWriter#DOUBLE DOUBLE} item.
 69   */
 70
 71  double doubleVal;
 72
 73  /**
 74   * First part of the value of this item, for items that do not hold a
 75   * primitive value.
 76   */
 77
 78  String strVal1;
 79
 80  /**
 81   * Second part of the value of this item, for items that do not hold a
 82   * primitive value.
 83   */
 84
 85  String strVal2;
 86
 87  /**
 88   * Third part of the value of this item, for items that do not hold a
 89   * primitive value.
 90   */
 91
 92  String strVal3;
 93
 94  /**
 95   * The hash code value of this constant pool item.
 96   */
 97
 98  int hashCode;
 99
100  /**
101   * Link to another constant pool item, used for collision lists in the
102   * constant pool's hash table.
103   */
104
105  Item next;
106
107  /**
108   * Constructs an uninitialized {@link Item Item} object.
109   */
110
111  Item () {
112  }
113
114  /**
115   * Constructs a copy of the given item.
116   *
117   * @param index index of the item to be constructed.
118   * @param i the item that must be copied into the item to be constructed.
119   */
120
121  Item (final short index, final Item i) {
122    this.index = index;
123    type = i.type;
124    intVal = i.intVal;
125    longVal = i.longVal;
126    floatVal = i.floatVal;
127    doubleVal = i.doubleVal;
128    strVal1 = i.strVal1;
129    strVal2 = i.strVal2;
130    strVal3 = i.strVal3;
131    hashCode = i.hashCode;
132  }
133
134  /**
135   * Sets this item to an {@link ClassWriter#INT INT} item.
136   *
137   * @param intVal the value of this item.
138   */
139
140  void set (final int intVal) {
141    this.type = ClassWriter.INT;
142    this.intVal = intVal;
143    this.hashCode = type + intVal;
144  }
145
146  /**
147   * Sets this item to a {@link ClassWriter#LONG LONG} item.
148   *
149   * @param longVal the value of this item.
150   */
151
152  void set (final long longVal) {
153    this.type = ClassWriter.LONG;
154    this.longVal = longVal;
155    this.hashCode = type + (int)longVal;
156  }
157
158  /**
159   * Sets this item to a {@link ClassWriter#FLOAT FLOAT} item.
160   *
161   * @param floatVal the value of this item.
162   */
163
164  void set (final float floatVal) {
165    this.type = ClassWriter.FLOAT;
166    this.floatVal = floatVal;
167    this.hashCode = type + (int)floatVal;
168  }
169
170  /**
171   * Sets this item to a {@link ClassWriter#DOUBLE DOUBLE} item.
172   *
173   * @param doubleVal the value of this item.
174   */
175
176  void set (final double doubleVal) {
177    this.type = ClassWriter.DOUBLE;
178    this.doubleVal = doubleVal;
179    this.hashCode = type + (int)doubleVal;
180  }
181
182  /**
183   * Sets this item to an item that do not hold a primitive value.
184   *
185   * @param type the type of this item.
186   * @param strVal1 first part of the value of this item.
187   * @param strVal2 second part of the value of this item.
188   * @param strVal3 third part of the value of this item.
189   */
190
191  void set (
192    final int type,
193    final String strVal1,
194    final String strVal2,
195    final String strVal3)
196  {
197    this.type = type;
198    this.strVal1 = strVal1;
199    this.strVal2 = strVal2;
200    this.strVal3 = strVal3;
201    switch (type) {
202      case ClassWriter.UTF8:
203      case ClassWriter.STR:
204      case ClassWriter.CLASS:
205        hashCode = type + strVal1.hashCode();
206        return;
207      case ClassWriter.NAME_TYPE:
208        hashCode = type + strVal1.hashCode()*strVal2.hashCode();
209        return;
210      //case ClassWriter.FIELD:
211      //case ClassWriter.METH:
212      //case ClassWriter.IMETH:
213      default:
214        hashCode = type + strVal1.hashCode()*strVal2.hashCode()*strVal3.hashCode();
215        return;
216    }
217  }
218
219  /**
220   * Indicates if the given item is equal to this one.
221   *
222   * @param i the item to be compared to this one.
223   * @return <tt>true</tt> if the given item if equal to this one,
224   *      <tt>false</tt> otherwise.
225   */
226
227  boolean isEqualTo (final Item i) {
228    if (i.type == type) {
229      switch (type) {
230        case ClassWriter.INT:
231          return i.intVal == intVal;
232        case ClassWriter.LONG:
233          return i.longVal == longVal;
234        case ClassWriter.FLOAT:
235          return i.floatVal == floatVal;
236        case ClassWriter.DOUBLE:
237          return i.doubleVal == doubleVal;
238        case ClassWriter.UTF8:
239        case ClassWriter.STR:
240        case ClassWriter.CLASS:
241          return i.strVal1.equals(strVal1);
242        case ClassWriter.NAME_TYPE:
243          return i.strVal1.equals(strVal1) &&
244                 i.strVal2.equals(strVal2);
245        //case ClassWriter.FIELD:
246        //case ClassWriter.METH:
247        //case ClassWriter.IMETH:
248        default:
249          return i.strVal1.equals(strVal1) &&
250                 i.strVal2.equals(strVal2) &&
251                 i.strVal3.equals(strVal3);
252      }
253    }
254    return false;
255  }
256}