public static @NotNull List<@NotNull LocalQuickFix> registerFixes(@NotNull PsiReference reference,
                                                                    @NotNull List<? super IntentionAction> registrar,
                                                                    @NotNull Function<? super String, PsiClass[]> shortReferenceNameToClassesLookup) {
    PsiElement psiElement = reference.getElement();
    String shortReferenceName = reference.getRangeInElement().substring(psiElement.getText());

    Project project = psiElement.getProject();
    PsiFile containingFile = psiElement.getContainingFile();
    if (containingFile == null) return Collections.emptyList();
    VirtualFile refVFile = containingFile.getVirtualFile();
    if (refVFile == null) return Collections.emptyList();

    ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
    Module currentModule = fileIndex.getModuleForFile(refVFile);
    if (currentModule == null) return Collections.emptyList();

    DependencyScope scope = fileIndex.isInTestSourceContent(refVFile) ? DependencyScope.TEST : DependencyScope.COMPILE;

    if (reference instanceof PsiJavaModuleReference moduleReference) {
      List<LocalQuickFix> result = new SmartList<>();
      createModuleFixes(moduleReference, currentModule, scope, result);
      result.forEach(fix -> registrar.add((IntentionAction)fix));
      return result;
    }

    List<LocalQuickFix> result = new SmartList<>();
    JavaPsiFacade facade = JavaPsiFacade.getInstance(project);

    registerExternalFixes(reference, psiElement, shortReferenceName, currentModule, scope, registrar, result);
    if (!result.isEmpty()) {
      return result;
    }

    PsiClass[] classes = shortReferenceNameToClassesLookup.fun(shortReferenceName);
    List<PsiClass> allowedDependencies = filterAllowedDependencies(psiElement, classes);
    if (allowedDependencies.isEmpty()) {
      return result;
    }
    if (reference instanceof PsiJavaCodeReferenceElement codeReference) {
      String qualifiedName = getQualifiedName(codeReference, shortReferenceName, containingFile);
      if (qualifiedName != null) {
        allowedDependencies.removeIf(aClass -> !qualifiedName.equals(aClass.getQualifiedName()));
      }
    }

    OrderEntryFix moduleDependencyFix = new AddModuleDependencyFix(reference, currentModule, scope, allowedDependencies);
    registrar.add(moduleDependencyFix);
    result.add(moduleDependencyFix);

    Map<Library, String> librariesToAdd = new HashMap<>();
    Set<VirtualFile> jars = new HashSet<>();
    Set<Library> excluded = new HashSet<>();
    Set<Library> withTestScope = new HashSet<>();
    ModuleFileIndex moduleFileIndex = ModuleRootManager.getInstance(currentModule).getFileIndex();
    for (PsiClass aClass : allowedDependencies) {
      if (!facade.getResolveHelper().isAccessible(aClass, psiElement, aClass)) continue;
      PsiFile psiFile = aClass.getContainingFile();
      if (psiFile == null) continue;
      VirtualFile virtualFile = psiFile.getVirtualFile();
      if (virtualFile == null) continue;
      for (OrderEntry orderEntry : fileIndex.getOrderEntriesForFile(virtualFile)) {
        if (orderEntry instanceof LibraryOrderEntry libraryEntry) {
          final Library library = libraryEntry.getLibrary();
          if (library == null) continue;
          VirtualFile[] files = library.getFiles(OrderRootType.CLASSES);
          if (files.length == 0) continue;
          final VirtualFile jar = files[0];

          String qualifiedName = aClass.getQualifiedName();
          if (qualifiedName == null) continue;

          if (jar == null || 
              libraryEntry.isModuleLevel() && !jars.add(jar) || 
              librariesToAdd.putIfAbsent(library, qualifiedName) != null) {
            continue;
          }
          OrderEntry entryForFile = moduleFileIndex.getOrderEntryForFile(virtualFile);
          if (entryForFile != null) {
            boolean testScopeLibraryInProduction = entryForFile instanceof ExportableOrderEntry && 
                                                   ((ExportableOrderEntry)entryForFile).getScope() == DependencyScope.TEST && 
                                                   !moduleFileIndex.isInTestSourceContent(refVFile);
            if (testScopeLibraryInProduction) {
              withTestScope.add(library);
            }
            else {
              excluded.add(library);
            }
          }
        }
      }

      excluded.forEach(librariesToAdd::remove);
      
      if (!librariesToAdd.isEmpty()) {
        class AddLibraryFix extends AddLibraryDependencyFix implements PriorityAction {
          private AddLibraryFix(@NotNull PsiReference reference,
                                @NotNull Module currentModule,
                                @NotNull Map<Library, String> libraries,
                                @NotNull DependencyScope scope, boolean exported) {
            super(reference, currentModule, libraries, scope, exported);
          }
          @Override
          public @NotNull Priority getPriority() {
            return withTestScope.isEmpty() ? Priority.NORMAL : Priority.LOW;
          }
        }
        OrderEntryFix fix = new AddLibraryFix(reference, currentModule, librariesToAdd, scope, false);
        registrar.add(fix);
        result.add(fix);
      }
      
      if (!withTestScope.isEmpty()) {
        MoveToTestRootFix fix = new MoveToTestRootFix(containingFile);
        if (fix.isAvailable(containingFile)) {
          registrar.add(fix);
          result.add(fix);
        }
      }
      
    }

    return result;
  }
public static @NotNull List<@NotNull LocalQuickFix> registerFixes(@NotNull PsiReference reference,
                                                                    @NotNull List<? super IntentionAction> registrar,
                                                                    @NotNull Function<? super String, PsiClass[]> shortReferenceNameToClassesLookup)