boolean (@NotNull PsiTypeCastExpression expression) { final PsiType castType = expression.getType(); final PsiExpression operand = expression.getOperand(); if (!(operand instanceof PsiReferenceExpression referenceExpression)) return false; final InstanceofChecker checker = new InstanceofChecker(referenceExpression, castType, false); PsiElement parent = findInterestingParent(expression); while (parent != null) { parent.accept(checker); if (checker.hasAgreeingInstanceof()) return true; parent = findInterestingParent(parent); } return false; }