开发者

Cannot remove block comment in Eclipse after formatting

开发者 https://www.devze.com 2023-02-02 17:37 出处:网络
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

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开发者_StackOverflow中文版 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);


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.


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!

Cannot remove block comment in Eclipse after formatting


I've run into this problem before and my solution is just to use line comments (//) generated by Eclipse instead of block comments. Select code, and then hit Ctrl-/ or Ctrl-7 to toggle // for every line selected. After formatting, those lines will get indented and formatted like text, but if you remove the comments (Ctrl-/ or Ctrl-7) and reformat, everything works fine.


Use Ctrl + \ (Back Slash) to remove /* --- --- --- */


I dont know if this helps solve your problem, but I found this very much helpful in my case. Consider this text -

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

After applying a block comment using CTRL + SHIFT + F.

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

Just add - after /* to exclude this block from formatting -

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

Now Check Again!!!

0

精彩评论

暂无评论...
验证码 换一张
取 消