Пример #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));
 }
Пример #2
0
 /**
  * Constructs a new {@link FieldWriter}.
  *
  * @param cw the class writer to which this field must be added.
  * @param access the field's access flags (see {@link Opcodes}).
  * @param name the field's name.
  * @param desc the field's descriptor (see {@link Type}).
  * @param signature the field's signature. May be <tt>null</tt>.
  * @param value the field's constant value. May be <tt>null</tt>.
  */
 FieldWriter(
     final ClassWriter cw,
     final int access,
     final String name,
     final String desc,
     final String signature,
     final Object value) {
   super(Opcodes.ASM4);
   if (cw.firstField == null) {
     cw.firstField = this;
   } else {
     cw.lastField.fv = this;
   }
   cw.lastField = this;
   this.cw = cw;
   this.access = access;
   this.name = cw.newUTF8(name);
   this.desc = cw.newUTF8(desc);
   if (ClassReader.SIGNATURES && signature != null) {
     this.signature = cw.newUTF8(signature);
   }
   if (value != null) {
     this.value = cw.newConstItem(value).index;
   }
 }
Пример #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);
 }
Пример #4
0
 /**
  * Returns the size of this field.
  *
  * @return the size of this field.
  */
 int getSize() {
   int size = 8;
   if (value != 0) {
     cw.newUTF8("ConstantValue");
     size += 8;
   }
   if ((access & Opcodes.ACC_SYNTHETIC) != 0 && (cw.version & 0xffff) < Opcodes.V1_5) {
     cw.newUTF8("Synthetic");
     size += 6;
   }
   if ((access & Opcodes.ACC_DEPRECATED) != 0) {
     cw.newUTF8("Deprecated");
     size += 6;
   }
   if (cw.version == Opcodes.V1_4 && (access & Opcodes.ACC_ENUM) != 0) {
     cw.newUTF8("Enum");
     size += 6;
   }
   if (signature != 0) {
     cw.newUTF8("Signature");
     size += 8;
   }
   if (anns != null) {
     cw.newUTF8("RuntimeVisibleAnnotations");
     size += 8 + anns.getSize();
   }
   if (ianns != null) {
     cw.newUTF8("RuntimeInvisibleAnnotations");
     size += 8 + ianns.getSize();
   }
   if (attrs != null) {
     size += attrs.getSize(cw, null, 0, -1, -1);
   }
   return size;
 }
Пример #5
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);
 }
Пример #6
0
 /**
  * Puts the content of this field into the given byte vector.
  *
  * @param out where the content of this field must be put.
  */
 void put(final ByteVector out) {
   out.putShort(access).putShort(name).putShort(desc);
   int attributeCount = 0;
   if (value != 0) {
     ++attributeCount;
   }
   if ((access & Opcodes.ACC_SYNTHETIC) != 0 && (cw.version & 0xffff) < Opcodes.V1_5) {
     ++attributeCount;
   }
   if ((access & Opcodes.ACC_DEPRECATED) != 0) {
     ++attributeCount;
   }
   if (cw.version == Opcodes.V1_4 && (access & Opcodes.ACC_ENUM) != 0) {
     ++attributeCount;
   }
   if (signature != 0) {
     ++attributeCount;
   }
   if (anns != null) {
     ++attributeCount;
   }
   if (ianns != null) {
     ++attributeCount;
   }
   if (attrs != null) {
     attributeCount += attrs.getCount();
   }
   out.putShort(attributeCount);
   if (value != 0) {
     out.putShort(cw.newUTF8("ConstantValue"));
     out.putInt(2).putShort(value);
   }
   if ((access & Opcodes.ACC_SYNTHETIC) != 0 && (cw.version & 0xffff) < Opcodes.V1_5) {
     out.putShort(cw.newUTF8("Synthetic")).putInt(0);
   }
   if ((access & Opcodes.ACC_DEPRECATED) != 0) {
     out.putShort(cw.newUTF8("Deprecated")).putInt(0);
   }
   if (cw.version == Opcodes.V1_4 && (access & Opcodes.ACC_ENUM) != 0) {
     out.putShort(cw.newUTF8("Enum")).putInt(0);
   }
   if (signature != 0) {
     out.putShort(cw.newUTF8("Signature"));
     out.putInt(2).putShort(signature);
   }
   if (anns != null) {
     out.putShort(cw.newUTF8("RuntimeVisibleAnnotations"));
     anns.put(out);
   }
   if (ianns != null) {
     out.putShort(cw.newUTF8("RuntimeInvisibleAnnotations"));
     ianns.put(out);
   }
   if (attrs != null) {
     attrs.put(cw, null, 0, -1, -1, out);
   }
 }
