Rename KotlinTypeFactory::simpleType to simpleTypeWithNonTrivialMemberScope

To state it must be used only for limited number of cases
This commit is contained in:
Denis Zharkov
2017-10-05 11:08:53 +03:00
parent 20334a2321
commit 1c9b454d90
20 changed files with 39 additions and 39 deletions
@@ -65,7 +65,7 @@ class TypeAliasExpander(
}
private fun TypeAliasExpansion.createAbbreviation(annotations: Annotations, isNullable: Boolean) =
KotlinTypeFactory.simpleType(
KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(
annotations,
descriptor.typeConstructor,
arguments,
@@ -369,11 +369,11 @@ class TypeResolver(
return if (scopeForTypeParameter is ErrorUtils.ErrorScope)
ErrorUtils.createErrorType("?")
else
KotlinTypeFactory.simpleType(annotations,
typeParameter.typeConstructor,
listOf(),
false,
scopeForTypeParameter)
KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(annotations,
typeParameter.typeConstructor,
listOf(),
false,
scopeForTypeParameter)
}
private fun getScopeForTypeParameter(c: TypeResolutionContext, typeParameterDescriptor: TypeParameterDescriptor): MemberScope {
@@ -81,7 +81,7 @@ fun replaceReturnTypeForCallable(type: KotlinType, given: KotlinType): KotlinTyp
fun replaceReturnTypeByUnknown(type: KotlinType) = replaceReturnTypeForCallable(type, DONT_CARE)
private fun replaceTypeArguments(type: KotlinType, newArguments: List<TypeProjection>) =
KotlinTypeFactory.simpleType(type.annotations, type.constructor, newArguments, type.isMarkedNullable, type.memberScope)
KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(type.annotations, type.constructor, newArguments, type.isMarkedNullable, type.memberScope)
private fun getParameterArgumentsOfCallableType(type: KotlinType) =
type.arguments.dropLast(1)
@@ -126,8 +126,8 @@ fun getErasedReceiverType(receiverParameterDescriptor: ReceiverParameterDescript
receiverType.constructor
}
return KotlinTypeFactory.simpleType(receiverType.annotations, receiverTypeConstructor, fakeTypeArguments,
receiverType.isMarkedNullable, ErrorUtils.createErrorScope("Error scope for erased receiver type", /*throwExceptions=*/true))
return KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(receiverType.annotations, receiverTypeConstructor, fakeTypeArguments,
receiverType.isMarkedNullable, ErrorUtils.createErrorScope("Error scope for erased receiver type", /*throwExceptions=*/true))
}
fun isOrOverridesSynthesized(descriptor: CallableMemberDescriptor): Boolean {
@@ -234,7 +234,7 @@ public class CommonSupertypes {
else {
newScope = ErrorUtils.createErrorScope("A scope for common supertype which is not a normal classifier", true);
}
return KotlinTypeFactory.simpleType(Annotations.Companion.getEMPTY(), constructor, newProjections, nullable, newScope);
return KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(Annotations.Companion.getEMPTY(), constructor, newProjections, nullable, newScope);
}
@NotNull
@@ -134,7 +134,7 @@ public class TypeIntersector {
IntersectionTypeConstructor constructor = new IntersectionTypeConstructor(resultingTypes);
return KotlinTypeFactory.simpleType(
return KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(
Annotations.Companion.getEMPTY(),
constructor,
Collections.emptyList(),
@@ -78,7 +78,7 @@ class JvmSharedVariablesManager(val builtIns: KotlinBuiltIns) : SharedVariablesM
ClassConstructorDescriptorImpl.create(genericRefClass, Annotations.EMPTY, true, SourceElement.NO_SOURCE).apply {
initialize(emptyList(), Visibilities.PUBLIC)
val typeParameter = typeParameters[0]
val typeParameterType = KotlinTypeFactory.simpleType(Annotations.EMPTY, typeParameter.typeConstructor, listOf(), false, MemberScope.Empty)
val typeParameterType = KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(Annotations.EMPTY, typeParameter.typeConstructor, listOf(), false, MemberScope.Empty)
returnType = KotlinTypeFactory.simpleNotNullType(Annotations.EMPTY, genericRefClass, listOf(TypeProjectionImpl(Variance.INVARIANT, typeParameterType)))
}
@@ -182,7 +182,7 @@ class JvmSharedVariablesManager(val builtIns: KotlinBuiltIns) : SharedVariablesM
private fun getSharedVariableType(valueType: KotlinType): KotlinType =
primitiveRefDescriptorProviders[getPrimitiveType(valueType)]?.refType ?:
objectRefDescriptorsProvider.getRefType(valueType)
private fun getPrimitiveType(type: KotlinType): PrimitiveType? =
when {
KotlinBuiltIns.isBoolean(type) -> PrimitiveType.BOOLEAN
@@ -46,7 +46,7 @@ sealed class NewTypeVariable(builtIns: KotlinBuiltIns, name: String) {
// member scope is used if we have receiver with type TypeVariable(T)
// todo add to member scope methods from supertypes for type variable
val defaultType: SimpleType = KotlinTypeFactory.simpleType(
val defaultType: SimpleType = KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(
Annotations.EMPTY, freshTypeConstructor, arguments = emptyList(),
nullable = false, memberScope = builtIns.any.unsubstitutedMemberScope)
@@ -61,4 +61,4 @@ class TypeVariableForLambdaReturnType(
val lambdaArgument: LambdaKotlinCallArgument,
builtIns: KotlinBuiltIns,
name: String
) : NewTypeVariable(builtIns, name)
) : NewTypeVariable(builtIns, name)
@@ -64,8 +64,8 @@ class ConstraintSystemTestData(
val matcher = INTEGER_VALUE_TYPE_PATTERN.matcher(name)
if (matcher.find()) {
val number = matcher.group(1)!!
return KotlinTypeFactory.simpleType(Annotations.EMPTY, IntegerValueTypeConstructor(number.toLong(), functionFoo.builtIns),
listOf(), false, MemberScope.Empty
return KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(Annotations.EMPTY, IntegerValueTypeConstructor(number.toLong(), functionFoo.builtIns),
listOf(), false, MemberScope.Empty
)
}
return typeResolver.resolveType(
@@ -125,7 +125,7 @@ internal object RawSubstitution : TypeSubstitution() {
if (type.isError) return ErrorUtils.createErrorType("Raw error type: ${type.constructor}") to false
return KotlinTypeFactory.simpleType(
return KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(
type.annotations, type.constructor,
type.constructor.parameters.map {
parameter ->
@@ -68,7 +68,7 @@ public abstract class AbstractTypeParameterDescriptor extends DeclarationDescrip
this.defaultType = storageManager.createLazyValue(new Function0<SimpleType>() {
@Override
public SimpleType invoke() {
return KotlinTypeFactory.simpleType(
return KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(
Annotations.Companion.getEMPTY(),
getTypeConstructor(), Collections.<TypeProjection>emptyList(), false,
new LazyScopeAdapter(storageManager.createLazyValue(
@@ -99,8 +99,8 @@ class IntegerValueTypeConstant(
}
}
val unknownIntegerType = KotlinTypeFactory.simpleType(Annotations.EMPTY, typeConstructor, emptyList<TypeProjection>(),
false, ErrorUtils.createErrorScope("Scope for number value type (" + typeConstructor.toString() + ")", true)
val unknownIntegerType = KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(Annotations.EMPTY, typeConstructor, emptyList<TypeProjection>(),
false, ErrorUtils.createErrorScope("Scope for number value type (" + typeConstructor.toString() + ")", true)
)
fun getType(expectedType: KotlinType): KotlinType = TypeUtils.getPrimitiveNumberType(typeConstructor, expectedType)
@@ -50,11 +50,11 @@ object KotlinTypeFactory {
return constructor.declarationDescriptor!!.defaultType
}
return simpleType(annotations, constructor, arguments, nullable, computeMemberScope(constructor, arguments))
return simpleTypeWithNonTrivialMemberScope(annotations, constructor, arguments, nullable, computeMemberScope(constructor, arguments))
}
@JvmStatic
fun simpleType(
fun simpleTypeWithNonTrivialMemberScope(
annotations: Annotations,
constructor: TypeConstructor,
arguments: List<TypeProjection>,
@@ -135,7 +135,7 @@ fun SimpleType.replace(
if (newArguments.isEmpty() && newAnnotations === annotations) return this
if (newArguments.isEmpty()) {
return KotlinTypeFactory.simpleType(
return KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(
newAnnotations,
constructor,
arguments,
@@ -197,7 +197,7 @@ public class TypeUtils {
}
TypeConstructor typeConstructor = classifierDescriptor.getTypeConstructor();
List<TypeProjection> arguments = getDefaultTypeProjections(typeConstructor.getParameters());
return KotlinTypeFactory.simpleType(
return KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(
Annotations.Companion.getEMPTY(),
typeConstructor,
arguments,
@@ -121,7 +121,7 @@ object TypeIntersector {
if (filteredSuperAndEqualTypes.size < 2) return filteredSuperAndEqualTypes.single()
val constructor = IntersectionTypeConstructor(inputTypes)
return KotlinTypeFactory.simpleType(Annotations.EMPTY, constructor, listOf(), false, constructor.createScopeForKotlinType())
return KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(Annotations.EMPTY, constructor, listOf(), false, constructor.createScopeForKotlinType())
}
private fun isStrictSupertype(subtype: KotlinType, supertype: KotlinType): Boolean {
@@ -165,4 +165,4 @@ object TypeIntersector {
}
}
}
}
}
@@ -142,13 +142,13 @@ object NewKotlinTypeChecker : KotlinTypeChecker {
is IntegerValueTypeConstructor -> {
val newConstructor = IntersectionTypeConstructor(constructor.supertypes.map { TypeUtils.makeNullableAsSpecified(it, type.isMarkedNullable) })
return KotlinTypeFactory.simpleType(type.annotations, newConstructor, listOf(), false, type.memberScope)
return KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(type.annotations, newConstructor, listOf(), false, type.memberScope)
}
is IntersectionTypeConstructor -> if (type.isMarkedNullable) {
val newSuperTypes = constructor.supertypes.map { it.makeNullable() }
val newConstructor = IntersectionTypeConstructor(newSuperTypes)
return KotlinTypeFactory.simpleType(type.annotations, newConstructor, listOf(), false, newConstructor.createScopeForKotlinType())
return KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(type.annotations, newConstructor, listOf(), false, newConstructor.createScopeForKotlinType())
}
}
@@ -76,11 +76,11 @@ private fun KotlinType.approximateNonDynamicFlexibleTypes(
(unwrap() as? AbbreviatedType)?.let {
return AbbreviatedType(it.expandedType, it.abbreviation.approximateNonDynamicFlexibleTypes(preferNotNull))
}
return KotlinTypeFactory.simpleType(annotations,
constructor,
arguments.map { it.substitute { type -> type.approximateFlexibleTypes(preferNotNull = true) } },
isMarkedNullable,
ErrorUtils.createErrorScope("This type is not supposed to be used in member resolution", true)
return KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(annotations,
constructor,
arguments.map { it.substitute { type -> type.approximateFlexibleTypes(preferNotNull = true) } },
isMarkedNullable,
ErrorUtils.createErrorScope("This type is not supposed to be used in member resolution", true)
)
}
@@ -155,4 +155,4 @@ fun KotlinType.getResolvableApproximations(
fun KotlinType.isAbstract(): Boolean {
val modality = (constructor.declarationDescriptor as? ClassDescriptor)?.modality
return modality == Modality.ABSTRACT || modality == Modality.SEALED
}
}
@@ -286,7 +286,7 @@ internal fun KotlinType.substitute(substitution: KotlinTypeSubstitution, varianc
val (projection, typeParameter) = pair
TypeProjectionImpl(Variance.INVARIANT, projection.type.substitute(substitution, typeParameter.variance))
}
KotlinTypeFactory.simpleType(annotations, constructor, newArguments, isMarkedNullable, memberScope)
KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(annotations, constructor, newArguments, isMarkedNullable, memberScope)
}
}
@@ -51,7 +51,7 @@ object CreateIteratorFunctionActionFactory : CreateCallableMemberFromUsageFactor
val returnJetTypeParameterType = TypeProjectionImpl(returnJetTypeParameterTypes[0])
val returnJetTypeArguments = Collections.singletonList(returnJetTypeParameterType)
val newReturnJetType = KotlinTypeFactory.simpleType(returnJetType.annotations,
val newReturnJetType = KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(returnJetType.annotations,
returnJetType.constructor,
returnJetTypeArguments,
returnJetType.isMarkedNullable,
@@ -101,7 +101,7 @@ private object ForceTypeCopySubstitution : TypeSubstitution() {
override fun get(key: KotlinType) =
with(key) {
if (isError) return@with asTypeProjection()
KotlinTypeFactory.simpleType(annotations, constructor, arguments, isMarkedNullable, memberScope).asTypeProjection()
KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(annotations, constructor, arguments, isMarkedNullable, memberScope).asTypeProjection()
}
override fun isEmpty() = false
@@ -118,4 +118,4 @@ fun suggestReceiverNames(project: Project, descriptor: CallableDescriptor): List
} ?: CollectingNameValidator(paramNames)
val receiverType = descriptor.extensionReceiverParameter?.type ?: return emptyList()
return KotlinNameSuggester.suggestNamesByType(receiverType, validator, "receiver")
}
}