Reputation: 131547
I have (Java) comments such as:
/*
* The quick brown fox jumped over the lazy dog.
*
*
* Notes:
* - The quick brown fox jumped over the lazy dog. The quick brown fox
* jumped over the lazy dog. The quick brown fox jumped over the lazy
* dog.
* - The second quick brown fox jumped over the lazy dog. The quick brown
* jumped over the lazy dog. The quick brown fox jumped over the lazy
* dog.
*/
The Eclipse auto-formatter sets the comment line width properly, but makes it:
/*
* The quick brown fox jumped over the lazy dog.
*
*
* Notes: - The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy
* dog. The quick brown fox jumped over the lazy dog. - The second quick brown fox jumped over the
* lazy dog. The quick brown jumped over the lazy dog. The quick brown fox jumped over the lazy dog.
*/
How do I the code formatter to leave the bulleted lists as-is, while still otherwise processing the comment?
Notes:
Upvotes: 30
Views: 21433
Reputation: 1114
I know the question is old but, I can also see nobody gave a satisfactory answer.
This resolved my issue.
Go to Preference->Java->Code Style->Formatter
. Here, go to Edit of whatever Formatter style you are using. In the Edit Dialog you will find a checkbox Enable Block Comment Formatting. Uncheck this. Change Profile name as I have done. Apply and OK. You are done.
Please refer to this below Image.
Hope this Helps.
Upvotes: 12
Reputation: 121
Specifically, you want to set:
org.eclipse.jdt.core.formatter.comment.format_block_comments=false
This is accessible somewhere in Eclipse settings, for VS Code, inside the root of the project you need a .settings directory, with a "org.eclipse.jdt.core.prefs" file that contains that line. This file would contain all your Eclipse settings that VS code leverages. This setting would apply similarly for other editors that use the Eclipse settings.
Upvotes: 1
Reputation: 2038
How about:
/**
* The quick brown fox jumped over the lazy dog.
*
* <p>Notes:
* <li>The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog.</li>
* <li>The second quick brown fox jumped over the lazy dog. The quick brown jumped over the lazy dog. The quick brown fox jumped over the lazy dog.</li>
*/
And then turn of "Format HTML tags" in Windows -> Preferences -> Java -> Code Style -> Formatter -> Edit... -> Comments
This still does the line width line breaking.
EDIT:
I used the following block-comment:
/*
* The quick brown fox jumped over the lazy dog.
*
* Notes:
* - The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog.
* - The second quick brown fox jumped over the lazy dog. The quick brown jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog.
*/
I'm using Eclipse Neon.3 for Java EE and my Formatter cor comments is set to a width of 150 and "Never join lines" selected. Formatting this block comment gives me the following result which I think is what you might want (Though I know that you don't want to "never join lines").
/*
* The quick brown fox jumped over the lazy dog.
*
* Notes:
* - The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The
* quick brown fox jumped over the lazy dog.
* - The second quick brown fox jumped over the lazy dog. The quick brown jumped over the lazy dog. The quick brown fox jumped over the lazy dog.
* The quick brown fox jumped over the lazy dog.
*/
There is just 1 small problem. When I add some more text to the first bulleted list and then formatting again I get the following result.
/*
* The quick brown fox jumped over the lazy dog.
*
* Notes:
* - The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The
* SOME MORE TEXT TO WRAP
* quick brown fox jumped over the lazy dog.
* - The second quick brown fox jumped over the lazy dog. The quick brown jumped over the lazy dog. The quick brown fox jumped over the lazy dog.
* The quick brown fox jumped over the lazy dog.
*/
That is because I told the formatter "not to join lines". When I unselect "Never join lines" I apparently get the same result as you have.
Upvotes: 0
Reputation: 682
Picking up what Bananeweizen said, you could also wrap the relevant comment block with <pre></pre>
tags, keeping every tab and space in it's place:
/*
* The quick brown fox jumped over the lazy dog.
*
*
*<pre>Notes:
* - The quick brown fox jumped over the lazy dog. The quick brown fox
* jumped over the lazy dog. The quick brown fox jumped over the lazy
* dog.
* - The second quick brown fox jumped over the lazy dog. The quick brown
* jumped over the lazy dog. The quick brown fox jumped over the lazy
* dog.</pre>
*/
Upvotes: 6
Reputation: 15109
This answer says that you add a hypen right after the opening /*
, i.e.:
/*-
* The quick brown fox jumped over the lazy dog.
*
*
* Notes:
* - The quick brown fox jumped over the lazy dog. The quick brown fox
* jumped over the lazy dog. The quick brown fox jumped over the lazy
* dog.
* - The second quick brown fox jumped over the lazy dog. The quick brown
* jumped over the lazy dog. The quick brown fox jumped over the lazy
* dog.
*/
This worked for me too.
Upvotes: 44
Reputation: 22070
In Java there are 2 different kinds of comments:
<br>
or <p>
)
used in the comment.In JavaDoc your example could be written like below (and would be formatted as shown):
/**
* The quick brown fox jumped over the lazy dog.
*
* <p>
* Notes:
* <ul>
* <li>The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown
* fox jumped over the lazy dog.</li>
* <li>The second quick brown fox jumped over the lazy dog. The quick brown jumped over the lazy dog. The quick
* brown fox jumped over the lazy dog.</li>
* </ul>
* </p>
*/
Upvotes: 2
Reputation: 13858
The answer to your question is probably the same as here: How to turn off the Eclipse code formatter for certain sections of Java code?
Since Eclipse 3.6 you can use the
// @formatter:off
...
// @formatter:on
annotations to disable code formatting.
Update:
Alternatively, you could also change the comment settings in the Preferences: in Java/Code Style/Formatter edit the formatter settings, and check the Comments page for the following settings:
Btw, this kind of manual list does not translate into a list in the generated code. It might make sense to use a html list for this reason.
Upvotes: 16
Reputation: 10646
You can make changes to how Eclipse formats comments and have special handling for block comments.
Got to Window -> preferences. Java > Code style > Formatter. Click on "New" to create a new template. Then under the tab "Comments" disable block comment formatting.
This will however never perform any formatting on block comments.
Upvotes: 6