Minor. simplified creation of simple type with default scope.
This commit is contained in:
+1
-1
@@ -44,7 +44,7 @@ class JavaClassOnCompanionChecker : CallChecker {
|
|||||||
|
|
||||||
val arguments = listOf(TypeProjectionImpl(containingClass.defaultType))
|
val arguments = listOf(TypeProjectionImpl(containingClass.defaultType))
|
||||||
val expectedType = KotlinTypeFactory.simpleType(Annotations.EMPTY, javaLangClass.typeConstructor, arguments,
|
val expectedType = KotlinTypeFactory.simpleType(Annotations.EMPTY, javaLangClass.typeConstructor, arguments,
|
||||||
actualType.isMarkedNullable, javaLangClass.getMemberScope(arguments))
|
actualType.isMarkedNullable)
|
||||||
context.trace.report(ErrorsJvm.JAVA_CLASS_ON_COMPANION.on(resolvedCall.call.callElement, actualType, expectedType))
|
context.trace.report(ErrorsJvm.JAVA_CLASS_ON_COMPANION.on(resolvedCall.call.callElement, actualType, expectedType))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -471,7 +471,7 @@ class TypeResolver(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return if (c.abbreviated) {
|
return if (c.abbreviated) {
|
||||||
val abbreviatedType = KotlinTypeFactory.simpleType(annotations, descriptor.typeConstructor, arguments, false, MemberScope.Empty)
|
val abbreviatedType = KotlinTypeFactory.simpleType(annotations, descriptor.typeConstructor, arguments, false)
|
||||||
type(abbreviatedType)
|
type(abbreviatedType)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
+1
-1
@@ -220,7 +220,7 @@ class DoubleColonExpressionResolver(
|
|||||||
val arguments = descriptor.typeConstructor.parameters.map(TypeUtils::makeStarProjection)
|
val arguments = descriptor.typeConstructor.parameters.map(TypeUtils::makeStarProjection)
|
||||||
KotlinTypeFactory.simpleType(
|
KotlinTypeFactory.simpleType(
|
||||||
Annotations.EMPTY, descriptor.typeConstructor, arguments,
|
Annotations.EMPTY, descriptor.typeConstructor, arguments,
|
||||||
possiblyBareType.isNullable || doubleColonExpression.hasQuestionMarks, descriptor.getMemberScope(arguments)
|
possiblyBareType.isNullable || doubleColonExpression.hasQuestionMarks
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
+1
-2
@@ -114,9 +114,8 @@ class JavaTypeResolver(
|
|||||||
val constructor = computeTypeConstructor(javaType, attr) ?: return null
|
val constructor = computeTypeConstructor(javaType, attr) ?: return null
|
||||||
val arguments = computeArguments(javaType, attr, constructor)
|
val arguments = computeArguments(javaType, attr, constructor)
|
||||||
val isNullable = isNullable(javaType, attr)
|
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? {
|
private fun computeTypeConstructor(javaType: JavaClassifierType, attr: JavaTypeAttributes): TypeConstructor? {
|
||||||
|
|||||||
+1
-2
@@ -121,8 +121,7 @@ internal object RawSubstitution : TypeSubstitution() {
|
|||||||
TypeProjectionImpl(componentTypeProjection.projectionKind, eraseType(componentTypeProjection.type))
|
TypeProjectionImpl(componentTypeProjection.projectionKind, eraseType(componentTypeProjection.type))
|
||||||
)
|
)
|
||||||
return KotlinTypeFactory.simpleType(
|
return KotlinTypeFactory.simpleType(
|
||||||
type.annotations, type.constructor, arguments, type.isMarkedNullable,
|
type.annotations, type.constructor, arguments, type.isMarkedNullable
|
||||||
declaration.getMemberScope(arguments)
|
|
||||||
) to false
|
) to false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-6
@@ -129,16 +129,11 @@ private fun SimpleType.enhanceInflexible(qualifiers: (Int) -> JavaTypeQualifiers
|
|||||||
enhancedNullabilityAnnotations
|
enhancedNullabilityAnnotations
|
||||||
).filterNotNull().compositeAnnotationsOrSingle()
|
).filterNotNull().compositeAnnotationsOrSingle()
|
||||||
|
|
||||||
val newSubstitution = TypeConstructorSubstitution.create(typeConstructor, enhancedArguments)
|
|
||||||
|
|
||||||
val enhancedType = KotlinTypeFactory.simpleType(
|
val enhancedType = KotlinTypeFactory.simpleType(
|
||||||
newAnnotations,
|
newAnnotations,
|
||||||
typeConstructor,
|
typeConstructor,
|
||||||
enhancedArguments,
|
enhancedArguments,
|
||||||
enhancedNullability,
|
enhancedNullability
|
||||||
if (enhancedClassifier is ClassDescriptor)
|
|
||||||
enhancedClassifier.getMemberScope(newSubstitution)
|
|
||||||
else enhancedClassifier.defaultType.memberScope
|
|
||||||
)
|
)
|
||||||
|
|
||||||
val result = if (effectiveQualifiers.isNotNullTypeParameter) NotNullTypeParameter(enhancedType) else enhancedType
|
val result = if (effectiveQualifiers.isNotNullTypeParameter) NotNullTypeParameter(enhancedType) else enhancedType
|
||||||
|
|||||||
@@ -17,10 +17,21 @@
|
|||||||
package org.jetbrains.kotlin.types
|
package org.jetbrains.kotlin.types
|
||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
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.descriptors.annotations.Annotations
|
||||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||||
|
|
||||||
object KotlinTypeFactory {
|
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
|
@JvmStatic
|
||||||
fun simpleType(
|
fun simpleType(
|
||||||
@@ -28,7 +39,7 @@ object KotlinTypeFactory {
|
|||||||
constructor: TypeConstructor,
|
constructor: TypeConstructor,
|
||||||
arguments: List<TypeProjection>,
|
arguments: List<TypeProjection>,
|
||||||
nullable: Boolean,
|
nullable: Boolean,
|
||||||
memberScope: MemberScope
|
memberScope: MemberScope = computeMemberScope(constructor, arguments)
|
||||||
): SimpleType = SimpleTypeImpl(annotations, constructor, arguments, nullable, memberScope)
|
): SimpleType = SimpleTypeImpl(annotations, constructor, arguments, nullable, memberScope)
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.types
|
package org.jetbrains.kotlin.types
|
||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
|
||||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
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(
|
return KotlinTypeFactory.simpleType(
|
||||||
newAnnotations,
|
newAnnotations,
|
||||||
constructor,
|
constructor,
|
||||||
newArguments,
|
newArguments,
|
||||||
isMarkedNullable,
|
isMarkedNullable
|
||||||
newScope
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user