diff --git a/ChangeLog.md b/ChangeLog.md index 3afa283d530..6817128742a 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -96,6 +96,8 @@ These artifacts include extensions for the types available in the latter JDKs, s ### IDE - [`KT-9125`](https://youtrack.jetbrains.com/issue/KT-9125) Support Type Hierarchy on references inside of super type call entries +- [`KT-13542`](https://youtrack.jetbrains.com/issue/KT-13542) Rename: Do not search parameter text occurrences outside of its containing declaration +- [`KT-8672`](https://youtrack.jetbrains.com/issue/KT-8672) Rename: Optimize search of parameter references in calls with named arguments #### Refactorings diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtParameter.java b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtParameter.java index 39252ea0d31..4714028bef0 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtParameter.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtParameter.java @@ -20,6 +20,8 @@ import com.intellij.lang.ASTNode; import com.intellij.navigation.ItemPresentation; import com.intellij.navigation.ItemPresentationProviders; import com.intellij.psi.PsiElement; +import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.psi.search.LocalSearchScope; import com.intellij.psi.search.SearchScope; import com.intellij.psi.tree.TokenSet; import com.intellij.psi.util.PsiTreeUtil; @@ -182,8 +184,14 @@ public class KtParameter extends KtNamedDeclarationStub imp @NotNull @Override public SearchScope getUseScope() { - KtDeclarationWithBody owner = getOwnerFunction(); - if (owner instanceof KtPrimaryConstructor && hasValOrVar()) return super.getUseScope(); - return owner != null ? owner.getUseScope() : super.getUseScope(); + KtExpression owner = getOwnerFunction(); + if (owner instanceof KtPrimaryConstructor) { + if (hasValOrVar()) return super.getUseScope(); + owner = ((KtPrimaryConstructor) owner).getContainingClassOrObject(); + } + if (owner == null) { + owner = PsiTreeUtil.getParentOfType(this, KtExpression.class); + } + return owner != null ? new LocalSearchScope(owner) : GlobalSearchScope.EMPTY_SCOPE; } } diff --git a/idea/testData/refactoring/rename/parameterTextOccurrences/after/test/test.kt b/idea/testData/refactoring/rename/parameterTextOccurrences/after/test/test.kt new file mode 100644 index 00000000000..e8e945cebe7 --- /dev/null +++ b/idea/testData/refactoring/rename/parameterTextOccurrences/after/test/test.kt @@ -0,0 +1,12 @@ +package test + +// a + +val t = "a" + +fun foo(b: Int) { + // b + val tt = "b" +} + +fun test() = foo(b = 1) \ No newline at end of file diff --git a/idea/testData/refactoring/rename/parameterTextOccurrences/before/test/test.kt b/idea/testData/refactoring/rename/parameterTextOccurrences/before/test/test.kt new file mode 100644 index 00000000000..80b9f080bfc --- /dev/null +++ b/idea/testData/refactoring/rename/parameterTextOccurrences/before/test/test.kt @@ -0,0 +1,12 @@ +package test + +// a + +val t = "a" + +fun foo(/*rename*/a: Int) { + // a + val tt = "a" +} + +fun test() = foo(a = 1) \ No newline at end of file diff --git a/idea/testData/refactoring/rename/parameterTextOccurrences/parameterTextOccurrences.test b/idea/testData/refactoring/rename/parameterTextOccurrences/parameterTextOccurrences.test new file mode 100644 index 00000000000..c4b7564b4c2 --- /dev/null +++ b/idea/testData/refactoring/rename/parameterTextOccurrences/parameterTextOccurrences.test @@ -0,0 +1,6 @@ +{ + "type": "MARKED_ELEMENT", + "mainFile": "test/test.kt", + "newName": "b", + "withRuntime": "true" +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/refactoring/rename/RenameTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/refactoring/rename/RenameTestGenerated.java index 8d4eeb1168a..546c32c8add 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/refactoring/rename/RenameTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/refactoring/rename/RenameTestGenerated.java @@ -251,6 +251,12 @@ public class RenameTestGenerated extends AbstractRenameTest { doTest(fileName); } + @TestMetadata("parameterTextOccurrences/parameterTextOccurrences.test") + public void testParameterTextOccurrences_ParameterTextOccurrences() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/rename/parameterTextOccurrences/parameterTextOccurrences.test"); + doTest(fileName); + } + @TestMetadata("parameterWithQuotation/parameterWithQuotation.test") public void testParameterWithQuotation_ParameterWithQuotation() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/rename/parameterWithQuotation/parameterWithQuotation.test");