在IntelliJ 2018中是否有一种方法可以自动生成检查任何参数传递的空值的代码行?
我希望IntelliJ更改这个:
// ----------| Constructor |-----------------------------------
public DailyProduct ( LocalDate localDate , String name , Integer quantity ) {
this.localDate = localDate;
this.name = name;
this.quantity = quantity;
}
…变成这样:
// ----------| Constructor |-----------------------------------
public DailyProduct ( LocalDate localDate , String name , Integer quantity , BigDecimal quality , BigDecimal realmq , BigDecimal cost ) {
Objects.requireNonNull( localDate ); // ⬅ Generate these checks for null values.
Objects.requireNonNull( name );
Objects.requireNonNull( quantity );
this.localDate = localDate;
this.name = name;
this.quantity = quantity;
}
更好的情况是,如果IntelliJ可以编写所有参数到成员分配,并使用Objects.requireNonNull。所以这样:
// ----------| Constructor |-----------------------------------
public DailyProduct ( LocalDate localDate , String name , Integer quantity , BigDecimal quality , BigDecimal realmq , BigDecimal cost ) {
}
…会变成这样:
// ----------| Constructor |-----------------------------------
public DailyProduct ( LocalDate localDate , String name , Integer quantity ) {
this.localDate = Objects.requireNonNull( localDate ); // ⬅ Generate all these lines entirely.
this.name = Objects.requireNonNull( name );
this.quantity = Objects.requireNonNull( quantity );
}
this.localDate = Objects.requireNonNull(localDate);
- Andy Turner