@Override public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) { registrar.registerReferenceProvider(PlatformPatterns.psiElement(YAMLScalar.class), new PsiReferenceProvider() { @NotNull @Override public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) { if (isConfigFile(element)) { String valueText = ((YAMLScalar) element).getTextValue(); List<MacroResolver.Match> matches = new MacroResolver().resolve(valueText); List<PsiReference> references = new ArrayList<>(); matches.stream() .filter(match -> !match.isEscaped()) .map(match -> resolvePsiReferences(element, match.getReference(), (element instanceof YAMLQuotedText ? 1 : 0) + match.getStartPos())) .forEach(references::addAll); return references.toArray(new PsiReference[references.size()]); } return PsiReference.EMPTY_ARRAY; } }); }
@Override public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) { registrar.registerReferenceProvider(PlatformPatterns.psiElement(PsiLiteralExpression.class), new PsiReferenceProvider() { @NotNull @Override public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) { if (isLiteralOfConfigurationAnnotation(element) || isCoffigMethod(element)) { PsiLiteralExpression literalExpression = (PsiLiteralExpression) element; String value = literalExpression.getValue() instanceof String ? (String) literalExpression.getValue() : null; List<PsiReference> psiReferences = resolvePsiReferences(element, value, 1); return psiReferences.toArray(new PsiReference[psiReferences.size()]); } return PsiReference.EMPTY_ARRAY; } }); }
PsiReferenceProvider createTagsReferenceProvider() { return new PsiReferenceProvider() { @NotNull @Override public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) { return Optional.ofNullable(element.getText()) .map(text -> new PsiReference[]{ new TagReference( element, element.getText(), traversal)}) .orElse(TagReference.EMPTY_ARRAY); } }; }
private void registerNamedReferenceProvider(@NotNull String[] names, final PsiNamePatternCondition<?> nameCondition, @NotNull Class scopeClass, final boolean caseSensitive, @NotNull PsiReferenceProvider provider, final double priority, @NotNull ElementPattern pattern) { NamedObjectProviderBinding providerBinding = myNamedBindingsMap.get(scopeClass); if (providerBinding == null) { myNamedBindingsMap.put(scopeClass, providerBinding = new NamedObjectProviderBinding() { @Override protected String getName(@NotNull final PsiElement position) { return nameCondition.getPropertyValue(position); } }); } providerBinding.registerProvider(names, pattern, caseSensitive, provider, priority); }
public void registerProvider(@NonNls @NotNull String[] names, @NotNull ElementPattern filter, boolean caseSensitive, @NotNull PsiReferenceProvider provider, final double priority) { final Map<String, List<ProviderInfo<ElementPattern>>> map = caseSensitive ? myNamesToProvidersMap : myNamesToProvidersMapInsensitive; for (final String attributeName : names) { String key = caseSensitive ? attributeName : attributeName.toLowerCase(); List<ProviderInfo<ElementPattern>> psiReferenceProviders = map.get(key); if (psiReferenceProviders == null) { map.put(key, psiReferenceProviders = new SmartList<ProviderInfo<ElementPattern>>()); } psiReferenceProviders.add(new ProviderInfo<ElementPattern>(provider, filter, priority)); } }
@Override public void registerReferenceProviders(PsiReferenceRegistrar registrar) { // references from same language registrar.registerReferenceProvider( PlatformPatterns.psiElement(KUserId.class).withLanguage(KLanguage.INSTANCE), new PsiReferenceProvider() { @NotNull @Override public PsiReference[] getReferencesByElement(PsiElement element, ProcessingContext context) { if (element instanceof KUserId) { final String key = element.getText(); return new PsiReference[]{new KReference((KUserId)element, new TextRange(0, key.length()))}; } return new PsiReference[0]; } } ); }
@Override public void addAcceptableReferenceProviders(@NotNull PsiElement position, @NotNull List<ProviderInfo<Provider, ProcessingContext>> list, @NotNull PsiReferenceService.Hints hints) { for (ProviderInfo<Provider, ElementPattern> trinity : myProviderPairs) { if (hints != PsiReferenceService.Hints.NO_HINTS && !((PsiReferenceProvider)trinity.provider).acceptsHints(position, hints)) { continue; } final ProcessingContext context = new ProcessingContext(); if (hints != PsiReferenceService.Hints.NO_HINTS) { context.put(PsiReferenceService.HINTS, hints); } boolean suitable = false; try { suitable = trinity.processingContext.accepts(position, context); } catch (IndexNotReadyException ignored) { } if (suitable) { list.add(new ProviderInfo<Provider, ProcessingContext>(trinity.provider, context, trinity.priority)); } } }
private void registerNamedReferenceProvider(@NotNull String[] names, final PsiNamePatternCondition<?> nameCondition, @NotNull Class scopeClass, final boolean caseSensitive, @NotNull PsiReferenceProvider provider, final double priority, @NotNull ElementPattern pattern) { NamedObjectProviderBinding<PsiReferenceProvider> providerBinding = myNamedBindingsMap.get(scopeClass); if (providerBinding == null) { myNamedBindingsMap.put(scopeClass, providerBinding = new NamedObjectProviderBinding<PsiReferenceProvider>() { @Override protected String getName(final PsiElement position) { return nameCondition.getPropertyValue(position); } }); } providerBinding.registerProvider(names, pattern, caseSensitive, provider, priority); }
@NotNull List<ProviderBinding.ProviderInfo<PsiReferenceProvider,ProcessingContext>> getPairsByElement(@NotNull PsiElement element, @NotNull PsiReferenceService.Hints hints) { final Class<? extends PsiElement> clazz = element.getClass(); List<ProviderBinding.ProviderInfo<PsiReferenceProvider, ProcessingContext>> ret = null; for (Class aClass : myKnownSupers.get(clazz)) { SimpleProviderBinding<PsiReferenceProvider> simpleBinding = myBindingsMap.get(aClass); NamedObjectProviderBinding<PsiReferenceProvider> namedBinding = myNamedBindingsMap.get(aClass); if (simpleBinding == null && namedBinding == null) continue; if (ret == null) ret = new SmartList<ProviderBinding.ProviderInfo<PsiReferenceProvider, ProcessingContext>>(); if (simpleBinding != null) { simpleBinding.addAcceptableReferenceProviders(element, ret, hints); } if (namedBinding != null) { namedBinding.addAcceptableReferenceProviders(element, ret, hints); } } return ret == null ? Collections.<ProviderBinding.ProviderInfo<PsiReferenceProvider, ProcessingContext>>emptyList() : ret; }
private void addMatchingProviders(final PsiElement position, @Nullable final List<ProviderInfo<Provider, ElementPattern>> providerList, @NotNull List<ProviderInfo<Provider, ProcessingContext>> ret, PsiReferenceService.Hints hints) { if (providerList == null) return; for(ProviderInfo<Provider, ElementPattern> trinity:providerList) { if (hints != PsiReferenceService.Hints.NO_HINTS && !((PsiReferenceProvider)trinity.provider).acceptsHints(position, hints)) { continue; } final ProcessingContext context = new ProcessingContext(); if (hints != PsiReferenceService.Hints.NO_HINTS) { context.put(PsiReferenceService.HINTS, hints); } boolean suitable = false; try { suitable = trinity.processingContext.accepts(position, context); } catch (IndexNotReadyException ignored) { } if (suitable) { ret.add(new ProviderInfo<Provider,ProcessingContext>(trinity.provider, context, trinity.priority)); } } }
@Override public void addAcceptableReferenceProviders(@Nonnull PsiElement position, @Nonnull List<ProviderInfo<Provider, ProcessingContext>> list, @Nonnull PsiReferenceService.Hints hints) { for (ProviderInfo<Provider, ElementPattern> trinity : myProviderPairs) { if (hints != PsiReferenceService.Hints.NO_HINTS && !((PsiReferenceProvider)trinity.provider).acceptsHints(position, hints)) { continue; } final ProcessingContext context = new ProcessingContext(); if (hints != PsiReferenceService.Hints.NO_HINTS) { context.put(PsiReferenceService.HINTS, hints); } boolean suitable = false; try { suitable = trinity.processingContext.accepts(position, context); } catch (IndexNotReadyException ignored) { } if (suitable) { list.add(new ProviderInfo<Provider, ProcessingContext>(trinity.provider, context, trinity.priority)); } } }
private void registerNamedReferenceProvider(@Nonnull String[] names, final PsiNamePatternCondition<?> nameCondition, @Nonnull Class scopeClass, final boolean caseSensitive, @Nonnull PsiReferenceProvider provider, final double priority, @Nonnull ElementPattern pattern) { NamedObjectProviderBinding<PsiReferenceProvider> providerBinding = myNamedBindingsMap.get(scopeClass); if (providerBinding == null) { providerBinding = ConcurrencyUtil.cacheOrGet(myNamedBindingsMap, scopeClass, new NamedObjectProviderBinding<PsiReferenceProvider>() { @Override protected String getName(final PsiElement position) { return nameCondition.getPropertyValue(position); } }); } providerBinding.registerProvider(names, pattern, caseSensitive, provider, priority); }
@Nonnull List<ProviderBinding.ProviderInfo<PsiReferenceProvider,ProcessingContext>> getPairsByElement(@Nonnull PsiElement element, @Nonnull PsiReferenceService.Hints hints) { final Class<? extends PsiElement> clazz = element.getClass(); List<ProviderBinding.ProviderInfo<PsiReferenceProvider, ProcessingContext>> ret = null; for (Class aClass : myKnownSupers.get(clazz)) { SimpleProviderBinding<PsiReferenceProvider> simpleBinding = myBindingsMap.get(aClass); NamedObjectProviderBinding<PsiReferenceProvider> namedBinding = myNamedBindingsMap.get(aClass); if (simpleBinding == null && namedBinding == null) continue; if (ret == null) ret = new SmartList<ProviderBinding.ProviderInfo<PsiReferenceProvider, ProcessingContext>>(); if (simpleBinding != null) { simpleBinding.addAcceptableReferenceProviders(element, ret, hints); } if (namedBinding != null) { namedBinding.addAcceptableReferenceProviders(element, ret, hints); } } return ret == null ? Collections.<ProviderBinding.ProviderInfo<PsiReferenceProvider, ProcessingContext>>emptyList() : ret; }
private void addMatchingProviders(final PsiElement position, @Nullable final List<ProviderInfo<Provider, ElementPattern>> providerList, @Nonnull List<ProviderInfo<Provider, ProcessingContext>> ret, PsiReferenceService.Hints hints) { if (providerList == null) return; for(ProviderInfo<Provider, ElementPattern> trinity:providerList) { if (hints != PsiReferenceService.Hints.NO_HINTS && !((PsiReferenceProvider)trinity.provider).acceptsHints(position, hints)) { continue; } final ProcessingContext context = new ProcessingContext(); if (hints != PsiReferenceService.Hints.NO_HINTS) { context.put(PsiReferenceService.HINTS, hints); } boolean suitable = false; try { suitable = trinity.processingContext.accepts(position, context); } catch (IndexNotReadyException ignored) { } if (suitable) { ret.add(new ProviderInfo<Provider,ProcessingContext>(trinity.provider, context, trinity.priority)); } } }
public void registerReferenceProviders(PsiReferenceRegistrar registrar) { registrar.registerReferenceProvider(psiElement(XmlAttributeValue.class).withParent(xmlAttribute().withLocalName("name", "href", "mode", "elements", "exclude-result-prefixes", "extension-element-prefixes", "stylesheet-prefix").withParent(xmlTag().withNamespace(XsltSupport.XSLT_NS))), new XsltReferenceProvider()); registrar.registerReferenceProvider(xmlAttributeValue().withValue(string().matches("[^()]+")).withParent(xmlAttribute("as").withParent(xmlTag().withNamespace(XsltSupport.XSLT_NS))), SchemaTypeProvider.INSTANCE); registrar.registerReferenceProvider(xmlAttributeValue().withParent(xmlAttribute("as").withParent(xmlTag().withNamespace(XsltSupport.XSLT_NS))).withValue(string().contains(":")), new PsiReferenceProvider() { @NotNull @Override public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) { return new PsiReference[]{new NamespacePrefixReference(element)}; } }); }
@NotNull @Override public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) { List<PsiReference> result = new ArrayList<>(); for (PsiReferenceProvider provider : providers) { result.addAll(Arrays.asList(provider.getReferencesByElement(element, context))); } return result.toArray(new PsiReference[result.size()]); }
PsiReferenceProvider createLocalReferenceProvider() { return new PsiReferenceProvider() { @NotNull @Override public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) { return Optional.ofNullable(element.getText()) .map(text -> new PsiReference[]{new LocalReference(element, StringUtils.removeAllQuotes(text)) }).orElse(LocalReference.EMPTY_ARRAY); } }; }
PsiReferenceProvider createFileReferenceProvider() { return new PsiReferenceProvider() { @NotNull @Override public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) { return Optional.ofNullable(element.getText()) .map(text -> new PsiReference[]{ new FileReference(element, StringUtils.removeAllQuotes(text)) }).orElse(FileReference.EMPTY_ARRAY); } }; }
PsiReferenceProvider createComponentFileReferenceProvider() { return new PsiReferenceProvider() { @NotNull @Override public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) { return Optional.ofNullable(element.getText()) .map(text -> new PsiReference[]{ new ComponentFileReference(element, StringUtils.removeAllQuotes(text)) }).orElse(FileReference.EMPTY_ARRAY); } }; }
PsiReferenceProvider createExternalDefinitionsInRootReferenceProvider() { return new PsiReferenceProvider() { @NotNull @Override public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) { return Optional.ofNullable(element.getText()) .map(text -> new PsiReference[]{ new DefinitionsInRootReference(element, StringUtils.removeAllQuotes(text)) }).orElse(DefinitionsInRootReference.EMPTY_ARRAY); } }; }
PsiReferenceProvider createExternalDefinitionsNotInRootReferenceProvider() { return new PsiReferenceProvider() { @NotNull @Override public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) { return Optional.ofNullable(element.getText()) .map(text -> new PsiReference[]{ new DefinitionsNotInRootReference(element, StringUtils.removeAllQuotes(text)) }).orElse(DefinitionsNotInRootReference.EMPTY_ARRAY); } }; }
PsiReferenceProvider createFileReferenceProvider() { return new PsiReferenceProvider() { @NotNull @Override public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) { return Optional.ofNullable(element.getText()) .map(text -> new PsiReference[]{ new FileReference( element, StringUtils.removeAllQuotes(text)) }).orElse(FileReference.EMPTY_ARRAY); } }; }
@Override public void unregisterProvider(@NotNull final PsiReferenceProvider provider) { for (final ProviderInfo<ElementPattern> trinity : new ArrayList<ProviderInfo<ElementPattern>>(myProviderPairs)) { if (trinity.provider.equals(provider)) { myProviderPairs.remove(trinity); } } }
public TemplateFileReferenceSet(String text, @NotNull PsiElement element, @Nullable PsiReferenceProvider provider) { super(text, element, detectShift(element, text), provider, SystemInfo.isFileSystemCaseSensitive); mySeparatorString = detectSeparator(element); reparse(); }
public RootFileReferenceSet(String str, @NotNull PsiElement element, int startInElement, PsiReferenceProvider provider, boolean caseSensitive, boolean endingSlashNotAllowed, @Nullable FileType[] suitableFileTypes) { super(str, element, startInElement, provider, caseSensitive, endingSlashNotAllowed, suitableFileTypes); }
public PyStringLiteralFileReferenceSet(@NotNull String str, @NotNull PyStringLiteralExpression element, int startInElement, PsiReferenceProvider provider, boolean caseSensitive, boolean endingSlashNotAllowed, @Nullable FileType[] suitableFileTypes) { super(str, element, startInElement, provider, caseSensitive, endingSlashNotAllowed, suitableFileTypes); myStringLiteralExpression = element; reparse(); }
@Override public void processQuery(ReferencesSearch.SearchParameters searchParameters, final Processor<PsiReference> processor) { if (!(searchParameters.getElementToSearch() instanceof PhpDocProperty)) { return; } final PhpDocProperty property = (PhpDocProperty) searchParameters.getElementToSearch(); PsiReferenceProvider[] providers = new PsiReferenceProvider[]{ new CollectionPropertyReferenceProvider(), new SetValueReferenceProvider(), }; PsiSearchHelper.SERVICE.getInstance(property.getProject()) .processElementsWithWord((psiElement, i) -> { if (!(psiElement instanceof StringLiteralExpression)) { return true; } ProcessingContext processingContext = new ProcessingContext(); processingContext.put("field", property.getName()); for (PsiReferenceProvider provider : providers) { for (PsiReference reference : provider.getReferencesByElement(psiElement, processingContext)) { if (reference.isReferenceTo(searchParameters.getElementToSearch())) { processor.process(reference); } } } return true; }, searchParameters.getScopeDeterminedByUser(), property.getName(), UsageSearchContext.IN_STRINGS, true); }
/** * @deprecated {@see com.intellij.psi.PsiReferenceContributor */ public void registerReferenceProvider(@Nullable ElementFilter elementFilter, @Nonnull Class scope, @Nonnull PsiReferenceProvider provider, double priority) { PsiElementPattern.Capture<PsiElement> capture = PlatformPatterns.psiElement(scope); registerReferenceProvider(capture.and(new FilterPattern(elementFilter)), provider, priority); }
private void registerExternalMacroLibraryProvider(PsiReferenceRegistrar registrar) { registrar.registerReferenceProvider(VTLMACROLIBRARY_COMMENT, new PsiReferenceProvider() { @NotNull public PsiReference[] getReferencesByElement(@NotNull final PsiElement element, @NotNull final ProcessingContext context) { final List<PsiReference> result = new SmartList<PsiReference>(); if (findAndAddReferencesByElement(element, "path=\"", "\"", result)) { findAndAddReferencesByElement(element, "file=\"", "\"", result); } return result.toArray(PsiReference.EMPTY_ARRAY); } }); }
private void registerVelocityPropertiesProvider(PsiReferenceRegistrar registrar) { registrar.registerReferenceProvider(VELOCITY_PROPERTIES_COMMENT, new PsiReferenceProvider() { @NotNull public PsiReference[] getReferencesByElement(@NotNull final PsiElement element, @NotNull final ProcessingContext context) { final List<PsiReference> result = new SmartList<PsiReference>(); if (findAndAddReferencesByElement(element, "path=\"", "\"", result)) { findAndAddReferencesByElement(element, "runtime_root=\"", "\"", result); findAndAddReferencesByElement(element, "file=\"", "\"", result); } return result.toArray(PsiReference.EMPTY_ARRAY); } }); }
public void testCustomReferenceProvider() throws Exception { PsiReferenceRegistrarImpl registrar = (PsiReferenceRegistrarImpl) ReferenceProvidersRegistry.getInstance().getRegistrar(JavaLanguage.INSTANCE); PsiReferenceProvider provider = new PsiReferenceProvider() { @Override @NotNull public PsiReference[] getReferencesByElement(@NotNull final PsiElement element, @NotNull final ProcessingContext context) { return new PsiReference[]{new PsiReferenceBase<PsiElement>(element) { @Override public PsiElement resolve() { return element; } @Override @NotNull public Object[] getVariants() { return new Object[]{"1", "2", "3"}; } }}; } }; try { registrar.registerReferenceProvider(PsiDocTag.class, provider); configureByFile("ReferenceProvider.java"); assertStringItems("1", "2", "3"); } finally { registrar.unregisterReferenceProvider(PsiDocTag.class, provider); } }
public CompositeReferenceProvider(PsiReferenceProvider ...providers) { this.providers = providers; }
@Nullable public PsiReferenceProvider getProvider() { return myProvider; }
@Override public PsiReferenceProvider getClassReferenceProvider() { return myProvider; }
void registerProvider(@NotNull PsiReferenceProvider provider, @NotNull ElementPattern pattern, double priority) { myProviderPairs.add(new ProviderInfo<ElementPattern>(provider, pattern, priority)); }
public void unregisterReferenceProvider(@NotNull Class scope, @NotNull PsiReferenceProvider provider) { myBindingsMap.get(scope).unregisterProvider(provider); }
public ProviderInfo(@NotNull PsiReferenceProvider provider, @NotNull Context processingContext, double priority) { this.provider = provider; this.processingContext = processingContext; this.priority = priority; }
public TemplateFileReferenceSet(@NotNull PsiElement element, @Nullable PsiReferenceProvider provider) { this(str(element), element, provider); }
public RootFileReferenceSet(String s, @NotNull PsiElement element, int offset, PsiReferenceProvider provider, boolean sensitive) { super(s, element, offset, provider, sensitive); }