static void removeTempVariableDeclarations(@NotNull List<TempVarAssignmentItem> tempVarAssignments) {
    if (tempVarAssignments.isEmpty()) return;
    Set<Statement> visited = new HashSet<>();
    Set<Statement> statements = tempVarAssignments.stream().filter(a -> a.delete).map(a -> a.statement()).collect(Collectors.toSet());
    Map<VarExprent, List<VarExprent>> vars =
      tempVarAssignments.stream().filter(a -> a.delete).map(a -> a.varExprent()).collect(Collectors.groupingBy(t -> t));
    Set<VarExprent> preserve = tempVarAssignments.stream().filter(a->!a.delete).map(t->t.varExprent).collect(Collectors.toSet());
    for (Statement statement : statements) {
      Statement parent = statement;
      while (parent != null) {
        if (visited.contains(parent)) {
          break;
        }
        visited.add(parent);
        List<Exprent> candidates;
        if (parent.getFirst() != null && parent.getFirst().type == StatementType.BASIC_BLOCK) {
          candidates = parent.getFirst().getExprents();
        }
        else if (parent.type == StatementType.TRY_CATCH || parent.type == StatementType.SEQUENCE) {
          candidates = parent.getVarDefinitions();
        }
        else {
          candidates = Collections.emptyList();
        }
        if (candidates == null) {
          candidates = new ArrayList<>();
        }
        List<List<Exprent>> listVarExprents = new ArrayList<>();
        listVarExprents.add(candidates);
        if (parent.getExprents() != null) {
          listVarExprents.add(parent.getExprents());
        }
        List<Exprent> toDelete = new ArrayList<>();
        for (List<Exprent> varExprents : listVarExprents) {
          for (int i = 0; i < varExprents.size(); i++) {
            Exprent exprent = varExprents.get(i);
            Exprent assignmentExprent = null;
            if (exprent.type == Exprent.EXPRENT_ASSIGNMENT) {
              assignmentExprent = exprent;
              exprent = ((AssignmentExprent)exprent).getLeft();
            }
            if (exprent.type != Exprent.EXPRENT_VAR) continue;
            VarExprent varExprent = (VarExprent)exprent;
            if (containVar(vars, varExprent) || (varExprent.isDefinition() && vars.containsKey(varExprent))) {
              if (varExprent.isDefinition() && preserve.contains(varExprent)) {
                continue;
              }
              toDelete.add(assignmentExprent == null ? varExprent : assignmentExprent);
            }
          }
          varExprents.removeAll(toDelete);
        }
        parent = parent.getParent();
      }
    }
  }
static void removeTempVariableDeclarations(@NotNull List<TempVarAssignmentItem> tempVarAssignments)