Avoid creating itself if the value set is equal

This commit is contained in:
Andrea Cavalli 2022-02-24 02:24:24 +01:00
parent 2c9e69dba2
commit a45f1908f1

View File

@ -2733,6 +2733,14 @@ public class SourcesGenerator {
setterMethod.returns(classType);
if (!fieldType.isPrimitive()) {
setterMethod.addStatement("$T.requireNonNull(" + fieldName + ")", Objects.class);
setterMethod.beginControlFlow("if ($T.equals(" + fieldName + ", this." + fieldName + "))", Objects.class);
setterMethod.addStatement("return this");
setterMethod.endControlFlow();
} else {
setterMethod.beginControlFlow("if (" + fieldName + " == this." + fieldName + ")");
setterMethod.addStatement("return this");
setterMethod.endControlFlow();
}
setterMethod.addCode("$[return $T.of(\n$]", classType);
setterMethod.addCode("$>");