This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
If I use the following piece of code to replace method body, it replaces only the last statement in some cases String bodyText = "{System.out.println(\"Hello World!\");}"; MethodTree meth = ...; //Assigned to old method tree MethodTree newMeth = wc.getTreeMaker().Method(meth.getModifiers(), meth.getName (), meth.getReturnType(), meth.getTypeParameters(), meth.getParameters(), meth.getThrows(), bodyText, (ExpressionTree)meth.getDefaultValue()); wc.rewrite(meth, newMeth); It seems to work fine if the body has no or one statement.
Created attachment 37897 [details] Test module to reproduce the bug
Install the attached module and follow these steps to reproduce the bug 1) Open the file TestClass.java which is part of the project 2) Select Refactor|Replace Method Body You will notice that the body of replace() is not replaced completely
I got exception when tried to reproduce.
This is caused by block matching. Original body is matched against a new one. In this case, the new should be printed from scratch. (Of course, matching should also work, but it is too complex and redundant in such case.)
Checking in src/org/netbeans/modules/java/source/save/CasualDiff.java; /cvs/java/source/src/org/netbeans/modules/java/source/save/CasualDiff.java,v <-- CasualDiff.java new revision: 1.64; previous revision: 1.63 done Checking in test/unit/src/org/netbeans/api/java/source/gen/MethodBodyTextTest.java; /cvs/java/source/test/unit/src/org/netbeans/api/java/source/gen/MethodBodyTextTest.java,v <-- MethodBodyTextTest.java new revision: 1.7; previous revision: 1.6 done