Java 类com.intellij.psi.impl.source.resolve.reference.PsiReferenceRegistrarImpl 实例源码

项目:consulo-java    文件:JavadocCompletionTest.java   
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);
  }
}