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() | |
} | |
} |
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
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) |
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
interface KSVisitor<D, R> { | |
fun visitNode(node: KSNode, data: D): R | |
fun visitClassDeclaration(classDeclaration: KSClassDeclaration, data: D): R | |
fun visitPropertyDeclaration(property: KSPropertyDeclaration, data: D): R | |
// ~20 more functions | |
} |
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
interface KSNode { | |
... | |
fun <D, R> accept(visitor: KSVisitor<D, R>, data: D): R | |
} |
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 KSPropertyDeclarationImpl(...) : KSPropertyDeclaration, ... { | |
... | |
override fun <D, R> accept(visitor: KSVisitor<D, R>, data: D): R { | |
return visitor.visitPropertyDeclaration(this, data) | |
} | |
} |
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
... | |
kotlin { | |
sourceSets { | |
main { | |
kotlin.srcDirs(file("$buildDir/generated/ksp/main/kotlin")) | |
} | |
} | |
} |
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 { | |
... | |
inner class Visitor(private val file: OutputStream) : KSVisitorVoid() { | |
override fun visitClassDeclaration(classDeclaration: KSClassDeclaration, data: Unit) { | |
} | |
override fun visitPropertyDeclaration(property: KSPropertyDeclaration, data: Unit) { | |
} |
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 | |
@Function(name = "myAmazingFunction") | |
interface MyAmazingFunction | |
fun main() { | |
println("Hello World!") | |
} |