private static void removeRedundantPatternVariables(PsiElement element) {
    for (PsiLambdaExpression lambda : PsiTreeUtil.collectElementsOfType(element, PsiLambdaExpression.class)) {
      PsiElement body = lambda.getBody();
      if (body instanceof PsiExpression expression && PsiTypes.booleanType().equals(expression.getType())) {
        List<PsiPatternVariable> variables = JavaPsiPatternUtil.getExposedPatternVariablesIgnoreParent(expression);
        for (PsiPatternVariable variable : variables) {
          if (variable.getPattern() instanceof PsiTypeTestPattern pattern && pattern.getParent() instanceof PsiDeconstructionList) {
            continue;
          }
          if (!VariableAccessUtils.variableIsUsed(variable, expression)) {
            variable.delete();
          }
        }
      }
    }
  }
private static void removeRedundantPatternVariables(PsiElement element)