From a7d59694565cfc27497152e5fb7209b09ed3eadf Mon Sep 17 00:00:00 2001 From: Thiago Santos Date: Wed, 13 Nov 2024 13:30:06 -0300 Subject: [PATCH] Folder changes only --- ksp-annotations/.gitignore | 1 - ksp-processor/.gitignore | 1 - ksp/core-annotations/.gitignore | 1 + .../core-annotations}/build.gradle.kts | 0 .../programadorthi/routing/annotation/Body.kt | 0 .../programadorthi/routing/annotation/Path.kt | 0 .../routing/annotation/Route.kt | 0 .../core-annotations}/gradle.properties | 0 ksp/core-processor/.gitignore | 1 + .../core-processor}/build.gradle.kts | 2 +- .../core-processor}/gradle.properties | 0 ...ols.ksp.processing.SymbolProcessorProvider | 0 .../routing/ksp/RoutingProcessor.kt | 47 +++++++++++++------ samples/ksp-sample/build.gradle.kts | 6 +-- settings.gradle.kts | 4 +- 15 files changed, 40 insertions(+), 23 deletions(-) delete mode 100644 ksp-annotations/.gitignore delete mode 100644 ksp-processor/.gitignore create mode 100644 ksp/core-annotations/.gitignore rename {ksp-annotations => ksp/core-annotations}/build.gradle.kts (100%) rename {ksp-annotations => ksp/core-annotations}/common/src/dev/programadorthi/routing/annotation/Body.kt (100%) rename {ksp-annotations => ksp/core-annotations}/common/src/dev/programadorthi/routing/annotation/Path.kt (100%) rename {ksp-annotations => ksp/core-annotations}/common/src/dev/programadorthi/routing/annotation/Route.kt (100%) rename {ksp-annotations => ksp/core-annotations}/gradle.properties (100%) create mode 100644 ksp/core-processor/.gitignore rename {ksp-processor => ksp/core-processor}/build.gradle.kts (87%) rename {ksp-processor => ksp/core-processor}/gradle.properties (100%) rename {ksp-processor => ksp/core-processor}/jvm/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider (100%) rename {ksp-processor => ksp/core-processor}/jvm/src/dev/programadorthi/routing/ksp/RoutingProcessor.kt (90%) diff --git a/ksp-annotations/.gitignore b/ksp-annotations/.gitignore deleted file mode 100644 index c795b05..0000000 --- a/ksp-annotations/.gitignore +++ /dev/null @@ -1 +0,0 @@ -build \ No newline at end of file diff --git a/ksp-processor/.gitignore b/ksp-processor/.gitignore deleted file mode 100644 index c795b05..0000000 --- a/ksp-processor/.gitignore +++ /dev/null @@ -1 +0,0 @@ -build \ No newline at end of file diff --git a/ksp/core-annotations/.gitignore b/ksp/core-annotations/.gitignore new file mode 100644 index 0000000..ce36b8c --- /dev/null +++ b/ksp/core-annotations/.gitignore @@ -0,0 +1 @@ +../../ksp-annotations/build diff --git a/ksp-annotations/build.gradle.kts b/ksp/core-annotations/build.gradle.kts similarity index 100% rename from ksp-annotations/build.gradle.kts rename to ksp/core-annotations/build.gradle.kts diff --git a/ksp-annotations/common/src/dev/programadorthi/routing/annotation/Body.kt b/ksp/core-annotations/common/src/dev/programadorthi/routing/annotation/Body.kt similarity index 100% rename from ksp-annotations/common/src/dev/programadorthi/routing/annotation/Body.kt rename to ksp/core-annotations/common/src/dev/programadorthi/routing/annotation/Body.kt diff --git a/ksp-annotations/common/src/dev/programadorthi/routing/annotation/Path.kt b/ksp/core-annotations/common/src/dev/programadorthi/routing/annotation/Path.kt similarity index 100% rename from ksp-annotations/common/src/dev/programadorthi/routing/annotation/Path.kt rename to ksp/core-annotations/common/src/dev/programadorthi/routing/annotation/Path.kt diff --git a/ksp-annotations/common/src/dev/programadorthi/routing/annotation/Route.kt b/ksp/core-annotations/common/src/dev/programadorthi/routing/annotation/Route.kt similarity index 100% rename from ksp-annotations/common/src/dev/programadorthi/routing/annotation/Route.kt rename to ksp/core-annotations/common/src/dev/programadorthi/routing/annotation/Route.kt diff --git a/ksp-annotations/gradle.properties b/ksp/core-annotations/gradle.properties similarity index 100% rename from ksp-annotations/gradle.properties rename to ksp/core-annotations/gradle.properties diff --git a/ksp/core-processor/.gitignore b/ksp/core-processor/.gitignore new file mode 100644 index 0000000..da334b4 --- /dev/null +++ b/ksp/core-processor/.gitignore @@ -0,0 +1 @@ +../../ksp-processor/build diff --git a/ksp-processor/build.gradle.kts b/ksp/core-processor/build.gradle.kts similarity index 87% rename from ksp-processor/build.gradle.kts rename to ksp/core-processor/build.gradle.kts index e355725..4524e01 100644 --- a/ksp-processor/build.gradle.kts +++ b/ksp/core-processor/build.gradle.kts @@ -11,7 +11,7 @@ kotlin { jvmMain { dependencies { implementation(projects.core) - implementation(projects.kspAnnotations) + implementation(projects.ksp.coreAnnotations) implementation(libs.kotlin.poet) implementation(libs.kotlin.poet.ksp) implementation(libs.ksp.api) diff --git a/ksp-processor/gradle.properties b/ksp/core-processor/gradle.properties similarity index 100% rename from ksp-processor/gradle.properties rename to ksp/core-processor/gradle.properties diff --git a/ksp-processor/jvm/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider b/ksp/core-processor/jvm/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider similarity index 100% rename from ksp-processor/jvm/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider rename to ksp/core-processor/jvm/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider diff --git a/ksp-processor/jvm/src/dev/programadorthi/routing/ksp/RoutingProcessor.kt b/ksp/core-processor/jvm/src/dev/programadorthi/routing/ksp/RoutingProcessor.kt similarity index 90% rename from ksp-processor/jvm/src/dev/programadorthi/routing/ksp/RoutingProcessor.kt rename to ksp/core-processor/jvm/src/dev/programadorthi/routing/ksp/RoutingProcessor.kt index 9a53ed2..fa5f20c 100644 --- a/ksp-processor/jvm/src/dev/programadorthi/routing/ksp/RoutingProcessor.kt +++ b/ksp/core-processor/jvm/src/dev/programadorthi/routing/ksp/RoutingProcessor.kt @@ -7,7 +7,6 @@ import com.google.devtools.ksp.getVisibility import com.google.devtools.ksp.processing.CodeGenerator import com.google.devtools.ksp.processing.Dependencies import com.google.devtools.ksp.processing.KSBuiltIns -import com.google.devtools.ksp.processing.KSPLogger import com.google.devtools.ksp.processing.Resolver import com.google.devtools.ksp.processing.SymbolProcessor import com.google.devtools.ksp.processing.SymbolProcessorEnvironment @@ -31,16 +30,12 @@ import dev.programadorthi.routing.annotation.Route public class RoutingProcessorProvider : SymbolProcessorProvider { override fun create(environment: SymbolProcessorEnvironment): SymbolProcessor { - return RoutingProcessor( - codeGenerator = environment.codeGenerator, - logger = environment.logger - ) + return RoutingProcessor(codeGenerator = environment.codeGenerator) } } private class RoutingProcessor( private val codeGenerator: CodeGenerator, - private val logger: KSPLogger ) : SymbolProcessor { private var invoked = false @@ -99,11 +94,23 @@ private class RoutingProcessor( if (isRegexRoute) { if (routeAnnotation.method.isBlank()) { configureSpec - .beginControlFlow("%M(path = %T(%S))", handle, Regex::class, routeAnnotation.regex) + .beginControlFlow( + "%M(path = %T(%S))", + handle, + Regex::class, + routeAnnotation.regex + ) } else { - val template = """%M(path = %T(%S), method = %M(value = "${routeAnnotation.method}"))""" + val template = + """%M(path = %T(%S), method = %M(value = "${routeAnnotation.method}"))""" configureSpec - .beginControlFlow(template, handle, Regex::class, routeAnnotation.regex, routeMethod) + .beginControlFlow( + template, + handle, + Regex::class, + routeAnnotation.regex, + routeMethod + ) } } else { val named = when { @@ -114,7 +121,8 @@ private class RoutingProcessor( configureSpec .beginControlFlow("%M(path = %S, $named)", handle, routeAnnotation.path) } else { - val template = """%M(path = %S, $named, method = %M(value = "${routeAnnotation.method}"))""" + val template = + """%M(path = %S, $named, method = %M(value = "${routeAnnotation.method}"))""" configureSpec .beginControlFlow(template, handle, routeAnnotation.path, routeMethod) } @@ -206,7 +214,14 @@ private class RoutingProcessor( else -> resolver.builtIns.requiredParse(type.resolve()) } when { - hasZeroOrOneParameter -> builder.add(PATH_TEMPLATE, paramName, call, customName, literal) + hasZeroOrOneParameter -> builder.add( + PATH_TEMPLATE, + paramName, + call, + customName, + literal + ) + else -> builder.addStatement(PATH_TEMPLATE, paramName, call, customName, "$literal,") } } @@ -233,9 +248,10 @@ private class RoutingProcessor( check(paramType.declaration == listDeclaration) { "TailCard parameter must be a List?" } - val genericArgument = checkNotNull(type.element?.typeArguments?.firstOrNull()?.type?.resolve()) { - "No type found at tailcard parameter" - } + val genericArgument = + checkNotNull(type.element?.typeArguments?.firstOrNull()?.type?.resolve()) { + "No type found at tailcard parameter" + } check(genericArgument == resolver.builtIns.stringType) { "TailCard list item type must be non nullable String" } @@ -318,7 +334,8 @@ private class RoutingProcessor( private val routeMethod = MemberName("dev.programadorthi.routing.core", "RouteMethod") private val call = MemberName("dev.programadorthi.routing.core.application", "call") private val receive = MemberName("dev.programadorthi.routing.core.application", "receive") - private val receiveNullable = MemberName("dev.programadorthi.routing.core.application", "receiveNullable") + private val receiveNullable = + MemberName("dev.programadorthi.routing.core.application", "receiveNullable") private const val BODY_TEMPLATE = "%L = %M.%M()%L" private const val FUN_INVOKE_END = ")" diff --git a/samples/ksp-sample/build.gradle.kts b/samples/ksp-sample/build.gradle.kts index 7f0d347..d96a602 100644 --- a/samples/ksp-sample/build.gradle.kts +++ b/samples/ksp-sample/build.gradle.kts @@ -5,7 +5,7 @@ plugins { dependencies { implementation(projects.core) - implementation(projects.kspAnnotations) - implementation(projects.kspProcessor) - ksp(projects.kspProcessor) + implementation(projects.ksp.coreAnnotations) + implementation(projects.ksp.coreProcessor) + ksp(projects.ksp.coreProcessor) } diff --git a/settings.gradle.kts b/settings.gradle.kts index 0b2264c..b209be6 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -25,8 +25,8 @@ include(":call-logging") include(":core") include(":events") include(":events-resources") -include(":ksp-annotations") -include(":ksp-processor") +include(":ksp:core-annotations") +include(":ksp:core-processor") include(":resources") include(":sessions") include(":status-pages")