类com.intellij.psi.PsiReferenceService源码实例Demo

下面列出了怎么用com.intellij.psi.PsiReferenceService的API类实例代码及写法,或者点击链接到github查看源代码。

@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;
}
 
源代码2 项目: consulo   文件: SimpleProviderBinding.java
@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));
    }
  }
}
 
源代码3 项目: consulo   文件: PsiReferenceRegistrarImpl.java
@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;
}
 
源代码4 项目: consulo   文件: NamedObjectProviderBinding.java
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));
    }
  }
}
 
@Nonnull
@Override
@RequiredReadAction
public PsiReference[] getReferences()
{
	return PsiReferenceService.getService().getContributedReferences(this);
}
 
源代码6 项目: consulo   文件: FindUsagesHelper.java
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;
}
 
源代码7 项目: consulo   文件: CoreApplicationEnvironment.java
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());
}
 
源代码8 项目: consulo   文件: NamedObjectProviderBinding.java
@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);
  }
}
 
@NotNull
public static PsiReference[] getReferences(CypherNamedElement element) {
    return PsiReferenceService.getService().getContributedReferences(element);
}
 
@Nonnull
@Override
public PsiReference[] getReferences()
{
	return PsiReferenceService.getService().getContributedReferences(this);
}
 
源代码11 项目: consulo-csharp   文件: CSharpStubMemberImpl.java
@Nonnull
@Override
public PsiReference[] getReferences()
{
	return PsiReferenceService.getService().getContributedReferences(this);
}
 
源代码12 项目: consulo   文件: MockReferenceProvidersRegistry.java
@Override
protected PsiReference[] doGetReferencesFromProviders(PsiElement context, PsiReferenceService.Hints hints) {
  return PsiReference.EMPTY_ARRAY;
}
 
源代码13 项目: consulo   文件: ProviderBinding.java
void addAcceptableReferenceProviders(@Nonnull PsiElement position,
@Nonnull List<ProviderInfo<T, ProcessingContext>> list,
@Nonnull PsiReferenceService.Hints hints);
 
 类所在包
 类方法
 同包方法