boolean isStatic = psiField.hasModifierProperty(PsiModifier.STATIC);
if (isStatic) {
method.withModifier(PsiModifier.STATIC);
}
PsiParameter methodParameter = method.getParameterList().getParameters()[0];
PsiModifierList methodParameterModifierList = methodParameter.getModifierList();
if (null != methodParameterModifierList) {
final Collection<String> annotationsToCopy = PsiAnnotationUtil.collectAnnotationsToCopy(psiField,
LombokUtils.NON_NULL_PATTERN, LombokUtils.NULLABLE_PATTERN);
for (String annotationFQN : annotationsToCopy) {
methodParameterModifierList.addAnnotation(annotationFQN);
}
}
final String thisOrClass = isStatic ? psiClass.getName() : "this";
String blockText = String.format("%s.%s = %s;", thisOrClass, psiField.getName(), methodParameter.getName());
if (!isStatic && !PsiType.VOID.equals(returnType)) {
blockText += "return this;";
}
method.withBody(PsiMethodUtil.createCodeBlockFromText(blockText, psiClass));