Might there be a way in IntelliJ 2018 to auto-generate the lines of code checking for null values passed in any argument?
I want IntelliJ to change this:
// ----------| Constructor |-----------------------------------
public DailyProduct ( LocalDate localDate , String name , Integer quantity ) {
this.localDate = localDate;
this.name = name;
this.quantity = quantity;
}
…to this:
// ----------| 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;
}
Even better would be if IntelliJ could write all the argument-to-member assignments and use the Objects.requireNonNull
. So this:
// ----------| Constructor |-----------------------------------
public DailyProduct ( LocalDate localDate , String name , Integer quantity , BigDecimal quality , BigDecimal realmq , BigDecimal cost ) {
}
…would become this:
// ----------| 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);
? – Concentration