void (@NotNull PyBinaryExpression leftExpression, @NotNull PyBinaryExpression rightExpression, @NotNull Project project) { final PyElementGenerator elementGenerator = PyElementGenerator.getInstance(project); final PyExpression newLeftExpression, newRightExpression; final String operator; if (myCommonIsInLeftLeft) { newLeftExpression = invertExpression(leftExpression, elementGenerator); } else { newLeftExpression = leftExpression; } if (myCommonIsInRightLeft) { operator = getLeftestOperator(rightExpression).getText(); newRightExpression = getLargeRightExpression(rightExpression, project); } else { operator = invertOperator(Objects.requireNonNull(rightExpression.getPsiOperator())); final PyExpression rightLeftExpr = rightExpression.getLeftExpression(); if (rightLeftExpr instanceof PyBinaryExpression) { newRightExpression = invertExpression((PyBinaryExpression)rightLeftExpr, elementGenerator); } else { newRightExpression = rightLeftExpr; } } final PyBinaryExpression binaryExpression = elementGenerator.createBinaryExpression(operator, newLeftExpression, newRightExpression); leftExpression.replace(makePsiConsistentBinaryExpression(project, binaryExpression)); rightExpression.delete(); }