格式化后无法在 Eclipse 中删除块注释

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4598002/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 15:35:31  来源:igfitidea点击:

Cannot remove block comment in Eclipse after formatting

eclipseformatting

提问by AniDev

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.

Eclipse 的自动格式化程序会更改块注释,因此 Source > Remove Block Comment 不会完全删除块注释。Source > Add Block Comment 将时钟注释的开始和结束添加到代码行,但在运行 Formatter (Ctrl + Shift + F) 后,它会包装代码行并在每行的开头添加一个星号。当我尝试使用 Source > Remove Block Comment 删除块注释时,块注释的开头和结尾被删除,但每行开头的星号不会被删除。

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

如何防止 Eclipse 添加这些星号,或者在删除块注释的开头和结尾时删除星号?

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);

采纳答案by Mehdi

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.

然后取消选中启用块注释格式

回答by CoderCroc

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

另一种替代解决方案是在 eclipse 中使用块选择模式,它足够快并且仍然保持其他注释的格式。您只需按几个键即可删除评论。

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

在窗口中,您可以切换块选择模式ALT+ SHIFT+ A。查看屏幕截图了解更多信息。

Steps to follow,

要遵循的步骤,

  • Press ALT+ SHIFT+ Ato toggle Block Selection Mode
  • Select vertical section of comment
  • Press Deleteor Backspace
  • Press ALT+ SHIFT+ Aagain to disable Block Selection Mode
  • Save the file and you have uncommented the code finally!
  • ALT+ SHIFT+A切换块选择模式
  • 选择评论的垂直部分
  • DeleteBackspace
  • 再次按ALT+ SHIFT+A禁用块选择模式
  • 保存文件,您终于取消了代码注释!

enter image description here

在此处输入图片说明

回答by spadequack

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.

我之前遇到过这个问题,我的解决方案就是使用 Eclipse 生成的行注释 (//) 而不是块注释。选择代码,然后按 Ctrl-/ 或 Ctrl-7 切换 // 为选定的每一行。格式化后,这些行将像文本一样缩进和格式化,但如果删除注释(Ctrl-/ 或 Ctrl-7)并重新格式化,一切正常。

回答by Chetsan

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

使用 Ctrl + \(反斜杠)删除 /* --- --- --- */

回答by SaratBhaswanth

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.

使用 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 CheckAgain!!!

现在再次检查!!!