private static TypeReference doNumericPromotion(final TypeReference leftType, final TypeReference rightType) { final JvmType left = leftType.getSimpleType(); final JvmType right = rightType.getSimpleType(); if (left == right) { return leftType; } if (left == JvmType.Double || right == JvmType.Double) { return BuiltinTypes.Double; } if (left == JvmType.Float || right == JvmType.Float) { return BuiltinTypes.Float; } if (left == JvmType.Long || right == JvmType.Long) { return BuiltinTypes.Long; } if (left.isNumeric() && left != JvmType.Boolean || right.isNumeric() && right != JvmType.Boolean) { return BuiltinTypes.Integer; } return leftType; }
private static TypeReference doNumericPromotion(final TypeReference leftType, final TypeReference rightType) { final JvmType left = leftType.getSimpleType(); final JvmType right = rightType.getSimpleType(); if (left == right) { return leftType; } if (left == JvmType.Double || right == JvmType.Double) { return BuiltinTypes.Double; } if (left == JvmType.Float || right == JvmType.Float) { return BuiltinTypes.Float; } if (left == JvmType.Long || right == JvmType.Long) { return BuiltinTypes.Long; } if (left.isNumeric() && left != JvmType.Boolean || right.isNumeric() && right != JvmType.Boolean) { return BuiltinTypes.Integer; } return leftType; }
private static TypeReference doNumericPromotion(final TypeReference leftType, final TypeReference rightType) { final JvmType left = leftType.getSimpleType(); final JvmType right = rightType.getSimpleType(); if (left == right) { return leftType; } if (left == JvmType.Double || right == JvmType.Double) { return BuiltinTypes.Double; } if (left == JvmType.Float || right == JvmType.Float) { return BuiltinTypes.Float; } if (left == JvmType.Long || right == JvmType.Long) { return BuiltinTypes.Long; } if (left.isNumeric() && left != JvmType.Boolean || right.isNumeric() && right != JvmType.Boolean) { return BuiltinTypes.Integer; } return leftType; }
public static boolean isArithmetic(@Nullable final TypeReference type) { if (type == null) { return false; } final JvmType jvmType = MetadataHelper.getUnderlyingPrimitiveTypeOrSelf(type).getSimpleType(); return jvmType.isNumeric() && jvmType != JvmType.Boolean; }
public static boolean isArithmetic(@Nullable final TypeReference type) { if (type == null) { return false; } final JvmType jvmType = MetadataHelper.getUnderlyingPrimitiveTypeOrSelf(type).getSimpleType(); return jvmType.isNumeric() && jvmType != JvmType.Boolean; }
public static boolean isArithmetic(@Nullable final TypeReference type) { if (type == null) { return false; } final JvmType jvmType = MetadataHelper.getUnderlyingPrimitiveTypeOrSelf(type).getSimpleType(); return jvmType.isNumeric() && jvmType != JvmType.Boolean; }
/** * Determines the conversion type, taking lossiness into consideration for numeric conversions. * Returns {@link ConversionType#NONE} if a determination could not be made. */ private ConversionType getConversion( @NotNull final TypeReference target, @NotNull final TypeReference source, @Nullable final Expression value) { final TypeReference unboxedTarget = unbox(target); final TypeReference unboxedSource = unbox(source); if (unboxedTarget.getSimpleType().isNumeric() && unboxedSource.getSimpleType().isNumeric()) { return getNumericConversion(target, source, value); } return MetadataHelper.getConversionType(target, source); }
/** * 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); }
@Override public Void visitUnaryOperatorExpression(final UnaryOperatorExpression node, final Void data) { super.visitUnaryOperatorExpression(node, data); switch (node.getOperator()) { case NOT: { final Expression operand = node.getExpression(); final ResolveResult result = _resolver.apply(operand); if (result != null && result.getType() != null && !TypeUtilities.isBoolean(result.getType()) && MetadataHelper.getUnderlyingPrimitiveTypeOrSelf(result.getType()).getSimpleType().isNumeric()) { final TypeReference comparandType = MetadataHelper.getUnderlyingPrimitiveTypeOrSelf(result.getType()); operand.replaceWith( new Function<AstNode, AstNode>() { @Override public AstNode apply(final AstNode input) { return new BinaryOperatorExpression( operand, BinaryOperatorType.INEQUALITY, new PrimitiveExpression(Expression.MYSTERY_OFFSET, JavaPrimitiveCast.cast(comparandType.getSimpleType(), 0)) ); } } ); } break; } } return null; }
@Override public Void visitUnaryOperatorExpression(final UnaryOperatorExpression node, final Void data) { super.visitUnaryOperatorExpression(node, data); switch (node.getOperator()) { case NOT: { final Expression operand = node.getExpression(); final ResolveResult result = _resolver.apply(operand); if (result != null && result.getType() != null && !TypeUtilities.isBoolean(result.getType()) && MetadataHelper.getUnderlyingPrimitiveTypeOrSelf(result.getType()).getSimpleType().isNumeric()) { final TypeReference comparandType = MetadataHelper.getUnderlyingPrimitiveTypeOrSelf(result.getType()); operand.replaceWith( new Function<AstNode, AstNode>() { @Override public AstNode apply(final AstNode input) { return new BinaryOperatorExpression( operand, BinaryOperatorType.INEQUALITY, new PrimitiveExpression(Expression.MYSTERY_OFFSET, JavaPrimitiveCast.cast(comparandType.getSimpleType(), 0)) ); } } ); } break; } } return null; }
@Override public Void visitUnaryOperatorExpression(final UnaryOperatorExpression node, final Void data) { super.visitUnaryOperatorExpression(node, data); switch (node.getOperator()) { case NOT: { final Expression operand = node.getExpression(); final ResolveResult result = _resolver.apply(operand); if (result != null && result.getType() != null && !TypeUtilities.isBoolean(result.getType()) && MetadataHelper.getUnderlyingPrimitiveTypeOrSelf(result.getType()).getSimpleType().isNumeric()) { final TypeReference comparandType = MetadataHelper.getUnderlyingPrimitiveTypeOrSelf(result.getType()); operand.replaceWith( new Function<AstNode, AstNode>() { @Override public AstNode apply(final AstNode input) { return new BinaryOperatorExpression( operand, BinaryOperatorType.INEQUALITY, new PrimitiveExpression(Expression.MYSTERY_OFFSET, JavaPrimitiveCast.cast(comparandType.getSimpleType(), 0)) ); } } ); } break; } } return null; }
return sourceJvmType.isNumeric() ? ConversionType.EXPLICIT : ConversionType.NONE;
return sourceJvmType.isNumeric() ? ConversionType.EXPLICIT : ConversionType.NONE;
return sourceJvmType.isNumeric() ? ConversionType.EXPLICIT : ConversionType.NONE;