Introduce COMPONENT_FUNCTION_NAME_PREFIX constant

This commit is contained in:
Ivan Kochurkin
2022-05-26 01:38:10 +03:00
committed by teamcity
parent 600b0d7b81
commit b573532d8c
3 changed files with 8 additions and 6 deletions
@@ -5,20 +5,19 @@
package org.jetbrains.kotlin.resolve
import org.jetbrains.kotlin.builtins.StandardNames.DATA_CLASS_COMPONENT_PREFIX
import org.jetbrains.kotlin.builtins.StandardNames.DATA_CLASS_COPY
import org.jetbrains.kotlin.name.Name
object DataClassResolver {
private const val COMPONENT_FUNCTION_NAME_PREFIX = "component"
fun createComponentName(index: Int): Name = Name.identifier(DATA_CLASS_COMPONENT_PREFIX + index)
fun createComponentName(index: Int): Name = Name.identifier(COMPONENT_FUNCTION_NAME_PREFIX + index)
fun getComponentIndex(componentName: String): Int = componentName.substring(COMPONENT_FUNCTION_NAME_PREFIX.length).toInt()
fun getComponentIndex(componentName: String): Int = componentName.substring(DATA_CLASS_COMPONENT_PREFIX.length).toInt()
fun isComponentLike(name: Name): Boolean = isComponentLike(name.asString())
private fun isComponentLike(name: String): Boolean {
if (!name.startsWith(COMPONENT_FUNCTION_NAME_PREFIX)) return false
if (!name.startsWith(DATA_CLASS_COMPONENT_PREFIX)) return false
try {
getComponentIndex(name)