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.

Bug 93730 - Replacing method body using TreeMaker API doesn't work in many cases
Summary: Replacing method body using TreeMaker API doesn't work in many cases
Alias: None
Product: java
Classification: Unclassified
Component: Source (show other bugs)
Version: 6.x
Hardware: All All
: P2 blocker (vote)
Assignee: Pavel Flaska
Depends on:
Blocks: 90451
  Show dependency tree
Reported: 2007-01-31 21:44 UTC by _ deva
Modified: 2007-02-20 14:06 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:

Test module to reproduce the bug (10.43 KB, application/x-compressed)
2007-01-31 21:45 UTC, _ deva

Note You need to log in before you can comment on or make changes to this bug.
Description _ deva 2007-01-31 21:44:14 UTC
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.
Comment 1 _ deva 2007-01-31 21:45:26 UTC
Created attachment 37897 [details]
Test module to reproduce the bug
Comment 2 _ deva 2007-01-31 21:50:10 UTC
Install the attached module and follow these steps to reproduce the bug
1) Open the file which is part of the project
2) Select Refactor|Replace Method Body

You will notice that the body of replace() is not replaced completely
Comment 3 Pavel Flaska 2007-02-20 09:10:40 UTC
I got exception when tried to reproduce.
Comment 4 Pavel Flaska 2007-02-20 09:34:44 UTC
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.)
Comment 5 Pavel Flaska 2007-02-20 14:06:43 UTC
Checking in src/org/netbeans/modules/java/source/save/;
new revision: 1.64; previous revision: 1.63
Checking in test/unit/src/org/netbeans/api/java/source/gen/;
new revision: 1.7; previous revision: 1.6