void (@NotNull PsiLiteralExpression expression) { super.visitLiteralExpression(expression); final PsiType type = expression.getType(); if (!getTypeBeforeCast().equals(type)) { return; } PsiElement parent = expression.getParent(); while (parent instanceof PsiPrefixExpression || parent instanceof PsiParenthesizedExpression) { parent = parent.getParent(); } if (!(parent instanceof PsiTypeCastExpression typeCastExpression)) { return; } final PsiType castType = typeCastExpression.getType(); if (!getCastType().equals(castType)) { return; } final PsiType expectedType = ExpectedTypeUtils.findExpectedType(typeCastExpression, false); // don't warn on red code. if (expectedType == null) { return; } else if (!getCastType().equals(expectedType)) { final PsiClassType boxedType = getCastType().getBoxedType(expression); assert boxedType != null; if (!boxedType.equals(expectedType)) { return; } } registerError(typeCastExpression, typeCastExpression); }