diff --git a/buildSrc/src/main/kotlin/kord-module.gradle.kts b/buildSrc/src/main/kotlin/kord-module.gradle.kts index 37397688ec0..fa495bd5121 100644 --- a/buildSrc/src/main/kotlin/kord-module.gradle.kts +++ b/buildSrc/src/main/kotlin/kord-module.gradle.kts @@ -10,6 +10,7 @@ plugins { repositories { mavenCentral() + maven("https://oss.sonatype.org/content/repositories/snapshots") } dependencies { diff --git a/buildSrc/src/main/kotlin/kord-multiplatform-module.gradle.kts b/buildSrc/src/main/kotlin/kord-multiplatform-module.gradle.kts index db9f9064e8f..5b6990a9733 100644 --- a/buildSrc/src/main/kotlin/kord-multiplatform-module.gradle.kts +++ b/buildSrc/src/main/kotlin/kord-multiplatform-module.gradle.kts @@ -12,6 +12,7 @@ plugins { repositories { mavenCentral() + maven("https://oss.sonatype.org/content/repositories/snapshots") } dependencies { diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 1599989c8fa..4bfe2c7a3bb 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -19,6 +19,7 @@ fastZlib = "2.0.1" # https://github.com/timotejroiko/fast-zlib # code generation ksp = "2.0.21-1.0.25" # https://github.com/google/ksp kotlinpoet = "1.18.1" # https://github.com/square/kotlinpoet +codegen-kt = "main-SNAPSHOT" # https://github.com/kordlib/codegen-kt # tests junit-jupiter = "5.11.2" # https://github.com/junit-team/junit5 @@ -68,6 +69,8 @@ stately-collections = { module = "co.touchlab:stately-concurrent-collections", v ksp-api = { module = "com.google.devtools.ksp:symbol-processing-api", version.ref = "ksp" } kotlinpoet = { module = "com.squareup:kotlinpoet", version.ref = "kotlinpoet" } kotlinpoet-ksp = { module = "com.squareup:kotlinpoet-ksp", version.ref = "kotlinpoet" } +codegen-kt-kotlinpoet = { module = "dev.kord.codegen:kotlinpoet", version.ref = "codegen-kt" } +codegen-kt-ksp = { module = "dev.kord.codegen:ksp", version.ref = "codegen-kt" } # tests kotlin-test-annotations-common = { module = "org.jetbrains.kotlin:kotlin-test-annotations-common", version.ref = "kotlin" } diff --git a/ksp-processors/build.gradle.kts b/ksp-processors/build.gradle.kts index 5df3edcbbfe..793818edc6e 100644 --- a/ksp-processors/build.gradle.kts +++ b/ksp-processors/build.gradle.kts @@ -8,12 +8,18 @@ kotlin { } } +repositories { + maven("https://oss.sonatype.org/content/repositories/snapshots") +} + dependencies { implementation(projects.kspAnnotations) implementation(libs.ksp.api) implementation(libs.kotlinpoet) implementation(libs.kotlinpoet.ksp) + implementation(libs.codegen.kt.kotlinpoet) + implementation(libs.codegen.kt.ksp) implementation(libs.kotlinx.serialization.json) // use types directly } diff --git a/ksp-processors/src/main/kotlin/KSPUtils.kt b/ksp-processors/src/main/kotlin/KSPUtils.kt index bab27d53157..b203c5c21ae 100644 --- a/ksp-processors/src/main/kotlin/KSPUtils.kt +++ b/ksp-processors/src/main/kotlin/KSPUtils.kt @@ -1,52 +1,9 @@ package dev.kord.ksp import com.google.devtools.ksp.KspExperimental -import com.google.devtools.ksp.findActualType import com.google.devtools.ksp.getAnnotationsByType -import com.google.devtools.ksp.isDefault import com.google.devtools.ksp.processing.Resolver import com.google.devtools.ksp.symbol.* -import kotlin.reflect.KProperty1 - -internal inline fun Resolver.getSymbolsWithAnnotation(inDepth: Boolean = false) = - getSymbolsWithAnnotation(A::class.qualifiedName!!, inDepth) - -internal fun Resolver.getNewClasses() = getNewFiles().flatMap { it.declarations.filterIsInstance() } - -internal inline fun KSAnnotation.isOfType() = isOfType(A::class.qualifiedName!!) - -internal fun KSAnnotation.isOfType(qualifiedName: String) = annotationType.resolve() - .declaration.let { if (it is KSTypeAlias) it.findActualType() else it } - .qualifiedName?.asString() == qualifiedName @OptIn(KspExperimental::class) internal inline fun KSAnnotated.getAnnotationsByType() = getAnnotationsByType(A::class) - -internal class AnnotationArguments private constructor( - private val arguments: Map, -) { - private fun getArgument(parameter: KProperty1) = arguments.getValue(parameter.name) - private val KProperty1.value get() = getArgument(this).value - - fun isDefault(parameter: KProperty1) = getArgument(parameter).isDefault() - - // can't return non-nullable values because of https://github.com/google/ksp/issues/885 - operator fun get(parameter: KProperty1) = parameter.value as KSAnnotation? - operator fun get(parameter: KProperty1>) = - @Suppress("UNCHECKED_CAST") (parameter.value as List?) - - companion object { - fun KSAnnotation.arguments() = - AnnotationArguments(arguments.associateBy { it.name!!.asString() }) - } -} - -@Suppress("RecursivePropertyAccessor") -internal val KSReferenceElement.isClassifierReference: Boolean - get() = when (this) { - is KSDynamicReference, is KSCallableReference -> false - is KSClassifierReference -> true - is KSDefNonNullReference -> enclosedType.isClassifierReference - is KSParenthesizedReference -> element.isClassifierReference - else -> error("Unexpected KSReferenceElement: $this") - } diff --git a/ksp-processors/src/main/kotlin/KotlinPoetDsl.kt b/ksp-processors/src/main/kotlin/KotlinPoetDsl.kt deleted file mode 100644 index 5176abe6d84..00000000000 --- a/ksp-processors/src/main/kotlin/KotlinPoetDsl.kt +++ /dev/null @@ -1,122 +0,0 @@ -package dev.kord.ksp - -import com.squareup.kotlinpoet.* -import com.squareup.kotlinpoet.MemberName.Companion.member -import kotlin.annotation.AnnotationRetention.SOURCE -import kotlin.annotation.AnnotationTarget.TYPE - -// for scope control, see https://kotlinlang.org/docs/type-safe-builders.html#scope-control-dslmarker -@DslMarker -@Retention(SOURCE) -@Target(TYPE) -internal annotation class KotlinPoetDsl - -internal typealias FileSpecBuilder = (@KotlinPoetDsl FileSpec.Builder).() -> Unit -internal typealias TypeSpecBuilder = (@KotlinPoetDsl TypeSpec.Builder).() -> Unit -internal typealias AnnotationSpecBuilder = (@KotlinPoetDsl AnnotationSpec.Builder).() -> Unit -internal typealias FunSpecBuilder = (@KotlinPoetDsl FunSpec.Builder).() -> Unit -internal typealias PropertySpecBuilder = (@KotlinPoetDsl PropertySpec.Builder).() -> Unit -internal typealias ParameterSpecBuilder = (@KotlinPoetDsl ParameterSpec.Builder).() -> Unit -internal typealias CodeBlockBuilder = (@KotlinPoetDsl CodeBlock.Builder).() -> Unit - - -// miscellaneous - -internal inline fun > E.asMemberName() = E::class.member(name) - -internal inline fun FileSpec(packageName: String, fileName: String, builder: FileSpecBuilder) = - FileSpec.builder(packageName, fileName).apply(builder).build() - - -// extensions for `Annotatable.Builder` - -@DelicateKotlinPoetApi("See 'AnnotationSpec.get'") -internal fun > T.addAnnotation( - annotation: Annotation, - includeDefaultValues: Boolean = false, -) = addAnnotation(AnnotationSpec.get(annotation, includeDefaultValues)) - -internal inline fun > T.addAnnotation(type: ClassName, builder: AnnotationSpecBuilder) = - addAnnotation(AnnotationSpec.builder(type).apply(builder).build()) - -internal inline fun Annotatable.Builder<*>.addAnnotation(builder: AnnotationSpecBuilder) = - addAnnotation(AnnotationSpec.builder(A::class).apply(builder).build()) - - -// extensions for `TypeSpecHolder.Builder` - -internal inline fun > T.addClass(name: String, builder: TypeSpecBuilder) = - addType(TypeSpec.classBuilder(name).apply(builder).build()) - -internal inline fun > T.addClass(className: ClassName, builder: TypeSpecBuilder) = - addType(TypeSpec.classBuilder(className).apply(builder).build()) - -internal inline fun > T.addObject(name: String, builder: TypeSpecBuilder) = - addType(TypeSpec.objectBuilder(name).apply(builder).build()) - - -// extensions for `MemberSpecHolder.Builder` - -internal inline fun > T.addFunction(name: String, builder: FunSpecBuilder) = - addFunction(FunSpec.builder(name).apply(builder).build()) - -internal inline fun MemberSpecHolder.Builder<*>.addProperty( - name: String, - vararg modifiers: KModifier, - builder: PropertySpecBuilder, -) = addProperty(PropertySpec.builder(name, typeNameOf(), *modifiers).apply(builder).build()) - -internal inline fun > T.addProperty( - name: String, - type: TypeName, - vararg modifiers: KModifier, - builder: PropertySpecBuilder, -) = addProperty(PropertySpec.builder(name, type, *modifiers).apply(builder).build()) - - -// extensions for `TypeSpec.Builder` - -internal inline fun TypeSpec.Builder.addCompanionObject(name: String? = null, builder: TypeSpecBuilder) = - addType(TypeSpec.companionObjectBuilder(name).apply(builder).build()) - -internal inline fun TypeSpec.Builder.primaryConstructor(builder: FunSpecBuilder) = - primaryConstructor(FunSpec.constructorBuilder().apply(builder).build()) - -internal inline fun TypeSpec.Builder.addInitializerBlock(builder: CodeBlockBuilder) = - addInitializerBlock(CodeBlock.builder().apply(builder).build()) - - -// extensions for `FunSpec.Builder` - -internal inline fun FunSpec.Builder.addParameter( - name: String, - type: TypeName, - vararg modifiers: KModifier, - builder: ParameterSpecBuilder, -) = addParameter(ParameterSpec.builder(name, type, *modifiers).apply(builder).build()) - -internal inline fun FunSpec.Builder.addParameter(name: String, vararg modifiers: KModifier) = - addParameter(name, typeNameOf(), *modifiers) - -internal inline fun FunSpec.Builder.returns() = returns(typeNameOf()) - -internal inline fun FunSpec.Builder.withControlFlow(controlFlow: String, vararg args: Any, builder: FunSpecBuilder) = - beginControlFlow(controlFlow, *args).apply(builder).endControlFlow() - - -// extensions for `PropertySpec.Builder` - -internal inline fun PropertySpec.Builder.delegate(builder: CodeBlockBuilder) = - delegate(CodeBlock.builder().apply(builder).build()) - -internal inline fun PropertySpec.Builder.getter(builder: FunSpecBuilder) = - getter(FunSpec.getterBuilder().apply(builder).build()) - - -// extensions for `CodeBlock.Builder` - -internal inline fun CodeBlock.Builder.withControlFlow( - controlFlow: String, - vararg args: Any?, - builder: CodeBlockBuilder, -) = beginControlFlow(controlFlow, *args).apply(builder).endControlFlow() diff --git a/ksp-processors/src/main/kotlin/generation/GenerationEntity.kt b/ksp-processors/src/main/kotlin/generation/GenerationEntity.kt index 1d887e879b7..e162737a39f 100644 --- a/ksp-processors/src/main/kotlin/generation/GenerationEntity.kt +++ b/ksp-processors/src/main/kotlin/generation/GenerationEntity.kt @@ -2,7 +2,7 @@ package dev.kord.ksp.generation import com.google.devtools.ksp.processing.KSPLogger import com.google.devtools.ksp.symbol.KSAnnotation -import dev.kord.ksp.AnnotationArguments.Companion.arguments +import dev.kord.codegen.ksp.annotations.AnnotationArguments.Companion.arguments import dev.kord.ksp.Generate import dev.kord.ksp.Generate.EntityType import dev.kord.ksp.Generate.EntityType.* diff --git a/ksp-processors/src/main/kotlin/generation/GenerationProcessor.kt b/ksp-processors/src/main/kotlin/generation/GenerationProcessor.kt index 288a07b9996..dcc8cb50af9 100644 --- a/ksp-processors/src/main/kotlin/generation/GenerationProcessor.kt +++ b/ksp-processors/src/main/kotlin/generation/GenerationProcessor.kt @@ -4,12 +4,12 @@ import com.google.devtools.ksp.processing.* import com.google.devtools.ksp.symbol.KSAnnotated import com.google.devtools.ksp.symbol.KSFile import com.squareup.kotlinpoet.ksp.writeTo +import dev.kord.codegen.ksp.getSymbolsWithAnnotation +import dev.kord.codegen.ksp.isOfType import dev.kord.ksp.Generate import dev.kord.ksp.generation.bitflags.generateFileSpec import dev.kord.ksp.generation.kordenum.generateFileSpec import dev.kord.ksp.getAnnotationsByType -import dev.kord.ksp.getSymbolsWithAnnotation -import dev.kord.ksp.isOfType /** [SymbolProcessorProvider] for [GenerationProcessor]. */ class GenerationProcessorProvider : SymbolProcessorProvider { diff --git a/ksp-processors/src/main/kotlin/generation/bitflags/BitFlagsGeneration.kt b/ksp-processors/src/main/kotlin/generation/bitflags/BitFlagsGeneration.kt index 72697797fc1..09df455b7c1 100644 --- a/ksp-processors/src/main/kotlin/generation/bitflags/BitFlagsGeneration.kt +++ b/ksp-processors/src/main/kotlin/generation/bitflags/BitFlagsGeneration.kt @@ -3,12 +3,21 @@ package dev.kord.ksp.generation.bitflags import com.google.devtools.ksp.symbol.KSFile -import com.squareup.kotlinpoet.ClassName +import com.squareup.kotlinpoet.* import com.squareup.kotlinpoet.KModifier.* import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy -import com.squareup.kotlinpoet.SET import com.squareup.kotlinpoet.ksp.addOriginatingKSFile -import dev.kord.ksp.* +import dev.kord.codegen.kotlinpoet.addAnnotation +import dev.kord.codegen.kotlinpoet.addClass +import dev.kord.codegen.kotlinpoet.addCompanionObject +import dev.kord.codegen.kotlinpoet.addFunction +import dev.kord.codegen.kotlinpoet.addInitializerBlock +import dev.kord.codegen.kotlinpoet.addParameter +import dev.kord.codegen.kotlinpoet.addProperty +import dev.kord.codegen.kotlinpoet.getter +import dev.kord.codegen.kotlinpoet.primaryConstructor +import dev.kord.codegen.kotlinpoet.returns +import dev.kord.codegen.kotlinpoet.withControlFlow import dev.kord.ksp.generation.GenerationEntity.BitFlags import dev.kord.ksp.generation.GenerationEntity.BitFlags.ValueType.BIT_SET import dev.kord.ksp.generation.GenerationEntity.BitFlags.ValueType.INT @@ -106,6 +115,7 @@ internal fun BitFlags.generateFileSpec(originatingFile: KSFile) = fileSpecForGen addStatement("shift++") } } + BIT_SET -> withControlFlow("for·(shift·in·0..<$valueName.size)") { addStatement("if·($valueName[shift])·add(%T.fromShift(shift))", entityCN) } diff --git a/ksp-processors/src/main/kotlin/generation/bitflags/Builder.kt b/ksp-processors/src/main/kotlin/generation/bitflags/Builder.kt index ca0ad0acbba..4c7245e804e 100644 --- a/ksp-processors/src/main/kotlin/generation/bitflags/Builder.kt +++ b/ksp-processors/src/main/kotlin/generation/bitflags/Builder.kt @@ -5,7 +5,7 @@ package dev.kord.ksp.generation.bitflags import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.KModifier.* import com.squareup.kotlinpoet.TypeSpec -import dev.kord.ksp.* +import dev.kord.codegen.kotlinpoet.* import dev.kord.ksp.generation.GenerationEntity.BitFlags import dev.kord.ksp.generation.GenerationEntity.BitFlags.ValueType.BIT_SET import dev.kord.ksp.generation.GenerationEntity.BitFlags.ValueType.INT diff --git a/ksp-processors/src/main/kotlin/generation/bitflags/ContainsPlusMinusCopy.kt b/ksp-processors/src/main/kotlin/generation/bitflags/ContainsPlusMinusCopy.kt index f32bf1d10ab..04751d390bc 100644 --- a/ksp-processors/src/main/kotlin/generation/bitflags/ContainsPlusMinusCopy.kt +++ b/ksp-processors/src/main/kotlin/generation/bitflags/ContainsPlusMinusCopy.kt @@ -2,17 +2,21 @@ package dev.kord.ksp.generation.bitflags -import com.squareup.kotlinpoet.* +import com.squareup.kotlinpoet.DelicateKotlinPoetApi import com.squareup.kotlinpoet.KModifier.* -import dev.kord.ksp.addAnnotation -import dev.kord.ksp.addFunction +import com.squareup.kotlinpoet.LambdaTypeName +import com.squareup.kotlinpoet.TypeName +import com.squareup.kotlinpoet.TypeSpec +import com.squareup.kotlinpoet.UNIT +import dev.kord.codegen.kotlinpoet.addAnnotation +import dev.kord.codegen.kotlinpoet.addFunction +import dev.kord.codegen.kotlinpoet.returns import dev.kord.ksp.generation.GenerationEntity.BitFlags import dev.kord.ksp.generation.GenerationEntity.BitFlags.ValueType.BIT_SET import dev.kord.ksp.generation.GenerationEntity.BitFlags.ValueType.INT import dev.kord.ksp.generation.shared.CONTRACT import dev.kord.ksp.generation.shared.EXACTLY_ONCE import dev.kord.ksp.generation.shared.GenerationContext -import dev.kord.ksp.returns context(BitFlags, GenerationContext) internal fun TypeSpec.Builder.addContains(parameterName: String, parameterType: TypeName) = addFunction("contains") { diff --git a/ksp-processors/src/main/kotlin/generation/bitflags/DeprecatedNewCompanion.kt b/ksp-processors/src/main/kotlin/generation/bitflags/DeprecatedNewCompanion.kt index 94c5d4ec3cb..5046735d994 100644 --- a/ksp-processors/src/main/kotlin/generation/bitflags/DeprecatedNewCompanion.kt +++ b/ksp-processors/src/main/kotlin/generation/bitflags/DeprecatedNewCompanion.kt @@ -7,7 +7,12 @@ import com.squareup.kotlinpoet.KModifier import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy import com.squareup.kotlinpoet.TypeSpec import com.squareup.kotlinpoet.jvm.jvmField -import dev.kord.ksp.* +import dev.kord.codegen.kotlinpoet.addAnnotation +import dev.kord.codegen.kotlinpoet.addClass +import dev.kord.codegen.kotlinpoet.addCompanionObject +import dev.kord.codegen.kotlinpoet.addFunction +import dev.kord.codegen.kotlinpoet.addProperty +import dev.kord.codegen.kotlinpoet.primaryConstructor import dev.kord.ksp.generation.GenerationEntity.BitFlags import dev.kord.ksp.generation.shared.GenerationContext import dev.kord.ksp.generation.shared.K_SERIALIZER diff --git a/ksp-processors/src/main/kotlin/generation/bitflags/FactoryFunctions.kt b/ksp-processors/src/main/kotlin/generation/bitflags/FactoryFunctions.kt index 5658590aeeb..a21481aa50e 100644 --- a/ksp-processors/src/main/kotlin/generation/bitflags/FactoryFunctions.kt +++ b/ksp-processors/src/main/kotlin/generation/bitflags/FactoryFunctions.kt @@ -6,14 +6,14 @@ import com.squareup.kotlinpoet.* import com.squareup.kotlinpoet.KModifier.* import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy import com.squareup.kotlinpoet.jvm.jvmName -import dev.kord.ksp.addAnnotation -import dev.kord.ksp.addFunction -import dev.kord.ksp.addParameter +import dev.kord.codegen.kotlinpoet.addAnnotation +import dev.kord.codegen.kotlinpoet.addFunction +import dev.kord.codegen.kotlinpoet.addParameter +import dev.kord.codegen.kotlinpoet.withControlFlow import dev.kord.ksp.generation.GenerationEntity.BitFlags import dev.kord.ksp.generation.shared.CONTRACT import dev.kord.ksp.generation.shared.EXACTLY_ONCE import dev.kord.ksp.generation.shared.GenerationContext -import dev.kord.ksp.withControlFlow context(GenerationContext) private val BitFlags.factoryFunctionName diff --git a/ksp-processors/src/main/kotlin/generation/bitflags/Serializer.kt b/ksp-processors/src/main/kotlin/generation/bitflags/Serializer.kt index 130c08dd9fc..0058f497bac 100644 --- a/ksp-processors/src/main/kotlin/generation/bitflags/Serializer.kt +++ b/ksp-processors/src/main/kotlin/generation/bitflags/Serializer.kt @@ -7,10 +7,10 @@ import com.squareup.kotlinpoet.KModifier.PRIVATE import com.squareup.kotlinpoet.MemberName import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy import com.squareup.kotlinpoet.TypeSpec -import dev.kord.ksp.addFunction -import dev.kord.ksp.addObject -import dev.kord.ksp.addParameter -import dev.kord.ksp.addProperty +import dev.kord.codegen.kotlinpoet.addFunction +import dev.kord.codegen.kotlinpoet.addObject +import dev.kord.codegen.kotlinpoet.addProperty +import dev.kord.codegen.kotlinpoet.addParameter import dev.kord.ksp.generation.GenerationEntity.BitFlags import dev.kord.ksp.generation.GenerationEntity.BitFlags.ValueType.BIT_SET import dev.kord.ksp.generation.GenerationEntity.BitFlags.ValueType.INT diff --git a/ksp-processors/src/main/kotlin/generation/kordenum/KordEnumGeneration.kt b/ksp-processors/src/main/kotlin/generation/kordenum/KordEnumGeneration.kt index a13724fbf57..eb2b36ffc8f 100644 --- a/ksp-processors/src/main/kotlin/generation/kordenum/KordEnumGeneration.kt +++ b/ksp-processors/src/main/kotlin/generation/kordenum/KordEnumGeneration.kt @@ -4,7 +4,7 @@ import com.google.devtools.ksp.symbol.KSFile import com.squareup.kotlinpoet.KModifier.PUBLIC import com.squareup.kotlinpoet.KModifier.SEALED import com.squareup.kotlinpoet.ksp.addOriginatingKSFile -import dev.kord.ksp.* +import dev.kord.codegen.kotlinpoet.* import dev.kord.ksp.generation.GenerationEntity.KordEnum import dev.kord.ksp.generation.shared.* import kotlinx.serialization.Serializable diff --git a/ksp-processors/src/main/kotlin/generation/kordenum/Serializer.kt b/ksp-processors/src/main/kotlin/generation/kordenum/Serializer.kt index 864ed48e039..daa6086d59c 100644 --- a/ksp-processors/src/main/kotlin/generation/kordenum/Serializer.kt +++ b/ksp-processors/src/main/kotlin/generation/kordenum/Serializer.kt @@ -4,9 +4,9 @@ package dev.kord.ksp.generation.kordenum import com.squareup.kotlinpoet.KModifier.OVERRIDE import com.squareup.kotlinpoet.TypeSpec -import dev.kord.ksp.addFunction -import dev.kord.ksp.addObject -import dev.kord.ksp.addParameter +import dev.kord.codegen.kotlinpoet.addFunction +import dev.kord.codegen.kotlinpoet.addObject +import dev.kord.codegen.kotlinpoet.addParameter import dev.kord.ksp.generation.GenerationEntity.KordEnum import dev.kord.ksp.generation.GenerationEntity.KordEnum.ValueType import dev.kord.ksp.generation.GenerationEntity.KordEnum.ValueType.INT diff --git a/ksp-processors/src/main/kotlin/generation/shared/EqualsHashCodeToString.kt b/ksp-processors/src/main/kotlin/generation/shared/EqualsHashCodeToString.kt index b82c7031c88..8e8a791e31d 100644 --- a/ksp-processors/src/main/kotlin/generation/shared/EqualsHashCodeToString.kt +++ b/ksp-processors/src/main/kotlin/generation/shared/EqualsHashCodeToString.kt @@ -6,10 +6,10 @@ import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.KModifier.FINAL import com.squareup.kotlinpoet.KModifier.OVERRIDE import com.squareup.kotlinpoet.TypeSpec -import dev.kord.ksp.addFunction -import dev.kord.ksp.addParameter +import dev.kord.codegen.kotlinpoet.addFunction +import dev.kord.codegen.kotlinpoet.addParameter +import dev.kord.codegen.kotlinpoet.returns import dev.kord.ksp.generation.GenerationEntity -import dev.kord.ksp.returns internal fun TypeSpec.Builder.addEqualsAndHashCodeBasedOnClassAndSingleProperty( className: ClassName, diff --git a/ksp-processors/src/main/kotlin/generation/shared/FileSpecForGenerationEntity.kt b/ksp-processors/src/main/kotlin/generation/shared/FileSpecForGenerationEntity.kt index 9021e12cdbc..915c5c89c20 100644 --- a/ksp-processors/src/main/kotlin/generation/shared/FileSpecForGenerationEntity.kt +++ b/ksp-processors/src/main/kotlin/generation/shared/FileSpecForGenerationEntity.kt @@ -6,8 +6,8 @@ import com.google.devtools.ksp.symbol.KSFile import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.DelicateKotlinPoetApi import com.squareup.kotlinpoet.FileSpec -import dev.kord.ksp.FileSpec -import dev.kord.ksp.addAnnotation +import dev.kord.codegen.kotlinpoet.FileSpec +import dev.kord.codegen.kotlinpoet.addAnnotation import dev.kord.ksp.generation.GenerationEntity internal class GenerationContext( diff --git a/ksp-processors/src/main/kotlin/generation/shared/Names.kt b/ksp-processors/src/main/kotlin/generation/shared/Names.kt index d92fa341ce9..646262fcae3 100644 --- a/ksp-processors/src/main/kotlin/generation/shared/Names.kt +++ b/ksp-processors/src/main/kotlin/generation/shared/Names.kt @@ -1,16 +1,24 @@ +@file:OptIn(ExperimentalContracts::class, DelicateKotlinPoetApi::class) + package dev.kord.ksp.generation.shared import com.squareup.kotlinpoet.ClassName +import com.squareup.kotlinpoet.DelicateKotlinPoetApi import com.squareup.kotlinpoet.MemberName -import com.squareup.kotlinpoet.MemberName.Companion.member import com.squareup.kotlinpoet.asClassName +import dev.kord.codegen.kotlinpoet.asMemberName import kotlinx.serialization.KSerializer +import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor +import kotlin.contracts.ExperimentalContracts +import kotlin.contracts.InvocationKind +import kotlin.contracts.contract internal val OPT_IN = ClassName("kotlin", "OptIn") -internal val CONTRACT = MemberName("kotlin.contracts", "contract") -internal val EXACTLY_ONCE = ClassName("kotlin.contracts", "InvocationKind").member("EXACTLY_ONCE") -internal val PRIMITIVE_SERIAL_DESCRIPTOR = MemberName("kotlinx.serialization.descriptors", "PrimitiveSerialDescriptor") +internal val CONTRACT = ::contract.asMemberName() +internal val EXACTLY_ONCE = InvocationKind.EXACTLY_ONCE.asMemberName() + +internal val PRIMITIVE_SERIAL_DESCRIPTOR = ::PrimitiveSerialDescriptor.asMemberName() internal val K_SERIALIZER = KSerializer::class.asClassName() internal val DISCORD_BIT_SET = ClassName("dev.kord.common", "DiscordBitSet") diff --git a/ksp-processors/src/main/kotlin/generation/shared/OptIns.kt b/ksp-processors/src/main/kotlin/generation/shared/OptIns.kt index 23bdf44c843..581cb4e89ff 100644 --- a/ksp-processors/src/main/kotlin/generation/shared/OptIns.kt +++ b/ksp-processors/src/main/kotlin/generation/shared/OptIns.kt @@ -6,7 +6,7 @@ import com.squareup.kotlinpoet.Annotatable import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.CodeBlock import com.squareup.kotlinpoet.joinToCode -import dev.kord.ksp.addAnnotation +import dev.kord.codegen.kotlinpoet.addAnnotation context(GenerationContext) internal fun Annotatable.Builder<*>.addEntryOptIns() { diff --git a/ksp-processors/src/main/kotlin/generation/shared/SharedContent.kt b/ksp-processors/src/main/kotlin/generation/shared/SharedContent.kt index 89b808ddab3..b9b2ac56758 100644 --- a/ksp-processors/src/main/kotlin/generation/shared/SharedContent.kt +++ b/ksp-processors/src/main/kotlin/generation/shared/SharedContent.kt @@ -5,7 +5,7 @@ package dev.kord.ksp.generation.shared import com.squareup.kotlinpoet.* import com.squareup.kotlinpoet.KModifier.* import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy -import dev.kord.ksp.* +import dev.kord.codegen.kotlinpoet.* import dev.kord.ksp.generation.GenerationEntity import kotlinx.serialization.descriptors.SerialDescriptor