From f5b7797255576e5f1c230e2ca3fcb5f4e602387c Mon Sep 17 00:00:00 2001 From: Goooler Date: Mon, 21 Feb 2022 22:01:06 +0800 Subject: Code cleanups (#2165) --- core/src/main/kotlin/utilities/ServiceLocator.kt | 17 +++++++---------- core/src/main/kotlin/utilities/safeEnumValueOf.kt | 2 +- 2 files changed, 8 insertions(+), 11 deletions(-) (limited to 'core/src/main/kotlin/utilities') diff --git a/core/src/main/kotlin/utilities/ServiceLocator.kt b/core/src/main/kotlin/utilities/ServiceLocator.kt index 00c9ae9f..3e515348 100644 --- a/core/src/main/kotlin/utilities/ServiceLocator.kt +++ b/core/src/main/kotlin/utilities/ServiceLocator.kt @@ -65,20 +65,17 @@ object ServiceLocator { when (it.protocol) { "file" -> it.toFile().listFiles()?.filter { it.extension == "properties" }?.map { lookupDescriptor(category, it.nameWithoutExtension) } ?: emptyList() "jar" -> { - val file = JarFile(URL(it.file.substringBefore("!")).toFile()) - try { + JarFile(URL(it.file.substringBefore("!")).toFile()).use { file -> val jarPath = it.file.substringAfterLast("!").removePrefix("/").removeSuffix("/") file.entries() - .asSequence() - .filter { entry -> !entry.isDirectory && entry.path == jarPath && entry.extension == "properties" } - .map { entry -> - lookupDescriptor(category, entry.fileName.substringBeforeLast(".")) - }.toList() - } finally { - file.close() + .asSequence() + .filter { entry -> !entry.isDirectory && entry.path == jarPath && entry.extension == "properties" } + .map { entry -> + lookupDescriptor(category, entry.fileName.substringBeforeLast(".")) + }.toList() } } - else -> emptyList() + else -> emptyList() } } } diff --git a/core/src/main/kotlin/utilities/safeEnumValueOf.kt b/core/src/main/kotlin/utilities/safeEnumValueOf.kt index 8fd5a086..9f4c23c9 100644 --- a/core/src/main/kotlin/utilities/safeEnumValueOf.kt +++ b/core/src/main/kotlin/utilities/safeEnumValueOf.kt @@ -1,4 +1,4 @@ package org.jetbrains.dokka.utilities inline fun > enumValueOrNull(name: String): T? = - T::class.java.enumConstants.firstOrNull { it.name.toUpperCase() == name.toUpperCase() } \ No newline at end of file + T::class.java.enumConstants.firstOrNull { it.name.equals(name, ignoreCase = true) } \ No newline at end of file -- cgit