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
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Source (show other bugs)
Version: 6.x
Hardware: All All
: P2 blocker (vote)
Assignee: Pavel Flaska
URL:
Keywords:
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:


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

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 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
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/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