예제 #1
0
 /**
  * Adds the given internal name to {@link #typeTable} and returns its index. Does nothing if the
  * type table already contains this internal name.
  *
  * @param type the internal name to be added to the type table.
  * @return the index of this internal name in the type table.
  */
 int addType(final String type) {
   key.set(TYPE_NORMAL, type, null, null);
   Item result = get(key);
   if (result == null) {
     result = addType(key);
   }
   return result.index;
 }
예제 #2
0
  @Test
  public void shouldConvertEmptyStringToNull() {
    deleteAndPopulateTable("items");

    Item it = new Item();
    it.set("item_number", "");
    it.validate();
    a(it.get("item_number")).shouldBeNull();
  }
예제 #3
0
 /**
  * Adds a name and type to the constant pool of the class being build. Does nothing if the
  * constant pool already contains a similar item. <i>This method is intended for {@link Attribute}
  * sub classes, and is normally not needed by class generators or adapters.</i>
  *
  * @param name a name.
  * @param desc a type descriptor.
  * @return the index of a new or already existing name and type item.
  */
 public int newNameType(final String name, final String desc) {
   key2.set(NAME_TYPE, name, desc, null);
   Item result = get(key2);
   if (result == null) {
     put122(NAME_TYPE, newUTF8(name), newUTF8(desc));
     result = new Item(index++, key2);
     put(result);
   }
   return result.index;
 }
예제 #4
0
 /**
  * Adds a string to the constant pool of the class being build. Does nothing if the constant pool
  * already contains a similar item.
  *
  * @param value the String value.
  * @return a new or already existing string item.
  */
 private Item newString(final String value) {
   key2.set(STR, value, null, null);
   Item result = get(key2);
   if (result == null) {
     pool.put12(STR, newUTF8(value));
     result = new Item(index++, key2);
     put(result);
   }
   return result;
 }
예제 #5
0
 /**
  * Adds a float to the constant pool of the class being build. Does nothing if the constant pool
  * already contains a similar item.
  *
  * @param value the float value.
  * @return a new or already existing float item.
  */
 Item newFloat(final float value) {
   key.set(value);
   Item result = get(key);
   if (result == null) {
     pool.putByte(FLOAT).putInt(Float.floatToIntBits(value));
     result = new Item(index++, key);
     put(result);
   }
   return result;
 }
예제 #6
0
 /**
  * Adds an integer to the constant pool of the class being build. Does nothing if the constant
  * pool already contains a similar item.
  *
  * @param value the int value.
  * @return a new or already existing int item.
  */
 Item newInteger(final int value) {
   key.set(value);
   Item result = get(key);
   if (result == null) {
     pool.putByte(INT).putInt(value);
     result = new Item(index++, key);
     put(result);
   }
   return result;
 }
예제 #7
0
 /**
  * Adds a field reference to the constant pool of the class being build. Does nothing if the
  * constant pool already contains a similar item.
  *
  * @param owner the internal name of the field's owner class.
  * @param name the field's name.
  * @param desc the field's descriptor.
  * @return a new or already existing field reference item.
  */
 Item newFieldItem(final String owner, final String name, final String desc) {
   key3.set(FIELD, owner, name, desc);
   Item result = get(key3);
   if (result == null) {
     put122(FIELD, newClass(owner), newNameType(name, desc));
     result = new Item(index++, key3);
     put(result);
   }
   return result;
 }
예제 #8
0
 /**
  * Adds a class reference to the constant pool of the class being build. Does nothing if the
  * constant pool already contains a similar item. <i>This method is intended for {@link Attribute}
  * sub classes, and is normally not needed by class generators or adapters.</i>
  *
  * @param value the internal name of the class.
  * @return a new or already existing class reference item.
  */
 Item newClassItem(final String value) {
   key2.set(CLASS, value, null, null);
   Item result = get(key2);
   if (result == null) {
     pool.put12(CLASS, newUTF8(value));
     result = new Item(index++, key2);
     put(result);
   }
   return result;
 }
예제 #9
0
 /**
  * Adds an UTF8 string to the constant pool of the class being build. Does nothing if the constant
  * pool already contains a similar item. <i>This method is intended for {@link Attribute} sub
  * classes, and is normally not needed by class generators or adapters.</i>
  *
  * @param value the String value.
  * @return the index of a new or already existing UTF8 item.
  */
 public int newUTF8(final String value) {
   key.set(UTF8, value, null, null);
   Item result = get(key);
   if (result == null) {
     pool.putByte(UTF8).putUTF8(value);
     result = new Item(index++, key);
     put(result);
   }
   return result.index;
 }
예제 #10
0
 /**
  * Adds a method reference to the constant pool of the class being build. Does nothing if the
  * constant pool already contains a similar item.
  *
  * @param owner the internal name of the method's owner class.
  * @param name the method's name.
  * @param desc the method's descriptor.
  * @param itf <tt>true</tt> if <tt>owner</tt> is an interface.
  * @return a new or already existing method reference item.
  */
 Item newMethodItem(final String owner, final String name, final String desc, final boolean itf) {
   key3.set(itf ? 'N' : 'M', owner, name, desc);
   Item result = get(key3);
   if (result == null) {
     put122(itf ? IMETH : METH, newClass(owner), newNameType(name, desc));
     result = new Item(index++, key3);
     put(result);
   }
   return result;
 }
예제 #11
0
 /**
  * Adds a double to the constant pool of the class being build. Does nothing if the constant pool
  * already contains a similar item.
  *
  * @param value the double value.
  * @return a new or already existing double item.
  */
 Item newDouble(final double value) {
   key.set(value);
   Item result = get(key);
   if (result == null) {
     pool.putByte(DOUBLE).putLong(Double.doubleToLongBits(value));
     result = new Item(index, key);
     put(result);
     index += 2;
   }
   return result;
 }
예제 #12
0
 /**
  * Adds a long to the constant pool of the class being build. Does nothing if the constant pool
  * already contains a similar item.
  *
  * @param value the long value.
  * @return a new or already existing long item.
  */
 Item newLong(final long value) {
   key.set(value);
   Item result = get(key);
   if (result == null) {
     pool.putByte(LONG).putLong(value);
     result = new Item(index, key);
     put(result);
     index += 2;
   }
   return result;
 }
예제 #13
0
 /**
  * Adds a method reference to the constant pool of the class being build. Does nothing if the
  * constant pool already contains a similar item.
  *
  * @param owner the internal name of the method's owner class.
  * @param name the method's name.
  * @param desc the method's descriptor.
  * @param itf <tt>true</tt> if <tt>owner</tt> is an interface.
  * @return a new or already existing method reference item.
  */
 final Item newMethodItem(String owner, String name, String desc, boolean itf) {
   int type = itf ? IMETH : METH;
   key3.set(type, owner, name, desc);
   Item result = get(key3);
   if (result == null) {
     put122(type, newClass(owner), newNameType(name, desc));
     result = new Item(index++, key3);
     put(result);
   }
   return result;
 }