示例#1
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;
 }
 /**
  * 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;
 }
示例#3
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);
   }
 }
示例#4
0
 /**
  * Puts the given annotation lists into the given byte vector.
  *
  * @param panns an array of annotation writer lists.
  * @param out where the annotations must be put.
  */
 static void put(final AnnotationWriter[] panns, final ByteVector out) {
   int size = 1 + 2 * panns.length;
   for (int i = 0; i < panns.length; ++i) {
     size += panns[i] == null ? 0 : panns[i].getSize();
   }
   out.putInt(size).putByte(panns.length);
   for (int i = 0; i < panns.length; ++i) {
     AnnotationWriter aw = panns[i];
     AnnotationWriter last = null;
     int n = 0;
     while (aw != null) {
       ++n;
       aw.visitEnd(); // in case user forgot to call visitEnd
       aw.prev = last;
       last = aw;
       aw = aw.next;
     }
     out.putShort(n);
     aw = last;
     while (aw != null) {
       out.putByteArray(aw.bv.data, 0, aw.bv.length);
       aw = aw.prev;
     }
   }
 }
示例#5
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);
   }
 }
示例#6
0
 public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
   ByteVector bv = new ByteVector();
   // write type, and reserve space for values count
   bv.putShort(newUTF8(desc)).putShort(0);
   AnnotationWriter aw = new AnnotationWriter(this, true, bv, bv, 2);
   if (visible) {
     aw.next = anns;
     anns = aw;
   } else {
     aw.next = ianns;
     ianns = aw;
   }
   return aw;
 }
示例#7
0
 public AnnotationVisitor visitAnnotation(final String desc, final boolean visible) {
   if (!ClassReader.ANNOTATIONS) {
     return null;
   }
   ByteVector bv = new ByteVector();
   // write type, and reserve space for values count
   bv.putShort(newUTF8(desc)).putShort(0);
   AnnotationWriter aw = new AnnotationWriter(this, true, bv, bv, 2);
   if (visible) {
     aw.next = anns;
     anns = aw;
   } else {
     aw.next = ianns;
     ianns = aw;
   }
   return aw;
 }
示例#8
0
 /**
  * Puts the annotations of this annotation writer list into the given byte vector.
  *
  * @param out where the annotations must be put.
  */
 void put(final ByteVector out) {
   int n = 0;
   int size = 2;
   AnnotationWriter aw = this;
   AnnotationWriter last = null;
   while (aw != null) {
     ++n;
     size += aw.bv.length;
     aw.visitEnd(); // in case user forgot to call visitEnd
     aw.prev = last;
     last = aw;
     aw = aw.next;
   }
   out.putInt(size);
   out.putShort(n);
   aw = last;
   while (aw != null) {
     out.putByteArray(aw.bv.data, 0, aw.bv.length);
     aw = aw.prev;
   }
 }
