Refactoring. Rename FlexibleTypeCapabilities -> FlexibleTypeFactory. Also use factory.create instead of DelegatingFlexibleType.create.
This commit is contained in:
@@ -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.
|
||||
@@ -25,7 +25,7 @@ import org.jetbrains.kotlin.descriptors.PackagePartProvider
|
||||
import org.jetbrains.kotlin.frontend.di.configureModule
|
||||
import org.jetbrains.kotlin.incremental.components.LookupTracker
|
||||
import org.jetbrains.kotlin.load.java.JavaClassFinderImpl
|
||||
import org.jetbrains.kotlin.load.java.JavaFlexibleTypeCapabilitiesProvider
|
||||
import org.jetbrains.kotlin.load.java.JavaFlexibleTypeFactoryProvider
|
||||
import org.jetbrains.kotlin.load.java.components.*
|
||||
import org.jetbrains.kotlin.load.java.lazy.ModuleClassResolver
|
||||
import org.jetbrains.kotlin.load.java.lazy.SingleModuleClassResolver
|
||||
@@ -62,7 +62,7 @@ fun StorageComponentContainer.configureJavaTopDownAnalysis(moduleContentScope: G
|
||||
useInstance(SamConversionResolverImpl)
|
||||
useImpl<JavaSourceElementFactoryImpl>()
|
||||
useImpl<JavaLazyAnalyzerPostConstruct>()
|
||||
useImpl<JavaFlexibleTypeCapabilitiesProvider>()
|
||||
useInstance(JavaFlexibleTypeFactoryProvider)
|
||||
}
|
||||
|
||||
fun createContainerForLazyResolveWithJava(
|
||||
|
||||
+5
-5
@@ -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,10 +16,10 @@
|
||||
|
||||
package org.jetbrains.kotlin.load.java
|
||||
|
||||
import org.jetbrains.kotlin.resolve.TypeResolver.FlexibleTypeCapabilitiesProvider
|
||||
import org.jetbrains.kotlin.types.FlexibleTypeCapabilities
|
||||
import org.jetbrains.kotlin.load.java.lazy.types.LazyJavaTypeResolver
|
||||
import org.jetbrains.kotlin.resolve.TypeResolver.FlexibleTypeFactoryProvider
|
||||
import org.jetbrains.kotlin.types.FlexibleTypeFactory
|
||||
|
||||
class JavaFlexibleTypeCapabilitiesProvider : FlexibleTypeCapabilitiesProvider() {
|
||||
override fun getCapabilities(): FlexibleTypeCapabilities = LazyJavaTypeResolver.FlexibleJavaClassifierTypeCapabilities
|
||||
object JavaFlexibleTypeFactoryProvider : FlexibleTypeFactoryProvider() {
|
||||
override val factory: FlexibleTypeFactory get() = LazyJavaTypeResolver.FlexibleJavaClassifierTypeFactory
|
||||
}
|
||||
+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.
|
||||
@@ -72,7 +72,7 @@ public class SingleAbstractMethodUtils {
|
||||
"' should not end with conflict";
|
||||
|
||||
if (FlexibleTypesKt.isNullabilityFlexible(samType)) {
|
||||
return LazyJavaTypeResolver.FlexibleJavaClassifierTypeCapabilities.create(type, TypeUtils.makeNullable(type));
|
||||
return LazyJavaTypeResolver.FlexibleJavaClassifierTypeFactory.INSTANCE.create(type, TypeUtils.makeNullable(type));
|
||||
}
|
||||
|
||||
return TypeUtils.makeNullableAsSpecified(type, samType.isMarkedNullable());
|
||||
|
||||
@@ -50,7 +50,7 @@ class TypeResolver(
|
||||
private val annotationResolver: AnnotationResolver,
|
||||
private val qualifiedExpressionResolver: QualifiedExpressionResolver,
|
||||
private val moduleDescriptor: ModuleDescriptor,
|
||||
private val flexibleTypeCapabilitiesProvider: FlexibleTypeCapabilitiesProvider,
|
||||
private val flexibleTypeFactoryProvider: FlexibleTypeFactoryProvider,
|
||||
private val storageManager: StorageManager,
|
||||
private val lazinessToken: TypeLazinessToken,
|
||||
private val dynamicTypesSettings: DynamicTypesSettings,
|
||||
@@ -58,10 +58,8 @@ class TypeResolver(
|
||||
private val identifierChecker: IdentifierChecker
|
||||
) {
|
||||
|
||||
open class FlexibleTypeCapabilitiesProvider {
|
||||
open fun getCapabilities(): FlexibleTypeCapabilities {
|
||||
return FlexibleTypeCapabilities.NONE
|
||||
}
|
||||
open class FlexibleTypeFactoryProvider {
|
||||
open val factory: FlexibleTypeFactory get() = FlexibleTypeFactory.DEFAULT
|
||||
}
|
||||
|
||||
fun resolveType(scope: LexicalScope, typeReference: KtTypeReference, trace: BindingTrace, checkBounds: Boolean): KotlinType {
|
||||
@@ -373,10 +371,8 @@ class TypeResolver(
|
||||
&& parameters.size == 2) {
|
||||
// We create flexible types by convention here
|
||||
// This is not intended to be used in normal users' environments, only for tests and debugger etc
|
||||
return type(DelegatingFlexibleType.create(
|
||||
arguments[0].type,
|
||||
arguments[1].type,
|
||||
flexibleTypeCapabilitiesProvider.getCapabilities())
|
||||
return type(flexibleTypeFactoryProvider.factory.create(arguments[0].type,
|
||||
arguments[1].type)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -25,7 +25,6 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt;
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope;
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker;
|
||||
import org.jetbrains.kotlin.types.typeUtil.TypeUtilsKt;
|
||||
@@ -86,14 +85,14 @@ public class CommonSupertypes {
|
||||
boolean hasFlexible = false;
|
||||
List<KotlinType> upper = new ArrayList<KotlinType>(types.size());
|
||||
List<KotlinType> lower = new ArrayList<KotlinType>(types.size());
|
||||
Set<FlexibleTypeCapabilities> capabilities = new LinkedHashSet<FlexibleTypeCapabilities>();
|
||||
Set<FlexibleTypeFactory> factories = new LinkedHashSet<FlexibleTypeFactory>();
|
||||
for (KotlinType type : types) {
|
||||
if (FlexibleTypesKt.isFlexible(type)) {
|
||||
hasFlexible = true;
|
||||
Flexibility flexibility = FlexibleTypesKt.flexibility(type);
|
||||
upper.add(flexibility.getUpperBound());
|
||||
lower.add(flexibility.getLowerBound());
|
||||
capabilities.add(flexibility.getExtraCapabilities());
|
||||
factories.add(flexibility.getFactory());
|
||||
}
|
||||
else {
|
||||
upper.add(type);
|
||||
@@ -102,10 +101,9 @@ public class CommonSupertypes {
|
||||
}
|
||||
|
||||
if (!hasFlexible) return commonSuperTypeForInflexible(types, recursionDepth, maxDepth);
|
||||
return DelegatingFlexibleType.create(
|
||||
return CollectionsKt.single(factories).create( // mixing different factories is not supported
|
||||
commonSuperTypeForInflexible(lower, recursionDepth, maxDepth),
|
||||
commonSuperTypeForInflexible(upper, recursionDepth, maxDepth),
|
||||
CollectionsKt.single(capabilities) // mixing different capabilities is not supported
|
||||
commonSuperTypeForInflexible(upper, recursionDepth, maxDepth)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+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.
|
||||
@@ -465,7 +465,7 @@ public class DescriptorSerializer {
|
||||
Flexibility flexibility = FlexibleTypesKt.flexibility(type);
|
||||
|
||||
ProtoBuf.Type.Builder lowerBound = type(flexibility.getLowerBound());
|
||||
lowerBound.setFlexibleTypeCapabilitiesId(getStringTable().getStringIndex(flexibility.getExtraCapabilities().getId()));
|
||||
lowerBound.setFlexibleTypeCapabilitiesId(getStringTable().getStringIndex(flexibility.getFactory().getId()));
|
||||
if (useTypeTable()) {
|
||||
lowerBound.setFlexibleUpperBoundId(typeId(flexibility.getUpperBound()));
|
||||
}
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ class FlexibleTypeAssertionsEnabledTest : KotlinTestWithEnvironmentManagement()
|
||||
val builtIns = JvmPlatform.builtIns
|
||||
|
||||
try {
|
||||
LazyJavaTypeResolver.FlexibleJavaClassifierTypeCapabilities.create(
|
||||
LazyJavaTypeResolver.FlexibleJavaClassifierTypeFactory.create(
|
||||
builtIns.intType, builtIns.stringType).arguments
|
||||
} catch (e: AssertionError) {
|
||||
assertEquals("Lower bound Int of a flexible type must be a subtype of the upper bound String", e.message)
|
||||
|
||||
+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
|
||||
}
|
||||
|
||||
+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.
|
||||
@@ -50,7 +50,7 @@ fun createBuiltInPackageFragmentProvider(
|
||||
localClassResolver,
|
||||
ErrorReporter.DO_NOTHING,
|
||||
LookupTracker.DO_NOTHING,
|
||||
FlexibleTypeCapabilitiesDeserializer.ThrowException,
|
||||
FlexibleTypeFactoryDeserializer.ThrowException,
|
||||
classDescriptorFactory,
|
||||
notFoundClasses,
|
||||
additionalSupertypes = additionalSupertypes
|
||||
|
||||
@@ -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.
|
||||
@@ -23,8 +23,7 @@ import org.jetbrains.kotlin.resolve.calls.inference.isCaptured
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||
import org.jetbrains.kotlin.types.typeUtil.*
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.check
|
||||
import org.jetbrains.kotlin.types.typeUtil.builtIns
|
||||
import java.util.*
|
||||
|
||||
data class ApproximationBounds<T>(
|
||||
@@ -98,12 +97,10 @@ fun approximateCapturedTypes(type: KotlinType): ApproximationBounds<KotlinType>
|
||||
val boundsForFlexibleLower = approximateCapturedTypes(type.lowerIfFlexible())
|
||||
val boundsForFlexibleUpper = approximateCapturedTypes(type.upperIfFlexible())
|
||||
|
||||
val extraCapabilities = type.flexibility().extraCapabilities
|
||||
val factory = type.flexibility().factory
|
||||
return ApproximationBounds(
|
||||
DelegatingFlexibleType.create(
|
||||
boundsForFlexibleLower.lower.lowerIfFlexible(), boundsForFlexibleUpper.lower.upperIfFlexible(), extraCapabilities),
|
||||
DelegatingFlexibleType.create(
|
||||
boundsForFlexibleLower.upper.lowerIfFlexible(), boundsForFlexibleUpper.upper.upperIfFlexible(), extraCapabilities))
|
||||
factory.create(boundsForFlexibleLower.lower.lowerIfFlexible(), boundsForFlexibleUpper.lower.upperIfFlexible()),
|
||||
factory.create(boundsForFlexibleLower.upper.lowerIfFlexible(), boundsForFlexibleUpper.upper.upperIfFlexible()))
|
||||
}
|
||||
|
||||
val typeConstructor = type.constructor
|
||||
|
||||
@@ -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.
|
||||
@@ -146,8 +146,8 @@ public class TypeSubstitutor {
|
||||
originalProjectionKind == Variance.INVARIANT || originalProjectionKind == substitutedProjectionKind :
|
||||
"Unexpected substituted projection kind: " + substitutedProjectionKind + "; original: " + originalProjectionKind;
|
||||
|
||||
KotlinType substitutedFlexibleType = DelegatingFlexibleType.create(
|
||||
substitutedLower.getType(), substitutedUpper.getType(), flexibility.getExtraCapabilities());
|
||||
KotlinType substitutedFlexibleType = flexibility.getFactory().create(
|
||||
substitutedLower.getType(), substitutedUpper.getType());
|
||||
return new TypeProjectionImpl(substitutedProjectionKind, substitutedFlexibleType);
|
||||
}
|
||||
|
||||
|
||||
@@ -33,17 +33,17 @@ interface Dynamicity : TypeCapability
|
||||
|
||||
fun KotlinType.isDynamic(): Boolean = this.getCapability(Dynamicity::class.java) != null
|
||||
|
||||
fun createDynamicType(builtIns: KotlinBuiltIns) = DynamicTypeCapabilities.createFlexibleType(builtIns.nothingType, builtIns.nullableAnyType)
|
||||
fun createDynamicType(builtIns: KotlinBuiltIns) = DynamicTypeFactory.create(builtIns.nothingType, builtIns.nullableAnyType)
|
||||
|
||||
object DynamicTypeCapabilities : FlexibleTypeCapabilities {
|
||||
object DynamicTypeFactory : FlexibleTypeFactory {
|
||||
override val id: String get() = "kotlin.DynamicType"
|
||||
|
||||
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, DynamicTypeCapabilities), Dynamicity, Specificity, NullAwareness, FlexibleTypeDelegation {
|
||||
private class Impl(lowerBound: KotlinType, upperBound: KotlinType) : DelegatingFlexibleType(lowerBound, upperBound, DynamicTypeFactory), Dynamicity, Specificity, NullAwareness, FlexibleTypeDelegation {
|
||||
companion object {
|
||||
internal val capabilityClasses = hashSetOf(
|
||||
Dynamicity::class.java,
|
||||
|
||||
@@ -20,17 +20,18 @@ import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||
|
||||
interface FlexibleTypeCapabilities {
|
||||
fun createFlexibleType(lowerBound: KotlinType, upperBound: KotlinType): KotlinType
|
||||
interface FlexibleTypeFactory {
|
||||
val id: String
|
||||
|
||||
object NONE : FlexibleTypeCapabilities {
|
||||
override fun createFlexibleType(lowerBound: KotlinType, upperBound: KotlinType): KotlinType {
|
||||
if (lowerBound == upperBound) return lowerBound
|
||||
return object : DelegatingFlexibleType(lowerBound, upperBound, this@NONE) {}
|
||||
}
|
||||
fun create(lowerBound: KotlinType, upperBound: KotlinType): KotlinType
|
||||
|
||||
object DEFAULT : FlexibleTypeFactory {
|
||||
override val id: String get() = "NONE"
|
||||
|
||||
override fun create(lowerBound: KotlinType, upperBound: KotlinType): KotlinType {
|
||||
if (lowerBound == upperBound) return lowerBound
|
||||
return object : DelegatingFlexibleType(lowerBound, upperBound, this@DEFAULT) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +48,7 @@ interface Flexibility : TypeCapability, SubtypingRepresentatives {
|
||||
val lowerBound: KotlinType
|
||||
val upperBound: KotlinType
|
||||
|
||||
val extraCapabilities: FlexibleTypeCapabilities
|
||||
val factory: FlexibleTypeFactory
|
||||
|
||||
override val subTypeRepresentative: KotlinType
|
||||
get() = lowerBound
|
||||
@@ -115,7 +116,7 @@ interface FlexibleTypeDelegation : TypeCapability {
|
||||
open class DelegatingFlexibleType protected constructor(
|
||||
override val lowerBound: KotlinType,
|
||||
override val upperBound: KotlinType,
|
||||
override val extraCapabilities: FlexibleTypeCapabilities
|
||||
override val factory: FlexibleTypeFactory
|
||||
) : DelegatingType(), NullAwareness, Flexibility, FlexibleTypeDelegation {
|
||||
companion object {
|
||||
internal val capabilityClasses = hashSetOf(
|
||||
@@ -125,11 +126,6 @@ open class DelegatingFlexibleType protected constructor(
|
||||
FlexibleTypeDelegation::class.java
|
||||
)
|
||||
|
||||
@JvmStatic
|
||||
fun create(lowerBound: KotlinType, upperBound: KotlinType, extraCapabilities: FlexibleTypeCapabilities): KotlinType {
|
||||
return extraCapabilities.createFlexibleType(lowerBound, upperBound)
|
||||
}
|
||||
|
||||
@JvmField
|
||||
var RUN_SLOW_ASSERTIONS = false
|
||||
}
|
||||
@@ -162,10 +158,8 @@ open class DelegatingFlexibleType protected constructor(
|
||||
}
|
||||
|
||||
override fun makeNullableAsSpecified(nullable: Boolean): KotlinType {
|
||||
return create(
|
||||
TypeUtils.makeNullableAsSpecified(lowerBound, nullable),
|
||||
TypeUtils.makeNullableAsSpecified(upperBound, nullable),
|
||||
extraCapabilities)
|
||||
return factory.create(TypeUtils.makeNullableAsSpecified(lowerBound, nullable),
|
||||
TypeUtils.makeNullableAsSpecified(upperBound, nullable))
|
||||
}
|
||||
|
||||
override fun computeIsNullable() = delegateType.isMarkedNullable
|
||||
|
||||
+10
-10
@@ -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,22 +16,22 @@
|
||||
|
||||
package org.jetbrains.kotlin.serialization.deserialization
|
||||
|
||||
import org.jetbrains.kotlin.types.DynamicTypeCapabilities
|
||||
import org.jetbrains.kotlin.types.FlexibleTypeCapabilities
|
||||
import org.jetbrains.kotlin.types.DynamicTypeFactory
|
||||
import org.jetbrains.kotlin.types.FlexibleTypeFactory
|
||||
|
||||
interface FlexibleTypeCapabilitiesDeserializer {
|
||||
object ThrowException : FlexibleTypeCapabilitiesDeserializer {
|
||||
override fun capabilitiesById(id: String): FlexibleTypeCapabilities? {
|
||||
interface FlexibleTypeFactoryDeserializer {
|
||||
object ThrowException : FlexibleTypeFactoryDeserializer {
|
||||
override fun capabilitiesById(id: String): FlexibleTypeFactory? {
|
||||
throw IllegalArgumentException("Capabilities not found by ThrowException manager: $id")
|
||||
}
|
||||
}
|
||||
|
||||
object Dynamic : FlexibleTypeCapabilitiesDeserializer {
|
||||
override fun capabilitiesById(id: String): FlexibleTypeCapabilities? {
|
||||
return if (id == DynamicTypeCapabilities.id) DynamicTypeCapabilities else null
|
||||
object Dynamic : FlexibleTypeFactoryDeserializer {
|
||||
override fun capabilitiesById(id: String): FlexibleTypeFactory? {
|
||||
return if (id == DynamicTypeFactory.id) DynamicTypeFactory else null
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun capabilitiesById(id: String): FlexibleTypeCapabilities?
|
||||
fun capabilitiesById(id: String): FlexibleTypeFactory?
|
||||
}
|
||||
+6
-8
@@ -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.
|
||||
@@ -56,14 +56,12 @@ class TypeDeserializer(
|
||||
fun type(proto: ProtoBuf.Type, additionalAnnotations: Annotations = Annotations.EMPTY): KotlinType {
|
||||
if (proto.hasFlexibleTypeCapabilitiesId()) {
|
||||
val id = c.nameResolver.getString(proto.flexibleTypeCapabilitiesId)
|
||||
val capabilities = c.components.flexibleTypeCapabilitiesDeserializer.capabilitiesById(id) ?:
|
||||
return ErrorUtils.createErrorType("${DeserializedType(c, proto)}: Capabilities not found for id $id")
|
||||
val capabilities = c.components.flexibleTypeFactoryDeserializer.capabilitiesById(id) ?:
|
||||
return ErrorUtils.createErrorType("${DeserializedType(c, proto)}: Capabilities not found for id $id")
|
||||
|
||||
return DelegatingFlexibleType.create(
|
||||
DeserializedType(c, proto),
|
||||
DeserializedType(c, proto.flexibleUpperBound(c.typeTable)!!),
|
||||
capabilities
|
||||
)
|
||||
return capabilities
|
||||
.create(DeserializedType(c, proto),
|
||||
DeserializedType(c, proto.flexibleUpperBound(c.typeTable)!!))
|
||||
}
|
||||
|
||||
return DeserializedType(c, proto, additionalAnnotations)
|
||||
|
||||
+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.
|
||||
@@ -34,7 +34,7 @@ class DeserializationComponents(
|
||||
val localClassResolver: LocalClassResolver,
|
||||
val errorReporter: ErrorReporter,
|
||||
val lookupTracker: LookupTracker,
|
||||
val flexibleTypeCapabilitiesDeserializer: FlexibleTypeCapabilitiesDeserializer,
|
||||
val flexibleTypeFactoryDeserializer: FlexibleTypeFactoryDeserializer,
|
||||
val fictitiousClassDescriptorFactory: ClassDescriptorFactory,
|
||||
val notFoundClasses: NotFoundClasses,
|
||||
val typeCapabilitiesLoader: TypeCapabilitiesLoader = TypeCapabilitiesLoader.NONE,
|
||||
|
||||
+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.
|
||||
@@ -48,7 +48,7 @@ class KotlinBuiltInDeserializerForDecompiler(
|
||||
storageManager, moduleDescriptor, BuiltInsClassDataFinder(proto, nameResolver),
|
||||
AnnotationAndConstantLoaderImpl(moduleDescriptor, notFoundClasses, BuiltInSerializerProtocol), packageFragmentProvider,
|
||||
ResolveEverythingToKotlinAnyLocalClassResolver(targetPlatform.builtIns), LoggingErrorReporter(LOG),
|
||||
LookupTracker.DO_NOTHING, FlexibleTypeCapabilitiesDeserializer.ThrowException, ClassDescriptorFactory.EMPTY,
|
||||
LookupTracker.DO_NOTHING, FlexibleTypeFactoryDeserializer.ThrowException, ClassDescriptorFactory.EMPTY,
|
||||
notFoundClasses
|
||||
)
|
||||
}
|
||||
|
||||
+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.
|
||||
@@ -64,7 +64,7 @@ class DeserializerForClassfileDecompiler(
|
||||
deserializationComponents = DeserializationComponents(
|
||||
storageManager, moduleDescriptor, classDataFinder, annotationAndConstantLoader, packageFragmentProvider,
|
||||
ResolveEverythingToKotlinAnyLocalClassResolver(targetPlatform.builtIns), LoggingErrorReporter(LOG),
|
||||
LookupTracker.DO_NOTHING, JavaFlexibleTypeCapabilitiesDeserializer, ClassDescriptorFactory.EMPTY, notFoundClasses
|
||||
LookupTracker.DO_NOTHING, JavaFlexibleTypeFactoryDeserializer, ClassDescriptorFactory.EMPTY, notFoundClasses
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+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.
|
||||
@@ -61,7 +61,7 @@ class KotlinJavaScriptDeserializerForDecompiler(
|
||||
deserializationComponents = DeserializationComponents(
|
||||
storageManager, moduleDescriptor, classDataFinder, annotationAndConstantLoader, packageFragmentProvider,
|
||||
ResolveEverythingToKotlinAnyLocalClassResolver(targetPlatform.builtIns), LoggingErrorReporter(LOG),
|
||||
LookupTracker.DO_NOTHING, FlexibleTypeCapabilitiesDeserializer.Dynamic, ClassDescriptorFactory.EMPTY,
|
||||
LookupTracker.DO_NOTHING, FlexibleTypeFactoryDeserializer.Dynamic, ClassDescriptorFactory.EMPTY,
|
||||
notFoundClasses
|
||||
)
|
||||
}
|
||||
|
||||
+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.
|
||||
@@ -37,7 +37,7 @@ import org.jetbrains.kotlin.serialization.ProtoBuf.Type
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf.Type.Argument.Projection
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf.TypeParameter.Variance
|
||||
import org.jetbrains.kotlin.serialization.deserialization.*
|
||||
import org.jetbrains.kotlin.types.DynamicTypeCapabilities
|
||||
import org.jetbrains.kotlin.types.DynamicTypeFactory
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.singletonOrEmptyList
|
||||
import java.util.*
|
||||
|
||||
@@ -71,7 +71,7 @@ class TypeClsStubBuilder(private val c: ClsStubBuilderContext) {
|
||||
if (type.hasFlexibleTypeCapabilitiesId()) {
|
||||
val id = c.nameResolver.getString(type.flexibleTypeCapabilitiesId)
|
||||
|
||||
if (id == DynamicTypeCapabilities.id) {
|
||||
if (id == DynamicTypeFactory.id) {
|
||||
KotlinPlaceHolderStubImpl<KtDynamicType>(parent, KtStubElementTypes.DYNAMIC_TYPE)
|
||||
return
|
||||
}
|
||||
|
||||
+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.
|
||||
@@ -48,7 +48,7 @@ fun createKotlinJavascriptPackageFragmentProvider(
|
||||
localClassResolver,
|
||||
ErrorReporter.DO_NOTHING,
|
||||
LookupTracker.DO_NOTHING,
|
||||
FlexibleTypeCapabilitiesDeserializer.Dynamic,
|
||||
FlexibleTypeFactoryDeserializer.Dynamic,
|
||||
ClassDescriptorFactory.EMPTY,
|
||||
notFoundClasses
|
||||
)
|
||||
|
||||
+6
-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.
|
||||
@@ -29,7 +29,10 @@ import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
|
||||
import org.jetbrains.kotlin.resolve.source.PsiSourceElement
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.FlexibleTypeFactory
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.KotlinTypeImpl
|
||||
import org.jetbrains.kotlin.types.StarProjectionImpl
|
||||
import org.jetbrains.kotlin.types.typeUtil.makeNullable
|
||||
|
||||
private class XmlSourceElement(override val psi: PsiElement) : PsiSourceElement
|
||||
@@ -106,7 +109,7 @@ private fun genProperty(
|
||||
override val resourceId = id
|
||||
}
|
||||
|
||||
val flexibleType = DelegatingFlexibleType.create(type, type.makeNullable(), FlexibleTypeCapabilities.NONE)
|
||||
val flexibleType = FlexibleTypeFactory.DEFAULT.create(type, type.makeNullable())
|
||||
property.setType(
|
||||
flexibleType,
|
||||
emptyList<TypeParameterDescriptor>(),
|
||||
|
||||
Reference in New Issue
Block a user