String (PsiExpression comparison, @NotNull CommentTracker ct) { if (!(comparison instanceof PsiBinaryExpression binOp)) return null; RelationType relationType = DfaPsiUtil.getRelationByToken(binOp.getOperationTokenType()); if (relationType == null) return null; String operator = binOp.getOperationSign().getText(); PsiExpression left = PsiUtil.skipParenthesizedExprDown(binOp.getLOperand()); PsiExpression right = PsiUtil.skipParenthesizedExprDown(binOp.getROperand()); if (left == null || right == null) return null; Integer leftValue = tryCast(getNumberFromLiteral(left), Integer.class); Integer rightValue = tryCast(getNumberFromLiteral(right), Integer.class); PsiPolyadicExpression leftPolyadic = tryCast(left, PsiPolyadicExpression.class); Integer leftAddend = tryCast(getLastAddend(leftPolyadic), Integer.class); PsiPolyadicExpression rightPolyadic = tryCast(right, PsiPolyadicExpression.class); Integer rightAddend = tryCast(getLastAddend(rightPolyadic), Integer.class); if (leftAddend != null) { if (leftAddend == 1 && operator.equals(">")) { return updateLastAddend(leftPolyadic, "", ct) + ">=" + ct.text(right); } if (leftAddend == 1 && operator.equals("<=")) { return updateLastAddend(leftPolyadic, "", ct) + "<" + ct.text(right); } if (leftAddend == -1 && operator.equals(">=")) { return updateLastAddend(leftPolyadic, "", ct) + ">" + ct.text(right); } if (leftAddend == -1 && operator.equals("<")) { return updateLastAddend(leftPolyadic, "", ct) + "<=" + ct.text(right); } if (rightValue != null) { rightValue -= leftAddend; return updateLastAddend(leftPolyadic, "", ct) + operator + rightValue; } } if (rightAddend != null) { if (rightAddend == 1 && operator.equals("<")) { return ct.text(left) + "<=" + updateLastAddend(rightPolyadic, "", ct); } if (rightAddend == 1 && operator.equals(">=")) { return ct.text(left) + ">" + updateLastAddend(rightPolyadic, "", ct); } if (rightAddend == -1 && operator.equals("<=")) { return ct.text(left) + "<" + updateLastAddend(rightPolyadic, "", ct); } if (rightAddend == -1 && operator.equals(">")) { return ct.text(left) + ">=" + updateLastAddend(rightPolyadic, "", ct); } if (leftValue != null) { leftValue -= rightAddend; return leftValue + operator + updateLastAddend(rightPolyadic, "", ct); } } if (leftAddend != null && rightAddend != null) { int diff = leftAddend - rightAddend; if (diff > 0) { return updateLastAddend(leftPolyadic, "+" + diff, ct) + operator + updateLastAddend(rightPolyadic, "", ct); } else if (diff < 0) { return updateLastAddend(leftPolyadic, "", ct) + operator + updateLastAddend(rightPolyadic, "+"+(-diff), ct); } else { return updateLastAddend(leftPolyadic, "", ct) + operator + updateLastAddend(rightPolyadic, "", ct); } } return null; }