public static void manualReindex() { ID<?, ?>[] indexIds = new ID<?, ?>[] { // php ModulePackageIndex.KEY, // xml|di configuration PluginIndex.KEY, TypeConfigurationIndex.KEY, VirtualTypeIndex.KEY, // layouts BlockClassNameIndex.KEY, BlockNameIndex.KEY, ContainerNameIndex.KEY, // events EventNameIndex.KEY, EventObserverIndex.KEY, // webapi WebApiTypeIndex.KEY, ModuleNameIndex.KEY }; for (ID<?, ?> id: indexIds) { FileBasedIndexImpl.getInstance().requestRebuild(id); FileBasedIndexImpl.getInstance().scheduleRebuild(id, new Throwable()); } }
public void assertIndex(@NotNull ID<String, ?> id, boolean notCondition, @NotNull String... keys) { for (String key : keys) { final Collection<VirtualFile> virtualFiles = new ArrayList<VirtualFile>(); FileBasedIndexImpl.getInstance().getFilesWithKey(id, new HashSet<String>(Arrays.asList(key)), new Processor<VirtualFile>() { @Override public boolean process(VirtualFile virtualFile) { virtualFiles.add(virtualFile); return true; } }, GlobalSearchScope.allScope(getProject())); if(notCondition && virtualFiles.size() > 0) { fail(String.format("Fail that ID '%s' not contains '%s'", id.toString(), key)); } else if(!notCondition && virtualFiles.size() == 0) { fail(String.format("Fail that ID '%s' contains '%s'", id.toString(), key)); } } }
public static void manualReindex() { ID<?,?>[] indexIds = new ID<?,?>[] { // php ModulePackageFileBasedIndex.NAME, EventsDeclarationsFileBasedIndex.NAME, // xml configuration // di PluginToTypeFileBasedIndex.NAME, TypeConfigurationFileBasedIndex.NAME, VirtualTypesNamesFileBasedIndex.NAME, // layouts BlockClassFileBasedIndex.NAME, BlockFileBasedIndex.NAME, ContainerFileBasedIndex.NAME, // events EventObserverFileBasedIndex.NAME, // webapi WebApiTypesFileBasedIndex.NAME }; for(ID<?,?> id: indexIds) { FileBasedIndexImpl.getInstance().requestRebuild(id); FileBasedIndexImpl.getInstance().scheduleRebuild(id, new Throwable()); } }
private void getImplementedBlocks(final Project project, VirtualFile virtualFile, final Set<VirtualFile> templatePathFiles, int depth) { if(templatePathFiles.contains(virtualFile) || depth-- <= 0) { return; } final String templateName = TemplateUtil.getTemplateName(project, virtualFile); if(templateName == null) { return; } final int finalDepth = depth; FileBasedIndexImpl.getInstance().getFilesWithKey(SmartyExtendsStubIndex.KEY, new HashSet<>(Arrays.asList(templateName)), virtualFile1 -> { templatePathFiles.add(virtualFile1); getImplementedBlocks(project, virtualFile1, templatePathFiles, finalDepth); return true; }, GlobalSearchScope.getScopeRestrictedByFileTypes(GlobalSearchScope.allScope(project), SmartyFileType.INSTANCE)); }
public void attachExtends(final SmartyFile smartyFile, final List<GotoRelatedItem> gotoRelatedItems) { final String templateName = TemplateUtil.getTemplateName(smartyFile.getProject(), smartyFile.getVirtualFile()); if(templateName == null) { return; } FileBasedIndexImpl.getInstance().getFilesWithKey(SmartyExtendsStubIndex.KEY, new HashSet<>(Arrays.asList(templateName)), virtualFile -> { PsiFile psiFile = PsiManager.getInstance(smartyFile.getProject()).findFile(virtualFile); if(psiFile != null) { gotoRelatedItems.add(new RelatedPopupGotoLineMarker.PopupGotoRelatedItem(psiFile, TemplateUtil.getTemplateName(psiFile.getProject(), psiFile.getVirtualFile())).withIcon(PhpIcons.IMPLEMENTED, PhpIcons.IMPLEMENTED)); } return true; }, GlobalSearchScope.getScopeRestrictedByFileTypes(GlobalSearchScope.allScope(smartyFile.getProject()), SmartyFileType.INSTANCE)); }
@NotNull public static Collection<ServiceResource> getIndexedBootstrapResources(@NotNull Project project, @NotNull BootstrapResource... bootstrapResources) { Collection<ServiceResource> serviceResources = new ArrayList<>(); for (BootstrapResource bootstrapResource : bootstrapResources) { for (Set<String> resources : FileBasedIndexImpl.getInstance().getValues(InitResourceServiceIndex.KEY, bootstrapResource.getText(), GlobalSearchScope.allScope(project))) { if(resources == null) { continue; } for (String s : resources) { String[] split = s.split(String.valueOf(InitResourceServiceIndex.TRIM_KEY)); if(split.length < 4) { continue; } ServiceResource e = new ServiceResource(split[0], split[1], split[2]); e.setSignature(split[3]); serviceResources.add(e); } } } return serviceResources; }
/** * Snippet target, only use ini files */ @NotNull public static Set<PsiElement> getSnippetNamespaceTargets(@NotNull Project project, @NotNull String namespace) { Set<VirtualFile> files = new HashSet<>(); FileBasedIndexImpl.getInstance().getFilesWithKey(SnippetIndex.KEY, new HashSet<>(Collections.singletonList(namespace)), virtualFile -> { if("ini".equalsIgnoreCase(virtualFile.getExtension())) { files.add(virtualFile); } return true; }, GlobalSearchScope.allScope(project)); // we are not allows to resolve inside index process PsiManager instance = PsiManager.getInstance(project); return files.stream() .map(instance::findFile) .filter(Objects::nonNull) .collect(Collectors.toSet()); }
public <T> void assertIndexContainsKeyWithValue(@NotNull ID<String, T> id, @NotNull String key, @NotNull IndexValue.Assert<T> tAssert) { List<T> values = FileBasedIndexImpl.getInstance().getValues(id, key, GlobalSearchScope.allScope(getProject())); for (T t : values) { if(tAssert.match(t)) { return; } } fail(String.format("Fail that Key '%s' matches on of '%s' values", key, values.size())); }
@Override protected void doSynchronizeRoots() { if (!myStartupActivityPerformed) return; if (myDoLogCachesUpdate) LOG.info(new Throwable("sync roots")); else LOG.info("project roots have changed"); DumbServiceImpl dumbService = DumbServiceImpl.getInstance(myProject); if (FileBasedIndex.getInstance() instanceof FileBasedIndexImpl) { dumbService.queueTask(new UnindexedFilesUpdater(myProject, false)); } }
public static Set<PsiElement> getContentIdentsTargets(final @NotNull Project project, final @NotNull VirtualFile currentFile, final @NotNull String ident) { final Set<PsiElement> psiElements = new HashSet<PsiElement>(); FileBasedIndexImpl.getInstance().getFilesWithKey(OxidContentIdentIndexer.KEY, new HashSet<String>(Arrays.asList(ident)), new Processor<VirtualFile>() { @Override public boolean process(VirtualFile virtualFile) { if (currentFile.equals(virtualFile)) { return true; } PsiFile psiFile = PsiManager.getInstance(project).findFile(virtualFile); if (psiFile == null) { return true; } psiFile.acceptChildren(new PsiRecursiveElementWalkingVisitor() { @Override public void visitElement(PsiElement element) { if(SmartyPattern.getAttributeInsideTagPattern("ident", "oxcontent").accepts(element)) { String content = element.getText(); if(StringUtils.isNotBlank(content) && content.equalsIgnoreCase(ident)) { psiElements.add(element); } } super.visitElement(element); } }); return true; } }, GlobalSearchScope.getScopeRestrictedByFileTypes(GlobalSearchScope.allScope(project), SmartyFileType.INSTANCE)); return psiElements; }
@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)); } }
public void assertIndexContainsKeyWithValue(@NotNull ID<String, String> id, @NotNull String key, @NotNull String value) { assertContainsElements(FileBasedIndexImpl.getInstance().getValues(id, key, GlobalSearchScope.allScope(getProject())), value); }
@Override public boolean acceptsFile(VirtualFile file) { FileType fileType = file.getFileType(); return fileType == XmlFileType.INSTANCE && !FileBasedIndexImpl.isProjectOrWorkspaceFile(file, fileType); }
public void attachIncludeTemplateGoto(final PsiElement sourceElement, final PsiFile psiFile, final List<PsiElement> psiTargets) { final String text = sourceElement.getText(); FileBasedIndexImpl.getInstance().getFilesWithKey(SmartyBlockStubIndex.KEY, new HashSet<>(Arrays.asList(text)), virtualFile -> { if(psiFile.getVirtualFile().equals(virtualFile)) { return true; } PsiFile psiFile1 = PsiManager.getInstance(sourceElement.getProject()).findFile(virtualFile); if(psiFile1 != null) { psiTargets.addAll(getBlockPsiElement(psiFile1, text)); } return true; }, GlobalSearchScope.getScopeRestrictedByFileTypes(GlobalSearchScope.allScope(psiFile.getProject()), SmartyFileType.INSTANCE)); }
public void attachInclude(final SmartyFile smartyFile, final List<GotoRelatedItem> gotoRelatedItems) { final String templateName = TemplateUtil.getTemplateName(smartyFile.getProject(), smartyFile.getVirtualFile()); if(templateName == null) { return; } FileBasedIndexImpl.getInstance().getFilesWithKey(SmartyIncludeStubIndex.KEY, new HashSet<>(Arrays.asList(templateName)), virtualFile -> { PsiFile psiFile = PsiManager.getInstance(smartyFile.getProject()).findFile(virtualFile); if(psiFile != null) { for(PsiElement psiElement: getIncludePsiElement(psiFile, templateName)) { gotoRelatedItems.add(new RelatedPopupGotoLineMarker.PopupGotoRelatedItem(psiElement, "Navigate to include").withIcon(PhpIcons.IMPLEMENTED, PhpIcons.IMPLEMENTED)); } } return true; }, GlobalSearchScope.getScopeRestrictedByFileTypes(GlobalSearchScope.allScope(smartyFile.getProject()), SmartyFileType.INSTANCE)); }
private ServiceInterface getFirstValue(@NotNull String key) { return FileBasedIndexImpl.getInstance().getValues(ServicesDefinitionStubIndex.KEY, key, GlobalSearchScope.allScope(getProject())).get(0); }