Java to Kotlin converter: more smartness about nullability

This commit is contained in:
Valentin Kipyatkov
2014-06-06 21:26:25 +04:00
parent e947ad7294
commit 0695f6b3d7
18 changed files with 143 additions and 10 deletions
@@ -1,6 +1,6 @@
//file
class C {
private String s = "";
private String s = x();
void foo() {
if (s == null) {
@@ -1,5 +1,5 @@
class C() {
private var s: String? = ""
private var s: String? = x()
fun foo() {
if (s == null) {
@@ -0,0 +1,13 @@
//file
interface I {
String getString();
}
class C {
void foo(I i) {
final String result = i.getString();
if (result != null) {
print(result);
}
}
}
@@ -0,0 +1,12 @@
trait I {
public fun getString(): String?
}
class C() {
fun foo(i: I) {
val result = i.getString()
if (result != null) {
print(result)
}
}
}
@@ -0,0 +1,13 @@
//file
interface I {
String getString();
}
class C {
void foo(I i) {
String result = i.getString();
if (result != null) {
print(result);
}
}
}
@@ -0,0 +1,12 @@
trait I {
public fun getString(): String?
}
class C() {
fun foo(i: I) {
val result = i.getString()
if (result != null) {
print(result)
}
}
}
@@ -0,0 +1,14 @@
//file
interface I {
String getString();
}
class C {
void foo(I i, boolean b) {
String result = i.getString();
if (b) result = null;
if (result != null) {
print(result);
}
}
}
@@ -0,0 +1,14 @@
trait I {
public fun getString(): String
}
class C() {
fun foo(i: I, b: Boolean) {
val result = i.getString()
if (b)
result = null
if (result != null) {
print(result)
}
}
}
@@ -0,0 +1,8 @@
//file
import org.jetbrains.annotations.Nullable;
class C {
@Nullable private final String string = getString();
static String getString() { return x(); }
}
@@ -0,0 +1,10 @@
class C() {
private val string: String? = getString()
class object {
fun getString(): String? {
return x()
}
}
}