StreamEx<ExpressionToConstantComparison> (PsiElement element) { PsiPolyadicExpression disjunction = PsiTreeUtil.getParentOfType(element, PsiPolyadicExpression.class); if (disjunction != null && disjunction.getOperationTokenType() == JavaTokenType.EQEQ) { disjunction = PsiTreeUtil.getParentOfType(disjunction, PsiPolyadicExpression.class); } if (disjunction == null || disjunction.getOperationTokenType() != JavaTokenType.OROR) return StreamEx.empty(); PsiExpression[] operands = disjunction.getOperands(); int offset = element.getTextOffset() - disjunction.getTextOffset(); int index = IntStreamEx.ofIndices(operands, op -> op.getStartOffsetInParent() + op.getTextLength() > offset) .findFirst().orElse(operands.length - 1); ExpressionToConstantComparison anchorComparison = ExpressionToConstantComparison.create(operands[index]); if (anchorComparison == null) return StreamEx.empty(); List<ExpressionToConstantComparison> prefix = IntStreamEx.rangeClosed(index - 1, 0, -1) .elements(operands) .map(ExpressionToConstantComparison::create) .takeWhile(anchorComparison::belongsToChain) .toList(); List<ExpressionToConstantComparison> suffix = StreamEx.of(operands, index + 1, operands.length) .map(ExpressionToConstantComparison::create) .takeWhile(anchorComparison::belongsToChain) .toList(); return StreamEx.ofReversed(prefix).append(anchorComparison).append(suffix); }