diff --git a/ktorm-ksp-compiler/src/main/kotlin/org/ktorm/ksp/compiler/parser/MetadataParser.kt b/ktorm-ksp-compiler/src/main/kotlin/org/ktorm/ksp/compiler/parser/MetadataParser.kt index 920a2585..68fc353d 100644 --- a/ktorm-ksp-compiler/src/main/kotlin/org/ktorm/ksp/compiler/parser/MetadataParser.kt +++ b/ktorm-ksp-compiler/src/main/kotlin/org/ktorm/ksp/compiler/parser/MetadataParser.kt @@ -73,22 +73,25 @@ internal class MetadataParser(resolver: Resolver, environment: SymbolProcessorEn } fun parseTableMetadata(cls: KSClassDeclaration): TableMetadata { - val r = _tablesCache[cls.qualifiedName!!.asString()] + val className = cls.qualifiedName!!.asString() + val r = _tablesCache[className] if (r != null) { return r } if (cls.classKind != CLASS && cls.classKind != INTERFACE) { - val name = cls.qualifiedName!!.asString() - throw IllegalStateException("$name is expected to be a class or interface but actually ${cls.classKind}.") + throw IllegalStateException("$className should be a class or interface but actually ${cls.classKind}.") } if (cls.classKind == INTERFACE && !cls.isSubclassOf>()) { - val name = cls.qualifiedName!!.asString() - throw IllegalStateException("$name must extend from org.ktorm.entity.Entity.") + throw IllegalStateException("$className must extend from org.ktorm.entity.Entity.") } - _logger.info("[ktorm-ksp-compiler] parse table metadata from entity: ${cls.qualifiedName!!.asString()}") + if (cls.classKind == CLASS && cls.isAbstract()) { + throw IllegalStateException("$className cannot be an abstract class.") + } + + _logger.info("[ktorm-ksp-compiler] parse table metadata from entity: $className") val table = cls.getAnnotationsByType(Table::class).first() val tableDef = TableMetadata( entityClass = cls, @@ -111,7 +114,7 @@ internal class MetadataParser(resolver: Resolver, environment: SymbolProcessorEn } } - _tablesCache[cls.qualifiedName!!.asString()] = tableDef + _tablesCache[className] = tableDef return tableDef } diff --git a/ktorm-ksp-compiler/src/test/kotlin/org/ktorm/ksp/compiler/parser/MetadataParserTest.kt b/ktorm-ksp-compiler/src/test/kotlin/org/ktorm/ksp/compiler/parser/MetadataParserTest.kt index 0f7c1e43..f57891cb 100644 --- a/ktorm-ksp-compiler/src/test/kotlin/org/ktorm/ksp/compiler/parser/MetadataParserTest.kt +++ b/ktorm-ksp-compiler/src/test/kotlin/org/ktorm/ksp/compiler/parser/MetadataParserTest.kt @@ -9,7 +9,7 @@ import org.ktorm.ksp.compiler.BaseKspTest class MetadataParserTest : BaseKspTest() { @Test - fun testEnumClass() = kspFailing("Gender is expected to be a class or interface but actually ENUM_CLASS.", """ + fun testEnumClass() = kspFailing("Gender should be a class or interface but actually ENUM_CLASS.", """ @Table enum class Gender { MALE, FEMALE } """.trimIndent()) @@ -23,6 +23,15 @@ class MetadataParserTest : BaseKspTest() { } """.trimIndent()) + @Test + fun testAbstractClass() = kspFailing("User cannot be an abstract class.", """ + @Table + abstract class User { + var id: Int = 0 + var name: String = "" + } + """.trimIndent()) + @Test fun testClassIgnoreProperties() = runKotlin(""" @Table(ignoreProperties = ["name"])