Adjust js stdlib to isEmpty transformation

This commit is contained in:
Denis Zharkov
2015-10-09 14:07:41 +03:00
parent 61459961fc
commit 83b680935b
5 changed files with 26 additions and 18 deletions
+1 -1
View File
@@ -5,5 +5,5 @@ import java.util.ArrayList;
fun box(): Boolean { fun box(): Boolean {
val a = ArrayList<Int>(); val a = ArrayList<Int>();
a.add(3) a.add(3)
return !(a.isEmpty()) && (ArrayList<Int>().isEmpty()); return !(a.isEmpty) && (ArrayList<Int>().isEmpty);
} }
+2 -2
View File
@@ -28,7 +28,7 @@ fun box(): Boolean {
return false return false
} }
if (a.isEmpty() || !ArrayList<Int>().isEmpty()) { if (a.isEmpty || !ArrayList<Int>().isEmpty) {
return false return false
} }
@@ -39,7 +39,7 @@ fun box(): Boolean {
assertEquals(a, b, "a == b") assertEquals(a, b, "a == b")
a.clear() a.clear()
assertEquals(true, a.isEmpty(), "a.isEmpty()") assertEquals(true, a.isEmpty, "a.isEmpty")
assertEquals(arrayOf(1, 500, 2, 3), list.toTypedArray(), "list.toTypedArray()") assertEquals(arrayOf(1, 500, 2, 3), list.toTypedArray(), "list.toTypedArray()")
+5 -3
View File
@@ -398,8 +398,10 @@
} }
return true; return true;
}, },
isEmpty: function () { isEmpty: {
return this.size === 0; get: function () {
return this.size === 0;
}
}, },
iterator: function () { iterator: function () {
// TODO: Do not implement mutable iterator() this way, make abstract // TODO: Do not implement mutable iterator() this way, make abstract
@@ -970,7 +972,7 @@
}); });
Kotlin.collectionsMax = function (c, comp) { Kotlin.collectionsMax = function (c, comp) {
if (c.isEmpty()) { if (c.isEmpty) {
//TODO: which exception? //TODO: which exception?
throw new Error(); throw new Error();
} }
+17 -11
View File
@@ -347,9 +347,11 @@
bucketsByHash = {}; bucketsByHash = {};
}; };
this.isEmpty = function () { Object.defineProperty(this, "isEmpty", {
return !buckets.length; get: function () {
}; return !buckets.length;
}
});
var createBucketAggregator = function (bucketFuncName) { var createBucketAggregator = function (bucketFuncName) {
return function () { return function () {
@@ -562,8 +564,10 @@
iterator: function () { iterator: function () {
return new Kotlin.PrimitiveHashMapValuesIterator(this.map.map, Object.keys(this.map.map)); return new Kotlin.PrimitiveHashMapValuesIterator(this.map.map, Object.keys(this.map.map));
}, },
isEmpty: function () { isEmpty: {
return this.map.isEmpty(); get: function () {
return this.map.isEmpty;
}
}, },
size: { size: {
get: function () { get: function () {
@@ -594,8 +598,10 @@
return this.$size; return this.$size;
} }
}, },
isEmpty: function () { isEmpty: {
return this.$size === 0; get: function () {
return this.$size === 0;
}
}, },
containsKey_za3rmp$: function (key) { containsKey_za3rmp$: function (key) {
// TODO: should process "__proto__" separately? // TODO: should process "__proto__" separately?
@@ -669,7 +675,7 @@
return this.map; return this.map;
}, },
toString: function() { toString: function() {
if (this.isEmpty()) return "{}"; if (this.isEmpty) return "{}";
var map = this.map; var map = this.map;
var isFirst = true; var isFirst = true;
var builder = "{"; var builder = "{";
@@ -1039,9 +1045,9 @@
return hashTable.size; return hashTable.size;
}}); }});
this.isEmpty = function () { Object.defineProperty(this, "isEmpty", { get: function () {
return hashTable.isEmpty(); return hashTable.isEmpty;
}; }});
this.clone = function () { this.clone = function () {
var h = new HashSet(hashingFunction, equalityFunction); var h = new HashSet(hashingFunction, equalityFunction);
@@ -11,7 +11,7 @@ fun box(): String {
assertTrue((stdlib_emptyListClass(): Any) is List<*>, "stdlib_emptyListClass() is List<*> #2") assertTrue((stdlib_emptyListClass(): Any) is List<*>, "stdlib_emptyListClass() is List<*> #2")
assertTrue((stdlib_emptyListClass(): Any) !is ArrayList<*>, "stdlib_emptyListClass() !is ArrayList<*>") assertTrue((stdlib_emptyListClass(): Any) !is ArrayList<*>, "stdlib_emptyListClass() !is ArrayList<*>")
assertTrue(stdlib_emptyListClass().isEmpty(), "stdlib_emptyListClass().isEmpty()") assertTrue(stdlib_emptyListClass().isEmpty, "stdlib_emptyListClass().isEmpty")
assertTrue(stdlib_emptyListClass().size() == 0, "stdlib_emptyListClass().size() == 0") assertTrue(stdlib_emptyListClass().size() == 0, "stdlib_emptyListClass().size() == 0")
return "OK" return "OK"