@Override
  protected boolean isClassMaybeImportedAlready(@NotNull PsiFile containingFile, @NotNull PsiClass classToImport) {
    if (containingFile instanceof PsiJavaFile) {
      PsiImportList importList = ((PsiJavaFile)containingFile).getImportList();
      if (importList == null) return false;
      boolean result = false;
      String classQualifiedName = classToImport.getQualifiedName();
      String packageName = classQualifiedName == null ? "" : StringUtil.getPackageName(classQualifiedName);
      for (PsiImportStatementBase statement : importList.getAllImportStatements()) {
        PsiJavaCodeReferenceElement importRef = statement.getImportReference();
        if (importRef == null) continue;
        String canonicalText = importRef.getCanonicalText(); // rely on the optimization: no resolve while getting import statement canonical text

        if (statement.isOnDemand()) {
          if (canonicalText.equals(packageName)) {
            result = true;
            break;
          }
        }
        else {
          if (canonicalText.equals(classQualifiedName)) {
            result = true;
            break;
          }
        }
      }
      return result;
    }
    if (containingFile instanceof JavaCodeFragment) {
      String classQualifiedName = classToImport.getQualifiedName();
      return classQualifiedName != null && ((JavaCodeFragment)containingFile).importsToString().contains(classQualifiedName);
    }
    return false;
  }
@Override
  protected boolean isClassMaybeImportedAlready(@NotNull PsiFile containingFile, @NotNull PsiClass classToImport)