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)
|
||||
|
||||
Reference in New Issue
Block a user