Refactoring. Move flexible type creation to KotlinTypeFactory.

This commit is contained in:
Stanislav Erokhin
2016-05-25 13:15:13 +03:00
parent 3a451744c5
commit 957bae18be
22 changed files with 168 additions and 149 deletions
@@ -34,6 +34,10 @@ import org.jetbrains.kotlin.types.typeUtil.*
fun KotlinType.approximateFlexibleTypes(preferNotNull: Boolean = false): KotlinType {
if (isDynamic()) return this
return approximateNonDynamicFlexibleTypes(preferNotNull)
}
private fun KotlinType.approximateNonDynamicFlexibleTypes(preferNotNull: Boolean = false): SimpleType {
if (isFlexible()) {
val flexible = flexibility()
val lowerClass = flexible.lowerBound.constructor.declarationDescriptor as? ClassDescriptor?
@@ -48,12 +52,12 @@ fun KotlinType.approximateFlexibleTypes(preferNotNull: Boolean = false): KotlinT
else
if (preferNotNull) flexible.lowerBound else flexible.upperBound
approximation = approximation.approximateFlexibleTypes()
approximation = approximation.approximateNonDynamicFlexibleTypes()
approximation = if (isAnnotatedNotNull()) approximation.makeNotNullable() else approximation
approximation = if (isAnnotatedNotNull()) TypeUtils.makeNotNullable(approximation) else approximation
if (approximation.isMarkedNullable && !flexible.lowerBound.isMarkedNullable && TypeUtils.isTypeParameter(approximation) && TypeUtils.hasNullableSuperType(approximation)) {
approximation = approximation.makeNotNullable()
approximation = TypeUtils.makeNotNullable(approximation)
}
return approximation
@@ -26,7 +26,6 @@ import org.jetbrains.kotlin.idea.decompiler.textBuilder.DeserializerForDecompile
import org.jetbrains.kotlin.idea.decompiler.textBuilder.LoggingErrorReporter
import org.jetbrains.kotlin.idea.decompiler.textBuilder.ResolveEverythingToKotlinAnyLocalClassifierResolver
import org.jetbrains.kotlin.incremental.components.LookupTracker
import org.jetbrains.kotlin.load.java.lazy.types.LazyJavaTypeResolver.FlexibleJavaClassifierTypeFactory
import org.jetbrains.kotlin.load.java.structure.JavaClass
import org.jetbrains.kotlin.load.kotlin.*
import org.jetbrains.kotlin.name.ClassId
@@ -40,6 +39,7 @@ import org.jetbrains.kotlin.serialization.deserialization.DeserializationCompone
import org.jetbrains.kotlin.serialization.deserialization.NotFoundClasses
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedPackageMemberScope
import org.jetbrains.kotlin.serialization.jvm.JvmProtoBufUtil
import org.jetbrains.kotlin.types.FlexibleJavaClassifierTypeFactory
fun DeserializerForClassfileDecompiler(classFile: VirtualFile): DeserializerForClassfileDecompiler {
val kotlinClassHeaderInfo = IDEKotlinBinaryClassCache.getKotlinBinaryClassHeaderData(classFile)