示例#9
0
 /**
  * Returns the bytecode of the class that was build with this class writer.
  *
  * @return the bytecode of the class that was build with this class writer.
  */
 public byte[] toByteArray() {
   // computes the real size of the bytecode of this class
   int size = 24 + 2 * interfaceCount;
   int nbFields = 0;
   FieldWriter fb = firstField;
   while (fb != null) {
     ++nbFields;
     size += fb.getSize();
     fb = fb.next;
   }
   int nbMethods = 0;
   MethodWriter mb = firstMethod;
   while (mb != null) {
     ++nbMethods;
     size += mb.getSize();
     mb = mb.next;
   }
   int attributeCount = 0;
   if (signature != 0) {
     ++attributeCount;
     size += 8;
     newUTF8("Signature");
   }
   if (sourceFile != 0) {
     ++attributeCount;
     size += 8;
     newUTF8("SourceFile");
   }
   if (sourceDebug != null) {
     ++attributeCount;
     size += sourceDebug.length + 4;
     newUTF8("SourceDebugExtension");
   }
   if (enclosingMethodOwner != 0) {
     ++attributeCount;
     size += 10;
     newUTF8("EnclosingMethod");
   }
   if ((access & Opcodes.ACC_DEPRECATED) != 0) {
     ++attributeCount;
     size += 6;
     newUTF8("Deprecated");
   }
   if ((access & Opcodes.ACC_SYNTHETIC) != 0 && (version & 0xffff) < Opcodes.V1_5) {
     ++attributeCount;
     size += 6;
     newUTF8("Synthetic");
   }
   if (innerClasses != null) {
     ++attributeCount;
     size += 8 + innerClasses.length;
     newUTF8("InnerClasses");
   }
   if (anns != null) {
     ++attributeCount;
     size += 8 + anns.getSize();
     newUTF8("RuntimeVisibleAnnotations");
   }
   if (ianns != null) {
     ++attributeCount;
     size += 8 + ianns.getSize();
     newUTF8("RuntimeInvisibleAnnotations");
   }
   if (attrs != null) {
     attributeCount += attrs.getCount();
     size += attrs.getSize(this, null, 0, -1, -1);
   }
   size += pool.length;
   // allocates a byte vector of this size, in order to avoid unnecessary
   // arraycopy operations in the ByteVector.enlarge() method
   ByteVector out = new ByteVector(size);
   out.putInt(0xCAFEBABE).putInt(version);
   out.putShort(index).putByteArray(pool.data, 0, pool.length);
   out.putShort(access).putShort(name).putShort(superName);
   out.putShort(interfaceCount);
   for (int i = 0; i < interfaceCount; ++i) {
     out.putShort(interfaces[i]);
   }
   out.putShort(nbFields);
   fb = firstField;
   while (fb != null) {
     fb.put(out);
     fb = fb.next;
   }
   out.putShort(nbMethods);
   mb = firstMethod;
   while (mb != null) {
     mb.put(out);
     mb = mb.next;
   }
   out.putShort(attributeCount);
   if (signature != 0) {
     out.putShort(newUTF8("Signature")).putInt(2).putShort(signature);
   }
   if (sourceFile != 0) {
     out.putShort(newUTF8("SourceFile")).putInt(2).putShort(sourceFile);
   }
   if (sourceDebug != null) {
     int len = sourceDebug.length - 2;
     out.putShort(newUTF8("SourceDebugExtension")).putInt(len);
     out.putByteArray(sourceDebug.data, 2, len);
   }
   if (enclosingMethodOwner != 0) {
     out.putShort(newUTF8("EnclosingMethod")).putInt(4);
     out.putShort(enclosingMethodOwner).putShort(enclosingMethod);
   }
   if ((access & Opcodes.ACC_DEPRECATED) != 0) {
     out.putShort(newUTF8("Deprecated")).putInt(0);
   }
   if ((access & Opcodes.ACC_SYNTHETIC) != 0 && (version & 0xffff) < Opcodes.V1_5) {
     out.putShort(newUTF8("Synthetic")).putInt(0);
   }
   if (innerClasses != null) {
     out.putShort(newUTF8("InnerClasses"));
     out.putInt(innerClasses.length + 2).putShort(innerClassesCount);
     out.putByteArray(innerClasses.data, 0, innerClasses.length);
   }
   if (anns != null) {
     out.putShort(newUTF8("RuntimeVisibleAnnotations"));
     anns.put(out);
   }
   if (ianns != null) {
     out.putShort(newUTF8("RuntimeInvisibleAnnotations"));
     ianns.put(out);
   }
   if (attrs != null) {
     attrs.put(this, null, 0, -1, -1, out);
   }
   if (invalidFrames) {
     ClassWriter cw = new ClassWriter(COMPUTE_FRAMES);
     new ClassReader(out.data).accept(cw, ClassReader.SKIP_FRAMES);
     return cw.toByteArray();
   }
   return out.data;
 }