Collection<PsiJavaModule> (Project project, Collection<PsiJavaModule> modules) { Set<VirtualFile> filter = new HashSet<>(); ProjectFileIndex index = ProjectFileIndex.getInstance(project); for (PsiJavaModule module : modules) { VirtualFile root = index.getClassRootForFile(module.getContainingFile().getVirtualFile()); if (root != null) { List<VirtualFile> files = descriptorFiles(root, false, false); VirtualFile main = ContainerUtil.getFirstItem(files); if (main != null && !(root.equals(main.getParent()) || version(main.getParent()) >= 9)) { filter.add(main); } for (int i = 1; i < files.size(); i++) { filter.add(files.get(i)); } } } if (!filter.isEmpty()) { modules = ContainerUtil.filter(modules, m -> !filter.contains(m.getContainingFile().getVirtualFile())); } return modules; }