Пример #7
0
 /**
  * Returns the size of this field.
  *
  * @return the size of this field.
  */
 int getSize() {
   int size = 8;
   if (value != 0) {
     cw.newUTF8("ConstantValue");
     size += 8;
   }
   if ((access & Opcodes.ACC_SYNTHETIC) != 0) {
     if ((cw.version & 0xFFFF) < Opcodes.V1_5
         || (access & ClassWriter.ACC_SYNTHETIC_ATTRIBUTE) != 0) {
       cw.newUTF8("Synthetic");
       size += 6;
     }
   }
   if ((access & Opcodes.ACC_DEPRECATED) != 0) {
     cw.newUTF8("Deprecated");
     size += 6;
   }
   if (ClassReader.SIGNATURES && signature != 0) {
     cw.newUTF8("Signature");
     size += 8;
   }
   if (ClassReader.ANNOTATIONS && anns != null) {
     cw.newUTF8("RuntimeVisibleAnnotations");
     size += 8 + anns.getSize();
   }
   if (ClassReader.ANNOTATIONS && ianns != null) {
     cw.newUTF8("RuntimeInvisibleAnnotations");
     size += 8 + ianns.getSize();
   }
   if (attrs != null) {
     size += attrs.getSize(cw, null, 0, -1, -1);
   }
   return size;
 }
Пример #8
0
 /**
  * Puts the content of this field into the given byte vector.
  *
  * @param out where the content of this field must be put.
  */
 void put(final ByteVector out) {
   int mask =
       Opcodes.ACC_DEPRECATED
           | ClassWriter.ACC_SYNTHETIC_ATTRIBUTE
           | ((access & ClassWriter.ACC_SYNTHETIC_ATTRIBUTE)
               / (ClassWriter.ACC_SYNTHETIC_ATTRIBUTE / Opcodes.ACC_SYNTHETIC));
   out.putShort(access & ~mask).putShort(name).putShort(desc);
   int attributeCount = 0;
   if (value != 0) {
     ++attributeCount;
   }
   if ((access & Opcodes.ACC_SYNTHETIC) != 0
       && ((cw.version & 0xFFFF) < Opcodes.V1_5
           || (access & ClassWriter.ACC_SYNTHETIC_ATTRIBUTE) != 0)) {
     ++attributeCount;
   }
   if ((access & Opcodes.ACC_DEPRECATED) != 0) {
     ++attributeCount;
   }
   if (ClassReader.SIGNATURES && signature != 0) {
     ++attributeCount;
   }
   if (ClassReader.ANNOTATIONS && anns != null) {
     ++attributeCount;
   }
   if (ClassReader.ANNOTATIONS && ianns != null) {
     ++attributeCount;
   }
   if (attrs != null) {
     attributeCount += attrs.getCount();
   }
   out.putShort(attributeCount);
   if (value != 0) {
     out.putShort(cw.newUTF8("ConstantValue"));
     out.putInt(2).putShort(value);
   }
   if ((access & Opcodes.ACC_SYNTHETIC) != 0
       && ((cw.version & 0xFFFF) < Opcodes.V1_5
           || (access & ClassWriter.ACC_SYNTHETIC_ATTRIBUTE) != 0)) {
     out.putShort(cw.newUTF8("Synthetic")).putInt(0);
   }
   if ((access & Opcodes.ACC_DEPRECATED) != 0) {
     out.putShort(cw.newUTF8("Deprecated")).putInt(0);
   }
   if (ClassReader.SIGNATURES && signature != 0) {
     out.putShort(cw.newUTF8("Signature"));
     out.putInt(2).putShort(signature);
   }
   if (ClassReader.ANNOTATIONS && anns != null) {
     out.putShort(cw.newUTF8("RuntimeVisibleAnnotations"));
     anns.put(out);
   }
   if (ClassReader.ANNOTATIONS && ianns != null) {
     out.putShort(cw.newUTF8("RuntimeInvisibleAnnotations"));
     ianns.put(out);
   }
   if (attrs != null) {
     attrs.put(cw, null, 0, -1, -1, out);
   }
 }
Пример #9
0
 public AnnotationVisitor visitAnnotation(final String desc, final boolean visible) {
   ByteVector bv = new ByteVector();
   // write type, and reserve space for values count
   bv.putShort(cw.newUTF8(desc)).putShort(0);
   AnnotationWriter aw = new AnnotationWriter(cw, true, bv, bv, 2);
   if (visible) {
     aw.next = anns;
     anns = aw;
   } else {
     aw.next = ianns;
     ianns = aw;
   }
   return aw;
 }
Пример #10
0
 /**
  * Constructs a new {@link FieldWriter}.
  *
  * @param cw the class writer to which this field must be added.
  * @param access the field's access flags (see {@link Opcodes}).
  * @param name the field's name.
  * @param desc the field's descriptor (see {@link Type}).
  * @param signature the field's signature. May be <tt>null</tt>.
  * @param value the field's constant value. May be <tt>null</tt>.
  */
 protected FieldWriter(
     final ClassWriter cw,
     final int access,
     final String name,
     final String desc,
     final String signature,
     final Object value) {
   if (cw.firstField == null) {
     cw.firstField = this;
   } else {
     cw.lastField.next = this;
   }
   cw.lastField = this;
   this.cw = cw;
   this.access = access;
   this.name = cw.newUTF8(name);
   this.desc = cw.newUTF8(desc);
   if (signature != null) {
     this.signature = cw.newUTF8(signature);
   }
   if (value != null) {
     this.value = cw.newConstItem(value).index;
   }
 }
Пример #11
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);
   }
 }