Render entries with outer classifiers in call hierarchy (KT-22698)
#KT-22698 Fixed
This commit is contained in:
+49
-46
@@ -31,14 +31,11 @@ import com.intellij.psi.PsiReference;
|
||||
import com.intellij.ui.LayeredIcon;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.ConstructorDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.ResolutionUtils;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.psi.*;
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
|
||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -141,62 +138,68 @@ public class KotlinCallHierarchyNodeDescriptor extends HierarchyNodeDescriptor i
|
||||
|
||||
@Nullable
|
||||
private static String renderElement(@Nullable PsiElement element) {
|
||||
String elementText;
|
||||
String containerText = null;
|
||||
|
||||
if (element instanceof KtFile) {
|
||||
elementText = ((KtFile) element).getName();
|
||||
return ((KtFile) element).getName();
|
||||
}
|
||||
else if (element instanceof KtNamedDeclaration) {
|
||||
BindingContext bindingContext = ResolutionUtils.analyze((KtElement) element, BodyResolveMode.FULL);
|
||||
|
||||
DeclarationDescriptor descriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, element);
|
||||
if (descriptor == null) return null;
|
||||
if (!(element instanceof KtNamedDeclaration)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (element instanceof KtClassOrObject) {
|
||||
if (element instanceof KtObjectDeclaration && ((KtObjectDeclaration) element).isCompanion()) {
|
||||
descriptor = descriptor.getContainingDeclaration();
|
||||
if (!(descriptor instanceof ClassDescriptor)) return null;
|
||||
DeclarationDescriptor descriptor = ResolutionUtils.resolveToDescriptorIfAny((KtNamedDeclaration) element, BodyResolveMode.PARTIAL);
|
||||
if (descriptor == null) return null;
|
||||
|
||||
String elementText;
|
||||
if (element instanceof KtClassOrObject) {
|
||||
if (element instanceof KtObjectDeclaration && ((KtObjectDeclaration) element).isCompanion()) {
|
||||
descriptor = descriptor.getContainingDeclaration();
|
||||
if (!(descriptor instanceof ClassDescriptor)) return null;
|
||||
|
||||
elementText = renderClassOrObject((ClassDescriptor) descriptor);
|
||||
}
|
||||
else if (element instanceof KtEnumEntry) {
|
||||
elementText = ((KtEnumEntry) element).getName();
|
||||
}
|
||||
else {
|
||||
if (((KtClassOrObject) element).getName() != null) {
|
||||
elementText = renderClassOrObject((ClassDescriptor) descriptor);
|
||||
}
|
||||
else if (element instanceof KtEnumEntry) {
|
||||
elementText = ((KtEnumEntry) element).getName();
|
||||
}
|
||||
else {
|
||||
if (((KtClassOrObject) element).getName() != null) {
|
||||
elementText = renderClassOrObject((ClassDescriptor) descriptor);
|
||||
}
|
||||
else {
|
||||
elementText = "[anonymous]";
|
||||
}
|
||||
elementText = "[anonymous]";
|
||||
}
|
||||
}
|
||||
else if (element instanceof KtNamedFunction || element instanceof KtConstructor) {
|
||||
elementText = renderNamedFunction((FunctionDescriptor) descriptor);
|
||||
}
|
||||
else if (element instanceof KtProperty) {
|
||||
elementText = ((KtProperty) element).getName();
|
||||
}
|
||||
else return null;
|
||||
|
||||
DeclarationDescriptor containerDescriptor = descriptor.getContainingDeclaration();
|
||||
while (containerDescriptor != null) {
|
||||
String name = containerDescriptor.getName().asString();
|
||||
if (!name.startsWith("<")) {
|
||||
containerText = name;
|
||||
break;
|
||||
}
|
||||
containerDescriptor = containerDescriptor.getContainingDeclaration();
|
||||
}
|
||||
}
|
||||
else if ((element instanceof KtNamedFunction || element instanceof KtConstructor)) {
|
||||
if (!(descriptor instanceof FunctionDescriptor)) return null;
|
||||
elementText = renderNamedFunction((FunctionDescriptor) descriptor);
|
||||
}
|
||||
else if (element instanceof KtProperty) {
|
||||
elementText = ((KtProperty) element).getName();
|
||||
}
|
||||
else return null;
|
||||
|
||||
if (elementText == null) return null;
|
||||
return containerText != null ? containerText + "." + elementText : elementText;
|
||||
}
|
||||
|
||||
public static String renderNamedFunction(FunctionDescriptor descriptor) {
|
||||
String containerText = null;
|
||||
DeclarationDescriptor containerDescriptor = descriptor.getContainingDeclaration();
|
||||
while (containerDescriptor != null) {
|
||||
if (containerDescriptor instanceof PackageFragmentDescriptor || containerDescriptor instanceof ModuleDescriptor) {
|
||||
break;
|
||||
}
|
||||
|
||||
Name name = containerDescriptor.getName();
|
||||
if (!name.isSpecial()) {
|
||||
String identifier = name.getIdentifier();
|
||||
containerText = containerText != null ? identifier + "." + containerText : identifier;
|
||||
}
|
||||
|
||||
containerDescriptor = containerDescriptor.getContainingDeclaration();
|
||||
}
|
||||
|
||||
return containerText != null ? containerText + "." + elementText : elementText;
|
||||
}
|
||||
|
||||
public static String renderNamedFunction(@NotNull FunctionDescriptor descriptor) {
|
||||
DeclarationDescriptor descriptorForName = descriptor instanceof ConstructorDescriptor
|
||||
? descriptor.getContainingDeclaration()
|
||||
: descriptor;
|
||||
|
||||
Vendored
+4
-4
@@ -1,10 +1,10 @@
|
||||
<node text="client.[anonymous] ()" base="true">
|
||||
<node text="packageFun(String)(2 usages) ()"/>
|
||||
<node text="KA(2 usages) ()"/>
|
||||
<node text="KA.foo(String) ()"/>
|
||||
<node text="KA.name ()"/>
|
||||
<node text="JA.JA()(2 usages) ()"/>
|
||||
<node text="JA.foo(String) ()">
|
||||
<node text="PrintStream.println(String) (java.io)"/>
|
||||
</node>
|
||||
<node text="KA(2 usages) ()"/>
|
||||
<node text="KA.foo(String) ()"/>
|
||||
<node text="KA.name ()"/>
|
||||
<node text="packageFun(String)(2 usages) ()"/>
|
||||
</node>
|
||||
|
||||
+7
-7
@@ -1,14 +1,14 @@
|
||||
<node text="KClient.bar() ()" base="true">
|
||||
<node text="KA.foo(String)(2 usages) ()"/>
|
||||
<node text="packageFun(String) ()"/>
|
||||
<node text="packageVal ()"/>
|
||||
<node text="JA.JA()(4 usages) ()"/>
|
||||
<node text="JA.foo(String)(2 usages) ()">
|
||||
<node text="PrintStream.println(String) (java.io)"/>
|
||||
</node>
|
||||
<node text="JA.JA()(4 usages) ()"/>
|
||||
<node text="bar.localFun(String)(2 usages) ()">
|
||||
<node text="KA(4 usages) ()"/>
|
||||
<node text="KA.foo(String)(2 usages) ()"/>
|
||||
<node text="KA.name(2 usages) ()"/>
|
||||
<node text="KClient.bar.localFun(String)(2 usages) ()">
|
||||
<node text="packageFun(String) ()"/>
|
||||
</node>
|
||||
<node text="KA.name(2 usages) ()"/>
|
||||
<node text="KA(4 usages) ()"/>
|
||||
<node text="packageFun(String) ()"/>
|
||||
<node text="packageVal ()"/>
|
||||
</node>
|
||||
|
||||
Vendored
+4
-4
@@ -6,14 +6,14 @@
|
||||
<node text="KA(2 usages) ()"/>
|
||||
<node text="KA.foo(String) ()"/>
|
||||
<node text="KA.name ()"/>
|
||||
<node text="localFun.bar() ()">
|
||||
<node text="client.localFun.bar() ()">
|
||||
<node text="KA(2 usages) ()"/>
|
||||
<node text="KA.foo(String) ()"/>
|
||||
<node text="KA.name ()"/>
|
||||
<node text="JA.JA()(2 usages) ()"/>
|
||||
<node text="JA.foo(String) ()">
|
||||
<node text="PrintStream.println(String) (java.io)"/>
|
||||
</node>
|
||||
<node text="KA(2 usages) ()"/>
|
||||
<node text="JA.JA()(2 usages) ()"/>
|
||||
<node text="KA.foo(String) ()"/>
|
||||
</node>
|
||||
<node text="packageFun(String)(2 usages) ()"/>
|
||||
</node>
|
||||
|
||||
+5
-5
@@ -1,12 +1,12 @@
|
||||
<node text="KA ()" base="true">
|
||||
<node text="JA ()"/>
|
||||
<node text="packageFun(String) ()"/>
|
||||
<node text="KClient.bar ()"/>
|
||||
<node text="bar.localFun() ()"/>
|
||||
<node text="main0.kt ()"/>
|
||||
<node text="KClientObj ()"/>
|
||||
<node text="JA.newKA() ()"/>
|
||||
<node text="KClient ()"/>
|
||||
<node text="KClient ()"/>
|
||||
<node text="KClient.bar ()"/>
|
||||
<node text="KClient.bar() ()"/>
|
||||
<node text="KClient.bar.localFun() ()"/>
|
||||
<node text="KClientObj ()"/>
|
||||
<node text="main0.kt ()"/>
|
||||
<node text="packageFun(String) ()"/>
|
||||
</node>
|
||||
|
||||
+1
-1
@@ -5,8 +5,8 @@
|
||||
<node text="KClient(2 usages) ()"/>
|
||||
<node text="KClient.bar()(2 usages) ()"/>
|
||||
<node text="KClient.bar(2 usages) ()"/>
|
||||
<node text="KClient.bar.localFun()(2 usages) ()"/>
|
||||
<node text="KClientObj(2 usages) ()"/>
|
||||
<node text="bar.localFun()(2 usages) ()"/>
|
||||
<node text="main0.kt(2 usages) ()"/>
|
||||
<node text="packageFun(String)(2 usages) ()"/>
|
||||
</node>
|
||||
|
||||
+2
-2
@@ -1,3 +1,3 @@
|
||||
<node text="p.foo() (p)" base="true">
|
||||
<node text="q.bar() (q)"/>
|
||||
<node text="foo() (p)" base="true">
|
||||
<node text="bar() (q)"/>
|
||||
</node>
|
||||
|
||||
+4
-4
@@ -1,6 +1,6 @@
|
||||
<node text="client.KA ()" base="true">
|
||||
<node text="bar.localFun() ()"/>
|
||||
<node text="client.bar() ()"/>
|
||||
<node text="client.KClientObj ()"/>
|
||||
<node text="KClient.client.KA ()" base="true">
|
||||
<node text="KClient.client.bar.localFun() ()"/>
|
||||
<node text="KClient.client() ()"/>
|
||||
<node text="KClient.client.bar() ()"/>
|
||||
<node text="KClient.client.KClientObj ()"/>
|
||||
</node>
|
||||
|
||||
Vendored
+4
-4
@@ -1,6 +1,6 @@
|
||||
<node text="client.foo(String) ()" base="true">
|
||||
<node text="client.bar() ()"/>
|
||||
<node text="bar.localFun() ()"/>
|
||||
<node text="client.KClientObj ()"/>
|
||||
<node text="KClient.client.foo(String) ()" base="true">
|
||||
<node text="KClient.client() ()"/>
|
||||
<node text="KClient.client.bar() ()"/>
|
||||
<node text="KClient.client.bar.localFun() ()"/>
|
||||
<node text="KClient.client.KClientObj ()"/>
|
||||
</node>
|
||||
|
||||
+8
-8
@@ -1,12 +1,12 @@
|
||||
<node text="T.KA ()" base="true">
|
||||
<node text="main0.kt ()"/>
|
||||
<node text="JA.newKA() ()"/>
|
||||
<node text="KClientObj ()"/>
|
||||
<node text="KClient ()"/>
|
||||
<node text="packageFun(String) ()"/>
|
||||
<node text="KClient.bar ()"/>
|
||||
<node text="bar.localFun() ()"/>
|
||||
<node text="KClient ()"/>
|
||||
<node text="JA ()"/>
|
||||
<node text="JA.newKA() ()"/>
|
||||
<node text="KClient ()"/>
|
||||
<node text="KClient ()"/>
|
||||
<node text="KClient.bar ()"/>
|
||||
<node text="KClient.bar() ()"/>
|
||||
<node text="KClient.bar.localFun() ()"/>
|
||||
<node text="KClientObj ()"/>
|
||||
<node text="main0.kt ()"/>
|
||||
<node text="packageFun(String) ()"/>
|
||||
</node>
|
||||
|
||||
idea/testData/hierarchy/calls/callers/kotlinNestedInnerClass/KotlinNestedInnerClass_verification.xml
Vendored
+6
-6
@@ -1,12 +1,12 @@
|
||||
<node text="T.KA ()" base="true">
|
||||
<node text="KClient.bar ()"/>
|
||||
<node text="JA.newKA() ()"/>
|
||||
<node text="bar.localFun() ()"/>
|
||||
<node text="JA ()"/>
|
||||
<node text="JA.newKA() ()"/>
|
||||
<node text="KClient ()"/>
|
||||
<node text="KClientObj ()"/>
|
||||
<node text="KClient ()"/>
|
||||
<node text="KClient.bar ()"/>
|
||||
<node text="KClient.bar() ()"/>
|
||||
<node text="packageFun(String) ()"/>
|
||||
<node text="KClient ()"/>
|
||||
<node text="KClient.bar.localFun() ()"/>
|
||||
<node text="KClientObj ()"/>
|
||||
<node text="main0.kt ()"/>
|
||||
<node text="packageFun(String) ()"/>
|
||||
</node>
|
||||
|
||||
Vendored
+4
-4
@@ -1,11 +1,11 @@
|
||||
<node text="packageFun(String) ()" base="true">
|
||||
<node text="bar.localFun() ()"/>
|
||||
<node text="main0.kt ()"/>
|
||||
<node text="JA ()"/>
|
||||
<node text="JA.foo() ()"/>
|
||||
<node text="KClientObj ()"/>
|
||||
<node text="KClient ()"/>
|
||||
<node text="KClient ()"/>
|
||||
<node text="KClient.bar ()"/>
|
||||
<node text="KClient.bar() ()"/>
|
||||
<node text="JA ()"/>
|
||||
<node text="KClient.bar.localFun() ()"/>
|
||||
<node text="KClientObj ()"/>
|
||||
<node text="main0.kt ()"/>
|
||||
</node>
|
||||
|
||||
Vendored
+1
-1
@@ -5,7 +5,7 @@
|
||||
<node text="KClient ()"/>
|
||||
<node text="KClient.bar() ()"/>
|
||||
<node text="KClient.bar(2 usages) ()"/>
|
||||
<node text="KClient.bar.localFun() ()"/>
|
||||
<node text="KClientObj(2 usages) ()"/>
|
||||
<node text="bar.localFun() ()"/>
|
||||
<node text="packageFun(String) ()"/>
|
||||
</node>
|
||||
|
||||
+1
-1
@@ -5,8 +5,8 @@
|
||||
<node text="KClient(2 usages) ()"/>
|
||||
<node text="KClient.bar()(2 usages) ()"/>
|
||||
<node text="KClient.bar(4 usages) ()"/>
|
||||
<node text="KClient.bar.localFun()(2 usages) ()"/>
|
||||
<node text="KClientObj(4 usages) ()"/>
|
||||
<node text="bar.localFun()(2 usages) ()"/>
|
||||
<node text="main0.kt(2 usages) ()"/>
|
||||
<node text="packageFun(String)(2 usages) ()"/>
|
||||
</node>
|
||||
|
||||
Reference in New Issue
Block a user