views:

1153

answers:

4

Is there a way to make Eclipse's built-in formatter ignore comments? Whenever I run it, it turns this:

    /*
     * PSEUDOCODE
     * Read in user's string/paragraph
     * 
     * Three cases are possible
     * Case 1: foobar
     *         do case 1 things
     * Case 2: fred hacker
     *         do case 2 things
     * Case 3: cowboyneal
     *         do case 3 things
     *         
     * In all cases, do some other thing
     */

into this:

    /*
     * PSEUDOCODE Read in user's string/paragraph
     * 
     * Three cases are possible Case 1: foobar do case 1 things Case 2: fred
     * hacker do case 2 things Case 3: cowboyneal do case 3 things
     * 
     * In all cases, do some other thing
     */

EDIT: I'm asking about Java. I have already played around with the Windows > Preferences > Java > Code Style > Formatter settings but can't find one for keeping comment formatting. I'm using Eclipse 3.4.0.

A: 

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".

Jonathan Fingland
+1  A: 

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.

skaffman
+2  A: 

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>
 * <df>Case 1: foobar</df>
 * <dd>        do case 1 things</dd>
 * <df>Case 2: fred hacker</df>
 * <dd>        do case 2 things</dd>
 * <df>Case 3: cowboyneal</df>
 * <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>, <df> and <dd> will help to present it properly within the Javadoc view.

VonC
The relevant part of this answer, for me, was that the HTML tags are NOT automatically inserted at line breaks and the like. Probably obvious to most, but I didn't realize I had to hand-code things like <br>s until I saw it here.
Lord Torgamus
@Lord Torgamus: not only you have to add thosetags, but the first sentence requires a periode and a space, before the `<br />`! (see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4165985)
VonC
+1  A: 

Or you can surround the specific text with < pre> < /pre> tags

Philip