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.isSimplePropertyGetter(method) || method.hasModifierProperty(PsiModifier.ABSTRACT)) { 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.getGetterName(field))) .findAny(); } else if (body.getStatementCount() == 1) { return Optional.of(body.getStatements()[0]) .filter(PsiReturnStatement.class::isInstance) .map(PsiReturnStatement.class::cast) .map(PsiReturnStatement::getReturnValue) .map(PsiUtil::deparenthesizeExpression) .filter(PsiReferenceExpression.class::isInstance) .map(PsiReferenceExpression.class::cast) .map(PsiReferenceExpression::resolve) .filter(PsiField.class::isInstance) .map(PsiField.class::cast); } return Optional.empty(); }