com.intellij.psi.PsiReferenceProvider Java Examples

The following examples show how to use com.intellij.psi.PsiReferenceProvider. 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: ReferenceContributor.java    From intellij-swagger with MIT License 6 votes vote down vote up
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);
    }
  };
}
 
Example #2
Source File: ReferenceContributor.java    From intellij-swagger with MIT License 6 votes vote down vote up
PsiReferenceProvider createSchemaNameReferenceProvider() {
  return new PsiReferenceProvider() {
    @NotNull
    @Override
    public PsiReference[] getReferencesByElement(
        @NotNull PsiElement element, @NotNull ProcessingContext context) {
      return Optional.ofNullable(element.getText())
          .map(
              text ->
                  new PsiReference[] {
                    new SchemaNameReference(element, StringUtils.removeAllQuotes(text))
                  })
          .orElse(SchemaNameReference.EMPTY_ARRAY);
    }
  };
}
 
Example #3
Source File: ReferenceContributor.java    From intellij-swagger with MIT License 6 votes vote down vote up
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);
    }
  };
}
 
Example #4
Source File: BuckIdentifierReferenceContributor.java    From buck with Apache License 2.0 6 votes vote down vote up
@Override
public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) {

  registrar.registerReferenceProvider(
      PlatformPatterns.psiElement(BuckIdentifier.class),
      new PsiReferenceProvider() {
        @NotNull
        @Override
        public PsiReference[] getReferencesByElement(
            @NotNull PsiElement element, @NotNull ProcessingContext context) {
          if (element instanceof BuckIdentifier) {
            BuckIdentifier identifier = (BuckIdentifier) element;
            return new PsiReference[] {new BuckIdentifierReference(identifier)};
          } else {
            return new PsiReference[0];
          }
        }
      });
}
 
Example #5
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 #6
Source File: PsiReferenceRegistrarImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #7
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 #8
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 #9
Source File: PsiReferenceRegistrarImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * @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);
}
 
Example #10
Source File: PsiReferenceRegistrarImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
/**
 * @deprecated {@link com.intellij.psi.PsiReferenceContributor}
 */
public void registerReferenceProvider(@Nullable ElementFilter elementFilter,
                                      @Nonnull Class scope,
                                      @Nonnull PsiReferenceProvider provider) {
  registerReferenceProvider(elementFilter, scope, provider, DEFAULT_PRIORITY);
}
 
Example #11
Source File: PsiReferenceRegistrarImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void unregisterReferenceProvider(@Nonnull Class scope, @Nonnull PsiReferenceProvider provider) {
  ProviderBinding<PsiReferenceProvider> providerBinding = myBindingsMap.get(scope);
  providerBinding.unregisterProvider(provider);
}
 
Example #12
Source File: PsiReferenceRegistrarImpl.java    From consulo with Apache License 2.0 2 votes vote down vote up
/**
 * @see com.intellij.psi.PsiReferenceContributor
 * @deprecated
 */
public void registerReferenceProvider(@Nonnull Class scope, @Nonnull PsiReferenceProvider provider) {
  registerReferenceProvider(null, scope, provider);
}