Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making Eclipse's Java code formatter ignore block comments

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

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.

like image 523
Pops Avatar asked Jun 21 '09 22:06

Pops


People also ask

How do I hide comments in Java?

Enabling 'Folding' in the preferences dialog lets you use the '+' and '-' buttons next to the line numbers to hide comments.

How do I format a block of code in Eclipse?

Highlight (left click, drag, left release) the lines you want to format, and press Ctrl + Shift + F , or right click and select Source -> Format . For Java code, you have to highlight a complete piece of code (statement(s), method).


1 Answers

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

like image 51
Michelle Crane Avatar answered Jan 05 '23 11:01

Michelle Crane