Fixes and refactors
This commit is contained in:
committed by
Dmitriy Novozhilov
parent
2e2e70fede
commit
19bfc43bee
@@ -341,7 +341,7 @@ class CollectionStubMethodGenerator(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun newType(classDescriptor: ClassDescriptor, typeArguments: List<TypeProjection>): KotlinType {
|
private fun newType(classDescriptor: ClassDescriptor, typeArguments: List<TypeProjection>): KotlinType {
|
||||||
return KotlinTypeFactory.simpleNotNullType(Annotations.EMPTY, classDescriptor, typeArguments)
|
return KotlinTypeFactory.simpleNotNullType(TypeAttributes.Empty, classDescriptor, typeArguments)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun FunctionDescriptor.signature(): JvmMethodGenericSignature =
|
private fun FunctionDescriptor.signature(): JvmMethodGenericSignature =
|
||||||
|
|||||||
@@ -402,16 +402,20 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo
|
|||||||
|
|
||||||
override fun unionTypeAttributes(types: List<KotlinTypeMarker>): List<AnnotationMarker> {
|
override fun unionTypeAttributes(types: List<KotlinTypeMarker>): List<AnnotationMarker> {
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
types as List<ConeKotlinType>
|
return (types as List<ConeKotlinType>).map { it.attributes }.reduce { x, y -> x.union(y) }.toList()
|
||||||
return types.map { it.attributes }.reduce { x, y -> x.union(y) }.toList()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun KotlinTypeMarker.replaceTypeAttributes(newAttributes: List<AnnotationMarker>): KotlinTypeMarker {
|
override fun KotlinTypeMarker.replaceTypeAttributes(newAttributes: List<AnnotationMarker>): KotlinTypeMarker {
|
||||||
require(this is ConeKotlinType)
|
require(this is ConeKotlinType)
|
||||||
val typeAttributes = newAttributes.filterIsInstance<ConeAttribute<*>>()
|
|
||||||
require(typeAttributes.size == newAttributes.size)
|
|
||||||
if (newAttributes.isEmpty()) return this
|
if (newAttributes.isEmpty()) return this
|
||||||
return createSimpleType(this.typeConstructor(), this.getArguments(), this.isNullable, this.isExtensionFunctionType, typeAttributes)
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
return createSimpleType(
|
||||||
|
this.typeConstructor(),
|
||||||
|
this.getArguments(),
|
||||||
|
this.isNullable,
|
||||||
|
this.isExtensionFunctionType,
|
||||||
|
newAttributes as List<ConeAttribute<*>>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun TypeConstructorMarker.getApproximatedIntegerLiteralType(): KotlinTypeMarker {
|
override fun TypeConstructorMarker.getApproximatedIntegerLiteralType(): KotlinTypeMarker {
|
||||||
|
|||||||
@@ -420,6 +420,12 @@ interface ConeTypeContext : TypeSystemContext, TypeSystemOptimizationContext, Ty
|
|||||||
return attributes.toList()
|
return attributes.toList()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun KotlinTypeMarker.getCustomAttributes(): List<AnnotationMarker> {
|
||||||
|
require(this is ConeKotlinType)
|
||||||
|
val compilerAttributes = CompilerConeAttributes.classIdByCompilerAttribute
|
||||||
|
return attributes.filterNot { it in compilerAttributes || it is CustomAnnotationTypeAttribute }
|
||||||
|
}
|
||||||
|
|
||||||
override fun SimpleTypeMarker.isStubType(): Boolean {
|
override fun SimpleTypeMarker.isStubType(): Boolean {
|
||||||
return this is ConeStubType
|
return this is ConeStubType
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-10
@@ -24,22 +24,24 @@ import org.jetbrains.kotlin.resolve.BindingTrace
|
|||||||
import org.jetbrains.kotlin.resolve.DeclarationReturnTypeSanitizer
|
import org.jetbrains.kotlin.resolve.DeclarationReturnTypeSanitizer
|
||||||
import org.jetbrains.kotlin.types.UnwrappedType
|
import org.jetbrains.kotlin.types.UnwrappedType
|
||||||
import org.jetbrains.kotlin.types.WrappedTypeFactory
|
import org.jetbrains.kotlin.types.WrappedTypeFactory
|
||||||
|
import org.jetbrains.kotlin.types.replaceAnnotations
|
||||||
|
|
||||||
object JvmDeclarationReturnTypeSanitizer : DeclarationReturnTypeSanitizer {
|
object JvmDeclarationReturnTypeSanitizer : DeclarationReturnTypeSanitizer {
|
||||||
override fun sanitizeReturnType(
|
override fun sanitizeReturnType(
|
||||||
inferred: UnwrappedType,
|
inferred: UnwrappedType,
|
||||||
wrappedTypeFactory: WrappedTypeFactory,
|
wrappedTypeFactory: WrappedTypeFactory,
|
||||||
trace: BindingTrace,
|
trace: BindingTrace,
|
||||||
languageVersionSettings: LanguageVersionSettings
|
languageVersionSettings: LanguageVersionSettings
|
||||||
): UnwrappedType =
|
): UnwrappedType =
|
||||||
if (languageVersionSettings.supportsFeature(LanguageFeature.StrictJavaNullabilityAssertions)) {
|
if (languageVersionSettings.supportsFeature(LanguageFeature.StrictJavaNullabilityAssertions)) {
|
||||||
// NB can't check for presence of EnhancedNullability here,
|
// NB can't check for presence of EnhancedNullability here,
|
||||||
// because it will also cause recursion in declaration type resolution.
|
// because it will also cause recursion in declaration type resolution.
|
||||||
inferred.replaceAnnotations(
|
inferred.replaceAttributes(
|
||||||
|
inferred.attributes.replaceAnnotations(
|
||||||
FilteredAnnotations(inferred.annotations, languageVersionSettings.supportsFeature(LanguageFeature.NewInference)) {
|
FilteredAnnotations(inferred.annotations, languageVersionSettings.supportsFeature(LanguageFeature.NewInference)) {
|
||||||
it != JvmAnnotationNames.ENHANCED_NULLABILITY_ANNOTATION
|
it != JvmAnnotationNames.ENHANCED_NULLABILITY_ANNOTATION
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
)
|
||||||
else inferred
|
} else inferred
|
||||||
}
|
}
|
||||||
+4
-3
@@ -20,12 +20,12 @@ import com.intellij.psi.PsiElement
|
|||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
|
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
|
||||||
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker
|
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker
|
||||||
import org.jetbrains.kotlin.resolve.calls.checkers.CallCheckerContext
|
import org.jetbrains.kotlin.resolve.calls.checkers.CallCheckerContext
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm
|
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm
|
||||||
import org.jetbrains.kotlin.types.KotlinTypeFactory
|
import org.jetbrains.kotlin.types.KotlinTypeFactory
|
||||||
|
import org.jetbrains.kotlin.types.TypeAttributes
|
||||||
import org.jetbrains.kotlin.types.TypeProjectionImpl
|
import org.jetbrains.kotlin.types.TypeProjectionImpl
|
||||||
|
|
||||||
class JavaClassOnCompanionChecker : CallChecker {
|
class JavaClassOnCompanionChecker : CallChecker {
|
||||||
@@ -44,8 +44,9 @@ class JavaClassOnCompanionChecker : CallChecker {
|
|||||||
val javaLangClass = actualType.constructor.declarationDescriptor as? ClassDescriptor ?: return
|
val javaLangClass = actualType.constructor.declarationDescriptor as? ClassDescriptor ?: return
|
||||||
|
|
||||||
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(
|
||||||
actualType.isMarkedNullable)
|
TypeAttributes.Empty, javaLangClass.typeConstructor, arguments,
|
||||||
|
actualType.isMarkedNullable)
|
||||||
context.trace.report(ErrorsJvm.JAVA_CLASS_ON_COMPANION.on(reportOn, actualType, expectedType))
|
context.trace.report(ErrorsJvm.JAVA_CLASS_ON_COMPANION.on(reportOn, actualType, expectedType))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ import org.jetbrains.kotlin.types.expressions.DeclarationScopeProviderForLocalCl
|
|||||||
import org.jetbrains.kotlin.types.expressions.LocalClassDescriptorHolder
|
import org.jetbrains.kotlin.types.expressions.LocalClassDescriptorHolder
|
||||||
import org.jetbrains.kotlin.types.expressions.LocalLazyDeclarationResolver
|
import org.jetbrains.kotlin.types.expressions.LocalLazyDeclarationResolver
|
||||||
import org.jetbrains.kotlin.types.extensions.TypeAttributeTranslators
|
import org.jetbrains.kotlin.types.extensions.TypeAttributeTranslators
|
||||||
|
import org.jetbrains.kotlin.types.extensions.TypeAttributeTranslatorsForInjection
|
||||||
import org.jetbrains.kotlin.util.ProgressManagerBasedCancellationChecker
|
import org.jetbrains.kotlin.util.ProgressManagerBasedCancellationChecker
|
||||||
|
|
||||||
fun StorageComponentContainer.configureModule(
|
fun StorageComponentContainer.configureModule(
|
||||||
@@ -80,7 +81,7 @@ fun StorageComponentContainer.configureModule(
|
|||||||
analyzerServices.platformConfigurator.configureModuleComponents(this)
|
analyzerServices.platformConfigurator.configureModuleComponents(this)
|
||||||
analyzerServices.platformConfigurator.configureModuleDependentCheckers(this)
|
analyzerServices.platformConfigurator.configureModuleDependentCheckers(this)
|
||||||
|
|
||||||
useInstance(TypeAttributeTranslators(moduleContext.project).translators)
|
useImpl<TypeAttributeTranslatorsForInjection>()
|
||||||
|
|
||||||
for (extension in StorageComponentContainerContributor.getInstances(moduleContext.project)) {
|
for (extension in StorageComponentContainerContributor.getInstances(moduleContext.project)) {
|
||||||
extension.registerModuleComponents(this, platform, moduleContext.module)
|
extension.registerModuleComponents(this, platform, moduleContext.module)
|
||||||
|
|||||||
@@ -242,7 +242,7 @@ class DeclarationsChecker(
|
|||||||
private fun checkTypeAliasExpansion(declaration: KtTypeAlias, typeAliasDescriptor: TypeAliasDescriptor) {
|
private fun checkTypeAliasExpansion(declaration: KtTypeAlias, typeAliasDescriptor: TypeAliasDescriptor) {
|
||||||
val typeAliasExpansion = TypeAliasExpansion.createWithFormalArguments(typeAliasDescriptor)
|
val typeAliasExpansion = TypeAliasExpansion.createWithFormalArguments(typeAliasDescriptor)
|
||||||
val reportStrategy = TypeAliasDeclarationCheckingReportStrategy(trace, typeAliasDescriptor, declaration, upperBoundChecker)
|
val reportStrategy = TypeAliasDeclarationCheckingReportStrategy(trace, typeAliasDescriptor, declaration, upperBoundChecker)
|
||||||
TypeAliasExpander(reportStrategy, true).expandWithoutAbbreviation(typeAliasExpansion, Annotations.EMPTY)
|
TypeAliasExpander(reportStrategy, true).expandWithoutAbbreviation(typeAliasExpansion, TypeAttributes.Empty)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkConstructorDeclaration(constructorDescriptor: ClassConstructorDescriptor, declaration: KtConstructor<*>) {
|
private fun checkConstructorDeclaration(constructorDescriptor: ClassConstructorDescriptor, declaration: KtConstructor<*>) {
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ class TypeResolver(
|
|||||||
|
|
||||||
fun resolveExpandedTypeForTypeAlias(typeAliasDescriptor: TypeAliasDescriptor): SimpleType {
|
fun resolveExpandedTypeForTypeAlias(typeAliasDescriptor: TypeAliasDescriptor): SimpleType {
|
||||||
val typeAliasExpansion = TypeAliasExpansion.createWithFormalArguments(typeAliasDescriptor)
|
val typeAliasExpansion = TypeAliasExpansion.createWithFormalArguments(typeAliasDescriptor)
|
||||||
val expandedType = TypeAliasExpander.NON_REPORTING.expandWithoutAbbreviation(typeAliasExpansion, Annotations.EMPTY)
|
val expandedType = TypeAliasExpander.NON_REPORTING.expandWithoutAbbreviation(typeAliasExpansion, TypeAttributes.Empty)
|
||||||
return expandedType
|
return expandedType
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -523,7 +523,7 @@ class TypeResolver(
|
|||||||
ErrorUtils.createErrorType("?")
|
ErrorUtils.createErrorType("?")
|
||||||
else
|
else
|
||||||
KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(
|
KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(
|
||||||
typeAttributeTranslators.toAttributes(annotations),
|
typeAttributeTranslators.toAttributes(annotations, typeParameter.typeConstructor, containing),
|
||||||
typeParameter.typeConstructor,
|
typeParameter.typeConstructor,
|
||||||
listOf(),
|
listOf(),
|
||||||
false,
|
false,
|
||||||
@@ -605,7 +605,11 @@ class TypeResolver(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val resultingType =
|
val resultingType =
|
||||||
KotlinTypeFactory.simpleNotNullType(typeAttributeTranslators.toAttributes(annotations), classDescriptor, arguments)
|
KotlinTypeFactory.simpleNotNullType(
|
||||||
|
typeAttributeTranslators.toAttributes(annotations, classDescriptor.typeConstructor, c.scope.ownerDescriptor),
|
||||||
|
classDescriptor,
|
||||||
|
arguments
|
||||||
|
)
|
||||||
|
|
||||||
// We create flexible types by convention here
|
// We create flexible types by convention here
|
||||||
// This is not intended to be used in normal users' environments, only for tests and debugger etc
|
// This is not intended to be used in normal users' environments, only for tests and debugger etc
|
||||||
@@ -701,9 +705,11 @@ class TypeResolver(
|
|||||||
return createErrorTypeForTypeConstructor(c, projectionFromAllQualifierParts, typeConstructor)
|
return createErrorTypeForTypeConstructor(c, projectionFromAllQualifierParts, typeConstructor)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val attributes = typeAttributeTranslators.toAttributes(annotations, descriptor.typeConstructor, c.scope.ownerDescriptor)
|
||||||
|
|
||||||
return if (c.abbreviated) {
|
return if (c.abbreviated) {
|
||||||
val abbreviatedType = KotlinTypeFactory.simpleType(
|
val abbreviatedType = KotlinTypeFactory.simpleType(
|
||||||
typeAttributeTranslators.toAttributes(annotations),
|
attributes,
|
||||||
descriptor.typeConstructor,
|
descriptor.typeConstructor,
|
||||||
arguments,
|
arguments,
|
||||||
false
|
false
|
||||||
@@ -711,7 +717,7 @@ class TypeResolver(
|
|||||||
type(abbreviatedType)
|
type(abbreviatedType)
|
||||||
} else {
|
} else {
|
||||||
val typeAliasExpansion = TypeAliasExpansion.create(null, descriptor, arguments)
|
val typeAliasExpansion = TypeAliasExpansion.create(null, descriptor, arguments)
|
||||||
val expandedType = TypeAliasExpander(reportStrategy, c.checkBounds).expand(typeAliasExpansion, annotations)
|
val expandedType = TypeAliasExpander(reportStrategy, c.checkBounds).expand(typeAliasExpansion, attributes)
|
||||||
type(expandedType)
|
type(expandedType)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -331,7 +331,7 @@ class CallCompleter(
|
|||||||
val value = constant.getValue(TypeUtils.NO_EXPECTED_TYPE).safeAs<Number>()?.toLong() ?: return null
|
val value = constant.getValue(TypeUtils.NO_EXPECTED_TYPE).safeAs<Number>()?.toLong() ?: return null
|
||||||
val typeConstructor = IntegerValueTypeConstructor(value, moduleDescriptor, constant.parameters)
|
val typeConstructor = IntegerValueTypeConstructor(value, moduleDescriptor, constant.parameters)
|
||||||
return KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(
|
return KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(
|
||||||
Annotations.EMPTY, typeConstructor, emptyList(), false,
|
TypeAttributes.Empty, typeConstructor, emptyList(), false,
|
||||||
ErrorUtils.createErrorScope("Scope for number value type ($typeConstructor)", true)
|
ErrorUtils.createErrorScope("Scope for number value type ($typeConstructor)", true)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
-2
@@ -54,8 +54,6 @@ class TypeTemplate(
|
|||||||
typeVariable.originalTypeParameter.builtIns.nothingType,
|
typeVariable.originalTypeParameter.builtIns.nothingType,
|
||||||
typeVariable.originalTypeParameter.builtIns.anyType.makeNullableAsSpecified(nullable)
|
typeVariable.originalTypeParameter.builtIns.anyType.makeNullableAsSpecified(nullable)
|
||||||
) {
|
) {
|
||||||
override fun replaceAnnotations(newAnnotations: Annotations) = this
|
|
||||||
|
|
||||||
override fun replaceAttributes(newAttributes: TypeAttributes) = this
|
override fun replaceAttributes(newAttributes: TypeAttributes) = this
|
||||||
|
|
||||||
override fun makeNullableAsSpecified(newNullability: Boolean) = TypeTemplate(typeVariable, builderInferenceData, newNullability)
|
override fun makeNullableAsSpecified(newNullability: Boolean) = TypeTemplate(typeVariable, builderInferenceData, newNullability)
|
||||||
|
|||||||
+1
-1
@@ -394,7 +394,7 @@ class KotlinToResolvedCallTransformer(
|
|||||||
val value = constant.getValue(TypeUtils.NO_EXPECTED_TYPE).safeAs<Number>()?.toLong() ?: return null
|
val value = constant.getValue(TypeUtils.NO_EXPECTED_TYPE).safeAs<Number>()?.toLong() ?: return null
|
||||||
val typeConstructor = IntegerLiteralTypeConstructor(value, moduleDescriptor, constant.parameters)
|
val typeConstructor = IntegerLiteralTypeConstructor(value, moduleDescriptor, constant.parameters)
|
||||||
return KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(
|
return KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(
|
||||||
Annotations.EMPTY, typeConstructor, emptyList(), false,
|
TypeAttributes.Empty, typeConstructor, emptyList(), false,
|
||||||
ErrorUtils.createErrorScope("Scope for number value type ($typeConstructor)", true),
|
ErrorUtils.createErrorScope("Scope for number value type ($typeConstructor)", true),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ fun replaceReturnTypeForCallable(type: KotlinType, given: KotlinType): KotlinTyp
|
|||||||
fun replaceReturnTypeByUnknown(type: KotlinType) = replaceReturnTypeForCallable(type, DONT_CARE)
|
fun replaceReturnTypeByUnknown(type: KotlinType) = replaceReturnTypeForCallable(type, DONT_CARE)
|
||||||
|
|
||||||
private fun replaceTypeArguments(type: KotlinType, newArguments: List<TypeProjection>) =
|
private fun replaceTypeArguments(type: KotlinType, newArguments: List<TypeProjection>) =
|
||||||
KotlinTypeFactory.simpleType(type.annotations, type.constructor, newArguments, type.isMarkedNullable)
|
KotlinTypeFactory.simpleType(type.attributes, type.constructor, newArguments, type.isMarkedNullable)
|
||||||
|
|
||||||
private fun getParameterArgumentsOfCallableType(type: KotlinType) =
|
private fun getParameterArgumentsOfCallableType(type: KotlinType) =
|
||||||
type.arguments.dropLast(1)
|
type.arguments.dropLast(1)
|
||||||
@@ -126,7 +126,7 @@ fun getErasedReceiverType(receiverParameterDescriptor: ReceiverParameterDescript
|
|||||||
}
|
}
|
||||||
|
|
||||||
return KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(
|
return KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(
|
||||||
receiverType.annotations, receiverTypeConstructor, fakeTypeArguments,
|
receiverType.attributes, receiverTypeConstructor, fakeTypeArguments,
|
||||||
receiverType.isMarkedNullable, ErrorUtils.createErrorScope("Error scope for erased receiver type", /*throwExceptions=*/true)
|
receiverType.isMarkedNullable, ErrorUtils.createErrorScope("Error scope for erased receiver type", /*throwExceptions=*/true)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ import org.jetbrains.kotlin.storage.StorageManager
|
|||||||
import org.jetbrains.kotlin.storage.getValue
|
import org.jetbrains.kotlin.storage.getValue
|
||||||
import org.jetbrains.kotlin.types.AbbreviatedType
|
import org.jetbrains.kotlin.types.AbbreviatedType
|
||||||
import org.jetbrains.kotlin.types.ErrorUtils
|
import org.jetbrains.kotlin.types.ErrorUtils
|
||||||
|
import org.jetbrains.kotlin.types.typeUtil.replaceAnnotations
|
||||||
|
|
||||||
abstract class LazyAnnotationsContext(
|
abstract class LazyAnnotationsContext(
|
||||||
val annotationResolver: AnnotationResolver,
|
val annotationResolver: AnnotationResolver,
|
||||||
|
|||||||
@@ -272,7 +272,7 @@ public class CommonSupertypes {
|
|||||||
else {
|
else {
|
||||||
newScope = ErrorUtils.createErrorScope("A scope for common supertype which is not a normal classifier", true);
|
newScope = ErrorUtils.createErrorScope("A scope for common supertype which is not a normal classifier", true);
|
||||||
}
|
}
|
||||||
return KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(Annotations.Companion.getEMPTY(), constructor, newProjections, nullable, newScope);
|
return KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(TypeAttributes.Companion.getEmpty(), constructor, newProjections, nullable, newScope);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
+1
-1
@@ -498,7 +498,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,
|
TypeAttributes.Empty, descriptor.typeConstructor, arguments,
|
||||||
possiblyBareType.isNullable || doubleColonExpression.hasQuestionMarks
|
possiblyBareType.isNullable || doubleColonExpression.hasQuestionMarks
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -286,7 +286,7 @@ open class IrBasedTypeParameterDescriptor(owner: IrTypeParameter) : TypeParamete
|
|||||||
|
|
||||||
private val _defaultType: SimpleType by lazy {
|
private val _defaultType: SimpleType by lazy {
|
||||||
KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(
|
KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(
|
||||||
Annotations.EMPTY, typeConstructor, emptyList(), false,
|
TypeAttributes.Empty, typeConstructor, emptyList(), false,
|
||||||
LazyScopeAdapter {
|
LazyScopeAdapter {
|
||||||
TypeIntersectionScope.create(
|
TypeIntersectionScope.create(
|
||||||
"Scope for type parameter " + name.asString(),
|
"Scope for type parameter " + name.asString(),
|
||||||
|
|||||||
+2
-2
@@ -405,8 +405,8 @@ class IrBuiltInsOverDescriptors(
|
|||||||
|
|
||||||
override val checkNotNullSymbol = defineCheckNotNullOperator()
|
override val checkNotNullSymbol = defineCheckNotNullOperator()
|
||||||
|
|
||||||
private fun TypeConstructor.makeNonNullType() = KotlinTypeFactory.simpleType(Annotations.EMPTY, this, listOf(), false)
|
private fun TypeConstructor.makeNonNullType() = KotlinTypeFactory.simpleType(TypeAttributes.Empty, this, listOf(), false)
|
||||||
private fun TypeConstructor.makeNullableType() = KotlinTypeFactory.simpleType(Annotations.EMPTY, this, listOf(), true)
|
private fun TypeConstructor.makeNullableType() = KotlinTypeFactory.simpleType(TypeAttributes.Empty, this, listOf(), true)
|
||||||
|
|
||||||
override val dataClassArrayMemberHashCodeSymbol = defineOperator("dataClassArrayMemberHashCode", intType, listOf(anyType))
|
override val dataClassArrayMemberHashCodeSymbol = defineOperator("dataClassArrayMemberHashCode", intType, listOf(anyType))
|
||||||
|
|
||||||
|
|||||||
@@ -406,6 +406,11 @@ interface IrTypeSystemContext : TypeSystemContext, TypeSystemCommonSuperTypesCon
|
|||||||
return this.annotations.map { object : AnnotationMarker, IrElement by it {} }
|
return this.annotations.map { object : AnnotationMarker, IrElement by it {} }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun KotlinTypeMarker.getCustomAttributes(): List<AnnotationMarker> {
|
||||||
|
require(this is IrType)
|
||||||
|
return emptyList()
|
||||||
|
}
|
||||||
|
|
||||||
override fun createErrorType(debugName: String): SimpleTypeMarker {
|
override fun createErrorType(debugName: String): SimpleTypeMarker {
|
||||||
TODO("IrTypeSystemContext doesn't support constraint system resolution")
|
TODO("IrTypeSystemContext doesn't support constraint system resolution")
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-6
@@ -60,7 +60,14 @@ class MutableVariableWithConstraints private constructor(
|
|||||||
&& previousConstraint.isNullabilityConstraint == constraint.isNullabilityConstraint
|
&& previousConstraint.isNullabilityConstraint == constraint.isNullabilityConstraint
|
||||||
) {
|
) {
|
||||||
if (newConstraintIsUseless(previousConstraint, constraint)) {
|
if (newConstraintIsUseless(previousConstraint, constraint)) {
|
||||||
return previousConstraint to false
|
// Preserve constraints with different custom type attributes.
|
||||||
|
// This allows us to union type attributes in NewCommonSuperTypeCalculator.kt
|
||||||
|
with(context) {
|
||||||
|
val prevAttributes = previousConstraint.type.getCustomAttributes()
|
||||||
|
if (prevAttributes.isEmpty() || prevAttributes == constraint.type.getCustomAttributes()) {
|
||||||
|
return previousConstraint to false
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val isMatchingForSimplification = when (previousConstraint.kind) {
|
val isMatchingForSimplification = when (previousConstraint.kind) {
|
||||||
@@ -139,11 +146,7 @@ class MutableVariableWithConstraints private constructor(
|
|||||||
return false
|
return false
|
||||||
|
|
||||||
return when (old.kind) {
|
return when (old.kind) {
|
||||||
ConstraintKind.EQUALITY -> {
|
ConstraintKind.EQUALITY -> true
|
||||||
with(context) {
|
|
||||||
old.type.getAttributes() == new.type.getAttributes()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ConstraintKind.LOWER -> new.kind.isLower()
|
ConstraintKind.LOWER -> new.kind.isLower()
|
||||||
ConstraintKind.UPPER -> new.kind.isUpper()
|
ConstraintKind.UPPER -> new.kind.isUpper()
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -291,7 +291,7 @@ class KotlinConstraintSystemCompleter(
|
|||||||
csBuilder.registerVariable(returnVariable)
|
csBuilder.registerVariable(returnVariable)
|
||||||
val functionalType: KotlinType = csBuilder.buildCurrentSubstitutor().safeSubstitute(candidate.getSystem().asConstraintSystemCompleterContext(), atom.expectedType!!) as KotlinType
|
val functionalType: KotlinType = csBuilder.buildCurrentSubstitutor().safeSubstitute(candidate.getSystem().asConstraintSystemCompleterContext(), atom.expectedType!!) as KotlinType
|
||||||
val expectedType = KotlinTypeFactory.simpleType(
|
val expectedType = KotlinTypeFactory.simpleType(
|
||||||
functionalType.annotations,
|
functionalType.attributes,
|
||||||
functionalType.constructor,
|
functionalType.constructor,
|
||||||
functionalType.arguments.dropLast(1) + returnVariable.defaultType.asTypeProjection(),
|
functionalType.arguments.dropLast(1) + returnVariable.defaultType.asTypeProjection(),
|
||||||
functionalType.isMarkedNullable
|
functionalType.isMarkedNullable
|
||||||
|
|||||||
+3
-1
@@ -148,7 +148,9 @@ interface NewTypeSubstitutor : TypeSubstitutorMarker {
|
|||||||
// simple classifier type
|
// simple classifier type
|
||||||
var replacement = substituteNotNullTypeWithConstructor(typeConstructor) ?: return null
|
var replacement = substituteNotNullTypeWithConstructor(typeConstructor) ?: return null
|
||||||
if (keepAnnotation) {
|
if (keepAnnotation) {
|
||||||
replacement = replacement.replaceAnnotations(CompositeAnnotations(replacement.annotations, type.annotations))
|
replacement = replacement.replaceAttributes(
|
||||||
|
replacement.attributes.add(type.attributes)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
if (type.isMarkedNullable) {
|
if (type.isMarkedNullable) {
|
||||||
replacement = replacement.makeNullableAsSpecified(true)
|
replacement = replacement.makeNullableAsSpecified(true)
|
||||||
|
|||||||
+2
-6
@@ -23,15 +23,11 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
|||||||
import org.jetbrains.kotlin.resolve.calls.model.PostponableKotlinCallArgument
|
import org.jetbrains.kotlin.resolve.calls.model.PostponableKotlinCallArgument
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.hasOnlyInputTypesAnnotation
|
import org.jetbrains.kotlin.resolve.descriptorUtil.hasOnlyInputTypesAnnotation
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.*
|
||||||
import org.jetbrains.kotlin.types.KotlinTypeFactory
|
|
||||||
import org.jetbrains.kotlin.types.SimpleType
|
|
||||||
import org.jetbrains.kotlin.types.TypeConstructor
|
|
||||||
import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner
|
import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner
|
||||||
import org.jetbrains.kotlin.types.checker.NewTypeVariableConstructor
|
import org.jetbrains.kotlin.types.checker.NewTypeVariableConstructor
|
||||||
import org.jetbrains.kotlin.types.model.TypeVariableMarker
|
import org.jetbrains.kotlin.types.model.TypeVariableMarker
|
||||||
import org.jetbrains.kotlin.types.model.TypeVariableTypeConstructorMarker
|
import org.jetbrains.kotlin.types.model.TypeVariableTypeConstructorMarker
|
||||||
import org.jetbrains.kotlin.types.TypeRefinement
|
|
||||||
|
|
||||||
|
|
||||||
class TypeVariableTypeConstructor(
|
class TypeVariableTypeConstructor(
|
||||||
@@ -74,7 +70,7 @@ sealed class NewTypeVariable(
|
|||||||
fun TypeConstructor.typeForTypeVariable(): SimpleType {
|
fun TypeConstructor.typeForTypeVariable(): SimpleType {
|
||||||
require(this is TypeVariableTypeConstructor)
|
require(this is TypeVariableTypeConstructor)
|
||||||
return KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(
|
return KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(
|
||||||
Annotations.EMPTY, this, arguments = emptyList(),
|
TypeAttributes.Empty, this, arguments = emptyList(),
|
||||||
nullable = false, memberScope = builtIns.any.unsubstitutedMemberScope
|
nullable = false, memberScope = builtIns.any.unsubstitutedMemberScope
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -33,6 +33,7 @@ import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
|||||||
import org.jetbrains.kotlin.test.DummyTraces
|
import org.jetbrains.kotlin.test.DummyTraces
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
import org.jetbrains.kotlin.types.KotlinTypeFactory
|
import org.jetbrains.kotlin.types.KotlinTypeFactory
|
||||||
|
import org.jetbrains.kotlin.types.TypeAttributes
|
||||||
import java.util.regex.Pattern
|
import java.util.regex.Pattern
|
||||||
|
|
||||||
class ConstraintSystemTestData(
|
class ConstraintSystemTestData(
|
||||||
@@ -67,7 +68,7 @@ class ConstraintSystemTestData(
|
|||||||
val number = matcher.group(1)!!
|
val number = matcher.group(1)!!
|
||||||
val parameters = CompileTimeConstant.Parameters(false, false, false, false, false, false, false, false)
|
val parameters = CompileTimeConstant.Parameters(false, false, false, false, false, false, false, false)
|
||||||
return KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(
|
return KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(
|
||||||
Annotations.EMPTY,
|
TypeAttributes.Empty,
|
||||||
IntegerValueTypeConstructor(number.toLong(), functionFoo.module, parameters),
|
IntegerValueTypeConstructor(number.toLong(), functionFoo.module, parameters),
|
||||||
listOf(),
|
listOf(),
|
||||||
false,
|
false,
|
||||||
|
|||||||
@@ -500,6 +500,8 @@ interface TypeSystemContext : TypeSystemOptimizationContext {
|
|||||||
|
|
||||||
fun KotlinTypeMarker.getAttributes(): List<AnnotationMarker>
|
fun KotlinTypeMarker.getAttributes(): List<AnnotationMarker>
|
||||||
|
|
||||||
|
fun KotlinTypeMarker.getCustomAttributes(): List<AnnotationMarker>
|
||||||
|
|
||||||
fun substitutionSupertypePolicy(type: SimpleTypeMarker): TypeCheckerState.SupertypesPolicy
|
fun substitutionSupertypePolicy(type: SimpleTypeMarker): TypeCheckerState.SupertypesPolicy
|
||||||
|
|
||||||
fun KotlinTypeMarker.isTypeVariableType(): Boolean
|
fun KotlinTypeMarker.isTypeVariableType(): Boolean
|
||||||
|
|||||||
+1
-1
@@ -281,7 +281,7 @@ class LazyJavaClassDescriptor(
|
|||||||
else -> return null
|
else -> return null
|
||||||
}
|
}
|
||||||
|
|
||||||
return KotlinTypeFactory.simpleNotNullType(Annotations.EMPTY, classDescriptor, parametersAsTypeProjections)
|
return KotlinTypeFactory.simpleNotNullType(TypeAttributes.Empty, classDescriptor, parametersAsTypeProjections)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getPurelyImplementsFqNameFromAnnotation(): FqName? {
|
private fun getPurelyImplementsFqNameFromAnnotation(): FqName? {
|
||||||
|
|||||||
+3
-3
@@ -119,8 +119,8 @@ class JavaTypeResolver(
|
|||||||
attr: JavaTypeAttributes,
|
attr: JavaTypeAttributes,
|
||||||
lowerResult: SimpleType?
|
lowerResult: SimpleType?
|
||||||
): SimpleType? {
|
): SimpleType? {
|
||||||
val annotations =
|
val attributes =
|
||||||
lowerResult?.annotations ?: LazyJavaAnnotations(c, javaType)
|
lowerResult?.attributes ?: LazyJavaAnnotations(c, javaType).toDefaultAttributes()
|
||||||
val constructor = computeTypeConstructor(javaType, attr) ?: return null
|
val constructor = computeTypeConstructor(javaType, attr) ?: return null
|
||||||
val isNullable = attr.isNullable()
|
val isNullable = attr.isNullable()
|
||||||
|
|
||||||
@@ -130,7 +130,7 @@ class JavaTypeResolver(
|
|||||||
|
|
||||||
val arguments = computeArguments(javaType, attr, constructor)
|
val arguments = computeArguments(javaType, attr, constructor)
|
||||||
|
|
||||||
return KotlinTypeFactory.simpleType(annotations, constructor, arguments, isNullable)
|
return KotlinTypeFactory.simpleType(attributes, constructor, arguments, isNullable)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun computeTypeConstructor(javaType: JavaClassifierType, attr: JavaTypeAttributes): TypeConstructor? {
|
private fun computeTypeConstructor(javaType: JavaClassifierType, attr: JavaTypeAttributes): TypeConstructor? {
|
||||||
|
|||||||
@@ -54,9 +54,6 @@ class RawTypeImpl private constructor(lowerBound: SimpleType, upperBound: Simple
|
|||||||
return classDescriptor.getMemberScope(RawSubstitution())
|
return classDescriptor.getMemberScope(RawSubstitution())
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun replaceAnnotations(newAnnotations: Annotations) =
|
|
||||||
RawTypeImpl(lowerBound.replaceAnnotations(newAnnotations), upperBound.replaceAnnotations(newAnnotations))
|
|
||||||
|
|
||||||
override fun replaceAttributes(newAttributes: TypeAttributes) =
|
override fun replaceAttributes(newAttributes: TypeAttributes) =
|
||||||
RawTypeImpl(lowerBound.replaceAttributes(newAttributes), upperBound.replaceAttributes(newAttributes))
|
RawTypeImpl(lowerBound.replaceAttributes(newAttributes), upperBound.replaceAttributes(newAttributes))
|
||||||
|
|
||||||
@@ -148,7 +145,7 @@ internal class RawSubstitution(typeParameterUpperBoundEraser: TypeParameterUpper
|
|||||||
TypeProjectionImpl(componentTypeProjection.projectionKind, eraseType(componentTypeProjection.type, attr))
|
TypeProjectionImpl(componentTypeProjection.projectionKind, eraseType(componentTypeProjection.type, attr))
|
||||||
)
|
)
|
||||||
return KotlinTypeFactory.simpleType(
|
return KotlinTypeFactory.simpleType(
|
||||||
type.annotations, type.constructor, arguments, type.isMarkedNullable
|
type.attributes, type.constructor, arguments, type.isMarkedNullable
|
||||||
) to false
|
) to false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,7 +153,7 @@ internal class RawSubstitution(typeParameterUpperBoundEraser: TypeParameterUpper
|
|||||||
|
|
||||||
val memberScope = declaration.getMemberScope(this)
|
val memberScope = declaration.getMemberScope(this)
|
||||||
return KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(
|
return KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(
|
||||||
type.annotations, declaration.typeConstructor,
|
type.attributes, declaration.typeConstructor,
|
||||||
declaration.typeConstructor.parameters.map { parameter ->
|
declaration.typeConstructor.parameters.map { parameter ->
|
||||||
computeProjection(parameter, attr)
|
computeProjection(parameter, attr)
|
||||||
},
|
},
|
||||||
|
|||||||
+1
-2
@@ -150,7 +150,7 @@ class JavaTypeEnhancement(private val javaResolverSettings: JavaResolverSettings
|
|||||||
).compositeAnnotationsOrSingle()
|
).compositeAnnotationsOrSingle()
|
||||||
|
|
||||||
val enhancedType = KotlinTypeFactory.simpleType(
|
val enhancedType = KotlinTypeFactory.simpleType(
|
||||||
newAnnotations,
|
newAnnotations.toDefaultAttributes(),
|
||||||
typeConstructor,
|
typeConstructor,
|
||||||
enhancedArguments.zip(arguments) { enhanced, original -> enhanced ?: original },
|
enhancedArguments.zip(arguments) { enhanced, original -> enhanced ?: original },
|
||||||
enhancedNullability ?: isMarkedNullable
|
enhancedNullability ?: isMarkedNullable
|
||||||
@@ -252,7 +252,6 @@ internal class NotNullTypeParameterImpl(override val delegate: SimpleType) : Not
|
|||||||
return NotNullTypeParameterImpl(result)
|
return NotNullTypeParameterImpl(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun replaceAnnotations(newAnnotations: Annotations) = NotNullTypeParameterImpl(delegate.replaceAnnotations(newAnnotations))
|
|
||||||
override fun replaceAttributes(newAttributes: TypeAttributes) = NotNullTypeParameterImpl(delegate.replaceAttributes(newAttributes))
|
override fun replaceAttributes(newAttributes: TypeAttributes) = NotNullTypeParameterImpl(delegate.replaceAttributes(newAttributes))
|
||||||
override fun makeNullableAsSpecified(newNullability: Boolean) =
|
override fun makeNullableAsSpecified(newNullability: Boolean) =
|
||||||
if (newNullability) delegate.makeNullableAsSpecified(true) else this
|
if (newNullability) delegate.makeNullableAsSpecified(true) else this
|
||||||
|
|||||||
+8
-3
@@ -48,7 +48,9 @@ import org.jetbrains.kotlin.resolve.sam.SamConversionResolverImpl
|
|||||||
import org.jetbrains.kotlin.serialization.deserialization.*
|
import org.jetbrains.kotlin.serialization.deserialization.*
|
||||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
||||||
import org.jetbrains.kotlin.storage.StorageManager
|
import org.jetbrains.kotlin.storage.StorageManager
|
||||||
|
import org.jetbrains.kotlin.types.DefaultTypeAttributeTranslator
|
||||||
import org.jetbrains.kotlin.types.checker.NewKotlinTypeChecker
|
import org.jetbrains.kotlin.types.checker.NewKotlinTypeChecker
|
||||||
|
import org.jetbrains.kotlin.types.extensions.TypeAttributeTranslatorsForInjection
|
||||||
|
|
||||||
// This class is needed only for easier injection: exact types of needed components are specified in the constructor here.
|
// This class is needed only for easier injection: exact types of needed components are specified in the constructor here.
|
||||||
// Otherwise injector generator is not smart enough to deduce, for example, which package fragment provider DeserializationComponents needs
|
// Otherwise injector generator is not smart enough to deduce, for example, which package fragment provider DeserializationComponents needs
|
||||||
@@ -63,7 +65,8 @@ class DeserializationComponentsForJava(
|
|||||||
errorReporter: ErrorReporter,
|
errorReporter: ErrorReporter,
|
||||||
lookupTracker: LookupTracker,
|
lookupTracker: LookupTracker,
|
||||||
contractDeserializer: ContractDeserializer,
|
contractDeserializer: ContractDeserializer,
|
||||||
kotlinTypeChecker: NewKotlinTypeChecker
|
kotlinTypeChecker: NewKotlinTypeChecker,
|
||||||
|
typeAttributeTranslators: TypeAttributeTranslatorsForInjection
|
||||||
) {
|
) {
|
||||||
val components: DeserializationComponents
|
val components: DeserializationComponents
|
||||||
|
|
||||||
@@ -77,7 +80,8 @@ class DeserializationComponentsForJava(
|
|||||||
additionalClassPartsProvider = jvmBuiltIns?.customizer ?: AdditionalClassPartsProvider.None,
|
additionalClassPartsProvider = jvmBuiltIns?.customizer ?: AdditionalClassPartsProvider.None,
|
||||||
platformDependentDeclarationFilter = jvmBuiltIns?.customizer ?: PlatformDependentDeclarationFilter.NoPlatformDependent,
|
platformDependentDeclarationFilter = jvmBuiltIns?.customizer ?: PlatformDependentDeclarationFilter.NoPlatformDependent,
|
||||||
extensionRegistryLite = JvmProtoBufUtil.EXTENSION_REGISTRY,
|
extensionRegistryLite = JvmProtoBufUtil.EXTENSION_REGISTRY,
|
||||||
kotlinTypeChecker = kotlinTypeChecker, samConversionResolver = SamConversionResolverImpl(storageManager, emptyList())
|
kotlinTypeChecker = kotlinTypeChecker, samConversionResolver = SamConversionResolverImpl(storageManager, emptyList()),
|
||||||
|
typeAttributeTranslators = typeAttributeTranslators.translators
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,6 +192,7 @@ fun makeDeserializationComponentsForJava(
|
|||||||
return DeserializationComponentsForJava(
|
return DeserializationComponentsForJava(
|
||||||
storageManager, module, DeserializationConfiguration.Default, javaClassDataFinder,
|
storageManager, module, DeserializationConfiguration.Default, javaClassDataFinder,
|
||||||
binaryClassAnnotationAndConstantLoader, lazyJavaPackageFragmentProvider, notFoundClasses,
|
binaryClassAnnotationAndConstantLoader, lazyJavaPackageFragmentProvider, notFoundClasses,
|
||||||
errorReporter, LookupTracker.DO_NOTHING, ContractDeserializer.DEFAULT, NewKotlinTypeChecker.Default
|
errorReporter, LookupTracker.DO_NOTHING, ContractDeserializer.DEFAULT, NewKotlinTypeChecker.Default,
|
||||||
|
TypeAttributeTranslatorsForInjection(listOf(DefaultTypeAttributeTranslator))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ dependencies {
|
|||||||
api(project(":core:util.runtime"))
|
api(project(":core:util.runtime"))
|
||||||
api(kotlinStdlib())
|
api(kotlinStdlib())
|
||||||
api(project(":kotlin-annotations-jvm"))
|
api(project(":kotlin-annotations-jvm"))
|
||||||
api(project(":compiler:util"))
|
|
||||||
compileOnly(intellijCoreDep()) { includeJars("intellij-core") }
|
compileOnly(intellijCoreDep()) { includeJars("intellij-core") }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -665,7 +665,10 @@ public abstract class KotlinBuiltIns {
|
|||||||
@NotNull
|
@NotNull
|
||||||
public SimpleType getArrayType(@NotNull Variance projectionType, @NotNull KotlinType argument, @NotNull Annotations annotations) {
|
public SimpleType getArrayType(@NotNull Variance projectionType, @NotNull KotlinType argument, @NotNull Annotations annotations) {
|
||||||
List<TypeProjectionImpl> types = Collections.singletonList(new TypeProjectionImpl(projectionType, argument));
|
List<TypeProjectionImpl> types = Collections.singletonList(new TypeProjectionImpl(projectionType, argument));
|
||||||
return KotlinTypeFactory.simpleNotNullType(annotations, getArray(), types);
|
return KotlinTypeFactory.simpleNotNullType(
|
||||||
|
TypeAttributesKt.toDefaultAttributes(annotations),
|
||||||
|
getArray(),
|
||||||
|
types);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -677,7 +680,7 @@ public abstract class KotlinBuiltIns {
|
|||||||
public SimpleType getEnumType(@NotNull SimpleType argument) {
|
public SimpleType getEnumType(@NotNull SimpleType argument) {
|
||||||
Variance projectionType = Variance.INVARIANT;
|
Variance projectionType = Variance.INVARIANT;
|
||||||
List<TypeProjectionImpl> types = Collections.singletonList(new TypeProjectionImpl(projectionType, argument));
|
List<TypeProjectionImpl> types = Collections.singletonList(new TypeProjectionImpl(projectionType, argument));
|
||||||
return KotlinTypeFactory.simpleNotNullType(Annotations.Companion.getEMPTY(), getEnum(), types);
|
return KotlinTypeFactory.simpleNotNullType(TypeAttributes.Companion.getEmpty(), getEnum(), types);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ class ReflectionTypes(module: ModuleDescriptor, private val notFoundClasses: Not
|
|||||||
val kMutableProperty2: ClassDescriptor by ClassLookup(3)
|
val kMutableProperty2: ClassDescriptor by ClassLookup(3)
|
||||||
|
|
||||||
fun getKClassType(annotations: Annotations, type: KotlinType, variance: Variance): KotlinType =
|
fun getKClassType(annotations: Annotations, type: KotlinType, variance: Variance): KotlinType =
|
||||||
KotlinTypeFactory.simpleNotNullType(annotations, kClass, listOf(TypeProjectionImpl(variance, type)))
|
KotlinTypeFactory.simpleNotNullType(annotations.toDefaultAttributes(), kClass, listOf(TypeProjectionImpl(variance, type)))
|
||||||
|
|
||||||
fun getKFunctionType(
|
fun getKFunctionType(
|
||||||
annotations: Annotations,
|
annotations: Annotations,
|
||||||
@@ -69,7 +69,7 @@ class ReflectionTypes(module: ModuleDescriptor, private val notFoundClasses: Not
|
|||||||
getFunctionTypeArgumentProjections(receiverType, contextReceiverTypes, parameterTypes, parameterNames, returnType, builtIns)
|
getFunctionTypeArgumentProjections(receiverType, contextReceiverTypes, parameterTypes, parameterNames, returnType, builtIns)
|
||||||
val classDescriptor =
|
val classDescriptor =
|
||||||
if (isSuspend) getKSuspendFunction(arguments.size - 1 /* return type */) else getKFunction(arguments.size - 1 /* return type */)
|
if (isSuspend) getKSuspendFunction(arguments.size - 1 /* return type */) else getKFunction(arguments.size - 1 /* return type */)
|
||||||
return KotlinTypeFactory.simpleNotNullType(annotations, classDescriptor, arguments)
|
return KotlinTypeFactory.simpleNotNullType(annotations.toDefaultAttributes(), classDescriptor, arguments)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getKPropertyType(annotations: Annotations, receiverTypes: List<KotlinType>, returnType: KotlinType, mutable: Boolean): SimpleType {
|
fun getKPropertyType(annotations: Annotations, receiverTypes: List<KotlinType>, returnType: KotlinType, mutable: Boolean): SimpleType {
|
||||||
@@ -90,7 +90,7 @@ class ReflectionTypes(module: ModuleDescriptor, private val notFoundClasses: Not
|
|||||||
}
|
}
|
||||||
|
|
||||||
val arguments = (receiverTypes + returnType).map(::TypeProjectionImpl)
|
val arguments = (receiverTypes + returnType).map(::TypeProjectionImpl)
|
||||||
return KotlinTypeFactory.simpleNotNullType(annotations, classDescriptor, arguments)
|
return KotlinTypeFactory.simpleNotNullType(annotations.toDefaultAttributes(), classDescriptor, arguments)
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@@ -184,7 +184,7 @@ class ReflectionTypes(module: ModuleDescriptor, private val notFoundClasses: Not
|
|||||||
|
|
||||||
fun createKPropertyStarType(module: ModuleDescriptor): KotlinType? {
|
fun createKPropertyStarType(module: ModuleDescriptor): KotlinType? {
|
||||||
val kPropertyClass = module.findClassAcrossModuleDependencies(StandardNames.FqNames.kProperty) ?: return null
|
val kPropertyClass = module.findClassAcrossModuleDependencies(StandardNames.FqNames.kProperty) ?: return null
|
||||||
return KotlinTypeFactory.simpleNotNullType(Annotations.EMPTY, kPropertyClass,
|
return KotlinTypeFactory.simpleNotNullType(TypeAttributes.Empty, kPropertyClass,
|
||||||
listOf(StarProjectionImpl(kPropertyClass.typeConstructor.parameters.single())))
|
listOf(StarProjectionImpl(kPropertyClass.typeConstructor.parameters.single())))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -257,7 +257,7 @@ fun createFunctionType(
|
|||||||
if (contextReceiverTypes.isNotEmpty()) typeAnnotations =
|
if (contextReceiverTypes.isNotEmpty()) typeAnnotations =
|
||||||
typeAnnotations.withContextReceiversFunctionAnnotation(builtIns, contextReceiverTypes.size)
|
typeAnnotations.withContextReceiversFunctionAnnotation(builtIns, contextReceiverTypes.size)
|
||||||
|
|
||||||
return KotlinTypeFactory.simpleNotNullType(typeAnnotations, classDescriptor, arguments)
|
return KotlinTypeFactory.simpleNotNullType(typeAnnotations.toDefaultAttributes(), classDescriptor, arguments)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Annotations.hasExtensionFunctionAnnotation() = hasAnnotation(StandardNames.FqNames.extensionFunctionType)
|
fun Annotations.hasExtensionFunctionAnnotation() = hasAnnotation(StandardNames.FqNames.extensionFunctionType)
|
||||||
|
|||||||
+1
-1
@@ -114,7 +114,7 @@ class FunctionClassDescriptor(
|
|||||||
TypeProjectionImpl(it.defaultType)
|
TypeProjectionImpl(it.defaultType)
|
||||||
}
|
}
|
||||||
|
|
||||||
KotlinTypeFactory.simpleNotNullType(Annotations.EMPTY, descriptor, arguments)
|
KotlinTypeFactory.simpleNotNullType(TypeAttributes.Empty, descriptor, arguments)
|
||||||
}.toList()
|
}.toList()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ fun transformSuspendFunctionToRuntimeFunctionType(suspendFunType: KotlinType): S
|
|||||||
suspendFunType.getContextReceiverTypesFromFunctionType(),
|
suspendFunType.getContextReceiverTypesFromFunctionType(),
|
||||||
suspendFunType.getValueParameterTypesFromFunctionType().map(TypeProjection::getType) +
|
suspendFunType.getValueParameterTypesFromFunctionType().map(TypeProjection::getType) +
|
||||||
KotlinTypeFactory.simpleType(
|
KotlinTypeFactory.simpleType(
|
||||||
Annotations.EMPTY,
|
TypeAttributes.Empty,
|
||||||
// Continuation interface is not a part of built-ins anymore, it has been moved to stdlib.
|
// Continuation interface is not a part of built-ins anymore, it has been moved to stdlib.
|
||||||
// While it must be somewhere in the dependencies, but here we don't have a reference to the module,
|
// While it must be somewhere in the dependencies, but here we don't have a reference to the module,
|
||||||
// and it's rather complicated to inject it by now, so we just use a fake class descriptor.
|
// and it's rather complicated to inject it by now, so we just use a fake class descriptor.
|
||||||
|
|||||||
+1
-1
@@ -71,7 +71,7 @@ public abstract class AbstractTypeParameterDescriptor extends DeclarationDescrip
|
|||||||
@Override
|
@Override
|
||||||
public SimpleType invoke() {
|
public SimpleType invoke() {
|
||||||
return KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(
|
return KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(
|
||||||
Annotations.Companion.getEMPTY(),
|
TypeAttributes.Companion.getEmpty(),
|
||||||
getTypeConstructor(), Collections.<TypeProjection>emptyList(), false,
|
getTypeConstructor(), Collections.<TypeProjection>emptyList(), false,
|
||||||
new LazyScopeAdapter(
|
new LazyScopeAdapter(
|
||||||
new Function0<MemberScope>() {
|
new Function0<MemberScope>() {
|
||||||
|
|||||||
+1
-1
@@ -143,7 +143,7 @@ public class LazySubstitutingClassDescriptor extends ModuleAwareClassDescriptor
|
|||||||
public SimpleType getDefaultType() {
|
public SimpleType getDefaultType() {
|
||||||
List<TypeProjection> typeProjections = TypeUtils.getDefaultTypeProjections(getTypeConstructor().getParameters());
|
List<TypeProjection> typeProjections = TypeUtils.getDefaultTypeProjections(getTypeConstructor().getParameters());
|
||||||
return KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(
|
return KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(
|
||||||
getAnnotations(),
|
DefaultTypeAttributeTranslator.INSTANCE.toAttributes(getAnnotations(), null, null),
|
||||||
getTypeConstructor(),
|
getTypeConstructor(),
|
||||||
typeProjections,
|
typeProjections,
|
||||||
false,
|
false,
|
||||||
|
|||||||
+4
-3
@@ -77,6 +77,10 @@ class CapturedType(
|
|||||||
override val isMarkedNullable: Boolean = false,
|
override val isMarkedNullable: Boolean = false,
|
||||||
override val attributes: TypeAttributes = TypeAttributes.Empty
|
override val attributes: TypeAttributes = TypeAttributes.Empty
|
||||||
) : SimpleType(), SubtypingRepresentatives, CapturedTypeMarker {
|
) : SimpleType(), SubtypingRepresentatives, CapturedTypeMarker {
|
||||||
|
|
||||||
|
override val annotations: Annotations
|
||||||
|
get() = attributes.toDefaultAnnotations()
|
||||||
|
|
||||||
override val arguments: List<TypeProjection>
|
override val arguments: List<TypeProjection>
|
||||||
get() = listOf()
|
get() = listOf()
|
||||||
|
|
||||||
@@ -103,9 +107,6 @@ class CapturedType(
|
|||||||
return CapturedType(typeProjection, constructor, newNullability, attributes)
|
return CapturedType(typeProjection, constructor, newNullability, attributes)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun replaceAnnotations(newAnnotations: Annotations): CapturedType =
|
|
||||||
CapturedType(typeProjection, constructor, isMarkedNullable, newAnnotations.toDefaultAttributes())
|
|
||||||
|
|
||||||
override fun replaceAttributes(newAttributes: TypeAttributes): SimpleType =
|
override fun replaceAttributes(newAttributes: TypeAttributes): SimpleType =
|
||||||
CapturedType(typeProjection, constructor, isMarkedNullable, newAttributes)
|
CapturedType(typeProjection, constructor, isMarkedNullable, newAttributes)
|
||||||
|
|
||||||
|
|||||||
@@ -21,10 +21,7 @@ import org.jetbrains.kotlin.builtins.StandardNames
|
|||||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||||
import org.jetbrains.kotlin.descriptors.findClassAcrossModuleDependencies
|
import org.jetbrains.kotlin.descriptors.findClassAcrossModuleDependencies
|
||||||
import org.jetbrains.kotlin.types.ErrorUtils
|
import org.jetbrains.kotlin.types.*
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
|
||||||
import org.jetbrains.kotlin.types.KotlinTypeFactory
|
|
||||||
import org.jetbrains.kotlin.types.TypeUtils
|
|
||||||
|
|
||||||
interface CompileTimeConstant<out T> {
|
interface CompileTimeConstant<out T> {
|
||||||
val isError: Boolean
|
val isError: Boolean
|
||||||
@@ -200,7 +197,7 @@ class IntegerValueTypeConstant(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val unknownIntegerType = KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(
|
val unknownIntegerType = KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(
|
||||||
Annotations.EMPTY, typeConstructor, emptyList(), false,
|
TypeAttributes.Empty, typeConstructor, emptyList(), false,
|
||||||
ErrorUtils.createErrorScope("Scope for number value type ($typeConstructor)", true)
|
ErrorUtils.createErrorScope("Scope for number value type ($typeConstructor)", true)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -60,7 +60,7 @@ class IntegerLiteralTypeConstructor : TypeConstructor {
|
|||||||
Mode.INTERSECTION_TYPE -> left.possibleTypes union right.possibleTypes
|
Mode.INTERSECTION_TYPE -> left.possibleTypes union right.possibleTypes
|
||||||
}
|
}
|
||||||
val constructor = IntegerLiteralTypeConstructor(left.value, left.module, possibleTypes)
|
val constructor = IntegerLiteralTypeConstructor(left.value, left.module, possibleTypes)
|
||||||
return KotlinTypeFactory.integerLiteralType(Annotations.EMPTY, constructor, false)
|
return KotlinTypeFactory.integerLiteralType(TypeAttributes.Empty, constructor, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun fold(left: IntegerLiteralTypeConstructor, right: SimpleType): SimpleType? =
|
private fun fold(left: IntegerLiteralTypeConstructor, right: SimpleType): SimpleType? =
|
||||||
@@ -127,7 +127,7 @@ class IntegerLiteralTypeConstructor : TypeConstructor {
|
|||||||
this.possibleTypes = possibleTypes
|
this.possibleTypes = possibleTypes
|
||||||
}
|
}
|
||||||
|
|
||||||
private val type = KotlinTypeFactory.integerLiteralType(Annotations.EMPTY, this, false)
|
private val type = KotlinTypeFactory.integerLiteralType(TypeAttributes.Empty, this, false)
|
||||||
|
|
||||||
private fun isContainsOnlyUnsignedTypes(): Boolean = module.allSignedLiteralTypes.all { it !in possibleTypes }
|
private fun isContainsOnlyUnsignedTypes(): Boolean = module.allSignedLiteralTypes.all { it !in possibleTypes }
|
||||||
|
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ class KClassValue(value: Value) : ConstantValue<KClassValue.Value>(value) {
|
|||||||
constructor(classId: ClassId, arrayDimensions: Int) : this(ClassLiteralValue(classId, arrayDimensions))
|
constructor(classId: ClassId, arrayDimensions: Int) : this(ClassLiteralValue(classId, arrayDimensions))
|
||||||
|
|
||||||
override fun getType(module: ModuleDescriptor): KotlinType =
|
override fun getType(module: ModuleDescriptor): KotlinType =
|
||||||
KotlinTypeFactory.simpleNotNullType(Annotations.EMPTY, module.builtIns.kClass, listOf(TypeProjectionImpl(getArgumentType(module))))
|
KotlinTypeFactory.simpleNotNullType(TypeAttributes.Empty, module.builtIns.kClass, listOf(TypeProjectionImpl(getArgumentType(module))))
|
||||||
|
|
||||||
fun getArgumentType(module: ModuleDescriptor): KotlinType {
|
fun getArgumentType(module: ModuleDescriptor): KotlinType {
|
||||||
when (value) {
|
when (value) {
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.types
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
|
||||||
|
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||||
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
|
class AnnotationsTypeAttribute(val annotations: Annotations) : TypeAttribute<AnnotationsTypeAttribute>() {
|
||||||
|
constructor(annotations: List<AnnotationDescriptor>) : this(Annotations.create(annotations))
|
||||||
|
|
||||||
|
override fun union(other: AnnotationsTypeAttribute?): AnnotationsTypeAttribute? = null
|
||||||
|
|
||||||
|
override fun intersect(other: AnnotationsTypeAttribute?): AnnotationsTypeAttribute? = null
|
||||||
|
|
||||||
|
override fun add(other: AnnotationsTypeAttribute?): AnnotationsTypeAttribute {
|
||||||
|
if (other == null) return this
|
||||||
|
return AnnotationsTypeAttribute(Annotations.create(annotations + other.annotations))
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isSubtypeOf(other: AnnotationsTypeAttribute?): Boolean = true
|
||||||
|
|
||||||
|
override val key: KClass<out AnnotationsTypeAttribute>
|
||||||
|
get() = AnnotationsTypeAttribute::class
|
||||||
|
|
||||||
|
override fun equals(other: Any?): Boolean {
|
||||||
|
if (other !is AnnotationsTypeAttribute) return false
|
||||||
|
return annotations == other.annotations
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val TypeAttributes.annotationsAttribute: AnnotationsTypeAttribute? by TypeAttributes.attributeAccessor<AnnotationsTypeAttribute>()
|
||||||
|
|
||||||
|
val TypeAttributes.annotations: Annotations get() = annotationsAttribute?.annotations ?: Annotations.EMPTY
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jetbrains.kotlin.types
|
|
||||||
|
|
||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
|
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptorImpl
|
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
|
||||||
import kotlin.reflect.KClass
|
|
||||||
|
|
||||||
class CustomAnnotationTypeAttribute(val annotations: Annotations) : TypeAttribute<CustomAnnotationTypeAttribute>() {
|
|
||||||
constructor(annotations: List<AnnotationDescriptor>) : this(Annotations.create(annotations))
|
|
||||||
|
|
||||||
override fun union(other: CustomAnnotationTypeAttribute?): CustomAnnotationTypeAttribute? = null
|
|
||||||
|
|
||||||
override fun intersect(other: CustomAnnotationTypeAttribute?): CustomAnnotationTypeAttribute? = null
|
|
||||||
|
|
||||||
override fun add(other: CustomAnnotationTypeAttribute?): CustomAnnotationTypeAttribute {
|
|
||||||
if (other == null) return this
|
|
||||||
return CustomAnnotationTypeAttribute(Annotations.create(annotations + other.annotations))
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun isSubtypeOf(other: CustomAnnotationTypeAttribute?): Boolean = true
|
|
||||||
|
|
||||||
override val key: KClass<out CustomAnnotationTypeAttribute>
|
|
||||||
get() = CustomAnnotationTypeAttribute::class
|
|
||||||
}
|
|
||||||
|
|
||||||
val TypeAttributes.custom: CustomAnnotationTypeAttribute? by TypeAttributes.attributeAccessor<CustomAnnotationTypeAttribute>()
|
|
||||||
|
|
||||||
val TypeAttributes.customAnnotations: Annotations get() = custom?.annotations ?: Annotations.EMPTY
|
|
||||||
@@ -36,8 +36,6 @@ open class ErrorType @JvmOverloads internal constructor(
|
|||||||
override fun toString(): String =
|
override fun toString(): String =
|
||||||
constructor.toString() + if (arguments.isEmpty()) "" else arguments.joinToString(", ", "<", ">", -1, "...", null)
|
constructor.toString() + if (arguments.isEmpty()) "" else arguments.joinToString(", ", "<", ">", -1, "...", null)
|
||||||
|
|
||||||
override fun replaceAnnotations(newAnnotations: Annotations): SimpleType = this
|
|
||||||
|
|
||||||
override fun replaceAttributes(newAttributes: TypeAttributes): SimpleType = this
|
override fun replaceAttributes(newAttributes: TypeAttributes): SimpleType = this
|
||||||
|
|
||||||
override fun makeNullableAsSpecified(newNullability: Boolean): SimpleType =
|
override fun makeNullableAsSpecified(newNullability: Boolean): SimpleType =
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ class IntersectionTypeConstructor(typesToIntersect: Collection<KotlinType>) : Ty
|
|||||||
@OptIn(TypeRefinement::class)
|
@OptIn(TypeRefinement::class)
|
||||||
fun createType(): SimpleType =
|
fun createType(): SimpleType =
|
||||||
KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(
|
KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(
|
||||||
Annotations.EMPTY, this, listOf(), false, this.createScopeForKotlinType()
|
TypeAttributes.Empty, this, listOf(), false, this.createScopeForKotlinType()
|
||||||
) { kotlinTypeRefiner ->
|
) { kotlinTypeRefiner ->
|
||||||
this.refine(kotlinTypeRefiner).createType()
|
this.refine(kotlinTypeRefiner).createType()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,8 +52,6 @@ sealed class KotlinType : Annotated, KotlinTypeMarker {
|
|||||||
abstract val isMarkedNullable: Boolean
|
abstract val isMarkedNullable: Boolean
|
||||||
abstract val memberScope: MemberScope
|
abstract val memberScope: MemberScope
|
||||||
abstract val attributes: TypeAttributes
|
abstract val attributes: TypeAttributes
|
||||||
override val annotations: Annotations
|
|
||||||
get() = attributes.toDefaultAnnotations()
|
|
||||||
|
|
||||||
abstract fun unwrap(): UnwrappedType
|
abstract fun unwrap(): UnwrappedType
|
||||||
|
|
||||||
@@ -163,7 +161,6 @@ abstract class WrappedType : KotlinType() {
|
|||||||
* todo: specify what happens with internal structure when we apply some [TypeSubstitutor]
|
* todo: specify what happens with internal structure when we apply some [TypeSubstitutor]
|
||||||
*/
|
*/
|
||||||
sealed class UnwrappedType : KotlinType() {
|
sealed class UnwrappedType : KotlinType() {
|
||||||
abstract fun replaceAnnotations(newAnnotations: Annotations): UnwrappedType
|
|
||||||
abstract fun replaceAttributes(newAttributes: TypeAttributes): UnwrappedType
|
abstract fun replaceAttributes(newAttributes: TypeAttributes): UnwrappedType
|
||||||
abstract fun makeNullableAsSpecified(newNullability: Boolean): UnwrappedType
|
abstract fun makeNullableAsSpecified(newNullability: Boolean): UnwrappedType
|
||||||
|
|
||||||
@@ -179,7 +176,6 @@ sealed class UnwrappedType : KotlinType() {
|
|||||||
* Or more precisely, all instances are subclasses of [SimpleType] or [WrappedType] (which contains [SimpleType] inside).
|
* Or more precisely, all instances are subclasses of [SimpleType] or [WrappedType] (which contains [SimpleType] inside).
|
||||||
*/
|
*/
|
||||||
abstract class SimpleType : UnwrappedType(), SimpleTypeMarker, TypeArgumentListMarker {
|
abstract class SimpleType : UnwrappedType(), SimpleTypeMarker, TypeArgumentListMarker {
|
||||||
abstract override fun replaceAnnotations(newAnnotations: Annotations): SimpleType
|
|
||||||
abstract override fun replaceAttributes(newAttributes: TypeAttributes): SimpleType
|
abstract override fun replaceAttributes(newAttributes: TypeAttributes): SimpleType
|
||||||
abstract override fun makeNullableAsSpecified(newNullability: Boolean): SimpleType
|
abstract override fun makeNullableAsSpecified(newNullability: Boolean): SimpleType
|
||||||
|
|
||||||
|
|||||||
@@ -65,31 +65,6 @@ object KotlinTypeFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
@JvmOverloads
|
|
||||||
@OptIn(TypeRefinement::class)
|
|
||||||
fun simpleType(
|
|
||||||
annotations: Annotations,
|
|
||||||
constructor: TypeConstructor,
|
|
||||||
arguments: List<TypeProjection>,
|
|
||||||
nullable: Boolean,
|
|
||||||
kotlinTypeRefiner: KotlinTypeRefiner? = null
|
|
||||||
): SimpleType {
|
|
||||||
if (annotations.isEmpty() && arguments.isEmpty() && !nullable && constructor.declarationDescriptor != null) {
|
|
||||||
return constructor.declarationDescriptor!!.defaultType
|
|
||||||
}
|
|
||||||
|
|
||||||
return simpleTypeWithNonTrivialMemberScope(
|
|
||||||
annotations, constructor, arguments, nullable,
|
|
||||||
computeMemberScope(constructor, arguments, kotlinTypeRefiner)
|
|
||||||
) f@{ refiner ->
|
|
||||||
val expandedTypeOrRefinedConstructor = refineConstructor(constructor, refiner, arguments) ?: return@f null
|
|
||||||
expandedTypeOrRefinedConstructor.expandedType?.let { return@f it }
|
|
||||||
|
|
||||||
simpleType(annotations, expandedTypeOrRefinedConstructor.refinedConstructor!!, arguments, nullable, refiner)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
@OptIn(TypeRefinement::class)
|
@OptIn(TypeRefinement::class)
|
||||||
@@ -118,7 +93,7 @@ object KotlinTypeFactory {
|
|||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun TypeAliasDescriptor.computeExpandedType(arguments: List<TypeProjection>): SimpleType {
|
fun TypeAliasDescriptor.computeExpandedType(arguments: List<TypeProjection>): SimpleType {
|
||||||
return TypeAliasExpander(TypeAliasExpansionReportStrategy.DO_NOTHING, false).expand(
|
return TypeAliasExpander(TypeAliasExpansionReportStrategy.DO_NOTHING, false).expand(
|
||||||
TypeAliasExpansion.create(null, this, arguments), Annotations.EMPTY
|
TypeAliasExpansion.create(null, this, arguments), TypeAttributes.Empty
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,33 +116,6 @@ object KotlinTypeFactory {
|
|||||||
|
|
||||||
private class ExpandedTypeOrRefinedConstructor(val expandedType: SimpleType?, val refinedConstructor: TypeConstructor?)
|
private class ExpandedTypeOrRefinedConstructor(val expandedType: SimpleType?, val refinedConstructor: TypeConstructor?)
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
@OptIn(TypeRefinement::class)
|
|
||||||
fun simpleTypeWithNonTrivialMemberScope(
|
|
||||||
annotations: Annotations,
|
|
||||||
constructor: TypeConstructor,
|
|
||||||
arguments: List<TypeProjection>,
|
|
||||||
nullable: Boolean,
|
|
||||||
memberScope: MemberScope
|
|
||||||
): SimpleType =
|
|
||||||
SimpleTypeImpl(constructor, arguments, nullable, memberScope) { kotlinTypeRefiner ->
|
|
||||||
val expandedTypeOrRefinedConstructor = refineConstructor(constructor, kotlinTypeRefiner, arguments) ?: return@SimpleTypeImpl null
|
|
||||||
expandedTypeOrRefinedConstructor.expandedType?.let { return@SimpleTypeImpl it }
|
|
||||||
|
|
||||||
simpleTypeWithNonTrivialMemberScope(
|
|
||||||
annotations,
|
|
||||||
expandedTypeOrRefinedConstructor.refinedConstructor!!,
|
|
||||||
arguments,
|
|
||||||
nullable,
|
|
||||||
memberScope
|
|
||||||
)
|
|
||||||
}.let {
|
|
||||||
if (annotations.isEmpty())
|
|
||||||
it
|
|
||||||
else
|
|
||||||
SimpleTypeWithAttributes(it, annotations.toDefaultAttributes())
|
|
||||||
}
|
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@OptIn(TypeRefinement::class)
|
@OptIn(TypeRefinement::class)
|
||||||
fun simpleTypeWithNonTrivialMemberScope(
|
fun simpleTypeWithNonTrivialMemberScope(
|
||||||
@@ -195,23 +143,6 @@ object KotlinTypeFactory {
|
|||||||
SimpleTypeWithAttributes(it, attributes)
|
SimpleTypeWithAttributes(it, attributes)
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
fun simpleTypeWithNonTrivialMemberScope(
|
|
||||||
annotations: Annotations,
|
|
||||||
constructor: TypeConstructor,
|
|
||||||
arguments: List<TypeProjection>,
|
|
||||||
nullable: Boolean,
|
|
||||||
memberScope: MemberScope,
|
|
||||||
refinedTypeFactory: RefinedTypeFactory
|
|
||||||
): SimpleType =
|
|
||||||
SimpleTypeImpl(constructor, arguments, nullable, memberScope, refinedTypeFactory)
|
|
||||||
.let {
|
|
||||||
if (annotations.isEmpty())
|
|
||||||
it
|
|
||||||
else
|
|
||||||
SimpleTypeWithAttributes(it, annotations.toDefaultAttributes())
|
|
||||||
}
|
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun simpleTypeWithNonTrivialMemberScope(
|
fun simpleTypeWithNonTrivialMemberScope(
|
||||||
attributes: TypeAttributes,
|
attributes: TypeAttributes,
|
||||||
@@ -229,13 +160,6 @@ object KotlinTypeFactory {
|
|||||||
SimpleTypeWithAttributes(it, attributes)
|
SimpleTypeWithAttributes(it, attributes)
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
fun simpleNotNullType(
|
|
||||||
annotations: Annotations,
|
|
||||||
descriptor: ClassDescriptor,
|
|
||||||
arguments: List<TypeProjection>
|
|
||||||
): SimpleType = simpleType(annotations, descriptor.typeConstructor, arguments, nullable = false)
|
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun simpleNotNullType(
|
fun simpleNotNullType(
|
||||||
attributes: TypeAttributes,
|
attributes: TypeAttributes,
|
||||||
@@ -246,7 +170,7 @@ object KotlinTypeFactory {
|
|||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun simpleType(
|
fun simpleType(
|
||||||
baseType: SimpleType,
|
baseType: SimpleType,
|
||||||
annotations: Annotations = baseType.annotations,
|
annotations: TypeAttributes = baseType.attributes,
|
||||||
constructor: TypeConstructor = baseType.constructor,
|
constructor: TypeConstructor = baseType.constructor,
|
||||||
arguments: List<TypeProjection> = baseType.arguments,
|
arguments: List<TypeProjection> = baseType.arguments,
|
||||||
nullable: Boolean = baseType.isMarkedNullable
|
nullable: Boolean = baseType.isMarkedNullable
|
||||||
@@ -260,11 +184,11 @@ object KotlinTypeFactory {
|
|||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun integerLiteralType(
|
fun integerLiteralType(
|
||||||
annotations: Annotations,
|
attributes: TypeAttributes,
|
||||||
constructor: IntegerLiteralTypeConstructor,
|
constructor: IntegerLiteralTypeConstructor,
|
||||||
nullable: Boolean
|
nullable: Boolean
|
||||||
): SimpleType = simpleTypeWithNonTrivialMemberScope(
|
): SimpleType = simpleTypeWithNonTrivialMemberScope(
|
||||||
annotations,
|
attributes,
|
||||||
constructor,
|
constructor,
|
||||||
emptyList(),
|
emptyList(),
|
||||||
nullable,
|
nullable,
|
||||||
@@ -290,12 +214,6 @@ private class SimpleTypeImpl(
|
|||||||
this
|
this
|
||||||
else SimpleTypeWithAttributes(this, newAttributes)
|
else SimpleTypeWithAttributes(this, newAttributes)
|
||||||
|
|
||||||
override fun replaceAnnotations(newAnnotations: Annotations) =
|
|
||||||
if (newAnnotations.isEmpty())
|
|
||||||
this
|
|
||||||
else
|
|
||||||
SimpleTypeWithAttributes(this, attributes.replaceAnnotations(newAnnotations))
|
|
||||||
|
|
||||||
override fun makeNullableAsSpecified(newNullability: Boolean) = when {
|
override fun makeNullableAsSpecified(newNullability: Boolean) = when {
|
||||||
newNullability == isMarkedNullable -> this
|
newNullability == isMarkedNullable -> this
|
||||||
newNullability -> NullableSimpleType(this)
|
newNullability -> NullableSimpleType(this)
|
||||||
@@ -322,9 +240,6 @@ class SupposititiousSimpleType(private val realType: SimpleType, val overwritten
|
|||||||
else SupposititiousSimpleType(newType, overwrittenClass)
|
else SupposititiousSimpleType(newType, overwrittenClass)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun replaceAnnotations(newAnnotations: Annotations): SimpleType =
|
|
||||||
maybeWrap(realType.replaceAnnotations(newAnnotations))
|
|
||||||
|
|
||||||
override fun replaceAttributes(newAttributes: TypeAttributes): SimpleType =
|
override fun replaceAttributes(newAttributes: TypeAttributes): SimpleType =
|
||||||
maybeWrap(realType.replaceAttributes(newAttributes))
|
maybeWrap(realType.replaceAttributes(newAttributes))
|
||||||
|
|
||||||
@@ -350,15 +265,9 @@ abstract class DelegatingSimpleTypeImpl(override val delegate: SimpleType) : Del
|
|||||||
else
|
else
|
||||||
this
|
this
|
||||||
|
|
||||||
override fun replaceAnnotations(newAnnotations: Annotations) =
|
|
||||||
if (newAnnotations !== annotations)
|
|
||||||
SimpleTypeWithAttributes(this, attributes.replaceAnnotations(newAnnotations))
|
|
||||||
else
|
|
||||||
this
|
|
||||||
|
|
||||||
override fun makeNullableAsSpecified(newNullability: Boolean): SimpleType {
|
override fun makeNullableAsSpecified(newNullability: Boolean): SimpleType {
|
||||||
if (newNullability == isMarkedNullable) return this
|
if (newNullability == isMarkedNullable) return this
|
||||||
return delegate.makeNullableAsSpecified(newNullability).replaceAnnotations(annotations)
|
return delegate.makeNullableAsSpecified(newNullability).replaceAttributes(attributes)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -366,6 +275,8 @@ private class SimpleTypeWithAttributes(
|
|||||||
delegate: SimpleType,
|
delegate: SimpleType,
|
||||||
override val attributes: TypeAttributes
|
override val attributes: TypeAttributes
|
||||||
) : DelegatingSimpleTypeImpl(delegate) {
|
) : DelegatingSimpleTypeImpl(delegate) {
|
||||||
|
override val annotations: Annotations
|
||||||
|
get() = attributes.toDefaultAnnotations()
|
||||||
@TypeRefinement
|
@TypeRefinement
|
||||||
override fun replaceDelegate(delegate: SimpleType) = SimpleTypeWithAttributes(delegate, attributes)
|
override fun replaceDelegate(delegate: SimpleType) = SimpleTypeWithAttributes(delegate, attributes)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,9 +48,6 @@ abstract class DelegatingSimpleType : SimpleType() {
|
|||||||
class AbbreviatedType(override val delegate: SimpleType, val abbreviation: SimpleType) : DelegatingSimpleType() {
|
class AbbreviatedType(override val delegate: SimpleType, val abbreviation: SimpleType) : DelegatingSimpleType() {
|
||||||
val expandedType: SimpleType get() = delegate
|
val expandedType: SimpleType get() = delegate
|
||||||
|
|
||||||
override fun replaceAnnotations(newAnnotations: Annotations) =
|
|
||||||
AbbreviatedType(delegate.replaceAnnotations(newAnnotations), abbreviation)
|
|
||||||
|
|
||||||
override fun replaceAttributes(newAttributes: TypeAttributes): SimpleType =
|
override fun replaceAttributes(newAttributes: TypeAttributes): SimpleType =
|
||||||
AbbreviatedType(delegate.replaceAttributes(newAttributes), abbreviation)
|
AbbreviatedType(delegate.replaceAttributes(newAttributes), abbreviation)
|
||||||
|
|
||||||
@@ -172,9 +169,6 @@ class DefinitelyNotNullType private constructor(
|
|||||||
override fun substitutionResult(replacement: KotlinType): KotlinType =
|
override fun substitutionResult(replacement: KotlinType): KotlinType =
|
||||||
replacement.unwrap().makeDefinitelyNotNullOrNotNull(useCorrectedNullabilityForTypeParameters)
|
replacement.unwrap().makeDefinitelyNotNullOrNotNull(useCorrectedNullabilityForTypeParameters)
|
||||||
|
|
||||||
override fun replaceAnnotations(newAnnotations: Annotations): DefinitelyNotNullType =
|
|
||||||
DefinitelyNotNullType(delegate.replaceAnnotations(newAnnotations), useCorrectedNullabilityForTypeParameters)
|
|
||||||
|
|
||||||
override fun replaceAttributes(newAttributes: TypeAttributes): SimpleType =
|
override fun replaceAttributes(newAttributes: TypeAttributes): SimpleType =
|
||||||
DefinitelyNotNullType(delegate.replaceAttributes(newAttributes), useCorrectedNullabilityForTypeParameters)
|
DefinitelyNotNullType(delegate.replaceAttributes(newAttributes), useCorrectedNullabilityForTypeParameters)
|
||||||
|
|
||||||
|
|||||||
@@ -64,8 +64,6 @@ abstract class AbstractStubType(val originalTypeVariable: TypeConstructor, overr
|
|||||||
override val attributes: TypeAttributes
|
override val attributes: TypeAttributes
|
||||||
get() = TypeAttributes.Empty
|
get() = TypeAttributes.Empty
|
||||||
|
|
||||||
override fun replaceAnnotations(newAnnotations: Annotations): SimpleType = this
|
|
||||||
|
|
||||||
override fun replaceAttributes(newAttributes: TypeAttributes): SimpleType = this
|
override fun replaceAttributes(newAttributes: TypeAttributes): SimpleType = this
|
||||||
|
|
||||||
override fun makeNullableAsSpecified(newNullability: Boolean): SimpleType {
|
override fun makeNullableAsSpecified(newNullability: Boolean): SimpleType {
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
|||||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.composeAnnotations
|
import org.jetbrains.kotlin.descriptors.annotations.composeAnnotations
|
||||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
|
||||||
import org.jetbrains.kotlin.types.typeUtil.containsTypeAliasParameters
|
import org.jetbrains.kotlin.types.typeUtil.containsTypeAliasParameters
|
||||||
import org.jetbrains.kotlin.types.typeUtil.requiresTypeAliasExpansion
|
import org.jetbrains.kotlin.types.typeUtil.requiresTypeAliasExpansion
|
||||||
|
|
||||||
@@ -19,21 +18,21 @@ class TypeAliasExpander(
|
|||||||
private val shouldCheckBounds: Boolean
|
private val shouldCheckBounds: Boolean
|
||||||
) {
|
) {
|
||||||
|
|
||||||
fun expand(typeAliasExpansion: TypeAliasExpansion, annotations: Annotations) =
|
fun expand(typeAliasExpansion: TypeAliasExpansion, attributes: TypeAttributes) =
|
||||||
expandRecursively(
|
expandRecursively(
|
||||||
typeAliasExpansion, annotations,
|
typeAliasExpansion, attributes,
|
||||||
isNullable = false, recursionDepth = 0, withAbbreviatedType = true
|
isNullable = false, recursionDepth = 0, withAbbreviatedType = true
|
||||||
)
|
)
|
||||||
|
|
||||||
fun expandWithoutAbbreviation(typeAliasExpansion: TypeAliasExpansion, annotations: Annotations) =
|
fun expandWithoutAbbreviation(typeAliasExpansion: TypeAliasExpansion, attributes: TypeAttributes) =
|
||||||
expandRecursively(
|
expandRecursively(
|
||||||
typeAliasExpansion, annotations,
|
typeAliasExpansion, attributes,
|
||||||
isNullable = false, recursionDepth = 0, withAbbreviatedType = false
|
isNullable = false, recursionDepth = 0, withAbbreviatedType = false
|
||||||
)
|
)
|
||||||
|
|
||||||
private fun expandRecursively(
|
private fun expandRecursively(
|
||||||
typeAliasExpansion: TypeAliasExpansion,
|
typeAliasExpansion: TypeAliasExpansion,
|
||||||
annotations: Annotations,
|
attributes: TypeAttributes,
|
||||||
isNullable: Boolean,
|
isNullable: Boolean,
|
||||||
recursionDepth: Int,
|
recursionDepth: Int,
|
||||||
withAbbreviatedType: Boolean
|
withAbbreviatedType: Boolean
|
||||||
@@ -51,19 +50,19 @@ class TypeAliasExpander(
|
|||||||
"Type alias expansion: result for ${typeAliasExpansion.descriptor} is ${expandedProjection.projectionKind}, should be invariant"
|
"Type alias expansion: result for ${typeAliasExpansion.descriptor} is ${expandedProjection.projectionKind}, should be invariant"
|
||||||
}
|
}
|
||||||
|
|
||||||
checkRepeatedAnnotations(expandedType.annotations, annotations)
|
checkRepeatedAnnotations(expandedType.annotations, attributes.annotations)
|
||||||
val expandedTypeWithExtraAnnotations =
|
val expandedTypeWithExtraAnnotations =
|
||||||
expandedType.combineAnnotations(annotations).let { TypeUtils.makeNullableIfNeeded(it, isNullable) }
|
expandedType.combineAttributes(attributes).let { TypeUtils.makeNullableIfNeeded(it, isNullable) }
|
||||||
|
|
||||||
return if (withAbbreviatedType)
|
return if (withAbbreviatedType)
|
||||||
expandedTypeWithExtraAnnotations.withAbbreviation(typeAliasExpansion.createAbbreviation(annotations, isNullable))
|
expandedTypeWithExtraAnnotations.withAbbreviation(typeAliasExpansion.createAbbreviation(attributes, isNullable))
|
||||||
else
|
else
|
||||||
expandedTypeWithExtraAnnotations
|
expandedTypeWithExtraAnnotations
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun TypeAliasExpansion.createAbbreviation(annotations: Annotations, isNullable: Boolean) =
|
private fun TypeAliasExpansion.createAbbreviation(attributes: TypeAttributes, isNullable: Boolean) =
|
||||||
KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(
|
KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(
|
||||||
annotations,
|
attributes,
|
||||||
descriptor.typeConstructor,
|
descriptor.typeConstructor,
|
||||||
arguments,
|
arguments,
|
||||||
isNullable,
|
isNullable,
|
||||||
@@ -125,23 +124,23 @@ class TypeAliasExpander(
|
|||||||
|
|
||||||
val substitutedType =
|
val substitutedType =
|
||||||
if (argumentType is DynamicType)
|
if (argumentType is DynamicType)
|
||||||
argumentType.combineAnnotations(underlyingType.annotations)
|
argumentType.combineAttributes(underlyingType.attributes)
|
||||||
else
|
else
|
||||||
argumentType.asSimpleType().combineNullabilityAndAnnotations(underlyingType)
|
argumentType.asSimpleType().combineNullabilityAndAnnotations(underlyingType)
|
||||||
|
|
||||||
return TypeProjectionImpl(resultingVariance, substitutedType)
|
return TypeProjectionImpl(resultingVariance, substitutedType)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun DynamicType.combineAnnotations(newAnnotations: Annotations): DynamicType =
|
private fun DynamicType.combineAttributes(newAttributes: TypeAttributes): DynamicType =
|
||||||
replaceAnnotations(createCombinedAnnotations(newAnnotations))
|
replaceAttributes(createdCombinedAttributes(newAttributes))
|
||||||
|
|
||||||
private fun SimpleType.combineAnnotations(newAnnotations: Annotations): SimpleType =
|
private fun SimpleType.combineAttributes(newAttributes: TypeAttributes): SimpleType =
|
||||||
if (isError) this else replace(newAnnotations = createCombinedAnnotations(newAnnotations))
|
if (isError) this else replaceAttributes(newAttributes = createdCombinedAttributes(newAttributes))
|
||||||
|
|
||||||
private fun KotlinType.createCombinedAnnotations(newAnnotations: Annotations): Annotations {
|
private fun KotlinType.createdCombinedAttributes(newAttributes: TypeAttributes): TypeAttributes {
|
||||||
if (isError) return annotations
|
if (isError) return attributes
|
||||||
|
|
||||||
return composeAnnotations(newAnnotations, annotations)
|
return newAttributes.add(attributes)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkRepeatedAnnotations(existingAnnotations: Annotations, newAnnotations: Annotations) {
|
private fun checkRepeatedAnnotations(existingAnnotations: Annotations, newAnnotations: Annotations) {
|
||||||
@@ -158,7 +157,7 @@ class TypeAliasExpander(
|
|||||||
TypeUtils.makeNullableIfNeeded(this, fromType.isMarkedNullable)
|
TypeUtils.makeNullableIfNeeded(this, fromType.isMarkedNullable)
|
||||||
|
|
||||||
private fun SimpleType.combineNullabilityAndAnnotations(fromType: KotlinType) =
|
private fun SimpleType.combineNullabilityAndAnnotations(fromType: KotlinType) =
|
||||||
combineNullability(fromType).combineAnnotations(fromType.annotations)
|
combineNullability(fromType).combineAttributes(fromType.attributes)
|
||||||
|
|
||||||
private fun expandNonArgumentTypeProjection(
|
private fun expandNonArgumentTypeProjection(
|
||||||
originalProjection: TypeProjection,
|
originalProjection: TypeProjection,
|
||||||
@@ -201,7 +200,7 @@ class TypeAliasExpander(
|
|||||||
TypeAliasExpansion.create(typeAliasExpansion, typeDescriptor, expandedArguments)
|
TypeAliasExpansion.create(typeAliasExpansion, typeDescriptor, expandedArguments)
|
||||||
|
|
||||||
val nestedExpandedType = expandRecursively(
|
val nestedExpandedType = expandRecursively(
|
||||||
nestedExpansion, type.annotations,
|
nestedExpansion, type.attributes,
|
||||||
isNullable = type.isMarkedNullable,
|
isNullable = type.isMarkedNullable,
|
||||||
recursionDepth = recursionDepth + 1,
|
recursionDepth = recursionDepth + 1,
|
||||||
withAbbreviatedType = false
|
withAbbreviatedType = false
|
||||||
|
|||||||
@@ -5,19 +5,29 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.types
|
package org.jetbrains.kotlin.types
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||||
|
|
||||||
interface TypeAttributeTranslator {
|
interface TypeAttributeTranslator {
|
||||||
fun toAttributes(annotations: Annotations): TypeAttributes
|
fun toAttributes(
|
||||||
|
annotations: Annotations,
|
||||||
|
typeConstructor: TypeConstructor? = null,
|
||||||
|
containingDeclaration: DeclarationDescriptor? = null
|
||||||
|
): TypeAttributes
|
||||||
|
|
||||||
fun toAnnotations(attributes: TypeAttributes): Annotations
|
fun toAnnotations(attributes: TypeAttributes): Annotations
|
||||||
}
|
}
|
||||||
|
|
||||||
object DefaultTypeAttributeTranslator : TypeAttributeTranslator {
|
object DefaultTypeAttributeTranslator : TypeAttributeTranslator {
|
||||||
override fun toAnnotations(attributes: TypeAttributes): Annotations {
|
override fun toAttributes(
|
||||||
return attributes.customAnnotations
|
annotations: Annotations,
|
||||||
|
typeConstructor: TypeConstructor?,
|
||||||
|
containingDeclaration: DeclarationDescriptor?
|
||||||
|
): TypeAttributes {
|
||||||
|
return TypeAttributes.create(listOf(AnnotationsTypeAttribute(annotations)))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toAttributes(annotations: Annotations): TypeAttributes {
|
override fun toAnnotations(attributes: TypeAttributes): Annotations {
|
||||||
return TypeAttributes.create(listOf(CustomAnnotationTypeAttribute(annotations)))
|
return attributes.annotations
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,9 +41,7 @@ class TypeAttributes private constructor(attributes: List<TypeAttribute<*>>) : A
|
|||||||
return generateNullableAccessor<TypeAttribute<*>, T>(T::class) as ReadOnlyProperty<TypeAttributes, T?>
|
return generateNullableAccessor<TypeAttribute<*>, T>(T::class) as ReadOnlyProperty<TypeAttributes, T?>
|
||||||
}
|
}
|
||||||
|
|
||||||
val Empty: TypeAttributes = TypeAttributes(emptyList())
|
val Empty: TypeAttributes = TypeAttributes(listOf(AnnotationsTypeAttribute(Annotations.EMPTY)))
|
||||||
|
|
||||||
private fun TypeAttribute<*>.predefined(): Pair<TypeAttribute<*>, TypeAttributes> = this to TypeAttributes(this)
|
|
||||||
|
|
||||||
fun create(attributes: List<TypeAttribute<*>>): TypeAttributes {
|
fun create(attributes: List<TypeAttribute<*>>): TypeAttributes {
|
||||||
return if (attributes.isEmpty()) {
|
return if (attributes.isEmpty()) {
|
||||||
@@ -119,6 +117,6 @@ fun TypeAttributes.toDefaultAnnotations(): Annotations =
|
|||||||
fun Annotations.toDefaultAttributes(): TypeAttributes = DefaultTypeAttributeTranslator.toAttributes(this)
|
fun Annotations.toDefaultAttributes(): TypeAttributes = DefaultTypeAttributeTranslator.toAttributes(this)
|
||||||
|
|
||||||
fun TypeAttributes.replaceAnnotations(newAnnotations: Annotations): TypeAttributes {
|
fun TypeAttributes.replaceAnnotations(newAnnotations: Annotations): TypeAttributes {
|
||||||
val withoutCustom = (custom?.let { this.remove(it) } ?: this)
|
val withoutCustom = (annotationsAttribute?.let { this.remove(it) } ?: this)
|
||||||
return withoutCustom.add(newAnnotations.toDefaultAttributes())
|
return withoutCustom.add(newAnnotations.toDefaultAttributes())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -160,12 +160,14 @@ fun SimpleType.replace(
|
|||||||
): SimpleType {
|
): SimpleType {
|
||||||
if (newArguments.isEmpty() && newAnnotations === annotations) return this
|
if (newArguments.isEmpty() && newAnnotations === annotations) return this
|
||||||
|
|
||||||
|
val newAttributes = attributes.replaceAnnotations(newAnnotations)
|
||||||
|
|
||||||
if (newArguments.isEmpty()) {
|
if (newArguments.isEmpty()) {
|
||||||
return replaceAnnotations(newAnnotations)
|
return replaceAttributes(newAttributes)
|
||||||
}
|
}
|
||||||
|
|
||||||
return KotlinTypeFactory.simpleType(
|
return KotlinTypeFactory.simpleType(
|
||||||
newAnnotations,
|
newAttributes,
|
||||||
constructor,
|
constructor,
|
||||||
newArguments,
|
newArguments,
|
||||||
isMarkedNullable
|
isMarkedNullable
|
||||||
|
|||||||
@@ -46,12 +46,6 @@ public class TypeUtils {
|
|||||||
throw new IllegalStateException(name);
|
throw new IllegalStateException(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public SimpleType replaceAnnotations(@NotNull Annotations newAnnotations) {
|
|
||||||
throw new IllegalStateException(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public SimpleType replaceAttributes(@NotNull TypeAttributes newAttributes) {
|
public SimpleType replaceAttributes(@NotNull TypeAttributes newAttributes) {
|
||||||
@@ -227,7 +221,7 @@ public class TypeUtils {
|
|||||||
) {
|
) {
|
||||||
List<TypeProjection> arguments = getDefaultTypeProjections(typeConstructor.getParameters());
|
List<TypeProjection> arguments = getDefaultTypeProjections(typeConstructor.getParameters());
|
||||||
return KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(
|
return KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(
|
||||||
Annotations.Companion.getEMPTY(),
|
TypeAttributes.Companion.getEmpty(),
|
||||||
typeConstructor,
|
typeConstructor,
|
||||||
arguments,
|
arguments,
|
||||||
false,
|
false,
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ fun TypeProjection.substitute(doSubstitute: (KotlinType) -> KotlinType): TypePro
|
|||||||
|
|
||||||
fun KotlinType.replaceAnnotations(newAnnotations: Annotations): KotlinType {
|
fun KotlinType.replaceAnnotations(newAnnotations: Annotations): KotlinType {
|
||||||
if (annotations.isEmpty() && newAnnotations.isEmpty()) return this
|
if (annotations.isEmpty() && newAnnotations.isEmpty()) return this
|
||||||
return unwrap().replaceAnnotations(newAnnotations)
|
return unwrap().replaceAttributes(attributes.replaceAnnotations(newAnnotations))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun KotlinTypeChecker.equalTypesOrNulls(type1: KotlinType?, type2: KotlinType?): Boolean {
|
fun KotlinTypeChecker.equalTypesOrNulls(type1: KotlinType?, type2: KotlinType?): Boolean {
|
||||||
|
|||||||
@@ -34,9 +34,6 @@ class SimpleTypeWithEnhancement(
|
|||||||
|
|
||||||
override val origin get() = delegate
|
override val origin get() = delegate
|
||||||
|
|
||||||
override fun replaceAnnotations(newAnnotations: Annotations): SimpleType =
|
|
||||||
origin.replaceAnnotations(newAnnotations).wrapEnhancement(enhancement) as SimpleType
|
|
||||||
|
|
||||||
override fun replaceAttributes(newAttributes: TypeAttributes): SimpleType =
|
override fun replaceAttributes(newAttributes: TypeAttributes): SimpleType =
|
||||||
origin.replaceAttributes(newAttributes).wrapEnhancement(enhancement) as SimpleType
|
origin.replaceAttributes(newAttributes).wrapEnhancement(enhancement) as SimpleType
|
||||||
|
|
||||||
@@ -64,9 +61,6 @@ class FlexibleTypeWithEnhancement(
|
|||||||
) : FlexibleType(origin.lowerBound, origin.upperBound),
|
) : FlexibleType(origin.lowerBound, origin.upperBound),
|
||||||
TypeWithEnhancement {
|
TypeWithEnhancement {
|
||||||
|
|
||||||
override fun replaceAnnotations(newAnnotations: Annotations): UnwrappedType =
|
|
||||||
origin.replaceAnnotations(newAnnotations).wrapEnhancement(enhancement)
|
|
||||||
|
|
||||||
override fun replaceAttributes(newAttributes: TypeAttributes): UnwrappedType =
|
override fun replaceAttributes(newAttributes: TypeAttributes): UnwrappedType =
|
||||||
origin.replaceAttributes(newAttributes).wrapEnhancement(enhancement)
|
origin.replaceAttributes(newAttributes).wrapEnhancement(enhancement)
|
||||||
|
|
||||||
|
|||||||
@@ -641,17 +641,15 @@ interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext, TypeSy
|
|||||||
|
|
||||||
override fun unionTypeAttributes(types: List<KotlinTypeMarker>): List<AnnotationMarker> {
|
override fun unionTypeAttributes(types: List<KotlinTypeMarker>): List<AnnotationMarker> {
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
types as List<KotlinType>
|
return (types as List<KotlinType>).map { it.unwrap().attributes }.reduce { x, y -> x.union(y) }.toList()
|
||||||
return types.map { it.unwrap().attributes }.reduce { x, y -> x.union(y) }.toList()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun KotlinTypeMarker.replaceTypeAttributes(newAttributes: List<AnnotationMarker>): KotlinTypeMarker {
|
override fun KotlinTypeMarker.replaceTypeAttributes(newAttributes: List<AnnotationMarker>): KotlinTypeMarker {
|
||||||
require(this is KotlinType)
|
require(this is KotlinType)
|
||||||
val typeAttributes = newAttributes.filterIsInstance<TypeAttribute<*>>()
|
|
||||||
require(typeAttributes.size == newAttributes.size)
|
|
||||||
if (newAttributes.isEmpty()) return this
|
if (newAttributes.isEmpty()) return this
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
return this.unwrap().replaceAttributes(
|
return this.unwrap().replaceAttributes(
|
||||||
TypeAttributes.create(typeAttributes)
|
TypeAttributes.create(newAttributes as List<TypeAttribute<*>>)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -675,6 +673,11 @@ interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext, TypeSy
|
|||||||
return this.attributes.toList()
|
return this.attributes.toList()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun KotlinTypeMarker.getCustomAttributes(): List<AnnotationMarker> {
|
||||||
|
require(this is KotlinType, this::errorMessage)
|
||||||
|
return this.attributes.filterNot { it is AnnotationsTypeAttribute }
|
||||||
|
}
|
||||||
|
|
||||||
override fun captureFromExpression(type: KotlinTypeMarker): KotlinTypeMarker? {
|
override fun captureFromExpression(type: KotlinTypeMarker): KotlinTypeMarker? {
|
||||||
return captureFromExpressionInternal(type as UnwrappedType)
|
return captureFromExpressionInternal(type as UnwrappedType)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ abstract class KotlinTypePreparator : AbstractTypePreparator() {
|
|||||||
val newConstructor =
|
val newConstructor =
|
||||||
IntersectionTypeConstructor(constructor.supertypes.map { TypeUtils.makeNullableAsSpecified(it, type.isMarkedNullable) })
|
IntersectionTypeConstructor(constructor.supertypes.map { TypeUtils.makeNullableAsSpecified(it, type.isMarkedNullable) })
|
||||||
return KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(
|
return KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(
|
||||||
type.annotations,
|
type.attributes,
|
||||||
newConstructor,
|
newConstructor,
|
||||||
listOf(),
|
listOf(),
|
||||||
false,
|
false,
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ private fun captureFromArguments(type: UnwrappedType, status: CaptureStatus): Un
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun UnwrappedType.replaceArguments(arguments: List<TypeProjection>) =
|
private fun UnwrappedType.replaceArguments(arguments: List<TypeProjection>) =
|
||||||
KotlinTypeFactory.simpleType(annotations, constructor, arguments, isMarkedNullable)
|
KotlinTypeFactory.simpleType(attributes, constructor, arguments, isMarkedNullable)
|
||||||
|
|
||||||
private fun captureArguments(type: UnwrappedType, status: CaptureStatus): List<TypeProjection>? {
|
private fun captureArguments(type: UnwrappedType, status: CaptureStatus): List<TypeProjection>? {
|
||||||
if (type.arguments.size != type.constructor.parameters.size) return null
|
if (type.arguments.size != type.constructor.parameters.size) return null
|
||||||
@@ -207,14 +207,14 @@ class NewCapturedType(
|
|||||||
captureStatus: CaptureStatus, lowerType: UnwrappedType?, projection: TypeProjection, typeParameter: TypeParameterDescriptor
|
captureStatus: CaptureStatus, lowerType: UnwrappedType?, projection: TypeProjection, typeParameter: TypeParameterDescriptor
|
||||||
) : this(captureStatus, NewCapturedTypeConstructor(projection, typeParameter = typeParameter), lowerType)
|
) : this(captureStatus, NewCapturedTypeConstructor(projection, typeParameter = typeParameter), lowerType)
|
||||||
|
|
||||||
|
override val annotations: Annotations
|
||||||
|
get() = attributes.toDefaultAnnotations()
|
||||||
|
|
||||||
override val arguments: List<TypeProjection> get() = listOf()
|
override val arguments: List<TypeProjection> get() = listOf()
|
||||||
|
|
||||||
override val memberScope: MemberScope // todo what about foo().bar() where foo() return captured type?
|
override val memberScope: MemberScope // todo what about foo().bar() where foo() return captured type?
|
||||||
get() = ErrorUtils.createErrorScope("No member resolution should be done on captured type!", true)
|
get() = ErrorUtils.createErrorScope("No member resolution should be done on captured type!", true)
|
||||||
|
|
||||||
override fun replaceAnnotations(newAnnotations: Annotations) =
|
|
||||||
NewCapturedType(captureStatus, constructor, lowerType, newAnnotations.toDefaultAttributes(), isMarkedNullable)
|
|
||||||
|
|
||||||
override fun replaceAttributes(newAttributes: TypeAttributes): SimpleType =
|
override fun replaceAttributes(newAttributes: TypeAttributes): SimpleType =
|
||||||
NewCapturedType(captureStatus, constructor, lowerType, newAttributes, isMarkedNullable)
|
NewCapturedType(captureStatus, constructor, lowerType, newAttributes, isMarkedNullable)
|
||||||
|
|
||||||
|
|||||||
@@ -52,9 +52,6 @@ class DynamicType(
|
|||||||
|
|
||||||
override val isMarkedNullable: Boolean get() = false
|
override val isMarkedNullable: Boolean get() = false
|
||||||
|
|
||||||
override fun replaceAnnotations(newAnnotations: Annotations): DynamicType =
|
|
||||||
DynamicType(delegate.builtIns, attributes.replaceAnnotations(newAnnotations))
|
|
||||||
|
|
||||||
override fun replaceAttributes(newAttributes: TypeAttributes): DynamicType =
|
override fun replaceAttributes(newAttributes: TypeAttributes): DynamicType =
|
||||||
DynamicType(delegate.builtIns, newAttributes)
|
DynamicType(delegate.builtIns, newAttributes)
|
||||||
|
|
||||||
|
|||||||
+11
-2
@@ -6,20 +6,29 @@
|
|||||||
package org.jetbrains.kotlin.types.extensions
|
package org.jetbrains.kotlin.types.extensions
|
||||||
|
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
|
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||||
import org.jetbrains.kotlin.extensions.ProjectExtensionDescriptor
|
import org.jetbrains.kotlin.extensions.ProjectExtensionDescriptor
|
||||||
import org.jetbrains.kotlin.types.*
|
import org.jetbrains.kotlin.types.*
|
||||||
|
|
||||||
interface TypeAttributeTranslatorExtension : TypeAttributeTranslator
|
interface TypeAttributeTranslatorExtension : TypeAttributeTranslator
|
||||||
|
|
||||||
|
class TypeAttributeTranslatorsForInjection(project: Project) {
|
||||||
|
val translators: List<TypeAttributeTranslator> = TypeAttributeTranslators(project).translators
|
||||||
|
}
|
||||||
|
|
||||||
class TypeAttributeTranslators private constructor(val translators: List<TypeAttributeTranslator>) {
|
class TypeAttributeTranslators private constructor(val translators: List<TypeAttributeTranslator>) {
|
||||||
|
|
||||||
constructor(project: Project) : this(getInstances(project) + DefaultTypeAttributeTranslator)
|
constructor(project: Project) : this(getInstances(project) + DefaultTypeAttributeTranslator)
|
||||||
|
|
||||||
|
|
||||||
fun toAttributes(annotations: Annotations): TypeAttributes {
|
fun toAttributes(
|
||||||
|
annotations: Annotations,
|
||||||
|
typeConstructor: TypeConstructor,
|
||||||
|
containingDeclaration: DeclarationDescriptor? = null
|
||||||
|
): TypeAttributes {
|
||||||
val translated = translators.map { translator ->
|
val translated = translators.map { translator ->
|
||||||
translator.toAttributes(annotations)
|
translator.toAttributes(annotations, typeConstructor, containingDeclaration)
|
||||||
}.flatten()
|
}.flatten()
|
||||||
return TypeAttributes.create(translated)
|
return TypeAttributes.create(translated)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -125,9 +125,6 @@ class FlexibleTypeImpl(lowerBound: SimpleType, upperBound: SimpleType) : Flexibl
|
|||||||
}.inheritEnhancement(unwrapped)
|
}.inheritEnhancement(unwrapped)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun replaceAnnotations(newAnnotations: Annotations): UnwrappedType =
|
|
||||||
KotlinTypeFactory.flexibleType(lowerBound.replaceAnnotations(newAnnotations), upperBound.replaceAnnotations(newAnnotations))
|
|
||||||
|
|
||||||
override fun replaceAttributes(newAttributes: TypeAttributes): UnwrappedType =
|
override fun replaceAttributes(newAttributes: TypeAttributes): UnwrappedType =
|
||||||
KotlinTypeFactory.flexibleType(lowerBound.replaceAttributes(newAttributes), upperBound.replaceAttributes(newAttributes))
|
KotlinTypeFactory.flexibleType(lowerBound.replaceAttributes(newAttributes), upperBound.replaceAttributes(newAttributes))
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -34,7 +34,7 @@ import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
|||||||
import org.jetbrains.kotlin.serialization.deserialization.builtins.BuiltInSerializerProtocol
|
import org.jetbrains.kotlin.serialization.deserialization.builtins.BuiltInSerializerProtocol
|
||||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedPackageMemberScope
|
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedPackageMemberScope
|
||||||
import org.jetbrains.kotlin.storage.StorageManager
|
import org.jetbrains.kotlin.storage.StorageManager
|
||||||
import org.jetbrains.kotlin.types.TypeAttributeTranslator
|
import org.jetbrains.kotlin.types.extensions.TypeAttributeTranslatorsForInjection
|
||||||
import org.jetbrains.kotlin.types.checker.NewKotlinTypeChecker
|
import org.jetbrains.kotlin.types.checker.NewKotlinTypeChecker
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
|
|
||||||
@@ -47,7 +47,7 @@ class MetadataPackageFragmentProvider(
|
|||||||
contractDeserializer: ContractDeserializer,
|
contractDeserializer: ContractDeserializer,
|
||||||
kotlinTypeChecker: NewKotlinTypeChecker,
|
kotlinTypeChecker: NewKotlinTypeChecker,
|
||||||
samConversionResolver: SamConversionResolver,
|
samConversionResolver: SamConversionResolver,
|
||||||
typeAttributeTranslators: List<TypeAttributeTranslator>
|
typeAttributeTranslators: TypeAttributeTranslatorsForInjection
|
||||||
) : AbstractDeserializedPackageFragmentProvider(storageManager, finder, moduleDescriptor) {
|
) : AbstractDeserializedPackageFragmentProvider(storageManager, finder, moduleDescriptor) {
|
||||||
init {
|
init {
|
||||||
components = DeserializationComponents(
|
components = DeserializationComponents(
|
||||||
@@ -68,7 +68,7 @@ class MetadataPackageFragmentProvider(
|
|||||||
BuiltInSerializerProtocol.extensionRegistry,
|
BuiltInSerializerProtocol.extensionRegistry,
|
||||||
kotlinTypeChecker,
|
kotlinTypeChecker,
|
||||||
samConversionResolver,
|
samConversionResolver,
|
||||||
typeAttributeTranslators = typeAttributeTranslators
|
typeAttributeTranslators = typeAttributeTranslators.translators
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+10
-4
@@ -67,9 +67,13 @@ class TypeDeserializer(
|
|||||||
return simpleType(proto, expandTypeAliases = true)
|
return simpleType(proto, expandTypeAliases = true)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun List<TypeAttributeTranslator>.toAttributes(annotations: Annotations): TypeAttributes {
|
private fun List<TypeAttributeTranslator>.toAttributes(
|
||||||
|
annotations: Annotations,
|
||||||
|
constructor: TypeConstructor,
|
||||||
|
containingDeclaration: DeclarationDescriptor
|
||||||
|
): TypeAttributes {
|
||||||
val translated = this.map { translator ->
|
val translated = this.map { translator ->
|
||||||
translator.toAttributes(annotations)
|
translator.toAttributes(annotations, constructor, containingDeclaration)
|
||||||
}.flatten()
|
}.flatten()
|
||||||
return TypeAttributes.create(translated)
|
return TypeAttributes.create(translated)
|
||||||
}
|
}
|
||||||
@@ -92,7 +96,7 @@ class TypeDeserializer(
|
|||||||
c.components.annotationAndConstantLoader.loadTypeAnnotations(proto, c.nameResolver)
|
c.components.annotationAndConstantLoader.loadTypeAnnotations(proto, c.nameResolver)
|
||||||
}
|
}
|
||||||
|
|
||||||
val attributes = c.components.typeAttributeTranslators.toAttributes(annotations)
|
val attributes = c.components.typeAttributeTranslators.toAttributes(annotations, constructor, c.containingDeclaration)
|
||||||
|
|
||||||
fun ProtoBuf.Type.collectAllArguments(): List<ProtoBuf.Type.Argument> =
|
fun ProtoBuf.Type.collectAllArguments(): List<ProtoBuf.Type.Argument> =
|
||||||
argumentList + outerType(c.typeTable)?.collectAllArguments().orEmpty()
|
argumentList + outerType(c.typeTable)?.collectAllArguments().orEmpty()
|
||||||
@@ -107,7 +111,9 @@ class TypeDeserializer(
|
|||||||
expandTypeAliases && declarationDescriptor is TypeAliasDescriptor -> {
|
expandTypeAliases && declarationDescriptor is TypeAliasDescriptor -> {
|
||||||
val expandedType = with(KotlinTypeFactory) { declarationDescriptor.computeExpandedType(arguments) }
|
val expandedType = with(KotlinTypeFactory) { declarationDescriptor.computeExpandedType(arguments) }
|
||||||
val expandedAttributes = c.components.typeAttributeTranslators.toAttributes(
|
val expandedAttributes = c.components.typeAttributeTranslators.toAttributes(
|
||||||
Annotations.create(annotations + expandedType.annotations)
|
Annotations.create(annotations + expandedType.annotations),
|
||||||
|
constructor,
|
||||||
|
c.containingDeclaration
|
||||||
)
|
)
|
||||||
expandedType
|
expandedType
|
||||||
.makeNullableAsSpecified(expandedType.isNullable() || proto.nullable)
|
.makeNullableAsSpecified(expandedType.isNullable() || proto.nullable)
|
||||||
|
|||||||
@@ -56,18 +56,18 @@ fun KClassifier.createType(
|
|||||||
|
|
||||||
// TODO: throw exception if argument does not satisfy bounds
|
// TODO: throw exception if argument does not satisfy bounds
|
||||||
|
|
||||||
val typeAnnotations =
|
val typeAttributes =
|
||||||
if (annotations.isEmpty()) Annotations.EMPTY
|
if (annotations.isEmpty()) TypeAttributes.Empty
|
||||||
else Annotations.EMPTY // TODO: support type annotations
|
else TypeAttributes.Empty // TODO: support type annotations
|
||||||
|
|
||||||
return KTypeImpl(createKotlinType(typeAnnotations, typeConstructor, arguments, nullable))
|
return KTypeImpl(createKotlinType(typeAttributes, typeConstructor, arguments, nullable))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createKotlinType(
|
private fun createKotlinType(
|
||||||
typeAnnotations: Annotations, typeConstructor: TypeConstructor, arguments: List<KTypeProjection>, nullable: Boolean
|
attributes: TypeAttributes, typeConstructor: TypeConstructor, arguments: List<KTypeProjection>, nullable: Boolean
|
||||||
): SimpleType {
|
): SimpleType {
|
||||||
val parameters = typeConstructor.parameters
|
val parameters = typeConstructor.parameters
|
||||||
return KotlinTypeFactory.simpleType(typeAnnotations, typeConstructor, arguments.mapIndexed { index, typeProjection ->
|
return KotlinTypeFactory.simpleType(attributes, typeConstructor, arguments.mapIndexed { index, typeProjection ->
|
||||||
val type = (typeProjection.type as KTypeImpl?)?.type
|
val type = (typeProjection.type as KTypeImpl?)?.type
|
||||||
when (typeProjection.variance) {
|
when (typeProjection.variance) {
|
||||||
KVariance.INVARIANT -> TypeProjectionImpl(Variance.INVARIANT, type!!)
|
KVariance.INVARIANT -> TypeProjectionImpl(Variance.INVARIANT, type!!)
|
||||||
|
|||||||
+2
-5
@@ -30,10 +30,7 @@ import org.jetbrains.kotlin.resolve.DescriptorFactory
|
|||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
|
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
|
||||||
import org.jetbrains.kotlin.resolve.source.PsiSourceElement
|
import org.jetbrains.kotlin.resolve.source.PsiSourceElement
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.*
|
||||||
import org.jetbrains.kotlin.types.KotlinTypeFactory
|
|
||||||
import org.jetbrains.kotlin.types.SimpleType
|
|
||||||
import org.jetbrains.kotlin.types.StarProjectionImpl
|
|
||||||
|
|
||||||
private class XmlSourceElement(override val psi: PsiElement) : PsiSourceElement
|
private class XmlSourceElement(override val psi: PsiElement) : PsiSourceElement
|
||||||
|
|
||||||
@@ -70,7 +67,7 @@ internal fun genPropertyForWidget(
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
KotlinTypeFactory.simpleNotNullType(
|
KotlinTypeFactory.simpleNotNullType(
|
||||||
Annotations.EMPTY, classDescriptor, defaultType.constructor.parameters.map(::StarProjectionImpl))
|
TypeAttributes.Empty, classDescriptor, defaultType.constructor.parameters.map(::StarProjectionImpl))
|
||||||
}
|
}
|
||||||
} ?: context.view
|
} ?: context.view
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -53,7 +53,7 @@ internal fun ClassDescriptor.createSerializerTypeFor(argument: SimpleType, baseS
|
|||||||
val types = listOf(TypeProjectionImpl(projectionType, argument))
|
val types = listOf(TypeProjectionImpl(projectionType, argument))
|
||||||
val descriptor = module.findClassAcrossModuleDependencies(ClassId.topLevel(baseSerializerInterface))
|
val descriptor = module.findClassAcrossModuleDependencies(ClassId.topLevel(baseSerializerInterface))
|
||||||
?: throw IllegalArgumentException("Can't locate $baseSerializerInterface. Is kotlinx-serialization library present in compile classpath?")
|
?: throw IllegalArgumentException("Can't locate $baseSerializerInterface. Is kotlinx-serialization library present in compile classpath?")
|
||||||
return KotlinTypeFactory.simpleNotNullType(Annotations.EMPTY, descriptor, types)
|
return KotlinTypeFactory.simpleNotNullType(TypeAttributes.Empty, descriptor, types)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun extractKSerializerArgumentFromImplementation(implementationClass: ClassDescriptor): KotlinType? {
|
internal fun extractKSerializerArgumentFromImplementation(implementationClass: ClassDescriptor): KotlinType? {
|
||||||
|
|||||||
+8
-8
@@ -58,7 +58,7 @@ object KSerializerDescriptorResolver {
|
|||||||
if (!classDescriptor.needSerializerFactory()) return
|
if (!classDescriptor.needSerializerFactory()) return
|
||||||
val serializerFactoryClass =
|
val serializerFactoryClass =
|
||||||
classDescriptor.module.getClassFromInternalSerializationPackage("SerializerFactory")
|
classDescriptor.module.getClassFromInternalSerializationPackage("SerializerFactory")
|
||||||
supertypes.add(KotlinTypeFactory.simpleNotNullType(Annotations.EMPTY, serializerFactoryClass, listOf()))
|
supertypes.add(KotlinTypeFactory.simpleNotNullType(TypeAttributes.Empty, serializerFactoryClass, listOf()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addSerializerSupertypes(classDescriptor: ClassDescriptor, supertypes: MutableList<KotlinType>) {
|
fun addSerializerSupertypes(classDescriptor: ClassDescriptor, supertypes: MutableList<KotlinType>) {
|
||||||
@@ -393,7 +393,7 @@ object KSerializerDescriptorResolver {
|
|||||||
assert(serializableDescriptor.declaredTypeParameters.size == typeParameters.size)
|
assert(serializableDescriptor.declaredTypeParameters.size == typeParameters.size)
|
||||||
val args = List(serializableDescriptor.declaredTypeParameters.size) { index ->
|
val args = List(serializableDescriptor.declaredTypeParameters.size) { index ->
|
||||||
val pType = KotlinTypeFactory.simpleNotNullType(
|
val pType = KotlinTypeFactory.simpleNotNullType(
|
||||||
Annotations.EMPTY,
|
TypeAttributes.Empty,
|
||||||
serializerClass,
|
serializerClass,
|
||||||
listOf(TypeProjectionImpl(typeParameters[index].defaultType))
|
listOf(TypeProjectionImpl(typeParameters[index].defaultType))
|
||||||
)
|
)
|
||||||
@@ -430,7 +430,7 @@ object KSerializerDescriptorResolver {
|
|||||||
)
|
)
|
||||||
|
|
||||||
val pType =
|
val pType =
|
||||||
KotlinTypeFactory.simpleNotNullType(Annotations.EMPTY, serializerClass, listOf(TypeProjectionImpl(targ.defaultType)))
|
KotlinTypeFactory.simpleNotNullType(TypeAttributes.Empty, serializerClass, listOf(TypeProjectionImpl(targ.defaultType)))
|
||||||
|
|
||||||
args.add(
|
args.add(
|
||||||
ValueParameterDescriptorImpl(
|
ValueParameterDescriptorImpl(
|
||||||
@@ -467,7 +467,7 @@ object KSerializerDescriptorResolver {
|
|||||||
|
|
||||||
val kSerializerStarType =
|
val kSerializerStarType =
|
||||||
KotlinTypeFactory.simpleNotNullType(
|
KotlinTypeFactory.simpleNotNullType(
|
||||||
Annotations.EMPTY,
|
TypeAttributes.Empty,
|
||||||
serializerClass,
|
serializerClass,
|
||||||
listOf(StarProjectionImpl(serializerClass.typeConstructor.parameters.first()))
|
listOf(StarProjectionImpl(serializerClass.typeConstructor.parameters.first()))
|
||||||
)
|
)
|
||||||
@@ -517,9 +517,9 @@ object KSerializerDescriptorResolver {
|
|||||||
val (typeArgs, args) = createKSerializerParamsForEachGenericArgument(f, serializableClass)
|
val (typeArgs, args) = createKSerializerParamsForEachGenericArgument(f, serializableClass)
|
||||||
|
|
||||||
val newSerializableType =
|
val newSerializableType =
|
||||||
KotlinTypeFactory.simpleNotNullType(Annotations.EMPTY, serializableClass, typeArgs.map { TypeProjectionImpl(it.defaultType) })
|
KotlinTypeFactory.simpleNotNullType(TypeAttributes.Empty, serializableClass, typeArgs.map { TypeProjectionImpl(it.defaultType) })
|
||||||
val serialReturnType =
|
val serialReturnType =
|
||||||
KotlinTypeFactory.simpleNotNullType(Annotations.EMPTY, serializerClass, listOf(TypeProjectionImpl(newSerializableType)))
|
KotlinTypeFactory.simpleNotNullType(TypeAttributes.Empty, serializerClass, listOf(TypeProjectionImpl(newSerializableType)))
|
||||||
|
|
||||||
f.initialize(null, thisClass.thisAsReceiverParameter, emptyList(), typeArgs, args, serialReturnType, Modality.FINAL, DescriptorVisibilities.PUBLIC)
|
f.initialize(null, thisClass.thisAsReceiverParameter, emptyList(), typeArgs, args, serialReturnType, Modality.FINAL, DescriptorVisibilities.PUBLIC)
|
||||||
return f
|
return f
|
||||||
@@ -550,7 +550,7 @@ object KSerializerDescriptorResolver {
|
|||||||
|
|
||||||
// object
|
// object
|
||||||
val objectType =
|
val objectType =
|
||||||
KotlinTypeFactory.simpleNotNullType(Annotations.EMPTY, thisClass, typeArgs.map { TypeProjectionImpl(it.defaultType) })
|
KotlinTypeFactory.simpleNotNullType(TypeAttributes.Empty, thisClass, typeArgs.map { TypeProjectionImpl(it.defaultType) })
|
||||||
args.add(
|
args.add(
|
||||||
ValueParameterDescriptorImpl(
|
ValueParameterDescriptorImpl(
|
||||||
containingDeclaration = f,
|
containingDeclaration = f,
|
||||||
@@ -646,7 +646,7 @@ object KSerializerDescriptorResolver {
|
|||||||
val param = serializerDescriptor.declaredTypeParameters[index]
|
val param = serializerDescriptor.declaredTypeParameters[index]
|
||||||
val pType =
|
val pType =
|
||||||
KotlinTypeFactory.simpleNotNullType(
|
KotlinTypeFactory.simpleNotNullType(
|
||||||
Annotations.EMPTY,
|
TypeAttributes.Empty,
|
||||||
serializerClass,
|
serializerClass,
|
||||||
listOf(TypeProjectionImpl(param.defaultType))
|
listOf(TypeProjectionImpl(param.defaultType))
|
||||||
)
|
)
|
||||||
|
|||||||
+2
-1
@@ -18,6 +18,7 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.module
|
|||||||
import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyAnnotationDescriptor
|
import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyAnnotationDescriptor
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
import org.jetbrains.kotlin.types.KotlinTypeFactory
|
import org.jetbrains.kotlin.types.KotlinTypeFactory
|
||||||
|
import org.jetbrains.kotlin.types.TypeAttributes
|
||||||
|
|
||||||
internal fun ClassConstructorDescriptor.isSerializationCtor(): Boolean {
|
internal fun ClassConstructorDescriptor.isSerializationCtor(): Boolean {
|
||||||
/*kind == CallableMemberDescriptor.Kind.SYNTHESIZED does not work because DeserializedClassConstructorDescriptor loses its kind*/
|
/*kind == CallableMemberDescriptor.Kind.SYNTHESIZED does not work because DeserializedClassConstructorDescriptor loses its kind*/
|
||||||
@@ -117,7 +118,7 @@ internal fun ClassDescriptor.getClassFromInternalSerializationPackage(classSimpl
|
|||||||
module.getClassFromInternalSerializationPackage(classSimpleName)
|
module.getClassFromInternalSerializationPackage(classSimpleName)
|
||||||
|
|
||||||
fun ClassDescriptor.toSimpleType(nullable: Boolean = false) =
|
fun ClassDescriptor.toSimpleType(nullable: Boolean = false) =
|
||||||
KotlinTypeFactory.simpleType(Annotations.EMPTY, this.typeConstructor, emptyList(), nullable)
|
KotlinTypeFactory.simpleType(TypeAttributes.Empty, this.typeConstructor, emptyList(), nullable)
|
||||||
|
|
||||||
internal fun Annotated.annotationsWithArguments(): List<Triple<ClassDescriptor, List<ValueArgument>, List<ValueParameterDescriptor>>> =
|
internal fun Annotated.annotationsWithArguments(): List<Triple<ClassDescriptor, List<ValueArgument>, List<ValueParameterDescriptor>>> =
|
||||||
annotations.asSequence()
|
annotations.asSequence()
|
||||||
|
|||||||
+1
-1
@@ -69,7 +69,7 @@ private fun KotlinType.approximateNonDynamicFlexibleTypes(
|
|||||||
return AbbreviatedType(it.expandedType, it.abbreviation.approximateNonDynamicFlexibleTypes(preferNotNull))
|
return AbbreviatedType(it.expandedType, it.abbreviation.approximateNonDynamicFlexibleTypes(preferNotNull))
|
||||||
}
|
}
|
||||||
return KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(
|
return KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(
|
||||||
annotations,
|
attributes,
|
||||||
constructor,
|
constructor,
|
||||||
arguments.map { it.substitute { type -> type.approximateFlexibleTypes(preferNotNull = true) } },
|
arguments.map { it.substitute { type -> type.approximateFlexibleTypes(preferNotNull = true) } },
|
||||||
isMarkedNullable,
|
isMarkedNullable,
|
||||||
|
|||||||
Reference in New Issue
Block a user