kotlin: Switch from ktfmt to ktlint (fixes build)

This commit is contained in:
Jason Penilla 2021-09-14 11:45:23 -07:00 committed by Jason
parent f0a4add565
commit 5648128217
6 changed files with 69 additions and 49 deletions

View file

@ -1,10 +1,9 @@
import org.jetbrains.dokka.gradle.DokkaTask import org.jetbrains.dokka.gradle.DokkaTask
import java.net.URL
plugins { plugins {
kotlin("jvm") version "1.4.31" kotlin("jvm") version "1.4.31"
id("org.jetbrains.dokka") version "1.4.20" id("org.jetbrains.dokka") version "1.4.20"
id("com.ncorti.ktfmt.gradle") version "0.6.0" id("org.jlleitschuh.gradle.ktlint") version "10.0.0"
} }
configurations.all { configurations.all {
@ -50,7 +49,3 @@ tasks {
kotlin { kotlin {
explicitApi() explicitApi()
} }
ktfmt {
dropboxStyle()
}

View file

@ -57,7 +57,8 @@ public class MutableCommandBuilder<C : Any> {
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
@Deprecated( @Deprecated(
message = "ArgumentDescription should be used over Description", message = "ArgumentDescription should be used over Description",
level = DeprecationLevel.HIDDEN) level = DeprecationLevel.HIDDEN
)
public constructor( public constructor(
name: String, name: String,
description: Description = Description.empty(), description: Description = Description.empty(),
@ -100,7 +101,8 @@ public class MutableCommandBuilder<C : Any> {
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
@Deprecated( @Deprecated(
message = "ArgumentDescription should be used over Description", message = "ArgumentDescription should be used over Description",
level = DeprecationLevel.HIDDEN) level = DeprecationLevel.HIDDEN
)
public constructor( public constructor(
name: String, name: String,
description: Description = Description.empty(), description: Description = Description.empty(),
@ -171,7 +173,7 @@ public class MutableCommandBuilder<C : Any> {
return this return this
} }
private fun onlyMutate(mutator: (Command.Builder<C>) -> Command.Builder<C>): Unit { private fun onlyMutate(mutator: (Command.Builder<C>) -> Command.Builder<C>) {
mutate(mutator) mutate(mutator)
} }
@ -207,7 +209,8 @@ public class MutableCommandBuilder<C : Any> {
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
@Deprecated( @Deprecated(
message = "ArgumentDescription should be used over Description", message = "ArgumentDescription should be used over Description",
level = DeprecationLevel.HIDDEN) level = DeprecationLevel.HIDDEN
)
public fun copy( public fun copy(
literal: String, literal: String,
description: Description, description: Description,
@ -306,7 +309,8 @@ public class MutableCommandBuilder<C : Any> {
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
@Deprecated( @Deprecated(
message = "ArgumentDescription should be used over Description", message = "ArgumentDescription should be used over Description",
level = DeprecationLevel.HIDDEN) level = DeprecationLevel.HIDDEN
)
public fun registerCopy( public fun registerCopy(
literal: String, literal: String,
description: Description, description: Description,
@ -481,7 +485,8 @@ public class MutableCommandBuilder<C : Any> {
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
@Deprecated( @Deprecated(
message = "ArgumentDescription should be used over Description", message = "ArgumentDescription should be used over Description",
level = DeprecationLevel.HIDDEN) level = DeprecationLevel.HIDDEN
)
public fun argument( public fun argument(
argument: CommandArgument<C, *>, argument: CommandArgument<C, *>,
description: Description = Description.empty() description: Description = Description.empty()
@ -511,7 +516,8 @@ public class MutableCommandBuilder<C : Any> {
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
@Deprecated( @Deprecated(
message = "ArgumentDescription should be used over Description", message = "ArgumentDescription should be used over Description",
level = DeprecationLevel.HIDDEN) level = DeprecationLevel.HIDDEN
)
public fun argument( public fun argument(
argument: CommandArgument.Builder<C, *>, argument: CommandArgument.Builder<C, *>,
description: Description = Description.empty() description: Description = Description.empty()
@ -541,7 +547,8 @@ public class MutableCommandBuilder<C : Any> {
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
@Deprecated( @Deprecated(
message = "ArgumentDescription should be used over Description", message = "ArgumentDescription should be used over Description",
level = DeprecationLevel.HIDDEN) level = DeprecationLevel.HIDDEN
)
public fun argument( public fun argument(
description: Description = Description.empty(), description: Description = Description.empty(),
argumentSupplier: () -> CommandArgument<C, *> argumentSupplier: () -> CommandArgument<C, *>
@ -572,7 +579,8 @@ public class MutableCommandBuilder<C : Any> {
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
@Deprecated( @Deprecated(
message = "ArgumentDescription should be used over Description", message = "ArgumentDescription should be used over Description",
level = DeprecationLevel.HIDDEN) level = DeprecationLevel.HIDDEN
)
public fun literal( public fun literal(
name: String, name: String,
description: Description = Description.empty(), description: Description = Description.empty(),
@ -627,7 +635,8 @@ public class MutableCommandBuilder<C : Any> {
.withAliases(*aliases) .withAliases(*aliases)
.withDescription(description) .withDescription(description)
.withArgument(argumentSupplier()) .withArgument(argumentSupplier())
.build()) .build()
)
} }
/** /**
@ -652,7 +661,8 @@ public class MutableCommandBuilder<C : Any> {
.withAliases(*aliases) .withAliases(*aliases)
.withDescription(description) .withDescription(description)
.withArgument(argument) .withArgument(argument)
.build()) .build()
)
} }
/** /**
@ -677,7 +687,8 @@ public class MutableCommandBuilder<C : Any> {
.withAliases(*aliases) .withAliases(*aliases)
.withDescription(description) .withDescription(description)
.withArgument(argumentBuilder) .withArgument(argumentBuilder)
.build()) .build()
)
} }
/** /**
@ -699,6 +710,7 @@ public class MutableCommandBuilder<C : Any> {
.flagBuilder(name) .flagBuilder(name)
.withAliases(*aliases) .withAliases(*aliases)
.withDescription(description) .withDescription(description)
.build()) .build()
)
} }
} }

View file

@ -27,6 +27,10 @@ import cloud.commandframework.annotations.AnnotationParser
import cloud.commandframework.annotations.MethodCommandExecutionHandler import cloud.commandframework.annotations.MethodCommandExecutionHandler
import cloud.commandframework.context.CommandContext import cloud.commandframework.context.CommandContext
import cloud.commandframework.execution.CommandExecutionCoordinator import cloud.commandframework.execution.CommandExecutionCoordinator
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.async
import kotlinx.coroutines.future.asCompletableFuture
import java.lang.reflect.Method import java.lang.reflect.Method
import java.util.concurrent.CompletableFuture import java.util.concurrent.CompletableFuture
import java.util.function.Predicate import java.util.function.Predicate
@ -34,8 +38,6 @@ import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext import kotlin.coroutines.EmptyCoroutineContext
import kotlin.reflect.full.callSuspend import kotlin.reflect.full.callSuspend
import kotlin.reflect.jvm.kotlinFunction import kotlin.reflect.jvm.kotlinFunction
import kotlinx.coroutines.*
import kotlinx.coroutines.future.asCompletableFuture
/** /**
* Adds coroutine support to the [AnnotationParser]. * Adds coroutine support to the [AnnotationParser].
@ -49,7 +51,8 @@ public fun <C> AnnotationParser<C>.installCoroutineSupport(
if (manager().commandExecutionCoordinator() is CommandExecutionCoordinator.SimpleCoordinator) { if (manager().commandExecutionCoordinator() is CommandExecutionCoordinator.SimpleCoordinator) {
RuntimeException( RuntimeException(
"""You are highly advised to not use the simple command execution coordinator together """You are highly advised to not use the simple command execution coordinator together
with coroutine support. Consider using the asynchronous command execution coordinator instead.""") with coroutine support. Consider using the asynchronous command execution coordinator instead."""
)
.printStackTrace() .printStackTrace()
} }

View file

@ -42,7 +42,8 @@ import kotlin.reflect.KClass
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
@Deprecated( @Deprecated(
message = "ArgumentDescription should be used over Description", message = "ArgumentDescription should be used over Description",
level = DeprecationLevel.HIDDEN) level = DeprecationLevel.HIDDEN
)
public fun <C : Any> CommandManager<C>.commandBuilder( public fun <C : Any> CommandManager<C>.commandBuilder(
name: String, name: String,
description: Description = Description.empty(), description: Description = Description.empty(),
@ -79,7 +80,8 @@ public fun <C : Any> CommandManager<C>.commandBuilder(
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
@Deprecated( @Deprecated(
message = "ArgumentDescription should be used over Description", message = "ArgumentDescription should be used over Description",
level = DeprecationLevel.HIDDEN) level = DeprecationLevel.HIDDEN
)
public fun <C : Any> CommandManager<C>.buildAndRegister( public fun <C : Any> CommandManager<C>.buildAndRegister(
name: String, name: String,
description: Description = Description.empty(), description: Description = Description.empty(),
@ -137,7 +139,8 @@ public fun <C : Any> Command.Builder<C>.senderType(type: KClass<out C>): Command
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
@Deprecated( @Deprecated(
message = "Use interface variant that allows for rich text", message = "Use interface variant that allows for rich text",
replaceWith = ReplaceWith("argumentDescription(description)")) replaceWith = ReplaceWith("argumentDescription(description)")
)
public fun description(description: String = ""): Description = public fun description(description: String = ""): Description =
if (description.isEmpty()) Description.empty() else Description.of(description) if (description.isEmpty()) Description.empty() else Description.of(description)

View file

@ -27,7 +27,10 @@ import cloud.commandframework.CommandManager
import cloud.commandframework.arguments.standard.StringArgument import cloud.commandframework.arguments.standard.StringArgument
import cloud.commandframework.execution.CommandExecutionCoordinator import cloud.commandframework.execution.CommandExecutionCoordinator
import cloud.commandframework.internal.CommandRegistrationHandler import cloud.commandframework.internal.CommandRegistrationHandler
import cloud.commandframework.kotlin.extension.* import cloud.commandframework.kotlin.extension.argumentDescription
import cloud.commandframework.kotlin.extension.buildAndRegister
import cloud.commandframework.kotlin.extension.command
import cloud.commandframework.kotlin.extension.commandBuilder
import cloud.commandframework.meta.CommandMeta import cloud.commandframework.meta.CommandMeta
import cloud.commandframework.meta.SimpleCommandMeta import cloud.commandframework.meta.SimpleCommandMeta
import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Assertions
@ -58,8 +61,10 @@ class CommandBuildingDSLTest {
handler { handler {
// ... // ...
} }
}) }
}) )
}
)
manager.buildAndRegister("is") { manager.buildAndRegister("is") {
commandDescription("Command description") commandDescription("Command description")
@ -92,13 +97,14 @@ class CommandBuildingDSLTest {
"is this going", "is this going",
"is this going too_far", "is this going too_far",
) )
.sorted()) .sorted()
)
} }
class TestCommandManager : class TestCommandManager : CommandManager<TestCommandSender>(
CommandManager<TestCommandSender>(
CommandExecutionCoordinator.simpleCoordinator(), CommandExecutionCoordinator.simpleCoordinator(),
CommandRegistrationHandler.nullCommandRegistrationHandler()) { CommandRegistrationHandler.nullCommandRegistrationHandler()
) {
override fun createDefaultCommandMeta(): SimpleCommandMeta { override fun createDefaultCommandMeta(): SimpleCommandMeta {
return SimpleCommandMeta.empty() return SimpleCommandMeta.empty()
} }

View file

@ -30,14 +30,14 @@ import cloud.commandframework.execution.AsynchronousCommandExecutionCoordinator
import cloud.commandframework.internal.CommandRegistrationHandler import cloud.commandframework.internal.CommandRegistrationHandler
import cloud.commandframework.meta.CommandMeta import cloud.commandframework.meta.CommandMeta
import cloud.commandframework.meta.SimpleCommandMeta import cloud.commandframework.meta.SimpleCommandMeta
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.future.await import kotlinx.coroutines.future.await
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit
class KotlinAnnotatedMethodsTest { class KotlinAnnotatedMethodsTest {
@ -68,14 +68,15 @@ class KotlinAnnotatedMethodsTest {
commandManager.executeCommand(TestCommandSender(), "test").await() commandManager.executeCommand(TestCommandSender(), "test").await()
} }
private class TestCommandSender {} private class TestCommandSender
private class TestCommandManager : private class TestCommandManager :
CommandManager<TestCommandSender>( CommandManager<TestCommandSender>(
AsynchronousCommandExecutionCoordinator.newBuilder<TestCommandSender>() AsynchronousCommandExecutionCoordinator.newBuilder<TestCommandSender>()
.withExecutor(executorService) .withExecutor(executorService)
.build(), .build(),
CommandRegistrationHandler.nullCommandRegistrationHandler()) { CommandRegistrationHandler.nullCommandRegistrationHandler()
) {
override fun hasPermission(sender: TestCommandSender, permission: String): Boolean = true override fun hasPermission(sender: TestCommandSender, permission: String): Boolean = true