Search in sources :

Example 31 with ProjectFileIndex

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

the class CreateClassAction method isAvailable.

private boolean isAvailable(@NotNull DataContext dataContext) {
    Project project = CommonDataKeys.PROJECT.getData(dataContext);
    IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
    if (project == null || view == null || view.getDirectories().length == 0) {
        return false;
    }
    ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
    for (PsiDirectory dir : view.getDirectories()) {
        if (projectFileIndex.isUnderSourceRootOfType(dir.getVirtualFile(), JavaModuleSourceRootTypes.SOURCES) && checkPackageExists(dir)) {
            return true;
        }
    }
    return false;
}
Also used : Project(com.intellij.openapi.project.Project) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) IdeView(com.intellij.ide.IdeView)

Example 32 with ProjectFileIndex

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

the class CreateLibraryFromFilesAction method update.

@Override
public void update(@NotNull AnActionEvent e) {
    final Project project = getEventProject(e);
    boolean visible = false;
    if (project != null && ModuleManager.getInstance(project).getModules().length > 0) {
        final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
        for (VirtualFile root : getRoots(e)) {
            if (!root.isInLocalFileSystem() && FileUtilRt.extensionEquals(root.getName(), "jar") && !fileIndex.isInLibraryClasses(root)) {
                visible = true;
                break;
            }
        }
    }
    Presentation presentation = e.getPresentation();
    presentation.setVisible(visible);
    presentation.setEnabled(visible);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) Presentation(com.intellij.openapi.actionSystem.Presentation)

Example 33 with ProjectFileIndex

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

the class JavaSourceAction method isAvailable.

protected static boolean isAvailable(DataContext dataContext) {
    final Module module = LangDataKeys.MODULE.getData(dataContext);
    final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
    if (module == null || view == null || view.getDirectories().length == 0 || AndroidFacet.getInstance(module) == null) {
        return false;
    }
    final ProjectFileIndex projectIndex = ProjectRootManager.getInstance(module.getProject()).getFileIndex();
    final JavaDirectoryService dirService = JavaDirectoryService.getInstance();
    for (PsiDirectory dir : view.getDirectories()) {
        if (projectIndex.isUnderSourceRootOfType(dir.getVirtualFile(), JavaModuleSourceRootTypes.SOURCES) && dirService.getPackage(dir) != null && !dirService.getPackage(dir).getQualifiedName().isEmpty()) {
            return true;
        }
    }
    return false;
}
Also used : ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) PsiDirectory(com.intellij.psi.PsiDirectory) Module(com.intellij.openapi.module.Module) IdeView(com.intellij.ide.IdeView) JavaDirectoryService(com.intellij.psi.JavaDirectoryService)

Example 34 with ProjectFileIndex

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

the class LegacyNewAndroidComponentAction method isAvailable.

private static boolean isAvailable(DataContext dataContext) {
    final Module module = LangDataKeys.MODULE.getData(dataContext);
    final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
    if (module == null || view == null || view.getDirectories().length == 0) {
        return false;
    }
    final AndroidFacet facet = AndroidFacet.getInstance(module);
    if (facet == null || facet.requiresAndroidModel()) {
        return false;
    }
    final ProjectFileIndex projectIndex = ProjectRootManager.getInstance(module.getProject()).getFileIndex();
    final JavaDirectoryService dirService = JavaDirectoryService.getInstance();
    for (PsiDirectory dir : view.getDirectories()) {
        if (projectIndex.isUnderSourceRootOfType(dir.getVirtualFile(), JavaModuleSourceRootTypes.SOURCES) && dirService.getPackage(dir) != null) {
            return true;
        }
    }
    return false;
}
Also used : ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) PsiDirectory(com.intellij.psi.PsiDirectory) Module(com.intellij.openapi.module.Module) IdeView(com.intellij.ide.IdeView) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) JavaDirectoryService(com.intellij.psi.JavaDirectoryService)

Example 35 with ProjectFileIndex

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

the class IncludeModuleForFileAction method findTarget.

@Nullable
private static VirtualFile findTarget(@NotNull AnActionEvent e, @NotNull Project project) {
    VirtualFile[] virtualFiles = VIRTUAL_FILE_ARRAY.getData(e.getDataContext());
    if (virtualFiles != null && virtualFiles.length == 1) {
        VirtualFile target = virtualFiles[0];
        if (isModuleSourceRoot(target, project) || project.getBaseDir().equals(target)) {
            // Module folders and project folder are ignored.
            return null;
        }
        ProjectFileIndex projectIndex = ProjectRootManager.getInstance(project).getFileIndex();
        if (projectIndex.isExcluded(target)) {
            // Excluded folders are ignored.
            return null;
        }
        return target;
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) Nullable(org.jetbrains.annotations.Nullable)

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