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
@@ -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;
}
}