[FE] Support context receivers on classes
This commit is contained in:
committed by
TeamCityServer
parent
c34fe8d547
commit
f4ddf66ac4
+1
@@ -167,6 +167,7 @@ class SyntheticClassOrObjectDescriptor(
|
||||
override fun getPrimaryConstructorModifierList(): KtModifierList? = null
|
||||
override fun getPrimaryConstructorParameters(): List<KtParameter> = emptyList()
|
||||
override fun getSecondaryConstructors(): List<KtSecondaryConstructor> = emptyList()
|
||||
override fun getContextReceiverTypeReferences(): List<KtTypeReference> = emptyList()
|
||||
|
||||
override fun getPsiOrParent() = _parent.psiOrParent
|
||||
override fun getParent() = _parent.psiOrParent
|
||||
|
||||
+1
-3
@@ -25,8 +25,6 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.getAllSuperclassesWithoutAny
|
||||
import org.jetbrains.kotlin.resolve.scopes.*
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.ErrorLexicalScope
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
import java.util.*
|
||||
|
||||
class ClassResolutionScopesSupport(
|
||||
private val classDescriptor: ClassDescriptor,
|
||||
@@ -69,7 +67,7 @@ class ClassResolutionScopesSupport(
|
||||
scopeWithGenerics,
|
||||
classDescriptor,
|
||||
true,
|
||||
listOf(classDescriptor.thisAsReceiverParameter),
|
||||
classDescriptor.contextReceivers + classDescriptor.thisAsReceiverParameter,
|
||||
LexicalScopeKind.CLASS_MEMBER_SCOPE
|
||||
)
|
||||
}
|
||||
|
||||
+28
-1
@@ -18,6 +18,7 @@ import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.kotlin.descriptors.impl.ClassDescriptorBase;
|
||||
import org.jetbrains.kotlin.descriptors.impl.FunctionDescriptorImpl;
|
||||
import org.jetbrains.kotlin.descriptors.impl.ReceiverParameterDescriptorImpl;
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticFactory0;
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation;
|
||||
import org.jetbrains.kotlin.lexer.KtTokens;
|
||||
@@ -39,6 +40,7 @@ import org.jetbrains.kotlin.resolve.lazy.declarations.ClassMemberDeclarationProv
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope;
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope;
|
||||
import org.jetbrains.kotlin.resolve.scopes.StaticScopeForKotlinEnum;
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ExtensionClassReceiver;
|
||||
import org.jetbrains.kotlin.resolve.source.KotlinSourceElementKt;
|
||||
import org.jetbrains.kotlin.storage.MemoizedFunctionToNotNull;
|
||||
import org.jetbrains.kotlin.storage.NotNullLazyValue;
|
||||
@@ -51,6 +53,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static kotlin.collections.CollectionsKt.firstOrNull;
|
||||
import static org.jetbrains.kotlin.descriptors.DescriptorVisibilities.PRIVATE;
|
||||
@@ -104,6 +107,8 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
|
||||
private final NotNullLazyValue<Collection<ClassDescriptor>> sealedSubclasses;
|
||||
|
||||
private final NotNullLazyValue<List<ReceiverParameterDescriptor>> contextReceivers;
|
||||
|
||||
public LazyClassDescriptor(
|
||||
@NotNull LazyClassContext c,
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@@ -294,9 +299,23 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
storageManager.createLazyValue(() -> {
|
||||
if (getModality() == Modality.SEALED) {
|
||||
return c.getSealedClassInheritorsProvider().computeSealedSubclasses(this, freedomForSealedInterfacesSupported);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
});
|
||||
this.contextReceivers = storageManager.createLazyValue(() -> {
|
||||
if (classOrObject == null) {
|
||||
return CollectionsKt.emptyList();
|
||||
}
|
||||
return classOrObject.getContextReceiverTypeReferences().stream().map(typeReference -> {
|
||||
KotlinType kotlinType = c.getTypeResolver().resolveType(getScopeForClassHeaderResolution(), typeReference, c.getTrace(), true);
|
||||
return new ReceiverParameterDescriptorImpl(
|
||||
this,
|
||||
new ExtensionClassReceiver(this, kotlinType, null),
|
||||
Annotations.Companion.getEMPTY()
|
||||
);
|
||||
}).collect(Collectors.toList());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -432,6 +451,12 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
return ((LazyClassMemberScope) getUnsubstitutedMemberScope()).getConstructors();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<ReceiverParameterDescriptor> getContextReceivers() {
|
||||
return contextReceivers.invoke();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassConstructorDescriptor getUnsubstitutedPrimaryConstructor() {
|
||||
return ((LazyClassMemberScope) getUnsubstitutedMemberScope()).getPrimaryConstructor();
|
||||
@@ -642,6 +667,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
ForceResolveUtil.forceResolveAllContents(getDescriptorsForExtraCompanionObjects());
|
||||
ForceResolveUtil.forceResolveAllContents(getUnsubstitutedMemberScope());
|
||||
ForceResolveUtil.forceResolveAllContents(getTypeConstructor());
|
||||
ForceResolveUtil.forceResolveAllContents(this.getContextReceivers());
|
||||
}
|
||||
|
||||
// Note: headers of member classes' members are not resolved
|
||||
@@ -671,6 +697,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
}
|
||||
getUnsubstitutedPrimaryConstructor();
|
||||
getVisibility();
|
||||
getContextReceivers();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
Reference in New Issue
Block a user