Java to Kotlin converter: fixed crash in converter + more correct auto insertion of !!

#KT-851 Fixed
This commit is contained in:
Valentin Kipyatkov
2014-06-24 21:09:29 +04:00
parent d3b773c0cd
commit 30a7c67aaa
7 changed files with 29 additions and 6 deletions
+3 -3
View File
@@ -569,9 +569,9 @@ public class Converter private(val project: Project, val settings: ConverterSett
val actualType = expression.getType()
if (actualType == null) return convertedExpression
if (actualType is PsiPrimitiveType && convertedExpression.isNullable ||
expectedType is PsiPrimitiveType && actualType is PsiClassType) {
convertedExpression = BangBangExpression(convertedExpression)
if (convertedExpression.isNullable &&
(actualType is PsiPrimitiveType || actualType is PsiClassType && expectedType is PsiPrimitiveType)) {
convertedExpression = BangBangExpression(convertedExpression).assignNoPrototype()
}
if (canConvertType(actualType, expectedType) && convertedExpression !is LiteralExpression) {
@@ -1672,6 +1672,11 @@ public class JavaToKotlinConverterTestGenerated extends AbstractJavaToKotlinConv
doTest("j2k/tests/testData/ast/issues/kt-837.java");
}
@TestMetadata("kt-851.java")
public void testKt_851() throws Exception {
doTest("j2k/tests/testData/ast/issues/kt-851.java");
}
@TestMetadata("kt-852.java")
public void testKt_852() throws Exception {
doTest("j2k/tests/testData/ast/issues/kt-852.java");
@@ -6,6 +6,6 @@ class Test() {
}
fun test() {
val i = getInteger(10)!!
val i = getInteger(10)
}
}
@@ -0,0 +1,9 @@
//file
class Test {
void putInt(int i) {}
void test() {
Byte b = 10;
putInt(b);
}
}
+9
View File
@@ -0,0 +1,9 @@
class Test() {
fun putInt(i: Int) {
}
fun test() {
val b = 10
putInt(b.toInt())
}
}
@@ -2,6 +2,6 @@ import kotlinApi.*
class C() {
fun foo() {
val v = globalGenericFunction<Int>(1)!!
val v = globalGenericFunction<Int>(1)
}
}
@@ -1,4 +1,4 @@
fun foo(i: Int) {
var i1 = i!!
var i1 = i
i1++
}