Beispiel #1
0
 public void visitEnum(final String name, final String desc, final String value) {
   ++size;
   if (named) {
     bv.putShort(cw.newUTF8(name));
   }
   bv.put12('e', cw.newUTF8(desc)).putShort(cw.newUTF8(value));
 }
Beispiel #2
0
 public AnnotationVisitor visitArray(final String name) {
   ++size;
   if (named) {
     bv.putShort(cw.newUTF8(name));
   }
   // write tag, and reserve space for array size
   bv.put12('[', 0);
   return new AnnotationWriter(cw, false, bv, bv, bv.length - 2);
 }
Beispiel #3
0
 public AnnotationVisitor visitAnnotation(final String name, final String desc) {
   ++size;
   if (named) {
     bv.putShort(cw.newUTF8(name));
   }
   // write tag and type, and reserve space for values count
   bv.put12('@', cw.newUTF8(desc)).putShort(0);
   return new AnnotationWriter(cw, true, bv, bv, bv.length - 2);
 }
Beispiel #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;
 }
Beispiel #5
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;
 }
Beispiel #6
0
 /**
  * Puts one byte and two shorts into the constant pool.
  *
  * @param b a byte.
  * @param s1 a short.
  * @param s2 another short.
  */
 private void put122(final int b, final int s1, final int s2) {
   pool.put12(b, s1).putShort(s2);
 }
Beispiel #7
0
 /**
  * Puts one byte and two shorts into the constant pool.
  *
  * @param b a byte.
  * @param s1 a short.
  * @param s2 another short.
  */
 private void put122(int b, int s1, int s2) {
   pool.put12(b, s1).putShort(s2);
 }
Beispiel #8
0
 public void visit(final String name, final Object value) {
   ++size;
   if (named) {
     bv.putShort(cw.newUTF8(name));
   }
   if (value instanceof String) {
     bv.put12('s', cw.newUTF8((String) value));
   } else if (value instanceof Byte) {
     bv.put12('B', cw.newInteger(((Byte) value).byteValue()).index);
   } else if (value instanceof Boolean) {
     int v = ((Boolean) value).booleanValue() ? 1 : 0;
     bv.put12('Z', cw.newInteger(v).index);
   } else if (value instanceof Character) {
     bv.put12('C', cw.newInteger(((Character) value).charValue()).index);
   } else if (value instanceof Short) {
     bv.put12('S', cw.newInteger(((Short) value).shortValue()).index);
   } else if (value instanceof Type) {
     bv.put12('c', cw.newUTF8(((Type) value).getDescriptor()));
   } else if (value instanceof byte[]) {
     byte[] v = (byte[]) value;
     bv.put12('[', v.length);
     for (int i = 0; i < v.length; i++) {
       bv.put12('B', cw.newInteger(v[i]).index);
     }
   } else if (value instanceof boolean[]) {
     boolean[] v = (boolean[]) value;
     bv.put12('[', v.length);
     for (int i = 0; i < v.length; i++) {
       bv.put12('Z', cw.newInteger(v[i] ? 1 : 0).index);
     }
   } else if (value instanceof short[]) {
     short[] v = (short[]) value;
     bv.put12('[', v.length);
     for (int i = 0; i < v.length; i++) {
       bv.put12('S', cw.newInteger(v[i]).index);
     }
   } else if (value instanceof char[]) {
     char[] v = (char[]) value;
     bv.put12('[', v.length);
     for (int i = 0; i < v.length; i++) {
       bv.put12('C', cw.newInteger(v[i]).index);
     }
   } else if (value instanceof int[]) {
     int[] v = (int[]) value;
     bv.put12('[', v.length);
     for (int i = 0; i < v.length; i++) {
       bv.put12('I', cw.newInteger(v[i]).index);
     }
   } else if (value instanceof long[]) {
     long[] v = (long[]) value;
     bv.put12('[', v.length);
     for (int i = 0; i < v.length; i++) {
       bv.put12('J', cw.newLong(v[i]).index);
     }
   } else if (value instanceof float[]) {
     float[] v = (float[]) value;
     bv.put12('[', v.length);
     for (int i = 0; i < v.length; i++) {
       bv.put12('F', cw.newFloat(v[i]).index);
     }
   } else if (value instanceof double[]) {
     double[] v = (double[]) value;
     bv.put12('[', v.length);
     for (int i = 0; i < v.length; i++) {
       bv.put12('D', cw.newDouble(v[i]).index);
     }
   } else {
     Item i = cw.newConstItem(value);
     bv.put12(".s.IFJDCS".charAt(i.type), i.index);
   }
 }