Bug 214284 - ISourceRange or IMethod save is wrong
Summary: ISourceRange or IMethod save is wrong
Status: VERIFIED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3.1   Edit
Hardware: PC Windows Vista
: P3 critical (vote)
Target Milestone: 3.4 M5   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-01-03 17:49 EST by Bruno Braga CLA
Modified: 2008-02-06 01:32 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Bruno Braga CLA 2008-01-03 17:49:18 EST
Build ID: M20070921-1145

Steps To Reproduce:
1. Add comment (javadoc) any method
2. Change this method (IMethod) using ISourceRange 
3. Javadoc is deleted :/


More information:
I'm using this code (see below) to change a method in a class.
It works perfectly.
But if before the method I put any comment (javadoc) it is deleted :/ 

------------
IBuffer buffer = imethod.getOpenable().getBuffer();
ISourceRange sourceRange = imethod.getSourceRange(); 

StringBuffer sourceMethod = new StringBuffer();
//sourceMethod = new method source

buffer.replace(sourceRange.getOffset(), sourceRange.getLength(), sourceMethod.toString());
imethod.getOpenable().save(null, true);
------------

In debug IMethod source does not have the javadoc comment (correct), but at the time of saving it's deleted and certainly would change only the source of the method, not the comment.
Comment 1 Frederic Fusier CLA 2008-01-05 07:24:13 EST
The javadoc comment is a part of the IMember when the element was got from source (see IMember#getJavadocRange()). So, if you replace the entire method source, then you have to include the new javadoc comment in it. If you do not want to change it then get it from the existing method first and add it at the beginning of the new source method before.

So, close as INVALID.
Comment 2 Bruno Braga CLA 2008-01-05 21:56:57 EST
hmmmm, ok.

Sorry for the issue. I didn't know if it was a bug or if works differently. I asked in 2 places and nobody answered. Then I had to open an issue to make sure that it was not a bug :)

http://www.eclipse.org/newsportal/article.php?id=22009&group=eclipse.tools.jdt#22009
http://www.eclipsezone.com/eclipse/forums/t105082.html

Thanks a lot!


Comment 3 Maxime Daniel CLA 2008-02-04 07:45:25 EST
Beyond the fact that the documentation of IMember#getJavadocRange could certainly bear some polishing (since it returns a range, why would we extract a javadoc from attached sources?), I don't quite see where it explains the relationships of the javadoc range to the source range (which according to comment #1 should, at least it case of source files, be an inclusion of the former into the latter). Hence if the behavior is the intended one, I would suggest that it be made more immediately understandable from the API.
Comment 4 Maxime Daniel CLA 2008-02-05 09:18:54 EST
Discussed with Frédéric and Jérôme and we agreed to open a fup bug to take care of documentation improvements. The behavior described in this bug is the expected one, hence:

Verified for 3.4M5 using I20080204-0010 build.
Comment 5 Bruno Braga CLA 2008-02-05 16:01:47 EST
hmmmm... good :)
Comment 6 Maxime Daniel CLA 2008-02-06 01:32:22 EST
(In reply to comment #4)
> Discussed with Frédéric and Jérôme and we agreed to open a fup bug to take care
> of documentation improvements.
This is bug 217837.