private void addImport(@NotNull PsiReference ref, @NotNull PsiClass targetClass) {
    DumbService.getInstance(myProject).withAlternativeResolveEnabled(() -> {
      if (!ref.getElement().isValid() || !targetClass.isValid()) {
        return;
      }

      StatisticsManager.getInstance().incUseCount(JavaStatisticsManager.createInfo(null, targetClass));
      WriteCommandAction.runWriteCommandAction(myProject, QuickFixBundle.message("add.import"), null,
                                               () -> doAddImport(ref, targetClass),
                                               ref.getElement().getContainingFile());
    });
  }
private void addImport(@NotNull PsiReference ref, @NotNull PsiClass targetClass)