Don't enable search stub declaration by name if file doesn't contain descriptor key

This might cause irrelevant declarations found with the same name.
This commit is contained in:
Nikolay Krasko
2016-11-25 18:05:18 +03:00
parent b816c182f0
commit 3537673417
2 changed files with 8 additions and 2 deletions
@@ -48,4 +48,8 @@ open class KtDecompiledFile(
val range = decompiledText.get().index.getRange(indexer, key) ?: return null
return PsiTreeUtil.findElementOfClassAtRange(this@KtDecompiledFile, range.startOffset, range.endOffset, KtDeclaration::class.java)
}
fun <T : Any> hasDeclarationWithKey(indexer: DecompiledTextIndexer<T>, key: T): Boolean {
return decompiledText.get().index.getRange(indexer, key) != null
}
}
@@ -148,8 +148,10 @@ object ByDescriptorIndexer : DecompiledTextIndexer<String> {
return classOrObject?.getPrimaryConstructor() ?: classOrObject
}
val descriptorKey = original.toStringKey()
if (!file.isContentsLoaded) {
if (original is MemberDescriptor) {
if (original is MemberDescriptor && file.hasDeclarationWithKey(this, descriptorKey)) {
val declarationContainer: KtDeclarationContainer? = when {
DescriptorUtils.isTopLevelDeclaration(original) -> file
original.containingDeclaration is ClassDescriptor ->
@@ -167,7 +169,7 @@ object ByDescriptorIndexer : DecompiledTextIndexer<String> {
}
}
return file.getDeclaration(this, original.toStringKey()) ?: run {
return file.getDeclaration(this, descriptorKey) ?: run {
if (descriptor !is ClassDescriptor) return null
val classFqName = descriptor.fqNameUnsafe