PatternVariableCandidate (@NotNull PatternVariableCandidate oldCandidate, @NotNull SequenceStatement newSequence, @NotNull SequenceStatement previousSequenceStatement, @NotNull Statement last, @Nullable DoStatement doStatement, @NotNull Set<AssignmentExprent> assignmentExprents, @NotNull AssignmentExprent assignmentExprent) { PatternVariableCandidate candidate = oldCandidate; Statement nextStatement = candidate.getNextStatement(); if (nextStatement == newSequence) { //if it has the same thing, let's reuse what we have; otherwise it will lead to a broken graph candidate = new PatternVariableCandidate(candidate.getVarExprent(), previousSequenceStatement, candidate.getUsedIfStatement(), candidate.getTempAssignments(), candidate.getCleaner() ); } else if (nextStatement instanceof IfStatement ifStatement && ifStatement.getSuccessorEdges(EdgeType.DIRECT_ALL).size() == 1 && ifStatement.getSuccessorEdges(EdgeType.DIRECT_ALL).get(0).getDestination() == last) { ArrayList<Statement> statements = new ArrayList<>(); statements.add(ifStatement); statements.add(last); candidate = new PatternVariableCandidate(candidate.getVarExprent(), new SequenceStatement(statements), candidate.getUsedIfStatement(), candidate.getTempAssignments(), candidate.getCleaner()); } else if (nextStatement instanceof SequenceStatement nextSeqStat) { if (nextSeqStat.getStats().isEmpty()) { return null; } Statement lastNextStatement = nextSeqStat.getStats().get(nextSeqStat.getStats().size() - 1); List<StatEdge> edges = lastNextStatement.getSuccessorEdges(EdgeType.DIRECT_ALL); if (edges.size() != 1) { return null; } StatEdge edge = edges.get(0); if (edge.getDestination() != last) { //edge contains break, so it can be assumed that the firstStatement of assignmentExprent is processed if (!edgeCanBeWayOutOfRoot(doStatement, edge)) { //something broken return null; } assignmentExprents.add(assignmentExprent); } nextSeqStat.getStats().addWithKey(last, last.id); } else { List<StatEdge> edges = nextStatement.getSuccessorEdges(EdgeType.ALL); if (edges.size() == 1 && edges.get(0).getType() == EdgeType.BREAK) { StatEdge edge = edges.get(0); //edge contains break, so it can be assumed that the firstStatement of assignmentExprent is processed if (edgeCanBeWayOutOfRoot(doStatement, edge)) { assignmentExprents.add(assignmentExprent); } } } return candidate; }