From c5dbd103355601c5eaf80fbc312f70d3edda2c5b Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 19 Oct 2024 15:39:00 +0600 Subject: [PATCH] hotfix due to deprecated annotation --- ...eclarationGetGenerateSealedWorkaroundAnnotation.kt | 11 +++++++++++ ksp/sealed/generator/src/main/kotlin/Processor.kt | 6 +++--- 2 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 ksp/sealed/generator/src/main/kotlin/KSClassDeclarationGetGenerateSealedWorkaroundAnnotation.kt diff --git a/ksp/sealed/generator/src/main/kotlin/KSClassDeclarationGetGenerateSealedWorkaroundAnnotation.kt b/ksp/sealed/generator/src/main/kotlin/KSClassDeclarationGetGenerateSealedWorkaroundAnnotation.kt new file mode 100644 index 00000000000..aab653b1349 --- /dev/null +++ b/ksp/sealed/generator/src/main/kotlin/KSClassDeclarationGetGenerateSealedWorkaroundAnnotation.kt @@ -0,0 +1,11 @@ +package dev.inmo.micro_utils.ksp.sealed.generator + +import com.google.devtools.ksp.KspExperimental +import com.google.devtools.ksp.getAnnotationsByType +import com.google.devtools.ksp.symbol.KSClassDeclaration +import dev.inmo.micro_utils.ksp.sealed.GenerateSealedWorkaround +import dev.inmo.microutils.kps.sealed.GenerateSealedWorkaround as OldGenerateSealedWorkaround + +@OptIn(KspExperimental::class) +val KSClassDeclaration.getGenerateSealedWorkaroundAnnotation + get() = (getAnnotationsByType(GenerateSealedWorkaround::class).firstOrNull() ?: getAnnotationsByType(OldGenerateSealedWorkaround::class).firstOrNull()) diff --git a/ksp/sealed/generator/src/main/kotlin/Processor.kt b/ksp/sealed/generator/src/main/kotlin/Processor.kt index bf716e02840..d2c7e1f522e 100644 --- a/ksp/sealed/generator/src/main/kotlin/Processor.kt +++ b/ksp/sealed/generator/src/main/kotlin/Processor.kt @@ -53,10 +53,10 @@ class Processor( ksClassDeclaration: KSClassDeclaration, resolver: Resolver ) { - val annotation = ksClassDeclaration.getAnnotationsByType(GenerateSealedWorkaround::class).first() + val annotation = ksClassDeclaration.getGenerateSealedWorkaroundAnnotation val subClasses = ksClassDeclaration.resolveSubclasses( searchIn = resolver.getAllFiles(), - allowNonSealed = annotation.includeNonSealedSubTypes + allowNonSealed = annotation ?.includeNonSealedSubTypes ?: false ).distinct() val subClassesNames = subClasses.filter { when (it.classKind) { @@ -112,7 +112,7 @@ class Processor( @OptIn(KspExperimental::class) override fun process(resolver: Resolver): List { (resolver.getSymbolsWithAnnotation(GenerateSealedWorkaround::class.qualifiedName!!)).filterIsInstance().forEach { - val prefix = it.getAnnotationsByType(GenerateSealedWorkaround::class).first().prefix.takeIf { + val prefix = (it.getGenerateSealedWorkaroundAnnotation) ?.prefix ?.takeIf { it.isNotEmpty() } ?: it.buildSubFileName.replaceFirst(it.simpleName.asString(), "") it.writeFile(prefix = prefix, suffix = "SealedWorkaround") {