J2K: coversion of specially mapped built-in methods + replacing "get" with "[]" where possible

This commit is contained in:
Valentin Kipyatkov
2015-10-16 22:45:19 +03:00
parent 50f559a1c8
commit dc909ac166
29 changed files with 327 additions and 57 deletions
@@ -6,6 +6,6 @@ internal class Foo {
fun foo(o: HashSet<Any?>?) {
val o2: HashSet<Any?>? = o
var foo: Int = 0
foo = o2!!.size()
foo = o2!!.size
}
}
@@ -4,6 +4,6 @@ internal class Foo {
fun foo(o: HashSet<Any>) {
val o2 = o
var foo = 0
foo = o2.size()
foo = o2.size
}
}
@@ -0,0 +1,22 @@
import java.util.HashMap;
import kotlinApi.KotlinClass;
class X {
int get(int index) {
return 0;
}
}
class C {
String foo(HashMap<String, String> map) {
return map.get("a");
}
int foo(X x) {
return x.get(0);
}
int foo(KotlinClass kotlinClass) {
return kotlinClass.get(0); // not operator!
}
}
@@ -0,0 +1,23 @@
// ERROR: Type mismatch: inferred type is kotlin.String? but kotlin.String was expected
import java.util.HashMap
import kotlinApi.KotlinClass
internal class X {
fun get(index: Int): Int {
return 0
}
}
internal class C {
fun foo(map: HashMap<String, String>): String {
return map["a"]
}
fun foo(x: X): Int {
return x.get(0)
}
fun foo(kotlinClass: KotlinClass): Int {
return kotlinClass.get(0) // not operator!
}
}
@@ -1,7 +1,7 @@
internal class C {
fun foo(o: Any) {
if (o is String) {
val l = o.length()
val l = o.length
}
}
}
@@ -1,7 +1,7 @@
internal class C {
fun foo(o: Any) {
if (o is String) {
val l = o.length()
val l = o.length
val substring = o.substring(l - 2)
}
}
@@ -7,7 +7,7 @@ internal class A// this is a primary constructor
} // end of primary constructor body
// this is a secondary constructor 2
constructor(s: String) : this(s.length()) {
constructor(s: String) : this(s.length) {
} // end of secondary constructor 2 body
}// this is a secondary constructor 1
// end of secondary constructor 1 body
@@ -1,3 +1,3 @@
internal open class Base(o: Any, l: Int)
internal class C(private val string: String) : Base(string, string.length())
internal class C(private val string: String) : Base(string, string.length)
@@ -1 +1 @@
internal class C @JvmOverloads constructor(private val string: String, a: Int = string.length())
internal class C @JvmOverloads constructor(private val string: String, a: Int = string.length)
+1 -1
View File
@@ -2,6 +2,6 @@ internal enum class Color : Runnable {
WHITE, BLACK, RED, YELLOW, BLUE;
override fun run() {
println("name()=" + name() + ", toString()=" + toString())
println("name()=" + name + ", toString()=" + toString())
}
}
+1 -1
View File
@@ -1,6 +1,6 @@
class A {
internal fun foo(collection: Collection<String>) {
for (i in collection.size() downTo 0) {
for (i in collection.size downTo 0) {
println(i)
}
}
+1 -1
View File
@@ -1,6 +1,6 @@
internal object Test {
fun toFileSystemSafeName(name: String): String {
val size = name.length()
val size = name.length
return name
}
}
@@ -2,6 +2,6 @@ import kotlinApi.*
internal class A {
fun foo(t: KotlinTrait): Int {
return t.nullableFun()!!.length() + t.notNullableFun().length()
return t.nullableFun()!!.length + t.notNullableFun().length
}
}
@@ -2,6 +2,6 @@ import kotlinApi.*
internal class A {
fun foo(c: KotlinClass): Int {
return c.nullableProperty!!.length() + c.property.length() + KotlinClass.nullableStaticVar!! + KotlinClass.staticVar + KotlinClass.nullableStaticFun(1)!! + KotlinClass.staticFun(1) + nullableGlobalFunction("")!!.length() + globalFunction("").length()
return c.nullableProperty!!.length + c.property.length + KotlinClass.nullableStaticVar!! + KotlinClass.staticVar + KotlinClass.nullableStaticFun(1)!! + KotlinClass.staticFun(1) + nullableGlobalFunction("")!!.length + globalFunction("").length
}
}
@@ -0,0 +1,30 @@
import java.util.*;
enum E {
A, B, C
}
class A {
void foo(List<String> list, Collection<Integer> collection, Map<Integer, Integer> map) {
int a = "".length();
String b = E.A.name();
int c = E.A.ordinal();
int d = list.size() + collection.size();
int e = map.size();
int f = map.keySet().size();
int g = map.values().size();
int h = map.entrySet().size();
}
void bar(List<String> list) {
char c = "a".charAt(0);
byte b = new Integer(10).byteValue();
int i = new Double(10.1).intValue();
float f = new Double(10.1).floatValue();
long l = new Double(10.1).longValue();
short s = new Double(10.1).shortValue();
String removed = list.remove(10);
Boolean isRemoved = list.remove("a");
}
}
@@ -0,0 +1,30 @@
import java.util.*
internal enum class E {
A, B, C
}
internal class A {
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
val d = list.size + collection.size
val e = map.size
val f = map.keys.size
val g = map.values.size
val h = map.entries.size
}
fun bar(list: MutableList<String>) {
val c = "a"[0]
val b = 10.toByte()
val i = 10.1.toInt()
val f = 10.1.toFloat()
val l = 10.1.toLong()
val s = 10.1.toShort()
val removed = list.removeAt(10)
val isRemoved = list.remove("a")
}
}
@@ -25,12 +25,12 @@ internal class A {
fun normalMethods() {
val s = "test string"
s.length()
s.length
s.isEmpty()
s.charAt(1)
s[1]
s.codePointAt(2)
s.codePointBefore(2)
s.codePointCount(0, s.length())
s.codePointCount(0, s.length)
s.offsetByCodePoints(0, 4)
s.compareTo("test 2")
s.concat(" another")
+1 -1
View File
@@ -6,7 +6,7 @@ internal class A {
}
fun bar(collection: MutableCollection<String>) {
if (collection.size() < 5) {
if (collection.size < 5) {
foo(collection)
} else {
collection.add("a")
@@ -4,6 +4,6 @@ internal class C {
}
fun foo(): Int {
return getString(true)!!.length()
return getString(true)!!.length
}
}
@@ -1,5 +1,5 @@
fun foo(s: String?, b: Boolean): Int {
if (s == null) println("null")
if (b) return s!!.length()
if (b) return s!!.length
return 10
}
+1 -1
View File
@@ -1,7 +1,7 @@
internal class A {
fun foo(s: String?): Int {
if (s != null) {
return s.length()
return s.length
}
return -1
}