return null;
}
private boolean addCastForAssignment(final AstNode left, final Expression right) {
final ResolveResult targetResult = _resolver.apply(left);
if (targetResult == null || targetResult.getType() == null) {
return false;
}
final ResolveResult valueResult = _resolver.apply(right);
if (valueResult == null || valueResult.getType() == null) {
return false;
}
final TypeReference unboxedTargetType = MetadataHelper.getUnderlyingPrimitiveTypeOrSelf(targetResult.getType());
final TypeReference unboxedValueType = MetadataHelper.getUnderlyingPrimitiveTypeOrSelf(valueResult.getType());
if (right instanceof PrimitiveExpression &&
unboxedTargetType.getSimpleType().isIntegral() &&
unboxedTargetType.getSimpleType().isSubWordOrInt32() &&
MetadataHelper.isAssignableFrom(BuiltinTypes.Integer, unboxedValueType, false)) {
return false;
}
final ConversionType conversionType = MetadataHelper.getConversionType(targetResult.getType(), valueResult.getType());
AstNode replacement = null;
if (conversionType == ConversionType.EXPLICIT || conversionType == ConversionType.EXPLICIT_TO_UNBOXED) {
final AstBuilder astBuilder = context.getUserData(Keys.AST_BUILDER);
if (astBuilder == null) {
return false;
}
final ConvertTypeOptions convertTypeOptions = new ConvertTypeOptions();
convertTypeOptions.setAllowWildcards(false);
final AstType castToType = astBuilder.convertType(targetResult.getType(), convertTypeOptions);
replacement = right.replaceWith(
new Function<AstNode, Expression>() {
@Override
public Expression apply(final AstNode e) {
return new CastExpression(castToType, right);
}
}
);
}
else if (conversionType == ConversionType.NONE) {
if (valueResult.getType().getSimpleType() == JvmType.Boolean &&
targetResult.getType().getSimpleType() != JvmType.Boolean &&
targetResult.getType().getSimpleType().isNumeric()) {
replacement = convertBooleanToNumeric(right);
if (targetResult.getType().getSimpleType().bitWidth() < 32) {
final AstBuilder astBuilder = context.getUserData(Keys.AST_BUILDER);
if (astBuilder != null) {
replacement = replacement.replaceWith(
new Function<AstNode, AstNode>() {
@Override
public AstNode apply(final AstNode input) {
return new CastExpression(astBuilder.convertType(targetResult.getType()), (Expression) input);
}
}
);
}
}
}
else if (targetResult.getType().getSimpleType() == JvmType.Boolean &&
valueResult.getType().getSimpleType() != JvmType.Boolean &&
valueResult.getType().getSimpleType().isNumeric()) {
replacement = convertNumericToBoolean(right, valueResult.getType());
}
else {
final AstBuilder astBuilder = context.getUserData(Keys.AST_BUILDER);
if (astBuilder != null) {