簡體   English   中英

IntelliJ 為選定的字段/方法創建內部 class

[英]IntelliJ create inner class for selected fields/methods

我有一個大的 class 包含很多定義。 有沒有辦法使用 IntelliJs 內置功能移動/創建/提取結構?

所以我可以保留對這些字段的引用,而不必為所有用法添加限定符?

當前是案例:

public static class Tables {

    public final static String METADATA_CREATE_TS = "create_ts";
    public final static String TABLE_1_ID;
    public final static String TABLE_1_NAME;
    public final static String TABLE_1_INTERNAL_ID;
    public final static String TABLE_1_CUSTOMER_ID;
    .
    .
    .
    public final static String TABLE_N_ID;
}

它應該是什么樣子:

public static class Tables {

    public final static String METADATA_CREATE_TS = "create_ts";
    public static class Table1 { 
        public final static String TABLE_1_ID;
        public final static String TABLE_1_NAME;
        public final static String TABLE_1_INTERNAL_ID;
        public final static String TABLE_1_CUSTOMER_ID;
    }
}
  1. 創建內部 class。
  2. Go 到 class 表 --> 右鍵單擊 --> 移動成員
  3. 標記要移動的字段。
  4. 在要寫入內部 class 名稱(...Tables.Table1)
  5. 點擊重構移動成員

這可以通過一些技巧來實現。

您可以在 IntelliJ 中使用 F6 將一組字段移動到新的 class。 After you created the new class you can than select all of the newly created classes and press F6 again to make all of those classes an inner class of a different class, which solved my overall goal.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM