Search in sources :

Example 6 with FileBasedIndex

use of com.intellij.util.indexing.FileBasedIndex in project intellij-community by JetBrains.

the class CompilerReferenceServiceImpl method getReferentFiles.

@TestOnly
@Nullable
public Set<VirtualFile> getReferentFiles(@NotNull PsiElement element) {
    FileBasedIndex fileIndex = FileBasedIndex.getInstance();
    final TIntHashSet ids = getReferentFileIds(element);
    if (ids == null)
        return null;
    Set<VirtualFile> fileSet = new THashSet<>();
    ids.forEach(id -> {
        final VirtualFile vFile = fileIndex.findFileById(myProject, id);
        assert vFile != null;
        fileSet.add(vFile);
        return true;
    });
    return fileSet;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileBasedIndex(com.intellij.util.indexing.FileBasedIndex) TIntHashSet(gnu.trove.TIntHashSet) THashSet(gnu.trove.THashSet) TestOnly(org.jetbrains.annotations.TestOnly) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with FileBasedIndex

use of com.intellij.util.indexing.FileBasedIndex in project intellij-community by JetBrains.

the class IndexTodoCacheManagerImpl method getFilesWithTodoItems.

@Override
@NotNull
public PsiFile[] getFilesWithTodoItems() {
    if (myProject.isDefault()) {
        return PsiFile.EMPTY_ARRAY;
    }
    final FileBasedIndex fileBasedIndex = FileBasedIndex.getInstance();
    final Set<PsiFile> allFiles = new HashSet<>();
    final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
    for (IndexPattern indexPattern : IndexPatternUtil.getIndexPatterns()) {
        final Collection<VirtualFile> files = fileBasedIndex.getContainingFiles(TodoIndex.NAME, new TodoIndexEntry(indexPattern.getPatternString(), indexPattern.isCaseSensitive()), GlobalSearchScope.allScope(myProject));
        ApplicationManager.getApplication().runReadAction(() -> {
            for (VirtualFile file : files) {
                if (projectFileIndex.isInContent(file)) {
                    final PsiFile psiFile = myPsiManager.findFile(file);
                    if (psiFile != null) {
                        allFiles.add(psiFile);
                    }
                }
            }
        });
    }
    return allFiles.isEmpty() ? PsiFile.EMPTY_ARRAY : PsiUtilCore.toPsiFileArray(allFiles);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) IndexPattern(com.intellij.psi.search.IndexPattern) PsiFile(com.intellij.psi.PsiFile) TodoIndexEntry(com.intellij.psi.impl.cache.impl.todo.TodoIndexEntry) FileBasedIndex(com.intellij.util.indexing.FileBasedIndex) HashSet(java.util.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with FileBasedIndex

use of com.intellij.util.indexing.FileBasedIndex in project intellij-community by JetBrains.

the class FrameworkDetectionManager method getValidDetectedFrameworks.

private List<? extends DetectedFrameworkDescription> getValidDetectedFrameworks() {
    final Set<Integer> detectors = myDetectedFrameworksData.getDetectorsForDetectedFrameworks();
    List<DetectedFrameworkDescription> descriptions = new ArrayList<>();
    final FileBasedIndex index = FileBasedIndex.getInstance();
    final DetectionExcludesConfiguration excludesConfiguration = DetectionExcludesConfiguration.getInstance(myProject);
    for (Integer id : detectors) {
        final Collection<? extends DetectedFrameworkDescription> frameworks = runDetector(id, index, excludesConfiguration, false);
        for (DetectedFrameworkDescription framework : frameworks) {
            descriptions.add(framework);
        }
    }
    return FrameworkDetectionUtil.removeDisabled(descriptions);
}
Also used : DetectedFrameworkDescription(com.intellij.framework.detection.DetectedFrameworkDescription) FileBasedIndex(com.intellij.util.indexing.FileBasedIndex) DetectionExcludesConfiguration(com.intellij.framework.detection.DetectionExcludesConfiguration)

Example 9 with FileBasedIndex

use of com.intellij.util.indexing.FileBasedIndex in project intellij-community by JetBrains.

the class JavaNullMethodArgumentUtil method findScopeWhereNullArgumentCanPass.

@Nullable
private static GlobalSearchScope findScopeWhereNullArgumentCanPass(@NotNull PsiMethod method, int parameterIndex) {
    final FileBasedIndex fileBasedIndex = FileBasedIndex.getInstance();
    final CommonProcessors.CollectProcessor<VirtualFile> collector = new CommonProcessors.CollectProcessor<>(new ArrayList<>());
    GlobalSearchScope searchScope = GlobalSearchScopeUtil.toGlobalSearchScope(method.getUseScope(), method.getProject());
    searchScope = searchScope.intersectWith(GlobalSearchScopesCore.projectProductionScope(method.getProject()));
    fileBasedIndex.getFilesWithKey(JavaNullMethodArgumentIndex.INDEX_ID, Collections.singleton(new JavaNullMethodArgumentIndex.MethodCallData(method.getName(), parameterIndex)), collector, searchScope);
    final Collection<VirtualFile> candidateFiles = collector.getResults();
    return candidateFiles.isEmpty() ? null : GlobalSearchScope.filesScope(method.getProject(), candidateFiles);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) CommonProcessors(com.intellij.util.CommonProcessors) FileBasedIndex(com.intellij.util.indexing.FileBasedIndex) Nullable(org.jetbrains.annotations.Nullable)

Example 10 with FileBasedIndex

use of com.intellij.util.indexing.FileBasedIndex in project intellij-community by JetBrains.

the class PythonMockSdk method create.

public static Sdk create(final String version, @NotNull final VirtualFile... additionalRoots) {
    final String mock_path = PythonTestUtil.getTestDataPath() + "/MockSdk" + version + "/";
    String sdkHome = new File(mock_path, "bin/python" + version).getPath();
    SdkType sdkType = PythonSdkType.getInstance();
    final Sdk sdk = new ProjectJdkImpl(MOCK_SDK_NAME + " " + version, sdkType) {

        @Override
        public String getVersionString() {
            return "Python " + version + " Mock SDK";
        }
    };
    final SdkModificator sdkModificator = sdk.getSdkModificator();
    sdkModificator.setHomePath(sdkHome);
    File libPath = new File(mock_path, "Lib");
    if (libPath.exists()) {
        sdkModificator.addRoot(LocalFileSystem.getInstance().refreshAndFindFileByIoFile(libPath), OrderRootType.CLASSES);
    }
    sdkModificator.addRoot(PyUserSkeletonsUtil.getUserSkeletonsDirectory(), OrderRootType.CLASSES);
    final LanguageLevel level = LanguageLevel.fromPythonVersion(version);
    final VirtualFile typeShedDir = PyTypeShed.INSTANCE.getDirectory();
    PyTypeShed.INSTANCE.findRootsForLanguageLevel(level).forEach(path -> {
        final VirtualFile file = typeShedDir.findFileByRelativePath(path);
        if (file != null) {
            sdkModificator.addRoot(file, OrderRootType.CLASSES);
        }
    });
    String mock_stubs_path = mock_path + PythonSdkType.SKELETON_DIR_NAME;
    sdkModificator.addRoot(LocalFileSystem.getInstance().refreshAndFindFileByPath(mock_stubs_path), PythonSdkType.BUILTIN_ROOT_TYPE);
    for (final VirtualFile root : additionalRoots) {
        sdkModificator.addRoot(root, OrderRootType.CLASSES);
    }
    sdkModificator.commitChanges();
    final FileBasedIndex index = FileBasedIndex.getInstance();
    index.requestRebuild(StubUpdatingIndex.INDEX_ID);
    index.requestRebuild(PyModuleNameIndex.NAME);
    return sdk;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PythonSdkType(com.jetbrains.python.sdk.PythonSdkType) SdkType(com.intellij.openapi.projectRoots.SdkType) LanguageLevel(com.jetbrains.python.psi.LanguageLevel) ProjectJdkImpl(com.intellij.openapi.projectRoots.impl.ProjectJdkImpl) Sdk(com.intellij.openapi.projectRoots.Sdk) SdkModificator(com.intellij.openapi.projectRoots.SdkModificator) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) FileBasedIndex(com.intellij.util.indexing.FileBasedIndex)

Aggregations

FileBasedIndex (com.intellij.util.indexing.FileBasedIndex)18 VirtualFile (com.intellij.openapi.vfs.VirtualFile)12 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)9 NotNull (org.jetbrains.annotations.NotNull)7 PsiFile (com.intellij.psi.PsiFile)4 Project (com.intellij.openapi.project.Project)3 Nullable (org.jetbrains.annotations.Nullable)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 DetectedFrameworkDescription (com.intellij.framework.detection.DetectedFrameworkDescription)2 DetectionExcludesConfiguration (com.intellij.framework.detection.DetectionExcludesConfiguration)2 JSOffsetBasedImplicitElement (com.intellij.lang.javascript.psi.impl.JSOffsetBasedImplicitElement)2 JSImplicitElementImpl (com.intellij.lang.javascript.psi.stubs.impl.JSImplicitElementImpl)2 Module (com.intellij.openapi.module.Module)2 PsiElement (com.intellij.psi.PsiElement)2 XmlFile (com.intellij.psi.xml.XmlFile)2 HashMap (com.intellij.util.containers.HashMap)2 HashSet (com.intellij.util.containers.HashSet)2 THashSet (gnu.trove.THashSet)2 InsertHandler (com.intellij.codeInsight.completion.InsertHandler)1 InsertionContext (com.intellij.codeInsight.completion.InsertionContext)1