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

Bug 497599

Summary: Custom CodeFormatter and snippet javadoc formatting
Product: [Eclipse Project] JDT Reporter: Liam Miller-Cushon <cushon>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3    
Version: 4.6   
Target Milestone: ---   
Hardware: Macintosh   
OS: Mac OS X   
Whiteboard: stalebug
Attachments:
Description Flags
A CodeFormatter plugin that demonstrates the issue none

Description Liam Miller-Cushon CLA 2016-07-09 01:36:14 EDT
Created attachment 262997 [details]
A CodeFormatter plugin that demonstrates the issue

The CodeFormatter extension point doesn't support making non-whitespace changes to javadoc when formatting snippets.

For example, when the `Generate Constructor using Fields...` refactoring is run with generated javadoc enabled, it formats a snippet like:

```
/**
 */public Hello(int x){super();this.x=x;}
```

And then rewrites the leading "/**\n */" to include the appropriate `@param` tags as a second step.

If a custom CodeFormatter changes the leading "/**\n */", e.g. to:

```
/**
 *
 */
```

Then the location of the leading comment is lost, and the generated javadoc defaults to being inserted at the end of the snippet.

Is this a bug? I expected the snippet formatting logic to tolerate non-whitespace changes inside javadoc.

Demo:

The attached zip file contains a CodeFormatter implementation that does nothing but rewrite leading "/**\n */" comments.

* extract codeformatterdemo.zip and open the project
* run it as an Eclipse Application
* create a Java project, and add a simple class:

```
public class Hello {
int x;
}
```

* enable the custom formatter: Java > Code Style > Formatter > Formatter implementation > Demo Java Formatter
* select the class name and run: Source > Generate Constructor using Fields...
* check `Generate constructor comments`

```
public class Hello {
/**
 *
 */public Hello(int x){super();this.x=x;}/**
 * @param x
 */

int x;
}
```
Comment 1 Eclipse Genie CLA 2019-10-31 15:36:27 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.

If you have further information on the current state of the bug, please add it. 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.