private PsiExpression calculateQualifier(PsiReferenceExpression parent) {
    if (parent instanceof PsiMethodReferenceExpression) {
      return createThisExpression();
    }
    if (parent.getParent() instanceof PsiMethodCallExpression methodCall) {
      final PsiMethodCallExpression copy = (PsiMethodCallExpression)methodCall.copy();
      final PsiExpression qualifier = copy.getMethodExpression().getQualifierExpression();
      if (qualifier != null) {
        qualifier.delete();
        JavaResolveResult resolveResult = copy.resolveMethodGenerics();
        if (methodCall.resolveMethod() == resolveResult.getElement() || !resolveResult.isValidResult()) {
          return null;
        }
        return createQualifiedThisExpression();
      }
    }
    else if (parent.resolve() instanceof PsiField field) {
      final PsiReferenceExpression copy = (PsiReferenceExpression)parent.copy();
      PsiExpression qualifier = copy.getQualifierExpression();
      if (qualifier != null) {
        qualifier.delete();
        PsiElement target = copy.resolve();
        if (target == field || target == null) {
          return null;
        }
        return target instanceof PsiField ? createQualifiedThisExpression() : createThisExpression();
      }
    }
    return null;
  }
private PsiExpression calculateQualifier(PsiReferenceExpression parent)