Move getterName/setterName to JvmAbi

Reuse in RuntimeTypeMapper in reflection
This commit is contained in:
Alexander Udalov
2015-07-09 20:05:44 +03:00
parent 64d8e35d26
commit c62f19ee82
13 changed files with 82 additions and 94 deletions
@@ -17,7 +17,6 @@
package org.jetbrains.kotlin.codegen; package org.jetbrains.kotlin.codegen;
import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiElement; import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; 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.codegen.state.JetTypeMapper;
import org.jetbrains.kotlin.descriptors.*; import org.jetbrains.kotlin.descriptors.*;
import org.jetbrains.kotlin.load.java.JvmAbi; import org.jetbrains.kotlin.load.java.JvmAbi;
import org.jetbrains.kotlin.name.Name;
import org.jetbrains.kotlin.psi.*; import org.jetbrains.kotlin.psi.*;
import org.jetbrains.kotlin.psi.psiUtil.PsiUtilPackage; import org.jetbrains.kotlin.psi.psiUtil.PsiUtilPackage;
import org.jetbrains.kotlin.resolve.BindingContext; 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) { public void genDelegate(@NotNull PropertyDescriptor delegate, @NotNull PropertyDescriptor delegateTo, @NotNull StackValue field) {
ClassDescriptor toClass = (ClassDescriptor) delegateTo.getContainingDeclaration(); ClassDescriptor toClass = (ClassDescriptor) delegateTo.getContainingDeclaration();
@@ -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.PackageClassUtils;
import org.jetbrains.kotlin.load.kotlin.PackagePartClassUtils; import org.jetbrains.kotlin.load.kotlin.PackagePartClassUtils;
import org.jetbrains.kotlin.load.kotlin.nativeDeclarations.NativeDeclarationsPackage; 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.platform.JavaToKotlinClassMap;
import org.jetbrains.kotlin.psi.JetExpression; import org.jetbrains.kotlin.psi.JetExpression;
import org.jetbrains.kotlin.psi.JetFile; import org.jetbrains.kotlin.psi.JetFile;
@@ -681,13 +684,13 @@ public class JetTypeMapper {
} }
boolean isAccessor = property instanceof AccessorForPropertyDescriptor; boolean isAccessor = property instanceof AccessorForPropertyDescriptor;
Name propertyName = isAccessor String propertyName = isAccessor
? Name.identifier(((AccessorForPropertyDescriptor) property).getIndexedAccessorSuffix()) ? ((AccessorForPropertyDescriptor) property).getIndexedAccessorSuffix()
: property.getName(); : property.getName().asString();
String accessorName = descriptor instanceof PropertyGetterDescriptor String accessorName = descriptor instanceof PropertyGetterDescriptor
? PropertyCodegen.getterName(propertyName) ? JvmAbi.getterName(propertyName)
: PropertyCodegen.setterName(propertyName); : JvmAbi.setterName(propertyName);
return isAccessor ? "access$" + accessorName : accessorName; return isAccessor ? "access$" + accessorName : accessorName;
} }
@@ -290,7 +290,8 @@ public class LightClassUtil {
new Function1<PsiMethod, Boolean>() { new Function1<PsiMethod, Boolean>() {
@Override @Override
public Boolean invoke(PsiMethod method) { 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);
} }
} }
); );
@@ -16,6 +16,7 @@
package org.jetbrains.kotlin.load.java; package org.jetbrains.kotlin.load.java;
import kotlin.KotlinPackage;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.name.ClassId; import org.jetbrains.kotlin.name.ClassId;
import org.jetbrains.kotlin.name.FqName; import org.jetbrains.kotlin.name.FqName;
@@ -55,10 +56,21 @@ public final class JvmAbi {
return isDelegated ? propertyName.asString() + DELEGATED_PROPERTY_NAME_SUFFIX : propertyName.asString(); return isDelegated ? propertyName.asString() + DELEGATED_PROPERTY_NAME_SUFFIX : propertyName.asString();
} }
public static boolean isAccessorName(String name) { @NotNull
return name.startsWith(GETTER_PREFIX) || name.startsWith(SETTER_PREFIX); 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);
} }
} }
@@ -111,7 +111,7 @@ object RuntimeTypeMapper {
val field = signature.getField() val field = signature.getField()
// TODO: some kind of test on the Java Bean convention? // 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()) deserializer.typeDescriptor(field.getType())
} }
@@ -120,7 +120,7 @@ object RuntimeTypeMapper {
throw KotlinReflectionInternalError("Incorrect resolution sequence for Java field $property") throw KotlinReflectionInternalError("Incorrect resolution sequence for Java field $property")
return StringBuilder { return StringBuilder {
append(getterName(method.getName().asString())) append(JvmAbi.getterName(method.getName().asString()))
append("()") append("()")
appendJavaType(method.getType()) appendJavaType(method.getType())
}.toString() }.toString()
@@ -128,14 +128,6 @@ object RuntimeTypeMapper {
else throw KotlinReflectionInternalError("Unknown origin of $property (${property.javaClass})") 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 { fun mapJvmClassToKotlinClassId(klass: Class<*>): ClassId {
if (klass.isArray()) { if (klass.isArray()) {
klass.getComponentType().primitiveType?.let { klass.getComponentType().primitiveType?.let {
@@ -19,27 +19,27 @@ package org.jetbrains.kotlin.idea.search.usagesSearch
import com.intellij.psi.PsiConstructorCall import com.intellij.psi.PsiConstructorCall
import com.intellij.psi.PsiElement import com.intellij.psi.PsiElement
import com.intellij.psi.PsiMethod 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.PsiReference
import com.intellij.psi.search.SearchScope import com.intellij.psi.search.SearchScope
import org.jetbrains.kotlin.asJava.KotlinLightElement 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.KotlinLightMethod
import org.jetbrains.kotlin.asJava.KotlinNoOriginLightMethod import org.jetbrains.kotlin.asJava.KotlinNoOriginLightMethod
import org.jetbrains.kotlin.asJava.unwrapped import org.jetbrains.kotlin.asJava.unwrapped
import org.jetbrains.kotlin.resolve.OverrideResolver import org.jetbrains.kotlin.descriptors.*
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.idea.caches.resolve.analyze import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.caches.resolve.getJavaMethodDescriptor 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.HierarchySearchRequest
import org.jetbrains.kotlin.idea.search.declarationsSearch.searchInheritors 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? val JetDeclaration.descriptor: DeclarationDescriptor?
get() = this.analyze().get(BindingContext.DECLARATION_TO_DESCRIPTOR, this) get() = this.analyze().get(BindingContext.DECLARATION_TO_DESCRIPTOR, this)
@@ -221,7 +221,7 @@ fun PsiReference.isPropertyReadOnlyUsage(): Boolean {
is JetProperty, is JetParameter -> origin as JetNamedDeclaration is JetProperty, is JetParameter -> origin as JetNamedDeclaration
else -> null else -> null
} }
return declaration != null && refTarget.getName() == PropertyCodegen.getterName(declaration.getNameAsName()) return declaration != null && refTarget.getName() == JvmAbi.getterName(declaration.getName()!!)
} }
return false return false
@@ -41,13 +41,12 @@ import com.sun.jdi.event.*
import com.sun.jdi.request.EventRequest import com.sun.jdi.request.EventRequest
import com.sun.jdi.request.MethodEntryRequest import com.sun.jdi.request.MethodEntryRequest
import org.jetbrains.annotations.TestOnly import org.jetbrains.annotations.TestOnly
import org.jetbrains.kotlin.codegen.PropertyCodegen
import org.jetbrains.kotlin.descriptors.PropertyDescriptor import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
import org.jetbrains.kotlin.idea.caches.resolve.analyzeAndGetResult import org.jetbrains.kotlin.idea.caches.resolve.analyzeAndGetResult
import org.jetbrains.kotlin.idea.util.application.runReadAction 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.load.kotlin.PackageClassUtils
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.JetCallableDeclaration import org.jetbrains.kotlin.psi.JetCallableDeclaration
import org.jetbrains.kotlin.psi.JetClassOrObject import org.jetbrains.kotlin.psi.JetClassOrObject
import org.jetbrains.kotlin.psi.JetParameter import org.jetbrains.kotlin.psi.JetParameter
@@ -165,17 +164,17 @@ class KotlinFieldBreakpoint(
} }
} }
BreakpointType.METHOD -> { BreakpointType.METHOD -> {
val propertyName = Name.identifier(getFieldName()) val fieldName = getFieldName()
if (getProperties().WATCH_ACCESS) { if (getProperties().WATCH_ACCESS) {
val getter = refType.methodsByName(PropertyCodegen.getterName(propertyName)).firstOrNull() val getter = refType.methodsByName(JvmAbi.getterName(fieldName)).firstOrNull()
if (getter != null) { if (getter != null) {
createMethodBreakpoint(debugProcess, refType, getter) createMethodBreakpoint(debugProcess, refType, getter)
} }
} }
if (getProperties().WATCH_MODIFICATION) { if (getProperties().WATCH_MODIFICATION) {
val setter = refType.methodsByName(PropertyCodegen.setterName(propertyName)).firstOrNull() val setter = refType.methodsByName(JvmAbi.setterName(fieldName)).firstOrNull()
if (setter != null) { if (setter != null) {
createMethodBreakpoint(debugProcess, refType, setter) createMethodBreakpoint(debugProcess, refType, setter)
} }
@@ -255,9 +254,8 @@ class KotlinFieldBreakpoint(
} }
private fun getMethodsName(): List<String> { private fun getMethodsName(): List<String> {
val propertyName = Name.identifier(getFieldName()) val fieldName = getFieldName()
return arrayListOf(PropertyCodegen.getterName(propertyName), PropertyCodegen.setterName(propertyName)) return listOf(JvmAbi.getterName(fieldName), JvmAbi.setterName(fieldName))
} }
override fun getEventMessage(event: LocatableEvent): String { override fun getEventMessage(event: LocatableEvent): String {
@@ -27,7 +27,6 @@ import com.sun.jdi.Field
import com.sun.jdi.Method import com.sun.jdi.Method
import com.sun.jdi.ObjectReference import com.sun.jdi.ObjectReference
import com.sun.jdi.Value import com.sun.jdi.Value
import org.jetbrains.kotlin.codegen.PropertyCodegen
import org.jetbrains.kotlin.load.java.JvmAbi import org.jetbrains.kotlin.load.java.JvmAbi
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
@@ -86,8 +85,6 @@ class DelegatedPropertyFieldDescriptor(
val fieldName = getName() val fieldName = getName()
if (!Name.isValidIdentifier(fieldName)) return null if (!Name.isValidIdentifier(fieldName)) return null
val getterName = PropertyCodegen.getterName(Name.identifier(fieldName)) return getObject().referenceType().methodsByName(JvmAbi.getterName(fieldName))?.firstOrNull()
return getObject().referenceType().methodsByName(getterName)?.firstOrNull()
} }
} }
@@ -25,7 +25,6 @@ import com.intellij.psi.*
import com.intellij.util.containers.MultiMap import com.intellij.util.containers.MultiMap
import org.jetbrains.kotlin.asJava.namedUnwrappedElement import org.jetbrains.kotlin.asJava.namedUnwrappedElement
import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.codegen.PropertyCodegen
import org.jetbrains.kotlin.descriptors.CallableDescriptor import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.descriptors.FunctionDescriptor import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.idea.caches.resolve.analyze 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.ShortenReferences
import org.jetbrains.kotlin.idea.util.application.executeWriteCommand import org.jetbrains.kotlin.idea.util.application.executeWriteCommand
import org.jetbrains.kotlin.idea.util.supertypes import org.jetbrains.kotlin.idea.util.supertypes
import org.jetbrains.kotlin.load.java.JvmAbi
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.getParentOfTypeAndBranch import org.jetbrains.kotlin.psi.psiUtil.getParentOfTypeAndBranch
@@ -91,7 +91,7 @@ public class ConvertFunctionToPropertyIntention : JetSelfTargetingIntention<JetN
override fun performRefactoring(descriptorsForChange: Collection<CallableDescriptor>) { override fun performRefactoring(descriptorsForChange: Collection<CallableDescriptor>) {
val conflicts = MultiMap<PsiElement, String>() val conflicts = MultiMap<PsiElement, String>()
val getterName = PropertyCodegen.getterName(callableDescriptor.getName()) val getterName = JvmAbi.getterName(callableDescriptor.getName().asString())
val callables = getAffectedCallables(project, descriptorsForChange) val callables = getAffectedCallables(project, descriptorsForChange)
val kotlinCalls = ArrayList<JetCallElement>() val kotlinCalls = ArrayList<JetCallElement>()
val foreignRefs = ArrayList<PsiReference>() val foreignRefs = ArrayList<PsiReference>()
@@ -24,7 +24,6 @@ import com.intellij.psi.*
import com.intellij.refactoring.util.RefactoringUIUtil import com.intellij.refactoring.util.RefactoringUIUtil
import com.intellij.util.containers.MultiMap import com.intellij.util.containers.MultiMap
import org.jetbrains.kotlin.asJava.namedUnwrappedElement import org.jetbrains.kotlin.asJava.namedUnwrappedElement
import org.jetbrains.kotlin.codegen.PropertyCodegen
import org.jetbrains.kotlin.descriptors.CallableDescriptor import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.idea.caches.resolve.analyze import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde 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.UsagesSearchTarget
import org.jetbrains.kotlin.idea.search.usagesSearch.search import org.jetbrains.kotlin.idea.search.usagesSearch.search
import org.jetbrains.kotlin.idea.util.application.executeWriteCommand 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.*
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
import org.jetbrains.kotlin.psi.psiUtil.siblings import org.jetbrains.kotlin.psi.psiUtil.siblings
@@ -80,7 +80,7 @@ public class ConvertPropertyToFunctionIntention : JetSelfTargetingIntention<JetP
override fun performRefactoring(descriptorsForChange: Collection<CallableDescriptor>) { override fun performRefactoring(descriptorsForChange: Collection<CallableDescriptor>) {
val propertyName = callableDescriptor.getName().asString() val propertyName = callableDescriptor.getName().asString()
val getterName = PropertyCodegen.getterName(callableDescriptor.getName()) val getterName = JvmAbi.getterName(callableDescriptor.getName().asString())
val conflicts = MultiMap<PsiElement, String>() val conflicts = MultiMap<PsiElement, String>()
val callables = getAffectedCallables(project, descriptorsForChange) val callables = getAffectedCallables(project, descriptorsForChange)
val kotlinRefs = ArrayList<JetSimpleNameExpression>() val kotlinRefs = ArrayList<JetSimpleNameExpression>()
@@ -28,7 +28,6 @@ import org.jetbrains.kotlin.asJava.getRepresentativeLightMethod
import org.jetbrains.kotlin.asJava.toLightMethods import org.jetbrains.kotlin.asJava.toLightMethods
import org.jetbrains.kotlin.asJava.unwrapped import org.jetbrains.kotlin.asJava.unwrapped
import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.codegen.PropertyCodegen
import org.jetbrains.kotlin.descriptors.CallableDescriptor import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.descriptors.Visibilities import org.jetbrains.kotlin.descriptors.Visibilities
import org.jetbrains.kotlin.descriptors.Visibility 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.idea.util.IdeDescriptorRenderers
import org.jetbrains.kotlin.lexer.JetTokens import org.jetbrains.kotlin.lexer.JetTokens
import org.jetbrains.kotlin.load.java.JvmAbi import org.jetbrains.kotlin.load.java.JvmAbi
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
import org.jetbrains.kotlin.types.JetType import org.jetbrains.kotlin.types.JetType
@@ -328,7 +326,7 @@ public class JetChangeInfo(
): JavaChangeInfo? { ): JavaChangeInfo? {
val newParameterList = receiverParameterInfo.singletonOrEmptyList() + getNonReceiverParameters() val newParameterList = receiverParameterInfo.singletonOrEmptyList() + getNonReceiverParameters()
val newJavaParameters = getJavaParameterInfos(currentPsiMethod, newParameterList).toTypedArray() 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) return createJavaChangeInfo(originalPsiMethod, currentPsiMethod, newName, currentPsiMethod.getReturnType(), newJavaParameters)
} }
@@ -344,7 +342,7 @@ public class JetChangeInfo(
newJavaParameters.add(ParameterInfoImpl(oldIndex, "receiver", PsiType.VOID)) 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()) return createJavaChangeInfo(originalPsiMethod, currentPsiMethod, newName, PsiType.VOID, newJavaParameters.toTypedArray())
} }
@@ -434,4 +432,4 @@ public fun ChangeInfo.toJetChangeInfo(originalChangeSignatureDescriptor: JetMeth
newParameters, newParameters,
null, null,
method) method)
} }
@@ -149,8 +149,8 @@ public class JetFunctionCallUsage extends JetUsageInfo<JetCallElement> {
String newName = changeInfo.getNewName(); String newName = changeInfo.getNewName();
if (isPropertyJavaUsage()) { if (isPropertyJavaUsage()) {
String currentName = ((JetSimpleNameExpression) callee).getReferencedName(); String currentName = ((JetSimpleNameExpression) callee).getReferencedName();
if (currentName.startsWith(JvmAbi.GETTER_PREFIX)) newName = PropertyCodegen.getterName(Name.identifier(newName)); if (currentName.startsWith(JvmAbi.GETTER_PREFIX)) newName = JvmAbi.getterName(newName);
else if (currentName.startsWith(JvmAbi.SETTER_PREFIX)) newName = PropertyCodegen.setterName(Name.identifier(newName)); else if (currentName.startsWith(JvmAbi.SETTER_PREFIX)) newName = JvmAbi.setterName(newName);
} }
callee.replace(JetPsiFactory(getProject()).createSimpleName(newName)); callee.replace(JetPsiFactory(getProject()).createSimpleName(newName));
@@ -16,32 +16,32 @@
package org.jetbrains.kotlin.idea.refactoring.rename 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 com.intellij.openapi.application.ApplicationManager
import org.jetbrains.kotlin.asJava.LightClassUtil import com.intellij.openapi.editor.Editor
import com.intellij.psi.search.searches.OverridingMethodsSearch import com.intellij.openapi.ui.Messages
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiMethod import com.intellij.psi.PsiMethod
import com.intellij.psi.SyntheticElement import com.intellij.psi.SyntheticElement
import com.intellij.refactoring.util.RefactoringUtil import com.intellij.psi.search.SearchScope
import com.intellij.refactoring.rename.RenameProcessor import com.intellij.psi.search.searches.OverridingMethodsSearch
import org.jetbrains.kotlin.codegen.PropertyCodegen
import org.jetbrains.kotlin.name.Name
import com.intellij.usageView.UsageInfo
import com.intellij.refactoring.listeners.RefactoringElementListener import com.intellij.refactoring.listeners.RefactoringElementListener
import com.intellij.openapi.editor.Editor import com.intellij.refactoring.rename.RenameProcessor
import org.jetbrains.kotlin.lexer.JetTokens import com.intellij.refactoring.rename.RenamePsiElementProcessor
import org.jetbrains.kotlin.resolve.BindingContext import com.intellij.refactoring.util.RefactoringUtil
import org.jetbrains.kotlin.psi.JetClassOrObject import com.intellij.usageView.UsageInfo
import com.intellij.openapi.ui.Messages import org.jetbrains.kotlin.asJava.LightClassUtil
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.asJava.namedUnwrappedElement import org.jetbrains.kotlin.asJava.namedUnwrappedElement
import org.jetbrains.kotlin.resolve.OverrideResolver import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
import org.jetbrains.kotlin.idea.util.application.runReadAction
import org.jetbrains.kotlin.idea.caches.resolve.analyze 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() { public class RenameKotlinPropertyProcessor : RenamePsiElementProcessor() {
override fun canProcessElement(element: PsiElement): Boolean = element.namedUnwrappedElement is JetProperty override fun canProcessElement(element: PsiElement): Boolean = element.namedUnwrappedElement is JetProperty
@@ -102,8 +102,9 @@ public class RenameKotlinPropertyProcessor : RenamePsiElementProcessor() {
return return
} }
val oldGetterName = PropertyCodegen.getterName(element.getNameAsName()) val name = element.getName()!!
val oldSetterName = PropertyCodegen.setterName(element.getNameAsName()) val oldGetterName = JvmAbi.getterName(name)
val oldSetterName = JvmAbi.setterName(name)
val refKindUsages = usages.toList().groupBy { usage: UsageInfo -> val refKindUsages = usages.toList().groupBy { usage: UsageInfo ->
val refElement = usage.getReference()?.resolve() 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<UsageInfo>(), refKindUsages[UsageKind.SETTER_USAGE]?.toTypedArray() ?: arrayOf<UsageInfo>(),
null) null)
super.renameElement(element, PropertyCodegen.getterName(Name.identifier(newName)), super.renameElement(element, JvmAbi.getterName(newName),
refKindUsages[UsageKind.GETTER_USAGE]?.toTypedArray() ?: arrayOf<UsageInfo>(), refKindUsages[UsageKind.GETTER_USAGE]?.toTypedArray() ?: arrayOf<UsageInfo>(),
null) null)
@@ -151,9 +152,7 @@ public class RenameKotlinPropertyProcessor : RenamePsiElementProcessor() {
if (overriderElement is PsiMethod) { if (overriderElement is PsiMethod) {
if (newName != null && Name.isValidIdentifier(newName)) { if (newName != null && Name.isValidIdentifier(newName)) {
val isGetter = overriderElement.getParameterList().getParametersCount() == 0 val isGetter = overriderElement.getParameterList().getParametersCount() == 0
val name = Name.identifier(newName) allRenames[overriderElement] = if (isGetter) JvmAbi.getterName(newName) else JvmAbi.setterName(newName)
allRenames[overriderElement] = if (isGetter) PropertyCodegen.getterName(name) else PropertyCodegen.setterName(name)
} }
} }
else { else {