boolean (@NotNull PsiExpression anchor, boolean expectedValue) { PsiElement parent; while (true) { parent = anchor.getParent(); if (parent instanceof PsiExpression parentExpr && BoolUtils.isNegation(parentExpr)) { expectedValue = !expectedValue; anchor = parentExpr; continue; } if (parent instanceof PsiParenthesizedExpression parenthesized) { anchor = parenthesized; continue; } if (parent instanceof PsiPolyadicExpression polyadic) { IElementType tokenType = polyadic.getOperationTokenType(); if (tokenType.equals(JavaTokenType.ANDAND) || tokenType.equals(JavaTokenType.OROR)) { // always true operand makes always true OR-chain and does not affect the result of AND-chain // Note that in `assert unknownExpression && trueExpression;` the trueExpression should not be reported // because this assertion is essentially the shortened `assert unknownExpression; assert trueExpression;` // which is not reported. boolean causesShortCircuit = (tokenType.equals(JavaTokenType.OROR) == expectedValue) && ArrayUtil.getLastElement(polyadic.getOperands()) != anchor; if (!causesShortCircuit) { // We still report `assert trueExpression || unknownExpression`, because here `unknownExpression` is never checked // which is probably not intended. anchor = polyadic; continue; } } } break; } if (parent instanceof PsiAssertStatement) { return expectedValue; } if (parent instanceof PsiIfStatement ifStatement && anchor == ifStatement.getCondition()) { PsiStatement thenBranch = ControlFlowUtils.stripBraces(ifStatement.getThenBranch()); if (thenBranch instanceof PsiThrowStatement) { return !expectedValue; } } return isAssertCallArgument(anchor, ContractValue.booleanValue(expectedValue)); }