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

Bug 235534

Summary: BodyDeclaration.modifiers().remove() leads to removing a comment.
Product: [Eclipse Project] JDT Reporter: kiril mitov <thebravoman>
Component: CoreAssignee: David Audel <david_audel>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: frederic_fusier, philippe_mulet
Version: 3.3.2   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
URL: CSN 1738926 2008
Whiteboard: stalebug
Attachments:
Description Flags
Test case for the problem none

Description kiril mitov CLA 2008-06-04 02:40:31 EDT
Created attachment 103512 [details]
Test case for the problem

Hi,
This problem was found in our eclipse base product. We have actions for automatically managing annotations of a different j2ee artifacts. We are using AST to add/remove annotations from the type.

I have noticed that if the class looks like this:

//some comment
@SomeAnnotation
public class MyClass {}

And I try to remove the annotation using

List modifiers = bodyDeclaration.modifiers();
Annotation annotation = findAnnotation(bodyDeclaration);
modifiers.remove(annotation);
TextEdit edit = unit.rewrite(doc, null);
edit.apply(doc);

Then the result will be

public class MyClass{}

and it should be 

//some comment 
public class MyClass()

The shown code is also removing the comment. The returned from unit.rewrite() method TextEdit is containing a DeleteEdit for deleting the comment. 

I am attaching a test case that is doing exactly this.

It is creating a java project. Then a working copy in the java project. Then it is finding the annotation and is trying to remove this annotation.

I have captured the logic for removing the annotation in ComplexAnnotation class.
I have tried to make the test case as simple as possible. The test case is:

final String content = "//@ApplicationException(rollback=false)\r\n"
			+ "@ApplicationException(rollback=false)\r\n"
			+ "public class SessionBean1{}";
IType type = getWorkingCopyType("SessionBean1.java", content);
new ComplexAnnotation().removeFromMember(type, type.getElementName());
assertEquals(		removeWhitespaces("//@ApplicationException(rollback=false)\r\n"
		+ "public class SessionBean1{}"),
removeWhitespaces(type.getSource()));


Best Regards,
Kiril
Comment 1 kiril mitov CLA 2008-11-27 03:15:00 EST
Hi, 

After an internal discussion we have decided that the behavior might be correct, but we can not decide on this.

A comment is removed. 
If the comment is for the annotation than removing it is NOT a defect. 
If the comment is for the type than removing it is A defect.

If removing this comment is an intended behavior of JDT we can threat this as not a bug. 

Could you review this and give a comment if this is working as designed?

 
Comment 2 Eclipse Genie CLA 2020-04-25 17:01:44 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.