Set<Module> (@NotNull PsiElement what) { VirtualFile vFile = PsiUtilCore.getVirtualFile(what); if (vFile == null) return null; Project project = what.getProject(); final ProjectFileIndex fileIndex = ProjectFileIndex.getInstance(project); if (fileIndex.isInLibrary(vFile)) { final List<OrderEntry> orderEntries = fileIndex.getOrderEntriesForFile(vFile); if (orderEntries.isEmpty()) { return null; } Set<Module> modules = new HashSet<>(orderEntries.size()); for (OrderEntry orderEntry : orderEntries) { if (orderEntry instanceof JdkOrderEntry) return null; modules.add(orderEntry.getOwnerModule()); } return modules; } Module module = ModuleUtilCore.findModuleForFile(vFile, project); return module != null ? Collections.singleton(module) : null; }