Minor, move utilities form CallableReferencesResolutionUtils.kt closer to usages
This commit is contained in:
-61
@@ -16,17 +16,12 @@
|
||||
|
||||
package org.jetbrains.kotlin.resolve.callableReferences
|
||||
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.builtins.ReflectionTypes
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.descriptors.impl.AnonymousFunctionDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor
|
||||
import org.jetbrains.kotlin.diagnostics.Errors.CALLABLE_REFERENCE_LHS_NOT_A_CLASS
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.KtCallableReferenceExpression
|
||||
import org.jetbrains.kotlin.psi.KtSimpleNameExpression
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.calls.CallResolver
|
||||
import org.jetbrains.kotlin.resolve.calls.callResolverUtil.ResolveArgumentsMode
|
||||
@@ -35,10 +30,7 @@ import org.jetbrains.kotlin.resolve.calls.context.CheckArgumentTypesMode
|
||||
import org.jetbrains.kotlin.resolve.calls.context.ResolutionContext
|
||||
import org.jetbrains.kotlin.resolve.calls.context.TemporaryTraceAndCache
|
||||
import org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResults
|
||||
import org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResultsUtil
|
||||
import org.jetbrains.kotlin.resolve.calls.util.CallMaker
|
||||
import org.jetbrains.kotlin.resolve.createFunctionType
|
||||
import org.jetbrains.kotlin.resolve.createValueParametersForInvokeInFunctionType
|
||||
import org.jetbrains.kotlin.resolve.scopes.BaseLexicalScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScopeKind
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||
@@ -47,8 +39,6 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.TransientReceiver
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.memberScopeAsImportingScope
|
||||
import org.jetbrains.kotlin.resolve.source.toSourceElement
|
||||
import org.jetbrains.kotlin.types.FunctionPlaceholders
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
import org.jetbrains.kotlin.types.expressions.DoubleColonLHS
|
||||
@@ -161,32 +151,6 @@ fun resolvePossiblyAmbiguousCallableReference(
|
||||
return null
|
||||
}
|
||||
|
||||
internal fun bindFunctionReference(expression: KtCallableReferenceExpression, type: KotlinType, context: ResolutionContext<*>) {
|
||||
val functionDescriptor = AnonymousFunctionDescriptor(
|
||||
context.scope.ownerDescriptor,
|
||||
Annotations.EMPTY,
|
||||
CallableMemberDescriptor.Kind.DECLARATION,
|
||||
expression.toSourceElement(), /* isCoroutine = */ false
|
||||
)
|
||||
|
||||
functionDescriptor.initialize(
|
||||
null, null, emptyList(),
|
||||
createValueParametersForInvokeInFunctionType(functionDescriptor, type.arguments.dropLast(1)),
|
||||
type.arguments.last().type,
|
||||
Modality.FINAL,
|
||||
Visibilities.PUBLIC
|
||||
)
|
||||
|
||||
context.trace.record(BindingContext.FUNCTION, expression, functionDescriptor)
|
||||
}
|
||||
|
||||
internal fun bindPropertyReference(expression: KtCallableReferenceExpression, referenceType: KotlinType, context: ResolutionContext<*>) {
|
||||
val localVariable = LocalVariableDescriptor(context.scope.ownerDescriptor, Annotations.EMPTY, Name.special("<anonymous>"),
|
||||
referenceType, /* mutable = */ false, false, expression.toSourceElement())
|
||||
|
||||
context.trace.record(BindingContext.VARIABLE, expression, localVariable)
|
||||
}
|
||||
|
||||
fun createReflectionTypeForCallableDescriptor(
|
||||
descriptor: CallableDescriptor,
|
||||
lhsType: KotlinType?,
|
||||
@@ -225,28 +189,3 @@ fun createReflectionTypeForCallableDescriptor(
|
||||
else -> throw UnsupportedOperationException("Callable reference resolved to an unsupported descriptor: $descriptor")
|
||||
}
|
||||
}
|
||||
|
||||
fun getResolvedCallableReferenceShapeType(
|
||||
reference: KtCallableReferenceExpression,
|
||||
lhsType: KotlinType?,
|
||||
overloadResolutionResults: OverloadResolutionResults<*>?,
|
||||
context: ResolutionContext<*>,
|
||||
expectedTypeUnknown: Boolean,
|
||||
reflectionTypes: ReflectionTypes,
|
||||
builtIns: KotlinBuiltIns,
|
||||
functionPlaceholders: FunctionPlaceholders
|
||||
): KotlinType? =
|
||||
when {
|
||||
overloadResolutionResults == null ->
|
||||
null
|
||||
overloadResolutionResults.isSingleResult ->
|
||||
OverloadResolutionResultsUtil.getResultingCall(overloadResolutionResults, context.contextDependency)?.let { call ->
|
||||
createReflectionTypeForCallableDescriptor(
|
||||
call.resultingDescriptor, lhsType, reflectionTypes, reference.isEmptyLHS, context.scope.ownerDescriptor
|
||||
)
|
||||
}
|
||||
expectedTypeUnknown /* && overload resolution was ambiguous */ ->
|
||||
functionPlaceholders.createFunctionPlaceholderType(emptyList(), false)
|
||||
else ->
|
||||
createFunctionType(builtIns, Annotations.EMPTY, null, emptyList(), TypeUtils.DONT_CARE)
|
||||
}
|
||||
|
||||
@@ -36,7 +36,9 @@ import org.jetbrains.kotlin.resolve.calls.context.CheckArgumentTypesMode;
|
||||
import org.jetbrains.kotlin.resolve.calls.context.ResolutionContext;
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilderImplKt;
|
||||
import org.jetbrains.kotlin.resolve.calls.model.MutableDataFlowInfoForArguments;
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResults;
|
||||
import org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResultsUtil;
|
||||
import org.jetbrains.kotlin.resolve.constants.IntegerValueTypeConstructor;
|
||||
import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluator;
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope;
|
||||
@@ -250,11 +252,27 @@ public class ArgumentTypeResolver {
|
||||
SHAPE_FUNCTION_ARGUMENTS
|
||||
);
|
||||
DoubleColonLHS lhs = pair.getFirst();
|
||||
OverloadResolutionResults<?> overloadResolutionResults = pair.getSecond();
|
||||
|
||||
KotlinType receiverType = lhs != null ? lhs.getType() : null;
|
||||
return CallableReferencesResolutionUtilsKt.getResolvedCallableReferenceShapeType(
|
||||
callableReferenceExpression, receiverType, pair.getSecond(), context, expectedTypeIsUnknown,
|
||||
reflectionTypes, builtIns, functionPlaceholders
|
||||
if (overloadResolutionResults == null) return null;
|
||||
|
||||
if (overloadResolutionResults.isSingleResult()) {
|
||||
ResolvedCall<?> resolvedCall =
|
||||
OverloadResolutionResultsUtil.getResultingCall(overloadResolutionResults, context.contextDependency);
|
||||
if (resolvedCall == null) return null;
|
||||
|
||||
return CallableReferencesResolutionUtilsKt.createReflectionTypeForCallableDescriptor(
|
||||
resolvedCall.getResultingDescriptor(), lhs != null ? lhs.getType() : null, reflectionTypes,
|
||||
callableReferenceExpression.isEmptyLHS(), context.scope.getOwnerDescriptor()
|
||||
);
|
||||
}
|
||||
|
||||
if (expectedTypeIsUnknown) {
|
||||
return functionPlaceholders.createFunctionPlaceholderType(Collections.<KotlinType>emptyList(), false);
|
||||
}
|
||||
|
||||
return FunctionTypeResolveUtilsKt.createFunctionType(
|
||||
builtIns, Annotations.Companion.getEMPTY(), null, Collections.<KotlinType>emptyList(), TypeUtils.DONT_CARE
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+34
-2
@@ -22,23 +22,26 @@ import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.config.LanguageFeatureSettings
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.descriptors.impl.AnonymousFunctionDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor
|
||||
import org.jetbrains.kotlin.diagnostics.Errors.*
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.codeFragmentUtil.suppressDiagnosticsInDebugMode
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getQualifiedElementSelector
|
||||
import org.jetbrains.kotlin.resolve.*
|
||||
import org.jetbrains.kotlin.resolve.callableReferences.bindFunctionReference
|
||||
import org.jetbrains.kotlin.resolve.callableReferences.bindPropertyReference
|
||||
import org.jetbrains.kotlin.resolve.callableReferences.createReflectionTypeForCallableDescriptor
|
||||
import org.jetbrains.kotlin.resolve.callableReferences.resolvePossiblyAmbiguousCallableReference
|
||||
import org.jetbrains.kotlin.resolve.calls.CallResolver
|
||||
import org.jetbrains.kotlin.resolve.calls.callResolverUtil.ResolveArgumentsMode
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.calls.context.ResolutionContext
|
||||
import org.jetbrains.kotlin.resolve.calls.context.TemporaryTraceAndCache
|
||||
import org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResults
|
||||
import org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResultsUtil
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
|
||||
import org.jetbrains.kotlin.resolve.calls.util.FakeCallableDescriptorForObject
|
||||
import org.jetbrains.kotlin.resolve.source.toSourceElement
|
||||
import org.jetbrains.kotlin.types.ErrorUtils
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.KotlinTypeFactory
|
||||
@@ -320,6 +323,35 @@ class DoubleColonExpressionResolver(
|
||||
return original.extensionReceiverParameter != null && original.dispatchReceiverParameter != null
|
||||
}
|
||||
|
||||
private fun bindFunctionReference(expression: KtCallableReferenceExpression, type: KotlinType, context: ResolutionContext<*>) {
|
||||
val functionDescriptor = AnonymousFunctionDescriptor(
|
||||
context.scope.ownerDescriptor,
|
||||
Annotations.EMPTY,
|
||||
CallableMemberDescriptor.Kind.DECLARATION,
|
||||
expression.toSourceElement(),
|
||||
/* isCoroutine = */ false
|
||||
)
|
||||
|
||||
functionDescriptor.initialize(
|
||||
null, null, emptyList(),
|
||||
createValueParametersForInvokeInFunctionType(functionDescriptor, type.arguments.dropLast(1)),
|
||||
type.arguments.last().type,
|
||||
Modality.FINAL,
|
||||
Visibilities.PUBLIC
|
||||
)
|
||||
|
||||
context.trace.record(BindingContext.FUNCTION, expression, functionDescriptor)
|
||||
}
|
||||
|
||||
private fun bindPropertyReference(expression: KtCallableReferenceExpression, referenceType: KotlinType, context: ResolutionContext<*>) {
|
||||
val localVariable = LocalVariableDescriptor(
|
||||
context.scope.ownerDescriptor, Annotations.EMPTY, Name.special("<anonymous>"), referenceType, /* mutable = */ false,
|
||||
/* isDelegated = */ false, expression.toSourceElement()
|
||||
)
|
||||
|
||||
context.trace.record(BindingContext.VARIABLE, expression, localVariable)
|
||||
}
|
||||
|
||||
fun resolveCallableReference(
|
||||
expression: KtCallableReferenceExpression,
|
||||
context: ExpressionTypingContext,
|
||||
|
||||
Reference in New Issue
Block a user