成员变量前的换行符(如果有注释)



使用IntelliJ IDEA,是否有一种方法可以将Java代码样式配置为在带注释的成员变量(但不是未带注释的会员变量(之前添加换行符。或者,如果任何成员变量都被注释(并且在注释之前有换行符(,那么所有的成员变量之前都可能有换行符。

例如。。。

// current / default -- hard to interpret at a glance
class Blah {
private int id;
@Required
@Length(max = 100)
private String firstName;
@Required
@Length(max = 100)
private String lastName;
private Instant birthDate;
private String favoriteColor;
}
// option 1: spaces before/after annotated members
class Blah {
private int id;
@Required
@Length(max = 100)
private String firstName;
@Required
@Length(max = 100)
private String lastName;
private Instant birthDate;
private String favoriteColor;
}
// option 2: spaces before all members / annotated members if any is annotated
class Blah {
private int id;
@Required
@Length(max = 100)
private String firstName;
@Required
@Length(max = 100)
private String lastName;
private Instant birthDate;
private String favoriteColor;
}
class BlahWithoutAnnotations {
private int id;
private String firstName;
private String lastName;
private Instant birthDate;
private String favoriteColor;
}

因此,正在寻找一种方法来配置代码样式以格式化选项1或2之类的内容。优选为2。

您可以进入Settings > Editor > Code Style > Java,在空白行选项卡中的Minimum Blank Lines部分中找到标记为Around field:的选项,并将其值更改为1。这将为您提供选项2;我不确定如何获得您的选项1,但我希望这会有所帮助。

相关内容

最新更新