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); } }