New J2K: add some tests from obsolete issues

This commit is contained in:
Ilya Kirillov
2019-06-21 17:31:17 +03:00
parent 98be5d8ed0
commit 0dfaae2bb4
41 changed files with 557 additions and 0 deletions
+7
View File
@@ -0,0 +1,7 @@
public class JJ {
public static void foo() {}
public void bar() {
this.foo();
}
}
+9
View File
@@ -0,0 +1,9 @@
class JJ {
fun bar() {
foo()
}
companion object {
fun foo() {}
}
}
+12
View File
@@ -0,0 +1,12 @@
public class A {
public interface I {
void f();
}
}
public class B extends A {
}
public class Test {
public B.I z = null;
}
+10
View File
@@ -0,0 +1,10 @@
open class A {
interface I {
fun f()
}
}
class B : A()
class Test {
var z: A.I? = null
}
+24
View File
@@ -0,0 +1,24 @@
package test.nullabilityOnClassBoundaries;
public class Item {
private String s1;
private String s2;
public void set(String s1, String s2) {
this.s1 = s1;
this.s2 = s2;
}
}
public class Reader {
public Item readItem(int n) {
Item item = new Item();
item.set(readString(n), null);
return item;
}
public String readString(int n) {
if (n <= 0) return null;
return Integer.toString(n);
}
}
+22
View File
@@ -0,0 +1,22 @@
package test.nullabilityOnClassBoundaries
class Item {
private var s1: String? = null
private var s2: String? = null
operator fun set(s1: String?, s2: String?) {
this.s1 = s1
this.s2 = s2
}
}
class Reader {
fun readItem(n: Int): Item {
val item = Item()
item[readString(n)] = null
return item
}
fun readString(n: Int): String? {
return if (n <= 0) null else Integer.toString(n)
}
}
+15
View File
@@ -0,0 +1,15 @@
package test;
public class TestMutltipleCtors {
private int x;
private int y;
public TestMutltipleCtors(int x) {
this.x = x;
}
public TestMutltipleCtors(int x, int y) {
this.x = x;
this.y = y;
}
}
+15
View File
@@ -0,0 +1,15 @@
package test
class TestMutltipleCtors {
private var x: Int
private var y = 0
constructor(x: Int) {
this.x = x
}
constructor(x: Int, y: Int) {
this.x = x
this.y = y
}
}
+15
View File
@@ -0,0 +1,15 @@
package test.hierarchy;
public class Base {
public void doStuff(String s) {}
}
public class Derived extends Base {
@Override
public void doStuff(String s) {
if (s == null)
System.out.println("null");
else
System.out.println("not null: " + s);
}
}
+11
View File
@@ -0,0 +1,11 @@
package test.hierarchy
open class Base {
open fun doStuff(s: String?) {}
}
class Derived : Base() {
override fun doStuff(s: String?) {
if (s == null) println("null") else println("not null: $s")
}
}
+9
View File
@@ -0,0 +1,9 @@
package test;
import java.util.HashMap;
public class TestPrimitiveFromMap {
public int foo(HashMap<String, Integer> map) {
return map.get("zzz");
}
}
+9
View File
@@ -0,0 +1,9 @@
package test
import java.util.HashMap
class TestPrimitiveFromMap {
fun foo(map: HashMap<String, Int?>): Int {
return map["zzz"]!!
}
}
+9
View File
@@ -0,0 +1,9 @@
package test;
import java.util.Map;
public class TestMapGetAsReceiver {
public int foo(Map<String, String> map) {
return map.get("zzz").length();
}
}
+7
View File
@@ -0,0 +1,7 @@
package test
class TestMapGetAsReceiver {
fun foo(map: Map<String, String?>): Int {
return map["zzz"]!!.length
}
}
+15
View File
@@ -0,0 +1,15 @@
package test;
public class TestValReassign {
private String s1;
private String s2;
public TestValReassign(String s1) {
this.s1 = s1;
}
public TestValReassign(String s1, String s2) {
this(s1);
this.s2 = s2;
}
}
+10
View File
@@ -0,0 +1,10 @@
package test
class TestValReassign(private val s1: String) {
private var s2: String? = null
constructor(s1: String?, s2: String?) : this(s1!!) {
this.s2 = s2
}
}
+4
View File
@@ -0,0 +1,4 @@
public class TestNestedClassesHierarchy {
public static class Base {}
public static class Derived extends Base {}
}
+4
View File
@@ -0,0 +1,4 @@
class TestNestedClassesHierarchy {
open class Base
class Derived : Base()
}
+22
View File
@@ -0,0 +1,22 @@
public class TestToStringReturnsNullable {
public static class Base {
public String string;
}
public static class Ctor extends Base {
public Ctor(String string) {
this.string = string;
}
}
public static class Derived extends Ctor {
public Derived(String string) {
super(string);
}
@Override
public String toString() {
return string;
}
}
}
+17
View File
@@ -0,0 +1,17 @@
class TestToStringReturnsNullable {
open class Base {
var string: String? = null
}
open class Ctor(string: String?) : Base() {
init {
this.string = string
}
}
class Derived(string: String?) : Ctor(string) {
override fun toString(): String {
return string!!
}
}
}
+6
View File
@@ -0,0 +1,6 @@
public class TestJavaBoxedPrimitives {
public Object[] foo(Boolean x1, Byte x2, Short x3, Integer x4,
Long x5, Float x6, Double x7, Character x8) {
return new Object[]{x1, x2, x3, x4, x5, x6, x7, x8};
}
}
+6
View File
@@ -0,0 +1,6 @@
class TestJavaBoxedPrimitives {
fun foo(x1: Boolean, x2: Byte, x3: Short, x4: Int,
x5: Long, x6: Float, x7: Double, x8: Char): Array<Any> {
return arrayOf(x1, x2, x3, x4, x5, x6, x7, x8)
}
}
+6
View File
@@ -0,0 +1,6 @@
public class TestNumberConversionsInTernary {
public double intOrDoubleAsDouble(boolean flag, int x, double y) {
double result = flag ? x : y;
return result;
}
}
+5
View File
@@ -0,0 +1,5 @@
class TestNumberConversionsInTernary {
fun intOrDoubleAsDouble(flag: Boolean, x: Int, y: Double): Double {
return (if (flag) x else y).toDouble()
}
}
+15
View File
@@ -0,0 +1,15 @@
public class TestNumberConversionInSetter {
private double d;
public void init() {
setD(1);
}
public double getD() {
return d;
}
public void setD(double d) {
this.d = d;
}
}
+8
View File
@@ -0,0 +1,8 @@
class TestNumberConversionInSetter {
var d = 0.0
fun init() {
d = 1.0
}
}
+7
View File
@@ -0,0 +1,7 @@
public class TestInnerClassCtor {
public class Inner {}
public void test() {
new TestInnerClassCtor.Inner();
}
}
+7
View File
@@ -0,0 +1,7 @@
class TestInnerClassCtor {
inner class Inner
fun test() {
Inner()
}
}
+8
View File
@@ -0,0 +1,8 @@
// RUNTIME_WITH_FULL_JDK
import java.util.function.Predicate;
public class TestSamInitializedWithLambda {
public final Predicate<String> isEmpty =
x -> x.length() == 0;
}
+5
View File
@@ -0,0 +1,5 @@
import java.util.function.Predicate
class TestSamInitializedWithLambda {
val isEmpty = Predicate { x: String -> x.length == 0 }
}
+16
View File
@@ -0,0 +1,16 @@
public class TestInitializeInTry {
Object x;
private Object y;
public TestInitializeInTry() {
try {
x = new Object();
y = new Object();
}
catch (Exception e) {
e.printStackTrace();
}
x.toString();
y.toString();
}
}
+15
View File
@@ -0,0 +1,15 @@
class TestInitializeInTry {
internal var x: Any? = null
private var y: Any? = null
init {
try {
x = Any()
y = Any()
} catch (e: Exception) {
e.printStackTrace()
}
x.toString()
y.toString()
}
}
+7
View File
@@ -0,0 +1,7 @@
public class Test {
int foo = 1;
public Test() {
int foo = foo = 2;
}
}
+8
View File
@@ -0,0 +1,8 @@
class Test {
internal var foo = 1
init {
foo = 2
val foo = foo
}
}
+17
View File
@@ -0,0 +1,17 @@
package test;
import java.util.Random;
public class Test {
public static void x() {
int a, b;
switch (new Random().nextInt()) {
case 0:
a = b = 1;
break;
default:
a = b = -1;
}
System.out.println(a + b);
}
}
+21
View File
@@ -0,0 +1,21 @@
package test
import java.util.Random
object Test {
fun x() {
val a: Int
val b: Int
when (Random().nextInt()) {
0 -> {
b = 1
a = b
}
else -> {
b = -1
a = b
}
}
println(a + b)
}
}
+3
View File
@@ -0,0 +1,3 @@
public class J {
public double x;
}
+3
View File
@@ -0,0 +1,3 @@
class J {
var x = 0.0
}
+24
View File
@@ -0,0 +1,24 @@
public class ArrayNullable {
public static void main(String[] args) {
int notNull = 0;
Integer[] a1 = new Integer[2];
a1[0] = null;
a1[1] = notNull;
System.out.println(a1[0]);
System.out.println(a1[1]);
Integer[] a2 = new Integer[2];
a2[0] = nullable();
a2[1] = notNull;
System.out.println(a2[0]);
System.out.println(a2[1]);
Integer[] a3 = new Integer[] { null, nullable(), notNull };
System.out.println(a3[0]);
System.out.println(a3[1]);
System.out.println(a3[2]);
}
public static Integer nullable() { return System.getProperty("user.home").length() > 20 ? null : 1; }
}
+24
View File
@@ -0,0 +1,24 @@
object ArrayNullable {
@JvmStatic
fun main(args: Array<String>) {
val notNull = 0
val a1: Array<Int?> = arrayOfNulls(2)
a1[0] = null
a1[1] = notNull
println(a1[0])
println(a1[1])
val a2: Array<Int?> = arrayOfNulls(2)
a2[0] = nullable()
a2[1] = notNull
println(a2[0])
println(a2[1])
val a3 = arrayOf(null, nullable(), notNull)
println(a3[0])
println(a3[1])
println(a3[2])
}
fun nullable(): Int? {
return if (System.getProperty("user.home").length > 20) null else 1
}
}