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:
@@ -48,4 +48,8 @@ open class KtDecompiledFile(
|
|||||||
val range = decompiledText.get().index.getRange(indexer, key) ?: return null
|
val range = decompiledText.get().index.getRange(indexer, key) ?: return null
|
||||||
return PsiTreeUtil.findElementOfClassAtRange(this@KtDecompiledFile, range.startOffset, range.endOffset, KtDeclaration::class.java)
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-2
@@ -148,8 +148,10 @@ object ByDescriptorIndexer : DecompiledTextIndexer<String> {
|
|||||||
return classOrObject?.getPrimaryConstructor() ?: classOrObject
|
return classOrObject?.getPrimaryConstructor() ?: classOrObject
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val descriptorKey = original.toStringKey()
|
||||||
|
|
||||||
if (!file.isContentsLoaded) {
|
if (!file.isContentsLoaded) {
|
||||||
if (original is MemberDescriptor) {
|
if (original is MemberDescriptor && file.hasDeclarationWithKey(this, descriptorKey)) {
|
||||||
val declarationContainer: KtDeclarationContainer? = when {
|
val declarationContainer: KtDeclarationContainer? = when {
|
||||||
DescriptorUtils.isTopLevelDeclaration(original) -> file
|
DescriptorUtils.isTopLevelDeclaration(original) -> file
|
||||||
original.containingDeclaration is ClassDescriptor ->
|
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
|
if (descriptor !is ClassDescriptor) return null
|
||||||
|
|
||||||
val classFqName = descriptor.fqNameUnsafe
|
val classFqName = descriptor.fqNameUnsafe
|
||||||
|
|||||||
Reference in New Issue
Block a user