Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 123557

Summary: ASTRewrite.remove deletes too much.
Product: [Eclipse Project] JDT Reporter: Ajay Patil <apatil>
Component: CoreAssignee: Martin Aeschlimann <martinae>
Status: CLOSED WONTFIX QA Contact:
Severity: major    
Priority: P3    
Version: 3.1.1   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Ajay Patil CLA 2006-01-12 01:34:47 EST
Hello,

I encountered this bug, when using the ASTRewrite.remove method 
to remove a fieldDeclaration.

astRewrite.remove(fieldDeclaration, null);

The original source file is as follows:
************** ORIGINAL_SOURCE *******************************
// Some_preceeding_line_comment
/**
 * ...
 */
 int i;
***************ORGINAL_SOURCE *******************************

The remove method removes not only the field declaration (and javadoc)
but also the preceeding line comment.

My understanding is that only the field declaration (and its javadoc)
should be deleted.

I have classified this bug as major, because comments are important
to the end-user and the unintended deletion of comments through a plug-in is
undesirable.

Regards,
Ajay
Comment 1 Martin Aeschlimann CLA 2006-01-12 04:39:22 EST
The AST rewriter uses a heuristic to map comments to nodes. All comments directly preceeding a node (without an empty line) are mapped to the node.

As an ASTrewiter client you have the possibility to override the mapping using a TargetSourceRangeComputer.
Comment 2 Ajay Patil CLA 2006-01-12 21:46:45 EST
Thank you for the quick reply.

I could resolve the problem by overwriding the TargetSourceRangeComputer
in ASTRewrite. In fact, this is very well documented in the Javadoc for
ASTRewrite.

So, I am sorry to have reported this as a bug.

Regards,
Ajay