diff --git a/js/js.translator/testData/java/abstractList/cases/iterator.kt b/js/js.translator/testData/java/abstractList/cases/iterator.kt index e7de9083a08..a5cb20cf7c0 100644 --- a/js/js.translator/testData/java/abstractList/cases/iterator.kt +++ b/js/js.translator/testData/java/abstractList/cases/iterator.kt @@ -4,7 +4,7 @@ import java.util.AbstractList class MyList(vararg val data: T) : AbstractList() { override fun get(index: Int) = data[index] - override fun size() = data.size() + override val size: Int get() = data.size() } fun test(expected: String, list: List) { diff --git a/js/js.translator/testData/java/arrayList/cases/retainAll.kt b/js/js.translator/testData/java/arrayList/cases/retainAll.kt index 76990dbb6e9..ea8042f7348 100644 --- a/js/js.translator/testData/java/arrayList/cases/retainAll.kt +++ b/js/js.translator/testData/java/arrayList/cases/retainAll.kt @@ -3,7 +3,7 @@ package foo import java.util.ArrayList; fun test(a: List, b: List, removed: Boolean, expected: List): String? { - val t = ArrayList(a.size()) + val t = ArrayList(a.size) t.addAll(a) if (t.retainAll(b) != removed) return "$a.retainAll($b) != $removed, result list: $t" diff --git a/js/js.translator/testData/kotlin_lib.js b/js/js.translator/testData/kotlin_lib.js index 0fd49fc4918..c624cd32184 100644 --- a/js/js.translator/testData/kotlin_lib.js +++ b/js/js.translator/testData/kotlin_lib.js @@ -290,7 +290,7 @@ /** @constructs */ function (list, index) { this.list = list; - this.size = list.size(); + this.size = list.size; this.index = (index === undefined) ? 0 : index; }, { hasNext: function () { @@ -399,18 +399,18 @@ return true; }, isEmpty: function () { - return this.size() === 0; + return this.size === 0; }, iterator: function () { // TODO: Do not implement mutable iterator() this way, make abstract return new Kotlin.ArrayIterator(this.toArray()); }, equals_za3rmp$: function (o) { - if (this.size() !== o.size()) return false; + if (this.size !== o.size) return false; var iterator1 = this.iterator(); var iterator2 = o.iterator(); - var i = this.size(); + var i = this.size; while (i-- > 0) { if (!Kotlin.equals(iterator1.next(), iterator2.next())) { return false; @@ -423,7 +423,7 @@ var builder = "["; var iterator = this.iterator(); var first = true; - var i = this.size(); + var i = this.size; while (i-- > 0) { if (first) { first = false; @@ -456,13 +456,13 @@ return new Kotlin.ListIterator(this); }, listIterator_za3lpa$: function(index) { - if (index < 0 || index > this.size()) { - throw new Kotlin.IndexOutOfBoundsException("Index: " + index + ", size: " + this.size()); + if (index < 0 || index > this.size) { + throw new Kotlin.IndexOutOfBoundsException("Index: " + index + ", size: " + this.size); } return new Kotlin.ListIterator(this, index); }, add_za3rmp$: function (element) { - this.add_vux3hl$(this.size(), element); + this.add_vux3hl$(this.size, element); return true; }, addAll_9cca64$: function (index, collection) { @@ -492,14 +492,14 @@ return -1; }, lastIndexOf_za3rmp$: function (o) { - var i = this.listIterator_za3lpa$(this.size()); + var i = this.listIterator_za3lpa$(this.size); while (i.hasPrevious()) if (Kotlin.equals(i.previous(), o)) return i.nextIndex(); return -1; }, subList_vux9f0$: function(fromIndex, toIndex) { - if (fromIndex < 0 || toIndex > this.size()) + if (fromIndex < 0 || toIndex > this.size) throw new Kotlin.IndexOutOfBoundsException(); if (fromIndex > toIndex) throw new Kotlin.IllegalArgumentException(); @@ -533,11 +533,13 @@ this.checkRange(index); this.list.set_vux3hl$(index + this.offset, value); }, - size: function () { - return this._size; + size: { + get: function () { + return this._size; + } }, add_vux3hl$: function (index, element) { - if (index < 0 || index > this.size()) { + if (index < 0 || index > this.size) { throw new Kotlin.IndexOutOfBoundsException(); } this.list.add_vux3hl$(index + this.offset, element); @@ -572,8 +574,10 @@ this.checkRange(index); this.array[index] = value; }, - size: function () { - return this.array.length; + size: { + get: function () { + return this.array.length; + } }, iterator: function () { return Kotlin.arrayIterator(this.array); @@ -587,7 +591,7 @@ }, addAll_4fm7v2$: function (collection) { var it = collection.iterator(); - for (var i = this.array.length, n = collection.size(); n-- > 0;) { + for (var i = this.array.length, n = collection.size; n-- > 0;) { this.array[i++] = it.next(); } }, diff --git a/js/js.translator/testData/maps.js b/js/js.translator/testData/maps.js index 95602409b56..d927d4471fb 100644 --- a/js/js.translator/testData/maps.js +++ b/js/js.translator/testData/maps.js @@ -61,7 +61,7 @@ } function hashSetEquals(o) { - if (o == null || this.size() !== o.size()) return false; + if (o == null || this.size !== o.size) return false; return this.containsAll_4fm7v2$(o); } @@ -399,13 +399,15 @@ return oldValue; }; - this.size = function () { - var total = 0, i = buckets.length; - while (i--) { - total += buckets[i].entries.length; + Object.defineProperty(this, "size", { + get: function () { + var total = 0, i = buckets.length; + while (i--) { + total += buckets[i].entries.length; + } + return total; } - return total; - }; + }); this.each = function (callback) { var entries = that._entries(), i = entries.length, entry; @@ -460,7 +462,7 @@ }; this.equals_za3rmp$ = function(o) { - if (o == null || this.size() !== o.size()) return false; + if (o == null || this.size !== o.size) return false; var entries = this._entries(); var i = entries.length; @@ -563,8 +565,10 @@ isEmpty: function () { return this.map.isEmpty(); }, - size: function () { - return this.map.size(); + size: { + get: function () { + return this.map.size; + } }, contains_za3rmp$: function (o) { return this.map.containsValue_za3rmp$(o); @@ -585,8 +589,10 @@ this.$size = 0; this.map = Object.create(null); }, { - size: function () { - return this.$size; + size: { + get: function () { + return this.$size; + } }, isEmpty: function () { return this.$size === 0; @@ -679,7 +685,7 @@ return builder + "}"; }, equals_za3rmp$: function(o) { - if (o == null || this.size() !== o.size()) return false; + if (o == null || this.size !== o.size) return false; var map = this.map; for (var key in map) { var key_ = this.convertKeyToKeyType(key); @@ -822,8 +828,10 @@ { equals_za3rmp$: hashSetEquals, hashCode: hashSetHashCode, - size: function () { - return this.map.size() + size: { + get: function () { + return this.map.size; + } }, contains_za3rmp$: function (element) { return this.map.containsKey_za3rmp$(element); @@ -897,8 +905,10 @@ { equals_za3rmp$: hashSetEquals, hashCode: hashSetHashCode, - size: function () { - return this.$size; + size: { + get: function () { + return this.$size; + } }, contains_za3rmp$: function (key) { return this.map[key] === true; @@ -1025,9 +1035,9 @@ hashTable.clear(); }; - this.size = function () { - return hashTable.size(); - }; + Object.defineProperty(this, "size", { get: function () { + return hashTable.size; + }}); this.isEmpty = function () { return hashTable.isEmpty(); diff --git a/libraries/stdlib/test/collections/IterableTests.kt b/libraries/stdlib/test/collections/IterableTests.kt index c0bb24d4b58..62d3ca57a2c 100644 --- a/libraries/stdlib/test/collections/IterableTests.kt +++ b/libraries/stdlib/test/collections/IterableTests.kt @@ -142,7 +142,7 @@ abstract class IterableTests>(val data: T, val empty: T) { val foo = data.filter { it.startsWith("f") } expect(true) { foo is List } expect(true) { foo.all { it.startsWith("f") } } - expect(1) { foo.size() } + expect(1) { foo.size } assertEquals(listOf("foo"), foo) } @@ -151,7 +151,7 @@ abstract class IterableTests>(val data: T, val empty: T) { val foo = data.drop(1) expect(true) { foo is List } expect(true) { foo.all { it.startsWith("b") } } - expect(1) { foo.size() } + expect(1) { foo.size } assertEquals(listOf("bar"), foo) } @@ -160,7 +160,7 @@ abstract class IterableTests>(val data: T, val empty: T) { val foo = data.dropWhile { it[0] == 'f' } expect(true) { foo is List } expect(true) { foo.all { it.startsWith("b") } } - expect(1) { foo.size() } + expect(1) { foo.size } assertEquals(listOf("bar"), foo) } @@ -169,7 +169,7 @@ abstract class IterableTests>(val data: T, val empty: T) { val notFoo = data.filterNot { it.startsWith("f") } expect(true) { notFoo is List } expect(true) { notFoo.none { it.startsWith("f") } } - expect(1) { notFoo.size() } + expect(1) { notFoo.size } assertEquals(listOf("bar"), notFoo) } @@ -216,7 +216,7 @@ abstract class IterableTests>(val data: T, val empty: T) { assertTrue { lengths.all { it == 3 } } - assertEquals(2, lengths.size()) + assertEquals(2, lengths.size) assertEquals(listOf(3, 3), lengths) } @@ -228,14 +228,14 @@ abstract class IterableTests>(val data: T, val empty: T) { @Test fun mapIndexed() { val shortened = data.mapIndexed { index, value -> value.substring(0..index) } - assertEquals(2, shortened.size()) + assertEquals(2, shortened.size) assertEquals(listOf("f", "ba"), shortened) } @Test fun withIndex() { val indexed = data.withIndex().map { it.value.substring(0..it.index) } - assertEquals(2, indexed.size()) + assertEquals(2, indexed.size) assertEquals(listOf("f", "ba"), indexed) }