@Contract(pure = true)
  private static @NotNull ElementFilter getCaseLabelElementListFilter(@NotNull PsiElement position) {
    PsiSwitchBlock switchBlock = PsiTreeUtil.getParentOfType(position, PsiSwitchBlock.class);
    if (switchBlock == null) return TrueFilter.INSTANCE;

    PsiExpression selector = switchBlock.getExpression();
    if (selector == null || selector.getType() == null) return TrueFilter.INSTANCE;

    PsiType selectorType = selector.getType();

    if (IN_ENUM_SWITCH_LABEL.accepts(position)) {
      ClassFilter enumClassFilter = new ClassFilter(PsiField.class) {
        @Override
        public boolean isAcceptable(Object element, PsiElement context) {
          return element instanceof PsiEnumConstant;
        }
      };
      if (!PsiUtil.isAvailable(JavaFeature.PATTERNS_IN_SWITCH, position)) {
        return enumClassFilter;
      }

      ClassFilter inheritorsEnumFilter = new ClassFilter(PsiClass.class) {
        @Override
        public boolean isAcceptable(Object element, PsiElement context) {
          return element instanceof PsiClass psiClass &&
                 (JAVA_LANG_OBJECT.equals(psiClass.getQualifiedName()) || psiClass.isEnum() || psiClass.isInterface()) &&
                 //it will be covered by enum class, and it looks like noise
                 !JAVA_LANG_COMPARABLE.equals(psiClass.getQualifiedName()) &&
                 TypeConversionUtil.areTypesConvertible(TypeUtils.getType(psiClass), selectorType);
        }
      };

      return new OrFilter(enumClassFilter, inheritorsEnumFilter);
    }

    ClassFilter constantVariablesFilter = new ClassFilter(PsiVariable.class) {
      @Override
      public boolean isAcceptable(Object element, PsiElement context) {
        PsiVariable variable;
        if (element instanceof PsiField field) {
          if (!field.hasModifierProperty(PsiModifier.FINAL) || !field.hasModifierProperty(PsiModifier.STATIC) ||
              !JavaResolveUtil.isAccessible(field, field.getContainingClass(), field.getModifierList(), context, null, null)) {
            return false;
          }

          PsiClass aClass = PsiUtil.resolveClassInClassTypeOnly(field.getType());
          if (aClass != null && aClass.isEnum()) {
            return false;
          }
          variable = field;
        }
        else if (element instanceof PsiLocalVariable local) {
          if (!local.hasModifierProperty(PsiModifier.FINAL)) {
            return false;
          }
          variable = local;
        }
        else {
          return false;
        }
        return TypeConversionUtil.isAssignable(selectorType, variable.getType());
      }
    };

    if (!PsiUtil.isAvailable(JavaFeature.PATTERNS_IN_SWITCH, position) ||
        isPrimitive(selectorType) || TypeUtils.isJavaLangString(selectorType)) {
      ClassFilter classFilter = new ClassFilter(PsiClass.class) {
        @Override
        public boolean isAcceptable(Object element, PsiElement context) {
          // Accept only classes with inner classes or with suitable fields
          if (!(element instanceof PsiClass psiClass)) return false;
          for (PsiClass aClass : psiClass.getInnerClasses()) {
            if (JavaResolveUtil.isAccessible(aClass, psiClass, aClass.getModifierList(), context, null, null)) {
              return true;
            }
          }
          return ContainerUtil.exists(psiClass.getAllFields(), field -> constantVariablesFilter.isAcceptable(field, context));
        }
      };
      return new OrFilter(classFilter, constantVariablesFilter);
    }

    ClassFilter enumInheritorsFilter = new ClassFilter(PsiField.class) {
      @Override
      public boolean isAcceptable(Object element, PsiElement context) {
        return element instanceof PsiEnumConstant enumConstant && TypeConversionUtil.areTypesConvertible(enumConstant.getType(), selectorType);
      }
    };

    if (TypeUtils.isJavaLangObject(selectorType)) {
      return new OrFilter(new ClassFilter(PsiClass.class), constantVariablesFilter, enumInheritorsFilter);
    }

    ClassFilter inheritorsFilter = new ClassFilter(PsiClass.class) {
      @Override
      public boolean isAcceptable(Object element, PsiElement context) {
        return element instanceof PsiClass psiClass &&
               TypeConversionUtil.areTypesConvertible(TypeUtils.getType(psiClass), selectorType);
      }
    };

    if (TypeUtils.isJavaLangString(selectorType)) {
      return new OrFilter(constantVariablesFilter, inheritorsFilter);
    }

    return selectorType instanceof PsiClassType
           ? new OrFilter(inheritorsFilter, enumInheritorsFilter)
           : TrueFilter.INSTANCE;
  }
@Contract(pure = true)
  private static @NotNull ElementFilter getCaseLabelElementListFilter(@NotNull PsiElement position)