Minor. simplified creation of simple type with default scope.

This commit is contained in:
Stanislav Erokhin
2016-06-04 02:21:06 +03:00
parent 0bec639b07
commit de97bc2a05
8 changed files with 19 additions and 25 deletions
@@ -44,7 +44,7 @@ class JavaClassOnCompanionChecker : CallChecker {
val arguments = listOf(TypeProjectionImpl(containingClass.defaultType))
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))
}
}
@@ -471,7 +471,7 @@ class TypeResolver(
}
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)
}
else {
@@ -220,7 +220,7 @@ class DoubleColonExpressionResolver(
val arguments = descriptor.typeConstructor.parameters.map(TypeUtils::makeStarProjection)
KotlinTypeFactory.simpleType(
Annotations.EMPTY, descriptor.typeConstructor, arguments,
possiblyBareType.isNullable || doubleColonExpression.hasQuestionMarks, descriptor.getMemberScope(arguments)
possiblyBareType.isNullable || doubleColonExpression.hasQuestionMarks
)
}
else {
@@ -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? {
@@ -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
}
@@ -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
)
}