From c62f19ee8242efef572253456e214f65a2e1f304 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Thu, 9 Jul 2015 20:05:44 +0300 Subject: [PATCH] Move getterName/setterName to JvmAbi Reuse in RuntimeTypeMapper in reflection --- .../kotlin/codegen/PropertyCodegen.java | 12 ----- .../kotlin/codegen/state/JetTypeMapper.java | 15 +++--- .../kotlin/asJava/LightClassUtil.java | 3 +- .../jetbrains/kotlin/load/java/JvmAbi.java | 18 +++++-- .../reflect/jvm/internal/RuntimeTypeMapper.kt | 12 +---- .../kotlin/idea/search/usagesSearch/utils.kt | 24 ++++----- .../breakpoints/KotlinFieldBreakpoint.kt | 14 +++-- .../DelegatedPropertyFieldDescriptor.kt | 5 +- .../ConvertFunctionToPropertyIntention.kt | 4 +- .../ConvertPropertyToFunctionIntention.kt | 4 +- .../changeSignature/JetChangeInfo.kt | 8 ++- .../usages/JetFunctionCallUsage.java | 4 +- .../rename/RenameKotlinPropertyProcessor.kt | 53 +++++++++---------- 13 files changed, 82 insertions(+), 94 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/PropertyCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/PropertyCodegen.java index 94acfe9cb26..5454cff725c 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/PropertyCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/PropertyCodegen.java @@ -17,7 +17,6 @@ package org.jetbrains.kotlin.codegen; import com.intellij.openapi.util.Pair; -import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.PsiElement; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -26,7 +25,6 @@ import org.jetbrains.kotlin.codegen.state.GenerationState; import org.jetbrains.kotlin.codegen.state.JetTypeMapper; import org.jetbrains.kotlin.descriptors.*; import org.jetbrains.kotlin.load.java.JvmAbi; -import org.jetbrains.kotlin.name.Name; import org.jetbrains.kotlin.psi.*; import org.jetbrains.kotlin.psi.psiUtil.PsiUtilPackage; import org.jetbrains.kotlin.resolve.BindingContext; @@ -491,16 +489,6 @@ public class PropertyCodegen { } } - @NotNull - public static String getterName(Name propertyName) { - return JvmAbi.GETTER_PREFIX + StringUtil.capitalizeWithJavaBeanConvention(propertyName.asString()); - } - - @NotNull - public static String setterName(Name propertyName) { - return JvmAbi.SETTER_PREFIX + StringUtil.capitalizeWithJavaBeanConvention(propertyName.asString()); - } - public void genDelegate(@NotNull PropertyDescriptor delegate, @NotNull PropertyDescriptor delegateTo, @NotNull StackValue field) { ClassDescriptor toClass = (ClassDescriptor) delegateTo.getContainingDeclaration(); diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/JetTypeMapper.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/JetTypeMapper.java index 832e249f77c..db4519777cb 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/JetTypeMapper.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/JetTypeMapper.java @@ -38,7 +38,10 @@ import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor; import org.jetbrains.kotlin.load.kotlin.PackageClassUtils; import org.jetbrains.kotlin.load.kotlin.PackagePartClassUtils; import org.jetbrains.kotlin.load.kotlin.nativeDeclarations.NativeDeclarationsPackage; -import org.jetbrains.kotlin.name.*; +import org.jetbrains.kotlin.name.ClassId; +import org.jetbrains.kotlin.name.FqName; +import org.jetbrains.kotlin.name.FqNameUnsafe; +import org.jetbrains.kotlin.name.SpecialNames; import org.jetbrains.kotlin.platform.JavaToKotlinClassMap; import org.jetbrains.kotlin.psi.JetExpression; import org.jetbrains.kotlin.psi.JetFile; @@ -681,13 +684,13 @@ public class JetTypeMapper { } boolean isAccessor = property instanceof AccessorForPropertyDescriptor; - Name propertyName = isAccessor - ? Name.identifier(((AccessorForPropertyDescriptor) property).getIndexedAccessorSuffix()) - : property.getName(); + String propertyName = isAccessor + ? ((AccessorForPropertyDescriptor) property).getIndexedAccessorSuffix() + : property.getName().asString(); String accessorName = descriptor instanceof PropertyGetterDescriptor - ? PropertyCodegen.getterName(propertyName) - : PropertyCodegen.setterName(propertyName); + ? JvmAbi.getterName(propertyName) + : JvmAbi.setterName(propertyName); return isAccessor ? "access$" + accessorName : accessorName; } diff --git a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/LightClassUtil.java b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/LightClassUtil.java index e9951862f26..a20d1b07061 100644 --- a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/LightClassUtil.java +++ b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/LightClassUtil.java @@ -290,7 +290,8 @@ public class LightClassUtil { new Function1() { @Override public Boolean invoke(PsiMethod method) { - return JvmAbi.isAccessorName(method.getName()); + String name = method.getName(); + return name.startsWith(JvmAbi.GETTER_PREFIX) || name.startsWith(JvmAbi.SETTER_PREFIX); } } ); diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/JvmAbi.java b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/JvmAbi.java index a0f89706774..b0afee8d1dc 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/JvmAbi.java +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/JvmAbi.java @@ -16,6 +16,7 @@ package org.jetbrains.kotlin.load.java; +import kotlin.KotlinPackage; import org.jetbrains.annotations.NotNull; import org.jetbrains.kotlin.name.ClassId; import org.jetbrains.kotlin.name.FqName; @@ -55,10 +56,21 @@ public final class JvmAbi { return isDelegated ? propertyName.asString() + DELEGATED_PROPERTY_NAME_SUFFIX : propertyName.asString(); } - public static boolean isAccessorName(String name) { - return name.startsWith(GETTER_PREFIX) || name.startsWith(SETTER_PREFIX); + @NotNull + public static String getterName(@NotNull String propertyName) { + return GETTER_PREFIX + capitalizeWithJavaBeanConvention(propertyName); } - private JvmAbi() { + @NotNull + public static String setterName(@NotNull String propertyName) { + return SETTER_PREFIX + capitalizeWithJavaBeanConvention(propertyName); + } + + /** + * @see com.intellij.openapi.util.text.StringUtil#capitalizeWithJavaBeanConvention(String) + */ + @NotNull + private static String capitalizeWithJavaBeanConvention(@NotNull String s) { + return s.length() > 1 && Character.isUpperCase(s.charAt(1)) ? s : KotlinPackage.capitalize(s); } } diff --git a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/RuntimeTypeMapper.kt b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/RuntimeTypeMapper.kt index 934fd724c47..4a960067e1e 100644 --- a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/RuntimeTypeMapper.kt +++ b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/RuntimeTypeMapper.kt @@ -111,7 +111,7 @@ object RuntimeTypeMapper { val field = signature.getField() // TODO: some kind of test on the Java Bean convention? - return getterName(nameResolver.getString(field.getName())) + + return JvmAbi.getterName(nameResolver.getString(field.getName())) + "()" + deserializer.typeDescriptor(field.getType()) } @@ -120,7 +120,7 @@ object RuntimeTypeMapper { throw KotlinReflectionInternalError("Incorrect resolution sequence for Java field $property") return StringBuilder { - append(getterName(method.getName().asString())) + append(JvmAbi.getterName(method.getName().asString())) append("()") appendJavaType(method.getType()) }.toString() @@ -128,14 +128,6 @@ object RuntimeTypeMapper { else throw KotlinReflectionInternalError("Unknown origin of $property (${property.javaClass})") } - private fun getterName(propertyName: String): String { - return JvmAbi.GETTER_PREFIX + propertyName.capitalizeWithJavaBeanConvention() - } - - private fun String.capitalizeWithJavaBeanConvention(): String { - return if (length() > 1 && this[1].isUpperCase()) this else capitalize() - } - fun mapJvmClassToKotlinClassId(klass: Class<*>): ClassId { if (klass.isArray()) { klass.getComponentType().primitiveType?.let { diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/usagesSearch/utils.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/usagesSearch/utils.kt index 348c47b96f8..29d488b3c77 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/usagesSearch/utils.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/usagesSearch/utils.kt @@ -19,27 +19,27 @@ package org.jetbrains.kotlin.idea.search.usagesSearch import com.intellij.psi.PsiConstructorCall import com.intellij.psi.PsiElement import com.intellij.psi.PsiMethod -import org.jetbrains.kotlin.descriptors.* -import org.jetbrains.kotlin.psi.* -import org.jetbrains.kotlin.psi.psiUtil.* -import org.jetbrains.kotlin.resolve.BindingContext import com.intellij.psi.PsiReference import com.intellij.psi.search.SearchScope import org.jetbrains.kotlin.asJava.KotlinLightElement -import org.jetbrains.kotlin.resolve.DescriptorUtils -import org.jetbrains.kotlin.codegen.PropertyCodegen import org.jetbrains.kotlin.asJava.KotlinLightMethod import org.jetbrains.kotlin.asJava.KotlinNoOriginLightMethod import org.jetbrains.kotlin.asJava.unwrapped -import org.jetbrains.kotlin.resolve.OverrideResolver -import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils -import org.jetbrains.kotlin.idea.references.* -import org.jetbrains.kotlin.idea.findUsages.UsageTypeUtils -import org.jetbrains.kotlin.idea.findUsages.UsageTypeEnum +import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.idea.caches.resolve.analyze import org.jetbrains.kotlin.idea.caches.resolve.getJavaMethodDescriptor +import org.jetbrains.kotlin.idea.findUsages.UsageTypeEnum +import org.jetbrains.kotlin.idea.findUsages.UsageTypeUtils +import org.jetbrains.kotlin.idea.references.unwrappedTargets import org.jetbrains.kotlin.idea.search.declarationsSearch.HierarchySearchRequest import org.jetbrains.kotlin.idea.search.declarationsSearch.searchInheritors +import org.jetbrains.kotlin.load.java.JvmAbi +import org.jetbrains.kotlin.psi.* +import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType +import org.jetbrains.kotlin.resolve.BindingContext +import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils +import org.jetbrains.kotlin.resolve.DescriptorUtils +import org.jetbrains.kotlin.resolve.OverrideResolver val JetDeclaration.descriptor: DeclarationDescriptor? get() = this.analyze().get(BindingContext.DECLARATION_TO_DESCRIPTOR, this) @@ -221,7 +221,7 @@ fun PsiReference.isPropertyReadOnlyUsage(): Boolean { is JetProperty, is JetParameter -> origin as JetNamedDeclaration else -> null } - return declaration != null && refTarget.getName() == PropertyCodegen.getterName(declaration.getNameAsName()) + return declaration != null && refTarget.getName() == JvmAbi.getterName(declaration.getName()!!) } return false diff --git a/idea/src/org/jetbrains/kotlin/idea/debugger/breakpoints/KotlinFieldBreakpoint.kt b/idea/src/org/jetbrains/kotlin/idea/debugger/breakpoints/KotlinFieldBreakpoint.kt index d6ba2fde21d..a0e4bee5ec5 100644 --- a/idea/src/org/jetbrains/kotlin/idea/debugger/breakpoints/KotlinFieldBreakpoint.kt +++ b/idea/src/org/jetbrains/kotlin/idea/debugger/breakpoints/KotlinFieldBreakpoint.kt @@ -41,13 +41,12 @@ import com.sun.jdi.event.* import com.sun.jdi.request.EventRequest import com.sun.jdi.request.MethodEntryRequest import org.jetbrains.annotations.TestOnly -import org.jetbrains.kotlin.codegen.PropertyCodegen import org.jetbrains.kotlin.descriptors.PropertyDescriptor import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor import org.jetbrains.kotlin.idea.caches.resolve.analyzeAndGetResult import org.jetbrains.kotlin.idea.util.application.runReadAction +import org.jetbrains.kotlin.load.java.JvmAbi import org.jetbrains.kotlin.load.kotlin.PackageClassUtils -import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.psi.JetCallableDeclaration import org.jetbrains.kotlin.psi.JetClassOrObject import org.jetbrains.kotlin.psi.JetParameter @@ -165,17 +164,17 @@ class KotlinFieldBreakpoint( } } BreakpointType.METHOD -> { - val propertyName = Name.identifier(getFieldName()) + val fieldName = getFieldName() if (getProperties().WATCH_ACCESS) { - val getter = refType.methodsByName(PropertyCodegen.getterName(propertyName)).firstOrNull() + val getter = refType.methodsByName(JvmAbi.getterName(fieldName)).firstOrNull() if (getter != null) { createMethodBreakpoint(debugProcess, refType, getter) } } if (getProperties().WATCH_MODIFICATION) { - val setter = refType.methodsByName(PropertyCodegen.setterName(propertyName)).firstOrNull() + val setter = refType.methodsByName(JvmAbi.setterName(fieldName)).firstOrNull() if (setter != null) { createMethodBreakpoint(debugProcess, refType, setter) } @@ -255,9 +254,8 @@ class KotlinFieldBreakpoint( } private fun getMethodsName(): List { - val propertyName = Name.identifier(getFieldName()) - return arrayListOf(PropertyCodegen.getterName(propertyName), PropertyCodegen.setterName(propertyName)) - + val fieldName = getFieldName() + return listOf(JvmAbi.getterName(fieldName), JvmAbi.setterName(fieldName)) } override fun getEventMessage(event: LocatableEvent): String { diff --git a/idea/src/org/jetbrains/kotlin/idea/debugger/render/DelegatedPropertyFieldDescriptor.kt b/idea/src/org/jetbrains/kotlin/idea/debugger/render/DelegatedPropertyFieldDescriptor.kt index 2495757e664..3ce3d947600 100644 --- a/idea/src/org/jetbrains/kotlin/idea/debugger/render/DelegatedPropertyFieldDescriptor.kt +++ b/idea/src/org/jetbrains/kotlin/idea/debugger/render/DelegatedPropertyFieldDescriptor.kt @@ -27,7 +27,6 @@ import com.sun.jdi.Field import com.sun.jdi.Method import com.sun.jdi.ObjectReference import com.sun.jdi.Value -import org.jetbrains.kotlin.codegen.PropertyCodegen import org.jetbrains.kotlin.load.java.JvmAbi import org.jetbrains.kotlin.name.Name @@ -86,8 +85,6 @@ class DelegatedPropertyFieldDescriptor( val fieldName = getName() if (!Name.isValidIdentifier(fieldName)) return null - val getterName = PropertyCodegen.getterName(Name.identifier(fieldName)) - return getObject().referenceType().methodsByName(getterName)?.firstOrNull() + return getObject().referenceType().methodsByName(JvmAbi.getterName(fieldName))?.firstOrNull() } } - diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertFunctionToPropertyIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertFunctionToPropertyIntention.kt index cb0082e01ce..71ab68953cc 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertFunctionToPropertyIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertFunctionToPropertyIntention.kt @@ -25,7 +25,6 @@ import com.intellij.psi.* import com.intellij.util.containers.MultiMap import org.jetbrains.kotlin.asJava.namedUnwrappedElement import org.jetbrains.kotlin.builtins.KotlinBuiltIns -import org.jetbrains.kotlin.codegen.PropertyCodegen import org.jetbrains.kotlin.descriptors.CallableDescriptor import org.jetbrains.kotlin.descriptors.FunctionDescriptor import org.jetbrains.kotlin.idea.caches.resolve.analyze @@ -44,6 +43,7 @@ import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers import org.jetbrains.kotlin.idea.util.ShortenReferences import org.jetbrains.kotlin.idea.util.application.executeWriteCommand import org.jetbrains.kotlin.idea.util.supertypes +import org.jetbrains.kotlin.load.java.JvmAbi import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.getParentOfTypeAndBranch @@ -91,7 +91,7 @@ public class ConvertFunctionToPropertyIntention : JetSelfTargetingIntention) { val conflicts = MultiMap() - val getterName = PropertyCodegen.getterName(callableDescriptor.getName()) + val getterName = JvmAbi.getterName(callableDescriptor.getName().asString()) val callables = getAffectedCallables(project, descriptorsForChange) val kotlinCalls = ArrayList() val foreignRefs = ArrayList() diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertPropertyToFunctionIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertPropertyToFunctionIntention.kt index 6a10c55f324..c533ba50d4d 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertPropertyToFunctionIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertPropertyToFunctionIntention.kt @@ -24,7 +24,6 @@ import com.intellij.psi.* import com.intellij.refactoring.util.RefactoringUIUtil import com.intellij.util.containers.MultiMap import org.jetbrains.kotlin.asJava.namedUnwrappedElement -import org.jetbrains.kotlin.codegen.PropertyCodegen import org.jetbrains.kotlin.descriptors.CallableDescriptor import org.jetbrains.kotlin.idea.caches.resolve.analyze import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde @@ -39,6 +38,7 @@ import org.jetbrains.kotlin.idea.search.usagesSearch.DefaultSearchHelper import org.jetbrains.kotlin.idea.search.usagesSearch.UsagesSearchTarget import org.jetbrains.kotlin.idea.search.usagesSearch.search import org.jetbrains.kotlin.idea.util.application.executeWriteCommand +import org.jetbrains.kotlin.load.java.JvmAbi import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType import org.jetbrains.kotlin.psi.psiUtil.siblings @@ -80,7 +80,7 @@ public class ConvertPropertyToFunctionIntention : JetSelfTargetingIntention) { val propertyName = callableDescriptor.getName().asString() - val getterName = PropertyCodegen.getterName(callableDescriptor.getName()) + val getterName = JvmAbi.getterName(callableDescriptor.getName().asString()) val conflicts = MultiMap() val callables = getAffectedCallables(project, descriptorsForChange) val kotlinRefs = ArrayList() diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/JetChangeInfo.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/JetChangeInfo.kt index d0fd4378a7d..0f049551a01 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/JetChangeInfo.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/JetChangeInfo.kt @@ -28,7 +28,6 @@ import org.jetbrains.kotlin.asJava.getRepresentativeLightMethod import org.jetbrains.kotlin.asJava.toLightMethods import org.jetbrains.kotlin.asJava.unwrapped import org.jetbrains.kotlin.builtins.KotlinBuiltIns -import org.jetbrains.kotlin.codegen.PropertyCodegen import org.jetbrains.kotlin.descriptors.CallableDescriptor import org.jetbrains.kotlin.descriptors.Visibilities import org.jetbrains.kotlin.descriptors.Visibility @@ -42,7 +41,6 @@ import org.jetbrains.kotlin.idea.refactoring.changeSignature.usages.KotlinCaller import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers import org.jetbrains.kotlin.lexer.JetTokens import org.jetbrains.kotlin.load.java.JvmAbi -import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils import org.jetbrains.kotlin.types.JetType @@ -328,7 +326,7 @@ public class JetChangeInfo( ): JavaChangeInfo? { val newParameterList = receiverParameterInfo.singletonOrEmptyList() + getNonReceiverParameters() val newJavaParameters = getJavaParameterInfos(currentPsiMethod, newParameterList).toTypedArray() - val newName = if (isGetter) PropertyCodegen.getterName(Name.identifier(getNewName())) else getNewName() + val newName = if (isGetter) JvmAbi.getterName(getNewName()) else getNewName() return createJavaChangeInfo(originalPsiMethod, currentPsiMethod, newName, currentPsiMethod.getReturnType(), newJavaParameters) } @@ -344,7 +342,7 @@ public class JetChangeInfo( newJavaParameters.add(ParameterInfoImpl(oldIndex, "receiver", PsiType.VOID)) } - val newName = PropertyCodegen.setterName(Name.identifier(getNewName())) + val newName = JvmAbi.setterName(getNewName()) return createJavaChangeInfo(originalPsiMethod, currentPsiMethod, newName, PsiType.VOID, newJavaParameters.toTypedArray()) } @@ -434,4 +432,4 @@ public fun ChangeInfo.toJetChangeInfo(originalChangeSignatureDescriptor: JetMeth newParameters, null, method) -} \ No newline at end of file +} diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/usages/JetFunctionCallUsage.java b/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/usages/JetFunctionCallUsage.java index 7d24b78320a..dc53ba1645c 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/usages/JetFunctionCallUsage.java +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/usages/JetFunctionCallUsage.java @@ -149,8 +149,8 @@ public class JetFunctionCallUsage extends JetUsageInfo { String newName = changeInfo.getNewName(); if (isPropertyJavaUsage()) { String currentName = ((JetSimpleNameExpression) callee).getReferencedName(); - if (currentName.startsWith(JvmAbi.GETTER_PREFIX)) newName = PropertyCodegen.getterName(Name.identifier(newName)); - else if (currentName.startsWith(JvmAbi.SETTER_PREFIX)) newName = PropertyCodegen.setterName(Name.identifier(newName)); + if (currentName.startsWith(JvmAbi.GETTER_PREFIX)) newName = JvmAbi.getterName(newName); + else if (currentName.startsWith(JvmAbi.SETTER_PREFIX)) newName = JvmAbi.setterName(newName); } callee.replace(JetPsiFactory(getProject()).createSimpleName(newName)); diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/rename/RenameKotlinPropertyProcessor.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/rename/RenameKotlinPropertyProcessor.kt index 356272f33d3..dbbd26b2b1a 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/rename/RenameKotlinPropertyProcessor.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/rename/RenameKotlinPropertyProcessor.kt @@ -16,32 +16,32 @@ package org.jetbrains.kotlin.idea.refactoring.rename -import com.intellij.refactoring.rename.RenamePsiElementProcessor -import com.intellij.psi.PsiElement -import org.jetbrains.kotlin.psi.JetProperty -import com.intellij.psi.search.SearchScope import com.intellij.openapi.application.ApplicationManager -import org.jetbrains.kotlin.asJava.LightClassUtil -import com.intellij.psi.search.searches.OverridingMethodsSearch +import com.intellij.openapi.editor.Editor +import com.intellij.openapi.ui.Messages +import com.intellij.psi.PsiElement import com.intellij.psi.PsiMethod import com.intellij.psi.SyntheticElement -import com.intellij.refactoring.util.RefactoringUtil -import com.intellij.refactoring.rename.RenameProcessor -import org.jetbrains.kotlin.codegen.PropertyCodegen -import org.jetbrains.kotlin.name.Name -import com.intellij.usageView.UsageInfo +import com.intellij.psi.search.SearchScope +import com.intellij.psi.search.searches.OverridingMethodsSearch import com.intellij.refactoring.listeners.RefactoringElementListener -import com.intellij.openapi.editor.Editor -import org.jetbrains.kotlin.lexer.JetTokens -import org.jetbrains.kotlin.resolve.BindingContext -import org.jetbrains.kotlin.psi.JetClassOrObject -import com.intellij.openapi.ui.Messages -import org.jetbrains.kotlin.descriptors.PropertyDescriptor +import com.intellij.refactoring.rename.RenameProcessor +import com.intellij.refactoring.rename.RenamePsiElementProcessor +import com.intellij.refactoring.util.RefactoringUtil +import com.intellij.usageView.UsageInfo +import org.jetbrains.kotlin.asJava.LightClassUtil import org.jetbrains.kotlin.asJava.namedUnwrappedElement -import org.jetbrains.kotlin.resolve.OverrideResolver -import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils -import org.jetbrains.kotlin.idea.util.application.runReadAction +import org.jetbrains.kotlin.descriptors.PropertyDescriptor import org.jetbrains.kotlin.idea.caches.resolve.analyze +import org.jetbrains.kotlin.idea.util.application.runReadAction +import org.jetbrains.kotlin.lexer.JetTokens +import org.jetbrains.kotlin.load.java.JvmAbi +import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.psi.JetClassOrObject +import org.jetbrains.kotlin.psi.JetProperty +import org.jetbrains.kotlin.resolve.BindingContext +import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils +import org.jetbrains.kotlin.resolve.OverrideResolver public class RenameKotlinPropertyProcessor : RenamePsiElementProcessor() { override fun canProcessElement(element: PsiElement): Boolean = element.namedUnwrappedElement is JetProperty @@ -102,8 +102,9 @@ public class RenameKotlinPropertyProcessor : RenamePsiElementProcessor() { return } - val oldGetterName = PropertyCodegen.getterName(element.getNameAsName()) - val oldSetterName = PropertyCodegen.setterName(element.getNameAsName()) + val name = element.getName()!! + val oldGetterName = JvmAbi.getterName(name) + val oldSetterName = JvmAbi.setterName(name) val refKindUsages = usages.toList().groupBy { usage: UsageInfo -> val refElement = usage.getReference()?.resolve() @@ -119,11 +120,11 @@ public class RenameKotlinPropertyProcessor : RenamePsiElementProcessor() { } } - super.renameElement(element, PropertyCodegen.setterName(Name.identifier(newName!!)), + super.renameElement(element, JvmAbi.setterName(newName!!), refKindUsages[UsageKind.SETTER_USAGE]?.toTypedArray() ?: arrayOf(), null) - super.renameElement(element, PropertyCodegen.getterName(Name.identifier(newName)), + super.renameElement(element, JvmAbi.getterName(newName), refKindUsages[UsageKind.GETTER_USAGE]?.toTypedArray() ?: arrayOf(), null) @@ -151,9 +152,7 @@ public class RenameKotlinPropertyProcessor : RenamePsiElementProcessor() { if (overriderElement is PsiMethod) { if (newName != null && Name.isValidIdentifier(newName)) { val isGetter = overriderElement.getParameterList().getParametersCount() == 0 - val name = Name.identifier(newName) - - allRenames[overriderElement] = if (isGetter) PropertyCodegen.getterName(name) else PropertyCodegen.setterName(name) + allRenames[overriderElement] = if (isGetter) JvmAbi.getterName(newName) else JvmAbi.setterName(newName) } } else {