PsiReferenceRegistrarImpl (@NotNull Language language) { PsiReferenceRegistrarImpl registrar = new PsiReferenceRegistrarImpl(); for (PsiReferenceContributor contributor : CONTRIBUTOR_EXTENSION.allForLanguageOrAny(language)) { registerContributedReferenceProviders(registrar, contributor); } List<PsiReferenceProviderBean> referenceProviderBeans = REFERENCE_PROVIDER_EXTENSION.allForLanguageOrAny(language); for (PsiReferenceProviderBean providerBean : referenceProviderBeans) { ElementPattern<PsiElement> pattern = providerBean.createElementPattern(); if (pattern != null) { registrar.registerReferenceProvider(pattern, new PsiReferenceProvider() { PsiReferenceProvider myProvider; @Override public PsiReference @NotNull [] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) { if (myProvider == null) { myProvider = providerBean.instantiate(); if (myProvider == null) { myProvider = NULL_REFERENCE_PROVIDER; } } return myProvider.getReferencesByElement(element, context); } }); } } registrar.markInitialized(); return registrar; }