Teach getOwnerFunction() in KtParamter work with stubs

This commit is contained in:
Nikolay Krasko
2016-04-20 20:26:41 +03:00
parent c62d906d5c
commit 39e6b893a7
2 changed files with 10 additions and 5 deletions
@@ -173,10 +173,8 @@ public class KtParameter extends KtNamedDeclarationStub<KotlinParameterStub> imp
@Nullable @Nullable
public KtFunction getOwnerFunction() { public KtFunction getOwnerFunction() {
PsiElement parent = getParent(); PsiElement parent = getParentByStub();
if (parent == null) return null; if (!(parent instanceof KtParameterList)) return null;
PsiElement grandparent = parent.getParent(); return ((KtParameterList) parent).getOwnerFunction();
if (!(grandparent instanceof KtFunction)) return null;
return (KtFunction) grandparent;
} }
} }
@@ -17,6 +17,7 @@
package org.jetbrains.kotlin.psi; package org.jetbrains.kotlin.psi;
import com.intellij.lang.ASTNode; import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.psi.stubs.KotlinPlaceHolderStub; import org.jetbrains.kotlin.psi.stubs.KotlinPlaceHolderStub;
@@ -61,4 +62,10 @@ public class KtParameterList extends KtElementImplStub<KotlinPlaceHolderStub<KtP
public void removeParameter(@NotNull KtParameter parameter) { public void removeParameter(@NotNull KtParameter parameter) {
EditCommaSeparatedListHelper.INSTANCE.removeItem(parameter); EditCommaSeparatedListHelper.INSTANCE.removeItem(parameter);
} }
public KtFunction getOwnerFunction() {
PsiElement parent = getParentByStub();
if (!(parent instanceof KtFunction)) return null;
return (KtFunction) parent;
}
} }