List<PsiFileSystemItem> (@NotNull VirtualFile parentFile, @NotNull VirtualFile root, @NotNull Module module, @NotNull List<PsiFileSystemItem> contextsForModule) { // here we try to find source roots that are not present in contextsForModule, but could be used to create a package and file List<SourceFolder> additionalSourceFolders = getMissingTargetFolders(module, contextsForModule); if (additionalSourceFolders.isEmpty()) { return contextsForModule; } List<PsiFileSystemItem> joinedContexts = new ArrayList<>(contextsForModule.size() + additionalSourceFolders.size()); joinedContexts.addAll(contextsForModule); PsiManager manager = PsiManager.getInstance(module.getProject()); String[] relativePath = getRelativePath(parentFile, root); for (SourceFolder sourceFolder : additionalSourceFolders) { if (sourceFolder.getFile() == null) continue; PsiDirectory directory = manager.findDirectory(sourceFolder.getFile()); if (directory == null) continue; String srcPackagePrefix = sourceFolder.getPackagePrefix(); String[] pathToCreate; if (srcPackagePrefix.isEmpty()) { pathToCreate = relativePath; } else { pathToCreate = removeCommonStartPackages(relativePath, srcPackagePrefix); } joinedContexts.add(new VirtualPsiDirectory(directory, pathToCreate)); } return joinedContexts; }