简体   繁体   English

IntelliJ 为选定的字段/方法创建内部 class

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

I have a big class containing a lot of definitions.我有一个大的 class 包含很多定义。 Is there a way to move/create/extract a structure using IntelliJs build in features?有没有办法使用 IntelliJs 内置功能移动/创建/提取结构?

So i can keep the references to those fields without having to add qualifiers for all usages?所以我可以保留对这些字段的引用,而不必为所有用法添加限定符?

Current is case:当前是案例:

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

How it should look like:它应该是什么样子:

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. Create the inner class.创建内部 class。
  2. Go to class Tables --> right click --> move members Go 到 class 表 --> 右键单击 --> 移动成员
  3. Mark the fields that you want to move.标记要移动的字段。
  4. In To write the inner class name (...Tables.Table1)在要写入内部 class 名称(...Tables.Table1)
  5. Click Refactor点击重构移动成员

This is doable with a little bit of trickery.这可以通过一些技巧来实现。

You can use F6 in IntelliJ to move a set number of fields to a new class.您可以在 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. 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