Optional<PsiField> (@NotNull PsiMethod method) { // it seems wrong to replace abstract possible getters // abstract methods maybe the part of interface so let them live if (!PropertyUtilBase.isSimplePropertySetter(method) || method.hasModifierProperty(PsiModifier.ABSTRACT)) { return Optional.empty(); } // check the parameter list // it should have 1 parameter with the same type if (Optional.of(method.getParameterList()) .filter(paramList -> paramList.getParametersCount() == 1) .map(paramList -> paramList.getParameter(0)) .map(PsiParameter::getType) .filter(expectedType -> Optional.ofNullable(method.getContainingClass()) .map(PsiClassUtil::collectClassFieldsIntern) .orElse(Collections.emptyList()) .stream() .filter(field -> method.getName().equals(LombokUtils.getSetterName(field))) .noneMatch(field -> expectedType.equals(field.getType())) ).isPresent()) { return Optional.empty(); } PsiCodeBlock body = method.getBody(); if (body == null) { return Optional.ofNullable(method.getContainingClass()) .map(PsiClassUtil::collectClassFieldsIntern) .orElse(Collections.emptyList()) .stream() .filter(field -> method.getName().equals(LombokUtils.getSetterName(field))) .findAny(); } else if (body.getStatementCount() == 1) { // validate that the method body doesn't contain anything additional // and also contain proper assign statement Optional<PsiAssignmentExpression> assignmentExpression = Optional.of(body.getStatements()[0]) .filter(PsiExpressionStatement.class::isInstance) .map(PsiExpressionStatement.class::cast) .map(PsiExpressionStatement::getExpression) .filter(PsiAssignmentExpression.class::isInstance) .map(PsiAssignmentExpression.class::cast); if (assignmentExpression.map(PsiAssignmentExpression::getRExpression) .filter(PsiReferenceExpression.class::isInstance).map(PsiReferenceExpression.class::cast) .map(PsiReferenceExpression::resolve).filter(PsiParameter.class::isInstance).isPresent()) { return assignmentExpression.map(PsiAssignmentExpression::getLExpression) .filter(PsiReferenceExpression.class::isInstance).map(PsiReferenceExpression.class::cast) .map(PsiReferenceExpression::resolve).filter(PsiField.class::isInstance) .map(PsiField.class::cast); } } return Optional.empty(); }