Merge pull request #646 from JetBrains/rr/yole/kt2016
Find Usages: Provide element description for HighlightUsagesDescriptionLocation
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.findUsages
|
package org.jetbrains.kotlin.idea.findUsages
|
||||||
|
|
||||||
|
import com.intellij.codeInsight.highlighting.HighlightUsagesDescriptionLocation
|
||||||
import com.intellij.psi.ElementDescriptionLocation
|
import com.intellij.psi.ElementDescriptionLocation
|
||||||
import com.intellij.psi.ElementDescriptionProvider
|
import com.intellij.psi.ElementDescriptionProvider
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
@@ -25,6 +26,7 @@ import com.intellij.refactoring.util.RefactoringDescriptionLocation
|
|||||||
import com.intellij.usageView.UsageViewLongNameLocation
|
import com.intellij.usageView.UsageViewLongNameLocation
|
||||||
import org.jetbrains.kotlin.asJava.unwrapped
|
import org.jetbrains.kotlin.asJava.unwrapped
|
||||||
import org.jetbrains.kotlin.descriptors.ConstructorDescriptor
|
import org.jetbrains.kotlin.descriptors.ConstructorDescriptor
|
||||||
|
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||||
import org.jetbrains.kotlin.idea.search.usagesSearch.descriptor
|
import org.jetbrains.kotlin.idea.search.usagesSearch.descriptor
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||||
@@ -44,6 +46,14 @@ public class JetElementDescriptionProvider : ElementDescriptionProvider {
|
|||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun targetDescriptor(): DeclarationDescriptor? {
|
||||||
|
val descriptor = (targetElement as JetDeclaration).descriptor ?: return null
|
||||||
|
if (descriptor is ConstructorDescriptor) {
|
||||||
|
return descriptor.getContainingDeclaration()
|
||||||
|
}
|
||||||
|
return descriptor
|
||||||
|
}
|
||||||
|
|
||||||
if (targetElement !is PsiNamedElement || targetElement !is JetElement) return null
|
if (targetElement !is PsiNamedElement || targetElement !is JetElement) return null
|
||||||
|
|
||||||
val name = (targetElement : PsiNamedElement).getName()
|
val name = (targetElement : PsiNamedElement).getName()
|
||||||
@@ -53,10 +63,7 @@ public class JetElementDescriptionProvider : ElementDescriptionProvider {
|
|||||||
name
|
name
|
||||||
is RefactoringDescriptionLocation -> {
|
is RefactoringDescriptionLocation -> {
|
||||||
val kind = elementKind() ?: return null
|
val kind = elementKind() ?: return null
|
||||||
var descriptor = (targetElement as JetDeclaration).descriptor ?: return null
|
val descriptor = targetDescriptor() ?: return null
|
||||||
if (descriptor is ConstructorDescriptor) {
|
|
||||||
descriptor = (descriptor as ConstructorDescriptor).getContainingDeclaration()
|
|
||||||
}
|
|
||||||
val desc =
|
val desc =
|
||||||
if (location.includeParent() && targetElement !is JetTypeParameter && targetElement !is JetParameter) {
|
if (location.includeParent() && targetElement !is JetTypeParameter && targetElement !is JetParameter) {
|
||||||
DescriptorUtils.getFqName(descriptor).asString()
|
DescriptorUtils.getFqName(descriptor).asString()
|
||||||
@@ -67,6 +74,11 @@ public class JetElementDescriptionProvider : ElementDescriptionProvider {
|
|||||||
|
|
||||||
"$kind ${CommonRefactoringUtil.htmlEmphasize(desc)}"
|
"$kind ${CommonRefactoringUtil.htmlEmphasize(desc)}"
|
||||||
}
|
}
|
||||||
|
is HighlightUsagesDescriptionLocation -> {
|
||||||
|
val kind = elementKind() ?: return null
|
||||||
|
val descriptor = targetDescriptor() ?: return null
|
||||||
|
"$kind ${descriptor.getName().asString()}"
|
||||||
|
}
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user