NJ2K: fix implicit type cast in binary expressions
#KT-37298 fixed
This commit is contained in:
@@ -141,7 +141,7 @@ class ImplicitCastsConversion(context: NewJ2kConverterContext) : RecursiveApplic
|
|||||||
val initialTypeName = expressionTypeAsPrimitive.jvmPrimitiveType.javaKeywordName.capitalize()
|
val initialTypeName = expressionTypeAsPrimitive.jvmPrimitiveType.javaKeywordName.capitalize()
|
||||||
val conversionFunctionName = "to${toTypeAsPrimitive.jvmPrimitiveType.javaKeywordName.capitalize()}"
|
val conversionFunctionName = "to${toTypeAsPrimitive.jvmPrimitiveType.javaKeywordName.capitalize()}"
|
||||||
return JKQualifiedExpression(
|
return JKQualifiedExpression(
|
||||||
copyTreeAndDetach(),
|
copyTreeAndDetach().parenthesizeIfBinaryExpression(),
|
||||||
JKCallExpressionImpl(
|
JKCallExpressionImpl(
|
||||||
symbolProvider.provideMethodSymbol("kotlin.$initialTypeName.$conversionFunctionName"),
|
symbolProvider.provideMethodSymbol("kotlin.$initialTypeName.$conversionFunctionName"),
|
||||||
JKArgumentList()
|
JKArgumentList()
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
class A {
|
||||||
|
void acceptDouble(double d) {}
|
||||||
|
void acceptDoubleBoxed(Double d) {}
|
||||||
|
|
||||||
|
public void conversion() {
|
||||||
|
int a = 10;
|
||||||
|
float b = 0.7f;
|
||||||
|
acceptDouble(a * b)
|
||||||
|
acceptDoubleBoxed(a * b)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
internal class A {
|
||||||
|
fun acceptDouble(d: Double) {}
|
||||||
|
fun acceptDoubleBoxed(d: Double?) {}
|
||||||
|
fun conversion() {
|
||||||
|
val a = 10
|
||||||
|
val b = 0.7f
|
||||||
|
acceptDouble((a * b).toDouble())
|
||||||
|
acceptDoubleBoxed((a * b).toDouble())
|
||||||
|
}
|
||||||
|
}
|
||||||
+18
@@ -2727,6 +2727,24 @@ public class NewJavaToKotlinConverterSingleFileTestGenerated extends AbstractNew
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("nj2k/testData/newJ2k/implicitCasts")
|
||||||
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
public static class ImplicitCasts extends AbstractNewJavaToKotlinConverterSingleFileTest {
|
||||||
|
private void runTest(String testDataFilePath) throws Exception {
|
||||||
|
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testAllFilesPresentInImplicitCasts() throws Exception {
|
||||||
|
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("nj2k/testData/newJ2k/implicitCasts"), Pattern.compile("^([^\\.]+)\\.java$"), null, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("arithmeticInFunctionCall.java")
|
||||||
|
public void testArithmeticInFunctionCall() throws Exception {
|
||||||
|
runTest("nj2k/testData/newJ2k/implicitCasts/arithmeticInFunctionCall.java");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("nj2k/testData/newJ2k/importStatement")
|
@TestMetadata("nj2k/testData/newJ2k/importStatement")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
|||||||
Reference in New Issue
Block a user