@Nullable
  @Override
  public PsiPackage resolvePackage(
      @NotNull PsiPackageManager packageManager,
      @NotNull VirtualFile virtualFile,
      @NotNull Class<? extends ModuleExtension> extensionClass,
      String qualifiedName) {
    ProjectFileIndex fileIndexFacade =
        ProjectFileIndex.SERVICE.getInstance(packageManager.getProject());
    PsiManager psiManager = PsiManager.getInstance(packageManager.getProject());
    if (fileIndexFacade.isInLibraryClasses(virtualFile)) {

      List<OrderEntry> orderEntriesForFile = fileIndexFacade.getOrderEntriesForFile(virtualFile);
      for (OrderEntry orderEntry : orderEntriesForFile) {
        Module ownerModule = orderEntry.getOwnerModule();
        ModuleExtension extension = ModuleUtilCore.getExtension(ownerModule, extensionClass);
        if (extension != null) {
          for (PsiPackageSupportProvider p : PsiPackageSupportProvider.EP_NAME.getExtensions()) {
            if (p.isSupported(extension)) {
              return p.createPackage(psiManager, packageManager, extensionClass, qualifiedName);
            }
          }
        }
      }
    }
    return null;
  }
    public KotlinPsiElementFinderImpl(Project project) {
      this.javaFileManager = findJavaFileManager(project);
      this.psiPackageManager = PsiPackageManager.getInstance(project);
      this.isCliFileManager = javaFileManager instanceof KotlinCliJavaFileManager;

      this.packageIndex = DirectoryIndex.getInstance(project);
      this.psiManager = PsiManager.getInstance(project);
    }
    @Override
    public PsiJavaPackage findPackage(
        @NotNull String qualifiedName, @NotNull GlobalSearchScope scope) {
      if (isCliFileManager) {
        return (PsiJavaPackage)
            psiPackageManager.findPackage(qualifiedName, JavaModuleExtension.class);
      }

      Query<VirtualFile> dirs = packageIndex.getDirectoriesByPackageName(qualifiedName, true);
      return hasDirectoriesInScope(dirs, scope)
          ? new PsiPackageImpl(
              psiManager, psiPackageManager, JavaModuleExtension.class, qualifiedName)
          : null;
    }