void (@NotNull PsiImportList importList) { final PsiElement parent = importList.getParent(); if (!(parent instanceof PsiJavaFile javaFile)) { return; } final String packageName = javaFile.getPackageName(); final PsiImportStatement[] importStatements = importList.getImportStatements(); for (final PsiImportStatement importStatement : importStatements) { final PsiJavaCodeReferenceElement reference = importStatement.getImportReference(); if (reference == null) { continue; } final String text = importStatement.getQualifiedName(); if (importStatement.isOnDemand()) { if (packageName.equals(text)) { registerError(importStatement); } } else { if (text == null) { return; } final int classNameIndex = text.lastIndexOf('.'); final String parentName; if (classNameIndex < 0) { parentName = ""; } else { parentName = text.substring(0, classNameIndex); } if (packageName.equals(parentName)) { registerError(importStatement); } } } }