Search in sources :

Example 11 with ProjectFileIndex

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

the class MavenDomUtil method findContainingMavenizedModule.

@Nullable
public static Module findContainingMavenizedModule(@NotNull PsiFile psiFile) {
    VirtualFile file = psiFile.getVirtualFile();
    if (file == null)
        return null;
    Project project = psiFile.getProject();
    MavenProjectsManager manager = MavenProjectsManager.getInstance(project);
    if (!manager.isMavenizedProject())
        return null;
    ProjectFileIndex index = ProjectRootManager.getInstance(project).getFileIndex();
    Module module = index.getModuleForFile(file);
    if (module == null || !manager.isMavenizedModule(module))
        return null;
    return module;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) Project(com.intellij.openapi.project.Project) MavenProject(org.jetbrains.idea.maven.project.MavenProject) MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) Module(com.intellij.openapi.module.Module) Nullable(org.jetbrains.annotations.Nullable)

Example 12 with ProjectFileIndex

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

the class AddImportHelper method getImportPriority.

@NotNull
public static ImportPriority getImportPriority(@NotNull PsiElement importLocation, @NotNull PsiFileSystemItem toImport) {
    final VirtualFile vFile = toImport.getVirtualFile();
    if (vFile == null) {
        return UNRESOLVED_SYMBOL_PRIORITY;
    }
    final ProjectRootManager projectRootManager = ProjectRootManager.getInstance(toImport.getProject());
    final ProjectFileIndex fileIndex = projectRootManager.getFileIndex();
    if (fileIndex.isInContent(vFile) && !fileIndex.isInLibraryClasses(vFile)) {
        return ImportPriority.PROJECT;
    }
    final Module module = ModuleUtilCore.findModuleForPsiElement(importLocation);
    final Sdk pythonSdk = module != null ? PythonSdkType.findPythonSdk(module) : projectRootManager.getProjectSdk();
    return PythonSdkType.isStdLib(vFile, pythonSdk) ? ImportPriority.BUILTIN : ImportPriority.THIRD_PARTY;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) Sdk(com.intellij.openapi.projectRoots.Sdk) Module(com.intellij.openapi.module.Module) ProjectRootManager(com.intellij.openapi.roots.ProjectRootManager) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with ProjectFileIndex

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

the class ImportCandidateHolder method getRelevance.

int getRelevance() {
    final Project project = myImportable.getProject();
    final PsiFile psiFile = myImportable.getContainingFile();
    final VirtualFile vFile = psiFile == null ? null : psiFile.getVirtualFile();
    if (vFile == null)
        return 0;
    final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
    // files under project source are most relevant
    final Module module = fileIndex.getModuleForFile(vFile);
    if (module != null)
        return 3;
    // then come files directly under Lib
    if (vFile.getParent().getName().equals("Lib"))
        return 2;
    // tests we don't want
    if (vFile.getParent().getName().equals("test"))
        return 0;
    return 1;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module)

Example 14 with ProjectFileIndex

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

the class CreateClassToBindFix method run.

public void run() {
    final Project project = myEditor.getProject();
    final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
    final VirtualFile sourceRoot = fileIndex.getSourceRootForFile(myEditor.getFile());
    if (sourceRoot == null) {
        Messages.showErrorDialog(myEditor, UIDesignerBundle.message("error.cannot.create.class.not.in.source.root"), CommonBundle.getErrorTitle());
        return;
    }
    ApplicationManager.getApplication().runWriteAction(() -> CommandProcessor.getInstance().executeCommand(project, () -> {
        // 1. Create all necessary packages
        final int indexOfLastDot = myClassName.lastIndexOf('.');
        final String packageName = myClassName.substring(0, indexOfLastDot != -1 ? indexOfLastDot : 0);
        final PsiDirectory psiDirectory;
        if (packageName.length() > 0) {
            final PackageWrapper packageWrapper = new PackageWrapper(PsiManager.getInstance(project), packageName);
            try {
                psiDirectory = RefactoringUtil.createPackageDirectoryInSourceRoot(packageWrapper, sourceRoot);
                LOG.assertTrue(psiDirectory != null);
            } catch (final IncorrectOperationException e) {
                ApplicationManager.getApplication().invokeLater(() -> Messages.showErrorDialog(myEditor, UIDesignerBundle.message("error.cannot.create.package", packageName, e.getMessage()), CommonBundle.getErrorTitle()));
                return;
            }
        } else {
            psiDirectory = PsiManager.getInstance(project).findDirectory(sourceRoot);
            LOG.assertTrue(psiDirectory != null);
        }
        // 2. Create class in the package
        try {
            final String name = myClassName.substring(indexOfLastDot != -1 ? indexOfLastDot + 1 : 0);
            final PsiClass aClass = JavaDirectoryService.getInstance().createClass(psiDirectory, name);
            createBoundFields(aClass);
        } catch (final IncorrectOperationException e) {
            ApplicationManager.getApplication().invokeLater(() -> Messages.showErrorDialog(myEditor, UIDesignerBundle.message("error.cannot.create.class", packageName, e.getMessage()), CommonBundle.getErrorTitle()));
        }
    }, getName(), null));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) IncorrectOperationException(com.intellij.util.IncorrectOperationException) PackageWrapper(com.intellij.refactoring.PackageWrapper)

Example 15 with ProjectFileIndex

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

the class AbstractFolderNode method containsImpl.

@Override
protected boolean containsImpl(@NotNull final VirtualFile file) {
    final PsiElement psiElement = extractPsiFromValue();
    if (psiElement == null || !psiElement.isValid()) {
        return false;
    }
    final VirtualFile valueFile = ((PsiDirectory) psiElement).getVirtualFile();
    if (!VfsUtil.isAncestor(valueFile, file, false)) {
        return false;
    }
    final Project project = psiElement.getProject();
    final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
    final Module module = fileIndex.getModuleForFile(valueFile);
    if (module == null) {
        return fileIndex.getModuleForFile(file) == null;
    }
    return ModuleRootManager.getInstance(module).getFileIndex().isInContent(file);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) PsiDirectory(com.intellij.psi.PsiDirectory) Module(com.intellij.openapi.module.Module) PsiElement(com.intellij.psi.PsiElement)

Aggregations

ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)164 VirtualFile (com.intellij.openapi.vfs.VirtualFile)124 Module (com.intellij.openapi.module.Module)54 Project (com.intellij.openapi.project.Project)51 Nullable (org.jetbrains.annotations.Nullable)38 PsiDirectory (com.intellij.psi.PsiDirectory)24 NotNull (org.jetbrains.annotations.NotNull)24 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)16 PsiFile (com.intellij.psi.PsiFile)15 ArrayList (java.util.ArrayList)15 IdeView (com.intellij.ide.IdeView)11 OrderEntry (com.intellij.openapi.roots.OrderEntry)10 ProjectRootManager (com.intellij.openapi.roots.ProjectRootManager)7 THashSet (gnu.trove.THashSet)6 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)5 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)4 List (java.util.List)4 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)3 Presentation (com.intellij.openapi.actionSystem.Presentation)3 CompilerManager (com.intellij.openapi.compiler.CompilerManager)3