[psi][AA] don't decompile code when stubs have enough information
^ KTIJ-25979 + do not assert when there are no stubs (text is already computed)
This commit is contained in:
+20
-4
@@ -50,6 +50,7 @@ import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.psi
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.*
|
||||
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.ifNotEmpty
|
||||
@@ -142,15 +143,30 @@ internal object FirReferenceResolveHelper {
|
||||
return when (qualified) {
|
||||
null -> FqName(expression.getReferencedName())
|
||||
else -> {
|
||||
qualified
|
||||
.collectDescendantsOfType<KtSimpleNameExpression>()
|
||||
.dropWhile { it.getReferencedName() == ROOT_PREFIX_FOR_IDE_RESOLUTION_MODE }
|
||||
.joinToString(separator = ".") { it.getReferencedName() }
|
||||
val refs =
|
||||
if (qualified is KtUserType && qualified.stub != null && (qualified.containingFile as? KtFile)?.isCompiled == true) {
|
||||
collectTypeReferences(qualified)
|
||||
} else {
|
||||
qualified.collectDescendantsOfType<KtSimpleNameExpression>()
|
||||
}
|
||||
refs.map { it.getReferencedName() }
|
||||
.dropWhile { it == ROOT_PREFIX_FOR_IDE_RESOLUTION_MODE }
|
||||
.joinToString(separator = ".")
|
||||
.let(::FqName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun collectTypeReferences(qualified: KtUserType): MutableList<KtNameReferenceExpression> {
|
||||
val refs = mutableListOf<KtNameReferenceExpression>()
|
||||
fun collectFragments(type: KtUserType) {
|
||||
type.getStubOrPsiChild(KtStubElementTypes.USER_TYPE)?.let { collectFragments(it) }
|
||||
refs.add(type.referenceExpression as? KtNameReferenceExpression ?: return)
|
||||
}
|
||||
collectFragments(qualified)
|
||||
return refs
|
||||
}
|
||||
|
||||
private fun KtSimpleNameExpression.isPartOfQualifiedExpression(): Boolean {
|
||||
var parent = parent
|
||||
while (parent is KtDotQualifiedExpression) {
|
||||
|
||||
@@ -278,7 +278,7 @@ inline fun <reified T : PsiElement> PsiElement.findDescendantOfType(
|
||||
|
||||
fun PsiElement.checkDecompiledText() {
|
||||
val file = containingFile
|
||||
if (file is KtFile && file.isCompiled) {
|
||||
if (file is KtFile && file.isCompiled && file.stub != null) {
|
||||
error("Attempt to load decompiled text, please use stubs instead. Decompile process might be slow and should be avoided")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user