-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(render): separate property and class introspector
- Loading branch information
Showing
10 changed files
with
152 additions
and
197 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
...rc/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/introspector/JpqlEntityIntrospector.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.linecorp.kotlinjdsl.render.jpql.introspector | ||
|
||
import com.linecorp.kotlinjdsl.SinceJdsl | ||
import kotlin.reflect.KCallable | ||
|
||
/** | ||
* Abstract class to get the entity information by introspecting KClass. | ||
*/ | ||
@SinceJdsl("3.1.0") | ||
abstract class JpqlEntityIntrospector : JpqlIntrospector { | ||
override fun introspect(property: KCallable<*>): JpqlPropertyDescription? = null | ||
} |
12 changes: 12 additions & 0 deletions
12
.../main/kotlin/com/linecorp/kotlinjdsl/render/jpql/introspector/JpqlPropertyIntrospector.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.linecorp.kotlinjdsl.render.jpql.introspector | ||
|
||
import com.linecorp.kotlinjdsl.SinceJdsl | ||
import kotlin.reflect.KClass | ||
|
||
/** | ||
* Abstract class to get the entity information by introspecting KCallable. | ||
*/ | ||
@SinceJdsl("3.1.0") | ||
abstract class JpqlPropertyIntrospector : JpqlIntrospector { | ||
override fun introspect(type: KClass<*>): JpqlEntityDescription? = null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 0 additions & 7 deletions
7
...pql/src/main/kotlin/com/linecorp/kotlinjdsl/render/jpql/introspector/impl/JpqlProperty.kt
This file was deleted.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
.../linecorp/kotlinjdsl/render/jpql/introspector/impl/KotlinStyleJpqlPropertyIntrospector.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.linecorp.kotlinjdsl.render.jpql.introspector.impl | ||
|
||
import com.linecorp.kotlinjdsl.Internal | ||
import com.linecorp.kotlinjdsl.render.jpql.introspector.JpqlPropertyDescription | ||
import com.linecorp.kotlinjdsl.render.jpql.introspector.JpqlPropertyIntrospector | ||
import kotlin.reflect.KCallable | ||
import kotlin.reflect.KFunction1 | ||
import kotlin.reflect.KProperty1 | ||
|
||
/** | ||
* Introspector that introspects a property name in KCallable using Kotlin style. | ||
*/ | ||
@Internal | ||
class KotlinStyleJpqlPropertyIntrospector : JpqlPropertyIntrospector() { | ||
override fun introspect(property: KCallable<*>): JpqlPropertyDescription? { | ||
return when (property) { | ||
is KProperty1<*, *> -> KotlinStyleProperty(property.name) | ||
is KFunction1<*, *> -> KotlinStyleProperty(resolvePropertyName(property)) | ||
else -> null | ||
} | ||
} | ||
|
||
private fun resolvePropertyName(getter: KFunction1<*, *>): String = | ||
if (getter.name.startsWith("is")) { | ||
getter.name | ||
} else { | ||
getter.name.removePrefix("get").replaceFirstChar { it.lowercase() } | ||
} | ||
} | ||
|
||
private data class KotlinStyleProperty( | ||
override val name: String, | ||
) : JpqlPropertyDescription |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.