void (@NotNull PsiReferenceRegistrar registrar) { registrar.registerReferenceProvider( PlatformPatterns.psiElement(PropertyKeyImpl.class).inVirtualFile(bundleFile()), new PsiReferenceProvider() { @Override public PsiReference @NotNull [] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) { if (!(element instanceof PropertyKeyImpl)) return PsiReference.EMPTY_ARRAY; if (!isPluginProject(element)) return PsiReference.EMPTY_ARRAY; String text = ((PropertyKeyImpl)element).getText(); return JBIterable.of( createActionOrGroupIdReference(element, text), createToolwindowIdReference(element, text), createExportableIdReference(element, text), createPluginIdReference(element, text), createAdvancedSettingReference(element, text) ).filter(Objects::nonNull).toArray(PsiReference.EMPTY_ARRAY); } @Nullable private static PsiReference createActionOrGroupIdReference(@NotNull PsiElement element, String text) { if (!isActionOrGroupKey(text)) return null; final int dotAfterPrefix = text.indexOf('.'); if (dotAfterPrefix == -1) return null; final int prefixEndIdx = dotAfterPrefix + 1; final int dotBeforeSuffix = text.lastIndexOf('.'); if (dotBeforeSuffix == -1) return null; if (dotBeforeSuffix <= prefixEndIdx) return null; String id = text.substring(prefixEndIdx, dotBeforeSuffix); String prefix = text.substring(0, prefixEndIdx); return new ActionOrGroupIdReference(element, id, prefix); } @Nullable private static PsiReference createToolwindowIdReference(@NotNull PsiElement element, String text) { if (!isToolwindowKey(text)) return null; String id = StringUtil.notNullize(StringUtil.substringAfter(text, TOOLWINDOW_STRIPE_PREFIX)).replace('_', ' '); return new ToolwindowIdReference(element, id); } @Nullable private static PsiReference createExportableIdReference(@NotNull PsiElement element, String text) { if (!isExportableKey(text)) return null; String id = text.replace(EXPORTABLE_PREFIX, "").replace(EXPORTABLE_SUFFIX, ""); return new ExportableIdReference(element, id); } @Nullable private static PsiReference createPluginIdReference(@NotNull PsiElement element, String text) { if (!isPluginDescriptionKey(text)) return null; String id = StringUtil.substringAfter(StringUtil.notNullize(StringUtil.substringBefore(text, DESCRIPTION)), PLUGIN); return new PluginIdReference(element, id); } @Nullable private static PsiReference createAdvancedSettingReference(@NotNull PsiElement element, String text) { if (!isAdvancedSettingKey(text)) return null; String s = StringUtil.notNullize(StringUtil.substringAfter(text, ADVANCED_SETTING)); String id = s.endsWith(DESCRIPTION) ? StringUtil.trimEnd(s, DESCRIPTION) : (s.endsWith(TRAILING_LABEL) ? StringUtil.trimEnd(s, TRAILING_LABEL) : s); TextRange range = TextRange.allOf(id).shiftRight(ADVANCED_SETTING.length()); return new AdvancedSettingsIdContributor.AdvancedSettingReference(element, range); } }); }