Refactoring. Rename FlexibleTypeCapabilities -> FlexibleTypeFactory. Also use factory.create instead of DelegatingFlexibleType.create.
This commit is contained in:
+2
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,8 +18,6 @@ package org.jetbrains.kotlin.load.java.lazy.descriptors
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.SourceElement
|
||||
import org.jetbrains.kotlin.descriptors.SupertypeLoopChecker
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.descriptors.impl.AbstractLazyTypeParameterDescriptor
|
||||
import org.jetbrains.kotlin.load.java.components.TypeUsage
|
||||
import org.jetbrains.kotlin.load.java.lazy.LazyJavaAnnotations
|
||||
@@ -51,7 +49,7 @@ class LazyJavaTypeParameterDescriptor(
|
||||
override fun resolveUpperBounds(): List<KotlinType> {
|
||||
val bounds = javaTypeParameter.upperBounds
|
||||
if (bounds.isEmpty()) {
|
||||
return listOf(LazyJavaTypeResolver.FlexibleJavaClassifierTypeCapabilities.create(
|
||||
return listOf(LazyJavaTypeResolver.FlexibleJavaClassifierTypeFactory.create(
|
||||
c.module.builtIns.anyType,
|
||||
c.module.builtIns.nullableAnyType
|
||||
))
|
||||
|
||||
+6
-9
@@ -57,7 +57,7 @@ class LazyJavaTypeResolver(
|
||||
}
|
||||
is JavaClassifierType ->
|
||||
if (attr.allowFlexible && attr.howThisTypeIsUsed != SUPERTYPE)
|
||||
FlexibleJavaClassifierTypeCapabilities.create(
|
||||
FlexibleJavaClassifierTypeFactory.create(
|
||||
LazyJavaClassifierType(javaType, attr.toFlexible(FLEXIBLE_LOWER_BOUND)),
|
||||
LazyJavaClassifierType(javaType, attr.toFlexible(FLEXIBLE_UPPER_BOUND))
|
||||
)
|
||||
@@ -76,7 +76,7 @@ class LazyJavaTypeResolver(
|
||||
if (primitiveType != null) {
|
||||
val jetType = c.module.builtIns.getPrimitiveArrayKotlinType(primitiveType)
|
||||
return@run if (attr.allowFlexible)
|
||||
FlexibleJavaClassifierTypeCapabilities.create(jetType, TypeUtils.makeNullable(jetType))
|
||||
FlexibleJavaClassifierTypeFactory.create(jetType, TypeUtils.makeNullable(jetType))
|
||||
else TypeUtils.makeNullableAsSpecified(jetType, !attr.isMarkedNotNull)
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ class LazyJavaTypeResolver(
|
||||
TYPE_ARGUMENT.toAttributes(attr.allowFlexible, attr.isForAnnotationParameter))
|
||||
|
||||
if (attr.allowFlexible) {
|
||||
return@run FlexibleJavaClassifierTypeCapabilities.create(
|
||||
return@run FlexibleJavaClassifierTypeFactory.create(
|
||||
c.module.builtIns.getArrayType(INVARIANT, componentType),
|
||||
TypeUtils.makeNullable(c.module.builtIns.getArrayType(OUT_VARIANCE, componentType)))
|
||||
}
|
||||
@@ -284,20 +284,17 @@ class LazyJavaTypeResolver(
|
||||
override fun getAnnotations() = annotations
|
||||
}
|
||||
|
||||
object FlexibleJavaClassifierTypeCapabilities : FlexibleTypeCapabilities {
|
||||
@JvmStatic
|
||||
fun create(lowerBound: KotlinType, upperBound: KotlinType) = DelegatingFlexibleType.create(lowerBound, upperBound, this)
|
||||
|
||||
object FlexibleJavaClassifierTypeFactory : FlexibleTypeFactory {
|
||||
override val id: String get() = "kotlin.jvm.PlatformType"
|
||||
|
||||
override fun createFlexibleType(lowerBound: KotlinType, upperBound: KotlinType): KotlinType {
|
||||
override fun create(lowerBound: KotlinType, upperBound: KotlinType): KotlinType {
|
||||
if (lowerBound == upperBound) return lowerBound
|
||||
|
||||
return Impl(lowerBound, upperBound)
|
||||
}
|
||||
|
||||
private class Impl(lowerBound: KotlinType, upperBound: KotlinType) :
|
||||
DelegatingFlexibleType(lowerBound, upperBound, FlexibleJavaClassifierTypeCapabilities), CustomTypeVariable, Specificity {
|
||||
DelegatingFlexibleType(lowerBound, upperBound, FlexibleJavaClassifierTypeFactory), CustomTypeVariable, Specificity {
|
||||
|
||||
override fun <T : TypeCapability> getCapability(capabilityClass: Class<T>): T? {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -97,7 +97,7 @@ internal object RawSubstitution : TypeSubstitution() {
|
||||
is ClassDescriptor -> {
|
||||
val lower = type.lowerIfFlexible()
|
||||
val upper = type.upperIfFlexible()
|
||||
LazyJavaTypeResolver.FlexibleJavaClassifierTypeCapabilities.create(
|
||||
LazyJavaTypeResolver.FlexibleJavaClassifierTypeFactory.create(
|
||||
eraseInflexibleBasedOnClassDescriptor(lower, declaration, lowerTypeAttr),
|
||||
eraseInflexibleBasedOnClassDescriptor(upper, declaration, upperTypeAttr)
|
||||
)
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -70,7 +70,7 @@ private fun KotlinType.enhancePossiblyFlexible(qualifiers: (Int) -> JavaTypeQual
|
||||
val wereChanges = lowerResult.wereChanges || upperResult.wereChanges
|
||||
Result(
|
||||
if (wereChanges)
|
||||
DelegatingFlexibleType.create(lowerResult.type, upperResult.type, extraCapabilities)
|
||||
factory.create(lowerResult.type, upperResult.type)
|
||||
else
|
||||
this@enhancePossiblyFlexible,
|
||||
lowerResult.subtreeSize,
|
||||
@@ -229,7 +229,7 @@ internal object NotNullTypeParameterTypeCapability : CustomTypeVariable {
|
||||
|
||||
if (replacement.isFlexible()) {
|
||||
with(replacement.flexibility()) {
|
||||
return DelegatingFlexibleType.create(lowerBound.prepareReplacement(), upperBound.prepareReplacement(), extraCapabilities)
|
||||
return factory.create(lowerBound.prepareReplacement(), upperBound.prepareReplacement())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -40,7 +40,7 @@ class DeserializationComponentsForJava(
|
||||
val localClassResolver = LocalClassResolverImpl()
|
||||
components = DeserializationComponents(
|
||||
storageManager, moduleDescriptor, classDataFinder, annotationAndConstantLoader, packageFragmentProvider, localClassResolver,
|
||||
errorReporter, lookupTracker, JavaFlexibleTypeCapabilitiesDeserializer, ClassDescriptorFactory.EMPTY,
|
||||
errorReporter, lookupTracker, JavaFlexibleTypeFactoryDeserializer, ClassDescriptorFactory.EMPTY,
|
||||
notFoundClasses, JavaTypeCapabilitiesLoader,
|
||||
additionalSupertypes = BuiltInClassesAreSerializableOnJvm(moduleDescriptor)
|
||||
)
|
||||
|
||||
+7
-7
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,14 +16,14 @@
|
||||
|
||||
package org.jetbrains.kotlin.load.kotlin
|
||||
|
||||
import org.jetbrains.kotlin.serialization.deserialization.FlexibleTypeCapabilitiesDeserializer
|
||||
import org.jetbrains.kotlin.load.java.lazy.types.LazyJavaTypeResolver
|
||||
import org.jetbrains.kotlin.types.FlexibleTypeCapabilities
|
||||
import org.jetbrains.kotlin.serialization.deserialization.FlexibleTypeFactoryDeserializer
|
||||
import org.jetbrains.kotlin.types.FlexibleTypeFactory
|
||||
|
||||
object JavaFlexibleTypeCapabilitiesDeserializer : FlexibleTypeCapabilitiesDeserializer {
|
||||
override fun capabilitiesById(id: String): FlexibleTypeCapabilities? {
|
||||
return if (id == LazyJavaTypeResolver.FlexibleJavaClassifierTypeCapabilities.id)
|
||||
LazyJavaTypeResolver.FlexibleJavaClassifierTypeCapabilities
|
||||
object JavaFlexibleTypeFactoryDeserializer : FlexibleTypeFactoryDeserializer {
|
||||
override fun capabilitiesById(id: String): FlexibleTypeFactory? {
|
||||
return if (id == LazyJavaTypeResolver.FlexibleJavaClassifierTypeFactory.id)
|
||||
LazyJavaTypeResolver.FlexibleJavaClassifierTypeFactory
|
||||
else null
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user