Search in sources :

Example 51 with ProjectFileIndex

use of com.intellij.openapi.roots.ProjectFileIndex in project intellij-community by JetBrains.

the class JavaDocInfoGenerator method elementHasSourceCode.

private boolean elementHasSourceCode() {
    PsiFileSystemItem[] items;
    if (myElement instanceof PsiDirectory) {
        final PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage((PsiDirectory) myElement);
        if (aPackage == null)
            return false;
        items = aPackage.getDirectories(new EverythingGlobalScope(myProject));
    } else if (myElement instanceof PsiPackage) {
        items = ((PsiPackage) myElement).getDirectories(new EverythingGlobalScope(myProject));
    } else {
        PsiFile containingFile = myElement.getNavigationElement().getContainingFile();
        if (containingFile == null)
            return false;
        items = new PsiFileSystemItem[] { containingFile };
    }
    ProjectFileIndex projectFileIndex = ProjectFileIndex.SERVICE.getInstance(myProject);
    for (PsiFileSystemItem item : items) {
        VirtualFile file = item.getVirtualFile();
        if (file != null && projectFileIndex.isInSource(file))
            return true;
    }
    return false;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) EverythingGlobalScope(com.intellij.psi.search.EverythingGlobalScope)

Example 52 with ProjectFileIndex

use of com.intellij.openapi.roots.ProjectFileIndex in project intellij-community by JetBrains.

the class JavaDirectoryServiceImpl method getPackage.

@Override
public PsiPackage getPackage(@NotNull PsiDirectory dir) {
    ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(dir.getProject()).getFileIndex();
    String packageName = projectFileIndex.getPackageNameByDirectory(dir.getVirtualFile());
    if (packageName == null)
        return null;
    return JavaPsiFacade.getInstance(dir.getProject()).findPackage(packageName);
}
Also used : ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex)

Example 53 with ProjectFileIndex

use of com.intellij.openapi.roots.ProjectFileIndex in project intellij-community by JetBrains.

the class ForwardDependenciesBuilder method analyze.

@Override
public void analyze() {
    final PsiManager psiManager = PsiManager.getInstance(getProject());
    psiManager.startBatchFilesProcessingMode();
    final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(getProject()).getFileIndex();
    try {
        getScope().accept(new PsiRecursiveElementVisitor() {

            @Override
            public void visitFile(final PsiFile file) {
                visit(file, fileIndex, psiManager, 0);
            }
        });
    } finally {
        psiManager.finishBatchFilesProcessingMode();
    }
}
Also used : ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex)

Example 54 with ProjectFileIndex

use of com.intellij.openapi.roots.ProjectFileIndex in project intellij-community by JetBrains.

the class NullFileReferenceHelper method findRoot.

@Override
public PsiFileSystemItem findRoot(final Project project, @NotNull final VirtualFile file) {
    final ProjectFileIndex index = ProjectRootManager.getInstance(project).getFileIndex();
    VirtualFile contentRootForFile = index.getContentRootForFile(file);
    return contentRootForFile != null ? PsiManager.getInstance(project).findDirectory(contentRootForFile) : null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex)

Example 55 with ProjectFileIndex

use of com.intellij.openapi.roots.ProjectFileIndex in project intellij-community by JetBrains.

the class CreateClassOrPackageFix method chooseDirectory.

@Nullable
private PsiDirectory chooseDirectory(final Project project, final PsiFile file) {
    PsiDirectory preferredDirectory = myWritableDirectoryList.isEmpty() ? null : myWritableDirectoryList.get(0);
    final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
    final VirtualFile virtualFile = file.getVirtualFile();
    assert virtualFile != null;
    final Module moduleForFile = fileIndex.getModuleForFile(virtualFile);
    if (myWritableDirectoryList.size() > 1 && !ApplicationManager.getApplication().isUnitTestMode()) {
        if (moduleForFile != null) {
            for (PsiDirectory directory : myWritableDirectoryList) {
                if (fileIndex.getModuleForFile(directory.getVirtualFile()) == moduleForFile) {
                    preferredDirectory = directory;
                    break;
                }
            }
        }
        return DirectoryChooserUtil.chooseDirectory(myWritableDirectoryList.toArray(new PsiDirectory[myWritableDirectoryList.size()]), preferredDirectory, project, new HashMap<>());
    }
    return preferredDirectory;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) Module(com.intellij.openapi.module.Module) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)157 VirtualFile (com.intellij.openapi.vfs.VirtualFile)119 Module (com.intellij.openapi.module.Module)52 Project (com.intellij.openapi.project.Project)49 Nullable (org.jetbrains.annotations.Nullable)37 NotNull (org.jetbrains.annotations.NotNull)24 PsiDirectory (com.intellij.psi.PsiDirectory)23 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)16 PsiFile (com.intellij.psi.PsiFile)14 ArrayList (java.util.ArrayList)13 IdeView (com.intellij.ide.IdeView)10 OrderEntry (com.intellij.openapi.roots.OrderEntry)9 THashSet (gnu.trove.THashSet)6 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)5 ProjectRootManager (com.intellij.openapi.roots.ProjectRootManager)5 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)4 File (java.io.File)4 List (java.util.List)4 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)3 Presentation (com.intellij.openapi.actionSystem.Presentation)3