2016-02-04 38 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

希望有更好的答案會出現... –