Reflection commands, fix genref
This commit is contained in:
1 parent
cc6f64c3b7
commit
51ae06d7cd
270 files changed
+3319
-134
No files matched your search
@@ -3,7 +3,7 @@ plugins {
|
||||
kotlin("jvm")
|
||||
id("maven-publish")
|
||||
id("signing")
|
||||
id("com.google.devtools.ksp") version "1.8.21-1.0.11"
|
||||
id("com.google.devtools.ksp") version "1.9.0-1.0.11"
|
||||
}
|
||||
|
||||
group = "tech.carcadex"
|
||||
@@ -21,7 +21,7 @@ repositories {
|
||||
dependencies {
|
||||
implementation("org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT")
|
||||
implementation(project(":architecture"))
|
||||
implementation("com.google.devtools.ksp:symbol-processing-api:1.8.21-1.0.11")
|
||||
implementation("com.google.devtools.ksp:symbol-processing-api:1.9.0-1.0.11")
|
||||
implementation("com.squareup:kotlinpoet:1.10.1")
|
||||
implementation("com.squareup:kotlinpoet-ksp:1.10.1")
|
||||
|
||||
|
||||
+12
-7
@@ -5,6 +5,7 @@ import com.google.devtools.ksp.getAnnotationsByType
|
||||
import com.google.devtools.ksp.processing.CodeGenerator
|
||||
import com.google.devtools.ksp.processing.Dependencies
|
||||
import com.google.devtools.ksp.processing.KSPLogger
|
||||
import com.google.devtools.ksp.processing.Resolver
|
||||
import com.google.devtools.ksp.symbol.KSFile
|
||||
import com.google.devtools.ksp.symbol.KSFunctionDeclaration
|
||||
import com.google.devtools.ksp.symbol.KSVisitorVoid
|
||||
@@ -14,13 +15,19 @@ import com.squareup.kotlinpoet.ksp.writeTo
|
||||
import tech.carcadex.kotlinbukkitkit.genref.plugin.annotations.OnDisable
|
||||
import tech.carcadex.kotlinbukkitkit.genref.plugin.annotations.Plugin
|
||||
import tech.carcadex.kotlinbukkitkit.architecture.KotlinPlugin
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.Paths
|
||||
import kotlin.io.path.deleteIfExists
|
||||
import kotlin.io.path.exists
|
||||
|
||||
var writed = false
|
||||
@OptIn(KotlinPoetKspPreview::class)
|
||||
class PluginVisitor(private val codeGenerator: CodeGenerator,
|
||||
private val logger: KSPLogger
|
||||
private val logger: KSPLogger,
|
||||
private val resolver: Resolver
|
||||
) : KSVisitorVoid() {
|
||||
|
||||
var funcs: MutableList<FunSpec> = mutableListOf()
|
||||
private var funcs: MutableList<FunSpec> = mutableListOf()
|
||||
|
||||
override fun visitFile(file: KSFile, data: Unit) {
|
||||
file.declarations.filter { it is KSFunctionDeclaration }.forEach { it.accept(this, Unit) }
|
||||
@@ -56,8 +63,9 @@ class PluginVisitor(private val codeGenerator: CodeGenerator,
|
||||
)
|
||||
}.build()
|
||||
|
||||
//todo try catch?
|
||||
fileSpec.writeTo(codeGenerator, Dependencies(false))
|
||||
if(writed) return
|
||||
fileSpec.writeTo(codeGenerator, Dependencies(false, *resolver.getAllFiles().toList().toTypedArray()))
|
||||
writed = true
|
||||
}
|
||||
|
||||
@OptIn(KspExperimental::class)
|
||||
@@ -65,9 +73,6 @@ class PluginVisitor(private val codeGenerator: CodeGenerator,
|
||||
if (function.getAnnotationsByType(OnDisable::class).any()) disable(function)
|
||||
|
||||
if(function.getAnnotationsByType(Plugin::class).any()) enable(function)
|
||||
|
||||
|
||||
function.returnType!!.accept(this, Unit)
|
||||
}
|
||||
|
||||
fun disable(function: KSFunctionDeclaration) {
|
||||
|
||||
+11
-7
@@ -14,16 +14,20 @@ import tech.carcadex.kotlinbukkitkit.genref.plugin.annotations.Plugin
|
||||
|
||||
class GenRefProcessor(private val codeGenerator: CodeGenerator,
|
||||
private val logger: KSPLogger) : SymbolProcessor {
|
||||
// private var invoked = false
|
||||
|
||||
@OptIn(KspExperimental::class)
|
||||
override fun process(resolver: Resolver): List<KSAnnotated> {
|
||||
val files = resolver.getAllFiles().filter { it.declarations.any { it is KSFunctionDeclaration && it.validate()
|
||||
&& it.isAnnotationPresent(Plugin::class)} }
|
||||
// if(invoked) return emptyList()
|
||||
val visitor = PluginVisitor(codeGenerator, logger, resolver)
|
||||
resolver.getAllFiles()
|
||||
.filter { it.validate() }
|
||||
.filter {
|
||||
it.declarations.any { it is KSFunctionDeclaration && it.validate() && it.isAnnotationPresent(Plugin::class) }
|
||||
}.firstOrNull()?.accept(visitor, Unit)
|
||||
|
||||
files.let { files -> files.forEach {
|
||||
it.accept(PluginVisitor(codeGenerator, logger), Unit)
|
||||
}
|
||||
}
|
||||
return files.filter { it.validate() }.toList()
|
||||
// invoked = true
|
||||
return emptyList()
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user