From cbb2e5c37973370733d47897e43ab028eb524d6d Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Thu, 25 Aug 2016 19:30:59 +0200 Subject: [PATCH] show context when invoking Show Implementations from Find Usages popup #KT-13475 Fixed --- idea/src/META-INF/plugin.xml | 2 ++ .../KotlinUsageToPsiElementProvider.kt | 33 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinUsageToPsiElementProvider.kt diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index 04b8ef604a2..b7a15dbb985 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -733,6 +733,8 @@ + + org.jetbrains.kotlin.idea.intentions.IfNullToElvisIntention Kotlin diff --git a/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinUsageToPsiElementProvider.kt b/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinUsageToPsiElementProvider.kt new file mode 100644 index 00000000000..95ddcfaa774 --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinUsageToPsiElementProvider.kt @@ -0,0 +1,33 @@ +/* + * Copyright 2010-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.idea.codeInsight + +import com.intellij.psi.PsiElement +import com.intellij.usages.UsageToPsiElementProvider +import org.jetbrains.kotlin.idea.KotlinLanguage +import org.jetbrains.kotlin.psi.KtImportDirective +import org.jetbrains.kotlin.psi.KtNamedDeclaration +import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf + +class KotlinUsageToPsiElementProvider : UsageToPsiElementProvider() { + override fun getAppropriateParentFrom(element: PsiElement): PsiElement? { + if (element.language == KotlinLanguage.INSTANCE) { + return element.parentsWithSelf.first { it is KtNamedDeclaration || it is KtImportDirective } + } + return null + } +}