Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot remove block comment in Eclipse after formatting

Eclipse's automatic formatter changes block comments such that the Source > Remove Block Comment does not completely remove the block comment. Source > Add Block Comment adds the start and end of the clock comment to the lines of code, but after running the Formatter (Ctrl + Shift + F), it wraps the lines of code and adds an asterisk to the start of each line. When I try to remove the block comment with Source > Remove Block Comment, the start and end of the block comment is removed, but the asterisks at the beginning of each line is not removed.

How do I prevent Eclipse from adding these asterisks, or remove the asterisks when it removes the start and end of the block comment?

Example:

Code like this:

    String abc="abc";     String def="def";     System.out.println(abc+def);     System.exit(0); 

Becomes like this after adding block comments:

/*  String abc="abc";     String def="def";     System.out.println(abc+def); */  System.exit(0); 

Which becomes like this after applying formatting:

    /*      * String abc="abc"; String def="def"; System.out.println(abc+def);      */System.exit(0); 

Which ends up like this after using the Remove Block Comment function:

    * String abc="abc"; String def="def"; System.out.println(abc+def);     System.exit(0); 
like image 269
AniDev Avatar asked Jan 04 '11 20:01

AniDev


People also ask

How do I remove a block comment?

Comment and uncomment blocks of codePress Ctrl+Shift+/ .

How do I hide comments in Eclipse?

Enabling 'Folding' in the preferences dialog lets you use the '+' and '-' buttons next to the line numbers to hide comments. Do do this... Then the comments will go away!


2 Answers

This may be a little late in the game, but I fixed this by disabling block comment formatting.

Windows -> Preferences -> Java -> Code Style -> Formatter -> Edit -> Comments 

Then uncheck Enable block comment formatting.

like image 187
Mehdi Avatar answered Oct 14 '22 22:10

Mehdi


One other alternative solution is use of Block Selection Mode in eclipse, which is quite fast enough and still keeps your other comments formatted. You just have to press few keys to remove comments.

In windows you can toggle Block Selection Mode by ALT + SHIFT + A. Checkout the screenshot for more.

Steps to follow,

  • Press ALT + SHIFT + A to toggle Block Selection Mode
  • Select vertical section of comment
  • Press Delete or Backspace
  • Press ALT + SHIFT + A again to disable Block Selection Mode
  • Save the file and you have uncommented the code finally!

enter image description here

like image 29
akash Avatar answered Oct 14 '22 20:10

akash