WrappedType: introduce WrappedTypeFactory to encapsulate wrapped types creation
This commit is contained in:
@@ -85,6 +85,7 @@ public class DescriptorResolver {
|
||||
private final FunctionsTypingVisitor functionsTypingVisitor;
|
||||
private final DestructuringDeclarationResolver destructuringDeclarationResolver;
|
||||
private final ModifiersChecker modifiersChecker;
|
||||
private final WrappedTypeFactory wrappedTypeFactory;
|
||||
private final SyntheticResolveExtension syntheticResolveExtension;
|
||||
|
||||
public DescriptorResolver(
|
||||
@@ -100,6 +101,7 @@ public class DescriptorResolver {
|
||||
@NotNull FunctionsTypingVisitor functionsTypingVisitor,
|
||||
@NotNull DestructuringDeclarationResolver destructuringDeclarationResolver,
|
||||
@NotNull ModifiersChecker modifiersChecker,
|
||||
@NotNull WrappedTypeFactory wrappedTypeFactory,
|
||||
@NotNull Project project
|
||||
) {
|
||||
this.annotationResolver = annotationResolver;
|
||||
@@ -114,6 +116,7 @@ public class DescriptorResolver {
|
||||
this.functionsTypingVisitor = functionsTypingVisitor;
|
||||
this.destructuringDeclarationResolver = destructuringDeclarationResolver;
|
||||
this.modifiersChecker = modifiersChecker;
|
||||
this.wrappedTypeFactory = wrappedTypeFactory;
|
||||
this.syntheticResolveExtension = SyntheticResolveExtension.Companion.getInstance(project);
|
||||
}
|
||||
|
||||
@@ -928,7 +931,7 @@ public class DescriptorResolver {
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
@NotNull
|
||||
/*package*/ static KotlinType transformAnonymousTypeIfNeeded(
|
||||
@NotNull DeclarationDescriptorWithVisibility descriptor,
|
||||
@NotNull KtDeclaration declaration,
|
||||
@@ -1104,14 +1107,14 @@ public class DescriptorResolver {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
/*package*/ DeferredType inferReturnTypeFromExpressionBody(
|
||||
/*package*/ KotlinType inferReturnTypeFromExpressionBody(
|
||||
@NotNull final BindingTrace trace,
|
||||
@NotNull final LexicalScope scope,
|
||||
@NotNull final DataFlowInfo dataFlowInfo,
|
||||
@NotNull final KtDeclarationWithBody function,
|
||||
@NotNull final FunctionDescriptor functionDescriptor
|
||||
) {
|
||||
return DeferredType.createRecursionIntolerant(storageManager, trace, new Function0<KotlinType>() {
|
||||
return wrappedTypeFactory.createRecursionIntolerantDeferredType(trace, new Function0<KotlinType>() {
|
||||
@Override
|
||||
public KotlinType invoke() {
|
||||
PreliminaryDeclarationVisitor.Companion.createForDeclaration(function, trace);
|
||||
|
||||
@@ -51,7 +51,6 @@ import org.jetbrains.kotlin.resolve.scopes.utils.findFirstFromMeAndParent
|
||||
import org.jetbrains.kotlin.resolve.source.KotlinSourceElement
|
||||
import org.jetbrains.kotlin.resolve.source.toSourceElement
|
||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.Variance.*
|
||||
import org.jetbrains.kotlin.types.typeUtil.containsTypeAliasParameters
|
||||
@@ -63,11 +62,11 @@ class TypeResolver(
|
||||
private val qualifiedExpressionResolver: QualifiedExpressionResolver,
|
||||
private val moduleDescriptor: ModuleDescriptor,
|
||||
private val typeTransformerForTests: TypeTransformerForTests,
|
||||
private val storageManager: StorageManager,
|
||||
private val lazinessToken: TypeLazinessToken,
|
||||
private val dynamicTypesSettings: DynamicTypesSettings,
|
||||
private val dynamicCallableDescriptors: DynamicCallableDescriptors,
|
||||
private val identifierChecker: IdentifierChecker,
|
||||
private val wrappedTypeFactory: WrappedTypeFactory,
|
||||
private val platformToKotlinClassMap: PlatformToKotlinClassMap,
|
||||
private val languageVersionSettings: LanguageVersionSettings
|
||||
) {
|
||||
@@ -119,7 +118,7 @@ class TypeResolver(
|
||||
if (!c.allowBareTypes && !c.forceResolveLazyTypes && lazinessToken.isLazy()) {
|
||||
// Bare types can be allowed only inside expressions; lazy type resolution is only relevant for declarations
|
||||
|
||||
val lazyKotlinType = LazyWrappedType(storageManager) {
|
||||
val lazyKotlinType = wrappedTypeFactory.createLazyWrappedType {
|
||||
doResolvePossiblyBareType(c, typeReference).actualType
|
||||
}
|
||||
c.trace.record(resolvedTypeSlice, typeReference, lazyKotlinType)
|
||||
|
||||
+5
-8
@@ -28,10 +28,7 @@ import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
|
||||
import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluator
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
import org.jetbrains.kotlin.types.DeferredType
|
||||
import org.jetbrains.kotlin.types.ErrorUtils
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices
|
||||
import org.jetbrains.kotlin.types.expressions.PreliminaryDeclarationVisitor
|
||||
|
||||
@@ -40,7 +37,8 @@ class VariableTypeAndInitializerResolver(
|
||||
private val expressionTypingServices: ExpressionTypingServices,
|
||||
private val typeResolver: TypeResolver,
|
||||
private val constantExpressionEvaluator: ConstantExpressionEvaluator,
|
||||
private val delegatedPropertyResolver: DelegatedPropertyResolver
|
||||
private val delegatedPropertyResolver: DelegatedPropertyResolver,
|
||||
private val wrappedTypeFactory: WrappedTypeFactory
|
||||
) {
|
||||
companion object {
|
||||
@JvmField
|
||||
@@ -82,8 +80,7 @@ class VariableTypeAndInitializerResolver(
|
||||
|
||||
variable.hasInitializer() -> when {
|
||||
!local ->
|
||||
DeferredType.createRecursionIntolerant(
|
||||
storageManager,
|
||||
wrappedTypeFactory.createRecursionIntolerantDeferredType(
|
||||
trace
|
||||
) {
|
||||
PreliminaryDeclarationVisitor.createForDeclaration(variable, trace)
|
||||
@@ -133,7 +130,7 @@ class VariableTypeAndInitializerResolver(
|
||||
scopeForInitializer: LexicalScope,
|
||||
dataFlowInfo: DataFlowInfo,
|
||||
trace: BindingTrace
|
||||
) = DeferredType.createRecursionIntolerant(storageManager, trace) {
|
||||
) = wrappedTypeFactory.createRecursionIntolerantDeferredType(trace) {
|
||||
val delegateExpression = property.delegateExpression!!
|
||||
val type = delegatedPropertyResolver.resolveDelegateExpression(
|
||||
delegateExpression, property, variableDescriptor, scopeForInitializer, trace, dataFlowInfo)
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.resolve.*
|
||||
import org.jetbrains.kotlin.resolve.extensions.SyntheticResolveExtension
|
||||
import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactory
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
import org.jetbrains.kotlin.types.WrappedTypeFactory
|
||||
|
||||
interface LazyClassContext {
|
||||
val declarationScopeProvider: DeclarationScopeProvider
|
||||
@@ -41,4 +42,5 @@ interface LazyClassContext {
|
||||
val languageVersionSettings: LanguageVersionSettings
|
||||
val syntheticResolveExtension: SyntheticResolveExtension
|
||||
val delegationFilter: DelegationFilter
|
||||
val wrappedTypeFactory: WrappedTypeFactory
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyPackageDescriptor;
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope;
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope;
|
||||
import org.jetbrains.kotlin.storage.*;
|
||||
import org.jetbrains.kotlin.types.WrappedTypeFactory;
|
||||
import org.jetbrains.kotlin.utils.SmartList;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@@ -82,6 +83,7 @@ public class ResolveSession implements KotlinCodeAnalyzer, LazyClassContext {
|
||||
private SupertypeLoopChecker supertypeLoopsResolver;
|
||||
private LanguageVersionSettings languageVersionSettings;
|
||||
private DelegationFilter delegationFilter;
|
||||
private WrappedTypeFactory wrappedTypeFactory;
|
||||
|
||||
private final SyntheticResolveExtension syntheticResolveExtension;
|
||||
|
||||
@@ -141,6 +143,11 @@ public class ResolveSession implements KotlinCodeAnalyzer, LazyClassContext {
|
||||
this.delegationFilter = delegationFilter;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setWrappedTypeFactory(WrappedTypeFactory wrappedTypeFactory) {
|
||||
this.wrappedTypeFactory = wrappedTypeFactory;
|
||||
}
|
||||
|
||||
// Only calls from injectors expected
|
||||
@Deprecated
|
||||
public ResolveSession(
|
||||
@@ -463,4 +470,10 @@ public class ResolveSession implements KotlinCodeAnalyzer, LazyClassContext {
|
||||
public SyntheticResolveExtension getSyntheticResolveExtension() {
|
||||
return syntheticResolveExtension;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public WrappedTypeFactory getWrappedTypeFactory() {
|
||||
return wrappedTypeFactory;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -368,7 +368,7 @@ open class LazyClassMemberScope(
|
||||
}
|
||||
|
||||
protected fun setDeferredReturnType(descriptor: ClassConstructorDescriptorImpl) {
|
||||
descriptor.returnType = DeferredType.create(c.storageManager, trace, { thisDescriptor.defaultType })
|
||||
descriptor.returnType = c.wrappedTypeFactory.createDeferredType(trace, { thisDescriptor.defaultType })
|
||||
}
|
||||
|
||||
override fun recordLookup(name: Name, from: LookupLocation) {
|
||||
|
||||
@@ -45,7 +45,7 @@ public class DeferredType extends WrappedType {
|
||||
};
|
||||
|
||||
@NotNull
|
||||
public static DeferredType create(
|
||||
/*package private*/ static DeferredType create(
|
||||
@NotNull StorageManager storageManager,
|
||||
@NotNull BindingTrace trace,
|
||||
@NotNull Function0<KotlinType> compute
|
||||
@@ -56,7 +56,7 @@ public class DeferredType extends WrappedType {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static DeferredType createRecursionIntolerant(
|
||||
/*package private*/ static DeferredType createRecursionIntolerant(
|
||||
@NotNull StorageManager storageManager,
|
||||
@NotNull BindingTrace trace,
|
||||
@NotNull Function0<KotlinType> compute
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2010-2017 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.types
|
||||
|
||||
import org.jetbrains.kotlin.resolve.BindingTrace
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
|
||||
open class WrappedTypeFactory(private val storageManager: StorageManager) {
|
||||
open fun createLazyWrappedType(computation: () -> KotlinType): KotlinType = LazyWrappedType(storageManager, computation)
|
||||
open fun createDeferredType(trace: BindingTrace, computation: () -> KotlinType): KotlinType = DeferredType.create(storageManager, trace, computation)
|
||||
open fun createRecursionIntolerantDeferredType(trace: BindingTrace, computation: () -> KotlinType): KotlinType = DeferredType.createRecursionIntolerant(storageManager, trace, computation)
|
||||
}
|
||||
+8
-8
@@ -731,14 +731,14 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
final ClassDescriptor descriptor
|
||||
) {
|
||||
if (slice == CLASS && declaration == expression.getObjectDeclaration()) {
|
||||
KotlinType defaultType = DeferredType.createRecursionIntolerant(components.globalContext.getStorageManager(),
|
||||
context.trace,
|
||||
new Function0<KotlinType>() {
|
||||
@Override
|
||||
public KotlinType invoke() {
|
||||
return descriptor.getDefaultType();
|
||||
}
|
||||
});
|
||||
KotlinType defaultType = components.wrappedTypeFactory.createRecursionIntolerantDeferredType(
|
||||
context.trace,
|
||||
new Function0<KotlinType>() {
|
||||
@Override
|
||||
public KotlinType invoke() {
|
||||
return descriptor.getDefaultType();
|
||||
}
|
||||
});
|
||||
result[0] = defaultType;
|
||||
}
|
||||
}
|
||||
|
||||
+7
@@ -28,6 +28,7 @@ import org.jetbrains.kotlin.resolve.calls.CallResolver;
|
||||
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker;
|
||||
import org.jetbrains.kotlin.resolve.calls.checkers.RttiExpressionChecker;
|
||||
import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluator;
|
||||
import org.jetbrains.kotlin.types.WrappedTypeFactory;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
@@ -60,6 +61,7 @@ public class ExpressionTypingComponents {
|
||||
/*package*/ OverloadChecker overloadChecker;
|
||||
/*package*/ LanguageVersionSettings languageVersionSettings;
|
||||
/*package*/ Iterable<RttiExpressionChecker> rttiExpressionCheckers;
|
||||
/*package*/ WrappedTypeFactory wrappedTypeFactory;
|
||||
|
||||
@Inject
|
||||
public void setGlobalContext(@NotNull GlobalContext globalContext) {
|
||||
@@ -200,4 +202,9 @@ public class ExpressionTypingComponents {
|
||||
public void setRttiExpressionCheckers(@NotNull Iterable<RttiExpressionChecker> rttiExpressionCheckers) {
|
||||
this.rttiExpressionCheckers = rttiExpressionCheckers;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setWrappedTypeFactory(WrappedTypeFactory wrappedTypeFactory) {
|
||||
this.wrappedTypeFactory = wrappedTypeFactory;
|
||||
}
|
||||
}
|
||||
|
||||
+8
-3
@@ -52,6 +52,7 @@ import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyClassDescriptor
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalWritableScope
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
import org.jetbrains.kotlin.types.WrappedTypeFactory
|
||||
|
||||
class LocalClassifierAnalyzer(
|
||||
private val globalContext: GlobalContext,
|
||||
@@ -65,7 +66,8 @@ class LocalClassifierAnalyzer(
|
||||
private val supertypeLoopChecker: SupertypeLoopChecker,
|
||||
private val targetPlatformVersion: TargetPlatformVersion,
|
||||
private val languageVersionSettings: LanguageVersionSettings,
|
||||
private val delegationFilter: DelegationFilter
|
||||
private val delegationFilter: DelegationFilter,
|
||||
private val wrappedTypeFactory: WrappedTypeFactory
|
||||
) {
|
||||
fun processClassOrObject(
|
||||
scope: LexicalWritableScope?,
|
||||
@@ -98,7 +100,8 @@ class LocalClassifierAnalyzer(
|
||||
supertypeLoopChecker,
|
||||
languageVersionSettings,
|
||||
SyntheticResolveExtension.getInstance(project),
|
||||
delegationFilter
|
||||
delegationFilter,
|
||||
wrappedTypeFactory
|
||||
)
|
||||
)
|
||||
|
||||
@@ -124,7 +127,8 @@ class LocalClassDescriptorHolder(
|
||||
val supertypeLoopChecker: SupertypeLoopChecker,
|
||||
val languageVersionSettings: LanguageVersionSettings,
|
||||
val syntheticResolveExtension: SyntheticResolveExtension,
|
||||
val delegationFilter: DelegationFilter
|
||||
val delegationFilter: DelegationFilter,
|
||||
val wrappedTypeFactory: WrappedTypeFactory
|
||||
) {
|
||||
// We do not need to synchronize here, because this code is used strictly from one thread
|
||||
private var classDescriptor: ClassDescriptor? = null
|
||||
@@ -163,6 +167,7 @@ class LocalClassDescriptorHolder(
|
||||
override val languageVersionSettings = this@LocalClassDescriptorHolder.languageVersionSettings
|
||||
override val syntheticResolveExtension = this@LocalClassDescriptorHolder.syntheticResolveExtension
|
||||
override val delegationFilter: DelegationFilter = this@LocalClassDescriptorHolder.delegationFilter
|
||||
override val wrappedTypeFactory: WrappedTypeFactory = this@LocalClassDescriptorHolder.wrappedTypeFactory
|
||||
},
|
||||
containingDeclaration,
|
||||
classOrObject.nameAsSafeName,
|
||||
|
||||
Reference in New Issue
Block a user