public static PsiElement replaceOccurenceWithFieldRef(PsiExpression occurrence, PsiField newField, PsiClass destinationClass)
    throws IncorrectOperationException {
    final PsiManager manager = destinationClass.getManager();
    final String fieldName = newField.getName();
    final JavaPsiFacade facade = JavaPsiFacade.getInstance(manager.getProject());
    final PsiElement element = occurrence.getUserData(ElementToWorkOn.PARENT);
    final PsiVariable psiVariable =
      facade.getResolveHelper().resolveAccessibleReferencedVariable(fieldName, element != null ? element : occurrence);
    final PsiElementFactory factory = facade.getElementFactory();
    if (psiVariable != null && psiVariable.equals(newField)) {
      return IntroduceVariableUtil.replace(occurrence, factory.createExpressionFromText(fieldName, null), manager.getProject());
    }
    else {
      final PsiReferenceExpression ref = (PsiReferenceExpression)factory.createExpressionFromText("this." + fieldName, null);
      if (!occurrence.isValid()) return null;
      if (newField.hasModifierProperty(PsiModifier.STATIC)) {
        if (destinationClass instanceof PsiImplicitClass) {
          //If it is an implicit class, it is impossible to use class reference as qualifier.
          //So if it is possible, keep it as unqualified.
          //Otherwise, if there are variables with the same name, let's use `this`, even though it is not a good practise
          JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(manager.getProject());
          String name = codeStyleManager.suggestUniqueVariableName(newField.getName(), occurrence, true);
          if (newField.getName().equals(name)) {
            ref.setQualifierExpression(null);
          }
        }
        else {
          ref.setQualifierExpression(factory.createReferenceExpression(destinationClass));
        }
      }
      return IntroduceVariableUtil.replace(occurrence, ref, manager.getProject());
    }
  }
public static PsiElement replaceOccurenceWithFieldRef(PsiExpression occurrence, PsiField newField, PsiClass destinationClass)