void (UsageInfo[] usages, Function<? super PsiDirectory, ? extends PsiDirectory> newDirMapper) { for (UsageInfo usage : usages) { if (usage instanceof RemoveOnDemandImportStatementsUsageInfo) { final PsiElement element = usage.getElement(); if (element != null) { element.delete(); } } if (usage instanceof MoveDirectoryUsageInfo moveDirUsage) { PsiDirectory sourceDirectory = moveDirUsage.getSourceDirectory(); if (sourceDirectory == null) continue; PsiJavaModule moduleDescriptor = JavaModuleGraphUtil.findDescriptorByElement(sourceDirectory); if (moduleDescriptor == null) continue; JavaDirectoryService directoryService = JavaDirectoryService.getInstance(); PsiPackage oldPackage = directoryService.getPackage(sourceDirectory); if (oldPackage == null) continue; PsiDirectory targetDirectory = ObjectUtils.tryCast(moveDirUsage.getTargetFileItem(), PsiDirectory.class); if (targetDirectory == null) continue; PsiPackage newPackage = directoryService.getPackage(targetDirectory); if (newPackage == null) continue; renamePackageStatements(moduleDescriptor.getExports(), oldPackage, newPackage); renamePackageStatements(moduleDescriptor.getOpens(), oldPackage, newPackage); } } }