private boolean shouldAnalyzePatternVariablesInCaseLabel(@NotNull PsiElement place) {
    if (place instanceof PsiCodeBlock) return true;
    boolean patternInSwitch = PsiUtil.isAvailable(JavaFeature.PATTERNS_IN_SWITCH, place);
    final AtomicBoolean thisSwitchLabelIsImmediate = new AtomicBoolean();

    PsiTreeUtil.treeWalkUp(place, getParent(), (currentScope, __) -> {

      PsiSwitchLabelStatementBase immediateSwitchLabel;

      if (currentScope instanceof PsiSwitchLabelStatementBase) {
        immediateSwitchLabel = (PsiSwitchLabelStatementBase)currentScope;
      }
      else {
        immediateSwitchLabel = PsiTreeUtil.getPrevSiblingOfType(currentScope, PsiSwitchLabelStatementBase.class);
      }

      while (immediateSwitchLabel != null && !patternInSwitch &&
             (PsiTreeUtil.getPrevSiblingOfType(immediateSwitchLabel, PsiStatement.class) instanceof PsiSwitchLabelStatementBase &&
              isCaseNull(immediateSwitchLabel))) {
       /*
        Example 1:
          case null:
            System.out.println("null");
          case String s: // illegal fall-through to a pattern in any version of Java
            System.out.println("String " + s);
            break;
        Example 2:
           case null: case String s: // legal in Java 17-19 Preview, illegal in Java 20 Preview
             System.out.println("String " + s);
             break;
        */
        immediateSwitchLabel = PsiTreeUtil.getPrevSiblingOfType(immediateSwitchLabel, PsiSwitchLabelStatementBase.class);
      }

      if (immediateSwitchLabel == this) {
        thisSwitchLabelIsImmediate.set(true);
        return false;
      }
      return true;
    });

    return thisSwitchLabelIsImmediate.get();
  }
private boolean shouldAnalyzePatternVariablesInCaseLabel(@NotNull PsiElement place)