void (@NotNull PsiTypeCastExpression expression) { final PsiType castType = expression.getType(); if (!ClassUtils.isPrimitiveNumericType(castType)) { return; } final PsiExpression operand = expression.getOperand(); if (operand == null) { return; } final PsiType operandType = operand.getType(); if (!ClassUtils.isPrimitiveNumericType(operandType) || !TypeUtils.isNarrowingConversion(operandType, castType)) { return; } if (ignoreIntegerCharCasts && PsiTypes.intType().equals(operandType) && PsiTypes.charType().equals(castType)) { return; } if (PsiTypes.longType().equals(operandType) && PsiTypes.intType().equals(castType)) { final PsiMethod method = PsiTreeUtil.getParentOfType(expression, PsiMethod.class, true, PsiClass.class, PsiLambdaExpression.class); if (MethodUtils.isHashCode(method)) { return; } } Object result = ExpressionUtils.computeConstantExpression(operand); if (result instanceof Character) { result = Integer.valueOf(((Character)result).charValue()); } if (result instanceof Number number) { if (ignoreOverflowingByteCasts && PsiTypes.intType().equals(operandType) && PsiTypes.byteType().equals(castType)) { final int i = number.intValue(); if (i > Byte.MIN_VALUE && i <= 255) { return; } } if (valueIsContainableInType(number, castType)) { return; } } final PsiTypeElement castTypeElement = expression.getCastType(); if (castTypeElement == null) { return; } LongRangeSet targetRange = JvmPsiRangeSetUtil.typeRange(castType); LongRangeSet lostRange = LongRangeSet.all(); if (targetRange != null && JvmPsiRangeSetUtil.typeRange(operandType) != null) { LongRangeSet valueRange = DfLongType.extractRange(CommonDataflow.getDfType(operand)); lostRange = valueRange.subtract(targetRange); if (lostRange.isEmpty()) return; } registerError(castTypeElement, operandType, lostRange.max() < 0); }