Light Classes: Replace accessor with property name when renaming KtProperty/KtParameter through its light methods

#KT-11880 Fixed
This commit is contained in:
Alexey Sedunov
2016-04-15 15:36:09 +03:00
parent c21dff66aa
commit 754e7cac52
24 changed files with 259 additions and 1 deletions
@@ -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
}