diff --git a/compiler/frontend/src/org/jetbrains/kotlin/analyzer/KotlinModificationTrackerService.kt b/compiler/frontend.common-psi/src/org/jetbrains/kotlin/analyzer/KotlinModificationTrackerService.kt similarity index 94% rename from compiler/frontend/src/org/jetbrains/kotlin/analyzer/KotlinModificationTrackerService.kt rename to compiler/frontend.common-psi/src/org/jetbrains/kotlin/analyzer/KotlinModificationTrackerService.kt index addb44bb014..80d625d2599 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/analyzer/KotlinModificationTrackerService.kt +++ b/compiler/frontend.common-psi/src/org/jetbrains/kotlin/analyzer/KotlinModificationTrackerService.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ diff --git a/compiler/frontend.common/src/org/jetbrains/kotlin/resolve/DataClassResolver.kt b/compiler/frontend.common/src/org/jetbrains/kotlin/resolve/DataClassResolver.kt new file mode 100644 index 00000000000..42124ec75e9 --- /dev/null +++ b/compiler/frontend.common/src/org/jetbrains/kotlin/resolve/DataClassResolver.kt @@ -0,0 +1,30 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.resolve + +import org.jetbrains.kotlin.name.Name + +object DataClassResolver { + private const val COMPONENT_FUNCTION_NAME_PREFIX = "component" + + 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 isComponentLike(name: Name): Boolean = isComponentLike(name.asString()) + + private fun isComponentLike(name: String): Boolean { + if (!name.startsWith(COMPONENT_FUNCTION_NAME_PREFIX)) return false + + try { + getComponentIndex(name) + } catch (e: NumberFormatException) { + return false + } + + return true + } +} \ No newline at end of file diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/JavaSyntheticPropertiesScope.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/JavaSyntheticPropertiesScope.kt index 2b3306695dc..2cfee30c56a 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/JavaSyntheticPropertiesScope.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/JavaSyntheticPropertiesScope.kt @@ -75,11 +75,8 @@ interface SyntheticJavaPropertyDescriptor : PropertyDescriptor, SyntheticPropert .firstOrNull { originalGetterOrSetter == it.getMethod || originalGetterOrSetter == it.setMethod } } - fun propertyNamesByAccessorName(name: Name): List = listOfNotNull( - propertyNameByGetMethodName(name), - propertyNameBySetMethodName(name, withIsPrefix = true), - propertyNameBySetMethodName(name, withIsPrefix = false) - ) + fun propertyNamesByAccessorName(name: Name): List = + org.jetbrains.kotlin.load.java.propertyNamesByAccessorName(name) fun findByGetterOrSetter(getterOrSetter: FunctionDescriptor, syntheticScope: SyntheticScope) = findByGetterOrSetter(getterOrSetter, diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DataClassDescriptorResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DataClassDescriptorResolver.kt index 4d9ef4eb4ce..59950ce2f48 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DataClassDescriptorResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DataClassDescriptorResolver.kt @@ -28,25 +28,11 @@ import org.jetbrains.kotlin.util.OperatorNameConventions object DataClassDescriptorResolver { val COPY_METHOD_NAME = Name.identifier("copy") - private val COMPONENT_FUNCTION_NAME_PREFIX = "component" + fun createComponentName(index: Int): Name = DataClassResolver.createComponentName(index) - fun createComponentName(index: Int): Name = Name.identifier(COMPONENT_FUNCTION_NAME_PREFIX + index) + fun getComponentIndex(componentName: String): Int = DataClassResolver.getComponentIndex(componentName) - fun getComponentIndex(componentName: String): Int = componentName.substring(COMPONENT_FUNCTION_NAME_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 - - try { - getComponentIndex(name) - } catch (e: NumberFormatException) { - return false - } - - return true - } + fun isComponentLike(name: Name): Boolean = DataClassResolver.isComponentLike(name) fun createComponentFunctionDescriptor( parameterIndex: Int, diff --git a/core/compiler.common.jvm/src/org/jetbrains/kotlin/load/java/propertiesConventionUtil.kt b/core/compiler.common.jvm/src/org/jetbrains/kotlin/load/java/propertiesConventionUtil.kt index 1687c435787..dcbf0251d77 100644 --- a/core/compiler.common.jvm/src/org/jetbrains/kotlin/load/java/propertiesConventionUtil.kt +++ b/core/compiler.common.jvm/src/org/jetbrains/kotlin/load/java/propertiesConventionUtil.kt @@ -18,6 +18,12 @@ fun propertyNameBySetMethodName(methodName: Name, withIsPrefix: Boolean): Name? fun propertyNamesBySetMethodName(methodName: Name): List = listOfNotNull(propertyNameBySetMethodName(methodName, false), propertyNameBySetMethodName(methodName, true)) +fun propertyNamesByAccessorName(name: Name): List = listOfNotNull( + propertyNameByGetMethodName(name), + propertyNameBySetMethodName(name, withIsPrefix = true), + propertyNameBySetMethodName(name, withIsPrefix = false) +) + private fun propertyNameFromAccessorMethodName( methodName: Name, prefix: String,