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()); } }
private static List<XmlTag> getComponentDeclarations(String componentValue, String componentType, ID<String, Void> id, Project project, ComponentMatcher componentMatcher) { List<XmlTag> results = new ArrayList<XmlTag>(); Collection<VirtualFile> containingFiles = FileBasedIndex.getInstance() .getContainingFiles( id, componentValue, GlobalSearchScope.allScope(project) ); PsiManager psiManager = PsiManager.getInstance(project); for (VirtualFile virtualFile: containingFiles) { XmlFile xmlFile = (XmlFile)psiManager.findFile(virtualFile); if (xmlFile == null) { continue; } XmlTag rootTag = xmlFile.getRootTag(); if (rootTag == null) { continue; } collectComponentDeclarations(rootTag, results, componentValue, componentType, componentMatcher); } return results; }
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 <K, V extends Comparable> List<IndexedRelevantResource<K, V>> getResources(ID<K, V> indexId, final K key, @Nullable final Module module, @NotNull Project project, @Nullable final GlobalSearchScope additionalScope) { if (project.isDefault()) return Collections.emptyList(); final ArrayList<IndexedRelevantResource<K, V>> resources = new ArrayList<IndexedRelevantResource<K, V>>(); final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex(); FileBasedIndex.getInstance().processValues(indexId, key, null, new FileBasedIndex.ValueProcessor<V>() { @Override public boolean process(VirtualFile file, V value) { ResourceRelevance relevance = ResourceRelevance.getRelevance(file, module, fileIndex, additionalScope); resources.add(new IndexedRelevantResource<K, V>(file, key, value, relevance)); return true; } }, new AdditionalIndexedRootsScope(GlobalSearchScope.allScope(project))); return resources; }
public static <K, V extends Comparable> List<IndexedRelevantResource<K, V>> getAllResources(ID<K, V> indexId, @Nullable final Module module, @NotNull Project project, @Nullable NullableFunction<List<IndexedRelevantResource<K, V>>, IndexedRelevantResource<K, V>> chooser) { ArrayList<IndexedRelevantResource<K, V>> all = new ArrayList<IndexedRelevantResource<K, V>>(); Collection<K> allKeys = FileBasedIndex.getInstance().getAllKeys(indexId, project); for (K key : allKeys) { List<IndexedRelevantResource<K, V>> resources = getResources(indexId, key, module, project, null); if (!resources.isEmpty()) { if (chooser == null) { all.add(resources.get(0)); } else { IndexedRelevantResource<K, V> resource = chooser.fun(resources); if (resource != null) { all.add(resource); } } } } return all; }
public static List<XmlTag> getComponentDeclarations(String componentValue, String componentType, ID<String, Void> id, Project project, ComponentMatcher componentMatcher) { List<XmlTag> results = new ArrayList<XmlTag>(); Collection<VirtualFile> containingFiles = FileBasedIndex.getInstance() .getContainingFiles( id, componentValue, GlobalSearchScope.allScope(project) ); PsiManager psiManager = PsiManager.getInstance(project); for (VirtualFile virtualFile: containingFiles) { XmlFile xmlFile = (XmlFile)psiManager.findFile(virtualFile); if (xmlFile == null) { continue; } XmlTag rootTag = xmlFile.getRootTag(); if (rootTag == null) { continue; } collectComponentDeclarations(rootTag, results, componentValue, componentType, componentMatcher); } return results; }
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()); } }
@NotNull @Override protected Collection<? extends PsiElement> compute() { Collection<VirtualFile> virtualFiles = new ArrayList<>(); for(ID<String, Void> key : Arrays.asList(BladeExtendsStubIndex.KEY, BladeSectionStubIndex.KEY, BladeIncludeStubIndex.KEY, BladeEachStubIndex.KEY)) { for(String templateName: templateNames) { FileBasedIndex.getInstance().getFilesWithKey(key, new HashSet<>(Collections.singletonList(templateName)), virtualFile -> { virtualFiles.add(virtualFile); return true; }, GlobalSearchScope.getScopeRestrictedByFileTypes(GlobalSearchScope.allScope(project), BladeFileType.INSTANCE)); } } return PsiElementUtils.convertVirtualFilesToPsiFiles(project, virtualFiles); }
public static <K, V extends Comparable> List<IndexedRelevantResource<K, V>> getResources(ID<K, V> indexId, final K key, @Nullable final Module module, @NotNull Project project, @Nullable final GlobalSearchScope additionalScope) { if (project.isDefault()) return Collections.emptyList(); final ArrayList<IndexedRelevantResource<K, V>> resources = new ArrayList<IndexedRelevantResource<K, V>>(); final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex(); FileBasedIndex.getInstance().processValues(indexId, key, null, new FileBasedIndex.ValueProcessor<V>() { public boolean process(VirtualFile file, V value) { ResourceRelevance relevance = ResourceRelevance.getRelevance(file, module, fileIndex, additionalScope); if (relevance != ResourceRelevance.NONE) { resources.add(new IndexedRelevantResource<K, V>(file, key, value, relevance)); } return true; } }, new AdditionalIndexedRootsScope(GlobalSearchScope.allScope(project))); return resources; }
private static void storeAdditionalData(final JSSymbolVisitor visitor, final ID<String, Void> index, final PsiElement declaration, final String command, final String argumentText, final int offset, final String value) { final Function<String, String> converter = NAME_CONVERTERS.get(command); final String defaultName = StringUtil.unquoteString(argumentText); final String name = converter != null ? converter.fun(argumentText) : defaultName; visitor.storeAdditionalData(declaration, index.toString(), name, offset, value); visitor.storeAdditionalData(declaration, EmberSymbolIndex.INDEX_ID.toString(), name, offset, null); if (!StringUtil.equals(defaultName, name)) { visitor.storeAdditionalData(declaration, EmberSymbolIndex.INDEX_ID.toString(), defaultName, offset, null); } }
/** * @param dataHolderKey Main data to cache * @param dataHolderNames Cache extracted name Set */ static public synchronized <T> Map<String, List<T>> getSetDataCache(@NotNull final Project project, @NotNull Key<CachedValue<Map<String, List<T>>>> dataHolderKey, final @NotNull Key<CachedValue<Set<String>>> dataHolderNames, @NotNull final ID<String, T> ID, @NotNull final GlobalSearchScope scope) { CachedValue<Map<String, List<T>>> cache = project.getUserData(dataHolderKey); if(cache == null) { cache = CachedValuesManager.getManager(project).createCachedValue(() -> { Map<String, List<T>> items = new HashMap<>(); final FileBasedIndex fileBasedIndex = FileBasedIndex.getInstance(); getIndexKeysCache(project, dataHolderNames, ID).stream().forEach(service -> items.put(service, fileBasedIndex.getValues(ID, service, scope)) ); return CachedValueProvider.Result.create(items, PsiModificationTracker.MODIFICATION_COUNT); }, false); project.putUserData(dataHolderKey, cache); } return cache.getValue(); }
public static void forceReindex() { ID<?,?>[] indexIds = new ID<?,?>[] { ContainerBuilderStubIndex.KEY, ContainerParameterStubIndex.KEY, DoctrineMetadataFileStubIndex.KEY, EventAnnotationStubIndex.KEY, FileResourcesIndex.KEY, PhpTwigTemplateUsageStubIndex.KEY, RoutesStubIndex.KEY, ServicesDefinitionStubIndex.KEY, ServicesTagStubIndex.KEY, TwigExtendsStubIndex.KEY, TwigIncludeStubIndex.KEY, TwigMacroFunctionStubIndex.KEY, TranslationStubIndex.KEY, TwigBlockIndexExtension.KEY }; for(ID<?,?> id: indexIds) { FileBasedIndex.getInstance().requestRebuild(id); FileBasedIndex.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>(); FileBasedIndex.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 void assertIndex(@NotNull ID<String, ?> id, boolean notCondition, @NotNull String... keys) { for (String key : keys) { final Collection<VirtualFile> virtualFiles = new ArrayList<VirtualFile>(); FileBasedIndex.getInstance().getFilesWithKey(id, new HashSet<>(Collections.singletonList(key)), 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 <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())); }
@NotNull public static Collection<VirtualFile> findCoffigFiles(Project project) { return FileBasedIndex.getInstance().getContainingFiles( ID.create("filetypes"), CoffigYamlFileType.INSTANCE, GlobalSearchScope.allScope(project)); }
@NotNull public static Collection<LookupElement> getIndexedKeyLookup(@NotNull Project project, @NotNull ID<String, ?> var1) { Collection<LookupElement> lookupElements = new ArrayList<>(); lookupElements.addAll(SymfonyProcessors.createResult(project, var1).stream().map( s -> LookupElementBuilder.create(s).withIcon(DrupalIcons.DRUPAL)).collect(Collectors.toList()) ); return lookupElements; }
private static ThreeState isApplicable(Project project, String componentName, String tagName, final ID<String, Void> index) { final JSNamedElementProxy component = EmberIndexUtil.resolve(project, index, componentName); if (component == null) { return ThreeState.UNSURE; } return ThreeState.YES; }
@Deprecated public CollectProjectUniqueKeysStrong(@NotNull Project project, @NotNull ID<String, ?> id, @NotNull Collection<String> strongKeys) { this.project = project; this.id = id; this.strongKeys = strongKeys; this.stringSet = new HashSet<>(); }
/** * @param dataHolderKey Main data to cache * @param dataHolderNames Cache extracted name Set */ static public synchronized Map<String, List<String>> getStringDataCache(@NotNull final Project project, @NotNull Key<CachedValue<Map<String, List<String>>>> dataHolderKey, final @NotNull Key<CachedValue<Set<String>>> dataHolderNames, @NotNull final ID<String, String> ID, @NotNull final GlobalSearchScope scope) { CachedValue<Map<String, List<String>>> cache = project.getUserData(dataHolderKey); if(cache == null) { cache = CachedValuesManager.getManager(project).createCachedValue(() -> { Map<String, List<String>> strings = new HashMap<>(); final FileBasedIndex fileBasedIndex = FileBasedIndex.getInstance(); getIndexKeysCache(project, dataHolderNames, ID).stream().forEach(parameterName -> { // just for secure if(parameterName == null) { return; } strings.put(parameterName, fileBasedIndex.getValues(ID, parameterName, scope)); }); return CachedValueProvider.Result.create(strings, PsiModificationTracker.MODIFICATION_COUNT); }, false); project.putUserData(dataHolderKey, cache); } return cache.getValue(); }
/** * There several methods that just need to check for names, as they also needed for value extraction, so cache them also */ static public synchronized Set<String> getIndexKeysCache(@NotNull final Project project, @NotNull Key<CachedValue<Set<String>>> dataHolderKey, @NotNull final ID<String, ?> ID) { CachedValue<Set<String>> cache = project.getUserData(dataHolderKey); if(cache == null) { cache = CachedValuesManager.getManager(project).createCachedValue(() -> CachedValueProvider.Result.create(SymfonyProcessors.createResult(project, ID), PsiModificationTracker.MODIFICATION_COUNT), false ); project.putUserData(dataHolderKey, cache); } return cache.getValue(); }
public <T> void assertIndexContainsKeyWithValue(@NotNull ID<String, T> id, @NotNull String key, @NotNull IndexValue.Assert<T> tAssert) { List<T> values = FileBasedIndex.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())); }
/** * Force reindex of all internal file indexes */ public static void forceReindex() { ID<?,?>[] indexIds = new ID<?,?>[] { AnnotationStubIndex.KEY, AnnotationUsageIndex.KEY, }; for(ID<?,?> id: indexIds) { FileBasedIndex.getInstance().requestRebuild(id); FileBasedIndex.getInstance().scheduleRebuild(id, new Throwable()); } }
@Nonnull @Override public <K, V> Collection<VirtualFile> getContainingFiles(@Nonnull ID<K, V> indexId, @Nonnull K dataKey, @Nonnull GlobalSearchScope filter) { return Collections.emptyList(); }
@Override public <K, V> boolean processValues(@Nonnull ID<K, V> indexId, @Nonnull K dataKey, @Nullable VirtualFile inFile, @Nonnull ValueProcessor<V> processor, @Nonnull GlobalSearchScope filter) { return false; }
@Override public <K, V> boolean processFilesContainingAllKeys(@Nonnull ID<K, V> indexId, @Nonnull Collection<K> dataKeys, @Nonnull GlobalSearchScope filter, @Nullable Condition<V> valueChecker, @Nonnull Processor<VirtualFile> processor) { return false; }
@Override public <K, V> boolean getFilesWithKey(@Nonnull ID<K, V> indexId, @Nonnull Set<K> dataKeys, @Nonnull Processor<VirtualFile> processor, @Nonnull GlobalSearchScope filter) { return false; }
public UpdateData(@Nonnull Map<Key, Value> newData, @Nonnull ThrowableComputable<InputDataDiffBuilder<Key, Value>, IOException> currentDataEvaluator, @Nonnull ID<Key, Value> indexId, @Nullable ThrowableRunnable<IOException> forwardIndexUpdate) { myNewData = newData; myCurrentDataEvaluator = currentDataEvaluator; myIndexId = indexId; myForwardIndexUpdate = forwardIndexUpdate; }
@NotNull @Override public ID<String, Integer> getName() { return KEY; }
public static Collection<String> getAllKeys(ID<String, Void> id, Project project) { return FileBasedIndex.getInstance().getAllKeys(id, project); }