StdLib cleanup, deprecated symbol usage: List and Map members

This commit is contained in:
Ilya Gorbunov
2015-11-14 06:21:17 +03:00
parent 838109c302
commit dadcdb5771
15 changed files with 51 additions and 51 deletions
@@ -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)
}
}
@@ -87,15 +87,15 @@ public fun <K, V> CompareContext<Map<K, V>>.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 <T> CompareContext<T>.equalityBehavior(objectName: String = "") {
@@ -15,7 +15,7 @@ class CollectionJVMTest {
private fun <T> identitySetOf(vararg values: T): MutableSet<T> {
val map = IdentityHashMap<T, String>()
values.forEach { map.put(it, "") }
return map.keySet()
return map.keys
}
private data class IdentityData(public val value: Int)
@@ -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<String> { 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"])
+5 -5
View File
@@ -78,8 +78,8 @@ class MapTest {
val map = mapOf("beverage" to "beer", "location" to "Mells", "name" to "James")
val list = arrayListOf<String>()
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<String, Int>) -> Map<String, Int>) {
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<String, Int>) -> 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 {
@@ -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<String>(), original)
}
+2 -2
View File
@@ -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).
+10 -10
View File
@@ -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<String>()
val actualValues = ArrayList<Int>()
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<String>()
val actualValues = ArrayList<Int>()
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<Int>()
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())
+4 -4
View File
@@ -505,10 +505,10 @@ fun parseIDL(reader: CharStream): Repository {
ModuleVisitor(declarations).visit(idl)
return Repository(
declarations.filterIsInstance<InterfaceDefinition>().filter { it.name.isEmpty().not() }.groupBy { it.name }.mapValues { it.getValue().reduce(::merge) },
declarations.filterIsInstance<TypedefDefinition>().groupBy { it.name }.mapValues { it.getValue().first() },
declarations.filterIsInstance<ExtensionInterfaceDefinition>().groupBy { it.name }.mapValues { it.getValue().map { it.implements } },
declarations.filterIsInstance<EnumDefinition>().groupBy { it.name }.mapValues { it.getValue().reduce { a, b -> a } }
declarations.filterIsInstance<InterfaceDefinition>().filter { it.name.isEmpty().not() }.groupBy { it.name }.mapValues { it.value.reduce(::merge) },
declarations.filterIsInstance<TypedefDefinition>().groupBy { it.name }.mapValues { it.value.first() },
declarations.filterIsInstance<ExtensionInterfaceDefinition>().groupBy { it.name }.mapValues { it.value.map { it.implements } },
declarations.filterIsInstance<EnumDefinition>().groupBy { it.name }.mapValues { it.value.reduce { a, b -> a } }
)
}
@@ -26,7 +26,7 @@ fun main(args: Array<String>) {
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<String>) {
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()
+10 -10
View File
@@ -112,7 +112,7 @@ fun Appendable.render(allTypes: Map<String, GenerateTraitOrClass>, 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<String, GenerateTraitOrClass>, 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<String, GenerateTraitOrClass>, 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<String, GenerateTraitOrClass>, 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<String, GenerateTraitOrClass>, 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<GenerateTraitOrClass>, 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)
}
}
@@ -54,7 +54,7 @@ tailrec fun allSuperTypesImpl(roots: List<GenerateTraitOrClass>, all: Map<String
}
}
fun standardTypes() = typeMapper.values().map {it.dropNullable()}.toSet()
fun standardTypes() = typeMapper.values.map {it.dropNullable()}.toSet()
fun Type.dynamicIfUnknownType(allTypes: Set<String>, standardTypes: Set<Type> = 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<String, GenerateTraitOrClass>) =
allTypes.values().asSequence()
allTypes.values.asSequence()
.flatMap {
it.secondaryConstructors.asSequence().flatMap { it.constructor.allTypes() } +
sequenceOf(it.primaryConstructor).filterNotNull().flatMap { it.constructor.allTypes() } +
@@ -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)
@@ -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) }
@@ -10,7 +10,7 @@ public class ThreadTracker {
val log = Logging.getLogger(this.javaClass)
private var before: Collection<Thread>? = getThreads()
private fun getThreads(): Collection<Thread> = Thread.getAllStackTraces().keySet()
private fun getThreads(): Collection<Thread> = Thread.getAllStackTraces().keys
public fun checkThreadLeak(gradle: Gradle?) {
try {