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 Test {
fun foo() {
val ss = Array</*T2@*/Array</*T1@*/String?>>(5/*LIT*/, { arrayOfNulls</*T0@*/String?>(5/*LIT*/)/*Array<T0@String!!U>!!L*/ }/*Function0<Int, T3@Array<T4@String>>!!L*/)
val ss = Array</*T2@*/Array</*T1@*/String?>>(5/*LIT*/, { arrayOfNulls</*T0@*/String>(5/*LIT*/)/*Array<T0@String!!U>!!L*/ }/*Function0<Int, T3@Array<T4@String>>!!L*/)
}
}
+1 -1
View File
@@ -1,5 +1,5 @@
fun test() {
val x: /*T2@*/Array</*T1@*/Int?> = arrayOfNulls</*T0@*/Int?>(10/*LIT*/)/*Array<T0@Int!!U>!!L*/
val x: /*T2@*/Array</*T1@*/Int?> = arrayOfNulls</*T0@*/Int>(10/*LIT*/)/*Array<T0@Int!!U>!!L*/
}
//T1 := UPPER due to 'INITIALIZER'
+2 -2
View File
@@ -1,5 +1,5 @@
open class A<T> {
open fun foo(): /*T3@*/Map</*T0@*/T, /*T2@*/List</*T1@*/T>>? {
open fun foo(): /*T3@*/Map</*T0@*/T, /*T2@*/List</*T1@*/T>?>? {
TODO()
}
@@ -9,7 +9,7 @@ open class A<T> {
}
class B : A</*T10@*/Int>() {
override fun foo(): /*T8@*/Map</*T5@*/Int, /*T7@*/List</*T6@*/Int>>? {
override fun foo(): /*T8@*/Map</*T5@*/Int, /*T7@*/List</*T6@*/Int>?>? {
return null/*NULL!!U*/
}
override fun bar(): /*T9@*/Int {
+1 -1
View File
@@ -1,4 +1,4 @@
fun b(m: /*T2@*/Map</*T0@*/Int, /*T1@*/String>): /*T3@*/String? {
fun b(m: /*T2@*/Map</*T0@*/Int?, /*T1@*/String?>): /*T3@*/String? {
return m/*T2@Map<T0@Int, T1@String>*/.get(42/*LIT*/)/*T1@String!!U*/
}
@@ -1,4 +1,4 @@
fun <T, E, F, S> foo(x: /*T0@*/T, y: /*T2@*/List</*T1@*/E>, z: /*T4@*/List</*T3@*/F>, a: /*T5@*/S) {}
fun <T, E, F, S> foo(x: /*T0@*/T, y: /*T2@*/List</*T1@*/E>?, z: /*T4@*/List</*T3@*/F>?, a: /*T5@*/S) {}
fun bar() {
val lst: /*T8@*/List</*T7@*/Int?> = listOf</*T6@*/Int?>(null/*NULL!!U*/)/*List<T6@Int>!!L*/
+5 -5
View File
@@ -1,6 +1,6 @@
fun notNullParameters(f: /*T3@*/Function2</*T0@*/Int, /*T1@*/Int, /*T2@*/String>) {}
fun nullableParameter(f: /*T7@*/Function2</*T4@*/Int?, /*T5@*/Int, /*T6@*/String>) {}
fun nullableReturnType(f: /*T11@*/Function2</*T8@*/Int, /*T9@*/Int, /*T10@*/String?>) {}
fun notNullParameters(f: /*T3@*/Function2</*T0@*/Int, /*T1@*/Int, /*T2@*/String?>?) {}
fun nullableParameter(f: /*T7@*/Function2</*T4@*/Int?, /*T5@*/Int?, /*T6@*/String?>?) {}
fun nullableReturnType(f: /*T11@*/Function2</*T8@*/Int, /*T9@*/Int?, /*T10@*/String?>?) {}
fun test() {
@@ -8,11 +8,11 @@ fun test() {
if (i/*T12@Int*/ < 10/*LIT*//*LIT*/ && j/*T13@Int*/ > 0/*LIT*//*LIT*//*LIT*/) ""/*LIT*/ else ""/*LIT*/
}/*Function2<T12@Int, T13@Int, T18@String>!!L*/)
nullableParameter({ i: /*T14@*/Int?, j: /*T15@*/Int ->
nullableParameter({ i: /*T14@*/Int?, j: /*T15@*/Int? ->
if (i/*T14@Int*/ == null/*LIT*/) ""/*LIT*/ else ""/*LIT*/
}/*Function2<T14@Int, T15@Int, T19@String>!!L*/)
nullableReturnType({ i: /*T16@*/Int, j: /*T17@*/Int ->
nullableReturnType({ i: /*T16@*/Int, j: /*T17@*/Int? ->
if (i/*T16@Int*/ < 10/*LIT*//*LIT*/) return@nullableReturnType null/*NULL!!U*/
return@nullableReturnType "nya"/*LIT*/
}/*Function2<T16@Int, T17@Int, T20@String>!!L*/)
+1 -1
View File
@@ -7,7 +7,7 @@ import java.util.stream.Stream
fun test(list: /*T1@*/List</*T0@*/String>) {
val x: /*T9@*/List</*T8@*/String> = list/*T1@List<T0@String>*/.stream()/*Stream<T0@String>!!L*/
.map</*T3@*/String>({ x: /*T2@*/String -> x/*T2@String*/ + ""/*LIT*//*LIT*/ }/*Function1<T2@String, T10@String>!!L*/)/*Stream<T3@String>*/
.collect</*T6@*/List</*T5@*/String>, /*T7@*/Any?>(Collectors/*LIT*/.toList</*T4@*/String>()/*Collector<T4@String, Any, MutableList<T4@String>>*/)/*T6@List<T5@String>*/
.collect</*T6@*/List</*T5@*/String>, /*T7@*/Any>(Collectors/*LIT*/.toList</*T4@*/String>()/*Collector<T4@String, Any, MutableList<T4@String>>*/)/*T6@List<T5@String>*/
}
+2 -2
View File
@@ -1,7 +1,7 @@
class Test {
fun foo1(r: /*T2@*/Function1</*T0@*/Int, /*T1@*/String?>) {}
fun foo1(r: /*T2@*/Function1</*T0@*/Int, /*T1@*/String?>?) {}
fun foo() {
foo1({ x: /*T3@*/Int -> ""/*LIT*/ }/*Function1<T3@Int, T5@String>!!L*/)
foo1({ x: /*T3@*/Int? -> ""/*LIT*/ }/*Function1<T3@Int, T5@String>!!L*/)
foo1({ i: /*T4@*/Int ->
if (i/*T4@Int*/ > 1/*LIT*//*LIT*/) {
return@foo1 null/*NULL!!U*/
+2 -2
View File
@@ -1,5 +1,5 @@
fun test(a: /*T1@*/List</*T0@*/Int>) {
for (i: /*T2@*/Int in a/*T1@List<T0@Int>*/) {
fun test(a: /*T1@*/List</*T0@*/Int?>) {
for (i: /*T2@*/Int? in a/*T1@List<T0@Int>*/) {
}
}
+1 -1
View File
@@ -1,4 +1,4 @@
fun bar(map: /*T2@*/HashMap</*T0@*/String?, /*T1@*/Int>, list1: /*T4@*/List</*T3@*/Int>, list2: /*T6@*/List</*T5@*/String?>) {
fun bar(map: /*T2@*/HashMap</*T0@*/String?, /*T1@*/Int>, list1: /*T4@*/List</*T3@*/Int?>, list2: /*T6@*/List</*T5@*/String?>) {
for (entry: /*T9@*/MutableMap.MutableEntry</*T7@*/String?, /*T8@*/Int> in map/*T2@HashMap<T0@String, T1@Int>*/.entries/*MutableSet<MutableEntry<T0@String, T1@Int>>*/) {
val value: /*T10@*/Int = entry/*T9@MutableEntry<T7@String, T8@Int>*/.value/*T8@Int*/
if (entry/*T9@MutableEntry<T7@String, T8@Int>*/.key/*T7@String*/ == null/*LIT*/) {
@@ -1,7 +1,7 @@
fun a(lst: /*T1@*/List</*T0@*/String>) {
val newList: /*T8@*/List</*T7@*/Int> = lst/*T1@List<T0@String>*/
.asSequence</*T2@*/String>()/*Sequence<T2@String>!!L*/
.map</*T4@*/String, /*T5@*/Int>({ x: /*T3@*/String -> 1/*LIT*/ }/*Function1<T3@String, T9@Int>!!L*/)/*Sequence<T5@Int>!!L*/
.map</*T4@*/String, /*T5@*/Int>({ x: /*T3@*/String? -> 1/*LIT*/ }/*Function1<T3@String, T9@Int>!!L*/)/*Sequence<T5@Int>!!L*/
.toList</*T6@*/Int>()/*List<T6@Int>!!L*/
}
@@ -1,5 +1,5 @@
open class A<T> {
open fun foo(): /*T3@*/Map</*T0@*/T, /*T2@*/List</*T1@*/T>> {
open fun foo(): /*T3@*/Map</*T0@*/T, /*T2@*/List</*T1@*/T>?>? {
TODO()
}
@@ -9,7 +9,7 @@ open class A<T> {
}
class B : A</*T9@*/Int>() {
override fun foo(): /*T8@*/Map</*T5@*/Int, /*T7@*/List</*T6@*/Int>> {
override fun foo(): /*T8@*/Map</*T5@*/Int, /*T7@*/List</*T6@*/Int>?>? {
TODO()
}
}
@@ -1,11 +1,11 @@
open class A<T> {
open fun foo(x: /*T1@*/List</*T0@*/T>, y: /*T2@*/Boolean, z: /*T3@*/T) {
open fun foo(x: /*T1@*/List</*T0@*/T>?, y: /*T2@*/Boolean?, z: /*T3@*/T) {
TODO()
}
}
class B : A</*T8@*/Int>() {
override fun foo(x: /*T5@*/List</*T4@*/Int>, y: /*T6@*/Boolean, z: /*T7@*/Int) {
class B : A</*T8@*/Int?>() {
override fun foo(x: /*T5@*/List</*T4@*/Int?>?, y: /*T6@*/Boolean?, z: /*T7@*/Int?) {
TODO()
}
}
+1 -1
View File
@@ -15,7 +15,7 @@ class Test2 {
}
class Handler {
fun postDelayed(r: Runnable, time: Long) {}
fun postDelayed(r: Runnable?, time: Long) {}
}
class Test3 {
@@ -1 +1 @@
val a = arrayOfNulls<Any?>(10)
val a = arrayOfNulls<Any>(10)
@@ -1 +1 @@
val d2 = arrayOfNulls<IntArray?>(5)
val d2 = arrayOfNulls<IntArray>(5)
@@ -1 +1 @@
val d3 = Array(5) { arrayOfNulls<IntArray?>(5) }
val d3 = Array(5) { arrayOfNulls<IntArray>(5) }
+1 -1
View File
@@ -1 +1 @@
val ss = Array(5) { arrayOfNulls<String?>(5) }
val ss = Array(5) { arrayOfNulls<String>(5) }
+1 -1
View File
@@ -1 +1 @@
val sss = Array(5) { Array(5) { arrayOfNulls<String?>(5) } }
val sss = Array(5) { Array(5) { arrayOfNulls<String>(5) } }
+1 -1
View File
@@ -1,6 +1,6 @@
internal class Test {
fun test() {
val i: Int? = Integer.valueOf(100)
val i = Integer.valueOf(100)
val s: Short = 3
val ss = s
}
+2 -2
View File
@@ -1,8 +1,8 @@
package test
class Integer(s: String) {
class Integer(s: String?) {
companion object {
fun valueOf(value: String): Integer {
fun valueOf(value: String?): Integer {
return Integer(value)
}
}
+1 -1
View File
@@ -1,5 +1,5 @@
internal class T {
fun main() {}
fun i(): Int {}
fun s(): String? {}
fun s(): String {}
}
+1 -1
View File
@@ -4,7 +4,7 @@ import java.util.HashMap
internal class Test {
constructor() {}
constructor(s: String) {}
constructor(s: String?) {}
}
internal class User {
@@ -1,2 +1,2 @@
internal open class Base(o: Any, l: Int)
internal open class Base(o: Any?, l: Int)
internal class C(private val string: String) : Base(string, string.length)
@@ -1,8 +1,6 @@
internal class A @JvmOverloads constructor(nested: Nested = Nested(Nested.FIELD)) {
internal class A @JvmOverloads constructor(nested: Nested? = Nested(Nested.FIELD)) {
internal class Nested(p: Int) {
companion object {
const val FIELD = 0
}
}
@@ -1,6 +1,6 @@
import A.Nested
internal class A @JvmOverloads constructor(nested: Nested = Nested(Nested.FIELD)) {
internal class A @JvmOverloads constructor(nested: Nested? = Nested(Nested.FIELD)) {
internal class Nested(p: Int) {
companion object {
const val FIELD = 0
@@ -2,7 +2,7 @@ package pack
import pack.A.Nested
internal class A @JvmOverloads constructor(nested: Nested = Nested(Nested.FIELD)) {
internal class A @JvmOverloads constructor(nested: Nested? = Nested(Nested.FIELD)) {
internal class Nested(p: Int) {
companion object {
const val FIELD = 0
@@ -2,7 +2,7 @@ package pack
import pack.A.Nested
internal class A @JvmOverloads constructor(nested: Nested = Nested(Nested.FIELD)) {
internal class A @JvmOverloads constructor(nested: Nested? = Nested(Nested.FIELD)) {
internal class Nested(p: Int) {
companion object {
const val FIELD = 0
@@ -1,4 +1,4 @@
internal open class Base(nested: Nested) {
internal open class Base(nested: Nested?) {
internal class Nested(p: Int) {
companion object {
const val FIELD = 0
+2 -4
View File
@@ -10,14 +10,12 @@ class Test {
protected var g = 0.toChar()
constructor() {}
constructor(name: String) {
constructor(name: String?) {
myName = foo(name)
}
companion object {
internal fun foo(n: String): String {
internal fun foo(n: String?): String {
return ""
}
}
+2 -2
View File
@@ -1,9 +1,9 @@
internal class C {
fun equals(c: C): Boolean {
fun equals(c: C?): Boolean {
return false
}
fun foo(c1: C, c2: C): Boolean {
fun foo(c1: C, c2: C?): Boolean {
return c1.equals(c2)
}
}
+2 -2
View File
@@ -1,13 +1,13 @@
import java.util.ArrayList
internal class C {
fun foo1(list: MutableList<String>) {
fun foo1(list: MutableList<String?>) {
for (i in list.indices) {
list[i] = "a"
}
}
fun foo2(list: ArrayList<String>) {
fun foo2(list: ArrayList<String?>) {
for (i in list.indices) {
list[i] = "a"
}
+1 -1
View File
@@ -1,5 +1,5 @@
internal class C {
fun foo(list: MutableList<String>) {
fun foo(list: MutableList<String?>) {
for (i in list.indices) {
list[i] = "a"
}
+1 -1
View File
@@ -1,5 +1,5 @@
internal class A {
var list: List<String>? = null
var list: List<String?>? = null
fun foo() {
for (e in list!!) {
println(e)
+1 -1
View File
@@ -1,2 +1,2 @@
val t: T?
val t: T
get() {}
@@ -11,6 +11,6 @@ internal class Test {
fun nya(): Double {
//TODO explicitlly call apply here
return foo(1, FunctionalI<Int?, Double?> { x: Int -> this.toDouble(x) })
return foo(1, FunctionalI<Int, Double> { x: Int -> this.toDouble(x) })
}
}
@@ -14,6 +14,6 @@ internal class Test {
}
fun nya(): Double {
return foo(1, FunctionalI<Int?, Double?> { x: A -> this.toDouble(x) })
return foo(1, FunctionalI<Int, Double> { x: A -> this.toDouble(x) })
}
}
+9 -9
View File
@@ -1,7 +1,7 @@
class Java8Class {
fun foo0(r: Function0<String>) {}
fun foo1(r: Function1<Int, String?>) {}
fun foo2(r: Function2<Int, Int, String>) {}
fun foo0(r: Function0<String?>?) {}
fun foo1(r: Function1<Int, String?>?) {}
fun foo2(r: Function2<Int?, Int?, String?>?) {}
fun helper() {}
fun foo() {
foo0 { "42" }
@@ -10,8 +10,8 @@ class Java8Class {
helper()
"42"
}
foo1 { i: Int -> "42" }
foo1 { i: Int -> "42" }
foo1 { i: Int? -> "42" }
foo1 { i: Int? -> "42" }
foo1 { i: Int ->
helper()
if (i > 1) {
@@ -19,12 +19,12 @@ class Java8Class {
}
"43"
}
foo2 { i: Int, j: Int -> "42" }
foo2 { i: Int, j: Int ->
foo2 { i: Int?, j: Int? -> "42" }
foo2 { i: Int?, j: Int? ->
helper()
"42"
}
val f = label@{ i: Int, k: Int ->
val f: Function2<Int, Int, String> = label@{ i: Int, k: Int? ->
helper()
if (i > 1) {
return@label "42"
@@ -32,7 +32,7 @@ class Java8Class {
"43"
}
val f1 = label@{ i1: Int, k1: Int ->
val f2 = label@{ i2: Int, k2: Int ->
val f2: Function2<Int, Int, String> = label@{ i2: Int, k2: Int? ->
helper()
if (i2 > 1) {
return@label "42"
+1 -1
View File
@@ -1 +1 @@
fun main(): String? {}
fun main(): String {}
+3 -3
View File
@@ -4,7 +4,7 @@ import java.util.stream.Collectors
object TestLambda {
@JvmStatic
fun main(args: Array<String>) {
val names: List<String> = Arrays.asList("A", "B")
val people: List<Person?> = names.stream().map { name: String -> Person(name) }.collect(Collectors.toList())
val names = Arrays.asList("A", "B")
val people = names.stream().map { name: String? -> Person(name) }.collect(Collectors.toList())
}
}
}
+2 -2
View File
@@ -1,8 +1,8 @@
package demo
internal class Test {
fun test(vararg args: Any) {
fun test(vararg args: Any?) {
var args = args
args = arrayOf(1, 2, 3)
args = arrayOf<Int?>(1, 2, 3)
}
}
@@ -1,2 +1,2 @@
internal open class Base(name: String)
internal class One(name: String, second: String?) : Base(name)
internal open class Base(name: String?)
internal class One(name: String?, second: String?) : Base(name)
@@ -1,2 +1,2 @@
internal open class Base(name: String)
internal class One(name: String, private val mySecond: String) : Base(name)
internal open class Base(name: String?)
internal class One(name: String?, private val mySecond: String) : Base(name)
+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
}
}
}
+3 -3
View File
@@ -2,12 +2,12 @@ import java.util.stream.Collectors
internal class Test {
fun main(lst: List<String>) {
val toList: List<String> = lst.stream().collect(Collectors.toList())
val toSet: Set<String> = lst.stream().collect(Collectors.toSet())
val toList = lst.stream().collect(Collectors.toList())
val toSet = lst.stream().collect(Collectors.toSet())
val count = lst.stream().count()
val anyMatch = lst.stream().anyMatch { v: String -> v.isEmpty() }
val allMatch = lst.stream().allMatch { v: String -> v.isEmpty() }
val noneMatch = lst.stream().noneMatch { v: String -> v.isEmpty() }
lst.stream().forEach { v: String -> println(v) }
lst.stream().forEach { v: String? -> println(v) }
}
}
+6 -6
View File
@@ -4,23 +4,23 @@ import java.util.stream.Stream
internal class Test {
fun main(lst: List<String>) {
val streamOfList: List<String> = lst.stream()
val streamOfList = lst.stream()
.map { x: String -> x + "e" }
.collect(Collectors.toList())
val streamOfElements: List<Int> = Stream.of(1, 2, 3)
val streamOfElements = Stream.of(1, 2, 3)
.map { x: Int -> x + 1 }
.collect(Collectors.toList())
val array = arrayOf(1, 2, 3)
val streamOfArray: List<Int> = Arrays.stream(array)
val streamOfArray = Arrays.stream(array)
.map { x: Int -> x + 1 }
.collect(Collectors.toList())
val streamOfArray2: List<Int> = Stream.of(*array)
val streamOfArray2 = Stream.of(*array)
.map { x: Int -> x + 1 }
.collect(Collectors.toList())
val streamIterate: List<Int> = Stream.iterate(2, { v: Int -> v * 2 })
val streamIterate = Stream.iterate(2, { v: Int -> v * 2 })
.map { x: Int -> x + 1 }
.collect(Collectors.toList())
val streamGenerate: List<Int> = Stream.generate { 42 }
val streamGenerate = Stream.generate { 42 }
.map { x: Int -> x + 1 }
.collect(Collectors.toList())
}
@@ -3,7 +3,7 @@ import java.util.stream.Stream
internal class Test {
fun main(lst: List<String?>?) {
val stream: Stream<Int> = Stream.of(1)
val list: List<Int> = stream.collect(Collectors.toList())
val stream = Stream.of(1)
val list = stream.collect(Collectors.toList())
}
}
+2 -2
View File
@@ -3,11 +3,11 @@ import java.util.stream.Collectors
internal class Test {
fun main(lst: List<Int>) {
val newLst: List<Int> = /*before list*/lst/*after list*/.stream/*before stream*/()/* after stream*/
val newLst = /*before list*/lst/*after list*/.stream/*before stream*/()/* after stream*/
.filter { x: Int -> x > 10 }
.map { x: Int -> x + 2 }/*some comment*/.distinct/*another comment*/()/* one more comment */.sorted()/*another one comment*/
.sorted(Comparator.naturalOrder())
.peek { x: Int -> println(x) }.limit(1)
.peek { x: Int? -> println(x) }.limit(1)
.skip(42)/*skipped*/
/*collecting one*/.collect/*collecting two */(Collectors.toList())/* cool */
}
+2 -2
View File
@@ -3,14 +3,14 @@ import java.util.stream.Stream
internal class Test {
fun main() {
val activities: List<String> = Stream.of("12")
val activities = Stream.of("12")
.map { v: String -> v + "nya" }
.filter { v: String? -> v != null }
.flatMap { v: String ->
Stream.of(v)
.flatMap { s: String -> Stream.of(s) }
}.filter { v: String ->
val name: String = v.javaClass.name
val name = v.javaClass.name
if (name == "name") {
return@filter false
}
+2 -2
View File
@@ -3,13 +3,13 @@ import java.util.stream.Collectors
internal class Test {
fun main(lst: List<Int>) {
val newLst: List<Int> = lst.stream()
val newLst = lst.stream()
.filter { x: Int -> x > 10 }
.map { x: Int -> x + 2 }
.distinct()
.sorted()
.sorted(Comparator.naturalOrder())
.peek { x: Int -> println(x) }
.peek { x: Int? -> println(x) }
.limit(1)
.skip(42)
.collect(Collectors.toList())
+1 -1
View File
@@ -4,7 +4,7 @@ import java.util.ArrayList
class ForEach {
fun test() {
val xs = ArrayList<Any>()
val ys: MutableList<Any> = LinkedList<Any?>()
val ys: MutableList<Any> = LinkedList<Any>()
for (x in xs) {
ys.add(x)
}
+1 -1
View File
@@ -4,7 +4,7 @@ import java.util.ArrayList
class Lists {
fun test() {
val xs: MutableList<Any?> = ArrayList()
val ys: MutableList<Any?> = LinkedList<Any?>()
val ys: MutableList<Any?> = LinkedList<Any>()
val zs = ArrayList<Any?>()
xs.add(null)
ys.add(null)
+1 -3
View File
@@ -9,10 +9,8 @@ internal class A {
private val d8 = 1.0
private val d9 = 1.0
private val x = 1 / (1.0 + 0)
fun foo1(d: Double) {}
fun foo2(d: Double) {}
fun foo2(d: Double?) {}
fun bar() {
foo1(1.0)
foo1(1.0)
+1 -3
View File
@@ -9,10 +9,8 @@ internal class A {
private val f8 = +1f
private val f9 = 1f
private val f10 = 1f
fun foo1(f: Float) {}
fun foo2(f: Float) {}
fun foo2(f: Float?) {}
fun bar() {
foo1(1f)
foo2(1f)
+1 -3
View File
@@ -7,10 +7,8 @@ internal class A {
private val l6 = -123456789101112
private val l7: Long = +1
private val l8 = +1L
fun foo1(l: Long) {}
fun foo2(l: Long) {}
fun foo2(l: Long?) {}
fun bar() {
foo1(1)
foo1(1L)
@@ -1,8 +1,9 @@
// ERROR: Operator call corresponds to a dot-qualified call 'value.plus(1)' which is not allowed on a nullable receiver 'value'.
import java.util.HashMap
internal enum class E { A, B, C }
internal class A {
fun foo(list: List<String?>, collection: Collection<Int?>, map: Map<Int, Int>) {
fun foo(list: List<String?>, collection: Collection<Int?>, map: Map<Int, Int?>) {
val a = "".length
val b = E.A.name
val c = E.A.ordinal
@@ -14,7 +15,7 @@ internal class A {
val i = map.entries.iterator().next().key + 1
}
fun bar(list: MutableList<String>, map: HashMap<String, Int>) {
fun bar(list: MutableList<String?>, map: HashMap<String?, Int?>) {
val c = "a"[0]
val b = 10.toByte()
val i = 10.1.toInt()
@@ -34,7 +35,7 @@ internal class A {
entry.setValue(value + 1)
}
}
fun kt21504() {
val b = "1".toByte()
val s = "1".toShort()
@@ -42,7 +43,6 @@ internal class A {
val l = "1".toLong()
val f = "1".toFloat()
val d = "1".toDouble()
val b2 = "1".toByte(10)
val s2 = "1".toShort(10)
val i2 = "1".toInt(10)
+4 -9
View File
@@ -1,7 +1,6 @@
// ERROR: Type mismatch: inferred type is String but Charset was expected
// ERROR: Type mismatch: inferred type is String but Charset was expected
import java.nio.charset.Charset
import java.util.Comparator
import java.util.Locale
internal class A {
@@ -9,19 +8,19 @@ internal class A {
fun constructors() {
String()
// TODO: new String("original");
String(charArrayOf('a', 'b', 'c'))
String(charArrayOf('b', 'd'), 1, 1)
String(intArrayOf(32, 65, 127), 0, 3)
val bytes = byteArrayOf(32, 65, 100, 81)
val charset: Charset = Charset.forName("utf-8")
val charset = Charset.forName("utf-8")
String(bytes)
String(bytes, charset)
String(bytes, 0, 2)
String(bytes, "utf-8")
String(bytes, 0, 2, "utf-8")
String(bytes, 0, 2, charset)
String(StringBuilder("content"))
String(StringBuffer("content"))
}
@@ -92,11 +91,9 @@ internal class A {
*/
s.trim { it <= ' ' }
"$s another"
s.toByteArray()
s.toByteArray(Charset.forName("utf-8"))
s.toByteArray(charset("utf-8"))
val chars = CharArray(10)
s.toCharArray(chars, 0, 1, 11)
}
@@ -109,20 +106,18 @@ internal class A {
1.11f.toString()
3.14.toString()
Any().toString()
String.format(
Locale.FRENCH,
"Je ne mange pas %d jours",
6
)
String.format("Operation completed with %s", "success")
val chars = charArrayOf('a', 'b', 'c')
String(chars)
String(chars, 1, 2)
String(chars)
String(chars, 1, 2)
val order: Comparator<String?>? = java.lang.String.CASE_INSENSITIVE_ORDER
val order = java.lang.String.CASE_INSENSITIVE_ORDER
}
fun unsupportedMethods() {
@@ -1,8 +1,8 @@
internal class A<T> {
fun foo(nonMutableCollection: Collection<String>?,
mutableCollection: MutableCollection<String>,
fun foo(nonMutableCollection: Collection<String?>?,
mutableCollection: MutableCollection<String?>,
mutableSet: MutableSet<T?>,
mutableMap: MutableMap<String, T>) {
mutableMap: MutableMap<String?, T>) {
mutableCollection.addAll(nonMutableCollection!!)
mutableSet.add(mutableMap.remove("a"))
}
@@ -1,9 +1,9 @@
internal class A {
fun foo(set: MutableSet<String>) {
fun foo(set: MutableSet<String?>) {
bar(set)
}
fun bar(collection: MutableCollection<String>) {
fun bar(collection: MutableCollection<String?>) {
collection.add("a")
}
}
}
+1 -1
View File
@@ -8,7 +8,7 @@ internal class IteratorTest {
mutableMap2.entries.iterator().remove()
}
fun testFunctionParameters(immutableCollection: Collection<String>, mutableList: MutableList<Int>) {
fun testFunctionParameters(immutableCollection: Collection<String?>, mutableList: MutableList<Int?>) {
val it = immutableCollection.iterator()
while (it.hasNext()) {
it.next()
+2 -2
View File
@@ -1,9 +1,9 @@
internal class A {
fun foo(collection: MutableCollection<String>) {
fun foo(collection: MutableCollection<String?>) {
bar(collection)
}
fun bar(collection: MutableCollection<String>) {
fun bar(collection: MutableCollection<String?>) {
if (collection.size < 5) {
foo(collection)
} else {
+4 -4
View File
@@ -11,14 +11,14 @@ internal open class Base {
return ""
}
open fun nya(s: String): String {
open fun nya(s: String?): String? {
return s
}
}
internal interface I {
fun zoo(o: Any?): String?
fun nya(s: String): String {
fun nya(s: String?): String? {
return ""
}
}
@@ -36,7 +36,7 @@ internal class C : Base(), I {
return ""
}
override fun nya(s: String): String {
override fun nya(s: String?): String? {
return ""
}
}
}
+1 -1
View File
@@ -1,6 +1,6 @@
class NullableArray {
fun createArrayFailure(size: Int): Array<String?> {
return arrayOfNulls<String?>(size)
return arrayOfNulls(size)
}
fun createArraySuccess(size: Int): Array<String> {
+1 -1
View File
@@ -9,7 +9,7 @@ internal class X {
}
internal class C {
fun foo(map: HashMap<String, String>): String? {
fun foo(map: HashMap<String?, String?>): String? {
return map["a"]
}
+2 -1
View File
@@ -1,8 +1,9 @@
// RUNTIME_WITH_FULL_JDK
import java.util.Map;
class C {
String foo(Map<Integer, String> map) {
private String foo(Map<Integer, String> map) {
return map.getOrDefault(1, "bar");
}
}
+1 -1
View File
@@ -1,5 +1,5 @@
internal class C {
fun foo(map: Map<Int, String>): String {
private fun foo(map: Map<Int, String>): String {
return map[1] ?: "bar"
}
}
@@ -1,7 +1,7 @@
object C {
fun consume1(c: C) {}
fun consume2(c: C) {}
fun foo(cList: List<C>) {
fun consume1(c: C?) {}
fun consume2(c: C?) {}
fun foo(cList: List<C?>) {
val iter: Iterator<*> = cList.iterator()
while (iter.hasNext()) {
val c = iter.next() as C
@@ -1,9 +1,9 @@
import java.util.HashMap
internal class Test {
fun test(map: HashMap<String, String>) {
map.forEach { (key: String, value: String) -> foo(key, value) }
fun test(map: HashMap<String?, String?>) {
map.forEach { (key: String?, value: String?) -> foo(key, value) }
}
fun foo(key: String, value: String) {}
fun foo(key: String?, value: String?) {}
}
+1 -1
View File
@@ -5,7 +5,7 @@ import java.util.HashMap
internal class Test {
fun main() {
val commonMap = HashMap<String, Int>()
val rawMap: HashMap<*, *> = HashMap<String?, Int?>()
val rawMap: HashMap<*, *> = HashMap<String, Int>()
val superRawMap: HashMap<*, *> = HashMap<Any?, Any?>()
}
}
+1 -1
View File
@@ -5,7 +5,7 @@ import java.util.ArrayList
internal class Test {
fun main() {
val common: List<String> = ArrayList()
val raw: List<*> = ArrayList<String?>()
val raw: List<*> = ArrayList<String>()
val superRaw: List<*> = ArrayList<Any?>()
}
}
+3 -3
View File
@@ -7,8 +7,8 @@ internal class TestT {
internal class U {
fun main() {
val t = TestT()
t.getT<String?>()
t.getT<Int?>()
t.getT<Any?>()
t.getT<String>()
t.getT<Int>()
t.getT<Any>()
}
}
+1 -1
View File
@@ -12,6 +12,6 @@ internal class C {
return string
}
fun foo(i: I) {}
fun foo(i: I?) {}
var string: String? = null
}
@@ -1,9 +1,9 @@
// !specifyLocalVariableTypeByDefault: true
fun foo(list: List<String>) {
fun foo(list: List<String?>) {
val array: IntArray = IntArray(10)
for (i: Int in 0..9) {
array[i] = i
}
for (s: String in list) print(s)
for (s: String? in list) print(s)
}
+2 -3
View File
@@ -1,7 +1,7 @@
package demo
object SwitchDemo {
fun print(o: Any) {
fun print(o: Any?) {
println(o)
}
@@ -78,7 +78,6 @@ object SwitchDemo {
@JvmStatic
fun main(args: Array<String>) {
for (i in 1..12)
test(i)
for (i in 1..12) test(i)
}
}
+2 -2
View File
@@ -5,8 +5,8 @@ import java.util.Arrays
class Foo {
fun test() {
val list: List<String> = Arrays.asList("a", "b")
val array1: Array<Any?> = list.toTypedArray()
val list = Arrays.asList("a", "b")
val array1: Array<Any> = list.toTypedArray()
val array2: Array<Any> = list.toTypedArray<String>()
}
}
+1 -1
View File
@@ -3,7 +3,7 @@ package demo
import java.util.ArrayList
class TestJava {
fun f(result: Function1<String, Unit>) {
fun f(result: Function1<String?, Unit>) {
result.invoke("a")
}
@@ -1,9 +1,9 @@
// ERROR: Null can not be a value of a non-null type Iterator<String?>
// ERROR: Null can not be a value of a non-null type Iterator<String?>
// ERROR: Null can not be a value of a non-null type Iterator<String>
// ERROR: Null can not be a value of a non-null type Iterator<String>
package demo
internal class Test : Iterable<String?> {
override fun iterator(): Iterator<String?> {
override fun iterator(): Iterator<String> {
return null
}
@@ -13,7 +13,7 @@ internal class Test : Iterable<String?> {
}
internal class FullTest : Iterable<String?> {
override fun iterator(): Iterator<String?> {
override fun iterator(): Iterator<String> {
return null
}
@@ -1,9 +1,9 @@
// ERROR: Null can not be a value of a non-null type Iterator<String?>
// ERROR: Null can not be a value of a non-null type Iterator<String?>
// ERROR: Null can not be a value of a non-null type Iterator<String>
// ERROR: Null can not be a value of a non-null type Iterator<String>
package demo
internal class Test : Iterable<String?> {
override fun iterator(): Iterator<String?> {
override fun iterator(): Iterator<String> {
return null
}
@@ -13,7 +13,7 @@ internal class Test : Iterable<String?> {
}
internal class FullTest : Iterable<String?> {
override fun iterator(): Iterator<String?> {
override fun iterator(): Iterator<String> {
return null
}
@@ -1,8 +1,8 @@
// ERROR: Null can not be a value of a non-null type Iterator<String?>
// ERROR: Null can not be a value of a non-null type Iterator<String>
package demo
internal class Test : Iterable<String?> {
override fun iterator(): Iterator<String?> {
override fun iterator(): Iterator<String> {
return null
}
+3 -3
View File
@@ -2,8 +2,8 @@ import java.util.stream.Collectors
class Test {
private fun addPackages(packages: Collection<Number>) {
val sorted: List<Number> = packages.stream()
.filter { repoPackage: Number? -> repoPackage != null }
.collect(Collectors.toList())
val sorted = packages.stream()
.filter { repoPackage: Number? -> repoPackage != null }
.collect(Collectors.toList())
}
}