Uast: Abort converting KotlinType to PsiType if it contains anonymous types (KT-15483)
This commit is contained in:
@@ -30,7 +30,10 @@ import com.intellij.psi.util.PsiTypesUtil
|
||||
import org.jetbrains.kotlin.asJava.toLightClass
|
||||
import org.jetbrains.kotlin.asJava.toLightElements
|
||||
import org.jetbrains.kotlin.codegen.signature.BothSignatureWriter
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||
import org.jetbrains.kotlin.load.kotlin.TypeMappingMode
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
@@ -78,6 +81,8 @@ internal fun KotlinType.toPsiType(source: UElement, element: KtElement, boxed: B
|
||||
if (psiType != null) return psiType
|
||||
}
|
||||
|
||||
if (this.containsLocalTypes()) return UastErrorType
|
||||
|
||||
val project = element.project
|
||||
val typeMapper = ServiceManager.getService(project, KotlinUastBindingContextProviderService::class.java)
|
||||
.getTypeMapper(element) ?: return UastErrorType
|
||||
@@ -95,6 +100,22 @@ internal fun KotlinType.toPsiType(source: UElement, element: KtElement, boxed: B
|
||||
return ClsTypeElementImpl(source.getParentOfType<UDeclaration>(false)?.psi ?: element, typeText, '\u0000').type
|
||||
}
|
||||
|
||||
private fun KotlinType.containsLocalTypes(): Boolean {
|
||||
val typeDeclarationDescriptor = this.constructor.declarationDescriptor
|
||||
if (typeDeclarationDescriptor is ClassDescriptor) {
|
||||
val containerDescriptor = typeDeclarationDescriptor.containingDeclaration
|
||||
if (containerDescriptor is PropertyDescriptor || containerDescriptor is FunctionDescriptor) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
if (arguments.any { it.type.containsLocalTypes() }) {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
internal fun KtTypeReference?.toPsiType(source: UElement, boxed: Boolean = false): PsiType {
|
||||
if (this == null) return UastErrorType
|
||||
return (analyze()[BindingContext.TYPE, this] ?: return UastErrorType).toPsiType(source, this, boxed)
|
||||
|
||||
Reference in New Issue
Block a user