[Misc] Introduce helper-method 'IntersectionTypeConstructor.createType()'

This commit is contained in:
Dmitry Savvinov
2019-07-10 14:06:35 +03:00
parent 5c13e02e9c
commit fe78e153f7
5 changed files with 12 additions and 34 deletions
@@ -23,7 +23,6 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor;
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor;
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
import org.jetbrains.kotlin.resolve.calls.inference.CallHandle;
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystem;
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilderImpl;
@@ -132,15 +131,7 @@ public class TypeIntersector {
return TypeUtils.makeNullableAsSpecified(resultingTypes.get(0), allNullable);
}
IntersectionTypeConstructor constructor = new IntersectionTypeConstructor(resultingTypes);
return KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(
Annotations.Companion.getEMPTY(),
constructor,
Collections.emptyList(),
allNullable,
constructor.createScopeForKotlinType()
);
return new IntersectionTypeConstructor(resultingTypes).createType();
}
/**
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.types
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.resolve.scopes.MemberScope
import org.jetbrains.kotlin.resolve.scopes.TypeIntersectionScope
import java.util.*
@@ -60,6 +61,11 @@ class IntersectionTypeConstructor(typesToIntersect: Collection<KotlinType>) : Ty
return intersectedTypes == other.intersectedTypes
}
fun createType(): SimpleType =
KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(
Annotations.EMPTY, this, listOf(), false, this.createScopeForKotlinType()
)
override fun hashCode(): Int = hashCode
}
@@ -80,4 +86,4 @@ inline fun IntersectionTypeConstructor.transformComponents(
if (!changed) return null
return IntersectionTypeConstructor(newSupertypes)
}
}
@@ -127,13 +127,7 @@ private fun KotlinType.makeIntersectionTypeDefinitelyNotNullOrNotNull(): SimpleT
val typeConstructor = constructor as? IntersectionTypeConstructor ?: return null
val definitelyNotNullConstructor = typeConstructor.makeDefinitelyNotNullOrNotNull() ?: return null
return KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(
annotations,
definitelyNotNullConstructor,
listOf(),
false,
definitelyNotNullConstructor.createScopeForKotlinType()
)
return definitelyNotNullConstructor.createType()
}
private fun IntersectionTypeConstructor.makeDefinitelyNotNullOrNotNull(): IntersectionTypeConstructor? {
@@ -16,7 +16,6 @@
package org.jetbrains.kotlin.types.checker
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.resolve.constants.IntegerLiteralTypeConstructor
import org.jetbrains.kotlin.types.*
import java.util.*
@@ -119,14 +118,7 @@ object TypeIntersector {
if (filteredSuperAndEqualTypes.size < 2) return filteredSuperAndEqualTypes.single()
val constructor = IntersectionTypeConstructor(inputTypes)
return KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(
Annotations.EMPTY,
constructor,
listOf(),
false,
constructor.createScopeForKotlinType()
)
return IntersectionTypeConstructor(inputTypes).createType()
}
private fun filterTypes(
@@ -111,13 +111,8 @@ class NewKotlinTypeCheckerImpl() : NewKotlinTypeChecker {
is IntersectionTypeConstructor -> if (type.isMarkedNullable) {
val newConstructor = constructor.transformComponents(transform = { it.makeNullable() }) ?: constructor
return KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(
type.annotations,
newConstructor,
listOf(),
false,
newConstructor.createScopeForKotlinType()
)
return newConstructor.createType()
}
}