diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 61a9130..3729299 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -1,6 +1,8 @@ - + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 94a25f7..35eb1dd 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/annotations/build.gradle.kts b/annotations/build.gradle.kts deleted file mode 100644 index b568d9e..0000000 --- a/annotations/build.gradle.kts +++ /dev/null @@ -1,3 +0,0 @@ -plugins { - org.jetbrains.kotlin.jvm -} diff --git a/annotations/src/main/kotlin/GenerateInlinedConstructor.kt b/annotations/src/main/kotlin/GenerateInlinedConstructor.kt deleted file mode 100644 index 8d8fce3..0000000 --- a/annotations/src/main/kotlin/GenerateInlinedConstructor.kt +++ /dev/null @@ -1,2 +0,0 @@ -class GenerateInlinedConstructor { -} diff --git a/buildSrc/src/main/kotlin/code-generator.gradle.kts b/buildSrc/src/main/kotlin/code-generator.gradle.kts index 604f4ea..e9fbf74 100644 --- a/buildSrc/src/main/kotlin/code-generator.gradle.kts +++ b/buildSrc/src/main/kotlin/code-generator.gradle.kts @@ -20,10 +20,14 @@ kotlin { jvm() targets { + jvm { + attributes { + attribute(generationSourceAttribute, false as java.lang.Boolean) + } + } jvm("generationSource") { - mavenPublication { } attributes { - attribute(generationSourceAttribute, JBoolean(true)) + attribute(generationSourceAttribute, true as java.lang.Boolean) } compilations.all { @@ -73,5 +77,5 @@ ksp { } dependencies { - "kspGenerationSource"(project(":code-processor")) + "kspGenerationSource"(project(":kotlinpoet:processor")) } diff --git a/buildSrc/src/main/kotlin/kord-publishing.gradle.kts b/buildSrc/src/main/kotlin/kord-publishing.gradle.kts index f3bc73a..9eee34a 100644 --- a/buildSrc/src/main/kotlin/kord-publishing.gradle.kts +++ b/buildSrc/src/main/kotlin/kord-publishing.gradle.kts @@ -1,8 +1,11 @@ import com.vanniktech.maven.publish.JavadocJar import com.vanniktech.maven.publish.KotlinJvm +import com.vanniktech.maven.publish.KotlinMultiplatform import gradle.kotlin.dsl.accessors._8d1ef46afdac024fc616c6e49cc7c389.kotlin import org.intellij.lang.annotations.Language import org.jetbrains.dokka.gradle.AbstractDokkaLeafTask +import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMetadataTarget +import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget plugins { org.jetbrains.dokka @@ -57,39 +60,44 @@ mavenPublishing { } } -// Since we only target JVM, we publish jvm artifacts only -plugins.withId("org.jetbrains.kotlin.multiplatform") { - val dokkaJar by tasks.registering(Jar::class) { - from(tasks.named("dokkaHtml")) - archiveClassifier = "javadoc" - } +afterEvaluate { + plugins.withId("org.jetbrains.kotlin.multiplatform") { + if (kotlin.targets.any { it !is KotlinJvmTarget && it !is KotlinMetadataTarget }) { + mavenPublishing.configure(KotlinMultiplatform(JavadocJar.Dokka("dokkaHtml"))) + return@withId + } + val dokkaJar by tasks.registering(Jar::class) { + from(tasks.named("dokkaHtml")) + archiveClassifier = "javadoc" + } - // We're kinda abusing the KMP target system here - // We make an extra jvm target for the kotlinpoet source to run ksp on it, however we don't want to publish - // that target, so we emulate the "jvm" target being a normal Kotlin/JVM project and publish it that way - afterEvaluate { - publishing.publications.create("maven") { - from(kotlin.targets.getByName("jvm").components.first()) - artifact(dokkaJar) + // We're kinda abusing the KMP target system here + // We make an extra jvm target for the kotlinpoet source to run ksp on it, however we don't want to publish + // that target, so we emulate the "jvm" target being a normal Kotlin/JVM project and publish it that way + afterEvaluate { + publishing.publications.create("maven") { + from(kotlin.targets.getByName("jvm").components.first()) + artifact(dokkaJar) + } } - } - // Remove auto-generated KMP publications - tasks { - withType { - enabled = name == "publishMavenPublicationToMavenLocal" - } + // Remove auto-generated KMP publications + tasks { + withType { + enabled = name == "publishMavenPublicationToMavenLocal" + } - withType { - enabled = name == "publishMavenPublicationToMavenRepository" - || name == "publishMavenPublicationToMavenCentralRepository" - } + withType { + enabled = name == "publishMavenPublicationToMavenRepository" + || name == "publishMavenPublicationToMavenCentralRepository" + } - // Theoretically, this makes us loose information, however, that information is not relevant, since this is - // pretty much only a JVM lib targeting JVM 1.8 (so validation of that is unnecessary) - withType { - enabled = false + // Theoretically, this makes us loose information, however, that information is not relevant, since this is + // pretty much only a JVM lib targeting JVM 1.8 (so validation of that is unnecessary) + withType { + enabled = false + } } } } diff --git a/docs/topics/Annotation-Argument-Processor.md b/docs/topics/Annotation-Argument-Processor.md index bc1cc72..3bed099 100644 --- a/docs/topics/Annotation-Argument-Processor.md +++ b/docs/topics/Annotation-Argument-Processor.md @@ -8,6 +8,7 @@ to generate that boiler plate for you ```kotlin dependencies { + compileOnly("dev.kord.codegen", "ksp-annotations", "%version%") ksp("dev.kord.codegen", "ksp-processor", "%version%") } ``` diff --git a/kotlinpoet/annotations/build.gradle.kts b/kotlinpoet/annotations/build.gradle.kts new file mode 100644 index 0000000..3ba0765 --- /dev/null +++ b/kotlinpoet/annotations/build.gradle.kts @@ -0,0 +1,29 @@ +plugins { + org.jetbrains.kotlin.multiplatform + com.google.devtools.ksp +} + +kotlin { + explicitApi() + + jvm() + + sourceSets { + commonMain { + dependencies { + compileOnly(projects.ksp.annotations) + } + } + + named("jvmMain") { + kotlin.srcDir("build/generated/ksp/jvm/jvmMain/kotlin") + dependencies { + implementation(projects.ksp) + } + } + } +} + +dependencies { + "kspJvm"(projects.ksp.processor) +} diff --git a/ksp-annotations/src/commonMain/kotlin/InlineConstructor.kt b/kotlinpoet/annotations/src/commonMain/kotlin/InlineConstructor.kt similarity index 100% rename from ksp-annotations/src/commonMain/kotlin/InlineConstructor.kt rename to kotlinpoet/annotations/src/commonMain/kotlin/InlineConstructor.kt diff --git a/kotlinpoet/build.gradle.kts b/kotlinpoet/build.gradle.kts index 828eb53..042d3ec 100644 --- a/kotlinpoet/build.gradle.kts +++ b/kotlinpoet/build.gradle.kts @@ -8,8 +8,8 @@ plugins { dependencies { commonMainApi(libs.kotlinpoet) commonMainImplementation(kotlin("reflect")) - commonMainCompileOnly(projects.kspAnnotations) - kspCommonMainMetadata(projects.codeProcessor) + commonMainCompileOnly(projects.kotlinpoet.internalAnnotations) + kspCommonMainMetadata(projects.kotlinpoet.processor) commonTestImplementation(kotlin("test-junit5")) } @@ -28,3 +28,8 @@ tasks { useJUnitPlatform() } } + +apiValidation { + ignoredProjects.add("internal-annotations") + ignoredProjects.add("processor") +} diff --git a/code-processor/build.gradle.kts b/kotlinpoet/processor/build.gradle.kts similarity index 74% rename from code-processor/build.gradle.kts rename to kotlinpoet/processor/build.gradle.kts index 12c1a41..7886397 100644 --- a/code-processor/build.gradle.kts +++ b/kotlinpoet/processor/build.gradle.kts @@ -12,6 +12,7 @@ dependencies { implementation(libs.codegen.kotlinpoet) implementation(libs.kotlinpoet.ksp) implementation(libs.ksp.api) - implementation(projects.kspAnnotations) + implementation(projects.kotlinpoet.internalAnnotations) + implementation(projects.ksp.annotations) implementation(projects.ksp) } diff --git a/code-processor/src/main/kotlin/CodeProcessor.kt b/kotlinpoet/processor/src/main/kotlin/CodeProcessor.kt similarity index 100% rename from code-processor/src/main/kotlin/CodeProcessor.kt rename to kotlinpoet/processor/src/main/kotlin/CodeProcessor.kt diff --git a/code-processor/src/main/kotlin/ConstructorInliner.kt b/kotlinpoet/processor/src/main/kotlin/ConstructorInliner.kt similarity index 100% rename from code-processor/src/main/kotlin/ConstructorInliner.kt rename to kotlinpoet/processor/src/main/kotlin/ConstructorInliner.kt diff --git a/code-processor/src/main/kotlin/builder_functions/BuilderFunctionCollector.kt b/kotlinpoet/processor/src/main/kotlin/builder_functions/BuilderFunctionCollector.kt similarity index 100% rename from code-processor/src/main/kotlin/builder_functions/BuilderFunctionCollector.kt rename to kotlinpoet/processor/src/main/kotlin/builder_functions/BuilderFunctionCollector.kt diff --git a/code-processor/src/main/kotlin/builder_functions/BuilderVisitor.kt b/kotlinpoet/processor/src/main/kotlin/builder_functions/BuilderVisitor.kt similarity index 100% rename from code-processor/src/main/kotlin/builder_functions/BuilderVisitor.kt rename to kotlinpoet/processor/src/main/kotlin/builder_functions/BuilderVisitor.kt diff --git a/code-processor/src/main/kotlin/builder_functions/GenerateBuilderFunction.kt b/kotlinpoet/processor/src/main/kotlin/builder_functions/GenerateBuilderFunction.kt similarity index 100% rename from code-processor/src/main/kotlin/builder_functions/GenerateBuilderFunction.kt rename to kotlinpoet/processor/src/main/kotlin/builder_functions/GenerateBuilderFunction.kt diff --git a/code-processor/src/main/kotlin/constructor_inliner/ConstructorInliner.kt b/kotlinpoet/processor/src/main/kotlin/constructor_inliner/ConstructorInliner.kt similarity index 100% rename from code-processor/src/main/kotlin/constructor_inliner/ConstructorInliner.kt rename to kotlinpoet/processor/src/main/kotlin/constructor_inliner/ConstructorInliner.kt diff --git a/code-processor/src/main/kotlin/constructor_inliner/InlinedConstructorGenerator.kt b/kotlinpoet/processor/src/main/kotlin/constructor_inliner/InlinedConstructorGenerator.kt similarity index 98% rename from code-processor/src/main/kotlin/constructor_inliner/InlinedConstructorGenerator.kt rename to kotlinpoet/processor/src/main/kotlin/constructor_inliner/InlinedConstructorGenerator.kt index a620dce..0eabb57 100644 --- a/code-processor/src/main/kotlin/constructor_inliner/InlinedConstructorGenerator.kt +++ b/kotlinpoet/processor/src/main/kotlin/constructor_inliner/InlinedConstructorGenerator.kt @@ -5,7 +5,6 @@ package dev.kord.codegen.generator.constructor_inliner import com.google.devtools.ksp.symbol.KSValueParameter import com.squareup.kotlinpoet.* import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy -import com.squareup.kotlinpoet.jvm.jvmWildcard import com.squareup.kotlinpoet.ksp.toClassName import dev.kord.codegen.generator.utils.* import dev.kord.codegen.generator.builder_functions.FactoryFunction diff --git a/code-processor/src/main/kotlin/reification/IsReifyable.kt b/kotlinpoet/processor/src/main/kotlin/reification/IsReifyable.kt similarity index 100% rename from code-processor/src/main/kotlin/reification/IsReifyable.kt rename to kotlinpoet/processor/src/main/kotlin/reification/IsReifyable.kt diff --git a/code-processor/src/main/kotlin/reification/Reifyer.kt b/kotlinpoet/processor/src/main/kotlin/reification/Reifyer.kt similarity index 96% rename from code-processor/src/main/kotlin/reification/Reifyer.kt rename to kotlinpoet/processor/src/main/kotlin/reification/Reifyer.kt index 727e5da..3d58490 100644 --- a/code-processor/src/main/kotlin/reification/Reifyer.kt +++ b/kotlinpoet/processor/src/main/kotlin/reification/Reifyer.kt @@ -1,7 +1,6 @@ package dev.kord.codegen.generator.reification import com.google.devtools.ksp.symbol.KSClassDeclaration -import com.google.devtools.ksp.symbol.Modifier.* import com.squareup.kotlinpoet.* import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy import com.squareup.kotlinpoet.ksp.* @@ -10,7 +9,6 @@ import dev.kord.codegen.generator.utils.toParameterSpec import dev.kord.codegen.generator.utils.toTypeParameterResolver import dev.kord.codegen.kotlinpoet.CodeBlock import dev.kord.codegen.kotlinpoet.FunSpec -import java.lang.reflect.Modifier import kotlin.reflect.KClass val AS_CLASS_NAME = MemberName("com.squareup.kotlinpoet", "asClassName") @@ -69,8 +67,7 @@ fun MaybeReifiableFunction.reify(): FunSpec { .map { it.toParameterSpec( typeVariableResolver, - simpleName.asString().endsWith("Builder"), - INLINE in this@reify.modifiers + simpleName.asString().endsWith("Builder") ) } .toList() diff --git a/code-processor/src/main/kotlin/reification/ReifyingVisitor.kt b/kotlinpoet/processor/src/main/kotlin/reification/ReifyingVisitor.kt similarity index 99% rename from code-processor/src/main/kotlin/reification/ReifyingVisitor.kt rename to kotlinpoet/processor/src/main/kotlin/reification/ReifyingVisitor.kt index f6085b3..a678b61 100644 --- a/code-processor/src/main/kotlin/reification/ReifyingVisitor.kt +++ b/kotlinpoet/processor/src/main/kotlin/reification/ReifyingVisitor.kt @@ -1,7 +1,6 @@ package dev.kord.codegen.generator.reification import com.google.devtools.ksp.containingFile -import com.google.devtools.ksp.getDeclaredFunctions import com.google.devtools.ksp.isConstructor import com.google.devtools.ksp.isPublic import com.google.devtools.ksp.processing.SymbolProcessorEnvironment diff --git a/code-processor/src/main/kotlin/utils/AnnotationUtil.kt b/kotlinpoet/processor/src/main/kotlin/utils/AnnotationUtil.kt similarity index 100% rename from code-processor/src/main/kotlin/utils/AnnotationUtil.kt rename to kotlinpoet/processor/src/main/kotlin/utils/AnnotationUtil.kt diff --git a/code-processor/src/main/kotlin/utils/ContractHelper.kt b/kotlinpoet/processor/src/main/kotlin/utils/ContractHelper.kt similarity index 100% rename from code-processor/src/main/kotlin/utils/ContractHelper.kt rename to kotlinpoet/processor/src/main/kotlin/utils/ContractHelper.kt diff --git a/code-processor/src/main/kotlin/utils/FileSpec.kt b/kotlinpoet/processor/src/main/kotlin/utils/FileSpec.kt similarity index 100% rename from code-processor/src/main/kotlin/utils/FileSpec.kt rename to kotlinpoet/processor/src/main/kotlin/utils/FileSpec.kt diff --git a/code-processor/src/main/kotlin/utils/KSPUtils.kt b/kotlinpoet/processor/src/main/kotlin/utils/KSPUtils.kt similarity index 90% rename from code-processor/src/main/kotlin/utils/KSPUtils.kt rename to kotlinpoet/processor/src/main/kotlin/utils/KSPUtils.kt index 6a46a48..f481107 100644 --- a/code-processor/src/main/kotlin/utils/KSPUtils.kt +++ b/kotlinpoet/processor/src/main/kotlin/utils/KSPUtils.kt @@ -4,11 +4,12 @@ import com.google.devtools.ksp.getDeclaredFunctions import com.google.devtools.ksp.symbol.* import com.squareup.kotlinpoet.* import com.squareup.kotlinpoet.ksp.TypeParameterResolver -import com.squareup.kotlinpoet.ksp.toKModifier import com.squareup.kotlinpoet.ksp.toTypeName -import com.squareup.kotlinpoet.ksp.toTypeParameterResolver -fun KSValueParameter.toParameterSpec(typeParamResolver: TypeParameterResolver = TypeParameterResolver.EMPTY, useParent: Boolean = false, noInline: Boolean = false) = +fun KSValueParameter.toParameterSpec( + typeParamResolver: TypeParameterResolver = TypeParameterResolver.EMPTY, + useParent: Boolean = false +) = ParameterSpec.builder(name!!.asString(), type.toTypeName(typeParamResolver), modifiers) .apply { if (name!!.asString() == "block") { diff --git a/code-processor/src/main/kotlin/utils/Names.kt b/kotlinpoet/processor/src/main/kotlin/utils/Names.kt similarity index 87% rename from code-processor/src/main/kotlin/utils/Names.kt rename to kotlinpoet/processor/src/main/kotlin/utils/Names.kt index 8e1666c..ce5be7d 100644 --- a/code-processor/src/main/kotlin/utils/Names.kt +++ b/kotlinpoet/processor/src/main/kotlin/utils/Names.kt @@ -1,8 +1,9 @@ @file:Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER") -@file:OptIn(CodeGenInternal::class) +@file:OptIn(CodeGenInternal::class, DelicateKotlinPoetApi::class) package dev.kord.codegen.generator.utils +import com.squareup.kotlinpoet.DelicateKotlinPoetApi import com.squareup.kotlinpoet.asClassName import dev.kord.codegen.kotlinpoet.CodeGenDsl import dev.kord.codegen.kotlinpoet.CodeGenInternal diff --git a/code-processor/src/main/kotlin/utils/ParameterHelpers.kt b/kotlinpoet/processor/src/main/kotlin/utils/ParameterHelpers.kt similarity index 100% rename from code-processor/src/main/kotlin/utils/ParameterHelpers.kt rename to kotlinpoet/processor/src/main/kotlin/utils/ParameterHelpers.kt diff --git a/code-processor/src/main/kotlin/utils/ReificationUtil.kt b/kotlinpoet/processor/src/main/kotlin/utils/ReificationUtil.kt similarity index 100% rename from code-processor/src/main/kotlin/utils/ReificationUtil.kt rename to kotlinpoet/processor/src/main/kotlin/utils/ReificationUtil.kt diff --git a/code-processor/src/main/kotlin/utils/RunOnceFunction.kt b/kotlinpoet/processor/src/main/kotlin/utils/RunOnceFunction.kt similarity index 100% rename from code-processor/src/main/kotlin/utils/RunOnceFunction.kt rename to kotlinpoet/processor/src/main/kotlin/utils/RunOnceFunction.kt diff --git a/code-processor/src/main/kotlin/visitors/BeginEndVisitor.kt b/kotlinpoet/processor/src/main/kotlin/visitors/BeginEndVisitor.kt similarity index 96% rename from code-processor/src/main/kotlin/visitors/BeginEndVisitor.kt rename to kotlinpoet/processor/src/main/kotlin/visitors/BeginEndVisitor.kt index 2a77538..3092b97 100644 --- a/code-processor/src/main/kotlin/visitors/BeginEndVisitor.kt +++ b/kotlinpoet/processor/src/main/kotlin/visitors/BeginEndVisitor.kt @@ -3,14 +3,12 @@ package dev.kord.codegen.generator.visitors import com.google.devtools.ksp.getDeclaredFunctions import com.google.devtools.ksp.processing.SymbolProcessorEnvironment import com.google.devtools.ksp.symbol.KSClassDeclaration -import com.google.devtools.ksp.symbol.KSFunctionDeclaration import com.google.devtools.ksp.symbol.KSValueParameter import com.squareup.kotlinpoet.* import com.squareup.kotlinpoet.ksp.toClassName import com.squareup.kotlinpoet.ksp.writeTo import dev.kord.codegen.generator.packageName import dev.kord.codegen.generator.utils.FileSpec -import dev.kord.codegen.generator.utils.addCallsInPlaceExactlyOnce import dev.kord.codegen.generator.utils.mapToValueParameterList import dev.kord.codegen.generator.utils.toParameterSpec import dev.kord.codegen.generator.builder_functions.getBuilderScopeName diff --git a/code-processor/src/main/kotlin/visitors/VisitorBase.kt b/kotlinpoet/processor/src/main/kotlin/visitors/VisitorBase.kt similarity index 100% rename from code-processor/src/main/kotlin/visitors/VisitorBase.kt rename to kotlinpoet/processor/src/main/kotlin/visitors/VisitorBase.kt diff --git a/code-processor/src/main/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider b/kotlinpoet/processor/src/main/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider similarity index 100% rename from code-processor/src/main/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider rename to kotlinpoet/processor/src/main/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider diff --git a/ksp-annotations/build.gradle.kts b/ksp-annotations/build.gradle.kts deleted file mode 100644 index e1ec5ec..0000000 --- a/ksp-annotations/build.gradle.kts +++ /dev/null @@ -1,23 +0,0 @@ -plugins { - org.jetbrains.kotlin.multiplatform - com.google.devtools.ksp -} - -kotlin { - explicitApi() - jvm() -} - -dependencies { - commonMainImplementation(projects.ksp) - "kspJvm"(projects.kspProcessor) -} - -kotlin { - sourceSets { - named("jvmMain") { - kotlin.srcDir("build/generated/ksp/jvm/jvmMain") - } - } -} - diff --git a/ksp-processor/api/ksp-processor.api b/ksp-processor/api/ksp-processor.api deleted file mode 100644 index 08d99b8..0000000 --- a/ksp-processor/api/ksp-processor.api +++ /dev/null @@ -1,54 +0,0 @@ -public final class dev/kord/codegen/ksp/processor/NamesKt { - public static final field NULL_IF_DEFAULT Ljava/lang/String; - public static final field PROCESSOR_ANNOTATION Ljava/lang/String; - public static final fun getARGUMENTS ()Lcom/squareup/kotlinpoet/MemberName; - public static final fun getARGUMENTS_NOT_NULL ()Lcom/squareup/kotlinpoet/MemberName; - public static final fun getGET_ANNOTATIONS_BY_TYPE ()Lcom/squareup/kotlinpoet/MemberName; - public static final fun getGET_ANNOTATION_BY_TYPE ()Lcom/squareup/kotlinpoet/MemberName; -} - -public final class dev/kord/codegen/ksp/processor/ProcessorAnnotationProcessor : com/google/devtools/ksp/processing/SymbolProcessor { - public synthetic fun (Lcom/google/devtools/ksp/processing/SymbolProcessorEnvironment;Lkotlin/jvm/internal/DefaultConstructorMarker;)V - public fun process (Lcom/google/devtools/ksp/processing/Resolver;)Ljava/util/List; -} - -public final class dev/kord/codegen/ksp/processor/ProcessorAnnotationProcessor$Provider : com/google/devtools/ksp/processing/SymbolProcessorProvider { - public fun ()V - public fun create (Lcom/google/devtools/ksp/processing/SymbolProcessorEnvironment;)Lcom/google/devtools/ksp/processing/SymbolProcessor; -} - -public final class dev/kord/codegen/ksp/processor/generator/AccessorFunctionsKt { - public static final fun accessorFunction (Ldev/kord/codegen/ksp/processor/generator/ProcessingContext;)V -} - -public final class dev/kord/codegen/ksp/processor/generator/DataClassRepresentationKt { - public static final fun dataClassRepresentation (Ldev/kord/codegen/ksp/processor/generator/ProcessingContext;)V - public static final fun dataClassType (Lcom/google/devtools/ksp/symbol/KSPropertyDeclaration;Lcom/google/devtools/ksp/symbol/KSClassDeclaration;)Lcom/squareup/kotlinpoet/TypeName; - public static final fun isMappedAnnotation (Lcom/google/devtools/ksp/symbol/KSType;Lcom/google/devtools/ksp/symbol/KSClassDeclaration;)Z -} - -public final class dev/kord/codegen/ksp/processor/generator/FactoryFunctionKt { - public static final fun factoryFunction (Lcom/squareup/kotlinpoet/TypeSpec$Builder;Lcom/google/devtools/ksp/symbol/KSClassDeclaration;Ljava/lang/String;)V -} - -public final class dev/kord/codegen/ksp/processor/generator/GeneratorKt { - public static final fun processAnnotation (Lcom/google/devtools/ksp/processing/SymbolProcessorEnvironment;Lcom/google/devtools/ksp/symbol/KSClassDeclaration;)V -} - -public final class dev/kord/codegen/ksp/processor/generator/ProcessingContext { - public fun (Lcom/google/devtools/ksp/processing/SymbolProcessorEnvironment;Lcom/squareup/kotlinpoet/FileSpec$Builder;Lcom/google/devtools/ksp/symbol/KSClassDeclaration;Ljava/lang/String;)V - public final fun component1 ()Lcom/google/devtools/ksp/processing/SymbolProcessorEnvironment; - public final fun component2 ()Lcom/squareup/kotlinpoet/FileSpec$Builder; - public final fun component3 ()Lcom/google/devtools/ksp/symbol/KSClassDeclaration; - public final fun component4 ()Ljava/lang/String; - public final fun copy (Lcom/google/devtools/ksp/processing/SymbolProcessorEnvironment;Lcom/squareup/kotlinpoet/FileSpec$Builder;Lcom/google/devtools/ksp/symbol/KSClassDeclaration;Ljava/lang/String;)Ldev/kord/codegen/ksp/processor/generator/ProcessingContext; - public static synthetic fun copy$default (Ldev/kord/codegen/ksp/processor/generator/ProcessingContext;Lcom/google/devtools/ksp/processing/SymbolProcessorEnvironment;Lcom/squareup/kotlinpoet/FileSpec$Builder;Lcom/google/devtools/ksp/symbol/KSClassDeclaration;Ljava/lang/String;ILjava/lang/Object;)Ldev/kord/codegen/ksp/processor/generator/ProcessingContext; - public fun equals (Ljava/lang/Object;)Z - public final fun getDeclaration ()Lcom/google/devtools/ksp/symbol/KSClassDeclaration; - public final fun getEnvironment ()Lcom/google/devtools/ksp/processing/SymbolProcessorEnvironment; - public final fun getFile ()Lcom/squareup/kotlinpoet/FileSpec$Builder; - public final fun getPackageName ()Ljava/lang/String; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - diff --git a/ksp/annotations/api/annotations.api b/ksp/annotations/api/annotations.api new file mode 100644 index 0000000..df5ddee --- /dev/null +++ b/ksp/annotations/api/annotations.api @@ -0,0 +1,7 @@ +public abstract interface annotation class dev/kord/codegen/ksp/annotations/NullIfDefault : java/lang/annotation/Annotation { +} + +public abstract interface annotation class dev/kord/codegen/ksp/annotations/ProcessorAnnotation : java/lang/annotation/Annotation { + public abstract fun packageName ()Ljava/lang/String; +} + diff --git a/ksp/annotations/build.gradle.kts b/ksp/annotations/build.gradle.kts new file mode 100644 index 0000000..127dce1 --- /dev/null +++ b/ksp/annotations/build.gradle.kts @@ -0,0 +1,29 @@ +plugins { + org.jetbrains.kotlin.multiplatform + `kord-publishing` +} + +base { + archivesName = "ksp-annotations" +} + +kotlin { + explicitApi() + + jvm() + js(IR) { + browser() + nodejs() + } + + mingwX64() + linuxX64() + linuxArm64() + +// TODO: CI infra for darwin targets +// ios() +// watchos() +// tvos() +// macosX64() +// macosArm64() +} diff --git a/ksp/src/main/kotlin/annotations/ProcessorAnnotation.kt b/ksp/annotations/src/commonMain/kotlin/ProcessorAnnotation.kt similarity index 88% rename from ksp/src/main/kotlin/annotations/ProcessorAnnotation.kt rename to ksp/annotations/src/commonMain/kotlin/ProcessorAnnotation.kt index 4c5c46f..47c603c 100644 --- a/ksp/src/main/kotlin/annotations/ProcessorAnnotation.kt +++ b/ksp/annotations/src/commonMain/kotlin/ProcessorAnnotation.kt @@ -1,12 +1,8 @@ package dev.kord.codegen.ksp.annotations -import com.google.devtools.ksp.symbol.KSAnnotated -import com.google.devtools.ksp.symbol.KSAnnotation - - /** * This annotation instructs the processor to generate a data class wrapper around the annotation with - * factory functions to instantiate it from a [KSAnnotation]. + * factory functions to instantiate it from a `KSAnnotation`. * * # Type mappings * KSP does not represent all types identical to the ones in the actual annotation, please use the mapping below @@ -21,9 +17,9 @@ import com.google.devtools.ksp.symbol.KSAnnotation * # Factory function * * In order to obtain an instance of the wrapper type, please use the generated constructor function which takes an - * [KSAnnotation] + * `KSAnnotation` * - * # Obtaining the annotations from [KSAnnotated] + * # Obtaining the annotations from `KSAnnotated` * * If the Annotation is annotated with [Repeatable] use the generated KSAnnotated.getAnnotationNames function * otherwise use the generated KSAnnotated.getAnnotationName function diff --git a/ksp/api/ksp.api b/ksp/api/ksp.api index 57066d7..ef020bf 100644 --- a/ksp/api/ksp.api +++ b/ksp/api/ksp.api @@ -47,30 +47,3 @@ public final class dev/kord/codegen/ksp/annotations/AnnotationArguments$NonNullA public final fun notNull (Ldev/kord/codegen/ksp/annotations/AnnotationArguments;)Ldev/kord/codegen/ksp/annotations/AnnotationArguments$NonNullAnnotationArguments; } -public abstract interface annotation class dev/kord/codegen/ksp/annotations/NullIfDefault : java/lang/annotation/Annotation { -} - -public abstract interface annotation class dev/kord/codegen/ksp/annotations/ProcessorAnnotation : java/lang/annotation/Annotation { - public abstract fun packageName ()Ljava/lang/String; -} - -public final class dev/kord/codegen/ksp/processor/ProcessorAnnotation { - public static final field Companion Ldev/kord/codegen/ksp/processor/ProcessorAnnotation$Companion; - public synthetic fun (Ljava/lang/String;Lkotlin/jvm/internal/DefaultConstructorMarker;)V - public final fun component1 ()Ljava/lang/String; - public final fun copy (Ljava/lang/String;)Ldev/kord/codegen/ksp/processor/ProcessorAnnotation; - public static synthetic fun copy$default (Ldev/kord/codegen/ksp/processor/ProcessorAnnotation;Ljava/lang/String;ILjava/lang/Object;)Ldev/kord/codegen/ksp/processor/ProcessorAnnotation; - public fun equals (Ljava/lang/Object;)Z - public final fun getPackageName ()Ljava/lang/String; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class dev/kord/codegen/ksp/processor/ProcessorAnnotation$Companion { - public final fun ProcessorAnnotation (Lcom/google/devtools/ksp/symbol/KSAnnotation;)Ldev/kord/codegen/ksp/processor/ProcessorAnnotation; -} - -public final class dev/kord/codegen/ksp/processor/ProcessorAnnotationKt { - public static final fun getProcessorAnnotation (Lcom/google/devtools/ksp/symbol/KSAnnotated;)Ldev/kord/codegen/ksp/processor/ProcessorAnnotation; -} - diff --git a/ksp/build.gradle.kts b/ksp/build.gradle.kts index f42d297..d579b27 100644 --- a/ksp/build.gradle.kts +++ b/ksp/build.gradle.kts @@ -32,10 +32,15 @@ testing { } } -tasks { +apiValidation { + ignoredProjects.add("annotations") + ignoredProjects.add("processor") +} + +subprojects { afterEvaluate { - named("kspTestKotlin") { - dependsOn(jar) + mavenPublishing { + coordinates(group.toString(), "ksp-$name", version.toString()) } } } diff --git a/ksp-processor/build.gradle.kts b/ksp/processor/build.gradle.kts similarity index 78% rename from ksp-processor/build.gradle.kts rename to ksp/processor/build.gradle.kts index 215e9f2..51e0f89 100644 --- a/ksp-processor/build.gradle.kts +++ b/ksp/processor/build.gradle.kts @@ -3,6 +3,10 @@ plugins { `kord-publishing` } +base { + archivesName = "ksp-processor" +} + kotlin { compilerOptions { freeCompilerArgs.add("-Xcontext-receivers") @@ -10,8 +14,9 @@ kotlin { } dependencies { - implementation(libs.ksp.api) implementation(libs.kotlinpoet.ksp) + implementation(libs.ksp.api) implementation(libs.codegen.kotlinpoet) implementation(libs.codegen.ksp) + implementation(projects.ksp.annotations) } diff --git a/ksp-processor/src/main/kotlin/Names.kt b/ksp/processor/src/main/kotlin/Names.kt similarity index 100% rename from ksp-processor/src/main/kotlin/Names.kt rename to ksp/processor/src/main/kotlin/Names.kt diff --git a/ksp-processor/src/main/kotlin/ProcessorAnnotationProcessor.kt b/ksp/processor/src/main/kotlin/ProcessorAnnotationProcessor.kt similarity index 100% rename from ksp-processor/src/main/kotlin/ProcessorAnnotationProcessor.kt rename to ksp/processor/src/main/kotlin/ProcessorAnnotationProcessor.kt diff --git a/ksp-processor/src/main/kotlin/generator/AccessorFunctions.kt b/ksp/processor/src/main/kotlin/generator/AccessorFunctions.kt similarity index 100% rename from ksp-processor/src/main/kotlin/generator/AccessorFunctions.kt rename to ksp/processor/src/main/kotlin/generator/AccessorFunctions.kt diff --git a/ksp-processor/src/main/kotlin/generator/DataClassRepresentation.kt b/ksp/processor/src/main/kotlin/generator/DataClassRepresentation.kt similarity index 100% rename from ksp-processor/src/main/kotlin/generator/DataClassRepresentation.kt rename to ksp/processor/src/main/kotlin/generator/DataClassRepresentation.kt diff --git a/ksp-processor/src/main/kotlin/generator/FactoryFunction.kt b/ksp/processor/src/main/kotlin/generator/FactoryFunction.kt similarity index 100% rename from ksp-processor/src/main/kotlin/generator/FactoryFunction.kt rename to ksp/processor/src/main/kotlin/generator/FactoryFunction.kt diff --git a/ksp-processor/src/main/kotlin/generator/Generator.kt b/ksp/processor/src/main/kotlin/generator/Generator.kt similarity index 100% rename from ksp-processor/src/main/kotlin/generator/Generator.kt rename to ksp/processor/src/main/kotlin/generator/Generator.kt diff --git a/ksp-processor/src/main/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider b/ksp/processor/src/main/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider similarity index 100% rename from ksp-processor/src/main/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider rename to ksp/processor/src/main/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider diff --git a/ksp/src/main/kotlin/TypeResolvers.kt b/ksp/src/main/kotlin/TypeResolvers.kt index 44937af..27beae4 100644 --- a/ksp/src/main/kotlin/TypeResolvers.kt +++ b/ksp/src/main/kotlin/TypeResolvers.kt @@ -1,11 +1,9 @@ package dev.kord.codegen.ksp -import com.google.devtools.ksp.KspExperimental import com.google.devtools.ksp.findActualType import com.google.devtools.ksp.getAnnotationsByType import com.google.devtools.ksp.processing.Resolver import com.google.devtools.ksp.symbol.* -import dev.kord.codegen.ksp.processor.getProcessorAnnotation /** * Get all symbols with specified annotation. diff --git a/settings.gradle.kts b/settings.gradle.kts index 75832cf..734cb25 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -13,4 +13,16 @@ plugins { rootProject.name = "codegen-kt" -include("code-processor", "kotlinpoet", "ksp", "ksp-processor", "ksp-annotations", "bom") +include( + ":kotlinpoet:annotations", + ":kotlinpoet:processor", + ":kotlinpoet", + ":ksp:annotations", + ":ksp:processor", + ":ksp" +) + +// For some reason not doing this makes Gradle interpret both "annotations" modules the same and causes circular +// dependencies +project(":kotlinpoet:annotations").name = "internal-annotations" +