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

发布于 2024-10-10 05:04:57 字数 841 浏览 6 评论 0原文

Eclipse 的自动格式化程序会更改块注释,以便 Source >删除块注释并不能完全删除块注释。来源>>添加块注释将时钟注释的开头和结尾添加到代码行中,但在运行格式化程序 (Ctrl + Shift + F) 后,它会将代码行换行并在每行的开头添加一个星号。当我尝试使用 Source > 删除块注释时删除块注释,块注释的开头和结尾被删除,但每行开头的星号不被删除。

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

示例:

这样的代码:

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

添加块注释后变成这样:

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

应用格式后变成这样:

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

使用删除块注释功能后变成这样:

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

花海 2024-10-17 05:04:57

这可能有点晚了,但我通过禁用块注释格式解决了这个问题。

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

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

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.

坐在坟头思考人生 2024-10-17 05:04:57

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

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

步骤如下,

  • ALT + SHIFT + A 切换块选择模式
  • 选择注释的垂直部分按
  • < kbd>删除或退格
  • 再次按ALT + SHIFT + A禁用阻止选择模式
  • 保存文件,您终于取消了代码注释!

输入图像描述这里

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

誰認得朕 2024-10-17 05:04:57

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

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.

给我一枪 2024-10-17 05:04:57

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

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

信仰 2024-10-17 05:04:57

我不知道这是否有助于解决您的问题,但我发现这对我的情况非常有帮助。考虑此文本 -

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

使用 CTRL + SHIFT + F 应用块注释后。

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

只需在 /* 之后添加 - 即可从格式中排除此块 -

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

现在检查 再来一次!!!

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!!!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文