void (PsiJavaFile javaFile, Set<String> imports) { PsiImportList importList = new ImportHelper(JavaCodeStyleSettings.getInstance(javaFile)) .prepareOptimizeImportsResult(javaFile, anImport -> !imports.contains(anImport.name())); if (importList != null) { Objects.requireNonNull(javaFile.getImportList()).replace(importList); } }