void (@NotNull Collection<PsiClass> list, @NotNull PsiFile containingFile) { if (!(containingFile instanceof PsiJavaFile javaFile)) return; PsiImportList importList = javaFile.getImportList(); PsiImportStatementBase[] importStatements = importList == null ? PsiImportStatementBase.EMPTY_ARRAY : importList.getAllImportStatements(); Set<String> unresolvedImports = new HashSet<>(importStatements.length); for (PsiImportStatementBase statement : importStatements) { PsiJavaCodeReferenceElement ref = statement.getImportReference(); String name = ref == null ? null : ref.getReferenceName(); if (name != null && ref.resolve() == null) unresolvedImports.add(name); } if (unresolvedImports.isEmpty()) return; list.removeIf(aClass -> { String className = aClass.getName(); return className != null && unresolvedImports.contains(className); }); }