Runnable (@NotNull final PsiFile file) { if (isInsideTestResourceRoot(file)) { return EmptyRunnable.INSTANCE; } PyUnresolvedReferencesVisitor visitor = prepare(file); return () -> { LOG.debug(String.format("----------------- OPTIMIZE IMPORTS STARTED (%s) -----------------", file.getVirtualFile())); visitor.optimizeImports(); if (mySortImports && file instanceof PyFile) { new ImportSorter((PyFile)file).run(); } LOG.debug("----------------- OPTIMIZE IMPORTS FINISHED -----------------"); }; }