Set<String> (@NotNull PsiJavaFile file, @NotNull Collection<Import> imports, @NotNull Set<String> onDemandImports) { GlobalSearchScope resolveScope = file.getResolveScope(); String thisPackageName = file.getPackageName(); Set<String> implicitlyImportedPackages = Set.of(file.getImplicitlyImportedPackages()); JavaPsiFacade facade = JavaPsiFacade.getInstance(file.getProject()); List<String> onDemandImportsList = new ArrayList<>(onDemandImports); List<PsiClass> onDemandElements = ContainerUtil.map(onDemandImportsList, onDemandName -> facade.findClass(onDemandName, resolveScope)); Set<String> namesToUseSingle = new HashSet<>(); for (Import anImport : imports) { String name = anImport.name; String prefix = getPackageOrClassName(name); if (prefix.isEmpty()) continue; boolean isImplicitlyImported = implicitlyImportedPackages.contains(prefix); if (!onDemandImports.contains(prefix) && !isImplicitlyImported) continue; String shortName = PsiNameHelper.getShortClassName(name); String thisPackageClass = !thisPackageName.isEmpty() ? thisPackageName + "." + shortName : shortName; if (facade.findClass(thisPackageClass, resolveScope) != null && facade.findClass(name, resolveScope) != null) { namesToUseSingle.add(name); continue; } if (!isImplicitlyImported) { String langPackageClass = JAVA_LANG_PACKAGE + "." + shortName; //TODO : JSP! if (facade.findClass(langPackageClass, resolveScope) != null && facade.findClass(name, resolveScope) != null) { namesToUseSingle.add(name); continue; } } PsiResolveHelper resolveHelper = facade.getResolveHelper(); for (int i = 0; i < onDemandImportsList.size(); i++) { String onDemandName = onDemandImportsList.get(i); if (prefix.equals(onDemandName)) continue; if (anImport.isStatic) { PsiClass aClass = onDemandElements.get(i); if (aClass != null) { PsiField field = aClass.findFieldByName(shortName, true); if (field != null && checkMemberAccessibility(field, resolveHelper, file, aClass, prefix)) { namesToUseSingle.add(name); } else { PsiClass inner = aClass.findInnerClassByName(shortName, true); if (inner != null && checkMemberAccessibility(inner, resolveHelper, file, aClass, prefix)) { namesToUseSingle.add(name); } else { PsiMethod[] methods = aClass.findMethodsByName(shortName, true); if (ContainerUtil.exists(methods, psiMethod -> checkMemberAccessibility(psiMethod, resolveHelper, file, aClass, prefix))) { namesToUseSingle.add(name); } } } } } else { PsiClass aClass = facade.findClass(onDemandName + "." + shortName, resolveScope); if (aClass != null) { namesToUseSingle.add(name); } } } } return namesToUseSingle; }