aboutsummaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
authorGoooler <wangzongler@gmail.com>2022-02-21 22:01:06 +0800
committerGitHub <noreply@github.com>2022-02-21 17:01:06 +0300
commitf5b7797255576e5f1c230e2ca3fcb5f4e602387c (patch)
tree25fd98250066c4ed6c2fff1104be533604bbf1b9 /core/src
parentdf4780c31026aaa626746f49f0e6fa3fa0278a05 (diff)
downloaddokka-f5b7797255576e5f1c230e2ca3fcb5f4e602387c.tar.gz
dokka-f5b7797255576e5f1c230e2ca3fcb5f4e602387c.tar.bz2
dokka-f5b7797255576e5f1c230e2ca3fcb5f4e602387c.zip
Code cleanups (#2165)
Diffstat (limited to 'core/src')
-rw-r--r--core/src/main/kotlin/CoreExtensions.kt2
-rw-r--r--core/src/main/kotlin/model/Documentable.kt2
-rw-r--r--core/src/main/kotlin/model/WithChildren.kt8
-rw-r--r--core/src/main/kotlin/pages/ContentNodes.kt2
-rw-r--r--core/src/main/kotlin/transformers/documentation/DocumentableMerger.kt1
-rw-r--r--core/src/main/kotlin/transformers/documentation/DocumentableToPageTranslator.kt1
-rw-r--r--core/src/main/kotlin/transformers/documentation/DocumentableTransformer.kt1
-rw-r--r--core/src/main/kotlin/transformers/pages/PageCreator.kt1
-rw-r--r--core/src/main/kotlin/utilities/ServiceLocator.kt17
-rw-r--r--core/src/main/kotlin/utilities/safeEnumValueOf.kt2
10 files changed, 15 insertions, 22 deletions
diff --git a/core/src/main/kotlin/CoreExtensions.kt b/core/src/main/kotlin/CoreExtensions.kt
index 0dd5780b..ddfa0c69 100644
--- a/core/src/main/kotlin/CoreExtensions.kt
+++ b/core/src/main/kotlin/CoreExtensions.kt
@@ -26,6 +26,6 @@ object CoreExtensions {
private fun <T : Any> coreExtensionPoint() = object {
operator fun provideDelegate(thisRef: CoreExtensions, property: KProperty<*>): Lazy<ExtensionPoint<T>> =
- lazy { ExtensionPoint<T>(thisRef::class.qualifiedName!!, property.name) }
+ lazy { ExtensionPoint(thisRef::class.qualifiedName!!, property.name) }
}
} \ No newline at end of file
diff --git a/core/src/main/kotlin/model/Documentable.kt b/core/src/main/kotlin/model/Documentable.kt
index fcbb9591..13d04555 100644
--- a/core/src/main/kotlin/model/Documentable.kt
+++ b/core/src/main/kotlin/model/Documentable.kt
@@ -126,7 +126,7 @@ data class DPackage(
* e.g. this will return a human readable version for root packages.
* Use [packageName] or `dri.packageName` instead to obtain the real packageName
*/
- override val name: String = if (packageName.isBlank()) "[root]" else packageName
+ override val name: String = packageName.ifBlank { "[root]" }
override val children: List<Documentable> = properties + functions + classlikes + typealiases
diff --git a/core/src/main/kotlin/model/WithChildren.kt b/core/src/main/kotlin/model/WithChildren.kt
index 59a14acc..01a188c8 100644
--- a/core/src/main/kotlin/model/WithChildren.kt
+++ b/core/src/main/kotlin/model/WithChildren.kt
@@ -79,10 +79,10 @@ fun <T : WithChildren<T>> T.asPrintableTree(
nodeNameBuilder(element)
appendLine()
element.children.takeIf(Collection<*>::isNotEmpty)?.also { children ->
- val newOwnPrefix = childPrefix + '\u251c' + '\u2500' + ' '
- val lastOwnPrefix = childPrefix + '\u2514' + '\u2500' + ' '
- val newChildPrefix = childPrefix + '\u2502' + ' ' + ' '
- val lastChildPrefix = childPrefix + ' ' + ' ' + ' '
+ val newOwnPrefix = "$childPrefix├─ "
+ val lastOwnPrefix = "$childPrefix└─ "
+ val newChildPrefix = "$childPrefix│ "
+ val lastChildPrefix = "$childPrefix "
children.forEachIndexed { n, e ->
if (n != children.lastIndex) append(e, newOwnPrefix, newChildPrefix)
else append(e, lastOwnPrefix, lastChildPrefix)
diff --git a/core/src/main/kotlin/pages/ContentNodes.kt b/core/src/main/kotlin/pages/ContentNodes.kt
index 23baa482..4210b4dd 100644
--- a/core/src/main/kotlin/pages/ContentNodes.kt
+++ b/core/src/main/kotlin/pages/ContentNodes.kt
@@ -33,7 +33,7 @@ data class ContentText(
) : ContentNode {
override fun withNewExtras(newExtras: PropertyContainer<ContentNode>): ContentText = copy(extra = newExtras)
override fun withSourceSets(sourceSets: Set<DisplaySourceSet>): ContentText = copy(sourceSets = sourceSets)
- override fun hasAnyContent(): Boolean = !text.isBlank()
+ override fun hasAnyContent(): Boolean = text.isNotBlank()
}
// TODO: Remove
diff --git a/core/src/main/kotlin/transformers/documentation/DocumentableMerger.kt b/core/src/main/kotlin/transformers/documentation/DocumentableMerger.kt
index 358fdb1d..1d655423 100644
--- a/core/src/main/kotlin/transformers/documentation/DocumentableMerger.kt
+++ b/core/src/main/kotlin/transformers/documentation/DocumentableMerger.kt
@@ -1,7 +1,6 @@
package org.jetbrains.dokka.transformers.documentation
import org.jetbrains.dokka.model.DModule
-import org.jetbrains.dokka.plugability.DokkaContext
fun interface DocumentableMerger {
operator fun invoke(modules: Collection<DModule>): DModule?
diff --git a/core/src/main/kotlin/transformers/documentation/DocumentableToPageTranslator.kt b/core/src/main/kotlin/transformers/documentation/DocumentableToPageTranslator.kt
index f8005cfe..cd85b8ad 100644
--- a/core/src/main/kotlin/transformers/documentation/DocumentableToPageTranslator.kt
+++ b/core/src/main/kotlin/transformers/documentation/DocumentableToPageTranslator.kt
@@ -1,7 +1,6 @@
package org.jetbrains.dokka.transformers.documentation
import org.jetbrains.dokka.model.DModule
-import org.jetbrains.dokka.pages.ModulePageNode
import org.jetbrains.dokka.pages.RootPageNode
fun interface DocumentableToPageTranslator {
diff --git a/core/src/main/kotlin/transformers/documentation/DocumentableTransformer.kt b/core/src/main/kotlin/transformers/documentation/DocumentableTransformer.kt
index a808a224..923a7236 100644
--- a/core/src/main/kotlin/transformers/documentation/DocumentableTransformer.kt
+++ b/core/src/main/kotlin/transformers/documentation/DocumentableTransformer.kt
@@ -1,7 +1,6 @@
package org.jetbrains.dokka.transformers.documentation
import org.jetbrains.dokka.model.DModule
-import org.jetbrains.dokka.model.Documentable
import org.jetbrains.dokka.plugability.DokkaContext
fun interface DocumentableTransformer {
diff --git a/core/src/main/kotlin/transformers/pages/PageCreator.kt b/core/src/main/kotlin/transformers/pages/PageCreator.kt
index ebb9dac5..fb5b3b47 100644
--- a/core/src/main/kotlin/transformers/pages/PageCreator.kt
+++ b/core/src/main/kotlin/transformers/pages/PageCreator.kt
@@ -1,7 +1,6 @@
package org.jetbrains.dokka.transformers.pages
import org.jetbrains.dokka.pages.RootPageNode
-import org.jetbrains.dokka.plugability.DokkaContext
interface CreationContext
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<ServiceDescriptor>()
+ 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 <reified T : Enum<*>> 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