private static PsiElement replaceFieldWithGetter(PsiElement expr, PsiField psiField) throws IncorrectOperationException {
    if (RefactoringUtil.isAssignmentLHS(expr)) {
      // todo: warning
      return expr;
    }
    PsiElement newExpr = expr;

    PsiMethod getter = GroovyPropertyUtils.findGetterForField(psiField);

    if (getter != null) {
      if (JavaPsiFacade.getInstance(psiField.getProject()).getResolveHelper().isAccessible(getter, newExpr, null)) {

        GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(newExpr.getProject());
        String id = getter.getName();
        final PsiElement parent = newExpr.getParent();
        String qualifier = null;
        if (parent instanceof GrReferenceExpression) {
          final GrExpression qualifierExpression = ((GrReferenceExpression)parent).getQualifierExpression();
          if (qualifierExpression != null) {
            qualifier = qualifierExpression.getText();
          }
        }
        GrExpression getterCall;
        if (PsiTreeUtil.isAncestor(psiField.getContainingClass(), expr, true)) {
          getterCall = factory.createExpressionFromText((qualifier != null ? qualifier + "." : "") + id + "()");
        }
        else {
          getterCall = factory.createExpressionFromText((qualifier != null ? qualifier + "." : "") + psiField.getName());
        }
        if (parent != null) {
          newExpr = parent.replace(getterCall);
        }
        else {
          newExpr = expr.replace(getterCall);
        }
      }
      else {
        // todo: warning
      }
    }

    return newExpr;
  }
private static PsiElement replaceFieldWithGetter(PsiElement expr, PsiField psiField)