@@ -36,6 +36,7 @@ import java.io.OutputStreamWriter
3636 * - Mutable properties for UPDATE SET clauses
3737 * - Primary key metadata extraction from [@PrimaryKey][com.ctrip.sqllin.dsl.annotation.PrimaryKey]
3838 * and [@CompositePrimaryKey][com.ctrip.sqllin.dsl.annotation.CompositePrimaryKey] annotations
39+ * - Support for typealias of primitive types (resolves typealiases to their underlying types)
3940 *
4041 * The generated code provides compile-time safety for SQL DSL operations.
4142 *
@@ -164,7 +165,7 @@ class ClauseProcessor(
164165 }
165166 writer.write(nullableSymbol)
166167 writer.write(" get() = ${getSetClauseGetterValue(property)} \n " )
167- writer.write(" set(value) = ${appendFunction(elementName, property, isNotNull )} \n\n " )
168+ writer.write(" set(value) = ${appendFunction(elementName, property)} \n\n " )
168169 }
169170
170171 // Write the override instance for property `primaryKeyInfo`.
@@ -199,12 +200,27 @@ class ClauseProcessor(
199200
200201 /* *
201202 * Maps a property's Kotlin type to the corresponding clause element type name.
203+ * Supports typealiases by resolving them to their underlying types.
202204 *
203205 * @return The clause type name (ClauseNumber, ClauseString, ClauseBoolean, ClauseBlob), or null if unsupported
204206 */
205- private fun getClauseElementTypeStr (property : KSPropertyDeclaration ): String? = when (
206- property.typeName
207- ) {
207+ private fun getClauseElementTypeStr (property : KSPropertyDeclaration ): String? {
208+ val declaration = property.type.resolve().declaration
209+ return getClauseElementTypeStrByTypeName(declaration.typeName) ? : kotlin.run {
210+ if (declaration is KSTypeAlias )
211+ getClauseElementTypeStrByTypeName(declaration.typeName)
212+ else
213+ null
214+ }
215+ }
216+
217+ /* *
218+ * Maps a fully qualified type name to its corresponding clause element type.
219+ *
220+ * @param typeName The fully qualified type name to map
221+ * @return The clause type name (ClauseNumber, ClauseString, ClauseBoolean, ClauseBlob), or null if unsupported
222+ */
223+ private fun getClauseElementTypeStrByTypeName (typeName : String? ): String? = when (typeName) {
208224 Int ::class .qualifiedName,
209225 Long ::class .qualifiedName,
210226 Short ::class .qualifiedName,
@@ -228,12 +244,27 @@ class ClauseProcessor(
228244
229245 /* *
230246 * Generates the default getter value for SetClause properties based on type.
247+ * Supports typealiases by resolving them to their underlying types.
231248 *
232249 * @return The default value string for the property type, or null if unsupported
233250 */
234- private fun getSetClauseGetterValue (property : KSPropertyDeclaration ): String? = when (
235- property.typeName
236- ) {
251+ private fun getSetClauseGetterValue (property : KSPropertyDeclaration ): String? {
252+ val declaration = property.type.resolve().declaration
253+ return getDefaultValueByType(declaration.typeName) ? : kotlin.run {
254+ if (declaration is KSTypeAlias )
255+ getDefaultValueByType(declaration.typeName)
256+ else
257+ null
258+ }
259+ }
260+
261+ /* *
262+ * Returns the default value string for a given type name.
263+ *
264+ * @param typeName The fully qualified type name
265+ * @return The default value string (e.g., "0" for Int, "false" for Boolean), or null if unsupported
266+ */
267+ private fun getDefaultValueByType (typeName : String? ): String? = when (typeName) {
237268 Int ::class .qualifiedName -> " 0"
238269 Long ::class .qualifiedName -> " 0L"
239270 Short ::class .qualifiedName -> " 0"
@@ -256,13 +287,30 @@ class ClauseProcessor(
256287
257288 /* *
258289 * Generates the appropriate append function call for SetClause setters.
290+ * Supports typealiases by resolving them to their underlying types.
259291 *
260292 * @param elementName The serialized element name
261293 * @param property The property declaration
262- * @param isNotNull Whether the property is non-nullable
263294 * @return The append function call string, or null if unsupported type
264295 */
265- private fun appendFunction (elementName : String , property : KSPropertyDeclaration , isNotNull : Boolean ): String? = when (property.typeName) {
296+ private fun appendFunction (elementName : String , property : KSPropertyDeclaration ): String? {
297+ val declaration = property.type.resolve().declaration
298+ return appendFunctionByTypeName(elementName, declaration.typeName) ? : kotlin.run {
299+ if (declaration is KSTypeAlias )
300+ appendFunctionByTypeName(elementName, declaration.typeName)
301+ else
302+ null
303+ }
304+ }
305+
306+ /* *
307+ * Generates the append function call for a given type name.
308+ *
309+ * @param elementName The serialized element name
310+ * @param typeName The fully qualified type name
311+ * @return The append function call string, or null if unsupported type
312+ */
313+ private fun appendFunctionByTypeName (elementName : String , typeName : String? ): String? = when (typeName) {
266314 Int ::class .qualifiedName,
267315 Long ::class .qualifiedName,
268316 Short ::class .qualifiedName,
@@ -285,4 +333,16 @@ class ClauseProcessor(
285333 */
286334 private inline val KSPropertyDeclaration .typeName
287335 get() = type.resolve().declaration.qualifiedName?.asString()
336+
337+ /* *
338+ * Extension property that resolves a type alias to its underlying fully qualified type name.
339+ */
340+ private inline val KSTypeAlias .typeName
341+ get() = type.resolve().declaration.qualifiedName?.asString()
342+
343+ /* *
344+ * Extension property that retrieves a declaration's fully qualified type name.
345+ */
346+ private inline val KSDeclaration .typeName
347+ get() = qualifiedName?.asString()
288348}
0 commit comments