Try to avoid loading ast for decompiled files (KT-14804)

#KT-14804 Fixed
This commit is contained in:
Nikolay Krasko
2016-11-23 21:59:44 +03:00
parent 68df8c55e7
commit b816c182f0
7 changed files with 113 additions and 16 deletions
@@ -31,6 +31,7 @@ import org.jetbrains.kotlin.load.kotlin.JvmBuiltInsSettings
import org.jetbrains.kotlin.psi.KtCallableDeclaration
import org.jetbrains.kotlin.psi.KtClassOrObject
import org.jetbrains.kotlin.psi.KtDeclaration
import org.jetbrains.kotlin.psi.KtDeclarationContainer
import org.jetbrains.kotlin.renderer.DescriptorRenderer
import org.jetbrains.kotlin.renderer.DescriptorRendererModifier
import org.jetbrains.kotlin.resolve.DescriptorUtils
@@ -147,6 +148,24 @@ object ByDescriptorIndexer : DecompiledTextIndexer<String> {
return classOrObject?.getPrimaryConstructor() ?: classOrObject
}
if (!file.isContentsLoaded) {
if (original is MemberDescriptor) {
val declarationContainer: KtDeclarationContainer? = when {
DescriptorUtils.isTopLevelDeclaration(original) -> file
original.containingDeclaration is ClassDescriptor ->
getDeclarationForDescriptor(original.containingDeclaration as ClassDescriptor, file) as? KtClassOrObject
else -> null
}
if (declarationContainer != null) {
val descriptorName = original.name.asString()
val singleOrNull = declarationContainer.declarations.singleOrNull { it.name == descriptorName }
if (singleOrNull != null) {
return singleOrNull
}
}
}
}
return file.getDeclaration(this, original.toStringKey()) ?: run {
if (descriptor !is ClassDescriptor) return null