/** * Determines the numeric conversion type, taking lossiness into consideration. * Returns {@link ConversionType#NONE} if a determination could not be made. */ private ConversionType getNumericConversion( @NotNull final TypeReference target, @NotNull final TypeReference source, @Nullable final Expression value) { final TypeReference unboxedTarget = unbox(target); final TypeReference unboxedSource = unbox(source); final JvmType jvmSource = unboxedSource.getSimpleType(); final JvmType jvmTarget = unboxedTarget.getSimpleType(); if (jvmSource == JvmType.Boolean || !jvmSource.isNumeric() || jvmTarget == JvmType.Boolean || !jvmTarget.isNumeric()) { return ConversionType.NONE; } final ResolveResult resolveResult = value != null ? _resolver.apply(value) : null; final Object constantValue = resolveResult != null ? resolveResult.getConstantValue() : null; if (constantValue != null && isValidPrimitiveLiteralAssignment(unboxedTarget, constantValue) && isValidPrimitiveLiteralAssignment(unboxedSource, constantValue)) { return ConversionType.IDENTITY; } return MetadataHelper.getNumericConversionType(target, source); }
protected void processPossibleTypeCast(final Expression rightExpression, @Nullable final TypeReference leftType) { if (leftType == null) { return; } final Expression r = removeParentheses(rightExpression); if (r instanceof CastExpression) { final AstType castAstType = ((CastExpression) r).getType(); final TypeReference castType = castAstType != null ? castAstType.toTypeReference() : null; final Expression castOperand = ((CastExpression) r).getExpression(); if (castOperand != null && !castOperand.isNull() && castType != null) { final TypeReference operandType = getType(castOperand); if (operandType != null) { if (MetadataHelper.isAssignableFrom(leftType, operandType, false)) { addToResults((CastExpression) r, false); } else { final TypeReference unboxedCastType = MetadataHelper.getUnderlyingPrimitiveTypeOrSelf(castType); final TypeReference unboxedLeftType = MetadataHelper.getUnderlyingPrimitiveTypeOrSelf(leftType); if (castOperand instanceof PrimitiveExpression && TypeUtilities.isValidPrimitiveLiteralAssignment(unboxedCastType, ((PrimitiveExpression) castOperand).getValue()) && TypeUtilities.isValidPrimitiveLiteralAssignment(unboxedLeftType, ((PrimitiveExpression) castOperand).getValue())) { addToResults((CastExpression) r, true); } } } } } }
protected void processPossibleTypeCast(final Expression rightExpression, @Nullable final TypeReference leftType) { if (leftType == null) { return; } final Expression r = removeParentheses(rightExpression); if (r instanceof CastExpression) { final AstType castAstType = ((CastExpression) r).getType(); final TypeReference castType = castAstType != null ? castAstType.toTypeReference() : null; final Expression castOperand = ((CastExpression) r).getExpression(); if (castOperand != null && !castOperand.isNull() && castType != null) { final TypeReference operandType = getType(castOperand); if (operandType != null) { if (MetadataHelper.isAssignableFrom(leftType, operandType, false)) { addToResults((CastExpression) r, false); } else { final TypeReference unboxedCastType = MetadataHelper.getUnderlyingPrimitiveTypeOrSelf(castType); final TypeReference unboxedLeftType = MetadataHelper.getUnderlyingPrimitiveTypeOrSelf(leftType); if (castOperand instanceof PrimitiveExpression && TypeUtilities.isValidPrimitiveLiteralAssignment(unboxedCastType, ((PrimitiveExpression) castOperand).getValue()) && TypeUtilities.isValidPrimitiveLiteralAssignment(unboxedLeftType, ((PrimitiveExpression) castOperand).getValue())) { addToResults((CastExpression) r, true); } } } } } }
final TypeReference unboxedLeftType = unbox(leftType); if (isValidPrimitiveLiteralAssignment(unboxedLeftType, rr.getConstantValue()) && isValidPrimitiveLiteralAssignment(unboxedCastType, rr.getConstantValue())) {
final TypeReference unboxedOpType = MetadataHelper.getUnderlyingPrimitiveTypeOrSelf(opType); if (TypeUtilities.isValidPrimitiveLiteralAssignment(unboxedCastType, ((PrimitiveExpression) operand).getValue()) && TypeUtilities.isValidPrimitiveLiteralAssignment(unboxedOpType, ((PrimitiveExpression) operand).getValue())) {
final TypeReference unboxedOpType = MetadataHelper.getUnderlyingPrimitiveTypeOrSelf(opType); if (TypeUtilities.isValidPrimitiveLiteralAssignment(unboxedCastType, ((PrimitiveExpression) operand).getValue()) && TypeUtilities.isValidPrimitiveLiteralAssignment(unboxedOpType, ((PrimitiveExpression) operand).getValue())) {
TypeUtilities.isValidPrimitiveLiteralAssignment(unboxedTargetType, ((PrimitiveExpression) right).getValue())) {
TypeUtilities.isValidPrimitiveLiteralAssignment(unboxedTargetType, ((PrimitiveExpression) right).getValue())) {
TypeUtilities.isValidPrimitiveLiteralAssignment(unboxedTargetType, ((PrimitiveExpression) right).getValue())) {