【问题标题】:How do I stop Eclipse from moving my line comments after annotations?如何阻止 Eclipse 在注释后移动我的行注释?
【发布时间】:2016-05-14 11:45:40
【问题描述】:

我在一个类上设置了一些注解,cmet和注解在同一行,如:

@SampleAnnotation // sample comment
@AnotherAnnotation // another comment
public class SampleClass { }

但是,每次我格式化文件时,我的同一行注释都会被移到下一行。这不仅是不可取的,因为它移动了我的评论,而且更糟糕的是,它把评论放在了一个令人困惑的地方。上面的示例变为:

@SampleAnnotation
// sample comment
@AnotherAnnotation
// another comment
public class SampleClass { }

如何阻止 Eclipse 在格式化后移动这些 cmets?或者,我如何让 Eclipse 将 cmets 移动到上面的行,而不是下面的行?谢谢。

【问题讨论】:

  • 一开始就不要写cmets。相反,专注于使方法/注释名称的名称更具可读性。

标签: java eclipse formatter


【解决方案1】:

到目前为止,最好的解决方案是通知 Eclipse 关闭此类块的格式化程序。也就是说,原来的代码会变成:

// @formatter:off
@SampleAnnotation // sample comment
@AnotherAnnotation // another comment
// @formatter:on
public class SampleClass { }

确保您在 Eclipse 中启用了关闭/开启标签:

  1. 在主菜单中,访问WindowsPreferences
  2. 左侧手边,访问JavaCode StyleFormatter
  3. 右侧-手边,单击编辑
  4. 在出现的对话框中,点击最右侧的标签Off/On Tags
  5. 确保Enable Off/On tags选中
    • 如果您使用的是内置配置文件,则必须更改对话框顶部 Profile name 字段中的名称。
  6. 单击确定。对话框关闭后,再次单击 OK 以完成应用设置。

【讨论】:

    猜你喜欢
    • 2016-01-01
    • 2020-09-04
    • 2020-02-06
    • 2022-10-24
    • 2015-10-18
    • 2016-08-22
    • 1970-01-01
    • 2011-01-01
    • 2014-03-27
    相关资源
    最近更新 更多