void (Map<VirtualFile, MoveDirectoryWithClassesProcessor.TargetDirectoryWrapper> filesToMove, PsiDirectory[] directoriesToMove, Collection<? super UsageInfo> usages, boolean searchInComments, boolean searchInNonJavaFiles, Project project) { final Set<String> packageNames = new HashSet<>(); PsiManager psiManager = PsiManager.getInstance(project); for (VirtualFile vFile : filesToMove.keySet()) { PsiFile psiFile = psiManager.findFile(vFile); if (psiFile instanceof PsiClassOwner) { String packageName = ""; MoveDirectoryWithClassesProcessor.TargetDirectoryWrapper targetWrapper = filesToMove.get(vFile); PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage(targetWrapper.getRootDirectory()); if (aPackage != null) { String relatedPackageName = targetWrapper.getRelativePathFromRoot().replaceAll("/", "."); packageName = !relatedPackageName.isEmpty() ? StringUtil.getQualifiedName(aPackage.getQualifiedName(), relatedPackageName) : aPackage.getQualifiedName(); } final PsiClass[] classes = ((PsiClassOwner)psiFile).getClasses(); for (PsiClass aClass : classes) { String newQName = StringUtil.getQualifiedName(packageName, Objects.requireNonNull(aClass.getName())); Collections.addAll(usages, MoveClassesOrPackagesUtil.findUsages(aClass, searchInComments, searchInNonJavaFiles, newQName)); } packageNames.add(((PsiClassOwner)psiFile).getPackageName()); } } final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project); for (String packageName : packageNames) { final PsiPackage aPackage = psiFacade.findPackage(packageName); if (aPackage != null) { boolean remainsNothing = true; for (PsiDirectory packageDirectory : aPackage.getDirectories()) { if (!isUnderRefactoring(packageDirectory, directoriesToMove)) { remainsNothing = false; break; } } if (remainsNothing) { for (PsiReference reference : ReferencesSearch.search(aPackage, GlobalSearchScope.projectScope(project))) { final PsiElement element = reference.getElement(); final PsiImportStatementBase statementBase = PsiTreeUtil.getParentOfType(element, PsiImportStatementBase.class); if (statementBase != null && statementBase.isOnDemand() && !isUnderRefactoring(statementBase, directoriesToMove)) { usages.add(new RemoveOnDemandImportStatementsUsageInfo(statementBase)); } } } } } }