use of com.intellij.openapi.roots.ProjectFileIndex in project intellij-community by JetBrains.
the class NavBarModel method updateModel.
protected void updateModel(final PsiElement psiElement) {
final Set<VirtualFile> roots = new HashSet<>();
final ProjectRootManager projectRootManager = ProjectRootManager.getInstance(myProject);
final ProjectFileIndex projectFileIndex = projectRootManager.getFileIndex();
for (VirtualFile root : projectRootManager.getContentRoots()) {
VirtualFile parent = root.getParent();
if (parent == null || !projectFileIndex.isInContent(parent)) {
roots.add(root);
}
}
for (final NavBarModelExtension modelExtension : Extensions.getExtensions(NavBarModelExtension.EP_NAME)) {
for (VirtualFile root : modelExtension.additionalRoots(psiElement.getProject())) {
VirtualFile parent = root.getParent();
if (parent == null || !projectFileIndex.isInContent(parent)) {
roots.add(root);
}
}
}
final List<Object> updatedModel = new ArrayList<>();
ApplicationManager.getApplication().runReadAction(() -> traverseToRoot(psiElement, roots, updatedModel));
setModel(ContainerUtil.reverse(updatedModel));
}
use of com.intellij.openapi.roots.ProjectFileIndex in project intellij-community by JetBrains.
the class FileTreeModelBuilder method getModuleDirNode.
private PackageDependenciesNode getModuleDirNode(VirtualFile virtualFile, Module module, DirectoryNode childNode) {
if (virtualFile == null) {
return getModuleNode(module);
}
PackageDependenciesNode directoryNode = myModuleDirNodes.get(virtualFile);
if (directoryNode != null) {
if (myCompactEmptyMiddlePackages) {
final DirectoryNode nestedNode = ((DirectoryNode) directoryNode).getCompactedDirNode();
if (nestedNode != null) {
//decompact
boolean expand = false;
if (myTree != null) {
expand = !myTree.isCollapsed(new TreePath(directoryNode.getPath()));
}
DirectoryNode parentWrapper = nestedNode.getWrapper();
while (parentWrapper.getWrapper() != null) {
parentWrapper = parentWrapper.getWrapper();
}
for (int i = parentWrapper.getChildCount() - 1; i >= 0; i--) {
nestedNode.add((MutableTreeNode) parentWrapper.getChildAt(i));
}
((DirectoryNode) directoryNode).setCompactedDirNode(null);
parentWrapper.add(nestedNode);
nestedNode.removeUpReference();
if (myTree != null && expand) {
final Runnable expandRunnable = () -> myTree.expandPath(new TreePath(nestedNode.getPath()));
SwingUtilities.invokeLater(expandRunnable);
}
return parentWrapper;
}
if (directoryNode.getParent() == null) {
//find first node in tree
DirectoryNode parentWrapper = ((DirectoryNode) directoryNode).getWrapper();
if (parentWrapper != null) {
while (parentWrapper.getWrapper() != null) {
parentWrapper = parentWrapper.getWrapper();
}
return parentWrapper;
}
}
}
return directoryNode;
}
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
final VirtualFile sourceRoot = fileIndex.getSourceRootForFile(virtualFile);
final VirtualFile contentRoot = fileIndex.getContentRootForFile(virtualFile);
directoryNode = new DirectoryNode(virtualFile, myProject, myCompactEmptyMiddlePackages, myFlattenPackages, myBaseDir, myContentRoots);
myModuleDirNodes.put(virtualFile, (DirectoryNode) directoryNode);
final VirtualFile directory = virtualFile.getParent();
if (!myFlattenPackages && directory != null) {
if (myCompactEmptyMiddlePackages && !Comparing.equal(sourceRoot, virtualFile) && !Comparing.equal(contentRoot, virtualFile)) {
//compact
((DirectoryNode) directoryNode).setCompactedDirNode(childNode);
}
if (fileIndex.getModuleForFile(directory) == module) {
DirectoryNode parentDirectoryNode = myModuleDirNodes.get(directory);
if (parentDirectoryNode != null || !myCompactEmptyMiddlePackages || (sourceRoot != null && VfsUtilCore.isAncestor(directory, sourceRoot, false) && fileIndex.getSourceRootForFile(directory) != null) || Comparing.equal(directory, contentRoot)) {
getModuleDirNode(directory, module, (DirectoryNode) directoryNode).add(directoryNode);
} else {
directoryNode = getModuleDirNode(directory, module, (DirectoryNode) directoryNode);
}
} else {
getModuleNode(module).add(directoryNode);
}
} else {
if (Comparing.equal(contentRoot, virtualFile)) {
getModuleNode(module).add(directoryNode);
} else {
final VirtualFile root;
if (!Comparing.equal(sourceRoot, virtualFile) && sourceRoot != null) {
root = sourceRoot;
} else if (contentRoot != null) {
root = contentRoot;
} else {
root = null;
}
if (root != null) {
getModuleDirNode(root, module, null).add(directoryNode);
} else {
if (myExternalNode == null) {
myExternalNode = new GeneralGroupNode("External Dependencies", AllIcons.Nodes.PpLibFolder, myProject);
myRoot.add(myExternalNode);
}
myExternalNode.add(directoryNode);
}
}
}
return directoryNode;
}
use of com.intellij.openapi.roots.ProjectFileIndex in project intellij-community by JetBrains.
the class DirectoryNode method getFQName.
public String getFQName() {
final ProjectFileIndex index = ProjectRootManager.getInstance(myProject).getFileIndex();
VirtualFile directory = myVDirectory;
VirtualFile contentRoot = index.getContentRootForFile(directory);
if (Comparing.equal(directory, contentRoot)) {
return "";
}
if (contentRoot == null) {
return "";
}
return VfsUtilCore.getRelativePath(directory, contentRoot, '/');
}
use of com.intellij.openapi.roots.ProjectFileIndex in project intellij-community by JetBrains.
the class HighlightingSettingsPerFile method shouldInspect.
@Override
public boolean shouldInspect(@NotNull PsiElement psiRoot) {
final FileHighlightingSetting settingForRoot = getHighlightingSettingForRoot(psiRoot);
if (settingForRoot == FileHighlightingSetting.SKIP_HIGHLIGHTING || settingForRoot == FileHighlightingSetting.SKIP_INSPECTION) {
return false;
}
final Project project = psiRoot.getProject();
final VirtualFile virtualFile = psiRoot.getContainingFile().getVirtualFile();
if (virtualFile == null || !virtualFile.isValid())
return false;
if (ProjectUtil.isProjectOrWorkspaceFile(virtualFile)) {
return false;
}
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
if (ProjectScope.getLibrariesScope(project).contains(virtualFile) && !fileIndex.isInContent(virtualFile))
return false;
return !SingleRootFileViewProvider.isTooLargeForIntelligence(virtualFile);
}
use of com.intellij.openapi.roots.ProjectFileIndex in project intellij-community by JetBrains.
the class BaseClassesAnalysisAction method getContainingModule.
private static void getContainingModule(VirtualFile vFile, @NotNull Project project, Set<Module> result) {
final ProjectFileIndex fileIndex = ProjectFileIndex.getInstance(project);
final Module module = fileIndex.getModuleForFile(vFile);
if (module != null) {
result.add(module);
}
}
Aggregations