int[] (PsiPolyadicExpression context, List<PsiExpression> operands, boolean and) { assert !operands.isEmpty(); if (operands.size() == 1) { Object value = CommonDataflow.computeValue(operands.get(0)); return Boolean.valueOf(and).equals(value) ? new int[]{0} : ArrayUtilRt.EMPTY_INT_ARRAY; } String text = StreamEx.ofReversed(operands) .map(expression -> ParenthesesUtils.getText(expression, PsiPrecedenceUtil.AND_PRECEDENCE)).joining(and ? " && " : " || "); PsiExpression expression = JavaPsiFacade.getElementFactory(context.getProject()).createExpressionFromText(text, context); if (!(expression instanceof PsiPolyadicExpression expressionToAnalyze)) { LOG.error("Unexpected expression type: " + expression.getClass().getName(), new Attachment("reversed.txt", text)); return ArrayUtilRt.EMPTY_INT_ARRAY; } List<PsiExpression> reversedOperands = Arrays.asList(expressionToAnalyze.getOperands()); Map<PsiExpression, ThreeState> values = computeOperandValues(expressionToAnalyze); return StreamEx.ofKeys(values, ThreeState.fromBoolean(and)::equals) .mapToInt(operand -> IntStreamEx.ofIndices(reversedOperands, op -> PsiTreeUtil.isAncestor(op, operand, false)) .findFirst().orElse(0)) .map(index -> operands.size() - 1 - index) .toArray(); }