Move getterName/setterName to JvmAbi
Reuse in RuntimeTypeMapper in reflection
This commit is contained in:
@@ -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();
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -290,7 +290,8 @@ public class LightClassUtil {
|
||||
new Function1<PsiMethod, Boolean>() {
|
||||
@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);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<String> {
|
||||
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 {
|
||||
|
||||
+1
-4
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<JetN
|
||||
|
||||
override fun performRefactoring(descriptorsForChange: Collection<CallableDescriptor>) {
|
||||
val conflicts = MultiMap<PsiElement, String>()
|
||||
val getterName = PropertyCodegen.getterName(callableDescriptor.getName())
|
||||
val getterName = JvmAbi.getterName(callableDescriptor.getName().asString())
|
||||
val callables = getAffectedCallables(project, descriptorsForChange)
|
||||
val kotlinCalls = ArrayList<JetCallElement>()
|
||||
val foreignRefs = ArrayList<PsiReference>()
|
||||
|
||||
@@ -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<JetP
|
||||
|
||||
override fun performRefactoring(descriptorsForChange: Collection<CallableDescriptor>) {
|
||||
val propertyName = callableDescriptor.getName().asString()
|
||||
val getterName = PropertyCodegen.getterName(callableDescriptor.getName())
|
||||
val getterName = JvmAbi.getterName(callableDescriptor.getName().asString())
|
||||
val conflicts = MultiMap<PsiElement, String>()
|
||||
val callables = getAffectedCallables(project, descriptorsForChange)
|
||||
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.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)
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -149,8 +149,8 @@ public class JetFunctionCallUsage extends JetUsageInfo<JetCallElement> {
|
||||
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));
|
||||
|
||||
+26
-27
@@ -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<UsageInfo>(),
|
||||
null)
|
||||
|
||||
super.renameElement(element, PropertyCodegen.getterName(Name.identifier(newName)),
|
||||
super.renameElement(element, JvmAbi.getterName(newName),
|
||||
refKindUsages[UsageKind.GETTER_USAGE]?.toTypedArray() ?: arrayOf<UsageInfo>(),
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user