Java to Kotlin converter: even more smartness about nullability

This commit is contained in:
Valentin Kipyatkov
2014-06-04 17:35:46 +04:00
parent 15ffb6768c
commit d49b4f86fd
29 changed files with 273 additions and 50 deletions
@@ -0,0 +1,8 @@
//file
class C {
private String s = "";
void foo() {
s = null
}
}
@@ -0,0 +1,7 @@
class C() {
private var s: String? = ""
fun foo() {
s = null
}
}
@@ -0,0 +1,10 @@
//file
class C {
private String s = "";
void foo() {
if (s == null) {
System.out.print("null");
}
}
}
@@ -0,0 +1,9 @@
class C() {
private var s: String? = ""
fun foo() {
if (s == null) {
System.out.print("null")
}
}
}
@@ -0,0 +1,14 @@
//file
class C {
private String s;
public C(String s) {
this.s = s;
}
void foo() {
if (s != null) {
System.out.print("not null");
}
}
}
@@ -0,0 +1,8 @@
class C(private var s: String?) {
fun foo() {
if (s != null) {
System.out.print("not null")
}
}
}
@@ -0,0 +1,12 @@
//file
class C {
public String s = "";
}
class D {
void foo(C c) {
if (null == c.s) {
System.out.println("null");
}
}
}
@@ -0,0 +1,11 @@
class C() {
public var s: String? = ""
}
class D() {
fun foo(c: C) {
if (null == c.s) {
System.out.println("null")
}
}
}
@@ -0,0 +1,11 @@
//file
class C {
private String s;
public C(String s) {
this.s = s;
if (s == null) {
System.out.print("null");
}
}
}
@@ -0,0 +1,7 @@
class C(private var s: String?) {
{
if (s == null) {
System.out.print("null")
}
}
}
@@ -0,0 +1,6 @@
//method
void foo(String s) {
if (s != null) {
zoo(s)
}
}
@@ -0,0 +1,5 @@
fun foo(s: String?) {
if (s != null) {
zoo(s)
}
}
@@ -0,0 +1,8 @@
//method
// !specifyLocalVariableTypeByDefault: true
void foo(boolean b) {
String s = "abc";
if (b) {
s = null
}
}
@@ -0,0 +1,7 @@
// !specifyLocalVariableTypeByDefault: true
fun foo(b: Boolean) {
val s: String? = "abc"
if (b) {
s = null
}
}
@@ -0,0 +1,8 @@
//method
// !specifyLocalVariableTypeByDefault: true
void foo() {
String s = bar()
if (s != null) {
zoo(s)
}
}
@@ -0,0 +1,7 @@
// !specifyLocalVariableTypeByDefault: true
fun foo() {
val s: String? = bar()
if (s != null) {
zoo(s)
}
}