score:41

Accepted answer

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.

score:0

it is language-dependent.

for example, if working with javascript, you would go to "window -> preferences -> javascript -> code style -> formatter" and then edit the formatter options.

edit (reflecting changesin op questions

for editing java code formatting, go to "window -> preferences -> java -> code style -> formatter"

at the top of the panel you will see

active profile:
eclipse [built-in]

from there you have one button to the right, "edit", and two below, "new..." and "import...". i would recommend editing the existing profile.

in the edit profile dialog, there are a series of tabs along the top. the last tab is "comments". to completely disable comment formatting, uncheck "enable javadoc comment formatting", "enable block comment formatting", "enable line comment formatting", and "enable header comment formatting".

score:0

you can change this in windows - preferences - java - code style - formatter, than click the edit.. button, find comments, choose the never join lines.

then, it should be ok.

score:1

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:

  • rest of javadoc is still formatted
  • javadoc's html output will be "unformatted" as well because of pre tags

cons:

  • not seeing one

score:1

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. enter image description here

score:2

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.

score:2

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>
 */

score:9

surround the specific text with <pre> </pre> tags.

score:20

another possibility is to use html's <pre> in javadoc:

/**
 * <pre>
 *    this
 *   is
 *      kept
 *  as
 *    is
 * </pre>
 */

at least this is how i tend to embed my ascii-art in source code comments :)

score:27

i just learned from a co-worker that eclipse offers special formatting tags that can be used for this:

// @formatter:off
/*
 * ╔════════╦═══════╦══════════╗
 * ║ month  ║ sales ║ position ║
 * ╠════════╬═══════╬══════════╣
 * ║ june   ║ 44k   ║ 2nd      ║
 * ║ july   ║ 39k   ║ 2nd      ║
 * ║ august ║ 49k   ║ 4th      ║
 * ╚════════╩═══════╩══════════╝
 *
 * this comment shouldn't be formatted, and will now be ignored by the formatter.
 */
// @formatter:on

note that you may need to manually enable this feature through the preferences menu → java > code style > formatter, clicking on edit, selecting the off/on tags tab and checking enable off/on tags (source).

a quick google for the string @formatter:off brought me to this other so answer, which mentioned this feature in the context of disabling the formatter for code blocks. i've confirmed that it works for line comments, "normal" block comments and javadoc block comments as well.

score:193

there is another solution that you can use to suppress the formatting of specific block comments. use /*- (note the hyphen) at the beginning of the block comment, and the formatting won't be affected if you format the rest of the file.

/*-
 * here is a block comment with some very special
 * formatting that i want indent(1) to ignore.
 *
 *    one
 *        two
 *            three
 */

source: http://www.oracle.com/technetwork/java/javase/documentation/codeconventions-141999.html#350


Related Query

More Query from same tag