This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FunctionProcessor(...) : SymbolProcessor { | |
override fun process(resolver: Resolver): List<KSAnnotated> { | |
val symbols = resolver | |
.getSymbolsWithAnnotation("com.morfly.Function") | |
.filterIsInstance<KSClassDeclaration>() | |
if (!symbols.iterator().hasNext()) return emptyList() | |
val file: OutputStream = codeGenerator.createNewFile( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Function(name = "myAmazingFunction") | |
interface MyAmazingFunction { | |
val arg1: String | |
val arg2: Map<String, List<*>> | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun myAmazingFunction( | |
arg1: String, | |
arg2: Map<String, List<*>> | |
) { | |
println("Hello from myAmazingFunction") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// annotations/build.gradle.kts | |
plugins { | |
kotlin("jvm") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// processor/build.gradle.kts | |
plugins { | |
kotlin("jvm") | |
} | |
dependencies { | |
implementation(project(":annotations")) | |
implementation("com.google.devtools.ksp:symbol-processing-api:1.6.20-1.0.5") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// main-project/build.gradle.kts | |
plugins { | |
kotlin("jvm") | |
id("com.google.devtools.ksp") | |
} | |
dependencies { | |
implementation(project(":annotations")) | |
ksp(project(":processor")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// settings.gradle.kts | |
pluginManagement { | |
plugins { | |
id("com.google.devtools.ksp") version "1.6.20-1.0.5" | |
kotlin("jvm") version "1.6.20" | |
} | |
repositories { | |
gradlePluginPortal() | |
google() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.morfly | |
class FunctionProcessor( | |
private val codeGenerator: CodeGenerator, | |
private val logger: KSPLogger, | |
private val options: Map<String, String> | |
): SymbolProcessor { | |
override fun process(resolver: Resolver): List<KSAnnotated> { | |
// leave it blank for now |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.morfly | |
class FunctionProcessorProvider : SymbolProcessorProvider { | |
override fun create(environment: SymbolProcessorEnvironment): SymbolProcessor { | |
return FunctionProcessor( | |
codeGenerator = environment.codeGenerator, | |
logger = environment.logger, | |
options = environment.options | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.morfly | |
@Target(AnnotationTarget.CLASS) | |
annotation class Function(val name: String) |