Pull Up: Approximate anonymous object type with its direct supertype
This commit is contained in:
@@ -28,10 +28,13 @@ import org.jetbrains.kotlin.load.java.JvmAnnotationNames.JETBRAINS_NULLABLE_ANNO
|
||||
import org.jetbrains.kotlin.load.java.JvmAnnotationNames.JETBRAINS_READONLY_ANNOTATION
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.platform.JavaToKotlinClassMap
|
||||
import org.jetbrains.kotlin.psi.JetCallableDeclaration
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.getClassifier
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.typeUtil.immediateSupertypes
|
||||
import org.jetbrains.kotlin.types.typeUtil.makeNotNullable
|
||||
import org.jetbrains.kotlin.types.typeUtil.substitute
|
||||
import org.jetbrains.kotlin.types.typeUtil.supertypes
|
||||
@@ -94,3 +97,11 @@ public fun JetType.approximateWithResolvableType(scope: LexicalScope?, checkType
|
||||
return supertypes().firstOrNull { it.isResolvableInScope(scope, checkTypeParameters) }
|
||||
?: KotlinBuiltIns.getInstance().getAnyType()
|
||||
}
|
||||
|
||||
public fun JetType.anonymousObjectSuperTypeOrNull(): JetType? {
|
||||
val classDescriptor = constructor.declarationDescriptor
|
||||
if (classDescriptor != null && DescriptorUtils.isAnonymousObject(classDescriptor)) {
|
||||
return immediateSupertypes().firstOrNull() ?: KotlinBuiltIns.getInstance().anyType
|
||||
}
|
||||
return null
|
||||
}
|
||||
Reference in New Issue
Block a user