Skip to content

Commit

Permalink
Folder changes only
Browse files Browse the repository at this point in the history
  • Loading branch information
programadorthi committed Nov 13, 2024
1 parent 0657ef8 commit a7d5969
Show file tree
Hide file tree
Showing 15 changed files with 40 additions and 23 deletions.
1 change: 0 additions & 1 deletion ksp-annotations/.gitignore

This file was deleted.

1 change: 0 additions & 1 deletion ksp-processor/.gitignore

This file was deleted.

1 change: 1 addition & 0 deletions ksp/core-annotations/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
../../ksp-annotations/build
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions ksp/core-processor/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
../../ksp-processor/build
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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 {
Expand All @@ -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)
}
Expand Down Expand Up @@ -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,")
}
}
Expand All @@ -233,9 +248,10 @@ private class RoutingProcessor(
check(paramType.declaration == listDeclaration) {
"TailCard parameter must be a List<String>?"
}
val genericArgument = checkNotNull(type.element?.typeArguments?.firstOrNull()?.type?.resolve()) {
"No <String> type found at tailcard parameter"
}
val genericArgument =
checkNotNull(type.element?.typeArguments?.firstOrNull()?.type?.resolve()) {
"No <String> type found at tailcard parameter"
}
check(genericArgument == resolver.builtIns.stringType) {
"TailCard list item type must be non nullable String"
}
Expand Down Expand Up @@ -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 = ")"
Expand Down
6 changes: 3 additions & 3 deletions samples/ksp-sample/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
4 changes: 2 additions & 2 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit a7d5969

Please sign in to comment.