[FE] Minor: do not try to check stub is not null

This commit is contained in:
Anastasiya Shadrina
2021-11-02 20:50:43 +07:00
committed by TeamCityServer
parent 617af898b0
commit f75571b97a
3 changed files with 14 additions and 64 deletions
@@ -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<KtContextReceiver> {
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<KtContextReceiver> =
getContextReceiverList()?.let { return it.contextReceivers() } ?: emptyList()
}
@@ -201,13 +201,12 @@ public class KtNamedFunction extends KtTypeParameterListOwnerStub<KotlinFunction
@NotNull
@Override
public List<KtContextReceiver> 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
@@ -117,33 +117,12 @@ public class KtProperty extends KtTypeParameterListOwnerStub<KotlinPropertyStub>
@NotNull
@Override
public List<KtContextReceiver> 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<KtContextReceiver> 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