Minor. simplified creation of simple type with default scope.
This commit is contained in:
+1
-2
@@ -114,9 +114,8 @@ class JavaTypeResolver(
|
||||
val constructor = computeTypeConstructor(javaType, attr) ?: return null
|
||||
val arguments = computeArguments(javaType, attr, constructor)
|
||||
val isNullable = isNullable(javaType, attr)
|
||||
val memberScope = AbstractLazyType.computeMemberScope(constructor, arguments)
|
||||
|
||||
return KotlinTypeFactory.simpleType(annotations, constructor, arguments, isNullable, memberScope)
|
||||
return KotlinTypeFactory.simpleType(annotations, constructor, arguments, isNullable)
|
||||
}
|
||||
|
||||
private fun computeTypeConstructor(javaType: JavaClassifierType, attr: JavaTypeAttributes): TypeConstructor? {
|
||||
|
||||
+1
-2
@@ -121,8 +121,7 @@ internal object RawSubstitution : TypeSubstitution() {
|
||||
TypeProjectionImpl(componentTypeProjection.projectionKind, eraseType(componentTypeProjection.type))
|
||||
)
|
||||
return KotlinTypeFactory.simpleType(
|
||||
type.annotations, type.constructor, arguments, type.isMarkedNullable,
|
||||
declaration.getMemberScope(arguments)
|
||||
type.annotations, type.constructor, arguments, type.isMarkedNullable
|
||||
) to false
|
||||
}
|
||||
|
||||
|
||||
+1
-6
@@ -129,16 +129,11 @@ private fun SimpleType.enhanceInflexible(qualifiers: (Int) -> JavaTypeQualifiers
|
||||
enhancedNullabilityAnnotations
|
||||
).filterNotNull().compositeAnnotationsOrSingle()
|
||||
|
||||
val newSubstitution = TypeConstructorSubstitution.create(typeConstructor, enhancedArguments)
|
||||
|
||||
val enhancedType = KotlinTypeFactory.simpleType(
|
||||
newAnnotations,
|
||||
typeConstructor,
|
||||
enhancedArguments,
|
||||
enhancedNullability,
|
||||
if (enhancedClassifier is ClassDescriptor)
|
||||
enhancedClassifier.getMemberScope(newSubstitution)
|
||||
else enhancedClassifier.defaultType.memberScope
|
||||
enhancedNullability
|
||||
)
|
||||
|
||||
val result = if (effectiveQualifiers.isNotNullTypeParameter) NotNullTypeParameter(enhancedType) else enhancedType
|
||||
|
||||
@@ -17,10 +17,21 @@
|
||||
package org.jetbrains.kotlin.types
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.TypeAliasDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||
|
||||
object KotlinTypeFactory {
|
||||
private fun computeMemberScope(constructor: TypeConstructor, arguments: List<TypeProjection>): MemberScope {
|
||||
val descriptor = constructor.declarationDescriptor
|
||||
return when (descriptor) {
|
||||
is TypeParameterDescriptor -> descriptor.getDefaultType().memberScope
|
||||
is ClassDescriptor -> descriptor.getMemberScope(TypeConstructorSubstitution.create(constructor, arguments))
|
||||
is TypeAliasDescriptor -> ErrorUtils.createErrorScope("Scope for abbreviation: ${descriptor.name}", true)
|
||||
else -> throw IllegalStateException("Unsupported classifier: $descriptor for constructor: $constructor")
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun simpleType(
|
||||
@@ -28,7 +39,7 @@ object KotlinTypeFactory {
|
||||
constructor: TypeConstructor,
|
||||
arguments: List<TypeProjection>,
|
||||
nullable: Boolean,
|
||||
memberScope: MemberScope
|
||||
memberScope: MemberScope = computeMemberScope(constructor, arguments)
|
||||
): SimpleType = SimpleTypeImpl(annotations, constructor, arguments, nullable, memberScope)
|
||||
|
||||
@JvmStatic
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.types
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
|
||||
@@ -145,20 +144,11 @@ fun SimpleType.replace(
|
||||
)
|
||||
}
|
||||
|
||||
val newSubstitution = TypeConstructorSubstitution.create(constructor, newArguments)
|
||||
|
||||
val declarationDescriptor = constructor.declarationDescriptor
|
||||
val newScope =
|
||||
if (declarationDescriptor is ClassDescriptor)
|
||||
declarationDescriptor.getMemberScope(newSubstitution)
|
||||
else ErrorUtils.createErrorScope("Unexpected declaration descriptor for type constructor: $constructor")
|
||||
|
||||
return KotlinTypeFactory.simpleType(
|
||||
newAnnotations,
|
||||
constructor,
|
||||
newArguments,
|
||||
isMarkedNullable,
|
||||
newScope
|
||||
isMarkedNullable
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user