[FE] Add context receivers getter to KtCallableDeclaration interface

This commit is contained in:
Anastasiya Shadrina
2021-01-26 17:41:31 +07:00
committed by TeamCityServer
parent d1fdc4d787
commit 7de8380ddf
9 changed files with 94 additions and 0 deletions
@@ -960,6 +960,11 @@ public class DescriptorResolver {
if (receiverTypeRef != null) {
receiverType = typeResolver.resolveType(scopeForDeclarationResolutionWithTypeParameters, receiverTypeRef, trace, true);
}
List<KtTypeReference> contextReceiverTypeRefs = variableDeclaration.getContextReceiverTypeReferences();
for (KtTypeReference contextReceiverTypeRef: contextReceiverTypeRefs) {
typeResolver.resolveType(scopeForDeclarationResolutionWithTypeParameters, contextReceiverTypeRef, trace, true);
}
}
ReceiverParameterDescriptor receiverDescriptor;
@@ -197,6 +197,9 @@ class FunctionDescriptorResolver(
if (function is KtFunctionLiteral) expectedFunctionType.getReceiverType() else null
}
function.contextReceiverTypeReferences.onEach {
typeResolver.resolveType(headerScope, it, trace, true)
}
val valueParameterDescriptors =
createValueParameterDescriptors(function, functionDescriptor, headerScope, trace, expectedFunctionType, inferenceSession)
@@ -32,6 +32,9 @@ public interface KtCallableDeclaration extends KtNamedDeclaration, KtTypeParamet
@Nullable
KtTypeReference getReceiverTypeReference();
@NotNull
List<KtTypeReference> getContextReceiverTypeReferences();
@Nullable
KtTypeReference getTypeReference();
@@ -40,6 +40,8 @@ abstract class KtConstructor<T : KtConstructor<T>> : KtDeclarationStub<KotlinPla
override fun getReceiverTypeReference() = null
override fun getContextReceiverTypeReferences(): List<KtTypeReference> = emptyList()
override fun getTypeReference() = null
@Throws(IncorrectOperationException::class)
@@ -75,6 +75,12 @@ public class KtDestructuringDeclarationEntry extends KtNamedDeclarationNotStubbe
return null;
}
@NotNull
@Override
public List<KtTypeReference> getContextReceiverTypeReferences() {
return Collections.emptyList();
}
@Nullable
@Override
public KtTypeParameterList getTypeParameterList() {
@@ -62,6 +62,12 @@ public abstract class KtFunctionNotStubbed extends KtTypeParameterListOwnerNotSt
return null;
}
@NotNull
@Override
public List<KtTypeReference> getContextReceiverTypeReferences() {
return Collections.emptyList();
}
@Override
@Nullable
public KtTypeReference getTypeReference() {
@@ -183,6 +183,37 @@ public class KtNamedFunction extends KtTypeParameterListOwnerStub<KotlinFunction
return getReceiverTypeRefByTree();
}
@NotNull
@Override
public List<KtTypeReference> getContextReceiverTypeReferences() {
KotlinFunctionStub stub = getStub();
if (stub != null) {
List<KtContextReceiver> childContextReceivers = getStubOrPsiChildrenAsList(KtStubElementTypes.CONTEXT_RECEIVER);
if (!childContextReceivers.isEmpty()) {
return childContextReceivers.get(0).typeReferences();
}
else {
return Collections.emptyList();
}
}
return getContextReceiverTypeRefsByTree();
}
@NotNull
private List<KtTypeReference> getContextReceiverTypeRefsByTree() {
PsiElement child = getFirstChild();
while (child != null) {
IElementType tt = child.getNode().getElementType();
if (tt == KtTokens.LPAR || tt == KtTokens.COLON) break;
if (child instanceof KtContextReceiver) {
return ((KtContextReceiver) child).typeReferences();
}
child = child.getNextSibling();
}
return Collections.emptyList();
}
@Nullable
private KtTypeReference getReceiverTypeRefByTree() {
PsiElement child = getFirstChild();
@@ -193,6 +193,12 @@ public class KtParameter extends KtNamedDeclarationStub<KotlinParameterStub> imp
return null;
}
@NotNull
@Override
public List<KtTypeReference> getContextReceiverTypeReferences() {
return Collections.emptyList();
}
@Nullable
@Override
public KtTypeParameterList getTypeParameterList() {
@@ -114,6 +114,38 @@ public class KtProperty extends KtTypeParameterListOwnerStub<KotlinPropertyStub>
return getReceiverTypeRefByTree();
}
@NotNull
@Override
public List<KtTypeReference> getContextReceiverTypeReferences() {
KotlinPropertyStub stub = getStub();
if (stub != null) {
KtContextReceiver contextReceiver = getStubOrPsiChild(KtStubElementTypes.CONTEXT_RECEIVER);
if (contextReceiver != null) {
return contextReceiver.typeReferences();
} else {
return Collections.emptyList();
}
}
return getContextReceiverTypeRefsByTree();
}
@NotNull
private List<KtTypeReference> getContextReceiverTypeRefsByTree() {
ASTNode node = getNode().getFirstChildNode();
while (node != null) {
IElementType tt = node.getElementType();
if (tt == KtTokens.COLON) {
break;
}
if (tt == KtNodeTypes.CONTEXT_RECEIVER) {
KtContextReceiver contextReceiver = (KtContextReceiver) node.getPsi();
return contextReceiver.typeReferences();
}
node = node.getTreeNext();
}
return Collections.emptyList();
}
@Nullable
private KtTypeReference getReceiverTypeRefByTree() {
ASTNode node = getNode().getFirstChildNode();