Unused symbol: fix false positive in anonymous object in top level or companion object

#KT-31800 Fixed
#KT-20868 Fixed
This commit is contained in:
Toshiaki Kameyama
2020-02-10 13:38:16 +09:00
committed by Vladimir Dolzhenko
parent ef1e54eda9
commit a3252b9480
10 changed files with 106 additions and 0 deletions
@@ -130,6 +130,21 @@ abstract class KtNamedDeclarationStub<T extends KotlinStubWithFqName<?>> extends
KtElement enclosingBlock = KtPsiUtil.getEnclosingElementForLocalDeclaration(this, false);
if (enclosingBlock != null) {
PsiElement enclosingParent = enclosingBlock.getParent();
KtObjectDeclaration containingObject = PsiTreeUtil.getParentOfType(this, KtObjectDeclaration.class);
if (containingObject != null && containingObject.isObjectLiteral()) {
KtDeclarationWithInitializer declaration =
PsiTreeUtil.getParentOfType(containingObject, KtDeclarationWithInitializer.class);
if (declaration != null && declaration.hasModifier(KtTokens.PRIVATE_KEYWORD)) {
if (enclosingParent instanceof KtFile) {
return new LocalSearchScope(enclosingParent);
}
if (enclosingParent instanceof KtObjectDeclaration && ((KtObjectDeclaration) enclosingParent).isCompanion()) {
return new LocalSearchScope(enclosingParent.getParent());
}
}
}
if (enclosingParent instanceof KtContainerNode) {
enclosingParent = enclosingParent.getParent();
}