boolean (@NotNull PsiExpression expression, @Nullable PsiType toType) { while (expression instanceof PsiTypeCastExpression || expression instanceof PsiParenthesizedExpression) { if (expression instanceof PsiTypeCastExpression) { expression = ((PsiTypeCastExpression)expression).getOperand(); } if (expression instanceof PsiParenthesizedExpression) { expression = ((PsiParenthesizedExpression)expression).getExpression(); } } if (expression == null) return false; PsiType rType = expression.getType(); PsiType castType = GenericsUtil.getVariableTypeByExpressionType(toType); return rType != null && toType != null && TypeConversionUtil.areTypesConvertible(rType, toType) && toType.isAssignableFrom(castType); }