From: chibash Date: Thu, 20 Nov 2014 13:57:52 +0000 (+0900) Subject: fixed JASSIST-208 X-Git-Tag: rel_3_19_0_ga~9 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=07c2e6440fcd9136e9dfcae08497edefe66a9bc9;p=javassist.git fixed JASSIST-208 --- diff --git a/Readme.html b/Readme.html index 354af82a..35ffa495 100644 --- a/Readme.html +++ b/Readme.html @@ -283,7 +283,7 @@ see javassist.Dump.

-version 3.19

diff --git a/src/main/javassist/bytecode/ClassFileWriter.java b/src/main/javassist/bytecode/ClassFileWriter.java index 38a9c5d6..a6c8bfb0 100644 --- a/src/main/javassist/bytecode/ClassFileWriter.java +++ b/src/main/javassist/bytecode/ClassFileWriter.java @@ -145,7 +145,7 @@ public class ClassFileWriter { output.writeShort(fields.size()); fields.write(output); - output.writeShort(methods.size()); + output.writeShort(methods.numOfMethods()); methods.write(output); } catch (IOException e) {} @@ -190,7 +190,7 @@ public class ClassFileWriter { out.writeShort(fields.size()); fields.write(out); - out.writeShort(methods.size()); + out.writeShort(methods.numOfMethods()); methods.write(out); if (aw == null) out.writeShort(0); @@ -503,7 +503,14 @@ public class ClassFileWriter { 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(); } diff --git a/src/test/javassist/JvstTest4.java b/src/test/javassist/JvstTest4.java index 13784fd7..2a60af8b 100644 --- a/src/test/javassist/JvstTest4.java +++ b/src/test/javassist/JvstTest4.java @@ -181,15 +181,19 @@ public class JvstTest4 extends JvstTestRoot { 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); @@ -1065,6 +1069,7 @@ public class JvstTest4 extends JvstTestRoot { 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();