<p>-version 3.19
<ul>
-<li>JIRA JASSIST-158, 205, 206, 207, 211, 212, 216, 220, 223, 224, 227, 230, 234, 235.
+<li>JIRA JASSIST-158, 205, 206, 207, 211, 212, 216, 220, 223, 224, 227, 230, 234, 235, 236.
</ul>
</p>
output.writeShort(fields.size());
fields.write(output);
- output.writeShort(methods.size());
+ output.writeShort(methods.numOfMethods());
methods.write(output);
}
catch (IOException e) {}
out.writeShort(fields.size());
fields.write(out);
- out.writeShort(methods.size());
+ out.writeShort(methods.numOfMethods());
methods.write(out);
if (aw == null)
out.writeShort(0);
output.writeInt(startPos + 2, output.getPos() - startPos - 6);
}
- int size() { return methodCount; }
+ /**
+ * Returns the length of the bytecode that has been added so far.
+ *
+ * @return the length in bytes.
+ */
+ public int size() { return output.getPos() - startPos - 14; }
+
+ int numOfMethods() { return methodCount; }
int dataSize() { return output.size(); }
ClassFileWriter.MethodWriter mw = cfw.getMethodWriter();
mw.begin(AccessFlag.PUBLIC, MethodInfo.nameInit, "()V", null, null);
+ assertEquals(0, mw.size());
mw.add(Opcode.ALOAD_0);
+ assertEquals(1, mw.size());
mw.addInvoke(Opcode.INVOKESPECIAL, "java/lang/Object", MethodInfo.nameInit, "()V");
mw.add(Opcode.RETURN);
mw.codeEnd(1, 1);
mw.end(null, null);
mw.begin(AccessFlag.PUBLIC, "move", "(II)V", null, null);
+ assertEquals(0, mw.size());
mw.add(Opcode.ALOAD_0);
mw.addInvoke(Opcode.INVOKEVIRTUAL, "java/lang/Object", "toString", "()Ljava/lang/String;");
+ assertEquals(4, mw.size());
mw.add(Opcode.POP);
mw.add(Opcode.RETURN);
mw.add(Opcode.POP);
AnnotationsAttribute attr
= new AnnotationsAttribute(cp, AnnotationsAttribute.visibleTag);
Annotation a = new Annotation(anno.getName(), cp);
+ a.addMemberValue("value", new javassist.bytecode.annotation.StringMemberValue("file/path", cp));
attr.setAnnotation(a);
m.getMethodInfo().addAttribute(attr);
cc.writeFile();