Light Classes: Replace accessor with property name when renaming KtProperty/KtParameter through its light methods
#KT-11880 Fixed
This commit is contained in:
@@ -24,6 +24,9 @@ import com.intellij.psi.scope.PsiScopeProcessor
|
||||
import com.intellij.psi.util.*
|
||||
import com.intellij.util.IncorrectOperationException
|
||||
import org.jetbrains.kotlin.idea.KotlinLanguage
|
||||
import org.jetbrains.kotlin.load.java.propertyNameByGetMethodName
|
||||
import org.jetbrains.kotlin.load.java.propertyNameBySetMethodName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOriginKind
|
||||
|
||||
@@ -95,7 +98,19 @@ sealed class KtLightMethodImpl(
|
||||
|
||||
override fun setName(name: String): PsiElement? {
|
||||
val toRename = kotlinOrigin as? PsiNamedElement ?: throwCanNotModify()
|
||||
toRename.setName(name)
|
||||
|
||||
val newName = if (toRename is KtProperty || toRename is KtParameter) {
|
||||
val methodName = Name.guessByFirstCharacter(name)
|
||||
val propertyName = toRename.name ?: ""
|
||||
when {
|
||||
name.startsWith("get") -> propertyNameByGetMethodName(methodName)
|
||||
name.startsWith("set") -> propertyNameBySetMethodName(methodName, propertyName.startsWith("is"))
|
||||
else -> null
|
||||
}?.asString() ?: name
|
||||
}
|
||||
else name
|
||||
|
||||
toRename.setName(newName)
|
||||
return this
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user