Skip to content

Commit

Permalink
hotfix due to deprecated annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
InsanusMokrassar committed Oct 19, 2024
1 parent ee2521c commit c5dbd10
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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())
6 changes: 3 additions & 3 deletions ksp/sealed/generator/src/main/kotlin/Processor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -112,7 +112,7 @@ class Processor(
@OptIn(KspExperimental::class)
override fun process(resolver: Resolver): List<KSAnnotated> {
(resolver.getSymbolsWithAnnotation(GenerateSealedWorkaround::class.qualifiedName!!)).filterIsInstance<KSClassDeclaration>().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") {
Expand Down

0 comments on commit c5dbd10

Please sign in to comment.