Improvements in element description provider (proper treatment of light classes/methods, support of simple vs qualified names)

This commit is contained in:
Alexey Sedunov
2014-01-17 20:54:02 +04:00
parent fc848ec263
commit e70af5d372
25 changed files with 55 additions and 34 deletions
+1 -1
View File
@@ -270,7 +270,7 @@
forClass="org.jetbrains.jet.lang.psi.JetParameter"/> forClass="org.jetbrains.jet.lang.psi.JetParameter"/>
<gotoTargetRendererProvider id="JetGotoTargetRenderProvider" implementation="org.jetbrains.jet.plugin.JetGotoTargetRenderProvider" <gotoTargetRendererProvider id="JetGotoTargetRenderProvider" implementation="org.jetbrains.jet.plugin.JetGotoTargetRenderProvider"
order="first"/> order="first"/>
<elementDescriptionProvider implementation="org.jetbrains.jet.plugin.findUsages.JetElementDescriptionProvider"/> <elementDescriptionProvider implementation="org.jetbrains.jet.plugin.findUsages.JetElementDescriptionProvider" order="first"/>
<findUsagesHandlerFactory implementation="org.jetbrains.jet.plugin.findUsages.KotlinFindUsagesHandlerFactory"/> <findUsagesHandlerFactory implementation="org.jetbrains.jet.plugin.findUsages.KotlinFindUsagesHandlerFactory"/>
<usageTypeProvider implementation="org.jetbrains.jet.plugin.findUsages.JetUsageTypeProvider"/> <usageTypeProvider implementation="org.jetbrains.jet.plugin.findUsages.JetUsageTypeProvider"/>
<refactoring.safeDeleteProcessor <refactoring.safeDeleteProcessor
@@ -23,27 +23,48 @@ import com.intellij.psi.PsiNamedElement
import com.intellij.refactoring.util.RefactoringDescriptionLocation import com.intellij.refactoring.util.RefactoringDescriptionLocation
import com.intellij.usageView.UsageViewLongNameLocation import com.intellij.usageView.UsageViewLongNameLocation
import org.jetbrains.jet.lang.psi.* import org.jetbrains.jet.lang.psi.*
import org.jetbrains.jet.lang.resolve.java.jetAsJava.KotlinLightMethod
import org.jetbrains.jet.asJava.KotlinLightClass
import org.jetbrains.jet.lang.psi.psiUtil.getParentByType
import org.jetbrains.jet.plugin.search.usagesSearch.descriptor
import org.jetbrains.jet.lang.resolve.DescriptorUtils
public class JetElementDescriptionProvider : ElementDescriptionProvider { public class JetElementDescriptionProvider : ElementDescriptionProvider {
public override fun getElementDescription(element: PsiElement, location: ElementDescriptionLocation): String? { public override fun getElementDescription(element: PsiElement, location: ElementDescriptionLocation): String? {
fun elementKind() = when (element) { val targetElement = element.getNavigationElement()
is JetClass -> if (element.isTrait()) "Trait" else "Class"
is JetObjectDeclaration -> "Object" fun elementKind() = when (targetElement) {
is JetNamedFunction -> "Function" is JetClass -> if (targetElement.isTrait()) "trait" else "class"
is JetProperty -> "Property" is JetObjectDeclaration -> "object"
is JetTypeParameter -> "Type parameter" is JetNamedFunction -> "function"
is JetProperty -> "property"
is JetTypeParameter -> "type parameter"
else -> null else -> null
} }
if (element !is PsiNamedElement || element !is JetElement) return null if (targetElement !is PsiNamedElement || targetElement !is JetElement) return null
val name = (element as PsiNamedElement).getName() val name = (targetElement as PsiNamedElement).getName()
return when(location) { return when(location) {
is UsageViewLongNameLocation -> is UsageViewLongNameLocation ->
name name
is RefactoringDescriptionLocation -> is RefactoringDescriptionLocation -> {
elementKind()?.let { kind -> "$kind $name" } val kind = elementKind()
if (kind != null) {
val descriptor = (targetElement as JetDeclaration).descriptor
if (descriptor != null) {
val desc = if (location.includeParent() && targetElement !is JetTypeParameter) {
DescriptorUtils.getFqName(descriptor).asString()
}
else descriptor.getName().asString()
"$kind $desc"
}
else null
}
else null
}
else -> null else -> null
} }
} }
@@ -1 +1 @@
Class A has 1 usage that is not safe to delete. class test.A has 1 usage that is not safe to delete.
@@ -1 +1 @@
Class A has 3 usages that are not safe to delete.Of those 2 usages are in strings, comments, non-code files or generated code. class test.A has 3 usages that are not safe to delete.Of those 2 usages are in strings, comments, non-code files or generated code.
@@ -1 +1 @@
Class C has 1 usage that is not safe to delete. class test.A.C has 1 usage that is not safe to delete.
@@ -1 +1 @@
Trait A has 1 usage that is not safe to delete. trait test.A has 1 usage that is not safe to delete.
@@ -1 +1 @@
Class A has 1 usage that is not safe to delete. class test.A has 1 usage that is not safe to delete.
@@ -1 +1 @@
Function foo has 1 usage that is not safe to delete. function test.foo has 1 usage that is not safe to delete.
@@ -1 +1 @@
Object O has 1 usage that is not safe to delete. object test.A.O has 1 usage that is not safe to delete.
@@ -1 +1 @@
Object A has 1 usage that is not safe to delete. object test.A has 1 usage that is not safe to delete.
@@ -1 +1 @@
Object A has 1 usage that is not safe to delete. object test.A has 1 usage that is not safe to delete.
@@ -1 +1 @@
method C.getFoo() implements method B.getFoo(). method C.getFoo() implements property B.foo.
@@ -1 +1 @@
method C.getFoo() implements method B.getFoo(). method C.getFoo() implements property B.foo.
@@ -1 +1 @@
method C.setFoo(String) implements method B.setFoo(String). method C.setFoo(String) implements property B.foo.
@@ -1 +1 @@
Property foo has 1 usage that is not safe to delete. property test.foo has 1 usage that is not safe to delete.
@@ -1 +1 @@
Type parameter X has 1 usage that is not safe to delete. type parameter X has 1 usage that is not safe to delete.
@@ -1 +1 @@
Type parameter Y has 1 usage that is not safe to delete. type parameter Y has 1 usage that is not safe to delete.
@@ -1 +1 @@
Type parameter X has 2 usages that are not safe to delete. type parameter X has 2 usages that are not safe to delete.
@@ -1 +1 @@
Type parameter X has 1 usage that is not safe to delete. type parameter X has 1 usage that is not safe to delete.
@@ -1 +1 @@
Type parameter X has 1 usage that is not safe to delete. type parameter X has 1 usage that is not safe to delete.
@@ -1 +1 @@
Type parameter X has 1 usage that is not safe to delete. type parameter X has 1 usage that is not safe to delete.
@@ -1 +1 @@
Type parameter Y has 1 usage that is not safe to delete. type parameter Y has 1 usage that is not safe to delete.
@@ -1 +1 @@
Type parameter X has 2 usages that are not safe to delete. type parameter X has 2 usages that are not safe to delete.
@@ -1 +1 @@
Type parameter X has 1 usage that is not safe to delete. type parameter X has 1 usage that is not safe to delete.
@@ -1 +1 @@
Type parameter X has 1 usage that is not safe to delete. type parameter X has 1 usage that is not safe to delete.