Call Hierarchy: Find implicit constructor calls in Java code
This commit is contained in:
+14
-1
@@ -23,6 +23,7 @@ import com.intellij.openapi.application.ReadActionProcessor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.light.LightMemberReference;
|
||||
import com.intellij.psi.search.SearchScope;
|
||||
import com.intellij.psi.search.searches.MethodReferencesSearch;
|
||||
import com.intellij.psi.search.searches.ReferencesSearch;
|
||||
@@ -114,7 +115,14 @@ public class KotlinCallerMethodsTreeStructure extends KotlinCallTreeStructure {
|
||||
processPsiMethodCallers(propertyMethods, descriptor, methodToDescriptorMap, searchScope, false);
|
||||
}
|
||||
if (element instanceof JetClassOrObject) {
|
||||
processJetClassOrObjectCallers((JetClassOrObject) element, descriptor, methodToDescriptorMap, searchScope);
|
||||
JetPrimaryConstructor constructor = ((JetClassOrObject) element).getPrimaryConstructor();
|
||||
if (constructor != null) {
|
||||
PsiMethod lightMethod = LightClassUtil.getLightClassMethod(constructor);
|
||||
processPsiMethodCallers(Collections.singleton(lightMethod), descriptor, methodToDescriptorMap, searchScope, false);
|
||||
}
|
||||
else {
|
||||
processJetClassOrObjectCallers((JetClassOrObject) element, descriptor, methodToDescriptorMap, searchScope);
|
||||
}
|
||||
}
|
||||
|
||||
Object[] callers = methodToDescriptorMap.values().toArray(new Object[methodToDescriptorMap.size()]);
|
||||
@@ -205,6 +213,11 @@ public class KotlinCallerMethodsTreeStructure extends KotlinCallTreeStructure {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (ref instanceof LightMemberReference) {
|
||||
PsiElement refTarget = ref.resolve();
|
||||
// Accept implicit superclass constructor reference in Java code
|
||||
if (!(refTarget instanceof PsiMethod && ((PsiMethod) refTarget).isConstructor())) return true;
|
||||
}
|
||||
|
||||
PsiElement refElement = ref.getElement();
|
||||
if (PsiTreeUtil.getParentOfType(refElement, JetImportDirective.class, true) != null) return true;
|
||||
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
<node text="B ()" base="true">
|
||||
<node text="A.A(Int) ()"/>
|
||||
<node text="JJ.JJ() ()"/>
|
||||
</node>
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
open class <caret>B()
|
||||
|
||||
open class A : B {
|
||||
constructor(a: Int) {
|
||||
|
||||
}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
class JJ extends B {
|
||||
JJ() {
|
||||
|
||||
}
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
<node text="B.B() ()" base="true">
|
||||
<node text="JJ.JJ() ()"/>
|
||||
<node text="A.A(Int) ()"/>
|
||||
</node>
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
open class B {
|
||||
<caret>constructor() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
open class A : B {
|
||||
constructor(a: Int) {
|
||||
|
||||
}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
class JJ extends B {
|
||||
JJ() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -358,6 +358,12 @@ public class HierarchyTestGenerated extends AbstractHierarchyTest {
|
||||
doCallerHierarchyTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kotlinPrimaryConstructorImplicitCalls")
|
||||
public void testKotlinPrimaryConstructorImplicitCalls() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/hierarchy/calls/callers/kotlinPrimaryConstructorImplicitCalls/");
|
||||
doCallerHierarchyTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kotlinPrivateClass")
|
||||
public void testKotlinPrivateClass() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/hierarchy/calls/callers/kotlinPrivateClass/");
|
||||
@@ -388,6 +394,12 @@ public class HierarchyTestGenerated extends AbstractHierarchyTest {
|
||||
doCallerHierarchyTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kotlinSecondaryConstructorImplicitCalls")
|
||||
public void testKotlinSecondaryConstructorImplicitCalls() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/hierarchy/calls/callers/kotlinSecondaryConstructorImplicitCalls/");
|
||||
doCallerHierarchyTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kotlinUnresolvedFunction")
|
||||
public void testKotlinUnresolvedFunction() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/hierarchy/calls/callers/kotlinUnresolvedFunction/");
|
||||
|
||||
Reference in New Issue
Block a user