Rename: Support retargeting/shadowing conflict checking for functions

#KT-22564 Fixed
This commit is contained in:
Alexey Sedunov
2018-02-07 16:23:36 +03:00
parent 5c6bba9f14
commit 695a2a4098
8 changed files with 51 additions and 6 deletions
@@ -58,9 +58,6 @@ class KotlinRefactoringSupportProvider : RefactoringSupportProvider() {
if (element.isLocal) return true
}
is KtDestructuringDeclarationEntry -> return true
is KtFunction -> {
if (element.isLocal && element.nameIdentifier != null) return true
}
is KtParameter -> {
val parent = element.parent
if (parent is KtForExpression) {
@@ -96,7 +96,11 @@ class RenameKotlinFunctionProcessor : RenameKotlinPsiProcessor() {
val declaration = element.unwrapped as? KtNamedFunction ?: return
val descriptor = declaration.unsafeResolveToDescriptor()
checkConflictsAndReplaceUsageInfos(element, allRenames, result)
checkRedeclarations(descriptor, newName, result)
result += SmartList<UsageInfo>().also { collisions ->
checkRedeclarations(descriptor, newName, collisions)
checkOriginalUsagesRetargeting(declaration, newName, result, collisions)
checkNewNameUsagesRetargeting(declaration, newName, collisions)
}
}
class FunctionWithSupersWrapper(
@@ -229,6 +233,8 @@ class RenameKotlinFunctionProcessor : RenameKotlinPsiProcessor() {
RenameUtil.doRenameGenericNamedElement(element, newName, simpleUsages.toTypedArray(), listener)
usages.forEach { (it as? KtResolvableCollisionUsageInfo)?.apply() }
(element.unwrapped as? KtNamedDeclaration)?.let(::dropOverrideKeywordIfNecessary)
}
@@ -35,6 +35,7 @@ import org.jetbrains.kotlin.idea.references.mainReference
import org.jetbrains.kotlin.idea.search.and
import org.jetbrains.kotlin.idea.search.restrictToKotlinSources
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
import org.jetbrains.kotlin.idea.util.getAllAccessibleFunctions
import org.jetbrains.kotlin.idea.util.getAllAccessibleVariables
import org.jetbrains.kotlin.idea.util.getResolutionScope
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
@@ -166,6 +167,7 @@ private fun LexicalScope.getRelevantDescriptors(
val nameAsName = Name.identifier(name)
return when (declaration) {
is KtProperty, is KtParameter, is PsiField -> getAllAccessibleVariables(nameAsName)
is KtNamedFunction -> getAllAccessibleFunctions(nameAsName)
is KtClassOrObject, is PsiClass -> listOfNotNull(findClassifier(nameAsName, NoLookupLocation.FROM_IDE))
else -> emptyList()
}
+10
View File
@@ -0,0 +1,10 @@
class A {
fun foo() {}
fun goo() {
fun <caret>innerGoo() {
foo()
}
innerGoo()
}
}
@@ -0,0 +1,10 @@
class A {
fun foo() {}
fun goo() {
fun foo() {
this.foo()
}
foo()
}
}
@@ -0,0 +1,8 @@
package test
fun foo() {
fun <caret>innerGoo() {
foo()
}
innerGoo()
}
@@ -0,0 +1,8 @@
package test
fun foo() {
fun foo() {
test.foo()
}
innerGoo()
}
@@ -55,7 +55,7 @@ class InplaceRenameTest : LightPlatformCodeInsightTestCase() {
}
fun testLocalFunction() {
doTestInplaceRename("bar")
doTestMemberInplaceRename("bar")
}
fun testFunctionParameterNotInplace() {
@@ -71,7 +71,7 @@ class InplaceRenameTest : LightPlatformCodeInsightTestCase() {
}
fun testLabelFromFunction() {
doTestInplaceRename("foo")
doTestMemberInplaceRename("foo")
}
fun testMultiDeclaration() {
@@ -130,6 +130,10 @@ class InplaceRenameTest : LightPlatformCodeInsightTestCase() {
doTestMemberInplaceRename("is")
}
fun testAddThis() {
doTestMemberInplaceRename("foo")
}
private fun doTestImplicitLambdaParameter(newName: String) {
configureByFile(getTestName(false) + ".kt")