New J2K: use nullable type for unknown for public declarations & prepare for mutability inference

#KT-32518 fixed
This commit is contained in:
Ilya Kirillov
2019-08-29 18:18:39 +03:00
parent 0040490daf
commit c28515be59
128 changed files with 784 additions and 609 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
class TestReturnsArray {
fun strings(n: Int): Array<String?> {
val result = arrayOfNulls<String?>(n)
val result = arrayOfNulls<String>(n)
for (i in 0 until n) {
result[i] = Integer.toString(i)
}
+2 -2
View File
@@ -2,7 +2,7 @@ class TestMutltipleCtorsWithJavadoc
/**
* Javadoc for 1st ctor
* @param x
*/(private val x: String) {
*/(private val x: String?) {
private var y: String? = null
// ---
@@ -14,7 +14,7 @@ class TestMutltipleCtorsWithJavadoc
* @param x
* @param y
*/
constructor(x: String, y: String?) : this(x) {
constructor(x: String?, y: String?) : this(x) {
this.y = y
}
+1 -1
View File
@@ -3,7 +3,7 @@ package test
import java.util.HashMap
class TestPrimitiveFromMap {
fun foo(map: HashMap<String, Int>): Int {
fun foo(map: HashMap<String?, Int?>): Int {
return map["zzz"]!!
}
}
+1 -1
View File
@@ -1,7 +1,7 @@
package test
class TestMapGetAsReceiver {
fun foo(map: Map<String, String>): Int {
fun foo(map: Map<String?, String>): Int {
return map["zzz"]!!.length
}
}
+2 -2
View File
@@ -1,9 +1,9 @@
package test
class TestValReassign(private val s1: String) {
class TestValReassign(private val s1: String?) {
private var s2: String? = null
constructor(s1: String, s2: String?) : this(s1) {
constructor(s1: String?, s2: String?) : this(s1) {
this.s2 = s2
}
+2 -2
View File
@@ -3,13 +3,13 @@ class TestToStringReturnsNullable {
var string: String? = null
}
open class Ctor(string: String) : Base() {
open class Ctor(string: String?) : Base() {
init {
this.string = string
}
}
class Derived(string: String) : Ctor(string) {
class Derived(string: String?) : Ctor(string) {
override fun toString(): String {
return string!!
}
+1 -1
View File
@@ -6,7 +6,7 @@ class TestJavaExpectedTypeInference {
fun test(node: DefaultMutableTreeNode) {
val e: Enumeration<DefaultMutableTreeNode> = node.children()
while (e.hasMoreElements()) {
val child: DefaultMutableTreeNode = e.nextElement()
val child = e.nextElement()
val name = child.userObject as String
println(name)
}
+2 -2
View File
@@ -1,11 +1,11 @@
import java.util.ArrayList
internal interface FooInterface {
fun foo(): ArrayList<out Foo.SomeClass>?
fun foo(): ArrayList<out Foo.SomeClass?>?
}
class Foo : FooInterface {
override fun foo(): ArrayList<SomeClass>? {
override fun foo(): ArrayList<SomeClass?>? {
return null
}
+1 -1
View File
@@ -5,6 +5,6 @@ internal class Test {
fun context() {
val items: MutableList<Double> = ArrayList()
items.add(1.0)
items.forEach(Consumer { o: Double -> println(o) })
items.forEach(Consumer { o: Double? -> println(o) })
}
}
+1 -1
View File
@@ -1,4 +1,4 @@
internal class X(private val list: List<Y>) {
internal class X(private val list: MutableList<Y>) {
internal inner class Y
}
+1 -3
View File
@@ -1,12 +1,10 @@
package demo
internal class Test {
fun putInt(i: Int) {}
fun putInt(i: Int?) {}
fun test() {
val b: Byte = 10
putInt(b.toInt())
val b2: Byte = 10
putInt(b2.toInt())
}
+1 -2
View File
@@ -1,8 +1,7 @@
package demo
internal class Test {
fun putInt(i: Int) {}
fun putInt(i: Int?) {}
fun test() {
val i = 10
putInt(i)
+1 -1
View File
@@ -1,6 +1,6 @@
package demo
internal class Test(i: Int) {
internal class Test(i: Int?) {
fun test() {
val i = 10
Test(i)
+1 -1
View File
@@ -13,7 +13,7 @@ internal object FileRead {
val fstream = FileInputStream(File("file.txt"))
val `in` = DataInputStream(fstream)
val br = BufferedReader(InputStreamReader(`in`))
var strLine: String
var strLine: String?
while (br.readLine().also { strLine = it } != null) {
println(strLine)
}
+2 -2
View File
@@ -8,9 +8,9 @@ internal object One {
var myContainer = Container()
}
internal class StringContainer(s: String)
internal class StringContainer(s: String?)
internal class Test {
fun putString(s: String) {}
fun putString(s: String?) {}
fun test() {
putString(One.myContainer.myString)
StringContainer(One.myContainer.myString)
+3 -3
View File
@@ -2,12 +2,12 @@ object ArrayNullable {
@JvmStatic
fun main(args: Array<String>) {
val notNull = 0
val a1 = arrayOfNulls<Int?>(2)
val a1 = arrayOfNulls<Int>(2)
a1[0] = null
a1[1] = notNull
println(a1[0])
println(a1[1])
val a2 = arrayOfNulls<Int?>(2)
val a2 = arrayOfNulls<Int>(2)
a2[0] = nullable()
a2[1] = notNull
println(a2[0])
@@ -21,4 +21,4 @@ object ArrayNullable {
fun nullable(): Int? {
return if (System.getProperty("user.home").length > 20) null else 1
}
}
}