Search: Restrict KtParameter usage scope to its containing declaration

#KT-13542 Fixed
 #KT-8672 Fixed
This commit is contained in:
Alexey Sedunov
2016-08-22 11:30:19 +03:00
parent 6480118da6
commit e908c6c1b2
6 changed files with 49 additions and 3 deletions
+2
View File
@@ -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
@@ -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<KotlinParameterStub> 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;
}
}
@@ -0,0 +1,12 @@
package test
// a
val t = "a"
fun foo(b: Int) {
// b
val tt = "b"
}
fun test() = foo(b = 1)
@@ -0,0 +1,12 @@
package test
// a
val t = "a"
fun foo(/*rename*/a: Int) {
// a
val tt = "a"
}
fun test() = foo(a = 1)
@@ -0,0 +1,6 @@
{
"type": "MARKED_ELEMENT",
"mainFile": "test/test.kt",
"newName": "b",
"withRuntime": "true"
}
@@ -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");