From dadcdb5771e6eeecae0fb370b9add4a7cdb38cf6 Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Sat, 14 Nov 2015 06:21:17 +0300 Subject: [PATCH] StdLib cleanup, deprecated symbol usage: List and Map members --- libraries/stdlib/src/kotlin/io/files/Utils.kt | 2 +- .../test/collections/CollectionBehaviors.kt | 8 ++++---- .../test/collections/CollectionJVMTest.kt | 2 +- .../stdlib/test/collections/MapJVMTest.kt | 6 +++--- libraries/stdlib/test/collections/MapTest.kt | 10 +++++----- .../test/collections/ReversedViewsTest.kt | 6 +++--- libraries/stdlib/test/io/Files.kt | 4 ++-- libraries/stdlib/test/js/MapJsTest.kt | 20 +++++++++---------- libraries/tools/idl2k/src/main/kotlin/idl.kt | 8 ++++---- libraries/tools/idl2k/src/main/kotlin/main.kt | 4 ++-- .../tools/idl2k/src/main/kotlin/render.kt | 20 +++++++++---------- .../idl2k/src/main/kotlin/typeMappings.kt | 4 ++-- .../annotation/AnnotationListParseTest.kt | 4 ++-- .../internal/AnnotationProcessingManager.kt | 2 +- .../kotlin/gradle/plugin/ThreadTracker.kt | 2 +- 15 files changed, 51 insertions(+), 51 deletions(-) diff --git a/libraries/stdlib/src/kotlin/io/files/Utils.kt b/libraries/stdlib/src/kotlin/io/files/Utils.kt index bad0ba29e1f..3c1ac8bcd7d 100644 --- a/libraries/stdlib/src/kotlin/io/files/Utils.kt +++ b/libraries/stdlib/src/kotlin/io/files/Utils.kt @@ -368,7 +368,7 @@ public fun File.normalize(): File { when (name) { "." -> { } - ".." -> if (!list.isEmpty() && list.get(list.size - 1) != "..") list.remove(list.size - 1) else list.add(name) + ".." -> if (!list.isEmpty() && list.get(list.size - 1) != "..") list.removeAt(list.size - 1) else list.add(name) else -> list.add(name) } } diff --git a/libraries/stdlib/test/collections/CollectionBehaviors.kt b/libraries/stdlib/test/collections/CollectionBehaviors.kt index a32a193ed2d..47bb716df45 100644 --- a/libraries/stdlib/test/collections/CollectionBehaviors.kt +++ b/libraries/stdlib/test/collections/CollectionBehaviors.kt @@ -87,15 +87,15 @@ public fun CompareContext>.mapBehavior() { (object {}).let { propertyEquals { containsKey(it)} } if (expected.isEmpty().not()) - propertyEquals { contains(keySet().first()) } + propertyEquals { contains(keys.first()) } propertyEquals { containsKeyRaw(keys.firstOrNull()) } propertyEquals { containsValueRaw(values.firstOrNull()) } propertyEquals { getRaw(null) } - compareProperty( { keySet() }, { setBehavior("keySet") } ) - compareProperty( { entrySet() }, { setBehavior("entrySet") } ) - compareProperty( { values() }, { collectionBehavior("values") }) + compareProperty( { keys }, { setBehavior("keySet") } ) + compareProperty( { entries }, { setBehavior("entrySet") } ) + compareProperty( { values }, { collectionBehavior("values") }) } public fun CompareContext.equalityBehavior(objectName: String = "") { diff --git a/libraries/stdlib/test/collections/CollectionJVMTest.kt b/libraries/stdlib/test/collections/CollectionJVMTest.kt index 14b34a0048b..2488b6289f3 100644 --- a/libraries/stdlib/test/collections/CollectionJVMTest.kt +++ b/libraries/stdlib/test/collections/CollectionJVMTest.kt @@ -15,7 +15,7 @@ class CollectionJVMTest { private fun identitySetOf(vararg values: T): MutableSet { val map = IdentityHashMap() values.forEach { map.put(it, "") } - return map.keySet() + return map.keys } private data class IdentityData(public val value: Int) diff --git a/libraries/stdlib/test/collections/MapJVMTest.kt b/libraries/stdlib/test/collections/MapJVMTest.kt index 412b58b821f..909a99e72b0 100644 --- a/libraries/stdlib/test/collections/MapJVMTest.kt +++ b/libraries/stdlib/test/collections/MapJVMTest.kt @@ -12,7 +12,7 @@ class MapJVMTest { assertEquals(1, map["a"]) assertEquals(2, map["b"]) assertEquals(3, map["c"]) - assertEquals(listOf("a", "b", "c"), map.keySet().toList()) + assertEquals(listOf("a", "b", "c"), map.keys.toList()) } @test fun toSortedMap() { @@ -21,13 +21,13 @@ class MapJVMTest { assertEquals(1, sorted["a"]) assertEquals(2, sorted["b"]) assertEquals(3, sorted["c"]) - assertEquals(listOf("a", "b", "c"), sorted.keySet().toList()) + assertEquals(listOf("a", "b", "c"), sorted.keys.toList()) } @test fun toSortedMapWithComparator() { val map = mapOf(Pair("c", 3), Pair("bc", 2), Pair("bd", 4), Pair("abc", 1)) val sorted = map.toSortedMap(compareBy { it.length } thenBy { it }) - assertEquals(listOf("c", "bc", "bd", "abc"), sorted.keySet().toList()) + assertEquals(listOf("c", "bc", "bd", "abc"), sorted.keys.toList()) assertEquals(1, sorted["abc"]) assertEquals(2, sorted["bc"]) assertEquals(3, sorted["c"]) diff --git a/libraries/stdlib/test/collections/MapTest.kt b/libraries/stdlib/test/collections/MapTest.kt index f2eaa12f5d1..808cc4e31fe 100644 --- a/libraries/stdlib/test/collections/MapTest.kt +++ b/libraries/stdlib/test/collections/MapTest.kt @@ -78,8 +78,8 @@ class MapTest { val map = mapOf("beverage" to "beer", "location" to "Mells", "name" to "James") val list = arrayListOf() for (e in map) { - list.add(e.getKey()) - list.add(e.getValue()) + list.add(e.key) + list.add(e.value) } assertEquals(6, list.size) @@ -201,7 +201,7 @@ class MapTest { assertEquals(1, map["a"]) assertEquals(2, map["b"]) assertEquals(3, map["c"]) - assertEquals(listOf("c", "b", "a"), map.keySet().toList()) + assertEquals(listOf("c", "b", "a"), map.keys.toList()) } @test fun filter() { @@ -317,7 +317,7 @@ class MapTest { fun testMinus(doMinus: (Map) -> Map) { val original = mapOf("A" to 1, "B" to 2) val shortened = doMinus(original) - assertEquals("A" to 1, shortened.entrySet().single().toPair()) + assertEquals("A" to 1, shortened.entries.single().toPair()) } @test fun minus() = testMinus { it - "B" - "C" } @@ -335,7 +335,7 @@ class MapTest { fun testMinusAssign(doMinusAssign: (MutableMap) -> Unit) { val original = hashMapOf("A" to 1, "B" to 2) doMinusAssign(original) - assertEquals("A" to 1, original.entrySet().single().toPair()) + assertEquals("A" to 1, original.entries.single().toPair()) } @test fun minusAssign() = testMinusAssign { diff --git a/libraries/stdlib/test/collections/ReversedViewsTest.kt b/libraries/stdlib/test/collections/ReversedViewsTest.kt index 5d5b171454e..f48e0860b8a 100644 --- a/libraries/stdlib/test/collections/ReversedViewsTest.kt +++ b/libraries/stdlib/test/collections/ReversedViewsTest.kt @@ -113,14 +113,14 @@ class ReversedViewsTest { val original = arrayListOf("a", "b", "c") val reversed = original.asReversed() - reversed.remove(0) // remove c + reversed.removeAt(0) // remove c assertEquals(listOf("a", "b"), original) assertEquals(listOf("b", "a"), reversed) - reversed.remove(1) // remove a + reversed.removeAt(1) // remove a assertEquals(listOf("b"), original) - reversed.remove(0) // remove remaining b + reversed.removeAt(0) // remove remaining b assertEquals(emptyList(), original) } diff --git a/libraries/stdlib/test/io/Files.kt b/libraries/stdlib/test/io/Files.kt index 987f11ba032..909fa730285 100644 --- a/libraries/stdlib/test/io/Files.kt +++ b/libraries/stdlib/test/io/Files.kt @@ -329,7 +329,7 @@ class FilesTest { fun afterVisitDirectory(dir: File) { assertEquals(stack.last(), dir) - stack.remove(stack.lastIndex) + stack.removeAt(stack.lastIndex) } fun visitFile(file: File) { @@ -339,7 +339,7 @@ class FilesTest { fun visitDirectoryFailed(dir: File, e: IOException) { assertEquals(stack.last(), dir) - stack.remove(stack.lastIndex) + stack.removeAt(stack.lastIndex) failed.add(dir.name) } basedir.walkTopDown().enter(::beforeVisitDirectory).leave(::afterVisitDirectory). diff --git a/libraries/stdlib/test/js/MapJsTest.kt b/libraries/stdlib/test/js/MapJsTest.kt index be15f601ba5..dfab09e6186 100644 --- a/libraries/stdlib/test/js/MapJsTest.kt +++ b/libraries/stdlib/test/js/MapJsTest.kt @@ -153,17 +153,17 @@ abstract class MapJsTest { // #KT-3035 @test fun emptyMapValues() { val emptyMap = emptyMap() - assertTrue(emptyMap.values().isEmpty()) + assertTrue(emptyMap.values.isEmpty()) } @test fun mapValues() { val map = createTestMap() - assertEquals(VALUES.toNormalizedList(), map.values().toNormalizedList()) + assertEquals(VALUES.toNormalizedList(), map.values.toNormalizedList()) } @test fun mapKeySet() { val map = createTestMap() - assertEquals(KEYS.toNormalizedList(), map.keySet().toNormalizedList()) + assertEquals(KEYS.toNormalizedList(), map.keys.toNormalizedList()) } @test fun mapEntrySet() { @@ -171,9 +171,9 @@ abstract class MapJsTest { val actualKeys = ArrayList() val actualValues = ArrayList() - for (e in map.entrySet()) { - actualKeys.add(e.getKey()) - actualValues.add(e.getValue()) + for (e in map.entries) { + actualKeys.add(e.key) + actualValues.add(e.value) } assertEquals(KEYS.toNormalizedList(), actualKeys.toNormalizedList()) @@ -293,8 +293,8 @@ abstract class MapJsTest { val actualKeys = ArrayList() val actualValues = ArrayList() for (e in map) { - actualKeys.add(e.getKey()) - actualValues.add(e.getValue()) + actualKeys.add(e.key) + actualValues.add(e.value) } assertEquals(KEYS.toNormalizedList(), actualKeys.toNormalizedList()) @@ -308,8 +308,8 @@ abstract class MapJsTest { val actualValues = ArrayList() val iterator = map.iterator() for (e in iterator) { - actualKeys.add(e.getKey()) - actualValues.add(e.getValue()) + actualKeys.add(e.key) + actualValues.add(e.value) } assertEquals(KEYS.toNormalizedList(), actualKeys.toNormalizedList()) diff --git a/libraries/tools/idl2k/src/main/kotlin/idl.kt b/libraries/tools/idl2k/src/main/kotlin/idl.kt index cfc349237fa..88400aa4295 100644 --- a/libraries/tools/idl2k/src/main/kotlin/idl.kt +++ b/libraries/tools/idl2k/src/main/kotlin/idl.kt @@ -505,10 +505,10 @@ fun parseIDL(reader: CharStream): Repository { ModuleVisitor(declarations).visit(idl) return Repository( - declarations.filterIsInstance().filter { it.name.isEmpty().not() }.groupBy { it.name }.mapValues { it.getValue().reduce(::merge) }, - declarations.filterIsInstance().groupBy { it.name }.mapValues { it.getValue().first() }, - declarations.filterIsInstance().groupBy { it.name }.mapValues { it.getValue().map { it.implements } }, - declarations.filterIsInstance().groupBy { it.name }.mapValues { it.getValue().reduce { a, b -> a } } + declarations.filterIsInstance().filter { it.name.isEmpty().not() }.groupBy { it.name }.mapValues { it.value.reduce(::merge) }, + declarations.filterIsInstance().groupBy { it.name }.mapValues { it.value.first() }, + declarations.filterIsInstance().groupBy { it.name }.mapValues { it.value.map { it.implements } }, + declarations.filterIsInstance().groupBy { it.name }.mapValues { it.value.reduce { a, b -> a } } ) } diff --git a/libraries/tools/idl2k/src/main/kotlin/main.kt b/libraries/tools/idl2k/src/main/kotlin/main.kt index a3c981a7994..153e70f9691 100644 --- a/libraries/tools/idl2k/src/main/kotlin/main.kt +++ b/libraries/tools/idl2k/src/main/kotlin/main.kt @@ -26,7 +26,7 @@ fun main(args: Array) { val repository = repositoryPre.copy(typeDefs = repositoryPre.typeDefs.mapValues { it.value.copy(mapType(repositoryPre, it.value.types)) }) - val definitions = mapDefinitions(repository, repository.interfaces.values()).map { + val definitions = mapDefinitions(repository, repository.interfaces.values).map { if (it.name in relocations) { // we need this to get interfaces listed in the relocations in valid package // to keep compatibility with DOM Java API @@ -35,7 +35,7 @@ fun main(args: Array) { it } } - val unions = generateUnions(definitions, repository.typeDefs.values()) + val unions = generateUnions(definitions, repository.typeDefs.values) val allPackages = definitions.map { it.namespace }.distinct().sorted() outDir.deleteRecursively() diff --git a/libraries/tools/idl2k/src/main/kotlin/render.kt b/libraries/tools/idl2k/src/main/kotlin/render.kt index eefb8e9b26f..6d4e233a3ff 100644 --- a/libraries/tools/idl2k/src/main/kotlin/render.kt +++ b/libraries/tools/idl2k/src/main/kotlin/render.kt @@ -112,7 +112,7 @@ fun Appendable.render(allTypes: Map, typeNamesToUn append(iface.name) val primary = iface.primaryConstructor if (primary != null && (primary.constructor.arguments.isNotEmpty() || iface.secondaryConstructors.isNotEmpty())) { - renderArgumentsDeclaration(primary.constructor.fixRequiredArguments(iface.name).arguments.dynamicIfUnknownType(allTypes.keySet()), false) + renderArgumentsDeclaration(primary.constructor.fixRequiredArguments(iface.name).arguments.dynamicIfUnknownType(allTypes.keys), false) } val superCallName = primary?.initTypeCall?.name @@ -130,7 +130,7 @@ fun Appendable.render(allTypes: Map, typeNamesToUn iface.secondaryConstructors.forEach { secondary -> indent(false, 1) append("constructor") - renderArgumentsDeclaration(secondary.constructor.fixRequiredArguments(iface.name).arguments.dynamicIfUnknownType(allTypes.keySet()), false) + renderArgumentsDeclaration(secondary.constructor.fixRequiredArguments(iface.name).arguments.dynamicIfUnknownType(allTypes.keys), false) if (secondary.initTypeCall != null) { append(" : ") @@ -146,9 +146,9 @@ fun Appendable.render(allTypes: Map, typeNamesToUn val superSignatures = superAttributes.map { it.signature } merge superFunctions.map { it.signature } iface.memberAttributes - .filter { it !in superAttributes && !it.static && (it.isVar || (it.isVal && superAttributesByName[it.name]?.hasNoVars() ?: true)) } - .map { it.dynamicIfUnknownType(allTypes.keySet()) } - .groupBy { it.signature }.reduceValues().values().forEach { arg -> + .filter { it !in superAttributes && !it.static && (it.isVar || (it.isVal && superAttributesByName[it.name]?.hasNoVars() ?: true)) } + .map { it.dynamicIfUnknownType(allTypes.keys) } + .groupBy { it.signature }.reduceValues().values.forEach { arg -> renderAttributeDeclarationAsProperty(arg, override = arg.signature in superSignatures, open = iface.kind == GenerateDefinitionKind.CLASS && arg.isVal, @@ -157,7 +157,7 @@ fun Appendable.render(allTypes: Map, typeNamesToUn level = 1 ) } - iface.memberFunctions.filter { it !in superFunctions && !it.static }.map { it.dynamicIfUnknownType(allTypes.keySet()) }.groupBy { it.signature }.reduceValues(::betterFunction).values().forEach { + iface.memberFunctions.filter { it !in superFunctions && !it.static }.map { it.dynamicIfUnknownType(allTypes.keys) }.groupBy { it.signature }.reduceValues(::betterFunction).values.forEach { renderFunctionDeclaration(it.fixRequiredArguments(iface.name), it.signature in superSignatures, commented = it.isCommented(iface.name)) } @@ -185,7 +185,7 @@ fun Appendable.render(allTypes: Map, typeNamesToUn appendln() if (iface.generateBuilderFunction) { - renderBuilderFunction(iface, allSuperTypes, allTypes.keySet()) + renderBuilderFunction(iface, allSuperTypes, allTypes.keys) } } @@ -232,15 +232,15 @@ fun Appendable.render(namespace: String, ifaces: List, uni val declaredTypes = ifaces.toMap { it.name } val allTypes = declaredTypes + unions.anonymousUnionsMap + unions.typedefsMarkersMap - declaredTypes.values().filter { it.namespace == namespace }.forEach { + declaredTypes.values.filter { it.namespace == namespace }.forEach { render(allTypes, unions.typeNamesToUnionsMap, it) } - unions.anonymousUnionsMap.values().filter { it.namespace == "" || it.namespace == namespace }.forEach { + unions.anonymousUnionsMap.values.filter { it.namespace == "" || it.namespace == namespace }.forEach { render(allTypes, emptyMap(), it, markerAnnotation = true) } - unions.typedefsMarkersMap.values().filter { it.namespace == "" || it.namespace == namespace }.forEach { + unions.typedefsMarkersMap.values.filter { it.namespace == "" || it.namespace == namespace }.forEach { render(allTypes, emptyMap(), it, markerAnnotation = true) } } diff --git a/libraries/tools/idl2k/src/main/kotlin/typeMappings.kt b/libraries/tools/idl2k/src/main/kotlin/typeMappings.kt index fabe8011c45..d419b2a7d2d 100644 --- a/libraries/tools/idl2k/src/main/kotlin/typeMappings.kt +++ b/libraries/tools/idl2k/src/main/kotlin/typeMappings.kt @@ -54,7 +54,7 @@ tailrec fun allSuperTypesImpl(roots: List, all: Map, standardTypes: Set = standardTypes()): Type = when { this is DynamicType, this is UnitType -> this @@ -110,7 +110,7 @@ private fun mapTypedef(repository: Repository, type: SimpleType): Type { private fun GenerateFunction?.allTypes() = if (this != null) sequenceOf(returnType) + arguments.asSequence().map { it.type } else emptySequence() internal fun collectUnionTypes(allTypes: Map) = - allTypes.values().asSequence() + allTypes.values.asSequence() .flatMap { it.secondaryConstructors.asSequence().flatMap { it.constructor.allTypes() } + sequenceOf(it.primaryConstructor).filterNotNull().flatMap { it.constructor.allTypes() } + diff --git a/libraries/tools/kotlin-annotation-processing/src/test/kotlin/org/jetbrains/kotlin/annotation/AnnotationListParseTest.kt b/libraries/tools/kotlin-annotation-processing/src/test/kotlin/org/jetbrains/kotlin/annotation/AnnotationListParseTest.kt index 2fc1763e460..c5d0a547662 100644 --- a/libraries/tools/kotlin-annotation-processing/src/test/kotlin/org/jetbrains/kotlin/annotation/AnnotationListParseTest.kt +++ b/libraries/tools/kotlin-annotation-processing/src/test/kotlin/org/jetbrains/kotlin/annotation/AnnotationListParseTest.kt @@ -61,8 +61,8 @@ public class AnnotationListParseTest { val actualAnnotations = StringBuilder() parsedAnnotations.forEach { - for (element in it.getValue()) { - actualAnnotations.append(it.getKey()).append(' ').append(element.classFqName) + for (element in it.value) { + actualAnnotations.append(it.key).append(' ').append(element.classFqName) when (element) { is AnnotatedMethodDescriptor -> actualAnnotations.append(' ').append(element.methodName) is AnnotatedFieldDescriptor -> actualAnnotations.append(' ').append(element.fieldName) diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/internal/AnnotationProcessingManager.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/internal/AnnotationProcessingManager.kt index ae97325dc7d..d77483037e4 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/internal/AnnotationProcessingManager.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/internal/AnnotationProcessingManager.kt @@ -96,7 +96,7 @@ private fun Project.createKotlinAfterJavaTask( } getAllTasks(false) - .flatMap { it.getValue() } + .flatMap { it.value } .filter { javaTask in it.taskDependencies.getDependencies(it) } .forEach { it.dependsOn(kotlinAfterJavaTask) } diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/ThreadTracker.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/ThreadTracker.kt index 2205c795303..35a0754d790 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/ThreadTracker.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/ThreadTracker.kt @@ -10,7 +10,7 @@ public class ThreadTracker { val log = Logging.getLogger(this.javaClass) private var before: Collection? = getThreads() - private fun getThreads(): Collection = Thread.getAllStackTraces().keySet() + private fun getThreads(): Collection = Thread.getAllStackTraces().keys public fun checkThreadLeak(gradle: Gradle?) { try {