Rewrite mutable collection stub method generation

The main problem of the previous approach was that we were only generating
erased method signatures, which was incorrect in case a class also had a member
from another supertype with the same signature as the substituted one from the
collection. Javac issues compilation errors when compiling Java code against
such classes.

Also all the needed method stub signatures were hardcoded in
generateBuiltInMethodStubs() and the case of MutableListIterator was missing
This commit is contained in:
Alexander Udalov
2014-10-22 16:48:30 +04:00
parent 1fc9c58b24
commit 35e956609a
25 changed files with 795 additions and 112 deletions
@@ -0,0 +1,20 @@
import java.util.AbstractList
class A : AbstractList<String>() {
override fun get(index: Int): String = ""
override fun size(): Int = 0
}
fun box(): String {
val a = A()
val b = A()
a.addAll(b)
a.addAll(0, b)
a.removeAll(b)
a.retainAll(b)
a.clear()
a.remove("")
return "OK"
}
@@ -0,0 +1,22 @@
import java.util.AbstractMap
import java.util.Collections
class A : AbstractMap<Int, String>() {
override fun entrySet(): Set<Map.Entry<Int, String>> = Collections.emptySet()
}
fun box(): String {
val a = A()
val b = A()
a.remove(0)
a.putAll(b)
a.clear()
a.keySet()
a.values()
a.entrySet()
return "OK"
}
@@ -0,0 +1,20 @@
import java.util.HashSet
class A : HashSet<Long>()
fun box(): String {
val a = A()
val b = A()
a.iterator()
a.add(0L)
a.remove(0L)
a.addAll(b)
a.removeAll(b)
a.retainAll(b)
a.clear()
return "OK"
}
@@ -0,0 +1,24 @@
// KT-6042 java.lang.UnsupportedOperationException with ArrayList
import java.util.ArrayList
class A : ArrayList<String>()
fun box(): String {
val a = A()
val b = A()
a.addAll(b)
a.addAll(0, b)
a.removeAll(b)
a.retainAll(b)
a.clear()
a.add("")
a.set(0, "")
a.add(0, "")
a.remove(0)
a.remove("")
return "OK"
}
@@ -0,0 +1,20 @@
import java.util.HashMap
class A : HashMap<String, Double>()
fun box(): String {
val a = A()
val b = A()
a.put("", 0.0)
a.remove("")
a.putAll(b)
a.clear()
a.keySet()
a.values()
a.entrySet()
return "OK"
}
@@ -0,0 +1,20 @@
import java.util.HashSet
class A : HashSet<Long>()
fun box(): String {
val a = A()
val b = A()
a.iterator()
a.add(0L)
a.remove(0L)
a.addAll(b)
a.removeAll(b)
a.retainAll(b)
a.clear()
return "OK"
}