Skip to content

Commit

Permalink
generate refs class
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentlauvlwj committed Jul 16, 2023
1 parent c2968e8 commit a783546
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ public class KtormProcessorProvider : SymbolProcessorProvider {
.replace(Regex(""",\s*"""), ", ")
.replace(Regex(""",\s*\)"""), ")")
.replace(Regex("""\s*get\(\)\s="""), " get() =")
.replace(Regex("""\s+=\s+"""), " = ")
.replace("import org.ktorm.ksp.`annotation`", "import org.ktorm.ksp.annotation")

return ktLintRuleEngine.format(code)
} catch (e: Exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.ktorm.ksp.compiler.generator

import com.squareup.kotlinpoet.*
import org.ktorm.ksp.spi.TableMetadata
import org.ktorm.schema.Table

/**
* Created by vince at Jul 15, 2023.
Expand All @@ -27,6 +28,17 @@ internal object RefsClassGenerator {
typeSpec.addProperty(propertySpec)
}

val funSpec = FunSpec.builder("toList")
.addKdoc("Return all referenced tables as a list.")
.returns(typeNameOf<List<Table<*>>>())
.addCode("return·listOf(")

for (column in table.columns) {
val refTablePropertyName = column.refTablePropertyName ?: continue
funSpec.addCode("%N, ", refTablePropertyName)
}

typeSpec.addFunction(funSpec.addCode(")").build())
return typeSpec.build()
}
}

0 comments on commit a783546

Please sign in to comment.