private static @Nullable FindUsagesHandler proxy(final @Nullable FindUsagesHandlerBase base) {
    if (base == null) {
      return null;
    }
    else if (base instanceof FindUsagesHandler) {
      return (FindUsagesHandler)base;
    }
    else if (base instanceof PyFindUsagesHandler) {
      // Important note: override methods that are overridden in PyFindUsagesHandler inheritors.

      return new FindUsagesHandler(base.getPsiElement()) {
        @Override
        public @NotNull FindUsagesOptions getFindUsagesOptions(@Nullable DataContext dataContext) {
          return base.getFindUsagesOptions(dataContext);
        }

        @Override
        protected boolean isSearchForTextOccurrencesAvailable(@NotNull PsiElement psiElement, boolean isSingleFile) {
          return ((PyFindUsagesHandler)base).isSearchForTextOccurrencesAvailable(psiElement, isSingleFile);
        }

        @Override
        public PsiElement @NotNull [] getPrimaryElements() {
          return base.getPrimaryElements();
        }

        @Override
        public @NotNull Collection<PsiReference> findReferencesToHighlight(@NotNull PsiElement target,
                                                                           @NotNull SearchScope searchScope) {
          return base.findReferencesToHighlight(target, searchScope);
        }

        @Override
        public @NotNull AbstractFindUsagesDialog getFindUsagesDialog(boolean isSingleFile,
                                                                     boolean toShowInNewTab,
                                                                     boolean mustOpenInNewTab) {

          if (base instanceof FindUsagesHandlerUi) {
            return ((FindUsagesHandlerUi)base).getFindUsagesDialog(isSingleFile, toShowInNewTab, mustOpenInNewTab);
          }
          else {
            return super.getFindUsagesDialog(isSingleFile, toShowInNewTab, mustOpenInNewTab);
          }
        }
      };
    }
    else {
      @NonNls String msg = base.toString() + " is of unexpected type.";
      throw new IllegalArgumentException(msg);
    }
  }
private static @Nullable FindUsagesHandler proxy(final @Nullable FindUsagesHandlerBase base)