Java Code Examples for com.intellij.util.indexing.FileBasedIndex#getInstance()
The following examples show how to use
com.intellij.util.indexing.FileBasedIndex#getInstance() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FileModuleIndexService.java From reasonml-idea-plugin with MIT License | 6 votes |
@NotNull public List<FileBase> getFiles(@NotNull Project project, @NotNull GlobalSearchScope scope) { List<FileBase> result = new ArrayList<>(); FileBasedIndex fileIndex = FileBasedIndex.getInstance(); ID<String, FileModuleData> indexId = m_index.getName(); Collection<String> allKeys = fileIndex.getAllKeys(indexId, project); LOG.debug("all keys (" + allKeys.size() + "): " + Joiner.join(", ", allKeys)); for (String key : allKeys) { if (!"Pervasives".equals(key)) { Collection<PsiModule> psiModules = ModuleIndex.getInstance().get(key, project, scope); for (PsiModule psiModule : psiModules) { result.add((FileBase) psiModule.getContainingFile()); } } } return result; }
Example 2
Source File: FileModuleIndexService.java From reasonml-idea-plugin with MIT License | 6 votes |
@NotNull Collection<IndexedFileModule> getFilesForNamespace(@NotNull String namespace, @NotNull GlobalSearchScope scope) { Collection<IndexedFileModule> result = new ArrayList<>(); FileBasedIndex fileIndex = FileBasedIndex.getInstance(); if (scope.getProject() != null) { for (String key : fileIndex.getAllKeys(m_index.getName(), scope.getProject())) { List<FileModuleData> values = fileIndex.getValues(m_index.getName(), key, scope); int valuesSize = values.size(); if (valuesSize > 2) { System.out.println("ERROR, size of " + key + " is " + valuesSize); } else { for (FileModuleData value : values) { if (valuesSize == 1 || value.isInterface()) { if (namespace.equals(value.getNamespace())) { result.add(value); } } } } } } return result; }
Example 3
Source File: TYPO3DetectionListener.java From idea-php-typo3-plugin with MIT License | 6 votes |
@Override public void projectOpened(@NotNull Project project) { this.checkProject(project); TYPO3CMSSettings instance = TYPO3CMSSettings.getInstance(project); IdeaPluginDescriptor plugin = PluginManager.getPlugin(PluginId.getId("com.cedricziel.idea.typo3")); if (plugin == null) { return; } String version = instance.getVersion(); if (version == null || !plugin.getVersion().equals(version)) { instance.setVersion(plugin.getVersion()); FileBasedIndex index = FileBasedIndex.getInstance(); index.scheduleRebuild(CoreServiceMapStubIndex.KEY, new Throwable()); index.scheduleRebuild(ExtensionNameStubIndex.KEY, new Throwable()); index.scheduleRebuild(IconIndex.KEY, new Throwable()); index.scheduleRebuild(ResourcePathIndex.KEY, new Throwable()); index.scheduleRebuild(RouteIndex.KEY, new Throwable()); index.scheduleRebuild(TablenameFileIndex.KEY, new Throwable()); index.scheduleRebuild(LegacyClassesForIDEIndex.KEY, new Throwable()); index.scheduleRebuild(MethodArgumentDroppedIndex.KEY, new Throwable()); index.scheduleRebuild(ControllerActionIndex.KEY, new Throwable()); } }
Example 4
Source File: CoreServiceParser.java From idea-php-typo3-plugin with MIT License | 6 votes |
private void collectServices(Project project) { FileBasedIndex index = FileBasedIndex.getInstance(); Collection<VirtualFile> containingFiles = index.getContainingFiles( FileTypeIndex.NAME, PhpFileType.INSTANCE, GlobalSearchScope.allScope(project) ); containingFiles.removeIf(virtualFile -> !(virtualFile.getName().contains("ext_localconf.php"))); for (VirtualFile projectFile : containingFiles) { PsiFile psiFile = PsiManager.getInstance(project).findFile(projectFile); if (psiFile != null) { CoreServiceDefinitionParserVisitor visitor = new CoreServiceDefinitionParserVisitor(serviceMap); psiFile.accept(visitor); serviceMap.putAll(visitor.getServiceMap()); } } }
Example 5
Source File: TwigUtil.java From idea-php-symfony2-plugin with MIT License | 6 votes |
/** * Get all macros inside file * * {% macro foobar %}{% endmacro %} * {% macro input(name, value, type, size) %}{% endmacro %} */ @NotNull public static Collection<TwigMacroTagInterface> getMacros(@NotNull PsiFile file) { Collection<TwigMacroTagInterface> macros = new ArrayList<>(); Collection<String> keys = new ArrayList<>(); FileBasedIndex fileBasedIndex = FileBasedIndex.getInstance(); fileBasedIndex.processAllKeys(TwigMacroFunctionStubIndex.KEY, s -> { keys.add(s); return true; }, GlobalSearchScope.fileScope(file), null); for (String key : keys) { macros.addAll(fileBasedIndex.getValues(TwigMacroFunctionStubIndex.KEY, key, GlobalSearchScope.fileScope(file))); } return macros; }
Example 6
Source File: IndexTodoCacheManagerImpl.java From consulo with Apache License 2.0 | 6 votes |
@Override @Nonnull 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); }
Example 7
Source File: ProjectRootManagerComponent.java From consulo with Apache License 2.0 | 5 votes |
@Override protected void doSynchronizeRoots() { if (!myStartupActivityPerformed) return; if (myDoLogCachesUpdate) { LOG.debug(new Throwable("sync roots")); } else if (!ApplicationManager.getApplication().isUnitTestMode()) LOG.info("project roots have changed"); DumbServiceImpl dumbService = DumbServiceImpl.getInstance(myProject); if (FileBasedIndex.getInstance() instanceof FileBasedIndexImpl) { dumbService.queueTask(new UnindexedFilesUpdater(myProject)); } }
Example 8
Source File: IndexTodoCacheManagerImpl.java From consulo with Apache License 2.0 | 5 votes |
@Override public int getTodoCount(@Nonnull final VirtualFile file, @Nonnull final IndexPatternProvider patternProvider) { if (myProject.isDefault()) { return 0; } if (file instanceof VirtualFileWindow) return -1; final FileBasedIndex fileBasedIndex = FileBasedIndex.getInstance(); return Arrays.stream(patternProvider.getIndexPatterns()).mapToInt(indexPattern -> fetchCount(fileBasedIndex, file, indexPattern)).sum(); }
Example 9
Source File: EnvironmentVariablesApi.java From idea-php-dotenv-plugin with MIT License | 4 votes |
@NotNull public static Map<String, String> getAllKeyValues(Project project) { FileBasedIndex fileBasedIndex = FileBasedIndex.getInstance(); Map<String, String> keyValues = new HashMap<>(); Map<String, String> secondaryKeyValues = new HashMap<>(); Map<VirtualFile, FileAcceptResult> resultsCache = new HashMap<>(); fileBasedIndex.processAllKeys(DotEnvKeyValuesIndex.KEY, s -> { for(VirtualFile virtualFile : fileBasedIndex.getContainingFiles(DotEnvKeyValuesIndex.KEY, s, GlobalSearchScope.allScope(project))) { FileAcceptResult fileAcceptResult; if(resultsCache.containsKey(virtualFile)) { fileAcceptResult = resultsCache.get(virtualFile); } else { fileAcceptResult = getFileAcceptResult(virtualFile); resultsCache.put(virtualFile, fileAcceptResult); } if(!fileAcceptResult.isAccepted()) { continue; } EnvironmentKeyValue keyValue = EnvironmentVariablesUtil.getKeyValueFromString(s); if(fileAcceptResult.isPrimary()) { if(keyValues.containsKey(keyValue.getKey())) return true; keyValues.put(keyValue.getKey(), keyValue.getValue()); } else { if(!secondaryKeyValues.containsKey(keyValue.getKey())) { secondaryKeyValues.put(keyValue.getKey(), keyValue.getValue()); } } } return true; }, project); return keyValues.size() > 0 ? keyValues : secondaryKeyValues; }