diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/KtClassOrObject.kt b/compiler/psi/src/org/jetbrains/kotlin/psi/KtClassOrObject.kt index ea01417b63a..bbabbac5722 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/psi/KtClassOrObject.kt +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/KtClassOrObject.kt @@ -188,38 +188,10 @@ abstract class KtClassOrObject : return parts.joinToString(separator = ".") } - fun getContextReceiverList(): KtContextReceiverList? { - val stub = stub - if (stub != null) { - return getStubOrPsiChild(KtStubElementTypes.CONTEXT_RECEIVER_LIST) - } - var node = node.firstChildNode - while (node != null) { - val tt = node.elementType - if (tt === KtNodeTypes.CONTEXT_RECEIVER_LIST) { - return node.psi as KtContextReceiverList - } - node = node.treeNext - } - return null - } + fun getContextReceiverList(): KtContextReceiverList? = getStubOrPsiChild(KtStubElementTypes.CONTEXT_RECEIVER_LIST) - override fun getContextReceivers(): List { - val stub = stub - if (stub != null) { - return getStubOrPsiChildrenAsList(KtStubElementTypes.CONTEXT_RECEIVER) - } - var node = node.firstChildNode - while (node != null) { - val tt = node.elementType - if (tt === KtNodeTypes.CONTEXT_RECEIVER_LIST) { - val contextReceiver = node.psi as KtContextReceiverList - return contextReceiver.contextReceivers() - } - node = node.treeNext - } - return emptyList() - } + override fun getContextReceivers(): List = + getContextReceiverList()?.let { return it.contextReceivers() } ?: emptyList() } diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/KtNamedFunction.java b/compiler/psi/src/org/jetbrains/kotlin/psi/KtNamedFunction.java index 338d89c3a59..4a8ae943861 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/psi/KtNamedFunction.java +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/KtNamedFunction.java @@ -201,13 +201,12 @@ public class KtNamedFunction extends KtTypeParameterListOwnerStub getContextReceivers() { - KtContextReceiverList list = getContextReceiverList(); - return list != null ? list.contextReceivers() : Collections.emptyList(); - } - - @Nullable - private KtContextReceiverList getContextReceiverList() { - return getStubOrPsiChild(KtStubElementTypes.CONTEXT_RECEIVER_LIST); + KtContextReceiverList contextReceiverList = getStubOrPsiChild(KtStubElementTypes.CONTEXT_RECEIVER_LIST); + if (contextReceiverList != null) { + return contextReceiverList.contextReceivers(); + } else { + return Collections.emptyList(); + } } @Override diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/KtProperty.java b/compiler/psi/src/org/jetbrains/kotlin/psi/KtProperty.java index 186e79809fd..5aee715cfac 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/psi/KtProperty.java +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/KtProperty.java @@ -117,33 +117,12 @@ public class KtProperty extends KtTypeParameterListOwnerStub @NotNull @Override public List getContextReceivers() { - KotlinPropertyStub stub = getStub(); - if (stub != null) { - KtContextReceiverList contextReceiver = getStubOrPsiChild(KtStubElementTypes.CONTEXT_RECEIVER_LIST); - if (contextReceiver != null) { - return contextReceiver.contextReceivers(); - } else { - return Collections.emptyList(); - } + KtContextReceiverList contextReceiverList = getStubOrPsiChild(KtStubElementTypes.CONTEXT_RECEIVER_LIST); + if (contextReceiverList != null) { + return contextReceiverList.contextReceivers(); + } else { + return Collections.emptyList(); } - return getContextReceiverTypeRefsByTree(); - } - - @NotNull - private List getContextReceiverTypeRefsByTree() { - ASTNode node = getNode().getFirstChildNode(); - while (node != null) { - IElementType tt = node.getElementType(); - if (tt == KtTokens.COLON) { - break; - } - if (tt == KtNodeTypes.CONTEXT_RECEIVER_LIST) { - KtContextReceiverList contextReceiver = (KtContextReceiverList) node.getPsi(); - return contextReceiver.contextReceivers(); - } - node = node.getTreeNext(); - } - return Collections.emptyList(); } @Nullable