diff --git a/stdlib/ktSrc/JavaUtilMap.kt b/stdlib/ktSrc/JavaUtilMap.kt index b2749cb3060..3125f3b4d4c 100644 --- a/stdlib/ktSrc/JavaUtilMap.kt +++ b/stdlib/ktSrc/JavaUtilMap.kt @@ -13,6 +13,9 @@ val JMap<*,*>.size : Int val JMap<*,*>.empty : Boolean get() = isEmpty() +/** Provides [] access to maps */ +fun JMap.set(key : K, value : V) = this.put(key, value) + /** Returns the key of the entry */ val JEntry.key : K get() = getKey() diff --git a/templatelib/src/TemplateHtml.kt b/templatelib/src/TemplateHtml.kt index 955070382ea..39323d78b90 100644 --- a/templatelib/src/TemplateHtml.kt +++ b/templatelib/src/TemplateHtml.kt @@ -120,7 +120,6 @@ class Body() : BodyTag("body") { fun a(href : String, init : A.()-> Unit) { val a = initTag(init) a.href = href - a.attributes.put("href", href) } } @@ -146,15 +145,11 @@ class A() : BodyTag("a") { override fun create() = A() } - var href: String? = null - /* - TODO this doesn't compile - see http://youtrack.jetbrains.net/issue/KT-866 - - var href : String - get() = attributes["href"] - set(value) { attributes["href"] = value } - */ + var href : String + get() = attributes["href"] + set(value) { + attributes["href"] = value + } } fun body(init: Body.()-> Unit): Body { diff --git a/testlib/test/MapTest.kt b/testlib/test/MapTest.kt index a22eb122026..6589210d337 100644 --- a/testlib/test/MapTest.kt +++ b/testlib/test/MapTest.kt @@ -36,4 +36,17 @@ class MapTest() : TestSupport() { assertEquals(data.size, 0) } + + fun testSetViaIndexOperators() { + // TODO cant just create a HashMap due to KT-834 + val map: Map = HashMap() + assert{ map.empty } + assertEquals(map.size, 0) + + map["name"] = "James" + + assert{ !map.empty } + assertEquals(map.size, 1) + assertEquals("James", map["name"]) + } } \ No newline at end of file