com.intellij.psi.PsiReferenceService Java Examples

The following examples show how to use com.intellij.psi.PsiReferenceService. 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: SingleTargetRequestResultProcessor.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public boolean processTextOccurrence(@Nonnull PsiElement element, int offsetInElement, @Nonnull final Processor<? super PsiReference> consumer) {
  if (!myTarget.isValid()) {
    return false;
  }

  final List<PsiReference> references = ourReferenceService.getReferences(element, new PsiReferenceService.Hints(myTarget, offsetInElement));
  //noinspection ForLoopReplaceableByForEach
  for (int i = 0; i < references.size(); i++) {
    PsiReference ref = references.get(i);
    ProgressManager.checkCanceled();
    if (ReferenceRange.containsOffsetInElement(ref, offsetInElement) && ref.isReferenceTo(myTarget) && !consumer.process(ref)) {
      return false;
    }
  }
  return true;
}
 
Example #2
Source File: SimpleProviderBinding.java    From consulo with Apache License 2.0 6 votes vote down vote up
@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));
    }
  }
}
 
Example #3
Source File: PsiReferenceRegistrarImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #4
Source File: NamedObjectProviderBinding.java    From consulo with Apache License 2.0 6 votes vote down vote up
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));
    }
  }
}
 
Example #5
Source File: CSharpConstantExpressionImpl.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
@RequiredReadAction
public PsiReference[] getReferences()
{
	return PsiReferenceService.getService().getContributedReferences(this);
}
 
Example #6
Source File: FindUsagesHelper.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static boolean processUsagesInText(@Nonnull final PsiElement element,
                                             @Nonnull Collection<String> stringToSearch,
                                             @Nonnull GlobalSearchScope searchScope,
                                             @Nonnull Processor<UsageInfo> processor) {
  final TextRange elementTextRange = ApplicationManager.getApplication().runReadAction(new NullableComputable<TextRange>() {
    @Override
    public TextRange compute() {
      if (!element.isValid() || element instanceof PsiCompiledElement) return null;
      return element.getTextRange();
    }
  });
  UsageInfoFactory factory = new UsageInfoFactory() {
    @Override
    public UsageInfo createUsageInfo(@Nonnull PsiElement usage, int startOffset, int endOffset) {
      if (elementTextRange != null
          && usage.getContainingFile() == element.getContainingFile()
          && elementTextRange.contains(startOffset)
          && elementTextRange.contains(endOffset)) {
        return null;
      }

      PsiReference someReference = usage.findReferenceAt(startOffset);
      if (someReference != null) {
        PsiElement refElement = someReference.getElement();
        for (PsiReference ref : PsiReferenceService.getService().getReferences(refElement, new PsiReferenceService.Hints(element, null))) {
          if (element.getManager().areElementsEquivalent(ref.resolve(), element)) {
            TextRange range = ref.getRangeInElement().shiftRight(refElement.getTextRange().getStartOffset() - usage.getTextRange().getStartOffset());
            return new UsageInfo(usage, range.getStartOffset(), range.getEndOffset(), true);
          }
        }
      }

      return new UsageInfo(usage, startOffset, endOffset, true);
    }
  };
  for (String s : stringToSearch) {
    if (!PsiSearchHelperImpl.processTextOccurrences(element, s, searchScope, processor, factory)) return false;
  }
  return true;
}
 
