Skip to content

Commit 56bb456

Browse files
abelkovSpace Team
authored andcommitted
[PSI] KtNamedFunction cleanup
Inline function and invert 'if' conditions. KT-80965
1 parent 85bf861 commit 56bb456

File tree

1 file changed

+25
-28
lines changed

1 file changed

+25
-28
lines changed

compiler/psi/psi-api/src/org/jetbrains/kotlin/psi/KtNamedFunction.java

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,7 @@ public boolean hasTypeParameterListBeforeFunctionName() {
4444
if (stub != null) {
4545
return stub.getHasTypeParameterListBeforeFunctionName();
4646
}
47-
return hasTypeParameterListBeforeFunctionNameByTree();
48-
}
4947

50-
private boolean hasTypeParameterListBeforeFunctionNameByTree() {
5148
KtTypeParameterList typeParameterList = getTypeParameterList();
5249
if (typeParameterList == null) {
5350
return false;
@@ -69,7 +66,7 @@ public boolean hasBlockBody() {
6966
}
7067

7168
@Nullable
72-
@IfNotParsed // "function" with no "fun" keyword is created by parser for "{...}" on top-level or in class body
69+
@IfNotParsed // "function" with no "fun" keyword is created by parser for "{...}" on top-level or in the class body
7370
public PsiElement getFunKeyword() {
7471
return findChildByType(KtTokens.FUN_KEYWORD);
7572
}
@@ -113,10 +110,8 @@ public List<KtParameter> getValueParameters() {
113110
@Nullable
114111
public KtExpression getBodyExpression() {
115112
KotlinFunctionStub stub = getGreenStub();
116-
if (stub != null) {
117-
if (!stub.getHasBody()) {
118-
return null;
119-
}
113+
if (stub != null && !stub.getHasBody()) {
114+
return null;
120115
}
121116

122117
return findChildByClass(KtExpression.class);
@@ -158,19 +153,20 @@ public boolean hasDeclaredReturnType() {
158153
@Nullable
159154
public KtTypeReference getReceiverTypeReference() {
160155
KotlinFunctionStub stub = getGreenStub();
161-
if (stub != null) {
162-
if (!stub.isExtension()) {
163-
return null;
164-
}
165-
List<KtTypeReference> childTypeReferences = getStubOrPsiChildrenAsList(KtStubBasedElementTypes.TYPE_REFERENCE);
166-
if (!childTypeReferences.isEmpty()) {
167-
return childTypeReferences.get(0);
168-
}
169-
else {
170-
return null;
171-
}
156+
if (stub == null) {
157+
return getReceiverTypeRefByTree();
158+
}
159+
160+
if (!stub.isExtension()) {
161+
return null;
162+
}
163+
List<KtTypeReference> childTypeReferences = getStubOrPsiChildrenAsList(KtStubBasedElementTypes.TYPE_REFERENCE);
164+
if (!childTypeReferences.isEmpty()) {
165+
return childTypeReferences.get(0);
166+
}
167+
else {
168+
return null;
172169
}
173-
return getReceiverTypeRefByTree();
174170
}
175171

176172
@Nullable
@@ -204,15 +200,16 @@ public List<KtContextReceiver> getContextReceivers() {
204200
@Nullable
205201
public KtTypeReference getTypeReference() {
206202
KotlinFunctionStub stub = getGreenStub();
207-
if (stub != null) {
208-
List<KtTypeReference> typeReferences = getStubOrPsiChildrenAsList(KtStubBasedElementTypes.TYPE_REFERENCE);
209-
int returnTypeIndex = stub.isExtension() ? 1 : 0;
210-
if (returnTypeIndex >= typeReferences.size()) {
211-
return null;
212-
}
213-
return typeReferences.get(returnTypeIndex);
203+
if (stub == null) {
204+
return TypeRefHelpersKt.getTypeReference(this);
205+
}
206+
207+
List<KtTypeReference> typeReferences = getStubOrPsiChildrenAsList(KtStubBasedElementTypes.TYPE_REFERENCE);
208+
int returnTypeIndex = stub.isExtension() ? 1 : 0;
209+
if (returnTypeIndex >= typeReferences.size()) {
210+
return null;
214211
}
215-
return TypeRefHelpersKt.getTypeReference(this);
212+
return typeReferences.get(returnTypeIndex);
216213
}
217214

218215
@Override

0 commit comments

Comments
 (0)