PsiImportStatementBase (@NotNull PsiMember member, List<? extends PsiImportStatementBase> importStatements) { final String memberQualifiedName; final String memberPackageName; final PsiClass containingClass = member.getContainingClass(); if (member instanceof PsiClass referencedClass) { memberQualifiedName = referencedClass.getQualifiedName(); memberPackageName = memberQualifiedName != null ? StringUtil.getPackageName(memberQualifiedName) : null; } else { if (!member.hasModifierProperty(PsiModifier.STATIC) || containingClass == null) { return null; } memberPackageName = containingClass.getQualifiedName(); memberQualifiedName = memberPackageName + '.' + member.getName(); } if (memberPackageName == null) { return null; } final boolean hasOnDemandImportConflict = ImportUtils.hasOnDemandImportConflict(memberQualifiedName, myFile); for (PsiImportStatementBase importStatement : importStatements) { if (!importStatement.isOnDemand()) { final PsiJavaCodeReferenceElement reference = importStatement.getImportReference(); if (reference == null) { continue; } final JavaResolveResult[] targets = reference.multiResolve(false); for (JavaResolveResult target : targets) { if (member.equals(target.getElement())) { return importStatement; } } } else { if (hasOnDemandImportConflict) { continue; } final PsiElement target = importStatement.resolve(); if (target instanceof PsiPackage aPackage) { if (memberPackageName.equals(aPackage.getQualifiedName())) { return importStatement; } } else if (target instanceof PsiClass aClass) { // a regular import statement does NOT import inner classes from super classes, but a static import does if (importStatement instanceof PsiImportStaticStatement) { if (member.hasModifierProperty(PsiModifier.STATIC) && InheritanceUtil.isInheritorOrSelf(aClass, containingClass, true)) { return importStatement; } } else if (importStatement instanceof PsiImportStatement && member instanceof PsiClass && aClass.equals(containingClass)) { return importStatement; } } } } return null; }