Example #7
Source File: CoreApplicationEnvironment.java    From consulo with Apache License 2.0 5 votes vote down vote up
public CoreApplicationEnvironment(@Nonnull Disposable parentDisposable) {
  myParentDisposable = parentDisposable;

  myFileTypeRegistry = new CoreFileTypeRegistry();

  myApplication = createApplication(myParentDisposable);
  ApplicationManager.setApplication(myApplication, myParentDisposable);
  myLocalFileSystem = createLocalFileSystem();
  myJarFileSystem = createJarFileSystem();

  final InjectingContainer appContainer = myApplication.getInjectingContainer();
  registerComponentInstance(appContainer, FileDocumentManager.class, new MockFileDocumentManagerImpl(DocumentImpl::new, null));

  VirtualFileSystem[] fs = {myLocalFileSystem, myJarFileSystem};
  VirtualFileManagerImpl virtualFileManager = new VirtualFileManagerImpl(myApplication, fs);
  registerComponentInstance(appContainer, VirtualFileManager.class, virtualFileManager);

  registerApplicationExtensionPoint(ASTLazyFactory.EP.getExtensionPointName(), ASTLazyFactory.class);
  registerApplicationExtensionPoint(ASTLeafFactory.EP.getExtensionPointName(), ASTLeafFactory.class);
  registerApplicationExtensionPoint(ASTCompositeFactory.EP.getExtensionPointName(), ASTCompositeFactory.class);

  addExtension(ASTLazyFactory.EP.getExtensionPointName(), new DefaultASTLazyFactory());
  addExtension(ASTLeafFactory.EP.getExtensionPointName(), new DefaultASTLeafFactory());
  addExtension(ASTCompositeFactory.EP.getExtensionPointName(), new DefaultASTCompositeFactory());

  registerApplicationService(EncodingManager.class, new CoreEncodingRegistry());
  registerApplicationService(VirtualFilePointerManager.class, createVirtualFilePointerManager());
  registerApplicationService(PsiBuilderFactory.class, new PsiBuilderFactoryImpl());
  registerApplicationService(ReferenceProvidersRegistry.class, new MockReferenceProvidersRegistry());
  registerApplicationService(StubTreeLoader.class, new CoreStubTreeLoader());
  registerApplicationService(PsiReferenceService.class, new PsiReferenceServiceImpl());
  registerApplicationService(MetaDataRegistrar.class, new MetaRegistry());

  registerApplicationService(ProgressManager.class, createProgressIndicatorProvider());

  registerApplicationService(JobLauncher.class, createJobLauncher());
  registerApplicationService(CodeFoldingSettings.class, new CodeFoldingSettings());
  registerApplicationService(CommandProcessor.class, new CoreCommandProcessor());
}
 
Example #8
Source File: NamedObjectProviderBinding.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void addAcceptableReferenceProviders(@Nonnull PsiElement position, @Nonnull List<ProviderInfo<Provider, ProcessingContext>> list, @Nonnull PsiReferenceService.Hints hints) {
  String name = getName(position);
  if (name != null) {
    addMatchingProviders(position, myNamesToProvidersMap.get(name), list, hints);
    addMatchingProviders(position, myNamesToProvidersMapInsensitive.get(name.toLowerCase()), list, hints);
  }
}
 
Example #9
Source File: CypherPsiImplUtil.java    From jetbrains-plugin-graph-database-support with Apache License 2.0 4 votes vote down vote up
@NotNull
public static PsiReference[] getReferences(CypherNamedElement element) {
    return PsiReferenceService.getService().getContributedReferences(element);
}
 
Example #10
Source File: CSharpCallArgumentListImpl.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public PsiReference[] getReferences()
{
	return PsiReferenceService.getService().getContributedReferences(this);
}
 
Example #11
Source File: CSharpStubMemberImpl.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public PsiReference[] getReferences()
{
	return PsiReferenceService.getService().getContributedReferences(this);
}
 
Example #12
Source File: MockReferenceProvidersRegistry.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
protected PsiReference[] doGetReferencesFromProviders(PsiElement context, PsiReferenceService.Hints hints) {
  return PsiReference.EMPTY_ARRAY;
}
 
Example #13
Source File: ProviderBinding.java    From consulo with Apache License 2.0 4 votes vote down vote up
void addAcceptableReferenceProviders(@Nonnull PsiElement position,
@Nonnull List<ProviderInfo<T, ProcessingContext>> list,
@Nonnull PsiReferenceService.Hints hints);