void (@NotNull List<TempVarAssignmentItem> tempVarAssignments) { if (tempVarAssignments.isEmpty()) return; Set<Statement> visited = new HashSet<>(); Set<Statement> statements = tempVarAssignments.stream().map(a -> a.statement()).collect(Collectors.toSet()); Map<VarExprent, List<VarExprent>> vars = tempVarAssignments.stream().map(a -> a.varExprent()).collect(Collectors.groupingBy(t -> t)); 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))) { toDelete.add(assignmentExprent == null ? varExprent : assignmentExprent); } } varExprents.removeAll(toDelete); } parent = parent.getParent(); } } }