Search in sources :

Example 86 with ProjectFileIndex

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

the class AndroidSdkResolveScopeProvider method getResolveScope.

@Nullable
@Override
public GlobalSearchScope getResolveScope(@NotNull VirtualFile file, Project project) {
    if (!ProjectFacetManager.getInstance(project).hasFacets(AndroidFacet.ID))
        return null;
    ProjectFileIndex index = ProjectRootManager.getInstance(project).getFileIndex();
    JdkOrderEntry entry = ContainerUtil.findInstance(index.getOrderEntriesForFile(file), JdkOrderEntry.class);
    final Sdk sdk = entry == null ? null : entry.getJdk();
    if (sdk == null || !(sdk.getSdkType() instanceof AndroidSdkType)) {
        return null;
    }
    return new MyJdkScope(project, entry, index.isInLibrarySource(file));
}
Also used : JdkOrderEntry(com.intellij.openapi.roots.JdkOrderEntry) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) AndroidSdkType(org.jetbrains.android.sdk.AndroidSdkType) Sdk(com.intellij.openapi.projectRoots.Sdk) Nullable(org.jetbrains.annotations.Nullable)

Example 87 with ProjectFileIndex

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

the class InstantRunPositionManager method getRelPathFromSourceRoot.

@Nullable
private static String getRelPathFromSourceRoot(@NotNull Project project, @NotNull PsiFile file) {
    ProjectFileIndex fileIndex = ProjectFileIndex.SERVICE.getInstance(project);
    VirtualFile sourceRoot = fileIndex.getSourceRootForFile(file.getVirtualFile());
    if (sourceRoot == null) {
        return null;
    }
    return VfsUtilCore.getRelativePath(file.getVirtualFile(), sourceRoot);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) Nullable(org.jetbrains.annotations.Nullable)

Example 88 with ProjectFileIndex

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

the class AndroidViewProjectNode method contains.

/** Copy of {@link com.intellij.ide.projectView.impl.nodes.AbstractProjectNode#contains(VirtualFile)}*/
@Override
public boolean contains(@NotNull VirtualFile file) {
    Project project = getProject();
    assert project != null;
    ProjectFileIndex index = ProjectRootManager.getInstance(project).getFileIndex();
    VirtualFile baseDir = getProject().getBaseDir();
    return index.isInContent(file) || index.isInLibraryClasses(file) || index.isInLibrarySource(file) || (baseDir != null && isAncestor(baseDir, file, false));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex)

Example 89 with ProjectFileIndex

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

the class TestArtifactSearchScopes method get.

@Nullable
public static TestArtifactSearchScopes get(@NotNull VirtualFile file, @NotNull Project project) {
    if (GradleSyncState.getInstance(project).lastSyncFailed()) {
        return null;
    }
    ProjectFileIndex projectFileIndex = ProjectFileIndex.SERVICE.getInstance(project);
    Module module = projectFileIndex.getModuleForFile(file);
    return module != null ? get(module) : null;
}
Also used : ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) Module(com.intellij.openapi.module.Module) Nullable(org.jetbrains.annotations.Nullable)

Example 90 with ProjectFileIndex

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

the class DartAnnotator method canBeAnalyzedByServer.

@Contract("_, null -> false")
private static boolean canBeAnalyzedByServer(@NotNull final Project project, @Nullable final VirtualFile file) {
    if (!DartAnalysisServerService.isLocalAnalyzableFile(file))
        return false;
    final DartSdk sdk = DartSdk.getDartSdk(project);
    if (sdk == null || !DartAnalysisServerService.isDartSdkVersionSufficient(sdk))
        return false;
    // server can highlight files from Dart SDK, packages and from modules with enabled Dart support
    final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
    if (fileIndex.isInLibraryClasses(file))
        return true;
    final Module module = fileIndex.getModuleForFile(file);
    return module != null && DartSdkLibUtil.isDartSdkEnabled(module);
}
Also used : DartSdk(com.jetbrains.lang.dart.sdk.DartSdk) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) Module(com.intellij.openapi.module.Module) Contract(org.jetbrains.annotations.Contract)

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