Fixes and refactors

This commit is contained in:
Irene Dea
2021-10-21 13:22:51 -07:00
committed by Dmitriy Novozhilov
parent 2e2e70fede
commit 19bfc43bee
70 changed files with 263 additions and 327 deletions
@@ -281,7 +281,7 @@ class LazyJavaClassDescriptor(
else -> return null
}
return KotlinTypeFactory.simpleNotNullType(Annotations.EMPTY, classDescriptor, parametersAsTypeProjections)
return KotlinTypeFactory.simpleNotNullType(TypeAttributes.Empty, classDescriptor, parametersAsTypeProjections)
}
private fun getPurelyImplementsFqNameFromAnnotation(): FqName? {
@@ -119,8 +119,8 @@ class JavaTypeResolver(
attr: JavaTypeAttributes,
lowerResult: SimpleType?
): SimpleType? {
val annotations =
lowerResult?.annotations ?: LazyJavaAnnotations(c, javaType)
val attributes =
lowerResult?.attributes ?: LazyJavaAnnotations(c, javaType).toDefaultAttributes()
val constructor = computeTypeConstructor(javaType, attr) ?: return null
val isNullable = attr.isNullable()
@@ -130,7 +130,7 @@ class JavaTypeResolver(
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? {
@@ -54,9 +54,6 @@ class RawTypeImpl private constructor(lowerBound: SimpleType, upperBound: Simple
return classDescriptor.getMemberScope(RawSubstitution())
}
override fun replaceAnnotations(newAnnotations: Annotations) =
RawTypeImpl(lowerBound.replaceAnnotations(newAnnotations), upperBound.replaceAnnotations(newAnnotations))
override fun replaceAttributes(newAttributes: TypeAttributes) =
RawTypeImpl(lowerBound.replaceAttributes(newAttributes), upperBound.replaceAttributes(newAttributes))
@@ -148,7 +145,7 @@ internal class RawSubstitution(typeParameterUpperBoundEraser: TypeParameterUpper
TypeProjectionImpl(componentTypeProjection.projectionKind, eraseType(componentTypeProjection.type, attr))
)
return KotlinTypeFactory.simpleType(
type.annotations, type.constructor, arguments, type.isMarkedNullable
type.attributes, type.constructor, arguments, type.isMarkedNullable
) to false
}
@@ -156,7 +153,7 @@ internal class RawSubstitution(typeParameterUpperBoundEraser: TypeParameterUpper
val memberScope = declaration.getMemberScope(this)
return KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(
type.annotations, declaration.typeConstructor,
type.attributes, declaration.typeConstructor,
declaration.typeConstructor.parameters.map { parameter ->
computeProjection(parameter, attr)
},
@@ -150,7 +150,7 @@ class JavaTypeEnhancement(private val javaResolverSettings: JavaResolverSettings
).compositeAnnotationsOrSingle()
val enhancedType = KotlinTypeFactory.simpleType(
newAnnotations,
newAnnotations.toDefaultAttributes(),
typeConstructor,
enhancedArguments.zip(arguments) { enhanced, original -> enhanced ?: original },
enhancedNullability ?: isMarkedNullable
@@ -252,7 +252,6 @@ internal class NotNullTypeParameterImpl(override val delegate: SimpleType) : Not
return NotNullTypeParameterImpl(result)
}
override fun replaceAnnotations(newAnnotations: Annotations) = NotNullTypeParameterImpl(delegate.replaceAnnotations(newAnnotations))
override fun replaceAttributes(newAttributes: TypeAttributes) = NotNullTypeParameterImpl(delegate.replaceAttributes(newAttributes))
override fun makeNullableAsSpecified(newNullability: Boolean) =
if (newNullability) delegate.makeNullableAsSpecified(true) else this
@@ -48,7 +48,9 @@ import org.jetbrains.kotlin.resolve.sam.SamConversionResolverImpl
import org.jetbrains.kotlin.serialization.deserialization.*
import org.jetbrains.kotlin.storage.LockBasedStorageManager
import org.jetbrains.kotlin.storage.StorageManager
import org.jetbrains.kotlin.types.DefaultTypeAttributeTranslator
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.
// 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,
lookupTracker: LookupTracker,
contractDeserializer: ContractDeserializer,
kotlinTypeChecker: NewKotlinTypeChecker
kotlinTypeChecker: NewKotlinTypeChecker,
typeAttributeTranslators: TypeAttributeTranslatorsForInjection
) {
val components: DeserializationComponents
@@ -77,7 +80,8 @@ class DeserializationComponentsForJava(
additionalClassPartsProvider = jvmBuiltIns?.customizer ?: AdditionalClassPartsProvider.None,
platformDependentDeclarationFilter = jvmBuiltIns?.customizer ?: PlatformDependentDeclarationFilter.NoPlatformDependent,
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(
storageManager, module, DeserializationConfiguration.Default, javaClassDataFinder,
binaryClassAnnotationAndConstantLoader, lazyJavaPackageFragmentProvider, notFoundClasses,
errorReporter, LookupTracker.DO_NOTHING, ContractDeserializer.DEFAULT, NewKotlinTypeChecker.Default
errorReporter, LookupTracker.DO_NOTHING, ContractDeserializer.DEFAULT, NewKotlinTypeChecker.Default,
TypeAttributeTranslatorsForInjection(listOf(DefaultTypeAttributeTranslator))
)
}