com.intellij.openapi.roots.ModuleFileIndex Java Examples
The following examples show how to use
com.intellij.openapi.roots.ModuleFileIndex.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IdeaUtils.java From camel-idea-plugin with Apache License 2.0 | 6 votes |
public void iterateXmlDocumentRoots(Module module, Consumer<XmlTag> rootTag) { final GlobalSearchScope moduleScope = module.getModuleContentScope(); final GlobalSearchScope xmlFiles = GlobalSearchScope.getScopeRestrictedByFileTypes(moduleScope, XmlFileType.INSTANCE); ModuleFileIndex fileIndex = ModuleRootManager.getInstance(module).getFileIndex(); fileIndex.iterateContent(f -> { if (xmlFiles.contains(f)) { PsiFile file = PsiManager.getInstance(module.getProject()).findFile(f); if (file instanceof XmlFile) { XmlFile xmlFile = (XmlFile) file; XmlTag root = xmlFile.getRootTag(); if (root != null) { rootTag.accept(xmlFile.getRootTag()); } } } return true; }); }
Example #2
Source File: AbstractFileProcessor.java From consulo with Apache License 2.0 | 6 votes |
protected static void findFiles(final Module module, final List<PsiFile> files) { final ModuleFileIndex idx = ModuleRootManager.getInstance(module).getFileIndex(); final VirtualFile[] roots = ModuleRootManager.getInstance(module).getContentRoots(); for (VirtualFile root : roots) { idx.iterateContentUnderDirectory(root, new ContentIterator() { public boolean processFile(final VirtualFile dir) { if (dir.isDirectory()) { final PsiDirectory psiDir = PsiManager.getInstance(module.getProject()).findDirectory(dir); if (psiDir != null) { findFiles(files, psiDir, false); } } return true; } }); } }
Example #3
Source File: BaseProjectViewDirectoryHelper.java From consulo with Apache License 2.0 | 6 votes |
@RequiredReadAction public static void addAllSubpackages(List<AbstractTreeNode> container, PsiDirectory dir, ModuleFileIndex moduleFileIndex, ViewSettings viewSettings) { final Project project = dir.getProject(); PsiDirectory[] subdirs = dir.getSubdirectories(); for (PsiDirectory subdir : subdirs) { if (skipDirectory(subdir)) { continue; } if (moduleFileIndex != null) { if (!moduleFileIndex.isInContent(subdir.getVirtualFile())) { container.add(new PsiDirectoryNode(project, subdir, viewSettings)); continue; } } if (viewSettings.isHideEmptyMiddlePackages()) { if (!isEmptyMiddleDirectory(subdir, false)) { container.add(new PsiDirectoryNode(project, subdir, viewSettings)); } } else { container.add(new PsiDirectoryNode(project, subdir, viewSettings)); } addAllSubpackages(container, subdir, moduleFileIndex, viewSettings); } }
Example #4
Source File: BaseProjectViewDirectoryHelper.java From consulo with Apache License 2.0 | 5 votes |
@RequiredReadAction public static Collection<AbstractTreeNode> doGetDirectoryChildren(final PsiDirectory psiDirectory, final ViewSettings settings, final boolean withSubDirectories) { final List<AbstractTreeNode> children = new ArrayList<>(); final Project project = psiDirectory.getProject(); final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex(); final Module module = fileIndex.getModuleForFile(psiDirectory.getVirtualFile()); final ModuleFileIndex moduleFileIndex = module == null ? null : ModuleRootManager.getInstance(module).getFileIndex(); if (!settings.isFlattenPackages() || skipDirectory(psiDirectory)) { processPsiDirectoryChildren(psiDirectory, directoryChildrenInProject(psiDirectory, settings), children, fileIndex, null, settings, withSubDirectories); } else { // source directory in "flatten packages" mode final PsiDirectory parentDir = psiDirectory.getParentDirectory(); if (parentDir == null || skipDirectory(parentDir) /*|| !rootDirectoryFound(parentDir)*/ && withSubDirectories) { addAllSubpackages(children, psiDirectory, moduleFileIndex, settings); } PsiDirectory[] subdirs = psiDirectory.getSubdirectories(); for (PsiDirectory subdir : subdirs) { if (!skipDirectory(subdir)) { continue; } VirtualFile directoryFile = subdir.getVirtualFile(); if (FileTypeRegistry.getInstance().isFileIgnored(directoryFile)) continue; if (withSubDirectories) { children.add(new PsiDirectoryNode(project, subdir, settings)); } } processPsiDirectoryChildren(psiDirectory, psiDirectory.getFiles(), children, fileIndex, moduleFileIndex, settings, withSubDirectories); } return children; }
Example #5
Source File: BaseProjectViewDirectoryHelper.java From consulo with Apache License 2.0 | 5 votes |
@RequiredReadAction public static void processPsiDirectoryChildren(final PsiDirectory psiDir, PsiElement[] children, List<AbstractTreeNode> container, ProjectFileIndex projectFileIndex, ModuleFileIndex moduleFileIndex, ViewSettings viewSettings, boolean withSubDirectories) { Project project = psiDir.getProject(); for (PsiElement child : children) { if (!(child instanceof PsiFileSystemItem)) { LOGGER.error("Either PsiFile or PsiDirectory expected as a child of " + child.getParent() + ", but was " + child); continue; } final VirtualFile vFile = ((PsiFileSystemItem)child).getVirtualFile(); if (vFile == null) { continue; } if (moduleFileIndex != null && !moduleFileIndex.isInContent(vFile)) { continue; } if (child instanceof PsiFile) { container.add(new PsiFileNode(project, (PsiFile)child, viewSettings)); } else if (child instanceof PsiDirectory) { if (withSubDirectories) { PsiDirectory dir = (PsiDirectory)child; if (!vFile.equals(projectFileIndex.getSourceRootForFile(vFile))) { // if is not a source root if (viewSettings.isHideEmptyMiddlePackages() && !skipDirectory(psiDir) && isEmptyMiddleDirectory(dir, true)) { processPsiDirectoryChildren(dir, directoryChildrenInProject(dir, viewSettings), container, projectFileIndex, moduleFileIndex, viewSettings, withSubDirectories); // expand it recursively continue; } } container.add(new PsiDirectoryNode(project, dir, viewSettings)); } } } }
Example #6
Source File: ProjectViewModuleNode.java From consulo with Apache License 2.0 | 5 votes |
@Override @Nonnull @RequiredReadAction public Collection<AbstractTreeNode> getChildren() { Module module = getValue(); if (module == null || module.isDisposed()) { return Collections.emptyList(); } ModuleRootManager rootManager = ModuleRootManager.getInstance(module); ModuleFileIndex moduleFileIndex = rootManager.getFileIndex(); final VirtualFile[] contentRoots = rootManager.getContentRoots(); final List<AbstractTreeNode> children = new ArrayList<>(contentRoots.length + 1); final PsiManager psiManager = PsiManager.getInstance(module.getProject()); for (final VirtualFile contentRoot : contentRoots) { if (!moduleFileIndex.isInContent(contentRoot)) continue; if (contentRoot.isDirectory()) { PsiDirectory directory = psiManager.findDirectory(contentRoot); if(directory != null) { children.add(new PsiDirectoryNode(getProject(), directory, getSettings())); } } else { PsiFile file = psiManager.findFile(contentRoot); if(file != null) { children.add(new PsiFileNode(getProject(), file, getSettings())); } } } return children; }
Example #7
Source File: CSharpIconDescriptorUpdater.java From consulo-csharp with Apache License 2.0 | 4 votes |
public static boolean isUnderSourceRoot(@Nonnull Module module, @Nonnull VirtualFile file) { ModuleFileIndex fileIndex = ModuleRootManager.getInstance(module).getFileIndex(); return fileIndex.isInSourceContent(file) || fileIndex.isInTestSourceContent(file); }
Example #8
Source File: CSharpLocationUtil.java From consulo-csharp with Apache License 2.0 | 4 votes |
public static boolean isValidLocation(@Nonnull Project project, @Nullable VirtualFile virtualFile) { if(virtualFile == null || virtualFile.getFileType() != CSharpFileType.INSTANCE) { // if not virtual file - we dont need break highlight return true; } // msil representation highlight always if(virtualFile instanceof MsilFileRepresentationVirtualFile) { return true; } Module moduleForFile = ModuleUtilCore.findModuleForFile(virtualFile, project); if(moduleForFile == null) { return false; } DotNetSimpleModuleExtension extension = ModuleUtilCore.getExtension(moduleForFile, DotNetSimpleModuleExtension.class); if(extension == null) { return false; } if(ModuleUtilCore.getExtension(moduleForFile, CSharpSimpleModuleExtension.class) == null) { return false; } if(extension instanceof DotNetModuleExtension) { if(!((DotNetModuleExtension) extension).isAllowSourceRoots()) { return true; } else { ModuleFileIndex fileIndex = ModuleRootManager.getInstance(moduleForFile).getFileIndex(); return fileIndex.isInSourceContent(virtualFile) || fileIndex.isInTestSourceContent(virtualFile); } } else { return true; } }