Refactoring. Remove FlexibleTypeFactory.DEFAULT and refactor flexible type creation by special fq-name for tests.
This commit is contained in:
@@ -24,8 +24,8 @@ import org.jetbrains.kotlin.context.ModuleContext
|
|||||||
import org.jetbrains.kotlin.descriptors.PackagePartProvider
|
import org.jetbrains.kotlin.descriptors.PackagePartProvider
|
||||||
import org.jetbrains.kotlin.frontend.di.configureModule
|
import org.jetbrains.kotlin.frontend.di.configureModule
|
||||||
import org.jetbrains.kotlin.incremental.components.LookupTracker
|
import org.jetbrains.kotlin.incremental.components.LookupTracker
|
||||||
|
import org.jetbrains.kotlin.load.java.InternalFlexibleTypeTransformer
|
||||||
import org.jetbrains.kotlin.load.java.JavaClassFinderImpl
|
import org.jetbrains.kotlin.load.java.JavaClassFinderImpl
|
||||||
import org.jetbrains.kotlin.load.java.JavaFlexibleTypeFactoryProvider
|
|
||||||
import org.jetbrains.kotlin.load.java.components.*
|
import org.jetbrains.kotlin.load.java.components.*
|
||||||
import org.jetbrains.kotlin.load.java.lazy.ModuleClassResolver
|
import org.jetbrains.kotlin.load.java.lazy.ModuleClassResolver
|
||||||
import org.jetbrains.kotlin.load.java.lazy.SingleModuleClassResolver
|
import org.jetbrains.kotlin.load.java.lazy.SingleModuleClassResolver
|
||||||
@@ -62,7 +62,7 @@ fun StorageComponentContainer.configureJavaTopDownAnalysis(moduleContentScope: G
|
|||||||
useInstance(SamConversionResolverImpl)
|
useInstance(SamConversionResolverImpl)
|
||||||
useImpl<JavaSourceElementFactoryImpl>()
|
useImpl<JavaSourceElementFactoryImpl>()
|
||||||
useImpl<JavaLazyAnalyzerPostConstruct>()
|
useImpl<JavaLazyAnalyzerPostConstruct>()
|
||||||
useInstance(JavaFlexibleTypeFactoryProvider)
|
useInstance(InternalFlexibleTypeTransformer)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createContainerForLazyResolveWithJava(
|
fun createContainerForLazyResolveWithJava(
|
||||||
|
|||||||
+42
@@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.load.java
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.load.java.lazy.types.LazyJavaTypeResolver.FlexibleJavaClassifierTypeFactory
|
||||||
|
import org.jetbrains.kotlin.name.ClassId
|
||||||
|
import org.jetbrains.kotlin.name.FqName
|
||||||
|
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||||
|
import org.jetbrains.kotlin.resolve.TypeResolver.TypeTransformerForTests
|
||||||
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
|
|
||||||
|
object InternalFlexibleTypeTransformer : TypeTransformerForTests() {
|
||||||
|
// This is a "magic" classifier: when type resolver sees it in the code, e.g. ft<Foo, Foo?>, instead of creating a normal type,
|
||||||
|
// it creates a flexible type, e.g. (Foo..Foo?).
|
||||||
|
// This is used in tests and Evaluate Expression to have flexible types in the code,
|
||||||
|
// but normal users should not be referencing this classifier
|
||||||
|
@JvmField
|
||||||
|
val FLEXIBLE_TYPE_CLASSIFIER: ClassId = ClassId.topLevel(FqName("kotlin.internal.flexible.ft"))
|
||||||
|
|
||||||
|
override fun transformType(kotlinType: KotlinType): KotlinType? {
|
||||||
|
val descriptor = kotlinType.constructor.declarationDescriptor
|
||||||
|
if (descriptor != null && FLEXIBLE_TYPE_CLASSIFIER.asSingleFqName().toUnsafe() == DescriptorUtils.getFqName(descriptor)
|
||||||
|
&& kotlinType.arguments.size == 2) {
|
||||||
|
return FlexibleJavaClassifierTypeFactory.create(kotlinType.arguments[0].type, kotlinType.arguments[1].type)
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
-25
@@ -1,25 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jetbrains.kotlin.load.java
|
|
||||||
|
|
||||||
import org.jetbrains.kotlin.load.java.lazy.types.LazyJavaTypeResolver
|
|
||||||
import org.jetbrains.kotlin.resolve.TypeResolver.FlexibleTypeFactoryProvider
|
|
||||||
import org.jetbrains.kotlin.types.FlexibleTypeFactory
|
|
||||||
|
|
||||||
object JavaFlexibleTypeFactoryProvider : FlexibleTypeFactoryProvider() {
|
|
||||||
override val factory: FlexibleTypeFactory get() = LazyJavaTypeResolver.FlexibleJavaClassifierTypeFactory
|
|
||||||
}
|
|
||||||
@@ -50,7 +50,7 @@ class TypeResolver(
|
|||||||
private val annotationResolver: AnnotationResolver,
|
private val annotationResolver: AnnotationResolver,
|
||||||
private val qualifiedExpressionResolver: QualifiedExpressionResolver,
|
private val qualifiedExpressionResolver: QualifiedExpressionResolver,
|
||||||
private val moduleDescriptor: ModuleDescriptor,
|
private val moduleDescriptor: ModuleDescriptor,
|
||||||
private val flexibleTypeFactoryProvider: FlexibleTypeFactoryProvider,
|
private val typeTransformerForTests: TypeTransformerForTests,
|
||||||
private val storageManager: StorageManager,
|
private val storageManager: StorageManager,
|
||||||
private val lazinessToken: TypeLazinessToken,
|
private val lazinessToken: TypeLazinessToken,
|
||||||
private val dynamicTypesSettings: DynamicTypesSettings,
|
private val dynamicTypesSettings: DynamicTypesSettings,
|
||||||
@@ -58,8 +58,8 @@ class TypeResolver(
|
|||||||
private val identifierChecker: IdentifierChecker
|
private val identifierChecker: IdentifierChecker
|
||||||
) {
|
) {
|
||||||
|
|
||||||
open class FlexibleTypeFactoryProvider {
|
open class TypeTransformerForTests {
|
||||||
open val factory: FlexibleTypeFactory get() = FlexibleTypeFactory.DEFAULT
|
open fun transformType(kotlinType: KotlinType): KotlinType? = null
|
||||||
}
|
}
|
||||||
|
|
||||||
fun resolveType(scope: LexicalScope, typeReference: KtTypeReference, trace: BindingTrace, checkBounds: Boolean): KotlinType {
|
fun resolveType(scope: LexicalScope, typeReference: KtTypeReference, trace: BindingTrace, checkBounds: Boolean): KotlinType {
|
||||||
@@ -367,16 +367,12 @@ class TypeResolver(
|
|||||||
" but ${collectedArgumentAsTypeProjections.size} instead of ${parameters.size} found in ${type.text}"
|
" but ${collectedArgumentAsTypeProjections.size} instead of ${parameters.size} found in ${type.text}"
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Flexibility.FLEXIBLE_TYPE_CLASSIFIER.asSingleFqName().toUnsafe() == DescriptorUtils.getFqName(classDescriptor)
|
|
||||||
&& 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(flexibleTypeFactoryProvider.factory.create(arguments[0].type,
|
|
||||||
arguments[1].type)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
val resultingType = KotlinTypeImpl.create(annotations, classDescriptor, false, arguments)
|
val resultingType = KotlinTypeImpl.create(annotations, classDescriptor, false, arguments)
|
||||||
|
|
||||||
|
// We create flexible types by convention here
|
||||||
|
// This is not intended to be used in normal users' environments, only for tests and debugger etc
|
||||||
|
typeTransformerForTests.transformType(resultingType)?.let { return type(it) }
|
||||||
|
|
||||||
if (c.checkBounds) {
|
if (c.checkBounds) {
|
||||||
val substitutor = TypeSubstitutor.create(resultingType)
|
val substitutor = TypeSubstitutor.create(resultingType)
|
||||||
for (i in parameters.indices) {
|
for (i in parameters.indices) {
|
||||||
|
|||||||
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -35,12 +35,12 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
import org.jetbrains.kotlin.asJava.DuplicateJvmSignatureUtilKt;
|
import org.jetbrains.kotlin.asJava.DuplicateJvmSignatureUtilKt;
|
||||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
||||||
import org.jetbrains.kotlin.diagnostics.*;
|
import org.jetbrains.kotlin.diagnostics.*;
|
||||||
|
import org.jetbrains.kotlin.load.java.InternalFlexibleTypeTransformer;
|
||||||
import org.jetbrains.kotlin.psi.KtDeclaration;
|
import org.jetbrains.kotlin.psi.KtDeclaration;
|
||||||
import org.jetbrains.kotlin.psi.KtFile;
|
import org.jetbrains.kotlin.psi.KtFile;
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||||
import org.jetbrains.kotlin.resolve.diagnostics.Diagnostics;
|
import org.jetbrains.kotlin.resolve.diagnostics.Diagnostics;
|
||||||
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||||
import org.jetbrains.kotlin.types.Flexibility;
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -73,8 +73,8 @@ public abstract class BaseDiagnosticsTest
|
|||||||
public static final String CHECK_TYPE_IMPORT = "import " + CHECK_TYPE_PACKAGE + ".*";
|
public static final String CHECK_TYPE_IMPORT = "import " + CHECK_TYPE_PACKAGE + ".*";
|
||||||
|
|
||||||
public static final String EXPLICIT_FLEXIBLE_TYPES_DIRECTIVE = "EXPLICIT_FLEXIBLE_TYPES";
|
public static final String EXPLICIT_FLEXIBLE_TYPES_DIRECTIVE = "EXPLICIT_FLEXIBLE_TYPES";
|
||||||
public static final String EXPLICIT_FLEXIBLE_PACKAGE = Flexibility.Companion.getFLEXIBLE_TYPE_CLASSIFIER().getPackageFqName().asString();
|
public static final String EXPLICIT_FLEXIBLE_PACKAGE = InternalFlexibleTypeTransformer.FLEXIBLE_TYPE_CLASSIFIER.getPackageFqName().asString();
|
||||||
public static final String EXPLICIT_FLEXIBLE_CLASS_NAME = Flexibility.Companion.getFLEXIBLE_TYPE_CLASSIFIER().getRelativeClassName().asString();
|
public static final String EXPLICIT_FLEXIBLE_CLASS_NAME = InternalFlexibleTypeTransformer.FLEXIBLE_TYPE_CLASSIFIER.getRelativeClassName().asString();
|
||||||
private static final String EXPLICIT_FLEXIBLE_TYPES_DECLARATIONS
|
private static final String EXPLICIT_FLEXIBLE_TYPES_DECLARATIONS
|
||||||
= "\npackage " + EXPLICIT_FLEXIBLE_PACKAGE +
|
= "\npackage " + EXPLICIT_FLEXIBLE_PACKAGE +
|
||||||
"\npublic class " + EXPLICIT_FLEXIBLE_CLASS_NAME + "<L, U>";
|
"\npublic class " + EXPLICIT_FLEXIBLE_CLASS_NAME + "<L, U>";
|
||||||
|
|||||||
@@ -16,34 +16,15 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.types
|
package org.jetbrains.kotlin.types
|
||||||
|
|
||||||
import org.jetbrains.kotlin.name.ClassId
|
|
||||||
import org.jetbrains.kotlin.name.FqName
|
|
||||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||||
|
|
||||||
interface FlexibleTypeFactory {
|
interface FlexibleTypeFactory {
|
||||||
val id: String
|
val id: String
|
||||||
|
|
||||||
fun create(lowerBound: KotlinType, upperBound: KotlinType): KotlinType
|
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) {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Flexibility : TypeCapability, SubtypingRepresentatives {
|
interface Flexibility : TypeCapability, SubtypingRepresentatives {
|
||||||
companion object {
|
|
||||||
// This is a "magic" classifier: when type resolver sees it in the code, e.g. ft<Foo, Foo?>, instead of creating a normal type,
|
|
||||||
// it creates a flexible type, e.g. (Foo..Foo?).
|
|
||||||
// This is used in tests and Evaluate Expression to have flexible types in the code,
|
|
||||||
// but normal users should not be referencing this classifier
|
|
||||||
val FLEXIBLE_TYPE_CLASSIFIER: ClassId = ClassId.topLevel(FqName("kotlin.internal.flexible.ft"))
|
|
||||||
}
|
|
||||||
|
|
||||||
// lowerBound is a subtype of upperBound
|
// lowerBound is a subtype of upperBound
|
||||||
val lowerBound: KotlinType
|
val lowerBound: KotlinType
|
||||||
val upperBound: KotlinType
|
val upperBound: KotlinType
|
||||||
|
|||||||
+2
-2
@@ -25,11 +25,11 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
|||||||
import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl
|
import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl
|
||||||
import org.jetbrains.kotlin.descriptors.impl.PropertyGetterDescriptorImpl
|
import org.jetbrains.kotlin.descriptors.impl.PropertyGetterDescriptorImpl
|
||||||
import org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl
|
import org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl
|
||||||
|
import org.jetbrains.kotlin.load.java.lazy.types.LazyJavaTypeResolver
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
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.FlexibleTypeFactory
|
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
import org.jetbrains.kotlin.types.KotlinTypeImpl
|
import org.jetbrains.kotlin.types.KotlinTypeImpl
|
||||||
import org.jetbrains.kotlin.types.StarProjectionImpl
|
import org.jetbrains.kotlin.types.StarProjectionImpl
|
||||||
@@ -109,7 +109,7 @@ private fun genProperty(
|
|||||||
override val resourceId = id
|
override val resourceId = id
|
||||||
}
|
}
|
||||||
|
|
||||||
val flexibleType = FlexibleTypeFactory.DEFAULT.create(type, type.makeNullable())
|
val flexibleType = LazyJavaTypeResolver.FlexibleJavaClassifierTypeFactory.create(type, type.makeNullable())
|
||||||
property.setType(
|
property.setType(
|
||||||
flexibleType,
|
flexibleType,
|
||||||
emptyList<TypeParameterDescriptor>(),
|
emptyList<TypeParameterDescriptor>(),
|
||||||
|
|||||||
Reference in New Issue
Block a user