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.
Enabling 'Folding' in the preferences dialog lets you use the '+' and '-' buttons next to the line numbers to hide comments.
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).
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With