void (PsiIfStatement ifStatement, PsiInstanceOfExpression targetInstanceOf, List<PsiTypeCastExpression> relatedCastExpressions) { PsiElement current = targetInstanceOf; while (true) { PsiElement parent = current.getParent(); if (parent == null || parent == ifStatement) { break; } if (!(parent instanceof PsiPolyadicExpression polyadicExpression) || polyadicExpression.getOperationTokenType() != JavaTokenType.ANDAND) { break; } PsiExpression[] operands = polyadicExpression.getOperands(); int index = Arrays.asList(operands).indexOf(current); if (index == -1 || index == operands.length - 1) { break; } for (int i = index; i < operands.length; i++) { relatedCastExpressions.addAll(getRelatesCastExpressions(operands[i], targetInstanceOf)); } current = parent; } }