Пример #1
0
 /**
  * Converts a type path in string form, in the format used by {@link #toString()}, into a TypePath
  * object.
  *
  * @param typePath a type path in string form, in the format used by {@link #toString()}. May be
  *     null or empty.
  * @return the corresponding TypePath object, or null if the path is empty.
  */
 public static TypePath fromString(final String typePath) {
   if (typePath == null || typePath.length() == 0) {
     return null;
   }
   int n = typePath.length();
   ByteVector out = new ByteVector(n);
   out.putByte(0);
   for (int i = 0; i < n; ) {
     char c = typePath.charAt(i++);
     if (c == '[') {
       out.put11(ARRAY_ELEMENT, 0);
     } else if (c == '.') {
       out.put11(INNER_TYPE, 0);
     } else if (c == '*') {
       out.put11(WILDCARD_BOUND, 0);
     } else if (c >= '0' && c <= '9') {
       int typeArg = c - '0';
       while (i < n && (c = typePath.charAt(i)) >= '0' && c <= '9') {
         typeArg = typeArg * 10 + c - '0';
         i += 1;
       }
       out.put11(TYPE_ARGUMENT, typeArg);
     }
   }
   out.data[0] = (byte) (out.length / 2);
   return new TypePath(out.data, 0);
 }
Пример #2
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;
 }
Пример #3
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;
 }
Пример #4
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;
 }
Пример #5
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;
 }
Пример #6
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;
 }