Collect sam adapters for constructors in synthetic scope
Also place computation of synthetic constructors under one function
This commit is contained in:
@@ -45,6 +45,7 @@ import org.jetbrains.kotlin.resolve.calls.util.CallMaker;
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt;
|
||||
import org.jetbrains.kotlin.resolve.lazy.ForceResolveUtil;
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope;
|
||||
import org.jetbrains.kotlin.resolve.scopes.SyntheticScopes;
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.kotlin.types.KotlinTypeKt;
|
||||
@@ -70,6 +71,7 @@ public class CallResolver {
|
||||
private GenericCandidateResolver genericCandidateResolver;
|
||||
private CallCompleter callCompleter;
|
||||
private NewResolutionOldInference newCallResolver;
|
||||
private SyntheticScopes syntheticScopes;
|
||||
private final KotlinBuiltIns builtIns;
|
||||
private final LanguageVersionSettings languageVersionSettings;
|
||||
|
||||
@@ -119,6 +121,11 @@ public class CallResolver {
|
||||
this.newCallResolver = newCallResolver;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setSyntheticScopes(@NotNull SyntheticScopes syntheticScopes) {
|
||||
this.syntheticScopes = syntheticScopes;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public OverloadResolutionResults<VariableDescriptor> resolveSimpleProperty(@NotNull BasicCallResolutionContext context) {
|
||||
KtExpression calleeExpression = context.call.getCalleeExpression();
|
||||
@@ -357,7 +364,7 @@ public class CallResolver {
|
||||
@NotNull KotlinType constructedType
|
||||
) {
|
||||
Pair<Collection<ResolutionCandidate<ConstructorDescriptor>>, BasicCallResolutionContext> candidatesAndContext =
|
||||
prepareCandidatesAndContextForConstructorCall(constructedType, context);
|
||||
prepareCandidatesAndContextForConstructorCall(constructedType, context, syntheticScopes);
|
||||
|
||||
Collection<ResolutionCandidate<ConstructorDescriptor>> candidates = candidatesAndContext.getFirst();
|
||||
context = candidatesAndContext.getSecond();
|
||||
@@ -437,7 +444,7 @@ public class CallResolver {
|
||||
DescriptorUtils.getSuperClassType(currentClassDescriptor);
|
||||
|
||||
Pair<Collection<ResolutionCandidate<ConstructorDescriptor>>, BasicCallResolutionContext> candidatesAndContext =
|
||||
prepareCandidatesAndContextForConstructorCall(superType, context);
|
||||
prepareCandidatesAndContextForConstructorCall(superType, context, syntheticScopes);
|
||||
Collection<ResolutionCandidate<ConstructorDescriptor>> candidates = candidatesAndContext.getFirst();
|
||||
context = candidatesAndContext.getSecond();
|
||||
|
||||
@@ -459,7 +466,8 @@ public class CallResolver {
|
||||
@NotNull
|
||||
private static Pair<Collection<ResolutionCandidate<ConstructorDescriptor>>, BasicCallResolutionContext> prepareCandidatesAndContextForConstructorCall(
|
||||
@NotNull KotlinType superType,
|
||||
@NotNull BasicCallResolutionContext context
|
||||
@NotNull BasicCallResolutionContext context,
|
||||
@NotNull SyntheticScopes syntheticScopes
|
||||
) {
|
||||
if (!(superType.getConstructor().getDeclarationDescriptor() instanceof ClassDescriptor)) {
|
||||
return new Pair<>(Collections.<ResolutionCandidate<ConstructorDescriptor>>emptyList(), context);
|
||||
@@ -474,9 +482,9 @@ public class CallResolver {
|
||||
context = context.replaceExpectedType(superType);
|
||||
}
|
||||
|
||||
Collection<ResolutionCandidate<ConstructorDescriptor>> candidates =
|
||||
List<ResolutionCandidate<ConstructorDescriptor>> candidates =
|
||||
CallResolverUtilKt.createResolutionCandidatesForConstructors(
|
||||
context.scope, context.call, superType, !anyConstructorHasDeclaredTypeParameters
|
||||
context.scope, context.call, superType, !anyConstructorHasDeclaredTypeParameters, syntheticScopes
|
||||
);
|
||||
|
||||
return new Pair<>(candidates, context);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
* 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.
|
||||
@@ -35,6 +35,8 @@ import org.jetbrains.kotlin.resolve.calls.model.ArgumentMatch
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.ResolutionCandidate
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.SyntheticScopes
|
||||
import org.jetbrains.kotlin.resolve.scopes.collectSyntheticConstructors
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.getImplicitReceiversHierarchy
|
||||
@@ -192,8 +194,9 @@ fun createResolutionCandidatesForConstructors(
|
||||
lexicalScope: LexicalScope,
|
||||
call: Call,
|
||||
typeWithConstructors: KotlinType,
|
||||
useKnownTypeSubstitutor: Boolean
|
||||
): Collection<ResolutionCandidate<ConstructorDescriptor>> {
|
||||
useKnownTypeSubstitutor: Boolean,
|
||||
syntheticScopes: SyntheticScopes
|
||||
): List<ResolutionCandidate<ConstructorDescriptor>> {
|
||||
val classWithConstructors = typeWithConstructors.constructor.declarationDescriptor as ClassDescriptor
|
||||
|
||||
val unwrappedType = typeWithConstructors.unwrap()
|
||||
@@ -233,7 +236,9 @@ fun createResolutionCandidatesForConstructors(
|
||||
dispatchReceiver = null
|
||||
}
|
||||
|
||||
return constructors.map {
|
||||
val syntheticConstructors = constructors.flatMap { syntheticScopes.collectSyntheticConstructors(it) }
|
||||
|
||||
return (constructors + syntheticConstructors).map {
|
||||
ResolutionCandidate.create(call, it, dispatchReceiver, receiverKind, knownSubstitutor)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user