Is there a way to make Eclipse\'s built-in Java code formatter ignore comments? Whenever I run it, it turns this:
/*
* PSEUDOCODE
* Read in us
Update 2010, as pointed by the OP and in this answer, the special string // @formatter:off
in Eclipse 3.6 is enough.
It was not available at the time of the question.
Original answer: June 2009, Eclipse 3.4/3.5
With the Java Formatter (Windows > Preferences > Java > Code Style > Formatter
), you can create a new Formatter profile.
In the Comments tab (in eclipse3.5), you can make sure, in the "Javadoc comment settings
", to uncheck "Format HTML tags
".
Check also the "Never join lines
" in the "General settings
" section.
Then your comment should be written as:
/**
* PSEUDOCODE
* Read in user's string/paragraph
*
* Three cases are possible:
* <dl>
* <dt>Case 1: foobar</dt>
* <dd> do case 1 things</dd>
* <dt>Case 2: fred hacker</dt>
* <dd> do case 2 things</dd>
* <dt>Case 3: cowboyneal</dt>
* <dd> do case 3 things</dd>
* </dl>
* In all cases, do some other thing
*/
Note: I have made a Javadoc comment, and not a simple comment, as I believe a comment with that much text in it may be better placed in front of a method. Plus, Javadoc sections have more formatting parameters to play with.
If it is in front of a method (true Javadoc), the HTML tags <dl>, <dt> and <dd> will help to present it properly within the Javadoc view.
In Eclipse 3.4: Preferences, Java->Code Style->Formatter, then edit profile, comments tab. There's a bunch of options there for controlling comment formatting.
Surround the specific text with <pre> </pre>
tags.
one workaround is to add pre tag for the comments that you don't want eclipse to format
/**
* <pre>
* this part
* is
* out of
* format
*
* </pre>
*/
If you want to supress formatting in eclipse, you can always wrap content that is intended to NOT TO BE FORMATED into <pre>UNFORMATTED CONTENT</pre>
tag. Javadoc formatter will detect that tag, and leave everything between that tags unformatted.
Pros:
Cons:
Try this one. This worked for me. With the Java Formatter (Windows > Preferences > Java > Code Style > Formatter), you can create a new Formatter profile from existing and then edit it.
If Eclipse doesn't allow to save this then create a new one and save in that.