Find Usages: Restrict search scope for private class members

#KT-6124 Fixed
This commit is contained in:
Alexey Sedunov
2014-10-27 14:51:33 +03:00
parent a2930a581f
commit a13f334df2
8 changed files with 25 additions and 24 deletions
@@ -21,6 +21,7 @@ import com.intellij.psi.PsiElement;
import com.intellij.psi.search.LocalSearchScope;
import com.intellij.psi.search.SearchScope;
import com.intellij.psi.stubs.IStubElementType;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
@@ -89,9 +90,12 @@ abstract class JetNamedDeclarationStub<T extends PsiJetStubWithFqName> extends J
@NotNull
@Override
public SearchScope getUseScope() {
JetElement enclosingBlock = JetPsiUtil.getEnclosingElementForLocalDeclaration(this);
if (enclosingBlock != null) {
return new LocalSearchScope(enclosingBlock);
JetElement enclosingBlock = JetPsiUtil.getEnclosingElementForLocalDeclaration(this, false);
if (enclosingBlock != null) return new LocalSearchScope(enclosingBlock);
if (hasModifier(JetTokens.PRIVATE_KEYWORD)) {
JetElement containingClass = PsiTreeUtil.getParentOfType(this, JetClassOrObject.class);
if (containingClass != null) return new LocalSearchScope(containingClass);
}
return super.getUseScope();
@@ -819,12 +819,19 @@ public class JetPsiUtil {
@Nullable
public static JetElement getEnclosingElementForLocalDeclaration(@NotNull JetDeclaration declaration) {
if (declaration instanceof JetTypeParameter) {
return getEnclosingElementForLocalDeclaration(declaration, true);
}
@Nullable
public static JetElement getEnclosingElementForLocalDeclaration(@NotNull JetDeclaration declaration, boolean skipParameters) {
if (declaration instanceof JetTypeParameter && skipParameters) {
declaration = PsiTreeUtil.getParentOfType(declaration, JetNamedDeclaration.class);
}
else if (declaration instanceof JetParameter) {
if (((JetParameter) declaration).getValOrVarNode() != null) return null;
PsiElement parent = declaration.getParent();
if (parent != null && parent.getParent() instanceof JetNamedFunction) {
if (skipParameters && parent != null && parent.getParent() instanceof JetNamedFunction) {
declaration = (JetNamedFunction) parent.getParent();
}
}