List<SourceFolder> (@NotNull Module module, @NotNull Collection<? extends PsiFileSystemItem> contextsForModule) { // find additional source folders that can be used to create a file, e.g. they do not have the exact package, but it can be created ModuleRootModel model = ModuleRootManager.getInstance(module); return Arrays.stream(model.getContentEntries()) .flatMap(contentEntry -> Arrays.stream(contentEntry.getSourceFolders())) .filter(sourceFolder -> { if (sourceFolder.getFile() == null) return false; for (PsiFileSystemItem contextItem : contextsForModule) { if (VfsUtilCore.isAncestor(sourceFolder.getFile(), contextItem.getVirtualFile(), false)) { return false; } } return true; }) .collect(Collectors.toCollection(SmartList::new)); }