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;
}
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);
}
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);
}
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);
}
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;
}
Aggregations