Couple<String> (PsiLoopStatement loopStatement, CommentTracker ct) { if (loopStatement instanceof PsiForStatement) { CountingLoop loop = CountingLoop.from((PsiForStatement)loopStatement); if (loop == null) return null; String start, end; if (loop.isDescending()) { start = loop.isIncluding() ? ct.text(loop.getBound()) : JavaPsiMathUtil.add(loop.getBound(), 1, ct); end = JavaPsiMathUtil.add(loop.getInitializer(), 1, ct); } else { start = ct.text(loop.getInitializer()); end = loop.isIncluding() ? JavaPsiMathUtil.add(loop.getBound(), 1, ct) : ct.text(loop.getBound()); } return Couple.of(start, end); } if (loopStatement instanceof PsiWhileStatement) { PsiBinaryExpression condition = tryCast(PsiUtil.skipParenthesizedExprDown(((PsiWhileStatement)loopStatement).getCondition()), PsiBinaryExpression.class); if (condition == null) return null; RelationType relationType = DfaPsiUtil.getRelationByToken(condition.getOperationTokenType()); if (relationType == null) return null; PsiExpression left = condition.getLOperand(); PsiExpression right = condition.getROperand(); if (right == null) return null; String start, end; switch (relationType) { case GE -> { start = JavaPsiMathUtil.add(right, -1, ct); end = ct.text(left); } case GT -> { start = ct.text(right); end = ct.text(left); } case LE -> { start = JavaPsiMathUtil.add(left, -1, ct); end = ct.text(right); } case LT -> { start = ct.text(left); end = ct.text(right); } default -> { return null; } } return Couple.of(start, end); } return null; }