diff --git a/ksp/sealed/generator/src/main/kotlin/Processor.kt b/ksp/sealed/generator/src/main/kotlin/Processor.kt index f46ae51775e..95a2d2cf236 100644 --- a/ksp/sealed/generator/src/main/kotlin/Processor.kt +++ b/ksp/sealed/generator/src/main/kotlin/Processor.kt @@ -53,7 +53,7 @@ class Processor( val annotation = ksClassDeclaration.getGenerateSealedWorkaroundAnnotation val subClasses = ksClassDeclaration.resolveSubclasses( searchIn = resolver.getAllFiles(), - allowNonSealed = annotation ?.includeNonSealedSubTypes ?: false + allowNonSealed = withNoSuchElementWorkaround(null) { annotation ?.includeNonSealedSubTypes } ?: false ).distinct() val subClassesNames = subClasses.filter { when (it.classKind) { @@ -165,15 +165,7 @@ class Processor( @OptIn(KspExperimental::class) override fun process(resolver: Resolver): List { (resolver.getSymbolsWithAnnotation(GenerateSealedWorkaround::class.qualifiedName!!)).filterIsInstance().forEach { - val prefix = runCatching { - (it.getGenerateSealedWorkaroundAnnotation) ?.prefix - }.getOrElse { - if (it is NoSuchElementException) { - "" - } else { - throw it - } - } ?.takeIf { + val prefix = withNoSuchElementWorkaround(null) { (it.getGenerateSealedWorkaroundAnnotation) ?.prefix } ?.takeIf { it.isNotEmpty() } ?: it.buildSubFileName.replaceFirst(it.simpleName.asString(), "") it.writeFile(prefix = prefix, suffix = "SealedWorkaround") {