PackageSet (final PackageDependenciesNode node, final boolean recursively) { if (node instanceof ModuleGroupNode) { if (!recursively) return null; return new FilePatternPackageSet(getGroupModulePattern((ModuleGroupNode)node), "*//*"); } else if (node instanceof ModuleNode) { if (!recursively) return null; final String modulePattern = ((ModuleNode)node).getModuleName(); return new FilePatternPackageSet(modulePattern, "*/"); } else if (node instanceof DirectoryNode) { String pattern = ((DirectoryNode)node).getFQName(); if (pattern != null) { if (pattern.length() > 0) { pattern += recursively ? "//*" : "/*"; } else { pattern += recursively ? "*/" : "*"; } } final VirtualFile vDir = ((DirectoryNode)node).getDirectory(); final PsiElement psiElement = node.getPsiElement(); boolean projectFiles = true; String modulePattern = null; if (psiElement != null) { Project project = psiElement.getProject(); final Module module = ModuleUtilCore.findModuleForFile(vDir, project); if (module == null) { projectFiles = false; modulePattern = ProjectFileIndex.getInstance(project) .getOrderEntriesForFile(vDir).stream() .filter(entry -> entry instanceof LibraryOrSdkOrderEntry) .findFirst() .map(entry -> entry instanceof JdkOrderEntry ? ((JdkOrderEntry)entry).getJdkName() : entry.getPresentableName()) .orElse(null); } else { modulePattern = module.getName(); } } return new FilePatternPackageSet(modulePattern, pattern, projectFiles); } else if (node instanceof LibraryNode) { return new FilePatternPackageSet(node.toString(), recursively ? "*/" : "*", false); } else if (node instanceof FileNode fNode) { if (recursively) return null; final PsiFile file = (PsiFile)fNode.getPsiElement(); if (file == null) return null; final VirtualFile virtualFile = file.getVirtualFile(); LOG.assertTrue(virtualFile != null); final VirtualFile contentRoot = ProjectRootManager.getInstance(file.getProject()).getFileIndex().getContentRootForFile(virtualFile); if (contentRoot == null) return null; final String fqName = VfsUtilCore.getRelativePath(virtualFile, contentRoot, '/'); if (fqName != null) return new FilePatternPackageSet(getModulePattern(node), fqName); } else if (node instanceof GeneralGroupNode) {//external dependencies return new FilePatternPackageSet("", recursively ? "*/" : "*", false); } return null; }