@Nullable
  private static HighlightInfo.Builder checkFinalUsageInsideGuardedPattern(@NotNull PsiVariable variable, @NotNull PsiJavaCodeReferenceElement context) {
    PsiSwitchLabelStatementBase refLabel = PsiTreeUtil.getParentOfType(context, PsiSwitchLabelStatementBase.class);

    if (refLabel == null) return null;
    PsiExpression guardExpression = refLabel.getGuardExpression();
    if (!PsiTreeUtil.isAncestor(guardExpression, context, false)) return null;
    //this assignment is covered by com.intellij.codeInsight.daemon.impl.analysis.HighlightUtil.checkOutsideDeclaredCantBeAssignmentInGuard
    boolean isAssignment = context instanceof PsiReferenceExpression psiExpression && PsiUtil.isAccessedForWriting(psiExpression);
    if (!isAssignment && !PsiTreeUtil.isAncestor(guardExpression, variable, false) &&
        !isEffectivelyFinal(variable, refLabel, context)) {
      String message = JavaErrorBundle.message("guarded.pattern.variable.must.be.final");
      HighlightInfo.Builder builder = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(context).descriptionAndTooltip(message);
      IntentionAction action = getQuickFixFactory().createVariableAccessFromInnerClassFix(variable, refLabel);
      builder.registerFix(action, null, null, null, null);
      IntentionAction action2 = getQuickFixFactory().createMakeVariableEffectivelyFinalFix(variable);
      if (action2 != null) {
        builder.registerFix(action2, null, null, null, null);
      }
      ErrorFixExtensionPoint.registerFixes(builder, context, "guarded.pattern.variable.must.be.final");
      return builder;
    }
    return null;
  }
@Nullable
  private static HighlightInfo.Builder checkFinalUsageInsideGuardedPattern(@NotNull PsiVariable variable, @NotNull PsiJavaCodeReferenceElement context)