2016-02-04 62 views
4

我在一类设置一些注释,并在同一行注解注释,如:如何阻止Eclipse在注释之后移动我的行注释?

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

但是,每次我格式化文件时,我同行注释最终被移到下一行。这不仅是不可取的,因为它提出了我的评论,但更糟糕的是,它将评论置于一个令人困惑的地方。上述示例变为:

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

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

+0

不要在第一时间写评论。重点是让方法/注释名称更具可读性。 – adarshr

回答

0

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

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

确保您有关闭/打开Eclipse中启用标签:

  1. 在主菜单中,访问WindowsPreferences
  2. - 手侧,访问JavaCode StyleFormatter
  3. 右侧-手边,点击编辑Java → Code Style → Formatter → Edit
  4. 在出现的对话框,点击最右边的选项卡Off/On Tags
  5. 确保Enable Off/On tags检查Off/On Tags → Enable Off/On tags
    • 如果您使用的是内置的配置文件,你必须在Profile name领域的对话框顶部更改名称。
  6. Click OK。当对话框关闭时,再次单击确定以完成应用设置。
+0

希望有更好的答案会出现... –