PatternVariableCandidate (@NotNull Statement ifElseStat, @NotNull VarExprent operand, @NotNull ConstExprent checkType, @NotNull Statement topLevelStatement) { List<Exprent> ifElseExprents = ifElseStat.getExprents(); if (ifElseExprents==null || ifElseExprents.isEmpty() || ifElseExprents.get(0).type != Exprent.EXPRENT_ASSIGNMENT) return null; AssignmentExprent assignmentExprent = (AssignmentExprent)ifElseExprents.get(0); if (assignmentExprent.getLeft().type != Exprent.EXPRENT_VAR) return null; VarExprent varExprent = (VarExprent)assignmentExprent.getLeft(); if (assignmentExprent.getRight().type != Exprent.EXPRENT_FUNCTION) return null; FunctionExprent castExprent = (FunctionExprent)assignmentExprent.getRight(); if (castExprent.getFuncType() != FunctionExprent.FUNCTION_CAST) return null; if (!varExprent.isDefinition()) { Exprent leftAssignmentPart = assignmentExprent.getLeft(); Exprent rightAssignmentPart = assignmentExprent.getRight(); if (leftAssignmentPart.type != Exprent.EXPRENT_VAR || rightAssignmentPart.type != Exprent.EXPRENT_FUNCTION || ((FunctionExprent)rightAssignmentPart).getFuncType() != FunctionExprent.FUNCTION_CAST) { return null; } varExprent = ((VarExprent)leftAssignmentPart); List<Exprent> castOperands = ((FunctionExprent)rightAssignmentPart).getLstOperands(); if (castOperands.size() != 2 || castOperands.get(1).type != Exprent.EXPRENT_CONST) return null; VarType castType = ((ConstExprent)castOperands.get(1)).getConstType(); varExprent = (VarExprent)varExprent.copy(); varExprent.setVarType(castType); varExprent.setDefinition(true); } List<Exprent> castExprents = castExprent.getAllExprents(); if (castExprents.size() != 2 || !operand.equals(castExprents.get(0)) || !checkType.equals(castExprents.get(1))) { return null; } List<TempVarAssignmentItem> tempVarAssignments = new ArrayList<>(); if (!varExprent.isDefinition()) { tempVarAssignments.add(new TempVarAssignmentItem(varExprent, ifElseStat)); } if (assignmentExprent.getLeft() instanceof VarExprent toDelete) { tempVarAssignments.add(new TempVarAssignmentItem(toDelete, ifElseStat)); } return new PatternVariableCandidate(varExprent, topLevelStatement, new HashSet<>(), tempVarAssignments, () -> { }); }